CNCEC_SUBQHSE_WUHUAN/SGGL/FineUIPro.Web/CQMS/ProcessControl/InspectionManagementStatist...

289 lines
18 KiB
C#
Raw Normal View History

2021-04-30 10:28:37 +08:00
using BLL;
using System;
using System.Collections.Generic;
using System.Linq;
2021-05-20 17:16:01 +08:00
using System.Text;
2021-04-30 10:28:37 +08:00
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.CQMS.ProcessControl
{
2021-06-21 14:10:40 +08:00
public partial class InspectionManagementStatistics : PageBase
2021-04-30 10:28:37 +08:00
{
public DateTime StartDate;
public DateTime NextDate;
public DateTime NewDate;
2021-06-21 14:10:40 +08:00
public DateTime EndDate;
2021-04-30 10:28:37 +08:00
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)
{
2021-06-21 14:10:40 +08:00
if (string.IsNullOrEmpty(this.txtStartTime.Text.Trim()) && string.IsNullOrEmpty(this.txtEndTime.Text.Trim())) //未选择日期,统计项目开始起的每月数据
2021-04-30 10:28:37 +08:00
{
2021-06-21 14:10:40 +08:00
List<Model.InspectionManagementStatistics> StatisticsList = new List<Model.InspectionManagementStatistics>();
Model.Base_Project project = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
StartDate = Convert.ToDateTime(project.StartDate);
for (int i = 0; i < i + 1; i++)
2021-04-30 10:28:37 +08:00
{
2021-06-21 14:10:40 +08:00
Model.InspectionManagementStatistics Statistics = new Model.InspectionManagementStatistics();
if (i == 0)
2021-04-30 10:28:37 +08:00
{
2021-06-21 14:10:40 +08:00
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)
2021-04-30 10:28:37 +08:00
{
2021-06-21 14:10:40 +08:00
if (DateTime.Now < NewDate)
2021-04-30 10:28:37 +08:00
{
2021-06-21 14:10:40 +08:00
//统计所给时间段的全部数量
List<Model.View_CQMS_InspectionManagementDetail> managementListSunNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(this.CurrUser.LoginProjectId, cNProfessionalId, StartDate, DateTime.Now, false);
//统计所给时间段的合格数量
List<Model.View_CQMS_InspectionManagementDetail> managementListOneNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(this.CurrUser.LoginProjectId, 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;
2021-04-30 10:28:37 +08:00
}
else
{
2021-06-21 14:10:40 +08:00
NextDate = Convert.ToDateTime(StartDate.Year + "-" + StartDate.Month + "-25");
//统计所给事件段的全部数量
2023-09-01 17:11:53 +08:00
List<Model.View_CQMS_InspectionManagementDetail> managementListSunNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(this.CurrUser.LoginProjectId, cNProfessionalId, StartDate, NextDate, false);
2021-06-21 14:10:40 +08:00
//统计所给事件段的合格数量
2023-09-01 17:11:53 +08:00
List<Model.View_CQMS_InspectionManagementDetail> managementListOneNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(this.CurrUser.LoginProjectId, cNProfessionalId, StartDate, NextDate, true);
2021-06-21 14:10:40 +08:00
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%";
}
2021-04-30 10:28:37 +08:00
}
}
else
{
2021-06-21 14:10:40 +08:00
if (DateTime.Now < NewDate)
2021-04-30 10:28:37 +08:00
{
2021-06-21 14:10:40 +08:00
//统计所给事件段的全部数量
List<Model.View_CQMS_InspectionManagementDetail> managementListSunNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(this.CurrUser.LoginProjectId, cNProfessionalId, StartDate, DateTime.Now, false);
//统计所给事件段的合格数量
List<Model.View_CQMS_InspectionManagementDetail> managementListOneNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(this.CurrUser.LoginProjectId, 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;
2021-04-30 10:28:37 +08:00
}
else
{
2021-06-21 14:10:40 +08:00
//统计所给事件段的全部数量
List<Model.View_CQMS_InspectionManagementDetail> managementListSunNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(this.CurrUser.LoginProjectId, cNProfessionalId, StartDate, NewDate, false);
//统计所给事件段的合格数量
List<Model.View_CQMS_InspectionManagementDetail> managementListOneNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(this.CurrUser.LoginProjectId, 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%";
}
2021-04-30 10:28:37 +08:00
}
}
}
else
{
2021-06-21 14:10:40 +08:00
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");
2021-04-30 10:28:37 +08:00
if (DateTime.Now < NewDate)
{
//统计所给事件段的全部数量
List<Model.View_CQMS_InspectionManagementDetail> managementListSunNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(this.CurrUser.LoginProjectId, cNProfessionalId, StartDate, DateTime.Now, false);
//统计所给事件段的合格数量
List<Model.View_CQMS_InspectionManagementDetail> managementListOneNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(this.CurrUser.LoginProjectId, 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(this.CurrUser.LoginProjectId, cNProfessionalId, StartDate, NewDate, false);
//统计所给事件段的合格数量
List<Model.View_CQMS_InspectionManagementDetail> managementListOneNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(this.CurrUser.LoginProjectId, 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%";
}
}
}
2021-06-21 14:10:40 +08:00
StatisticsList.Add(Statistics);
2021-04-30 10:28:37 +08:00
}
2021-06-21 14:10:40 +08:00
Model.InspectionManagementStatistics StatisticsLast = new Model.InspectionManagementStatistics();
StatisticsLast.CheckDate = "合计";
int sum1 = 0;
int sum2 = 0;
foreach (Model.InspectionManagementStatistics item in StatisticsList)
2021-04-30 10:28:37 +08:00
{
2021-06-21 14:10:40 +08:00
sum1 += item.OneStatisticsSunNumber;
sum2 += item.SunNumber;
2021-04-30 10:28:37 +08:00
}
2021-06-21 14:10:40 +08:00
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();
2021-04-30 10:28:37 +08:00
}
2021-06-21 14:10:40 +08:00
else //选择日期,统计对应时间段内的数据
2021-04-30 10:28:37 +08:00
{
2021-06-21 14:10:40 +08:00
List<Model.InspectionManagementStatistics> StatisticsList = new List<Model.InspectionManagementStatistics>();
Model.Base_Project project = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
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(this.CurrUser.LoginProjectId, cNProfessionalId, StartDate, EndDate, false);
//统计所给时间段的合格数量
List<Model.View_CQMS_InspectionManagementDetail> managementListOneNumber = BLL.InspectionManagementService.getInspectionManagementDetailListByCNProfessionalIdAndDate(this.CurrUser.LoginProjectId, 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();
2021-04-30 10:28:37 +08:00
}
}
#endregion
protected void btnSearch_Click(object sender, EventArgs e)
{
2021-06-21 14:10:40 +08:00
if (this.drpCNProfessional.SelectedValue != BLL.Const._Null)
2021-04-30 10:28:37 +08:00
{
BindGvInspectionManagement(this.drpCNProfessional.SelectedValue);
}
else
{
BindGvInspectionManagement(null);
}
}
protected void btnOut_Click(object sender, EventArgs e)
{
2021-05-20 17:16:01 +08:00
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));
2021-04-30 10:28:37 +08:00
Response.End();
}
}
}