using BLL; using System; using System.Text; namespace FineUIPro.Web.PHTGL.InvoiceManage { public partial class InvoiceStandingBook : PageBase { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.GetButtonPower(); this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString(); // 绑定表格 this.BindGrid(); } } #region 绑定数据 /// /// 绑定数据 /// private void BindGrid() { Model.PHTGL_Invoice table = new Model.PHTGL_Invoice(); table.ProjectId = this.CurrUser.LoginProjectId; table.State = PhtglInvoiceService.StateDataIn; var tb = BLL.PhtglInvoiceService.GetListData(table, Grid1); Grid1.RecordCount = PhtglInvoiceService.Count; //tb = GetFilteredTable(Grid1.FilteredData, tb); Grid1.DataSource = tb; Grid1.DataBind(); } #endregion #region GV 数据操作 /// /// 过滤表头 /// /// /// //protected void Grid1_FilterChange(object sender, EventArgs e) //{ // this.BindGrid(); //} /// /// 分页 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { this.Grid1.PageIndex = e.NewPageIndex; this.BindGrid(); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { this.Grid1.SortDirection = e.SortDirection; this.Grid1.SortField = e.SortField; this.BindGrid(); } /// /// 分页显示条数下拉框 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { this.Grid1.PageSize = Convert.ToInt32(this.ddlPageSize.SelectedValue); this.BindGrid(); } #endregion #region 数据编辑事件 /// /// 新增 /// /// /// protected void btnNew_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("InvoiceStandingBookEdit.aspx?InvoiceId={0}", string.Empty, "增加 - "))); } /// /// 编辑按钮 /// /// /// protected void btnEdit_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string ID = Grid1.SelectedRowID; var model = BLL.PhtglInvoiceService.GetPHTGL_InvoiceById(ID); if (model != null) ///已上报时不能删除 { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("InvoiceStandingBookEdit.aspx?InvoiceId={0}", ID, "编辑 - "))); } } /// /// Grid行双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { this.btnEdit_Click(null, null); } /// /// 批量删除 /// /// /// protected void btnDelete_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length > 0) { foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); var model = BLL.PhtglInvoiceService.GetPHTGL_InvoiceById(rowID); if (model != null) { BLL.PhtglInvoiceService.DeletePHTGL_InvoiceById(rowID); } } BindGrid(); ShowNotify("删除数据成功!", MessageBoxIcon.Success); } } #endregion #region 关闭弹出窗 /// /// 关闭弹出窗 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { BindGrid(); } #endregion #region 获取权限按钮 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, BLL.Const.PHTGL_InvoiceStandingBookMenuId); if (buttonList.Count > 0) { if (buttonList.Contains(BLL.Const.BtnAdd)) { // this.btnNew.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnModify)) { this.btnMenuEdit.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnDelete)) { this.btnMenuDelete.Hidden = false; this.btnDelete.Hidden = false; } } } #endregion #region 导出按钮 /// 导出按钮 /// /// /// protected void btnOut_Click(object sender, EventArgs e) { Response.ClearContent(); string filename = Funs.GetNewFileName(); Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("" + filename, System.Text.Encoding.UTF8) + ".xls"); Response.ContentType = "application/excel"; Response.ContentEncoding = System.Text.Encoding.UTF8; this.Grid1.PageSize = 500; this.BindGrid(); Response.Write(GetGridTableHtml(Grid1)); Response.End(); } /// /// 导出方法 /// /// /// private string GetGridTableHtml(Grid grid) { StringBuilder sb = new StringBuilder(); sb.Append(""); sb.Append(""); sb.Append(""); foreach (GridColumn column in grid.Columns) { sb.AppendFormat("", column.HeaderText); } sb.Append(""); foreach (GridRow row in grid.Rows) { sb.Append(""); foreach (GridColumn column in grid.Columns) { string html = row.Values[column.ColumnIndex].ToString(); if (column.ColumnID == "tfNumber") { html = (row.FindControl("lblNumber") as System.Web.UI.WebControls.Label).Text; } sb.AppendFormat("", html); } sb.Append(""); } sb.Append("
{0}
{0}
"); return sb.ToString(); } #endregion protected void btnImport_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript( Window1.GetShowReference(string.Format("InvoiceDataIn.aspx?", "导入 - "))); } protected void btnOrderIn_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string ID = Grid1.SelectedRowID; var model = BLL.PhtglInvoiceService.GetPHTGL_InvoiceById(ID); if (model != null && !string.IsNullOrEmpty(model.ContractId)) { PhtglInvoiceService.ChangeStateToCreate(model.InvoiceId); ShowNotify("操作成功!", MessageBoxIcon.Success); } else { ShowNotify("请先关联合同!", MessageBoxIcon.Question); } } } }