using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Core.Mes.Client.Common; using Infragistics.Win.UltraWinGrid; using System.Diagnostics; using CoreFS.CA06; using System.Collections; using System.IO; namespace Core.LgMes.Client.LgDeviceManager { public partial class FrmDeviceCycleManage : frmStyleBase { public FrmDeviceCycleManage() { InitializeComponent(); } private bool bEditNow; private UltraGridRow currRow = null; private void FrmDeviceCycleManage_Load(object sender, EventArgs e) { proc_SetToolbarButtons(); _UpdateAfter = new Hashtable(); _UpdateBefore = new Hashtable(); _UpdateColumnName = new Hashtable(); } public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": { if (bEditNow) return; proc_Query(); proc_SetToolbarButtons(); break; } case "Edit": { if ((ultraGrid1.ActiveRow == null && ultraGrid2.ActiveRow == null) || bEditNow) return; if (tabControl1.SelectedIndex == 0) currRow = ultraGrid1.ActiveRow; else currRow = ultraGrid2.ActiveRow; this.proc_setCellReadOnly(currRow, false); bEditNow = true; this.proc_SetToolbarButtons(); break; } case "Save": { if (bEditNow) { proc_Add("Edit"); } proc_Query(); break; } case "Export": { try { if (ultraGrid1.Rows.Count == 0 && ultraGrid2.Rows.Count == 0) return; string strFileName = "设备周期管理" + DateTime.Now.ToString("yyyyMMdd"); SaveFileDialog dlg = new SaveFileDialog(); dlg.Title = "保存"; dlg.OverwritePrompt = true; dlg.Filter = "Excel文件(*.xls)|*.xls"; dlg.AddExtension = true; dlg.FileName = strFileName; if (dlg.ShowDialog() == DialogResult.OK) { strFileName = dlg.FileName; if (tabControl1.SelectedIndex == 0) ultraGridExcelExporter1.Export(ultraGrid1, strFileName); else ultraGridExcelExporter1.Export(ultraGrid2, strFileName); if (MessageBox.Show("数据导出成功!\r\n需要打开所导出文件吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { if (tabControl1.SelectedIndex == 0) ultraGridExcelExporter1.Export(ultraGrid1, strFileName); else ultraGridExcelExporter1.Export(ultraGrid2, strFileName); ProcessStartInfo p = new ProcessStartInfo(strFileName); p.WorkingDirectory = Path.GetDirectoryName(strFileName); Process.Start(p); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } break; } case "Cancel": { if (!(bEditNow)) return; if (MessageBox.Show("确定要取消[修改]操作吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return; if (bEditNow) { this.proc_setCellReadOnly(currRow, true); currRow = null; bEditNow = false; } this.proc_SetToolbarButtons(); break; } case "Close": { this.Close(); break; } } } public void proc_Query() { Cursor oldCursor = this.Cursor; this.Cursor = Cursors.WaitCursor; try { string ccmid = ""; if (tabControl1.SelectedIndex == 0) ccmid = " in ('5','6')"; else ccmid = " = '7'"; string sqlStr = string.Format(@"SELECT * FROM DEV_SXD_USE_INFO WHERE CCMID {0} ORDER BY SEQ_NO", ccmid); //调用服务端方法 CoreClientParam CCP_LgEts = new CoreClientParam(); DataTable dt = new DataTable(); CCP_LgEts.ServerName = "Core.LgMes.Server.Common.ComDBExecute"; CCP_LgEts.MethodName = "doSimpleQuery"; CCP_LgEts.ServerParams = new object[] { sqlStr }; CCP_LgEts.SourceDataTable = dt; this.ExecuteQueryToDataTable(CCP_LgEts, CoreInvokeType.Internal); DataSet ds = new DataSet(); if (tabControl1.SelectedIndex == 0) { if (dt != null && dt.Rows.Count > 0) { this.dataTable1.Rows.Clear(); DataRow dr; for (int iRow = 0; iRow < dt.Rows.Count; iRow++) { dr = this.dataTable1.NewRow(); for (int jCol = 0; jCol < dt.Columns.Count; jCol++) { if (this.dataTable1.Columns.Contains(dt.Columns[jCol].ColumnName)) { dr[dt.Columns[jCol].ColumnName] = dt.Rows[iRow][jCol]; } } this.dataTable1.Rows.Add(dr); } } ultraGrid1.UpdateData(); if (ultraGrid1.Rows.Count > 0) { ultraGrid1.ActiveCell = ultraGrid1.Rows[0].Cells["SEQ_NO"]; ultraGrid1.Rows[0].Cells["SEQ_NO"].Selected = false; } this.proc_SetUltraGridReadOnly(ultraGrid1); if (this.ultraGrid1 != null && ultraGrid1.Rows.Count > 0) { foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in this.ultraGrid1.Rows) { if (row.Cells["SEQ_NO"].Value.ToString().Equals("#强制更换周期")) { row.Cells["SEQ_NO"].Appearance.BackColor = Color.Red; continue; } if (row.Cells["SEQ_NO"].Value.ToString().Equals("#正常更换周期")) { row.Cells["SEQ_NO"].Appearance.BackColor = Color.Yellow; continue; } if (Double.Parse(row.Cells["JJQLJZM"].Value.ToString()) > 180000) row.Cells["JJQLJZM"].Appearance.BackColor = Color.Red; else if (Double.Parse(row.Cells["JJQLJZM"].Value.ToString()) > 150000) row.Cells["JJQLJZM"].Appearance.BackColor = Color.Yellow; else row.Cells["JJQLJZM"].Appearance.BackColor = Color.LightGreen; if (Double.Parse(row.Cells["JJQLJKM"].Value.ToString()) > 180000) row.Cells["JJQLJKM"].Appearance.BackColor = Color.Red; else if (Double.Parse(row.Cells["JJQLJKM"].Value.ToString()) > 150000) row.Cells["JJQLJKM"].Appearance.BackColor = Color.Yellow; else row.Cells["JJQLJKM"].Appearance.BackColor = Color.LightGreen; for (int i = 0; i < 15; i++) { if (row.Cells["SEQ_NO"].Value.ToString().Contains("周期")) break; if (i == 0) { if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 110000) row.Cells[i + "GGL"].Appearance.BackColor = Color.Red; else if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 100000) row.Cells[i + "GGL"].Appearance.BackColor = Color.Yellow; else row.Cells[i + "GGL"].Appearance.BackColor = Color.LightGreen; } if (i > 0 && i < 7) { if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 520000) row.Cells[i + "GGL"].Appearance.BackColor = Color.Red; else if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 460000) row.Cells[i + "GGL"].Appearance.BackColor = Color.Yellow; else row.Cells[i + "GGL"].Appearance.BackColor = Color.LightGreen; } if (i > 6 && i < 9) { if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 410000) row.Cells[i + "GGL"].Appearance.BackColor = Color.Red; else if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 350000) row.Cells[i + "GGL"].Appearance.BackColor = Color.Yellow; else row.Cells[i + "GGL"].Appearance.BackColor = Color.LightGreen; } if (i == 9) { if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 750000) row.Cells[i + "GGL"].Appearance.BackColor = Color.Red; else if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 690000) row.Cells[i + "GGL"].Appearance.BackColor = Color.Yellow; else row.Cells[i + "GGL"].Appearance.BackColor = Color.LightGreen; } if (i > 9 && i < 13) { if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 870000) row.Cells[i + "GGL"].Appearance.BackColor = Color.Red; else if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 810000) row.Cells[i + "GGL"].Appearance.BackColor = Color.Yellow; else row.Cells[i + "GGL"].Appearance.BackColor = Color.LightGreen; } if (i > 12 && i < 15) { if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 1150000) row.Cells[i + "GGL"].Appearance.BackColor = Color.Red; else if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 1040000) row.Cells[i + "GGL"].Appearance.BackColor = Color.Yellow; else row.Cells[i + "GGL"].Appearance.BackColor = Color.LightGreen; } } } } } else { if (dt != null && dt.Rows.Count > 0) { this.dataTable2.Rows.Clear(); DataRow dr; for (int iRow = 0; iRow < dt.Rows.Count; iRow++) { dr = this.dataTable2.NewRow(); for (int jCol = 0; jCol < dt.Columns.Count; jCol++) { if (this.dataTable2.Columns.Contains(dt.Columns[jCol].ColumnName)) { dr[dt.Columns[jCol].ColumnName] = dt.Rows[iRow][jCol]; } } this.dataTable2.Rows.Add(dr); } } ultraGrid2.UpdateData(); if (ultraGrid2.Rows.Count > 0) { ultraGrid2.ActiveCell = ultraGrid2.Rows[0].Cells["SEQ_NO"]; ultraGrid2.Rows[0].Cells["SEQ_NO"].Selected = false; } this.proc_SetUltraGridReadOnly(ultraGrid2); if (this.ultraGrid2 != null && ultraGrid2.Rows.Count > 0) { foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in this.ultraGrid2.Rows) { if (row.Cells["SEQ_NO"].Value.ToString().Equals("#强制更换周期")) { row.Cells["SEQ_NO"].Appearance.BackColor = Color.Red; continue; } if (row.Cells["SEQ_NO"].Value.ToString().Equals("#正常更换周期")) { row.Cells["SEQ_NO"].Appearance.BackColor = Color.Yellow; continue; } if (Double.Parse(row.Cells["JJQLJZM"].Value.ToString()) > 110000) row.Cells["JJQLJZM"].Appearance.BackColor = Color.Red; else if (Double.Parse(row.Cells["JJQLJZM"].Value.ToString()) > 100000) row.Cells["JJQLJZM"].Appearance.BackColor = Color.Yellow; else row.Cells["JJQLJZM"].Appearance.BackColor = Color.LightGreen; if (Double.Parse(row.Cells["JJQLJKM"].Value.ToString()) > 110000) row.Cells["JJQLJKM"].Appearance.BackColor = Color.Red; else if (Double.Parse(row.Cells["JJQLJKM"].Value.ToString()) > 100000) row.Cells["JJQLJKM"].Appearance.BackColor = Color.Yellow; else row.Cells["JJQLJKM"].Appearance.BackColor = Color.LightGreen; for (int i = 1; i < 19; i++) { if (row.Cells["SEQ_NO"].Value.ToString().Contains("周期")) break; if (i > 0 && i < 7) { if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 320000) row.Cells[i + "GGL"].Appearance.BackColor = Color.Red; else if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 300000) row.Cells[i + "GGL"].Appearance.BackColor = Color.Yellow; else row.Cells[i + "GGL"].Appearance.BackColor = Color.LightGreen; } if (i > 6 && i < 11) { if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 270000) row.Cells[i + "GGL"].Appearance.BackColor = Color.Red; else if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 250000) row.Cells[i + "GGL"].Appearance.BackColor = Color.Yellow; else row.Cells[i + "GGL"].Appearance.BackColor = Color.LightGreen; } if (i > 10 && i < 17) { if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 600000) row.Cells[i + "GGL"].Appearance.BackColor = Color.Red; else if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 550000) row.Cells[i + "GGL"].Appearance.BackColor = Color.Yellow; else row.Cells[i + "GGL"].Appearance.BackColor = Color.LightGreen; } if (i == 17) { if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 70000) row.Cells[i + "GGL"].Appearance.BackColor = Color.Red; else if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 60000) row.Cells[i + "GGL"].Appearance.BackColor = Color.Yellow; else row.Cells[i + "GGL"].Appearance.BackColor = Color.LightGreen; } if (i == 18) { if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 80000) row.Cells[i + "GGL"].Appearance.BackColor = Color.Red; else if (Double.Parse(row.Cells[i + "GGL"].Value.ToString()) > 70000) row.Cells[i + "GGL"].Appearance.BackColor = Color.Yellow; else row.Cells[i + "GGL"].Appearance.BackColor = Color.LightGreen; } } } } } } catch { } finally { this.Cursor = oldCursor; } } public void proc_Add(string flag) { try { this.ultraGrid1.UpdateData(); this.ultraGrid2.UpdateData(); if (dataTable1.Rows.Count > 0 || dataTable2.Rows.Count > 0) { string strErr = ""; string strMess = ""; if (flag == "Edit") { ArrayList arryColumn = new ArrayList(); ArrayList arryValue = new ArrayList(); string strCCMID, strSEQ = ""; if (tabControl1.SelectedIndex == 0) { strCCMID = this.ultraGrid1.ActiveRow.Cells["CCMID"].Text.Trim(); strSEQ = this.ultraGrid1.ActiveRow.Cells["SEQ_NO"].Text.Trim(); for (int intCount = 0; intCount < ultraGrid1.DisplayLayout.Bands[0].Columns.Count; intCount++) { string strKey = ultraGrid1.DisplayLayout.Bands[0].Columns[intCount].Key.ToString(); //判断是否修改过 if (_UpdateColumnName.ContainsKey(strKey) && _UpdateColumnName.ContainsValue(ultraGrid1.DisplayLayout.Bands[0].Columns[intCount].Header.Caption)) { arryColumn.Add(strKey); arryValue.Add((this.ultraGrid1.ActiveRow.Cells[strKey].Value.ToString().Trim().Length > 0) ? this.ultraGrid1.ActiveRow.Cells[strKey].Value.ToString() : "Empty"); } } } else { strCCMID = this.ultraGrid2.ActiveRow.Cells["CCMID"].Text.Trim(); strSEQ = this.ultraGrid2.ActiveRow.Cells["SEQ_NO"].Text.Trim(); for (int intCount = 0; intCount < ultraGrid2.DisplayLayout.Bands[0].Columns.Count; intCount++) { string strKey = ultraGrid2.DisplayLayout.Bands[0].Columns[intCount].Key.ToString(); //判断是否修改过 if (_UpdateColumnName.ContainsKey(strKey) && _UpdateColumnName.ContainsValue(ultraGrid2.DisplayLayout.Bands[0].Columns[intCount].Header.Caption)) { arryColumn.Add(strKey); arryValue.Add((this.ultraGrid2.ActiveRow.Cells[strKey].Value.ToString().Trim().Length > 0) ? this.ultraGrid2.ActiveRow.Cells[strKey].Value.ToString() : "Empty"); } } } string strSqlID = "SaveSxdData.Update"; object[] sArgs = new object[4]; sArgs[0] = strCCMID; //熔炼号 sArgs[1] = strSEQ; //岗位 sArgs[2] = arryColumn; //作业字段名 sArgs[3] = arryValue; //作业数据值 string strError = ""; DialogResult result = DialogResult.No; result = MessageBox.Show(this, "确实要保存信息吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == DialogResult.Yes) { Cursor oldCursor = this.Cursor; this.Cursor = Cursors.WaitCursor;//等待光标 try { CommonClientToServer ccTs = new CommonClientToServer(); ccTs.ob = ob; string strRCode = ccTs.ExecuteProcedureFunctions("Core.LgMes.Server.Common.ComDBProcedure", "ExecProcWithCollParam", strSqlID, sArgs, out strError); if (strError != "") { _UpdateColumnName.Clear(); _UpdateBefore.Clear(); _UpdateAfter.Clear(); this.Cursor = oldCursor; MessageBox.Show("保存不成功!\n" + strError, "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { this.Cursor = oldCursor; if (_UpdateColumnName != null && _UpdateColumnName.Count > 0) { _UpdateColumnName.Clear(); _UpdateBefore.Clear(); _UpdateAfter.Clear(); } } } catch (System.Exception exp) { _UpdateColumnName.Clear(); _UpdateBefore.Clear(); _UpdateAfter.Clear(); this.Cursor = oldCursor; MessageBox.Show("保存不成功!\n" + exp.ToString(), "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } this.proc_setCellReadOnly(currRow, true); currRow = null; bEditNow = false; } if (strErr == "") { dataTable1.AcceptChanges(); //JJBStaticFunction.SetRowEdit(ultraGrid1); if (!string.IsNullOrEmpty(strMess)) MessageBox.Show(strMess, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { MessageBox.Show("保存失败!输入信息已经存在或数据无效。", "错误"); } if (ultraGrid1.ActiveCell != null) ultraGrid1.ActiveCell.Activated = false; this.proc_SetToolbarButtons(); } } catch (System.Exception ex) { Console.WriteLine(ex.ToString()); } } private void proc_SetToolbarButtons() { try { this.ToolBarItemEnable(this, "Query", !bEditNow); this.ToolBarItemEnable(this, "Edit", (!bEditNow && (ultraGrid1.ActiveRow != null || ultraGrid2.ActiveRow != null))); this.ToolBarItemEnable(this, "Export", (!(bEditNow) && (ultraGrid1.Rows.Count > 0 || ultraGrid2.Rows.Count > 0))); this.ToolBarItemEnable(this, "Save", bEditNow); this.ToolBarItemEnable(this, "Cancel", bEditNow); } catch { } } private void proc_setCellReadOnly(UltraGridRow row, bool bReadOnly) { try { if (row == null) return; if (bReadOnly) { row.Activation = Activation.ActivateOnly; row.CellAppearance.BackColor = Color.White; foreach (Infragistics.Win.UltraWinGrid.UltraGridCell cell in row.Cells) { cell.CancelUpdate(); } } else { row.Activation = Activation.AllowEdit; row.CellAppearance.BackColor = Color.Khaki; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void proc_SetUltraGridReadOnly(Infragistics.Win.UltraWinGrid.UltraGridBase ultGrid) { foreach (UltraGridRow row in ultGrid.Rows) { row.Activation = Activation.ActivateOnly; } } private Hashtable _UpdateBefore; //修改之前值 private Hashtable _UpdateAfter; //修改之后值 private Hashtable _UpdateColumnName; //修改字段名 private void ultraGrid1_BeforeCellUpdate(object sender, BeforeCellUpdateEventArgs e) { if (!string.IsNullOrEmpty(e.Cell.Column.Header.Caption.Trim())) { if (_UpdateBefore != null && _UpdateBefore.Contains(e.Cell.Column.Key)) { _UpdateBefore.Remove(e.Cell.Column.Key); _UpdateColumnName.Remove(e.Cell.Column.Key); } _UpdateBefore.Add(e.Cell.Column.Key, e.Cell.Value.ToString()); _UpdateColumnName.Add(e.Cell.Column.Key, e.Cell.Column.Header.Caption); } } private void ultraGrid2_BeforeCellUpdate(object sender, BeforeCellUpdateEventArgs e) { if (!string.IsNullOrEmpty(e.Cell.Column.Header.Caption.Trim())) { if (_UpdateBefore != null && _UpdateBefore.Contains(e.Cell.Column.Key)) { _UpdateBefore.Remove(e.Cell.Column.Key); _UpdateColumnName.Remove(e.Cell.Column.Key); } _UpdateBefore.Add(e.Cell.Column.Key, e.Cell.Value.ToString()); _UpdateColumnName.Add(e.Cell.Column.Key, e.Cell.Column.Header.Caption); } } private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { _UpdateAfter = new Hashtable(); _UpdateBefore = new Hashtable(); _UpdateColumnName = new Hashtable(); } } }