using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Collections; using System.IO; using System.Diagnostics; using Infragistics.Win.UltraWinGrid; using CoreFS.CA06; using Core.Mes.Client.Common; using Core.LgMes.Client.Comm; namespace Core.LgMes.Client.LgResMgt { public partial class frmCutInfoAssit : frmStyleBase { private bool bAddNow, bEditNow, bDelNow; //是否在进行新增、修改或者删除操作 private UltraGridRow currRow = null; private CoreClientParam par; private string strReturn = "ExecuteCommand_Return"; public frmCutInfoAssit() { InitializeComponent(); } private void frmCutInfoAssit_Load(object sender, EventArgs e) { proc_Init(); proc_Query("", -1); proc_SetToolbarButtons(); } private void proc_Init() { try { ultraDateTimeEditor1.DateTime = DateTime.Today; ultraDateTimeEditor2.DateTime = DateTime.Today; par = new CoreClientParam(); par.ServerName = "lgResMgt.Core.LgMes.Server.LgResMgt"; par.MethodName = "classResCommonModule"; //par.ClassName = "Core.LgMes.Server.LgResMgt.classResCommonModule"; } catch (Exception ex) { MessageBox.Show("初始化失败!\r\n" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); if (MessageBox.Show("点击[是]将重新初始化,强烈建议执行此操作!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { proc_Init(); } } } private void proc_SetToolbarButtons() { try { ultraToolbarsManager1.Toolbars[0].Tools["QUERY"].SharedProps.Enabled = !(bAddNow || bEditNow || bDelNow); ultraToolbarsManager1.Toolbars[0].Tools["NEW"].SharedProps.Enabled = !(bAddNow || bEditNow || bDelNow); ultraToolbarsManager1.Toolbars[0].Tools["MODIFY"].SharedProps.Enabled = (!(bAddNow || bEditNow || bDelNow) && (ultraGrid1.ActiveRow != null)); ultraToolbarsManager1.Toolbars[0].Tools["DEL"].SharedProps.Enabled = (!(bAddNow || bEditNow || bDelNow) && (ultraGrid1.ActiveRow != null)); ultraToolbarsManager1.Toolbars[0].Tools["EXPORT"].SharedProps.Enabled = (!(bAddNow || bEditNow || bDelNow) && ultraGrid1.Rows.Count > 0); ultraToolbarsManager1.Toolbars[0].Tools["SAVE"].SharedProps.Enabled = (bAddNow || bEditNow); ultraToolbarsManager1.Toolbars[0].Tools["CANCEL"].SharedProps.Enabled = (bAddNow || bEditNow); ultraToolbarsManager1.Toolbars[0].Tools["SAVE"].SharedProps.Visible = (bAddNow || bEditNow); ultraToolbarsManager1.Toolbars[0].Tools["CANCEL"].SharedProps.Visible = (bAddNow || bEditNow); } catch { } } private void proc_SetUltraGridReadOnly(Infragistics.Win.UltraWinGrid.UltraGridBase ultGrid) { foreach (UltraGridRow row in ultGrid.Rows) { row.Activation = Activation.ActivateOnly; } } 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; row.Cells["CATEGORY"].Activation = Activation.AllowEdit; row.Cells["LENGTH"].Activation = Activation.AllowEdit; row.Cells["THICKNESS"].Activation = Activation.AllowEdit; row.Cells["WIDTH"].Activation = Activation.AllowEdit; row.Cells["WEIGHT"].Activation = Activation.AllowEdit; row.Cells["CUTTIME"].Activation = Activation.AllowEdit; row.Cells["BILLETNO"].Activation = Activation.ActivateOnly; row.Cells["SERIALNUM"].Activation = Activation.ActivateOnly; row.Cells["HEATNO"].Activation = Activation.ActivateOnly; row.Cells["BOOKER"].Activation = Activation.ActivateOnly; row.Cells["OPTDATE"].Activation = Activation.ActivateOnly; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void proc_Query(string strBilletNo, int iSerialNum) { Cursor oldCursor = this.Cursor; this.Cursor = Cursors.WaitCursor; try { string strFrom = ultraDateTimeEditor1.DateTime.ToString("yyyy-MM-dd"); string strTo = ultraDateTimeEditor2.DateTime.ToString("yyyy-MM-dd"); string strWhere = "where to_char(CUTTIME, 'yyyy-MM-dd') between '" + strFrom + "' and '" + strTo + "'"; string str = ""; str = ultraTextEditor1.Text.Trim(); if (str.Length > 0) strWhere += " and BILLETNO = '" + str + "'"; str = ultraTextEditor2.Text.Trim(); if (str.Length > 0) strWhere += " and HEATNO = '" + str + "'"; string strErr = ""; string strSql = "select BILLETNO, HEATNO, CATEGORY, " + "LENGTH, THICKNESS, WIDTH, WEIGHT, CUTTIME, BOOKER, OPTDATE, SERIALNUM " + "from JOB_INCISION_ASSIST " + strWhere + " order by CUTTIME desc, BILLETNO, SERIALNUM desc"; par.MethodName = strReturn; par.ServerParams = new object[] { strSql }; DataSet ds = null;//hengxing ClientCommon._RemotingHelp.ExecuteMethod(par, out strErr) as DataSet; if (strErr != "" || !(ds != null && ds.Tables.Count > 0)) { MessageBox.Show("数据加载失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); if (MessageBox.Show("是否重新加载数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) proc_Query(strBilletNo, iSerialNum); return; } if (ds != null && ds.Tables.Count > 0) { this.dataTable1.Rows.Clear(); DataRow dr; for (int iRow = 0; iRow < ds.Tables[0].Rows.Count; iRow++) { dr = this.dataTable1.NewRow(); for (int jCol = 0; jCol < ds.Tables[0].Columns.Count; jCol++) { dr[ds.Tables[0].Columns[jCol].ColumnName] = Convert.ToString(ds.Tables[0].Rows[iRow][jCol]); } this.dataTable1.Rows.Add(dr); } ultraGrid1.UpdateData(); } this.proc_SetUltraGridReadOnly(ultraGrid1); if (ultraGrid1.Rows.Count > 0) { ultraGrid1.ActiveCell = ultraGrid1.Rows[0].Cells["HEATNO"]; ultraGrid1.Rows[0].Cells["HEATNO"].Selected = false; } if (strBilletNo.Trim().Length == 0) return; int iNum = 0; for (int i = 0; i < ultraGrid1.Rows.Count; i++) { str = Convert.ToString(ultraGrid1.Rows[i].Cells["BILLETNO"].Value); iNum = Convert.ToInt32(ultraGrid1.Rows[i].Cells["SERIALNUM"].Value); if (str == strBilletNo && iNum == iSerialNum) { ultraGrid1.ActiveCell = ultraGrid1.Rows[i].Cells["BILLETNO"]; ultraGrid1.Rows[i].Cells["BILLETNO"].Selected = false; return; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { this.Cursor = oldCursor; } } private bool proc_CheckData(ref UltraGridRow row, out string strErr, out ArrayList alist) { strErr = ""; alist = new ArrayList(); try { if (row == null) { strErr = "未明确定义数据!"; return false; } string str = ""; decimal dValue = 0.0M; str = Convert.ToString(row.Cells["BILLETNO"].Value).Trim(); if (str.Length == 0) { strErr = "请选择坯料号!"; ultraGrid1.ActiveCell = row.Cells["BILLETNO"]; return false; } alist.Add(str); str = Convert.ToString(row.Cells["SERIALNUM"].Value).Trim(); alist.Add(str); str = Convert.ToString(row.Cells["HEATNO"].Value).Trim(); alist.Add(str); str = Convert.ToString(row.Cells["CATEGORY"].Value).Trim(); if (str.Length == 0) { strErr = "请选择类别!"; ultraGrid1.ActiveCell = row.Cells["CATEGORY"]; return false; } alist.Add(str); str = Convert.ToString(row.Cells["LENGTH"].Value).Trim(); if (str.Length > 0 && !decimal.TryParse(str, out dValue)) { strErr = "长度不正确!"; ultraGrid1.ActiveCell = row.Cells["LENGTH"]; return false; } alist.Add(str); str = Convert.ToString(row.Cells["THICKNESS"].Value).Trim(); if (str.Length > 0 && !decimal.TryParse(str, out dValue)) { strErr = "厚度不正确!"; ultraGrid1.ActiveCell = row.Cells["THICKNESS"]; return false; } alist.Add(str); str = Convert.ToString(row.Cells["WIDTH"].Value).Trim(); if (str.Length > 0 && !decimal.TryParse(str, out dValue)) { strErr = "宽度不正确!"; ultraGrid1.ActiveCell = row.Cells["WIDTH"]; return false; } alist.Add(str); str = Convert.ToString(row.Cells["WEIGHT"].Value).Trim(); if (str.Length > 0 && !decimal.TryParse(str, out dValue)) { strErr = "重量不正确!"; ultraGrid1.ActiveCell = row.Cells["WEIGHT"]; return false; } alist.Add(str); str = Convert.ToString(row.Cells["CUTTIME"].Value).Trim(); if (str.Length == 0) { strErr = "请录入切割时间!"; ultraGrid1.ActiveCell = row.Cells["CUTTIME"]; return false; } alist.Add(str); alist.Add(this.UserInfo.GetUserName()); } catch (Exception ex) { strErr = ex.Message.ToString(); return false; } return true; } private void proc_Add() { try { if (currRow == null) return; ultraGrid1.UpdateData(); string strMsg = ""; ArrayList alist; if (!this.proc_CheckData(ref currRow, out strMsg, out alist)) { MessageBox.Show(strMsg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.ultraGrid1.Focus(); this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false, false); return; } par.MethodName = "CutInfoAssit_Add"; par.ServerParams = new object[] { alist }; int iNum = 0;//hengxing (int)ClientCommon._RemotingHelp.ExecuteMethod(par, out strMsg); if (iNum < 0) { MessageBox.Show("实绩信息保存失败!\r\n" + strMsg, "出错", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.proc_setCellReadOnly(currRow, true); this.proc_Query(alist[0].ToString(), iNum); currRow = null; bAddNow = false; this.proc_SetToolbarButtons(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void proc_Edit() { try { if (currRow == null) return; ultraGrid1.UpdateData(); string strMsg = ""; ArrayList alist; if (!this.proc_CheckData(ref currRow, out strMsg, out alist)) { MessageBox.Show(strMsg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.ultraGrid1.Focus(); this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false, false); return; } par.MethodName = "CutInfoAssit_Edit"; par.ServerParams = new object[] { alist }; int iFlag = 0;//hengxing (int)ClientCommon._RemotingHelp.ExecuteMethod(par, out strMsg); if (iFlag < 0) { MessageBox.Show("实绩信息保存失败!\r\n" + strMsg, "出错", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.proc_setCellReadOnly(currRow, true); this.proc_Query(alist[0].ToString(), Convert.ToInt32(alist[1].ToString())); currRow = null; bEditNow = false; this.proc_SetToolbarButtons(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void proc_Delete() { try { if (this.ultraGrid1.Rows.Count == 0) return; if (this.ultraGrid1.ActiveRow == null) { MessageBox.Show("请选择要删除的实绩信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (MessageBox.Show("确定要删除所选实绩信息吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return; UltraGridRow row = ultraGrid1.ActiveRow; ArrayList alist = new ArrayList(); alist.Add(Convert.ToString(row.Cells["BILLETNO"].Value)); alist.Add(Convert.ToString(row.Cells["SERIALNUM"].Value)); par.MethodName = "CutInfoAssit_Del"; par.ServerParams = new object[] { alist }; string strMsg = ""; int iFlag = 0;//hengxing (int)ClientCommon._RemotingHelp.ExecuteMethod(par, out strMsg); if (iFlag < 0) { MessageBox.Show("实绩信息删除失败!\r\n" + strMsg, "出错", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.proc_Query("", -1); } catch (Exception ex) { MessageBox.Show(ex.Message); } } public override void ToolBar_Click(object sender, string ToolbarKey) { base.ToolBar_Click(sender, ToolbarKey); switch (ToolbarKey) { case "Exit": this.Close(); break; default: break; } } private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e) { switch (e.Tool.Key) { case "QUERY": { if (bAddNow || bEditNow || bDelNow) return; proc_Query("", -1); proc_SetToolbarButtons(); break; } case "NEW": { if (bAddNow || bEditNow || bDelNow) return; currRow = this.ultraGrid1.DisplayLayout.Bands[0].AddNew(); this.proc_setCellReadOnly(currRow, false); currRow.Cells["CUTTIME"].Value = DateTime.Now; bAddNow = true; ultraGrid1.ActiveCell = currRow.Cells["BILLETNO"]; currRow.Cells["BILLETNO"].Selected = false; this.proc_SetToolbarButtons(); break; } case "MODIFY": { if (ultraGrid1.ActiveRow == null || (bAddNow || bEditNow || bDelNow)) return; currRow = ultraGrid1.ActiveRow; this.proc_setCellReadOnly(currRow, false); bEditNow = true; ultraGrid1.ActiveCell = currRow.Cells["BILLETNO"]; currRow.Cells["BILLETNO"].Selected = false; currRow.Cells["BILLETNO"].Tag = currRow.Cells["BILLETNO"].Value; currRow.Cells["HEATNO"].Tag = currRow.Cells["HEATNO"].Value; currRow.Cells["CATEGORY"].Tag = currRow.Cells["CATEGORY"].Value; currRow.Cells["LENGTH"].Tag = currRow.Cells["LENGTH"].Value; currRow.Cells["THICKNESS"].Tag = currRow.Cells["THICKNESS"].Value; currRow.Cells["WIDTH"].Tag = currRow.Cells["WIDTH"].Value; currRow.Cells["WEIGHT"].Tag = currRow.Cells["WEIGHT"].Value; currRow.Cells["CUTTIME"].Tag = currRow.Cells["CUTTIME"].Value; this.proc_SetToolbarButtons(); break; } case "DEL": { if (ultraGrid1.ActiveRow == null || (bAddNow || bEditNow || bDelNow)) return; bDelNow = true; this.proc_SetToolbarButtons(); proc_Delete(); bDelNow = false; this.proc_SetToolbarButtons(); break; } case "SAVE": { if (bAddNow) { proc_Add(); } else if (bEditNow) { proc_Edit(); } break; } case "CANCEL": { if (!(bAddNow || bEditNow)) return; string strOpt = " [" + (bAddNow ? "新增" : (bEditNow ? "修改" : "")) + "]"; if (MessageBox.Show("确定要取消" + strOpt + "操作吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return; if (bAddNow) { currRow.Delete(false); currRow = null; if (ultraGrid1.Rows.Count > 0) { ultraGrid1.ActiveCell = ultraGrid1.Rows[ultraGrid1.Rows.Count - 1].Cells["BILLETNO"]; ultraGrid1.Rows[ultraGrid1.Rows.Count - 1].Cells["BILLETNO"].Selected = false; } bAddNow = false; } else if (bEditNow) { this.proc_setCellReadOnly(currRow, true); currRow.Cells["BILLETNO"].Value = currRow.Cells["BILLETNO"].Tag; currRow.Cells["HEATNO"].Value = currRow.Cells["HEATNO"].Tag; currRow.Cells["CATEGORY"].Value = currRow.Cells["CATEGORY"].Tag; currRow.Cells["LENGTH"].Value = currRow.Cells["LENGTH"].Tag; currRow.Cells["THICKNESS"].Value = currRow.Cells["THICKNESS"].Tag; currRow.Cells["WIDTH"].Value = currRow.Cells["WIDTH"].Tag; currRow.Cells["WEIGHT"].Value = currRow.Cells["WEIGHT"].Tag; currRow.Cells["CUTTIME"].Value = currRow.Cells["CUTTIME"].Tag; ultraGrid1.ActiveCell = currRow.Cells["BILLETNO"]; currRow.Cells["BILLETNO"].Selected = false; currRow = null; bEditNow = false; } this.proc_SetToolbarButtons(); break; } case "EXPORT": { if ((bAddNow || bEditNow || bDelNow) || ultraGrid1.Rows.Count <= 0) return; bool bInstalled = (Type.GetTypeFromProgID("Excel.Application") != null); if (!bInstalled) { MessageBox.Show("系统没有安装EXCEL组件,无法导出数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } string strFileName = Application.StartupPath + "\\Report\\切头、切尾、边角料实绩表.xls"; ultraGridExcelExporter1.Export(ultraGrid1, strFileName); ProcessStartInfo p = new ProcessStartInfo(strFileName); p.WorkingDirectory = Path.GetDirectoryName(strFileName); Process.Start(p); break; } case "CLOSE": { this.Close(); break; } } } private void frmCutInfoAssit_FormClosing(object sender, FormClosingEventArgs e) { try { if (bAddNow) { if (MessageBox.Show("[新增]操作尚未完成,确定要关闭吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) e.Cancel = true; else bAddNow = false; } else if (bEditNow) { if (MessageBox.Show("[修改]操作尚未完成,确定要关闭吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) e.Cancel = true; else bEditNow = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void ultraTextEditor_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e) { try { Infragistics.Win.UltraWinEditors.UltraTextEditor ultraTextEditor = (Infragistics.Win.UltraWinEditors.UltraTextEditor)sender; if (ultraTextEditor == null) return; if (ultraTextEditor.Text.Trim().Length > 0) { ultraTextEditor.Tag = ultraTextEditor.Text.Trim(); ultraTextEditor.Text = ""; } else { if (ultraTextEditor.Tag != null) { ultraTextEditor.Text = Convert.ToString(ultraTextEditor.Tag); } } } catch { } } private void ultraGrid1_ClickCellButton(object sender, CellEventArgs e) { try { if (!(bAddNow || bEditNow)) return; if (e.Cell == null) return; if (e.Cell != currRow.Cells[e.Cell.Column.Key]) return; if (e.Cell.Row.Index < 0) return; switch (e.Cell.Column.Key) { case "BILLETNO": { if (bAddNow) //修改记录时不能修改坯料号 { frmSelBillet frm = new frmSelBillet(); frm.ShowDialog(); if (frm.DialogResult == DialogResult.OK && frm.alstReturn != null) { this.currRow.Cells["BILLETNO"].Value = frm.alstReturn[0]; this.currRow.Cells["HEATNO"].Value = frm.alstReturn[1]; if (Convert.ToString(this.currRow.Cells["CATEGORY"].Value) == "01" || Convert.ToString(this.currRow.Cells["CATEGORY"].Value) == "02") { this.currRow.Cells["THICKNESS"].Value = frm.alstReturn[2]; this.currRow.Cells["WIDTH"].Value = frm.alstReturn[3]; } this.currRow.Cells["THICKNESS"].Tag = frm.alstReturn[2]; this.currRow.Cells["WIDTH"].Tag = frm.alstReturn[3]; } } break; } case "CUTTIME": { frmSetTime frm = new frmSetTime(e.Cell.Value); frm.Location = CStaticMethod.GetChildWindowLocation(frm.Size); frm.ShowDialog(); if (frm._returnTime > new DateTime(2000, 1, 1, 0, 0, 0)) e.Cell.Value = frm._returnTime; break; } } } catch { } } private void ultraGrid_CellListSelect(object sender, CellEventArgs e) { try { if (!bAddNow) return; if (e.Cell == null) return; if (e.Cell.Row.Index < 0) return; if (e.Cell.Column.Key != "CATEGORY") return; ultraGrid1.UpdateData(); if (Convert.ToString(e.Cell.Value) == "01" || Convert.ToString(e.Cell.Value) == "02") { if (this.currRow.Cells["THICKNESS"].Tag != null) this.currRow.Cells["THICKNESS"].Value = Convert.ToString(this.currRow.Cells["THICKNESS"].Tag); if (this.currRow.Cells["WIDTH"].Tag != null) this.currRow.Cells["WIDTH"].Value = Convert.ToString(this.currRow.Cells["WIDTH"].Tag); } } catch { } } private void ultraGrid_CellChange(object sender, CellEventArgs e) { try { if (!bAddNow && !bEditNow) return; if (e.Cell == null) return; if (e.Cell.Row.Index < 0) return; if (e.Cell.Column.Key != "LENGTH" && e.Cell.Column.Key != "THICKNESS" && e.Cell.Column.Key != "WIDTH" && e.Cell.Column.Key != "WEIGHT") return; string strText = Convert.ToString(e.Cell.Text.Trim()); if (strText.Length > 0) { decimal dValue = 0.0M; if (!decimal.TryParse(strText, out dValue)) { MessageBox.Show("无效数字!", e.Cell.Column.Header.Caption, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); e.Cell.CancelUpdate(); } } } catch { } } private void ultraGrid_AfterCellActivate(object sender, EventArgs e) { try { if (!bAddNow && !bEditNow) return; this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false, false); } catch { } } } }