/******************************************************************************* * Copyright(c) 2015 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_RPT_040109.cs * 2.功能描述:整体质量分析表 * 编辑履历: * 作者 日期 版本 修改内容 * 陈晓野 2016/11/09 1.00 新建 *******************************************************************************/ using System; using System.Collections.Generic; using System.Data; using System.Text; using System.Windows.Forms; using Dongke.IBOSS.PRD.Basics.BaseResources; using Dongke.IBOSS.PRD.Basics.DockPanel; using Dongke.IBOSS.PRD.Client.CommonModule; using Dongke.IBOSS.PRD.Client.Controls; using Dongke.IBOSS.PRD.Client.DataModels; using Dongke.IBOSS.PRD.WCF.DataModels; using Dongke.IBOSS.PRD.WCF.Proxys; namespace Dongke.IBOSS.PRD.Client.ReportModule { public partial class F_RPT_040109 : DKDockPanelBase { #region 成员变量 // 窗体的单例模式 private static F_RPT_040109 _instance; private DataTable g2DataTable = new DataTable(); private DataTable g3DataTable = new DataTable(); private int _minimumWidth = 40; #endregion #region 构造函数 public F_RPT_040109() { InitializeComponent(); // 窗体显示的Title //this.Text = FormTitles.F_RPT_040105; this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE; this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE; this.btnSearch.Text = ButtonText.BTN_SEARCH; this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION; this.gbxCondition.Text = Constant.LABEL_QUERY_CONDITIONS; g2DataTable.Columns.Add("goodstypename2"); g3DataTable.Columns.Add("goodstypename2"); g2DataTable.Rows.Add(new object[] { "成品率(%)" }); g3DataTable.Rows.Add(new object[] { "缺陷率(%)" }); } #endregion #region 单例模式 /// /// 单例模式,防止重复创建窗体 /// public static F_RPT_040109 Instance { get { if (_instance == null || _instance.IsDisposed) { _instance = new F_RPT_040109(); } return _instance; } } #endregion #region 事件处理 /// /// 窗体加载事件 /// /// /// private void F_RPT_040104_Load(object sender, EventArgs e) { try { // 加载权限 FormPermissionManager.FormPermissionControl(this.Name, this, LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData); //绑定下了列表 BindPage(); // 设置表格不自动创建列 this.dgvTQ.AutoGenerateColumns = false; this.dgvFR.AutoGenerateColumns = false; this.dgvDR.AutoGenerateColumns = false; this.dgvDL.AutoGenerateColumns = false; this.dropRptProcedure.Focus(); // 初始化时间控件为当前日期 DateTime now = DateTime.Now.Date; this.dtpAccountDateStart.Value = now; this.dtpAccountDateEnd.Value = now.AddDays(1).AddSeconds(-1); //getPurviewLine(); this.dgvFR.DataSource = this.g2DataTable; this.dgvDR.DataSource = this.g3DataTable; } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 自动适应列宽 /// /// /// private void tsbtnAdaptive_Click(object sender, EventArgs e) { this.dgvTQ.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); this.dgvFR.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); this.dgvDR.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); this.dgvDL.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); } /// /// 窗体关闭事件 /// /// /// private void F_RPT_040104_FormClosed(object sender, FormClosedEventArgs e) { _instance = null; } /// /// 关闭按钮 /// /// /// private void tsbtnClose_Click(object sender, EventArgs e) { this.Close(); } /// /// 查询按钮事件 /// /// /// private void btnSearch_Click(object sender, EventArgs e) { try { //this.tabcData.SelectedIndex = 0; //this.tabcData.Enabled = false; this.dgvFR.HorizontalMergeColumn = null; this.dgvTQ.DataSource = null; this.dgvFR.DataSource = this.g2DataTable; this.dgvDR.DataSource = this.g3DataTable; this.dgvDL.DataSource = null; List removeAt = new List(); foreach (DataGridViewColumn item in this.dgvFR.Columns) { if (!item.Name.StartsWith("g")) { removeAt.Add(item.Name); } } foreach (string item in removeAt) { this.dgvFR.Columns.Remove(item); } removeAt.Clear(); TreeNode top = this.g2TV.Nodes[0]; this.g2TV.Nodes.Clear(); this.g2TV.Nodes.Add(top); top = this.g3TV.Nodes[0]; this.g3TV.Nodes.Clear(); this.g3TV.Nodes.Add(top); foreach (DataGridViewColumn item in this.dgvDR.Columns) { if (!item.Name.StartsWith("g")) { removeAt.Add(item.Name); } } foreach (string item in removeAt) { this.dgvDR.Columns.Remove(item); } removeAt.Clear(); foreach (DataGridViewColumn item in this.dgvDL.Columns) { if (!item.Name.StartsWith("g")) { removeAt.Add(item.Name); } } foreach (string item in removeAt) { this.dgvDL.Columns.Remove(item); } removeAt.Clear(); DataSet dataSet = this.GetSearchData(); if (dataSet == null) { return; } List colHB = new List(); foreach (DataRow item in dataSet.Tables["DT"].Rows) { List colHBCell = new List(); string dtID = "T" + item["defecttypeid"].ToString(); string dtName = item["defecttypeName"].ToString(); // 缺陷排行 DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn(); col.Name = "a4" + dtID; col.HeaderText = dtName; col.DataPropertyName = dtID; DataGridViewCellStyle dgvcs = new System.Windows.Forms.DataGridViewCellStyle(); dgvcs.Alignment = DataGridViewContentAlignment.MiddleRight; dgvcs.NullValue = "0"; dgvcs.Format = "N0"; col.DefaultCellStyle = dgvcs; col.ReadOnly = true; this.dgvDL.Columns.Add(col); // 成品率 #region 成品率 TreeNode tnDTA2 = new TreeNode(dtName); tnDTA2.Name = "a2" + dtID; DataRow[] wgs = dataSet.Tables["WG"].Select("defecttypeid = " + item["defecttypeid"]); if (wgs == null || wgs.Length == 0) { foreach (DataRow drDF in dataSet.Tables["DF"].Rows) { string dfID = "F" + drDF["defectfineid"]; string dfName = drDF["defectfinecode"].ToString(); TreeNode tnDF = new TreeNode(dfName); tnDF.Name = tnDTA2.Name + "W" + dfID; tnDTA2.Nodes.Add(tnDF); DataGridViewTextBoxColumn colDF = new DataGridViewTextBoxColumn(); colDF.Name = tnDF.Name; colDF.MinimumWidth = this._minimumWidth; colDF.HeaderText = tnDF.Text; colDF.DataPropertyName = dtID + "W" + dfID; DataGridViewCellStyle dgvcsDF = new System.Windows.Forms.DataGridViewCellStyle(); dgvcsDF.Alignment = DataGridViewContentAlignment.MiddleRight; colDF.DefaultCellStyle = dgvcsDF; colDF.SortMode = DataGridViewColumnSortMode.NotSortable; colDF.ReadOnly = true; this.dgvFR.Columns.Add(colDF); colHBCell.Add(colDF.Index); } } else { foreach (DataRow drWG in wgs) { string wgID = "W" + drWG["workergroupid"]; string wgName = drWG["workergroupName"].ToString(); TreeNode tnWG = new TreeNode(wgName); tnWG.Name = tnDTA2.Name + wgID; tnDTA2.Nodes.Add(tnWG); foreach (DataRow drDF in dataSet.Tables["DF"].Rows) { string dfID = "F" + drDF["defectfineid"]; string dfName = drDF["defectfinecode"].ToString(); TreeNode tnDF = new TreeNode(dfName); tnDF.Name = tnWG.Name + dfID; tnWG.Nodes.Add(tnDF); DataGridViewTextBoxColumn colDF = new DataGridViewTextBoxColumn(); colDF.Name = tnDF.Name; colDF.HeaderText = tnDF.Text; colDF.MinimumWidth = this._minimumWidth; colDF.DataPropertyName = dtID + wgID + dfID; DataGridViewCellStyle dgvcsDF = new System.Windows.Forms.DataGridViewCellStyle(); dgvcsDF.Alignment = DataGridViewContentAlignment.MiddleRight; colDF.DefaultCellStyle = dgvcsDF; colDF.ReadOnly = true; colDF.SortMode = DataGridViewColumnSortMode.NotSortable; this.dgvFR.Columns.Add(colDF); colHBCell.Add(colDF.Index); } } } this.g2TV.Nodes.Add(tnDTA2); colHB.Add(string.Join(",", colHBCell.ToArray())); #endregion // 缺陷率 #region 缺陷率 DataRow[] tdr = dataSet.Tables["DR1"].Select("tid = '" + dtID + "'"); string dta3Name = dtName; if (tdr != null && tdr.Length > 0) { //dta3Name += Convert.ToDecimal(tdr[0]["DefectRate"]).ToString("(#,##0.00%)"); dta3Name += (tdr[0]["DefectRate"] == DBNull.Value ? "(" + Constant.DIV0 + ")" : Convert.ToDecimal(tdr[0]["DefectRate"]).ToString("(#,##0.00%)")); } else { dta3Name += "(0.00%)"; } TreeNode tnDTA3 = new TreeNode(dta3Name); tnDTA3.Name = "a3" + dtID; DataRow[] ds = dataSet.Tables["D"].Select("defectid is not null and defecttypeid = " + item["defecttypeid"]); if (ds == null || ds.Length == 0) { foreach (DataRow drDF in dataSet.Tables["DF"].Rows) { string dfID = "F" + drDF["defectfineid"]; string dfName = drDF["defectfinecode"].ToString(); TreeNode tnDF = new TreeNode(dfName); tnDF.Name = tnDTA3.Name + "D" + dfID; tnDTA3.Nodes.Add(tnDF); DataGridViewTextBoxColumn colDF = new DataGridViewTextBoxColumn(); colDF.Name = tnDF.Name; colDF.HeaderText = tnDF.Text; colDF.MinimumWidth = this._minimumWidth; colDF.DataPropertyName = dtID + "D" + dfID; DataGridViewCellStyle dgvcsDF = new System.Windows.Forms.DataGridViewCellStyle(); dgvcsDF.Alignment = DataGridViewContentAlignment.MiddleRight; colDF.DefaultCellStyle = dgvcsDF; colDF.SortMode = DataGridViewColumnSortMode.NotSortable; colDF.ReadOnly = true; this.dgvDR.Columns.Add(colDF); } } else { foreach (DataRow drD in ds) { string dID = "D" + drD["defectid"]; string dName = drD["defectname"].ToString(); TreeNode tnD = new TreeNode(dName); tnD.Name = tnDTA3.Name + dID; tnDTA3.Nodes.Add(tnD); foreach (DataRow drDF in dataSet.Tables["DF"].Rows) { string dfID = "F" + drDF["defectfineid"]; string dfName = drDF["defectfinecode"].ToString(); TreeNode tnDF = new TreeNode(dfName); tnDF.Name = tnD.Name + dfID; tnD.Nodes.Add(tnDF); DataGridViewTextBoxColumn colDF = new DataGridViewTextBoxColumn(); colDF.Name = tnDF.Name; colDF.HeaderText = tnDF.Text; colDF.MinimumWidth = this._minimumWidth; colDF.DataPropertyName = dtID + dID + dfID; DataGridViewCellStyle dgvcsDF = new System.Windows.Forms.DataGridViewCellStyle(); dgvcsDF.Alignment = DataGridViewContentAlignment.MiddleRight; colDF.DefaultCellStyle = dgvcsDF; colDF.SortMode = DataGridViewColumnSortMode.NotSortable; colDF.ReadOnly = true; this.dgvDR.Columns.Add(colDF); } } } this.g3TV.Nodes.Add(tnDTA3); #endregion } this.dgvTQ.DataSource = dataSet.Tables["TQ"]; this.dgvFR.DataSource = dataSet.Tables["FR"]; this.dgvDR.DataSource = dataSet.Tables["DR"]; this.dgvDL.DataSource = dataSet.Tables["DL"]; this.dgvFR.HorizontalMergeColumn = new Dictionary>(); //colHB.Insert(0, "0"); //this.dgvFR.HorizontalMergeColumn.Add(this.dgvFR.RowCount - 1, colHB); int index = (this.dgvFR.RowCount - 1) / 2; if (index < 0) { index = 0; } for (int i = index; i < this.dgvFR.RowCount; i++) { this.dgvFR.HorizontalMergeColumn.Add(i, colHB); } this.tsbtnAdaptive_Click(null, null); } catch (Exception ex) { this.btnSearch.Enabled = true; this.btnClearCondition.Enabled = true; // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } finally { this.btnSearch.Enabled = true; this.btnClearCondition.Enabled = true; this.tabcData.Enabled = true; this.dgvTQ.Enabled = true; this.dgvFR.Enabled = true; this.dgvDR.Enabled = true; this.dgvDL.Enabled = true; } } /// /// 清空条件按钮事件 /// /// /// private void btnClearCondition_Click(object sender, EventArgs e) { this.dropKilnCode.SelectedIndex = 0; DateTime now = DateTime.Now.Date; this.dtpAccountDateStart.Value = now; this.dtpAccountDateEnd.Value = now.AddDays(1).AddSeconds(-1); } #endregion #region 私有方法 /// /// 根据界面查询条件获取数据集 /// private DataSet GetSearchData() { try { RPT040109_SE se = new RPT040109_SE(); if (string.IsNullOrEmpty(this.dropRptProcedure.Text)) { this.dropRptProcedure.Focus(); return null; } se.RptProcedureID = Convert.ToInt32(this.dropRptProcedure.SelectedValue); //获取数据来源工序Id ServiceResultEntity sre0 = this.DoAsync(() => { return ReportModuleProxy.Service.GetRptSourceProcedureModule(se.RptProcedureID); } ); if (sre0.Data != null && sre0.Data.Tables.Count > 0) { se.RptSProcedureID = int.Parse(sre0.Data.Tables[0].Rows[Constant.INT_IS_ZERO]["Procedureid"].ToString()); } //获取数据来源工序Id if (!this.dropKilnCode.Text.Equals(Constant.CBO_SELECT_ALL_NAME)) { se.KilnID = Convert.ToInt32(this.dropKilnCode.SelectedValue); } //se.CreateTimeStart = DateTime.Parse(this.dtpAccountDateStart.Value.ToString("yyyy-MM-dd") + " 00:00:00"); //se.CreateTimeEnd = DateTime.Parse(this.dtpAccountDateEnd.Value.ToString("yyyy-MM-dd") + " 23:59:59"); se.CreateTimeStart = this.dtpAccountDateStart.Value; se.CreateTimeEnd = this.dtpAccountDateEnd.Value; se.HasUserGroup = this.chkUserGroup.Checked; // 调用服务器端获取数据集 ServiceResultEntity sre = DoAsync(() => { return ReportModuleProxy.Service.GetRPT040109SData(se); } ); if (sre.Status == Constant.ServiceResultStatus.Success) { if (sre.Data.Tables[0].Rows.Count <= Constant.INT_IS_ZERO) { // 提示未查找到数据 MessageBox.Show(Messages.MSG_CMN_I002, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); //清空数据 return null; } return sre.Data; } return null; } catch (Exception ex) { throw ex; } } /// /// 绑定下拉列表值 /// /// private void BindPage() { //绑定数据来源下拉列表 ServiceResultEntity sre1 = DoAsync(() => { return ReportModuleProxy.Service.GetRptProcedureModule(); } ); this.dropRptProcedure.DataSource = sre1.Data.Tables[Constant.INT_IS_ZERO]; this.dropRptProcedure.ValueMember = "Rptprocedureid"; this.dropRptProcedure.DisplayMember = "Rptprocedurename"; //绑定窑炉下来列表 ServiceResultEntity sre2 = DoAsync(() => { byte byFlage = Convert.ToByte(Constant.ValueFlag.Invalid); return ReportModuleProxy.Service.GetKilnData(byFlage); } ); DataTable dtKilnInfo = sre2.Data.Tables[Constant.INT_IS_ZERO]; DataRow newRowDic = dtKilnInfo.NewRow(); newRowDic["KilnID"] = Constant.CBO_SELECT_ALL_VALUE; newRowDic["KilnCode"] = Constant.CBO_SELECT_ALL_NAME; dtKilnInfo.Rows.InsertAt(newRowDic, Constant.INT_IS_ZERO); this.dropKilnCode.DataSource = dtKilnInfo; this.dropKilnCode.ValueMember = "KilnID"; this.dropKilnCode.DisplayMember = "KilnCode"; } #endregion /// /// 导出 /// /// /// private void tsbtnExport_Click(object sender, EventArgs e) { try { int si = this.tabcData.SelectedIndex; this.tabcData.SelectedIndex = 0; this.tabcData.SelectedIndex = 1; this.tabcData.SelectedIndex = 2; this.tabcData.SelectedIndex = 3; this.tabcData.SelectedIndex = si; // 多个sheet页 List dgvList = new List(); List tvList = new List(); List sheetList = new List(); dgvList.Add(this.dgvTQ); dgvList.Add(this.dgvFR); dgvList.Add(this.dgvDR); dgvList.Add(this.dgvDL); tvList.Add(null); tvList.Add(this.dgvFR.ColumnTreeView[0]); tvList.Add(this.dgvDR.ColumnTreeView[0]); tvList.Add(null); sheetList.Add(this.tabcData.TabPages[0].Text); sheetList.Add(this.tabcData.TabPages[1].Text); sheetList.Add(this.tabcData.TabPages[2].Text); sheetList.Add(this.tabcData.TabPages[3].Text); ExportExcel.Common.Instance.ExportExcel(dgvList, tvList, null, this.Text, this.Text, this.Font, "", this.Font, "", sheetList, true, true, true, this.dgvFR.IsTopDeep); //ExportExcel.Common.Instance.ExportExcelOneSheet(dgvList, tvList, null, this.Text, this.Text, this.Font, "", this.Font, "", sheetList, true, true, this.dgvFR.IsTopDeep); } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } } }