346 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			346 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | using System; | |||
|  | using System.Collections.Generic; | |||
|  | using System.Linq; | |||
|  | using System.Data; | |||
|  | using System.Data.SqlClient; | |||
|  | using BLL; | |||
|  | using Newtonsoft.Json.Linq; | |||
|  | using System.IO; | |||
|  | 
 | |||
|  | namespace FineUIPro.Web.JDGL.SGManPower | |||
|  | { | |||
|  |     public partial class ManPowerPlan : PageBase | |||
|  |     { | |||
|  |          | |||
|  |         protected void Page_Load(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (!IsPostBack) | |||
|  |             {  | |||
|  |                 BLL.UnitService.GetUnit(this.drpUnit, this.CurrUser.LoginProjectId, true);//单位 | |||
|  |                 this.txtStartTime.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now.AddDays(-30)); | |||
|  |                 this.txtEndTime.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now.AddDays(30)); | |||
|  |                 DropMainContractCode_SelectedIndexChanged(null, null); | |||
|  |             } | |||
|  |         } | |||
|  |          | |||
|  |          | |||
|  |         protected void DropMainContractCode_SelectedIndexChanged(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (!string.IsNullOrEmpty(drpUnit.SelectedValue)) | |||
|  |             { | |||
|  |                 panelCenterRegion.IFrameUrl = "./ManPowerPlanGrid.aspx?UnitId=" + drpUnit.SelectedValue + | |||
|  |                                               "&StartTime=" + this.txtStartTime.Text + "&EndTime=" + | |||
|  |                                               this.txtEndTime.Text; | |||
|  |             }  | |||
|  |         } | |||
|  |          | |||
|  |         /*protected void Page_Load(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (!IsPostBack) | |||
|  |             { | |||
|  |                 GetButtonPower(); | |||
|  |                 this.txtMonths.Text = string.Format("{0:yyyy-MM}", DateTime.Now); | |||
|  |                 BindGrid(); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         #region 新增 | |||
|  |         /// <summary> | |||
|  |         /// 新增 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void btnNew_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ManPowerPlanEdit.aspx"), "新增 - 施工人力计划")); | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #region 获取按钮权限 | |||
|  |         /// <summary> | |||
|  |         /// 获取按钮权限 | |||
|  |         /// </summary> | |||
|  |         /// <param name="button"></param> | |||
|  |         /// <returns></returns> | |||
|  |         private void GetButtonPower() | |||
|  |         { | |||
|  |             if (Request.Params["value"] == BLL.Const._Null) | |||
|  |             { | |||
|  |                 return; | |||
|  |             } | |||
|  |             var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.SGManPowerMenuId); | |||
|  |             if (buttonList.Count() > 0) | |||
|  |             { | |||
|  |                 if (buttonList.Contains(BLL.Const.BtnSave)) | |||
|  |                 { | |||
|  |                     this.btnNew.Hidden = false; | |||
|  |                 } | |||
|  |                 if (buttonList.Contains(BLL.Const.BtnModify)) | |||
|  |                 { | |||
|  |                     this.btnMenuModify.Hidden = false; | |||
|  |                 } | |||
|  |                 if (buttonList.Contains(BLL.Const.BtnDelete)) | |||
|  |                 { | |||
|  |                     this.btnMenuDel.Hidden = false; | |||
|  |                 } | |||
|  |             } | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         protected void btnMenuModify_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             EditData(); | |||
|  |         } | |||
|  |         /// <summary> | |||
|  |         /// 编辑数据方法 | |||
|  |         /// </summary> | |||
|  |         private void EditData() | |||
|  |         { | |||
|  |             if (Grid1.SelectedRowIndexArray.Length == 0) | |||
|  |             { | |||
|  |                 Alert.ShowInTop("请至少选择一条记录", MessageBoxIcon.Warning); | |||
|  |                 return; | |||
|  |             } | |||
|  |             PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ManPowerPlanEdit.aspx?Id={0}", Grid1.SelectedRowID), "编辑 - 月度计划")); | |||
|  |         } | |||
|  |          | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 加载Grid | |||
|  |         /// </summary> | |||
|  |         private void BindGrid() | |||
|  |         { | |||
|  |             DataTable tb = BindData(); | |||
|  |             Grid1.RecordCount = tb.Rows.Count; | |||
|  |             var table = this.GetPagedDataTable(Grid1, tb); | |||
|  |             Grid1.DataSource = table; | |||
|  |             Grid1.DataBind(); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 加载数据 | |||
|  |         /// </summary> | |||
|  |         /// <returns></returns> | |||
|  |         private DataTable BindData() | |||
|  |         { | |||
|  |             string strSql = @"
 | |||
|  | select mp.Id,mp.ProjectId,u.UnitName,uw.UnitWorkName,wp.WorkPostName,mp.Version,mp.Quantity,mp.PlanDate,su.UserName as CompileMan,mp.CompileTime,mp.Remarks from  JDGL_SGManPower mp | |||
|  | left join Base_Unit u on u.UnitId = mp.UnitId | |||
|  | left join WBS_UnitWork uw on uw.UnitWorkId = mp.UnitWorkId | |||
|  | left join Base_WorkPost wp on wp.WorkPostId = mp.WorkPostId | |||
|  | left join Sys_User su on su.UserId = mp.CompileMan | |||
|  | where mp.ProjectId=@ProjectId  order by mp.CompileTime";
 | |||
|  |             List<SqlParameter> listStr = new List<SqlParameter>(); | |||
|  |             listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId)); | |||
|  |             SqlParameter[] parameter = listStr.ToArray(); | |||
|  |             DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); | |||
|  |             return tb; | |||
|  |         } | |||
|  |         #region  月份选择事件 | |||
|  |         /// <summary> | |||
|  |         /// 月份选择事件 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void txtMonths_TextChanged(object sender, EventArgs e) | |||
|  |         { | |||
|  |             BindGrid(); | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #region  保存按钮 | |||
|  |         /// <summary> | |||
|  |         /// 保存按钮 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void btnSave_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (this.Grid1.Rows.Count > 0) | |||
|  |             { | |||
|  |                 JArray mergedData = Grid1.GetMergedData(); | |||
|  |                 foreach (JObject mergedRow in mergedData) | |||
|  |                 { | |||
|  |                     JObject values = mergedRow.Value<JObject>("values"); | |||
|  |                     int i = mergedRow.Value<int>("index"); | |||
|  |                     Model.JDGL_MonthPlan MonthPlan = BLL.MonthPlanService.GetMonthPlanById(this.Grid1.Rows[i].RowID); | |||
|  |                     if (MonthPlan != null) | |||
|  |                     { | |||
|  |                         MonthPlan.CompileMan = this.CurrUser.UserId; | |||
|  |                         MonthPlan.CompileDate = DateTime.Now; | |||
|  |                         BLL.MonthPlanService.UpdateMonthPlan(MonthPlan); | |||
|  |                     } | |||
|  |                 } | |||
|  |                 Alert.ShowInTop("保存成功!", MessageBoxIcon.Success); | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); | |||
|  |                 return; | |||
|  |             } | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         protected void btnMenuDel_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (Grid1.SelectedRowIndexArray.Length > 0) | |||
|  |             { | |||
|  |                 foreach (int rowIndex in Grid1.SelectedRowIndexArray) | |||
|  |                 { | |||
|  |                     string rowID = Grid1.DataKeys[rowIndex][0].ToString(); | |||
|  |                     BLL.ManPowerPlanService.DeleteSGManPowerById(rowID); | |||
|  |                 } | |||
|  |                 BindGrid(); | |||
|  |                 ShowNotify("删除数据成功!", MessageBoxIcon.Success); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         #region 导入 | |||
|  |         /// <summary> | |||
|  |         /// 导入按钮 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void btnImport_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ManPowerPlanIn.aspx?ProjectId={0}", this.CurrUser.LoginProjectId), "导入 - 施工人力计划")); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 关闭导入弹出窗口 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void Window1_Close(object sender, WindowCloseEventArgs e) | |||
|  |         { | |||
|  |             BindGrid(); | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #region 统计 | |||
|  |         /// <summary> | |||
|  |         /// 统计分析 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void BtnAnalyse_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("MonthPlanStatisc.aspx"), "统计 - 月度计划")); | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #region 导出按钮 | |||
|  |         /// 导出按钮 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param>  | |||
|  |         protected void btnOut_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (Grid1.Rows.Count == 0) | |||
|  |             { | |||
|  |                 ShowNotify("无数据可导出!", MessageBoxIcon.Warning); | |||
|  |                 return; | |||
|  |             } | |||
|  |             string rootPath = Server.MapPath("~/"); | |||
|  |             string initTemplatePath = string.Empty; | |||
|  |             string uploadfilepath = string.Empty; | |||
|  |             string newUrl = string.Empty; | |||
|  |             string filePath = string.Empty; | |||
|  |             initTemplatePath = Const.MonthPlanOutTemplateUrl; | |||
|  |             uploadfilepath = rootPath + initTemplatePath; | |||
|  |             newUrl = uploadfilepath.Replace(".xlsx", "(" + this.txtMonths.Text.Trim() + ").xlsx"); | |||
|  |             File.Copy(uploadfilepath, newUrl); | |||
|  |             // 第一步:读取文件流 | |||
|  |             NPOI.SS.UserModel.IWorkbook workbook; | |||
|  |             using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read)) | |||
|  |             { | |||
|  |                 workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(stream); | |||
|  |             } | |||
|  |             Model.SGGLDB db = Funs.DB; | |||
|  |             DataTable tb = BindData(); | |||
|  |             // 创建单元格样式 | |||
|  |             NPOI.SS.UserModel.ICellStyle cellStyle = workbook.CreateCellStyle(); | |||
|  |             cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; | |||
|  |             cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; | |||
|  |             cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; | |||
|  |             cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; | |||
|  |             cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; | |||
|  |             cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center; | |||
|  |             cellStyle.WrapText = true; | |||
|  |             var font = workbook.CreateFont(); | |||
|  |             font.FontHeightInPoints = 10; | |||
|  |             //font.FontHeightInPoints = (short)8.5;字号为小数时要转为short | |||
|  |             cellStyle.SetFont(font); | |||
|  |             // 第二步:创建新数据行 | |||
|  |             NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0); | |||
|  |             NPOI.SS.UserModel.IRow row = null; | |||
|  |             NPOI.SS.UserModel.ICell cell; | |||
|  |             int i = 1; | |||
|  |             for (int j = 0; j < tb.Rows.Count; j++) | |||
|  |             { | |||
|  |                 // 第二步:创建新数据行 | |||
|  |                 row = sheet.CreateRow(i); | |||
|  |                 // 添加数据 | |||
|  |                 cell = row.CreateCell(0); | |||
|  |                 cell.CellStyle = cellStyle; | |||
|  |                 cell.SetCellValue(i.ToString()); | |||
|  |                 cell = row.CreateCell(1); | |||
|  |                 cell.CellStyle = cellStyle; | |||
|  |                 //string unitName = string.Empty; | |||
|  |                 //var unit = units.FirstOrDefault(x => x.UnitId == item.UnitId); | |||
|  |                 //if (unit != null) | |||
|  |                 //{ | |||
|  |                 //    unitName = unit.UnitName; | |||
|  |                 //} | |||
|  |                 cell.SetCellValue(tb.Rows[j]["UnitName"].ToString()); | |||
|  |                 cell = row.CreateCell(2); | |||
|  |                 cell.CellStyle = cellStyle; | |||
|  |                 cell.SetCellValue(tb.Rows[j]["NodeContent"].ToString()); | |||
|  |                 cell = row.CreateCell(3); | |||
|  |                 cell.CellStyle = cellStyle; | |||
|  |                 string planDate = string.Empty; | |||
|  |                 if (tb.Rows[j]["PlanDate"] != DBNull.Value) | |||
|  |                 { | |||
|  |                     planDate = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(tb.Rows[j]["PlanDate"].ToString())); | |||
|  |                 } | |||
|  |                 cell.SetCellValue(planDate); | |||
|  |                 cell = row.CreateCell(4); | |||
|  |                 cell.CellStyle = cellStyle; | |||
|  |                 cell.SetCellValue(tb.Rows[j]["DutyPersonName"].ToString()); | |||
|  |                 cell = row.CreateCell(5); | |||
|  |                 cell.CellStyle = cellStyle; | |||
|  |                 string realDate = string.Empty; | |||
|  |                 if (tb.Rows[j]["RealDate"] != DBNull.Value) | |||
|  |                 { | |||
|  |                     realDate = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(tb.Rows[j]["RealDate"].ToString())); | |||
|  |                 } | |||
|  |                 cell.SetCellValue(realDate); | |||
|  |                 cell = row.CreateCell(6); | |||
|  |                 cell.CellStyle = cellStyle; | |||
|  |                 cell.SetCellValue(tb.Rows[j]["IsOKStr"].ToString()); | |||
|  |                 cell = row.CreateCell(7); | |||
|  |                 cell.CellStyle = cellStyle; | |||
|  |                 cell.SetCellValue(tb.Rows[j]["Remark"].ToString()); | |||
|  |                 i++; | |||
|  |             } | |||
|  |             // 第三步:写入文件流 | |||
|  |             using (FileStream stream = new FileStream(newUrl, FileMode.Create, FileAccess.Write)) | |||
|  |             { | |||
|  |                 workbook.Write(stream); | |||
|  |                 workbook.Close(); | |||
|  |             } | |||
|  |             string fileName = Path.GetFileName(newUrl); | |||
|  |             FileInfo info = new FileInfo(newUrl); | |||
|  |             long fileSize = info.Length; | |||
|  |             Response.Clear(); | |||
|  |             Response.ContentType = "application/x-zip-compressed"; | |||
|  |             Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); | |||
|  |             Response.AddHeader("Content-Length", fileSize.ToString()); | |||
|  |             Response.TransmitFile(newUrl, 0, fileSize); | |||
|  |             Response.Flush(); | |||
|  |             Response.Close(); | |||
|  |             File.Delete(newUrl); | |||
|  |         } | |||
|  |         #endregion*/ | |||
|  |     } | |||
|  | } |