289 lines
		
	
	
		
			18 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			289 lines
		
	
	
		
			18 KiB
		
	
	
	
		
			C#
		
	
	
	
| using BLL;
 | |
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Linq;
 | |
| using System.Text;
 | |
| using System.Web;
 | |
| using System.Web.UI;
 | |
| using System.Web.UI.WebControls;
 | |
| 
 | |
| namespace FineUIPro.Web.DataShowLocal
 | |
| {
 | |
|     public partial class InspectionManagementStatiscItem : PageBase
 | |
|     {
 | |
|         public DateTime StartDate;
 | |
|         public DateTime NextDate;
 | |
|         public DateTime NewDate;
 | |
|         public DateTime EndDate;
 | |
| 
 | |
|         public int SunNumber;
 | |
|         protected void Page_Load(object sender, EventArgs e)
 | |
|         {
 | |
|             if (!IsPostBack)
 | |
|             {
 | |
|                 BLL.CNProfessionalService.InitCNProfessionalDownList(this.drpCNProfessional, true);//专业
 | |
|                 BindGvInspectionManagement(null);
 | |
|             }
 | |
|         }
 | |
|         #region 绑定GridView
 | |
|         /// <summary>
 | |
|         /// 绑定
 | |
|         /// </summary>
 | |
|         /// <param name="cNProfessionalId"></param>
 | |
|         public void BindGvInspectionManagement(string cNProfessionalId)
 | |
|         {
 | |
|             if (string.IsNullOrEmpty(this.txtStartTime.Text.Trim()) && string.IsNullOrEmpty(this.txtEndTime.Text.Trim()))   //未选择日期,统计项目开始起的每月数据
 | |
|             {
 | |
|                 List<Model.InspectionManagementStatistics> StatisticsList = new List<Model.InspectionManagementStatistics>();
 | |
|                 Model.Base_Project project = BLL.ProjectService.GetProjectByProjectId(Request.Params["projectId"]);
 | |
|                 StartDate = Convert.ToDateTime(project.StartDate);
 | |
|                 for (int i = 0; i < i + 1; i++)
 | |
|                 {
 | |
|                     Model.InspectionManagementStatistics Statistics = new Model.InspectionManagementStatistics();
 | |
|                     if (i == 0)
 | |
|                     {
 | |
|                         NextDate = Convert.ToDateTime(DateTime.Parse(StartDate.ToString("yyyy-MM-dd")).AddMonths(1).ToShortDateString());
 | |
|                         NewDate = Convert.ToDateTime(NextDate.Year + "-" + NextDate.Month + "-25");
 | |
|                         Statistics.CheckDate = string.Format("{0:yyyy-MM-dd}", StartDate) + " 至 ";
 | |
|                         if (StartDate.Day < 25)
 | |
|                         {
 | |
|                             if (DateTime.Now < NewDate)
 | |
|                             {
 | |
|                                 //统计所给时间段的全部数量
 | |
|                                 List<Model.View_CQMS_InspectionManagementDetail> managementListSunNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(Request.Params["projectId"], cNProfessionalId, StartDate, DateTime.Now, false);
 | |
|                                 //统计所给时间段的合格数量
 | |
|                                 List<Model.View_CQMS_InspectionManagementDetail> managementListOneNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(Request.Params["projectId"], cNProfessionalId, StartDate, DateTime.Now, true);
 | |
| 
 | |
|                                 Statistics.CheckDate += string.Format("{0:yyyy-MM-dd}", DateTime.Now);
 | |
|                                 Statistics.SunNumber = managementListSunNumber.Count();
 | |
|                                 Statistics.OneStatisticsSunNumber = managementListOneNumber.Count();
 | |
|                                 if (managementListSunNumber.Count() != 0)//被除数不能为零
 | |
|                                 {
 | |
|                                     Statistics.OneStatistics = Math.Round((double)managementListOneNumber.Count() / (double)managementListSunNumber.Count() * 100, 2) + "%";//保留两位小数、后四舍五入
 | |
|                                 }
 | |
|                                 else
 | |
|                                 {
 | |
|                                     Statistics.OneStatistics = "0%";
 | |
|                                 }
 | |
|                                 StatisticsList.Add(Statistics);
 | |
|                                 break;
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 NextDate = Convert.ToDateTime(StartDate.Year + "-" + StartDate.Month + "-25");
 | |
|                                 //统计所给事件段的全部数量
 | |
|                                 List<Model.View_CQMS_InspectionManagementDetail> managementListSunNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(Request.Params["projectId"], cNProfessionalId, StartDate, NextDate, false);
 | |
|                                 //统计所给事件段的合格数量
 | |
|                                 List<Model.View_CQMS_InspectionManagementDetail> managementListOneNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(Request.Params["projectId"], cNProfessionalId, StartDate, NextDate, true);
 | |
| 
 | |
|                                 Statistics.CheckDate += string.Format("{0:yyyy-MM-dd}", NextDate);
 | |
|                                 Statistics.SunNumber = managementListSunNumber.Count();
 | |
|                                 Statistics.OneStatisticsSunNumber = managementListOneNumber.Count();
 | |
|                                 if (managementListSunNumber.Count() != 0)//被除数不能为零
 | |
|                                 {
 | |
|                                     Statistics.OneStatistics = Math.Round((double)managementListOneNumber.Count() / (double)managementListSunNumber.Count() * 100, 2) + "%";//保留两位小数、后四舍五入
 | |
|                                 }
 | |
|                                 else
 | |
|                                 {
 | |
|                                     Statistics.OneStatistics = "0%";
 | |
|                                 }
 | |
|                             }
 | |
|                         }
 | |
|                         else
 | |
|                         {
 | |
|                             if (DateTime.Now < NewDate)
 | |
|                             {
 | |
|                                 //统计所给事件段的全部数量
 | |
|                                 List<Model.View_CQMS_InspectionManagementDetail> managementListSunNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(Request.Params["projectId"], cNProfessionalId, StartDate, DateTime.Now, false);
 | |
|                                 //统计所给事件段的合格数量
 | |
|                                 List<Model.View_CQMS_InspectionManagementDetail> managementListOneNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(Request.Params["projectId"], cNProfessionalId, StartDate, DateTime.Now, true);
 | |
| 
 | |
|                                 Statistics.CheckDate += string.Format("{0:yyyy-MM-dd}", DateTime.Now);
 | |
|                                 Statistics.SunNumber = managementListSunNumber.Count();
 | |
|                                 Statistics.OneStatisticsSunNumber = managementListOneNumber.Count();
 | |
|                                 if (managementListSunNumber.Count() != 0)//被除数不能为零
 | |
|                                 {
 | |
|                                     Statistics.OneStatistics = Math.Round((double)managementListOneNumber.Count() / (double)managementListSunNumber.Count() * 100, 2) + "%";//保留两位小数、后四舍五入
 | |
|                                 }
 | |
|                                 else
 | |
|                                 {
 | |
|                                     Statistics.OneStatistics = "0%";
 | |
|                                 }
 | |
| 
 | |
|                                 StatisticsList.Add(Statistics);
 | |
|                                 break;
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 //统计所给事件段的全部数量
 | |
|                                 List<Model.View_CQMS_InspectionManagementDetail> managementListSunNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(Request.Params["projectId"], cNProfessionalId, StartDate, NewDate, false);
 | |
|                                 //统计所给事件段的合格数量
 | |
|                                 List<Model.View_CQMS_InspectionManagementDetail> managementListOneNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(Request.Params["projectId"], cNProfessionalId, StartDate, NewDate, true);
 | |
|                                 Statistics.CheckDate += string.Format("{0:yyyy-MM-dd}", NewDate);
 | |
|                                 Statistics.SunNumber = managementListSunNumber.Count();
 | |
|                                 Statistics.OneStatisticsSunNumber = managementListOneNumber.Count();
 | |
|                                 if (managementListSunNumber.Count() != 0)//被除数不能为零
 | |
|                                 {
 | |
|                                     Statistics.OneStatistics = Math.Round((double)managementListOneNumber.Count() / (double)managementListSunNumber.Count() * 100, 2) + "%";//保留两位小数、后四舍五入
 | |
|                                 }
 | |
|                                 else
 | |
|                                 {
 | |
|                                     Statistics.OneStatistics = "0%";
 | |
|                                 }
 | |
|                             }
 | |
|                         }
 | |
|                     }
 | |
|                     else
 | |
|                     {
 | |
| 
 | |
|                         if (StartDate.Day > 25)
 | |
|                         {
 | |
|                             Statistics.CheckDate = NewDate.Year + "-" + NewDate.Month + "-" + (NewDate.Day + 1) + " 至 ";
 | |
|                             StartDate = Convert.ToDateTime(NewDate.Year + "-" + NewDate.Month + "-" + (NewDate.Day + 1));//获取上一记录的结束日期加一天为本次记录的开始日期
 | |
|                         }
 | |
|                         else
 | |
|                         {
 | |
|                             Statistics.CheckDate = NextDate.Year + "-" + NextDate.Month + "-" + (NextDate.Day + 1) + " 至 ";
 | |
|                             StartDate = Convert.ToDateTime(NextDate.Year + "-" + NextDate.Month + "-" + (NextDate.Day + 1));//获取上一记录的结束日期加一天为本次记录的开始日期
 | |
|                         }
 | |
| 
 | |
|                         NextDate = Convert.ToDateTime(DateTime.Parse(NextDate.ToString("yyyy-MM-dd")).AddMonths(1).ToShortDateString());
 | |
|                         NewDate = Convert.ToDateTime(NextDate.Year + "-" + NextDate.Month + "-25");
 | |
|                         if (DateTime.Now < NewDate)
 | |
|                         {
 | |
|                             //统计所给事件段的全部数量
 | |
|                             List<Model.View_CQMS_InspectionManagementDetail> managementListSunNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(Request.Params["projectId"], cNProfessionalId, StartDate, DateTime.Now, false);
 | |
|                             //统计所给事件段的合格数量
 | |
|                             List<Model.View_CQMS_InspectionManagementDetail> managementListOneNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(Request.Params["projectId"], cNProfessionalId, StartDate, DateTime.Now, true);
 | |
| 
 | |
|                             Statistics.CheckDate += string.Format("{0:yyyy-MM-dd}", DateTime.Now);
 | |
|                             Statistics.SunNumber = managementListSunNumber.Count();
 | |
|                             Statistics.OneStatisticsSunNumber = managementListOneNumber.Count();
 | |
|                             if (managementListSunNumber.Count() != 0)//被除数不能为零
 | |
|                             {
 | |
|                                 Statistics.OneStatistics = Math.Round((double)managementListOneNumber.Count() / (double)managementListSunNumber.Count() * 100, 2) + "%";//保留两位小数、后四舍五入
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 Statistics.OneStatistics = "0%";
 | |
|                             }
 | |
| 
 | |
|                             StatisticsList.Add(Statistics);
 | |
|                             break;
 | |
|                         }
 | |
|                         else
 | |
|                         {
 | |
|                             //统计所给事件段的全部数量
 | |
|                             List<Model.View_CQMS_InspectionManagementDetail> managementListSunNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(Request.Params["projectId"], cNProfessionalId, StartDate, NewDate, false);
 | |
|                             //统计所给事件段的合格数量
 | |
|                             List<Model.View_CQMS_InspectionManagementDetail> managementListOneNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(Request.Params["projectId"], cNProfessionalId, StartDate, NewDate, true);
 | |
|                             Statistics.CheckDate += string.Format("{0:yyyy-MM-dd}", NewDate);
 | |
|                             Statistics.SunNumber = managementListSunNumber.Count();
 | |
|                             Statistics.OneStatisticsSunNumber = managementListOneNumber.Count();
 | |
|                             if (managementListSunNumber.Count() != 0)//被除数不能为零
 | |
|                             {
 | |
|                                 Statistics.OneStatistics = Math.Round((double)managementListOneNumber.Count() / (double)managementListSunNumber.Count() * 100, 2) + "%";//保留两位小数、后四舍五入
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 Statistics.OneStatistics = "0%";
 | |
|                             }
 | |
|                         }
 | |
|                     }
 | |
|                     StatisticsList.Add(Statistics);
 | |
|                 }
 | |
|                 Model.InspectionManagementStatistics StatisticsLast = new Model.InspectionManagementStatistics();
 | |
|                 StatisticsLast.CheckDate = "合计";
 | |
|                 int sum1 = 0;
 | |
|                 int sum2 = 0;
 | |
|                 foreach (Model.InspectionManagementStatistics item in StatisticsList)
 | |
|                 {
 | |
|                     sum1 += item.OneStatisticsSunNumber;
 | |
|                     sum2 += item.SunNumber;
 | |
| 
 | |
|                 }
 | |
|                 StatisticsLast.OneStatisticsSunNumber = sum1;
 | |
|                 StatisticsLast.SunNumber = sum2;
 | |
|                 if (sum2 != 0)//被除数不能为零
 | |
|                 {
 | |
|                     StatisticsLast.OneStatistics = Math.Round((double)sum1 / (double)sum2 * 100, 2) + "%";//保留两位小数、后四舍五入
 | |
|                 }
 | |
|                 else
 | |
|                 {
 | |
|                     StatisticsLast.OneStatistics = "0%";
 | |
|                 }
 | |
|                 StatisticsList.Add(StatisticsLast);
 | |
|                 this.Grid1.DataSource = StatisticsList;
 | |
|                 this.Grid1.DataBind();
 | |
|             }
 | |
|             else      //选择日期,统计对应时间段内的数据
 | |
|             {
 | |
|                 List<Model.InspectionManagementStatistics> StatisticsList = new List<Model.InspectionManagementStatistics>();
 | |
|                 Model.Base_Project project = BLL.ProjectService.GetProjectByProjectId(Request.Params["projectId"]);
 | |
|                 StartDate = Convert.ToDateTime(project.StartDate);
 | |
|                 EndDate = DateTime.Now;
 | |
|                 if (!string.IsNullOrEmpty(this.txtStartTime.Text.Trim()))
 | |
|                 {
 | |
|                     StartDate = Convert.ToDateTime(this.txtStartTime.Text.Trim());
 | |
|                 }
 | |
|                 if (!string.IsNullOrEmpty(this.txtEndTime.Text.Trim()))
 | |
|                 {
 | |
|                     EndDate = Convert.ToDateTime(this.txtEndTime.Text.Trim());
 | |
|                 }
 | |
|                 Model.InspectionManagementStatistics Statistics = new Model.InspectionManagementStatistics();
 | |
|                 //统计所给时间段的全部数量
 | |
|                 List<Model.View_CQMS_InspectionManagementDetail> managementListSunNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(Request.Params["projectId"], cNProfessionalId, StartDate, EndDate, false);
 | |
|                 //统计所给时间段的合格数量
 | |
|                 List<Model.View_CQMS_InspectionManagementDetail> managementListOneNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(Request.Params["projectId"], cNProfessionalId, StartDate, EndDate, true);
 | |
|                 Statistics.CheckDate = string.Format("{0:yyyy-MM-dd}", StartDate) + " 至 " + string.Format("{0:yyyy-MM-dd}", EndDate);
 | |
|                 Statistics.SunNumber = managementListSunNumber.Count();
 | |
|                 Statistics.OneStatisticsSunNumber = managementListOneNumber.Count();
 | |
|                 if (managementListSunNumber.Count() != 0)//被除数不能为零
 | |
|                 {
 | |
|                     Statistics.OneStatistics = Math.Round((double)managementListOneNumber.Count() / (double)managementListSunNumber.Count() * 100, 2) + "%";//保留两位小数、后四舍五入
 | |
|                 }
 | |
|                 else
 | |
|                 {
 | |
|                     Statistics.OneStatistics = "0%";
 | |
|                 }
 | |
|                 StatisticsList.Add(Statistics);
 | |
|                 this.Grid1.DataSource = StatisticsList;
 | |
|                 this.Grid1.DataBind();
 | |
|             }
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         protected void btnSearch_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             if (this.drpCNProfessional.SelectedValue != BLL.Const._Null)
 | |
|             {
 | |
|                 BindGvInspectionManagement(this.drpCNProfessional.SelectedValue);
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 BindGvInspectionManagement(null);
 | |
|             }
 | |
|         }
 | |
| 
 | |
| 
 | |
|         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 = Encoding.UTF8;
 | |
|             this.Grid1.PageSize = Grid1.RecordCount;
 | |
|             if (this.drpCNProfessional.SelectedValue != BLL.Const._Null)
 | |
|             {
 | |
|                 BindGvInspectionManagement(this.drpCNProfessional.SelectedValue);
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 BindGvInspectionManagement(null);
 | |
|             }
 | |
|             Response.Write(GetGridTableHtml2(Grid1));
 | |
|             Response.End();
 | |
|         }
 | |
|     }
 | |
| } |