| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592 |
- /*******************************************************************************
- * 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 单例模式
- /// <summary>
- /// 单例模式,防止重复创建窗体
- /// </summary>
- public static F_RPT_040109 Instance
- {
- get
- {
- if (_instance == null || _instance.IsDisposed)
- {
- _instance = new F_RPT_040109();
- }
- return _instance;
- }
- }
- #endregion
- #region 事件处理
- /// <summary>
- /// 窗体加载事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
- /// <summary>
- /// 自动适应列宽
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- /// <summary>
- /// 窗体关闭事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_RPT_040104_FormClosed(object sender, FormClosedEventArgs e)
- {
- _instance = null;
- }
- /// <summary>
- /// 关闭按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tsbtnClose_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- /// <summary>
- /// 查询按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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<string> removeAt = new List<string>();
- 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<string> colHB = new List<string>();
- foreach (DataRow item in dataSet.Tables["DT"].Rows)
- {
- List<int> colHBCell = new List<int>();
- 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<int, List<string>>();
- //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;
- }
- }
- /// <summary>
- /// 清空条件按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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 私有方法
-
- /// <summary>
- /// 根据界面查询条件获取数据集
- /// </summary>
- 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<ServiceResultEntity>(() =>
- {
- 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<ServiceResultEntity>(() =>
- {
- 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;
- }
- }
-
- /// <summary>
- /// 绑定下拉列表值
- /// </summary>
- /// <returns></returns>
- private void BindPage()
- {
- //绑定数据来源下拉列表
- ServiceResultEntity sre1 = DoAsync<ServiceResultEntity>(() =>
- {
- 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<ServiceResultEntity>(() =>
- {
- 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
- /// <summary>
- /// 导出
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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<DataGridView> dgvList = new List<DataGridView>();
- List<TreeView> tvList = new List<TreeView>();
- List<string> sheetList = new List<string>();
- 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);
- }
- }
- }
- }
|