199 lines
		
	
	
		
			8.7 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			199 lines
		
	
	
		
			8.7 KiB
		
	
	
	
		
			C#
		
	
	
	
| 
								 | 
							
								using System;
							 | 
						|||
| 
								 | 
							
								using System.Collections.Generic;
							 | 
						|||
| 
								 | 
							
								using System.Linq;
							 | 
						|||
| 
								 | 
							
								using System.Text;
							 | 
						|||
| 
								 | 
							
								using System.Web;
							 | 
						|||
| 
								 | 
							
								using System.Web.UI;
							 | 
						|||
| 
								 | 
							
								using System.Web.UI.WebControls;
							 | 
						|||
| 
								 | 
							
								using BLL;
							 | 
						|||
| 
								 | 
							
								using AspNet = System.Web.UI.WebControls;
							 | 
						|||
| 
								 | 
							
								namespace FineUIPro.Web.CQMS.ManageReport
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    public partial class HJGLStatisc : PageBase
							 | 
						|||
| 
								 | 
							
								    {
							 | 
						|||
| 
								 | 
							
								        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()
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            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;
							 | 
						|||
| 
								 | 
							
								            List<Model.Base_Unit> units = (from x in Funs.DB.Project_ProjectUnit
							 | 
						|||
| 
								 | 
							
								                                           join y in Funs.DB.Base_Unit on x.UnitId equals y.UnitId
							 | 
						|||
| 
								 | 
							
								                                           where x.ProjectId == this.CurrUser.LoginProjectId
							 | 
						|||
| 
								 | 
							
								                                           orderby y.UnitCode
							 | 
						|||
| 
								 | 
							
								                                           select y).ToList();
							 | 
						|||
| 
								 | 
							
								            foreach (var item in units)
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                //单位下所有集合
							 | 
						|||
| 
								 | 
							
								                List<Model.ProcessControl_NondestructiveTest> totalNondestructiveTestList = BLL.NondestructiveTestService.GetNondestructiveTestListByUnitIdAndDate(this.CurrUser.LoginProjectId, item.UnitId, projectStartDate, endDate);
							 | 
						|||
| 
								 | 
							
								                //单位下当期集合
							 | 
						|||
| 
								 | 
							
								                List<Model.ProcessControl_NondestructiveTest> NondestructiveTestList = BLL.NondestructiveTestService.GetNondestructiveTestListByUnitIdAndDate(this.CurrUser.LoginProjectId, item.UnitId, projectStartDate, endDate);
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                Model.CheckStatisc CheckStatisc = new Model.CheckStatisc();
							 | 
						|||
| 
								 | 
							
								                CheckStatisc.Num = i;
							 | 
						|||
| 
								 | 
							
								                CheckStatisc.WorkName = item.UnitName;
							 | 
						|||
| 
								 | 
							
								                CheckStatisc.CheckNum = NondestructiveTestList.Sum(x => x.PieceCount ?? 0);
							 | 
						|||
| 
								 | 
							
								                CheckStatisc.TotalCheckNum = totalNondestructiveTestList.Sum(x => x.PieceCount ?? 0);
							 | 
						|||
| 
								 | 
							
								                CheckStatisc.OKNum = NondestructiveTestList.Sum(x => x.OnceQualifiedCount ?? 0);
							 | 
						|||
| 
								 | 
							
								                CheckStatisc.TotalOKNum = totalNondestructiveTestList.Sum(x => x.OnceQualifiedCount ?? 0);
							 | 
						|||
| 
								 | 
							
								                if (CheckStatisc.CheckNum != 0)//被除数不能为零
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    CheckStatisc.OneOKRate = Math.Round((double)CheckStatisc.OKNum / (double)CheckStatisc.CheckNum * 100, 2) + "%";//保留两位小数、后四舍五入
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                else
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    CheckStatisc.OneOKRate = "0%";
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                if (CheckStatisc.TotalCheckNum != 0)//被除数不能为零
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    CheckStatisc.TotalOneOKRate = Math.Round((double)CheckStatisc.TotalOKNum / (double)CheckStatisc.TotalCheckNum * 100, 2) + "%";//保留两位小数、后四舍五入
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                else
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    CheckStatisc.TotalOneOKRate = "0%";
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                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;
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                if (StatisticsLast.CheckNum != 0)//被除数不能为零
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    StatisticsLast.OneOKRate = Math.Round((double)StatisticsLast.OKNum / (double)StatisticsLast.CheckNum * 100, 2) + "%";//保留两位小数、后四舍五入
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                else
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    StatisticsLast.OneOKRate = "0%";
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                if (StatisticsLast.TotalCheckNum != 0)//被除数不能为零
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    StatisticsLast.TotalOneOKRate = Math.Round((double)StatisticsLast.TotalOKNum / (double)StatisticsLast.TotalCheckNum * 100, 2) + "%";//保留两位小数、后四舍五入
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                else
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    StatisticsLast.TotalOneOKRate = "0%";
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                StatisticsList.Add(StatisticsLast);
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            this.Grid1.DataSource = StatisticsList;
							 | 
						|||
| 
								 | 
							
								            this.Grid1.DataBind();
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        #endregion
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        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 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)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            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 = System.Text.Encoding.UTF8;
							 | 
						|||
| 
								 | 
							
								            Response.Write(GetGridTableHtml(Grid1));
							 | 
						|||
| 
								 | 
							
								            Response.End();
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <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
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 |