using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Server; using Core.Mes.Client.Comm.Tool; using Core.StlMes.Client.PnCost.Models; using CoreFS.CA06; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Core.StlMes.Client.PnCost { public partial class frmCostCalculation : FrmBase { #region 定义变量 private string plineID = "first"; private string flagA; private string flagD; private string flagE; private string flagF; private string flagG; #endregion #region 初始化 public frmCostCalculation() { InitializeComponent(); } private void frmCostCalculation_Load(object sender, EventArgs e) { EntityHelper.ShowGridCaption(ultraGrid1.DisplayLayout.Bands[0]); EntityHelper.ShowGridCaption(ultraGrid2.DisplayLayout.Bands[0]); EntityHelper.ShowGridCaption(ultraGrid3.DisplayLayout.Bands[0]); EntityHelper.ShowGridCaption(ultraGrid4.DisplayLayout.Bands[0]); EntityHelper.ShowGridCaption(ultraGrid5.DisplayLayout.Bands[0]); EntityHelper.ShowGridCaption(ultraGrid6.DisplayLayout.Bands[0]); EntityHelper.ShowGridCaption(ultraGrid7.DisplayLayout.Bands[0]); ultraCheckEditor3.Checked = false; ultraTextEditor1.Enabled = false; for (int i = 2000; i < 2051; i++) { yeardrop.Items.Add(i); } string str1 = ""; for (int i = 1; i < 10; i++) { str1 = "0" + i.ToString2(); monthdrop.Items.Add(str1); } monthdrop.Items.Add(10); monthdrop.Items.Add(11); monthdrop.Items.Add(12); yeardrop.Value = System.DateTime.Now.Year.ToString2(); monthdrop.Value = System.DateTime.Now.Month.ToString2(); DataTable dt = ServerHelper.GetData("com.steering.pss.pncost.base.ComCalculation.querypliao", new object[] { }, ob); ulcmeBaseWL.DisplayMember = "BASENAME"; ulcmeBaseWL.ValueMember = "BASECODE"; ulcmeBaseWL.DataSource = dt; } #endregion #region 方法 public override void ToolBar_Click(object sender, string ToolbarKey) { base.ToolBar_Click(sender, ToolbarKey); switch (ToolbarKey) { case "Query": Query(); break; case "Refresh": Refresh(); break; case "CostMain": CostMain(); break; case "Close": this.Close(); break; case "Export": Export(); break; } } private void CostMain() { WaitingForm2 wf = new WaitingForm2(); wf.Msg = "正在计算,请稍候......"; wf.Show(); wf.Update(); string year = yeardrop.Value.ToString2(); string month = monthdrop.Value.ToString2(); string[] results = (string[])ServerHelper.SetDataReturnObj("com.steering.pss.pncost.base.ComCalculation.costMain", new object[] { year + month }, ob); wf.ShowToUser = false; wf.Close(); Query(); if (results[0] == "-1") { MessageUtil.ShowWarning(results[1]); return; } if (results[0] == "1") { MessageUtil.ShowTips("计算成功!"); } } /// 导出方法 /// /// 导出方法 /// private void Export() { if (ultraTabControl1.SelectedTab.Text == "电炉铸造锻造") { if (ultraGrid2.Rows.Count == 0) { MessageUtil.ShowWarning("查询数据为空,无法导出!"); return; } GridHelper.ulGridToExcel(ultraGrid2, "电炉铸造锻造计划成本"); } if (ultraTabControl1.SelectedTab.Text == "轧管") { if (ultraGrid3.Rows.Count == 0) { MessageUtil.ShowWarning("查询数据为空,无法导出!"); return; } GridHelper.ulGridToExcel(ultraGrid3, "轧管计划成本"); } if (ultraTabControl1.SelectedTab.Text == "镦拨扩") { if (ultraGrid4.Rows.Count == 0) { MessageUtil.ShowWarning("查询数据为空,无法导出!"); return; } GridHelper.ulGridToExcel(ultraGrid4, "镦拨扩计划成本"); } if (ultraTabControl1.SelectedTab.Text == "热处理") { if (ultraGrid5.Rows.Count == 0) { MessageUtil.ShowWarning("查询数据为空,无法导出!"); return; } GridHelper.ulGridToExcel(ultraGrid5, "热处理计划成本"); } if (ultraTabControl1.SelectedTab.Text == "加工") { if (ultraGrid6.Rows.Count == 0) { MessageUtil.ShowWarning("查询数据为空,无法导出!"); return; } GridHelper.ulGridToExcel(ultraGrid6, "加工计划成本"); } if (ultraTabControl1.SelectedTab.Text == "日志") { if (ultraGrid7.Rows.Count == 0) { MessageUtil.ShowWarning("查询数据为空,无法导出!"); return; } GridHelper.ulGridToExcel(ultraGrid7, "日志信息"); } if (ultraTabControl1.SelectedTab.Text == "订单成本统计") { if (ultraGrid8.Rows.Count == 0) { MessageUtil.ShowWarning("查询数据为空,无法导出!"); return; } GridHelper.ulGridToExcel(ultraGrid8, "订单成本统计"); } } /// 查询方法 /// /// 查询方法 /// private void Query() { plineID = flagA = flagD = flagE = flagF = flagG = ""; #region 条件验证 //年月 string year = yeardrop.Value.ToString2(); string month = monthdrop.Value.ToString2(); //排产订单编号 string strChan = ""; if (ultraCheckEditor3.Checked)//排产订单编号是否选择 { strChan = ultraTextEditor1.Text.Trim().ToString2();//排产订单编号 } #endregion #region 汇总 List data = EntityHelper.GetData( "com.steering.pss.pncost.base.ComCalculation.queryAll", new object[] { year + month }, ob); costCalculationGtlEntityBindingSource.DataSource = data; if (ultraGrid1.Rows.Count != 0) { ultraGrid1.UpdateData(); ultraGrid1.ActiveRow = ultraGrid1.Rows[0]; } #endregion tab(); } /// 判断tab页查询相应数据 /// /// 判断tab页查询相应数据 /// private void tab() { if (plineID == "first") { return; } if (ultraTabControl1.SelectedTab.Text == "轧管") { #region 条件验证 //年月 string year = yeardrop.Value.ToString2(); string month = monthdrop.Value.ToString2(); //扎管订单编号 string strChan = ""; if (ultraCheckEditor3.Checked)//扎管订单编号是否选择 { strChan = ultraTextEditor1.Text.Trim().ToString2();//扎管订单编号 } #endregion #region 扎管 if (plineID == "" || ultraGrid3.Rows.Count == 0 || flagD == "") { flagD = "already"; List dataD = EntityHelper.GetData( "com.steering.pss.pncost.base.ComCalculation.queryD", new object[] { year + month, strChan }, ob); costCalculationDEntityBindingSource.DataSource = dataD; if (ultraGrid3.Rows.Count == 0) { return; } //GridHelper.RefreshAndAutoSize(ultraGrid3); } for (int i = 0; i < ultraGrid3.Rows.Count; i++) { if (plineID == ultraGrid3.Rows[i].Cells["ProPlanId"].Value.ToString2()) { ultraGrid3.Rows[i].Appearance.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192))))); ultraGrid3.ActiveRow = ultraGrid3.Rows[i]; } else { ultraGrid3.Rows[i].Appearance.BackColor = System.Drawing.Color.White; } } #endregion } else if (ultraTabControl1.SelectedTab.Text == "镦拨扩") { #region 条件验证 //年月 string year = yeardrop.Value.ToString2(); string month = monthdrop.Value.ToString2(); //扎管订单编号 string strChan = ""; if (ultraCheckEditor3.Checked)//扎管订单编号是否选择 { strChan = ultraTextEditor1.Text.Trim().ToString2();//扎管订单编号 } #endregion #region 镦拨扩 if (plineID == "" || ultraGrid4.Rows.Count == 0 || flagE == "") { flagE = "already"; List dataE = EntityHelper.GetData( "com.steering.pss.pncost.base.ComCalculation.queryE", new object[] { year + month, strChan }, ob); costCalculationEEntityBindingSource.DataSource = dataE; if (ultraGrid4.Rows.Count == 0) { return; } //GridHelper.RefreshAndAutoSize(ultraGrid4); //ultraGrid4.ActiveRow = ultraGrid4.Rows[0]; } for (int i = 0; i < ultraGrid4.Rows.Count; i++) { if (plineID == ultraGrid4.Rows[i].Cells["ProPlanId"].Value.ToString2()) { ultraGrid4.Rows[i].Appearance.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192))))); } else { ultraGrid4.Rows[i].Appearance.BackColor = System.Drawing.Color.White; } } #endregion } else if (ultraTabControl1.SelectedTab.Text == "电炉铸造锻造") { #region 条件验证 //年月 string year = yeardrop.Value.ToString2(); string month = monthdrop.Value.ToString2(); //扎管订单编号 string strChan = ""; if (ultraCheckEditor3.Checked)//扎管订单编号是否选择 { strChan = ultraTextEditor1.Text.Trim().ToString2();//扎管订单编号 } #endregion #region 电炉铸造锻造 if (plineID == "" || ultraGrid2.Rows.Count == 0 || flagA == "") { flagA = "already"; List dataA = EntityHelper.GetData( "com.steering.pss.pncost.base.ComCalculation.queryA", new object[] { year + month, strChan }, ob); costCalculationAEntityBindingSource.DataSource = dataA; if (ultraGrid2.Rows.Count == 0) { return; } //GridHelper.RefreshAndAutoSize(ultraGrid2); //ultraGrid2.ActiveRow = ultraGrid2.Rows[0]; } for (int i = 0; i < ultraGrid2.Rows.Count; i++) { if (plineID == ultraGrid2.Rows[i].Cells["ProPlanId"].Value.ToString2()) { ultraGrid2.Rows[i].Appearance.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192))))); } else { ultraGrid2.Rows[i].Appearance.BackColor = System.Drawing.Color.White; } } #endregion } else if (ultraTabControl1.SelectedTab.Text == "热处理") { #region 条件验证 //年月 string year = yeardrop.Value.ToString2(); string month = monthdrop.Value.ToString2(); //扎管订单编号 string strChan = ""; if (ultraCheckEditor3.Checked)//扎管订单编号是否选择 { strChan = ultraTextEditor1.Text.Trim().ToString2();//扎管订单编号 } #endregion #region 热处理 if (plineID == "" || ultraGrid5.Rows.Count == 0 || flagF == "") { flagF = "already"; List dataF = EntityHelper.GetData( "com.steering.pss.pncost.base.ComCalculation.queryF", new object[] { year + month, strChan }, ob); costCalculationFEntityBindingSource.DataSource = dataF; if (ultraGrid5.Rows.Count == 0) { return; } //GridHelper.RefreshAndAutoSize(ultraGrid5); //ultraGrid5.ActiveRow = ultraGrid5.Rows[0]; } for (int i = 0; i < ultraGrid5.Rows.Count; i++) { if (plineID == ultraGrid5.Rows[i].Cells["ProPlanId"].Value.ToString2()) { ultraGrid5.Rows[i].Appearance.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192))))); } else { ultraGrid5.Rows[i].Appearance.BackColor = System.Drawing.Color.White; } } #endregion } else if (ultraTabControl1.SelectedTab.Text == "加工") { #region 条件验证 //年月 string year = yeardrop.Value.ToString2(); string month = monthdrop.Value.ToString2(); //扎管订单编号 string strChan = ""; if (ultraCheckEditor3.Checked)//扎管订单编号是否选择 { strChan = ultraTextEditor1.Text.Trim().ToString2();//扎管订单编号 } #endregion #region 加工 if (plineID == "" || ultraGrid6.Rows.Count == 0 || flagG == "") { flagG = "already"; List dataG = EntityHelper.GetData( "com.steering.pss.pncost.base.ComCalculation.queryG", new object[] { year + month, strChan }, ob); costCalculationGEntityBindingSource.DataSource = dataG; if (ultraGrid6.Rows.Count == 0) { return; } //ultraGrid6.ActiveRow = ultraGrid6.Rows[0]; } for (int i = 0; i < ultraGrid6.Rows.Count; i++) { if (plineID == ultraGrid6.Rows[i].Cells["ProPlanId"].Value.ToString2()) { ultraGrid6.Rows[i].Appearance.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192))))); } else { ultraGrid6.Rows[i].Appearance.BackColor = System.Drawing.Color.White; } } //GridHelper.RefreshAndAutoSize(ultraGrid6); #endregion } else if (ultraTabControl1.SelectedTab.Text == "订单成本统计") { #region 条件验证 //年月 string year = yeardrop.Value.ToString2(); string month = monthdrop.Value.ToString2(); #endregion #region 统计 if (plineID == "" || ultraGrid8.Rows.Count == 0 || flagG == "") { flagG = "already"; DataTable data = ServerHelper.GetData("com.steering.pss.pncost.base.ComCalculation.querycount", new object[] { year + month }, ob); GridHelper.CopyDataToDatatable(data, dataTable1, true); if (ultraGrid8.Rows.Count == 0) { return; } //ultraGrid6.ActiveRow = ultraGrid6.Rows[0]; } for (int i = 0; i < ultraGrid8.Rows.Count; i++) { if (plineID == ultraGrid8.Rows[i].Cells["pro_plan_id"].Value.ToString2()) { ultraGrid8.Rows[i].Appearance.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192))))); } else { ultraGrid8.Rows[i].Appearance.BackColor = System.Drawing.Color.White; } } //GridHelper.RefreshAndAutoSize(ultraGrid6); #endregion } else { #region 条件验证 //年月 string year = yeardrop.Value.ToString2(); string month = monthdrop.Value.ToString2(); //扎管订单编号 string strChan = ""; if (ultraCheckEditor3.Checked)//扎管订单编号是否选择 { strChan = ultraTextEditor1.Text.Trim().ToString2();//扎管订单编号 } #endregion #region 日志 List dataERR = EntityHelper.GetData( "com.steering.pss.pncost.base.ComCalculation.queryERR", new object[] { }, ob); costCalculationErrorEntityBindingSource.DataSource = dataERR; if (ultraGrid6.Rows.Count == 0) { return; } GridHelper.RefreshAndAutoSize(ultraGrid7); #endregion } } #endregion #region 事件 private void ultraCheckEditor3_CheckedChanged(object sender, EventArgs e) { ultraTextEditor1.Enabled = this.ultraCheckEditor3.Checked; } /// 电炉,锻造,铸造选中行事件 /// /// 电炉,锻造,铸造选中行事件 /// private void ultraGrid2_AfterRowActivate(object sender, EventArgs e) { plineID = ultraGrid2.ActiveRow.Cells["ProPlanId"].Value.ToString2(); for (int i = 0; i < ultraGrid2.Rows.Count; i++) { if (plineID == ultraGrid2.Rows[i].Cells["ProPlanId"].Value.ToString2()) { ultraGrid2.Rows[i].Appearance.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192))))); } else { ultraGrid2.Rows[i].Appearance.BackColor = System.Drawing.Color.White; } } } /// 扎管选中行事件 /// /// 扎管选中行事件 /// private void ultraGrid3_AfterRowActivate(object sender, EventArgs e) { plineID = ultraGrid3.ActiveRow.Cells["ProPlanId"].Value.ToString2(); for (int i = 0; i < ultraGrid3.Rows.Count; i++) { if (plineID == ultraGrid3.Rows[i].Cells["ProPlanId"].Value.ToString2()) { ultraGrid3.Rows[i].Appearance.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192))))); } else { ultraGrid3.Rows[i].Appearance.BackColor = System.Drawing.Color.White; } } } /// 热处理选中行事件 /// /// 热处理选中行事件 /// private void ultraGrid4_AfterRowActivate(object sender, EventArgs e) { plineID = ultraGrid4.ActiveRow.Cells["ProPlanId"].Value.ToString2(); for (int i = 0; i < ultraGrid4.Rows.Count; i++) { if (plineID == ultraGrid4.Rows[i].Cells["ProPlanId"].Value.ToString2()) { ultraGrid4.Rows[i].Appearance.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192))))); } else { ultraGrid4.Rows[i].Appearance.BackColor = System.Drawing.Color.White; } } } /// 吨拔廓选中行事件 /// /// 吨拔廓选中行事件 /// private void ultraGrid5_AfterRowActivate(object sender, EventArgs e) { plineID = ultraGrid5.ActiveRow.Cells["ProPlanId"].Value.ToString2(); for (int i = 0; i < ultraGrid5.Rows.Count; i++) { if (plineID == ultraGrid5.Rows[i].Cells["ProPlanId"].Value.ToString2()) { ultraGrid5.Rows[i].Appearance.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192))))); } else { ultraGrid5.Rows[i].Appearance.BackColor = System.Drawing.Color.White; } } } /// 加工选中行事件 /// /// 加工选中行事件 /// private void ultraGrid6_AfterRowActivate(object sender, EventArgs e) { plineID = ultraGrid6.ActiveRow.Cells["ProPlanId"].Value.ToString2(); for (int i = 0; i < ultraGrid6.Rows.Count; i++) { if (plineID == ultraGrid6.Rows[i].Cells["ProPlanId"].Value.ToString2()) { ultraGrid6.Rows[i].Appearance.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192))))); } else { ultraGrid6.Rows[i].Appearance.BackColor = System.Drawing.Color.White; } } } /// 汇总选中行事件 /// /// 汇总选中行事件 /// private void ultraGrid8_AfterRowActivate(object sender, EventArgs e) { plineID = ultraGrid8.ActiveRow.Cells["pro_plan_id"].Value.ToString2(); for (int i = 0; i < ultraGrid8.Rows.Count; i++) { if (plineID == ultraGrid8.Rows[i].Cells["pro_plan_id"].Value.ToString2()) { ultraGrid8.Rows[i].Appearance.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192))))); } else { ultraGrid8.Rows[i].Appearance.BackColor = System.Drawing.Color.White; } } } /// tab页选中行事件 /// /// tab页选中行事件 /// private void ultraTabControl1_SelectedTabChanged(object sender, Infragistics.Win.UltraWinTabControl.SelectedTabChangedEventArgs e) { tab(); } #endregion /// /// 导出 /// private void ExportData() { GridHelper.ulGridToExcel(ultraGrid1, "轧管生产数据统计"); } } }