using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Globalization; using System.IO; using System.Linq; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.Text; using System.Windows.Forms; using Core.Mes.Client.Comm.Server; using Core.Mes.Client.Comm.Tool; using Core.StlMes.Client.LgClassModel; using CoreFS.CA06; using Infragistics.Win; using Infragistics.Win.UltraWinGrid; namespace Core.StlMes.Client.LgCommon { /// /// 实绩管理响应炉号选中事件 /// public delegate void OperationOver(); public delegate void OperationBegin(); public partial class ucNewResBase : UserControl { public ucNewResBase() { InitializeComponent(); ClsControlPack.SetUltraGridStyle(ugData, 1); } public event OperationOver OperationOver; public event OperationBegin OperationBegin; public bool bOperationOver; protected OpeBase Ob; protected string _operator = ""; protected string _shiftCode = ""; protected string _stove = ""; protected string _station = ""; protected LG_PROCESS _process; private List allowSave = new List() { true, true, true, true }; //是否允许修改实绩 public bool AllowSave { get { return allowSave.All(p=>p); } } private object _htValueInitial = null; //初始值 private Hashtable _htValueChanged = null; //修改后的值 private Hashtable _htDatatypeChanged = null; //修改字段数据类型 private Hashtable _htCaptionChanged = null; //修改字段中文名 public void SetBase(OpeBase ob, string Operator, string ShifCode, LG_PROCESS Process) { Ob = ob; _operator = Operator; _shiftCode = ShifCode; _process = Process; } /// /// 初始值 /// public object htValueInitial { get { return _htValueInitial; } } /// /// 值发生变化列表 /// public Hashtable htValueChanged { get { ugData.UpdateData(); return _htValueChanged; } } /// /// 修改字段数据类型 /// public Hashtable htDatatypeChanged { get { ugData.UpdateData(); return _htDatatypeChanged; } } /// /// 值发生变化的字段名 /// public Hashtable htCaptionChanged { get { ugData.UpdateData(); return _htCaptionChanged; } } /// /// 有值发生变化 /// public bool HasChanged { get { ugData.UpdateData(); return (_htValueChanged != null && _htValueChanged.Count > 0); } } protected override void OnLoad(EventArgs e) { base.OnLoad(e); SetControlDelegate(); InitValuelist(); ResetData(); } protected virtual void InitValuelist() { try { if (ClsControlPack.GridContainsColumn(ugData, "SHIFTCODE")) { ValueList vlist = ClsBusinessPack.GetValuelistShift(); ClsControlPack.SetGridValuelist(ref ugData, "SHIFTCODE", ref vlist); } if (ClsControlPack.GridContainsColumn(ugData, "POTDISTINCTION")) { ValueList vlist1 = ClsBusinessPack.GetValuelistPotLevel(); ClsControlPack.SetGridValuelist(ref ugData, "POTDISTINCTION", ref vlist1); } if (ClsControlPack.GridContainsColumn(ugData, "POTWRAPSTATE")) { ValueList vlist2 = ClsBusinessPack.GetValuelistPotStatus(); ClsControlPack.SetGridValuelist(ref ugData, "POTWRAPSTATE", ref vlist2); } if (ClsControlPack.GridContainsColumn(ugData, "BILLETSECTION")) { ValueList vlist3 = ClsBusinessPack.GetValuelistBilletSection(); ClsControlPack.SetGridValuelist(ref ugData, "BILLETSECTION", ref vlist3); } if (ClsControlPack.GridContainsColumn(ugData, "MOLIRNTYPE")) { ValueList vlist3 = ClsBusinessPack.GetValuelistIronSourceForBOF(); ClsControlPack.SetGridValuelist(ref ugData, "MOLIRNTYPE", ref vlist3); } } catch { } } public void SetValuelistSteel(OpeBase ob) { try { ValueList vlist = ClsBusinessPack.GetValuelistSteel(ob); ClsControlPack.SetGridValuelist(ref ugData, "GRADECODE", ref vlist); } catch { } } protected virtual void SetControlDelegate() { ugData.ClickCellButton += new CellEventHandler(ugData_ClickCellButton); ugData.KeyDown += new KeyEventHandler(ugData_KeyDown); ugData.CellListSelect += new CellEventHandler(ugData_CellListSelect); ugData.AfterCellUpdate += new CellEventHandler(ugData_AfterCellUpdate); ugData.CellChange += new CellEventHandler(ugData_CellChange); ugData.KeyPress +=ugData_KeyPress; ugData.CellDataError +=ugData_CellDataError; } private void ugData_CellDataError(object sender, CellDataErrorEventArgs e) { e.RestoreOriginalValue = true; e.RaiseErrorEvent = false; } private void ugData_KeyPress(object sender, KeyPressEventArgs e) { if(this.ugData.ActiveCell==null) return; string strKey = this.ugData.ActiveCell.Column.ToString(); if (strKey == "POTNO" || strKey == "POTAGE") { if (!(Char.IsNumber(e.KeyChar) && ugData.ActiveRow.Cells[strKey].Value.ToString().Length <= 3) && e.KeyChar != '\b') { e.Handled = true; } } if (strKey == "OGGNUMID" || strKey == "GAGE" || strKey == "SAGE" || strKey == "BLOWO2TIMES" || strKey == "EMOLSTLTIME" || strKey == "IRONPOTID") { if (!(Char.IsNumber(e.KeyChar) && ugData.ActiveRow.Cells[strKey].Value.ToString().Length <= 6) && e.KeyChar != '\b') { e.Handled = true; } } if (strKey == "RSSTOVENO") { if (!(Char.IsNumber(e.KeyChar) && ugData.ActiveRow.Cells[strKey].Value.ToString().Length <= 8) && e.KeyChar != '\b') { e.Handled = true; } } if (strKey == "IRONPOTWGT" || strKey == "IRONTEMPERATURE" || strKey == "WSTEELWGT" || strKey == "PIGIRONWGT" || strKey == "O2CONSUME" || strKey == "TOPN2CONSUME" || strKey == "TERMINUSC" || strKey == "TERMINUSO2" || strKey == "TERMINUSTEPT" || strKey == "RSWGT") { if (!(e.KeyChar == '\b') && ugData.ActiveRow.Cells[strKey].Value.ToString().Length >= 6) { e.Handled = true; } if (!(Char.IsNumber(e.KeyChar) || e.KeyChar == '\b' || e.KeyChar == '.')) { e.Handled = true; } if (e.KeyChar == '.') { char[] arrary = ugData.ActiveRow.Cells[strKey].Text.ToCharArray(); if (arrary.Length == 0) { ugData.ActiveRow.Cells[strKey].Value = "0."; ugData.ActiveRow.Cells[strKey].SelStart = ugData.ActiveRow.Cells[strKey].Value.ToString().Length; e.Handled = true; } else { for (int i = 0; i < arrary.Length; i++) { if (arrary[i] == '.') e.Handled = true; } } } } if (strKey == "MEMO") { char[] arrary = ugData.ActiveRow.Cells[strKey].Text.ToCharArray(); if (!(e.KeyChar == '\b') && arrary.Length >= 40) { // MessageBox.Show("生产记事不能超过40个字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); e.Handled = true; } } if (strKey == "PROTECTDTEG") { char[] arrary = ugData.ActiveRow.Cells[strKey].Text.ToCharArray(); if (!(e.KeyChar == '\b') && arrary.Length >= 10) { // MessageBox.Show("保护渣名称不能超过10个字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); e.Handled = true; } } } protected virtual void ugData_ClickCellButton(object sender, CellEventArgs e) { try { if (e.Cell.Column.DataType == typeof(DateTime) || e.Cell.Column.DataType == typeof(DateTime?) ) { /* frmSetTime frm = new frmSetTime(e.Cell.Value); frm.Location = ClsControlPack.GetChildWindowLocation(frm.Size); if (frm.ShowDialog() == DialogResult.OK) { e.Cell.Value = frm.SelectDate; ugData.UpdateData(); }*/ //e.Cell.Value = DateTime.Now; DateTime dataValue = ClsBusinessPack.GetServerDateTime(Ob); if (ugData.Rows[0].Cells.Exists("OPTDATE")) { var vaule = ugData.Rows[0].Cells["OPTDATE"].Value; DateTime? OpdateDate = null; if (vaule != null) { OpdateDate = (DateTime?) vaule; } if (OpdateDate != null) { dataValue = DateTime.ParseExact( ((DateTime) OpdateDate).ToString("yyyy-MM-dd ") + dataValue.ToString("HH:mm:ss"), "yyyy-MM-dd HH:mm:ss", null); } } e.Cell.Value = dataValue; } else if (e.Cell.Column.DataType == typeof(Decimal) || e.Cell.Column.DataType == typeof(Decimal?)) { frmInputDecimal frm = new frmInputDecimal(Convert.ToString(e.Cell.Text)); frm.Location = ClsControlPack.GetChildWindowLocation(frm.Size); if (frm.ShowDialog() == DialogResult.OK) { if (!frm.ValueChanged) return; e.Cell.Value = frm.Value; ugData.UpdateData(); } } else if (e.Cell.Column.Key.Equals("Potno", StringComparison.OrdinalIgnoreCase) || e.Cell.Column.Key.Equals("Vacgrooveid", StringComparison.OrdinalIgnoreCase) ||e.Cell.Column.Key.Equals("Basketetno1", StringComparison.OrdinalIgnoreCase) ||e.Cell.Column.Key.Equals("Basketetno2", StringComparison.OrdinalIgnoreCase) ||e.Cell.Column.Key.Equals("Basketetno3", StringComparison.OrdinalIgnoreCase) || e.Cell.Column.Key.Equals("Basketetno4", StringComparison.OrdinalIgnoreCase) || e.Cell.Column.Key.Equals("BasketetNum", StringComparison.OrdinalIgnoreCase) || e.Cell.Column.Key.Equals("PotNum", StringComparison.OrdinalIgnoreCase) || e.Cell.Column.Key.Equals("Pot1Wgt", StringComparison.OrdinalIgnoreCase) || e.Cell.Column.Key.Equals("Pot2Wgt", StringComparison.OrdinalIgnoreCase) || e.Cell.Column.Key.Equals("Pot3Wgt", StringComparison.OrdinalIgnoreCase) ) { frmHeatNoEditor frm = new frmHeatNoEditor(); frm.InputText = Convert.ToString(e.Cell.Text); frm.Location = ClsControlPack.GetChildWindowLocation(frm.Size); if (frm.ShowDialog() == DialogResult.OK) { e.Cell.Value = frm.InputText; ugData.UpdateData(); } } } catch { } } protected virtual void ugData_CellChange(object sender, CellEventArgs e) { try { if (!e.Cell.Column.Hidden && e.Cell.Column.CellActivation == Activation.AllowEdit) { if (e.Cell.Column.DataType == typeof(DateTime) || e.Cell.Column.DataType == typeof(DateTime?) && Convert.ToString(e.Cell.Text).Contains("_")) { return; } ugData.UpdateData(); if (e.Cell.Column.Key.ToUpper() == "REPOSEBEGINTIME" && ugData.Rows[0].Cells["REPOSEBEGINTIME"].Value != null) { /* DateTime now = ClsBusinessPack.GetServerDateTime(Ob); DateTime dt1 = (DateTime)ugData.Rows[0].Cells["REPOSEBEGINTIME"].Value; if (dt1.Hour >= 20 && now.Hour <= 9) { now= now.AddDays(-1); ugData.Rows[0].Cells["OPTDATE"].Value = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second); ugData.Rows[0].Cells["REPOSEBEGINTIME"].Value = new DateTime(now.Year, now.Month, now.Day, dt1.Hour, dt1.Minute, dt1.Second); }*/ } if (e.Cell.Column.Key.ToUpper() == "OPTDATE") { try { if (ugData.Rows[0].Cells.Exists("REPOSEBEGINTIME") && ugData.Rows[0].Cells["REPOSEBEGINTIME"].Value != null) { DateTime opdt = (DateTime) ugData.Rows[0].Cells["OPTDATE"].Value; DateTime dt1 = (DateTime)ugData.Rows[0].Cells["REPOSEBEGINTIME"].Value; ugData.Rows[0].Cells["REPOSEBEGINTIME"].Value = new DateTime(opdt.Year,opdt.Month,opdt.Day, dt1.Hour,dt1.Minute,dt1.Second); } } catch (Exception) { } try { if (ugData.Rows[0].Cells.Exists("REPOSEENDTIME") && ugData.Rows[0].Cells["REPOSEENDTIME"].Value != null) { DateTime opdt = (DateTime)ugData.Rows[0].Cells["OPTDATE"].Value; DateTime dt1 = (DateTime)ugData.Rows[0].Cells["REPOSEENDTIME"].Value; ugData.Rows[0].Cells["REPOSEENDTIME"].Value = new DateTime(opdt.Year, opdt.Month, opdt.Day, dt1.Hour, dt1.Minute, dt1.Second); } } catch (Exception) { } ugData.UpdateData(); } /* try { if (ugData.Rows[0].Cells.Exists("REPOSEBEGINTIME") && ugData.Rows[0].Cells["REPOSEBEGINTIME"].Value != null && ugData.Rows[0].Cells.Exists("REPOSEENDTIME") && ugData.Rows[0].Cells["REPOSEENDTIME"].Value != null) { DateTime dt1 = (DateTime)ugData.Rows[0].Cells["REPOSEBEGINTIME"].Value; DateTime dt2 = (DateTime)ugData.Rows[0].Cells["REPOSEENDTIME"].Value; if (DateTime.Compare(dt1, dt2) > 0) dt2= dt2.AddDays(1); ugData.Rows[0].Cells["REPOSEENDTIME"].Value = dt2; ugData.UpdateData(); } } catch (Exception) { }*/ if (string.IsNullOrEmpty(Convert.ToString(e.Cell.Text))) { ugData.PerformAction(UltraGridAction.ExitEditMode); ugData.PerformAction(UltraGridAction.EnterEditMode); } } } catch { } } protected virtual void ugData_KeyDown(object sender, KeyEventArgs e) { try { UltraGridCell cell = ugData.ActiveCell; if (e.KeyCode != Keys.Enter || cell.Column.CellActivation != Activation.AllowEdit) return; ugData.UpdateData(); } catch { } } protected virtual void ugData_CellListSelect(object sender, CellEventArgs e) { try { if (!e.Cell.Column.Hidden && e.Cell.Column.CellActivation == Activation.AllowEdit) ugData.UpdateData(); } catch { } } protected virtual void ugData_AfterCellUpdate(object sender, CellEventArgs e) { try { if (!e.Cell.Column.Hidden && e.Cell.Column.CellActivation == Activation.AllowEdit) { InitHashtable(ref _htValueChanged); InitHashtable(ref _htDatatypeChanged); InitHashtable(ref _htCaptionChanged); string strKey = e.Cell.Column.Key.ToUpper(); string strCaption = e.Cell.Column.Header.Caption; Type type = e.Cell.Column.DataType; object value = e.Cell.Value; object valueInitial = null; var vaule = _htValueInitial.GetType().GetProperties().Where(p => p.Name.ToUpper() == strKey).ToList(); if (vaule.Any()) { var firstOrDefault = vaule.FirstOrDefault(); if (firstOrDefault != null) valueInitial = firstOrDefault.GetValue(_htValueInitial,null); } ; if ((value==null && valueInitial==null) || (value!=null && value.Equals(valueInitial))) { if (_htValueChanged.Contains(strKey)) _htValueChanged.Remove(strKey); if (_htDatatypeChanged.Contains(strKey)) _htDatatypeChanged.Remove(strKey); if (_htCaptionChanged.Contains(strKey)) _htCaptionChanged.Remove(strKey); try { e.Cell.Appearance.ResetBackColor(); } catch { } return; } try { e.Cell.Appearance.BackColor = Color.Orange; } catch { } if (!_htValueChanged.Contains(strKey)) _htValueChanged.Add(strKey, value); else _htValueChanged[strKey] = value; if (!_htDatatypeChanged.Contains(strKey)) _htDatatypeChanged.Add(strKey, type); else _htDatatypeChanged[strKey] = type; if (!_htCaptionChanged.Contains(strKey)) _htCaptionChanged.Add(strKey, strCaption); else _htCaptionChanged[strKey] = strCaption; if (!e.Cell.Column.Hidden && e.Cell.Column.CellActivation == Activation.AllowEdit) { UltraGridRow row = e.Cell.Row; if (strKey.Equals("REPOSEBEGINTIME", StringComparison.OrdinalIgnoreCase) || strKey.Equals("REPOSEENDTIME", StringComparison.OrdinalIgnoreCase)) { ugData.ActiveRow.Cells["REPOSETIME"].Value = null; if (row.Cells["REPOSEBEGINTIME"].Value == null && row.Cells["REPOSEENDTIME"].Value != null) { ugData.Rows[0].Cells["REPOSEBEGINTIME"].Value = ClsBusinessPack.GetLastOptionTime(Ob, _process); /* e.Cell.Appearance.BackColor = Color.Red; MessageBox.Show("不能没有处理开始时间", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); allowSave[1] = false;*/ } /* if (row.Cells["REPOSEBEGINTIME"].Value == null) return; DateTime Start = (DateTime) ugData.ActiveRow.Cells["REPOSEBEGINTIME"].Value; if (strKey.Equals("REPOSEBEGINTIME", StringComparison.OrdinalIgnoreCase) && valueInitial==null ) { if (!bOperationOver) { bOperationOver = true; saveDate(); if (OperationBegin != null) OperationBegin(); bOperationOver = false; return; } } if (row.Cells["REPOSEENDTIME"].Value == null) return; DateTime End = (DateTime) ugData.ActiveRow.Cells["REPOSEENDTIME"].Value; if (Start > End) { e.Cell.Appearance.BackColor = Color.Red; MessageBox.Show("处理结束时间不能早于开始时间", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); allowSave[1] = false; } else { if (ugData.ActiveRow.Cells["REPOSEBEGINTIME"].Appearance.BackColor == Color.Red) { ugData.ActiveRow.Cells["REPOSEBEGINTIME"].Appearance.BackColor = Color.Orange; } if (ugData.ActiveRow.Cells["REPOSEENDTIME"].Appearance.BackColor == Color.Red) { ugData.ActiveRow.Cells["REPOSEENDTIME"].Appearance.BackColor = Color.Orange; } allowSave[1] = true; ugData.ActiveRow.Cells["REPOSETIME"].Value = decimal.Parse(End.Subtract(Start) .TotalSeconds.ToString(CultureInfo.InvariantCulture)); } if (allowSave.All(p=>p) && strKey.Equals("REPOSEENDTIME", StringComparison.OrdinalIgnoreCase) && valueInitial == null) { if (bOperationOver) return; bOperationOver = true; saveDate(); if (OperationOver != null) { if (MessageBox.Show(@"该炉已经结束,是否切至下一炉", @"提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) OperationOver(); } bOperationOver = false; }*/ } else if (strKey.Equals("BALEPFTIME", StringComparison.OrdinalIgnoreCase) || strKey.Equals("BALELEAVETIME", StringComparison.OrdinalIgnoreCase)) { // ugData.ActiveRow.Cells["REPOSETIME"].Value = null; if (row.Cells["BALEPFTIME"].Value == null && row.Cells["BALELEAVETIME"].Value != null) { ugData.Rows[0].Cells["BALEPFTIME"].Value = ClsBusinessPack.GetLastOptionTime(Ob, _process); /* e.Cell.Appearance.BackColor = Color.Red; MessageBox.Show("不能没有到站时间", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); allowSave[1] = false;*/ } /* if (row.Cells["BALEPFTIME"].Value == null) return; DateTime Start = (DateTime)ugData.ActiveRow.Cells["BALEPFTIME"].Value; if (strKey.Equals("BALEPFTIME", StringComparison.OrdinalIgnoreCase) && valueInitial == null) { if (!bOperationOver) { bOperationOver = true; saveDate(); if (OperationBegin != null) OperationBegin(); bOperationOver = false; return; } } if (row.Cells["BALELEAVETIME"].Value == null) return; DateTime End = (DateTime)ugData.ActiveRow.Cells["BALELEAVETIME"].Value; if (Start > End) { e.Cell.Appearance.BackColor = Color.Red; MessageBox.Show("离站时间不能早于到站时间", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); allowSave[1] = false; } else { if (ugData.ActiveRow.Cells["BALEPFTIME"].Appearance.BackColor == Color.Red) { ugData.ActiveRow.Cells["BALEPFTIME"].Appearance.BackColor = Color.Orange; } if (ugData.ActiveRow.Cells["BALELEAVETIME"].Appearance.BackColor == Color.Red) { ugData.ActiveRow.Cells["BALELEAVETIME"].Appearance.BackColor = Color.Orange; } allowSave[1] = true; } if (allowSave.All(p => p) && strKey.Equals("BALELEAVETIME", StringComparison.OrdinalIgnoreCase) && valueInitial == null && allowSave[1]) { if (bOperationOver) return; bOperationOver = true; saveDate(); if (OperationOver != null) { if (MessageBox.Show(@"该炉已经结束,是否切至下一炉", @"提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) OperationOver(); } bOperationOver = false; }*/ } } } } catch { } } protected void SetUltraGridActiveCell(string ColumnName) { try { if (ugData.Rows.Count > 0) { ugData.Rows[0].Cells[ColumnName].Activated = true; ugData.PerformAction(UltraGridAction.EnterEditMode); } } catch { } } public virtual void ResetData() { DatabindingSource.Clear(); try { //string strKey = ""; //object Value = null; //for (int i = 0; i < ugData.DisplayLayout.Bands[0].Columns.Count; i++) //{ // try // { // ugData.Rows[0].Cells[strKey].Appearance.ResetBackColor(); // } // catch { } //} } catch { } finally { if (_htValueChanged != null) _htValueChanged.Clear(); if (_htDatatypeChanged != null) _htDatatypeChanged.Clear(); if (_htCaptionChanged != null) _htCaptionChanged.Clear(); } } public virtual void SetData(List ar) { try { for (int i = 0; i < allowSave.Count; i++) { allowSave[i] = true; } if (ar == null || ar.Count == 0) { ResetData(); return; } string strKey = ""; _htValueInitial = Clone(ar[0]); //.Clone(); ClsControlPack.SaftRefreshUI(ugData, () => { DatabindingSource.DataSource = ar; }); //for (int i = 0; i < ugData.DisplayLayout.Bands[0].Columns.Count; i++) //{ //strKey = this.ugData.DisplayLayout.Bands[0].Columns[i].Key; //try //{ // if (!_htValueInitial.Contains(strKey)) _htValueInitial.Add(strKey, ""); // if (ar[0].GetType().GetProperties() .Contains(strKey)) // { // Value = ar[strKey]; // if (strKey == "FACT_ROUTE") // Value = ClsBusinessPack.analysPath(Convert.ToString(Value)); // if (strKey == "OPTDATE") // Value = Convert.ToDateTime(Value).ToString("yyyy-MM-dd HH:mm:ss"); // if (strKey == "SUPPLYOXYGENTIME") // { // if (Value != "") // { // TimeSpan ts = new TimeSpan(0, 0, Convert.ToInt32(Value)); // string tsMin = ts.Minutes.ToString(); // string tsSen = ts.Seconds.ToString(); // Value = tsMin + "′" + tsSen + "″"; // } // else // { // Value =ClsDataAccessPack.GetTimeSpan(Convert.ToDateTime(ar["OPENOXYGENTIME"]), Convert.ToDateTime(ar["STOPOXYGENTIME"])); // } // } // ugData.Rows[0].Cells[i].Value = Value; // } // else // { // ugData.Rows[0].Cells[i].Value = DBNull.Value; // } //} //catch { } // try // { // ugData.Rows[0].Cells[strKey].Appearance.ResetBackColor(); // } // catch { } //} try { if (_htValueChanged != null) { _htValueChanged.Clear(); foreach (var VARIABLE in ugData.Rows[0].Cells) { VARIABLE.Appearance.ResetBackColor(); } } if (_htDatatypeChanged != null) _htDatatypeChanged.Clear(); if (_htCaptionChanged != null) _htCaptionChanged.Clear(); } catch { } } catch { } } private object Clone(object ob) { using (MemoryStream ms = new MemoryStream(1000)) { object CloneObject; BinaryFormatter bf = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.Clone)); bf.Serialize(ms, ob); ms.Seek(0, SeekOrigin.Begin); // 反序列化至另一个对象(即创建了一个原对象的深表副本) CloneObject = bf.Deserialize(ms); // 关闭流 ms.Close(); return CloneObject; } } protected void InitHashtable(ref Hashtable htbl) { if (htbl == null) htbl = new Hashtable(); } protected virtual void Refresh() { } public bool saveDate() { if (!(_htValueChanged != null && _htValueChanged.Count > 0)) return true; if (ugData.Rows[0].Cells.Exists("MOULDBALEWGT") && ugData.Rows[0].Cells["MOULDBALEWGT"].Value == null && ugData.Rows[0].Cells.Exists("BALELEAVETIME") && ugData.Rows[0].Cells["BALELEAVETIME"].Value != null) { MessageBox.Show(@"请维护钢水量"); return false; } else { if (ugData.Rows[0].Cells.Exists("MOULDBALEWGT") && ugData.Rows[0].Cells["MOULDBALEWGT"].Value != null && double.Parse(ugData.Rows[0].Cells["MOULDBALEWGT"].Value.ToString()) > 160) { MessageBox.Show(@"钢水量不能超过160吨"); return false; } } if (ugData.Rows[0].Cells.Exists("TAPPINGWGT") && ugData.Rows[0].Cells["TAPPINGWGT"].Value == null && ugData.Rows[0].Cells.Exists("REPOSEENDTIME") && ugData.Rows[0].Cells["REPOSEENDTIME"].Value != null) { MessageBox.Show(@"请维护出钢量"); return false; } if (ugData.Rows[0].Cells.Exists("REPOSEBEGINTIME") && !ugData.DisplayLayout.Bands[0].Columns["REPOSEBEGINTIME"].Hidden && ugData.Rows[0].Cells["REPOSEBEGINTIME"].Value == null) { if (MessageBox.Show(@"没有处理开始时间,是否删除该实绩", @"提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) try { ServerHelper.SetData("Core.LgMes.Server.LgDeviceManager.PerformanceManage.DeletePerformance", new object[] { _process, _stove }, Ob); Refresh(); return true; } catch (Exception ex) { return false; } return false; } if (ugData.Rows[0].Cells.Exists("BALEPFTIME") && !ugData.DisplayLayout.Bands[0].Columns["BALEPFTIME"].Hidden && ugData.Rows[0].Cells["BALEPFTIME"].Value == null) { if (MessageBox.Show(@"没有到站时间,是否删除该实绩", @"提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) try { ServerHelper.SetData("Core.LgMes.Server.LgDeviceManager.PerformanceManage.DeletePerformance", new object[] { _process, _stove }, Ob); Refresh(); return true; } catch (Exception ex) { return false; } return false; } DateTime dataValue = ClsBusinessPack.GetServerDateTime(Ob); if (ugData.Rows[0].Cells.Exists("REPOSEBEGINTIME") && !ugData.DisplayLayout.Bands[0].Columns["REPOSEBEGINTIME"].Hidden && ugData.Rows[0].Cells["REPOSEBEGINTIME"].Value != null) { DateTime dt1 = DateTime.Parse(ugData.Rows[0].Cells["REPOSEBEGINTIME"].Value.ToString2()); if (dt1.Year != dataValue.Year) { if ( MessageBox.Show("处理开始时间的年份与当前系统时间年份不一致,是否继续保存数据", @"提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) return false; } else { TimeSpan d3 = dataValue.Subtract(dt1); if (d3.Days > 1 || d3.Days < -1) { if ( MessageBox.Show("处理开始时间与当前时间相差" + Math.Abs(d3.Days) + "天,是否继续保存数据", @"提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) return false; } } } if (ugData.Rows[0].Cells.Exists("REPOSEENDTIME") && !ugData.DisplayLayout.Bands[0].Columns["REPOSEENDTIME"].Hidden && ugData.Rows[0].Cells["REPOSEENDTIME"].Value != null) { DateTime dt1 = DateTime.Parse(ugData.Rows[0].Cells["REPOSEENDTIME"].Value.ToString2()); if (dt1.Year != dataValue.Year) { if ( MessageBox.Show("处理结束时间的年份与当前系统时间年份不一致,是否继续保存数据", @"提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) return false; } else { TimeSpan d3 = dataValue.Subtract(dt1); if (d3.Days > 1 || d3.Days < -1) { if ( MessageBox.Show("处理结束时间与当前时间相差" + Math.Abs(d3.Days) + "天,是否继续保存数据", @"提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) return false; } } } if (ugData.Rows[0].Cells.Exists("BALESTARTTIME") && !ugData.DisplayLayout.Bands[0].Columns["BALESTARTTIME"].Hidden && ugData.Rows[0].Cells["BALESTARTTIME"].Value != null) { DateTime dt1 = DateTime.Parse(ugData.Rows[0].Cells["BALESTARTTIME"].Value.ToString2()); if (dt1.Year != dataValue.Year) { if ( MessageBox.Show("大包开浇时间的年份与当前系统时间年份不一致,是否继续保存数据", @"提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) return false; } else { TimeSpan d3 = dataValue.Subtract(dt1); if (d3.Days > 1 || d3.Days < -1) { if ( MessageBox.Show("大包开浇时间与当前时间相差" + Math.Abs(d3.Days) + "天,是否继续保存数据", @"提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) return false; } } } if (ugData.Rows[0].Cells.Exists("BALELEAVETIME") && !ugData.DisplayLayout.Bands[0].Columns["BALELEAVETIME"].Hidden && ugData.Rows[0].Cells["BALELEAVETIME"].Value != null) { DateTime dt1 = DateTime.Parse(ugData.Rows[0].Cells["BALELEAVETIME"].Value.ToString2()); if (dt1.Year != dataValue.Year) { if ( MessageBox.Show("大包停浇时间的年份与当前系统时间年份不一致,是否继续保存数据", @"提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) return false; } else { TimeSpan d3 = dataValue.Subtract(dt1); if (d3.Days > 1 || d3.Days < -1) { if ( MessageBox.Show("大包停浇时间与当前时间相差" + Math.Abs(d3.Days) + "天,是否继续保存数据", @"提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) return false; } } } var Args = new List { _process, _stove, _station, "01" }.Concat(GetDataChanged()) .ToArray(); int iRet = 0; string strMsg = ""; try { ServerHelper.SetData("Core.LgMes.Server.LgDeviceManager.PerformanceManage.SavePerformance", Args, Ob); Refresh(); return true; } catch (Exception ex) { return false; } } public List GetDataChanged() { List alColumns = new DataSourceList(); List alDataTypes = new DataSourceList(); List alValueCur = new DataSourceList(); List alValuePre = new DataSourceList(); List alChinese = new DataSourceList(); try { var keys = new ArrayList(); if ((htValueChanged != null) && (htValueChanged.Count > 0)) keys = new ArrayList(htValueChanged.Keys); object valueCur = null; foreach (var t1 in keys) { var strKey = Convert.ToString(t1); var datatype = (Type) htDatatypeChanged[strKey]; var strChinese = Convert.ToString(htCaptionChanged[strKey]); if (htValueChanged != null) valueCur = htValueChanged[strKey]; object valuePre = DBNull.Value; var vaule = htValueInitial.GetType().GetProperties().Where(p => p.Name.ToUpper() == strKey).ToList(); if (vaule.Any()) { var firstOrDefault = vaule.FirstOrDefault(); if (firstOrDefault != null) valuePre = firstOrDefault.GetValue(htValueInitial, null); } var strValueCur = ""; if (valueCur == DBNull.Value || valueCur==null) strValueCur = ""; else { if (valueCur != null) strValueCur = (datatype != typeof(DateTime) && datatype != typeof(DateTime?)) ? Convert.ToString(valueCur) : valueCur == null ? "" : ((DateTime)valueCur).ToString("yyyy-MM-dd HH:mm:ss"); } string strValuePre; if (valuePre == DBNull.Value|| valueCur==null) strValuePre = ""; else strValuePre = (datatype != typeof(DateTime) && datatype!=typeof(DateTime?)) ? Convert.ToString(valuePre) : valuePre==null?"": ((DateTime) valuePre).ToString("yyyy-MM-dd HH:mm:ss"); if (strKey == "SHIFTCODE") { _shiftCode = strValueCur; } else { alColumns.Add(strKey); alDataTypes.Add(datatype.FullName); alValueCur.Add(strValueCur); alValuePre.Add(strValuePre); alChinese.Add(strChinese); } } } catch { // ignored } return new List() { alColumns, alDataTypes, alValueCur, alValuePre, alChinese, _operator,_shiftCode }; } } }