using BLL; using MiniExcelLibs; using Model; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace FineUIPro.Web.CLGL { public partial class InputMaster : PageBase { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.GetButtonPower(); InitDrpList(); // 绑定表格 this.BindGrid(); } } #region 绑定数据 private void InitDrpList() { this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString(); drpWarehouse.DataTextField = "Text"; drpWarehouse.DataValueField = "Value"; drpWarehouse.DataSource = BLL.DropListService.HJGL_WarehouseCode(); drpWarehouse.DataBind(); Funs.FineUIPleaseSelect(this.drpWarehouse); drpTypeInt.DataTextField = "Key"; drpTypeInt.DataValueField = "Value"; drpTypeInt.DataSource = BLL.TwConst.TypeIntMap.Where(x => x.Key.Contains("入库")); drpTypeInt.DataBind(); Funs.FineUIPleaseSelect(this.drpTypeInt); } /// /// 绑定数据 /// private void BindGrid() { Model.Tw_InOutMasterOutput table = new Model.Tw_InOutMasterOutput(); table.ProjectId = this.CurrUser.LoginProjectId; if (drpTypeInt.SelectedValue != Const._Null) { table.TypeInt = Convert.ToInt32(drpTypeInt.SelectedValue); } if (drpWarehouse.SelectedValue != Const._Null) { table.WarehouseCode = drpWarehouse.SelectedValue; } var tb = BLL.TwInputmasterService.GetListData(table, Grid1); Grid1.RecordCount = TwInputmasterService.Count; Grid1.DataSource = tb; Grid1.DataBind(); Grid2.DataSource = null; Grid2.DataBind(); } private void BindDetailGrid(string inputMasterId) { Model.Tw_InOutDetailOutput table = new Model.Tw_InOutDetailOutput(); table.InputMasterId = inputMasterId; var tb = BLL.TwInputdetailService.GetListData(table, Grid2); Grid2.DataSource = tb; Grid2.DataBind(); for (int i = 0; i < Grid2.Rows.Count; i++) { var model = Grid2.Rows[i].DataItem as Model.Tw_InOutDetailOutput; if (model.ActNum != model.PlanNum) { Grid2.Rows[i].RowCssClass = "red"; } } } #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 Grid1_RowClick(object sender, GridRowClickEventArgs e) { if (e.RowIndex >= 0) { string ID = Grid1.DataKeys[e.RowIndex][0].ToString(); BindDetailGrid(ID); } } /// /// 分页显示条数下拉框 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { this.Grid1.PageSize = Convert.ToInt32(this.ddlPageSize.SelectedValue); this.BindGrid(); } #endregion #region 数据编辑事件 protected void btnSearch_Click(object sender, EventArgs e) { BindGrid(); } /// /// 编辑按钮 /// /// /// 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.TwInputmasterService.GetById(ID); if (model != null) ///已上报时不能删除 { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("InPlanMasterEdit.aspx?Id={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.TwInputmasterService.GetById(rowID); if (model != null) { BLL.TwInputmasterService.DeleteById(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.Tw_InputMasterMenuId); if (buttonList.Count > 0) { if (buttonList.Contains(BLL.Const.BtnAdd)) { } if (buttonList.Contains(BLL.Const.BtnModify)) { this.btnMenuEdit.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnDelete)) { //this.btnMenuDelete.Hidden = false; } } } #endregion #region 导出按钮 /// 导出按钮 /// /// /// protected void btnOut_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIDArray.Length>0) { var printModel= TwInputdetailService.GePrintListByInputMasterIds(Grid1.SelectedRowIDArray.ToList()); string path = Funs.RootPath + @"File\Excel\Temp\InputDetail.xlsx"; path = path.Replace(".xlsx", string.Format("{0:yyyy-MM-dd-HH-mm}", DateTime.Now) + ".xlsx"); MiniExcel.SaveAs(path, printModel); string fileName = "入库明细表.xlsx"; FileInfo info = new FileInfo(path); long fileSize = info.Length; System.Web.HttpContext.Current.Response.Clear(); System.Web.HttpContext.Current.Response.ContentType = "application/x-zip-compressed"; System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); System.Web.HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString()); System.Web.HttpContext.Current.Response.TransmitFile(path, 0, fileSize); System.Web.HttpContext.Current.Response.Flush(); System.Web.HttpContext.Current.Response.Close(); File.Delete(path); } } /// /// 导出方法 /// /// /// 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 Grid1_RowCommand(object sender, GridCommandEventArgs e) { if (e.CommandName == "btnInPlanMasterPrint") { Print(e.RowID); } } private void Print(string Id) { BLL.FastReportService.ResetData(); if (string.IsNullOrEmpty(Id)) { ShowNotify("请选择要打印的项", MessageBoxIcon.Warning); return; } Tw_InOutMasterOutput queryModel = new Tw_InOutMasterOutput() { Id = Id }; var result = TwInputmasterService.GetListData(queryModel).FirstOrDefault(); List tw_PrintMasters = new List(); List tw_PrintDetails = new List(); Model.Tw_PrintMaster printMaster = new Model.Tw_PrintMaster { ReqUnitName = result.ReqUnitName, CusBillCode = result.CusBillCode, CreateDate = result.CreateDate.Value.ToString("yyyy-MM-dd"), ProjectName = ProjectService.GetProjectNameByProjectId(result.ProjectId), CategoryString = result.CategoryString, BillName = TwConst.PrintMap.Where(x => x.Value == result.TypeInt).Select(x => x.Key).FirstOrDefault(), AuditManName = !string.IsNullOrEmpty(result.AuditMan) ? BLL.Person_PersonsService.getSignatureUrl(result.AuditMan) : "", AuditDate = string.Format("{0:yyyy-MM-dd}", result.AuditDate), AuditManName2 = !string.IsNullOrEmpty(result.AuditMan2) ? BLL.Person_PersonsService.getSignatureUrl(result.AuditMan2) : "", AuditDate2 = string.Format("{0:yyyy-MM-dd}", result.AuditDate2), WarehouseManName = !string.IsNullOrEmpty(result.WarehouseMan) ? BLL.Person_PersonsService.getSignatureUrl(result.WarehouseMan) : "", WarehouseManAuditDate = string.Format("{0:yyyy-MM-dd}", result.WarehouseDate), }; tw_PrintMasters.Add(printMaster); DataTable Table1 = LINQToDataTable(tw_PrintMasters); if (Table1 != null) { Table1.TableName = "Table1"; } Tw_InOutPlanDetail_Relation queryModel2 = new Tw_InOutPlanDetail_Relation() { InOutPlanMasterId = Id }; var ListDetailRelation = TwInoutplandetailRelationService.GetTw_InOutPlanDetail_RelationByModle(queryModel2).ToList(); int SortIndex = 1; int SortIndex2 = 1; var tw_PrintDetailRelation = (from x in ListDetailRelation join y in Funs.DB.HJGL_MaterialCodeLib on x.MaterialCode equals y.MaterialCode join z in Funs.DB.HJGL_Pipeline on x.PipelineId equals z.PipelineId join m in Funs.DB.WBS_UnitWork on z.UnitWorkId equals m.UnitWorkId select new Model.Tw_PrintDetail { SortIndex = SortIndex++, PipelineCode = z.PipelineCode, PipelineComponentCode = x.PrefabricatedComponents, MaterialCode = y.MaterialCode, MaterialDef = y.MaterialDef, MaterialSpec = y.MaterialSpec, MaterialUnit = y.MaterialUnit, PlanNum = (x.Number ?? 0).ToString(), UnitWorkName = m.UnitWorkName, }).ToList(); var UnitWorkName = tw_PrintDetailRelation.FirstOrDefault()?.UnitWorkName; Tw_PrintDetail tw_PrintDetailRelation2 = new Tw_PrintDetail { MaterialDef = "材料编码合计" }; var tw_PrintDetail = (from x in Funs.DB.Tw_InputDetail join y in Funs.DB.HJGL_MaterialCodeLib on x.MaterialCode equals y.MaterialCode where x.InputMasterId == Id select new Model.Tw_PrintDetail { SortIndex = 0, PipelineCode = "-", PipelineComponentCode = "-", MaterialCode = y.MaterialCode, MaterialDef = y.MaterialDef, MaterialSpec = y.MaterialSpec, MaterialUnit = y.MaterialUnit, PlanNum = (x.PlanNum ?? 0).ToString(), ActNum = (x.ActNum ?? 0).ToString(), UnitWorkName = UnitWorkName, }).ToList(); foreach (var item in tw_PrintDetail) { item.SortIndex = SortIndex2++; } tw_PrintDetails.AddRange(tw_PrintDetailRelation); tw_PrintDetails.Add(tw_PrintDetailRelation2); tw_PrintDetails.AddRange(tw_PrintDetail); DataTable Data = LINQToDataTable(tw_PrintDetails); if (Data != null) { Data.TableName = "Data"; } BLL.FastReportService.ResetData(); BLL.FastReportService.AddFastreportTable(Table1); BLL.FastReportService.AddFastreportTable(Data); string initTemplatePath = ""; string rootPath = Server.MapPath("~/"); initTemplatePath = "File\\Fastreport\\材料入库单.frx"; if (File.Exists(rootPath + initTemplatePath)) { PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("~/Controls/Fastreport.aspx?ReportPath={0}", rootPath + initTemplatePath))); } } } }