340 lines
		
	
	
		
			15 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			340 lines
		
	
	
		
			15 KiB
		
	
	
	
		
			C#
		
	
	
	
| using BLL;
 | ||
| using System;
 | ||
| using System.Collections.Generic;
 | ||
| using System.IO;
 | ||
| using System.Linq;
 | ||
| namespace FineUIPro.Web.CQMS.ManageReport
 | ||
| {
 | ||
|     public partial class DesignChangeStatisc : PageBase
 | ||
|     {
 | ||
|         private static List<Model.CheckStatisc> StatisticsList = new List<Model.CheckStatisc>();
 | ||
| 
 | ||
|         protected void Page_Load(object sender, EventArgs e)
 | ||
|         {
 | ||
|             if (!IsPostBack)
 | ||
|             {
 | ||
|                 Model.Base_Project project = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
 | ||
|                 this.txtStartDate.Text = "2015-01-01";
 | ||
|                 this.txtEndDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
 | ||
|                 if (project != null)
 | ||
|                 {
 | ||
|                     if (project.StartDate != null)
 | ||
|                     {
 | ||
|                         this.txtStartDate.Text = string.Format("{0:yyyy-MM-dd}", project.StartDate);
 | ||
|                     }
 | ||
|                 }
 | ||
|                 BindStatisc();
 | ||
|             }
 | ||
|         }
 | ||
|         #region 绑定GridView
 | ||
|         /// <summary>
 | ||
|         /// 绑定
 | ||
|         /// </summary>
 | ||
|         /// <param name="cNProfessionalId"></param>
 | ||
|         public void BindStatisc()
 | ||
|         {
 | ||
|             if (this.ckType.SelectedValue == "1")
 | ||
|             {
 | ||
| 
 | ||
|                 BindUnitStatisc();
 | ||
|             }
 | ||
|             else
 | ||
|             {
 | ||
| 
 | ||
|                 BindCNProfessionalStatisc();
 | ||
|             }
 | ||
| 
 | ||
|         }
 | ||
|         public void BindCNProfessionalStatisc()
 | ||
|         {
 | ||
|             DateTime startDate = Convert.ToDateTime(this.txtStartDate.Text.Trim());
 | ||
|             DateTime endDate = Convert.ToDateTime(this.txtEndDate.Text.Trim());
 | ||
|             DateTime projectStartDate = Convert.ToDateTime("2015-01-01");
 | ||
|             //List<Model.CheckStatisc> StatisticsList = new List<Model.CheckStatisc>();
 | ||
|             StatisticsList = new List<Model.CheckStatisc>();
 | ||
|             Model.Base_Project project = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
 | ||
|             if (project != null)
 | ||
|             {
 | ||
|                 if (project.StartDate != null)
 | ||
|                 {
 | ||
|                     projectStartDate = Convert.ToDateTime(project.StartDate);
 | ||
|                 }
 | ||
|             }
 | ||
|             int i = 1;
 | ||
|             var cNProfessionals = from x in Funs.DB.Base_CNProfessional where x.CNProfessionalId != Const.CNProfessionalConstructId orderby x.SortIndex select x;
 | ||
|             foreach (var item in cNProfessionals)
 | ||
|             {
 | ||
|                 //专业下所有集合
 | ||
|                 List<Model.Comprehensive_DesignChangeOrder> totalManagementList = BLL.DesignChangeOrderService.GetDesignChangeOrderListByCNProfessionalIdAndDate(this.CurrUser.LoginProjectId, item.CNProfessionalId, projectStartDate, endDate);
 | ||
|                 //专业下当期集合
 | ||
|                 List<Model.Comprehensive_DesignChangeOrder> managementList = BLL.DesignChangeOrderService.GetDesignChangeOrderListByCNProfessionalIdAndDate(this.CurrUser.LoginProjectId, item.CNProfessionalId, startDate, endDate);
 | ||
|                 Model.CheckStatisc checkStatisc = new Model.CheckStatisc();
 | ||
|                 checkStatisc.Num = i;
 | ||
|                 checkStatisc.WorkName = item.ProfessionalName;
 | ||
|                 checkStatisc.CheckNum = managementList.Count();
 | ||
|                 checkStatisc.TotalCheckNum = totalManagementList.Count();
 | ||
|                 checkStatisc.OKNum = managementList.Count(x => x.ApprovalDate != null);
 | ||
|                 checkStatisc.TotalOKNum = totalManagementList.Count(x => x.ApprovalDate != null);
 | ||
|                 checkStatisc.OneOKRate = managementList.Count(x => x.Status == "3").ToString();       //当期完成数
 | ||
|                 checkStatisc.TotalOneOKRate = totalManagementList.Count(x => x.Status == "3").ToString();    //累计完成数
 | ||
|                 StatisticsList.Add(checkStatisc);
 | ||
|                 i++;
 | ||
|             }
 | ||
| 
 | ||
|             if (StatisticsList.Count() > 0)   //增加总计
 | ||
|             {
 | ||
|                 Model.CheckStatisc StatisticsLast = new Model.CheckStatisc();
 | ||
|                 StatisticsLast.Num = StatisticsList.Count() + 1;
 | ||
|                 StatisticsLast.WorkName = "合计";
 | ||
|                 foreach (Model.CheckStatisc item in StatisticsList)
 | ||
|                 {
 | ||
|                     StatisticsLast.CheckNum += item.CheckNum;
 | ||
|                     StatisticsLast.TotalCheckNum += item.TotalCheckNum;
 | ||
|                     StatisticsLast.OKNum += item.OKNum;
 | ||
|                     StatisticsLast.TotalOKNum += item.TotalOKNum;
 | ||
|                     StatisticsLast.OneOKRate = (Convert.ToInt32(StatisticsLast.OneOKRate) + Convert.ToInt32(item.OneOKRate)).ToString();
 | ||
|                     StatisticsLast.TotalOneOKRate = (Convert.ToInt32(StatisticsLast.TotalOneOKRate) + Convert.ToInt32(item.TotalOneOKRate)).ToString();
 | ||
|                 }
 | ||
|                 StatisticsList.Add(StatisticsLast);
 | ||
|             }
 | ||
|             this.Grid1.DataSource = StatisticsList;
 | ||
|             this.Grid1.DataBind();
 | ||
|         }
 | ||
|         public void BindUnitStatisc()
 | ||
|         {
 | ||
|             DateTime startDate = Convert.ToDateTime(this.txtStartDate.Text.Trim());
 | ||
|             DateTime endDate = Convert.ToDateTime(this.txtEndDate.Text.Trim());
 | ||
|             DateTime projectStartDate = Convert.ToDateTime("2015-01-01");
 | ||
|             List<Model.CheckStatisc> StatisticsList = new List<Model.CheckStatisc>();
 | ||
|             Model.Base_Project project = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
 | ||
|             if (project != null)
 | ||
|             {
 | ||
|                 if (project.StartDate != null)
 | ||
|                 {
 | ||
|                     projectStartDate = Convert.ToDateTime(project.StartDate);
 | ||
|                 }
 | ||
|             }
 | ||
|             int i = 1;
 | ||
|             var units = BLL.UnitService.GetUnitByProjectIdList(this.CurrUser.LoginProjectId);
 | ||
|             foreach (var item in units)
 | ||
|             {
 | ||
|                 //专业下所有集合
 | ||
|                 List<Model.Comprehensive_DesignChangeOrder> totalManagementList = BLL.DesignChangeOrderService.GetDesignChangeOrderListByUnitIdAndDate(this.CurrUser.LoginProjectId, item.UnitId, projectStartDate, endDate);
 | ||
|                 //专业下当期集合
 | ||
|                 List<Model.Comprehensive_DesignChangeOrder> managementList = BLL.DesignChangeOrderService.GetDesignChangeOrderListByUnitIdAndDate(this.CurrUser.LoginProjectId, item.UnitId, startDate, endDate);
 | ||
|                 Model.CheckStatisc checkStatisc = new Model.CheckStatisc();
 | ||
|                 checkStatisc.Num = i;
 | ||
|                 checkStatisc.WorkName = item.UnitName;
 | ||
|                 checkStatisc.CheckNum = managementList.Count();
 | ||
|                 checkStatisc.TotalCheckNum = totalManagementList.Count();
 | ||
|                 checkStatisc.OKNum = managementList.Count(x => x.ApprovalDate != null);
 | ||
|                 checkStatisc.TotalOKNum = totalManagementList.Count(x => x.ApprovalDate != null);
 | ||
|                 checkStatisc.OneOKRate = managementList.Count(x => x.Status == "3").ToString();       //当期完成数
 | ||
|                 checkStatisc.TotalOneOKRate = totalManagementList.Count(x => x.Status == "3").ToString();    //累计完成数
 | ||
|                 StatisticsList.Add(checkStatisc);
 | ||
|                 i++;
 | ||
|             }
 | ||
| 
 | ||
|             if (StatisticsList.Count() > 0)   //增加总计
 | ||
|             {
 | ||
|                 Model.CheckStatisc StatisticsLast = new Model.CheckStatisc();
 | ||
|                 StatisticsLast.Num = StatisticsList.Count() + 1;
 | ||
|                 StatisticsLast.WorkName = "合计";
 | ||
|                 foreach (Model.CheckStatisc item in StatisticsList)
 | ||
|                 {
 | ||
|                     StatisticsLast.CheckNum += item.CheckNum;
 | ||
|                     StatisticsLast.TotalCheckNum += item.TotalCheckNum;
 | ||
|                     StatisticsLast.OKNum += item.OKNum;
 | ||
|                     StatisticsLast.TotalOKNum += item.TotalOKNum;
 | ||
|                     StatisticsLast.OneOKRate = (Convert.ToInt32(StatisticsLast.OneOKRate) + Convert.ToInt32(item.OneOKRate)).ToString();
 | ||
|                     StatisticsLast.TotalOneOKRate = (Convert.ToInt32(StatisticsLast.TotalOneOKRate) + Convert.ToInt32(item.TotalOneOKRate)).ToString();
 | ||
|                 }
 | ||
|                 StatisticsList.Add(StatisticsLast);
 | ||
|             }
 | ||
|             this.Grid1.DataSource = StatisticsList;
 | ||
|             this.Grid1.DataBind();
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
|         #endregion
 | ||
| 
 | ||
|         protected void ckType_SelectedIndexChanged(object sender, EventArgs e)
 | ||
|         {
 | ||
|             BindStatisc();
 | ||
|         }
 | ||
| 
 | ||
|         protected void btnSearch_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             if (string.IsNullOrEmpty(this.txtStartDate.Text.Trim()) || string.IsNullOrEmpty(this.txtEndDate.Text.Trim()))
 | ||
|             {
 | ||
|                 Alert.ShowInTop("开始和结束日期不能为空!", MessageBoxIcon.Warning);
 | ||
|                 return;
 | ||
|             }
 | ||
|             if (Convert.ToDateTime(this.txtStartDate.Text.Trim()) >= Convert.ToDateTime(this.txtEndDate.Text.Trim()))
 | ||
|             {
 | ||
|                 Alert.ShowInTop("开始日期不能大于结束日期!", MessageBoxIcon.Warning);
 | ||
|                 return;
 | ||
|             }
 | ||
|             BindStatisc();
 | ||
|         }
 | ||
|         
 | ||
|         protected void btnRset_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             drpUnit.SelectedIndex = 0;
 | ||
|             drpCNProfessional.SelectedIndex = 0;
 | ||
|             txtStartDate.Text = "";
 | ||
|             txtEndDate.Text = "";
 | ||
|             ckType.SelectedValue = "2";
 | ||
|             BindStatisc();
 | ||
|         }
 | ||
|         protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
 | ||
|         {
 | ||
|             BindStatisc();
 | ||
|         }
 | ||
|         #region 导出按钮
 | ||
|         /// 导出按钮
 | ||
|         /// </summary>
 | ||
|         /// <param name="sender"></param>
 | ||
|         /// <param name="e"></param>
 | ||
|         protected void btnOut_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             string rootPath = Server.MapPath("~/");
 | ||
|             string initTemplatePath = Const.DesignChangeStatiscTemlUrl;
 | ||
|             string uploadfilepath = string.Empty;
 | ||
|             string newUrl = string.Empty;
 | ||
|             uploadfilepath = rootPath + initTemplatePath;
 | ||
| 
 | ||
|             if (StatisticsList != null)
 | ||
|             {
 | ||
|                 string projectName = BLL.ProjectService.GetShortNameByProjectId(this.CurrUser.LoginProjectId);
 | ||
|                 newUrl = uploadfilepath.Replace("设计变更单统计模板", "设计变更单统计(" + projectName + DateTime.Now.ToString("yyyyMMdd") + ")");
 | ||
|                 if (File.Exists(newUrl))
 | ||
|                 {
 | ||
|                     File.Delete(newUrl);
 | ||
|                 }
 | ||
|                 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);
 | ||
|                     workbook = new NPOI.HSSF.UserModel.HSSFWorkbook(stream);
 | ||
|                 }
 | ||
|                 // 创建单元格样式
 | ||
|                 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 = 11;
 | ||
|                 cellStyle.SetFont(font);
 | ||
|                 // 第二步:创建新数据行
 | ||
|                 NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
 | ||
|                 NPOI.SS.UserModel.IRow row = sheet.GetRow(0);
 | ||
|                 NPOI.SS.UserModel.ICell cell;
 | ||
|                 int i = 3;
 | ||
|                 foreach (var item in StatisticsList)
 | ||
|                 {
 | ||
|                     // 第二步:创建新数据行
 | ||
|                     row = sheet.CreateRow(i);
 | ||
|                     // 添加数据
 | ||
|                     cell = row.CreateCell(0);
 | ||
|                     cell.CellStyle = cellStyle;
 | ||
|                     cell.SetCellValue(item.WorkName);//工作名称
 | ||
| 
 | ||
|                     cell = row.CreateCell(1);
 | ||
|                     cell.CellStyle = cellStyle;
 | ||
|                     cell.SetCellValue(item.CheckNum);
 | ||
| 
 | ||
|                     cell = row.CreateCell(2);
 | ||
|                     cell.CellStyle = cellStyle;
 | ||
|                     cell.SetCellValue(item.TotalCheckNum);
 | ||
| 
 | ||
|                     cell = row.CreateCell(3);
 | ||
|                     cell.CellStyle = cellStyle;
 | ||
|                     cell.SetCellValue(item.OKNum);
 | ||
| 
 | ||
|                     cell = row.CreateCell(4);
 | ||
|                     cell.CellStyle = cellStyle;
 | ||
|                     cell.SetCellValue(item.TotalOKNum);
 | ||
| 
 | ||
|                     cell = row.CreateCell(5);
 | ||
|                     cell.CellStyle = cellStyle;
 | ||
|                     cell.SetCellValue(item.OneOKRate);
 | ||
| 
 | ||
|                     cell = row.CreateCell(6);
 | ||
|                     cell.CellStyle = cellStyle;
 | ||
|                     cell.SetCellValue(item.TotalOneOKRate);
 | ||
| 
 | ||
|                     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);
 | ||
|             }
 | ||
|             else
 | ||
|             {
 | ||
|                 Alert.ShowInTop("当前无记录,无法导出!", MessageBoxIcon.Warning);
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 导出方法
 | ||
|         /// </summary>
 | ||
|         /// <param name="grid"></param>
 | ||
|         /// <returns></returns>
 | ||
|         //private string GetGridTableHtml(Grid grid)
 | ||
|         //{
 | ||
|         //    StringBuilder sb = new StringBuilder();
 | ||
|         //    sb.Append("<meta http-equiv=\"content-type\" content=\"application/excel; charset=UTF-8\"/>");
 | ||
|         //    sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
 | ||
|         //    sb.Append("<tr>");
 | ||
|         //    grid.PageSize = 10000;
 | ||
|         //    BindStatisc();
 | ||
|         //    foreach (GridColumn column in grid.Columns)
 | ||
|         //    {
 | ||
|         //        sb.AppendFormat("<td>{0}</td>", column.HeaderText);
 | ||
|         //    }
 | ||
|         //    sb.Append("</tr>");
 | ||
|         //    foreach (GridRow row in grid.Rows)
 | ||
|         //    {
 | ||
|         //        sb.Append("<tr>");
 | ||
|         //        foreach (GridColumn column in grid.Columns)
 | ||
|         //        {
 | ||
|         //            string html = row.Values[column.ColumnIndex].ToString();
 | ||
|         //            if (column.ColumnID == "tfNumber")
 | ||
|         //            {
 | ||
|         //                html = (row.FindControl("labNumber") as AspNet.Label).Text;
 | ||
|         //            }
 | ||
|         //            sb.AppendFormat("<td>{0}</td>", html);
 | ||
|         //        }
 | ||
| 
 | ||
|         //        sb.Append("</tr>");
 | ||
|         //    }
 | ||
| 
 | ||
|         //    sb.Append("</table>");
 | ||
| 
 | ||
|         //    return sb.ToString();
 | ||
|         //}
 | ||
|         #endregion
 | ||
|     }
 | ||
| } |