| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368 |
- using System;
- using System.Collections;
- using System.Drawing;
- using System.Windows.Forms;
- using CoreFS.CA06;
- using Infragistics.Win;
- using Infragistics.Win.UltraWinGrid;
- namespace Core.StlMes.Client.LgCommon
- {
- public partial class ucResBase : UserControl
- {
- private Hashtable _htValueInitial = null; //初始值
- private Hashtable _htValueChanged = null; //修改后的值
- private Hashtable _htDatatypeChanged = null; //修改字段数据类型
- private Hashtable _htCaptionChanged = null; //修改字段中文名
- /// <summary>
- /// 初始值
- /// </summary>
- public Hashtable htValueInitial
- {
- get { return _htValueInitial; }
- }
- /// <summary>
- /// 值发生变化列表
- /// </summary>
- public Hashtable htValueChanged
- {
- get
- {
- ultraGrid1.UpdateData();
- return _htValueChanged;
- }
- }
- /// <summary>
- /// 修改字段数据类型
- /// </summary>
- public Hashtable htDatatypeChanged
- {
- get
- {
- ultraGrid1.UpdateData();
- return _htDatatypeChanged;
- }
- }
- /// <summary>
- /// 值发生变化的字段名
- /// </summary>
- public Hashtable htCaptionChanged
- {
- get
- {
- ultraGrid1.UpdateData();
- return _htCaptionChanged;
- }
- }
- /// <summary>
- /// 有值发生变化
- /// </summary>
- public bool HasChanged
- {
- get
- {
- ultraGrid1.UpdateData();
- return (_htValueChanged != null && _htValueChanged.Count > 0);
- }
- }
- public ucResBase()
- {
- InitializeComponent();
- ClsControlPack.SetUltraGridStyle(ultraGrid1, 1);
- ClsControlPack.InitUserControl(this.ultraDataSource1, ultraGrid1);
- }
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
- //SetControlDelegate();
- InitValuelist();
- ResetData();
- }
- protected virtual void InitValuelist()
- {
- try
- {
- if (ClsControlPack.GridContainsColumn(ultraGrid1, "SHIFTCODE"))
- {
- ValueList vlist = ClsBusinessPack.GetValuelistShift();
- ClsControlPack.SetGridValuelist(ref ultraGrid1, "SHIFTCODE", ref vlist);
- }
- if (ClsControlPack.GridContainsColumn(ultraGrid1, "POTDISTINCTION"))
- {
- ValueList vlist1 = ClsBusinessPack.GetValuelistPotLevel();
- ClsControlPack.SetGridValuelist(ref ultraGrid1, "POTDISTINCTION", ref vlist1);
- }
- if (ClsControlPack.GridContainsColumn(ultraGrid1, "POTWRAPSTATE"))
- {
- ValueList vlist2 = ClsBusinessPack.GetValuelistPotStatus();
- ClsControlPack.SetGridValuelist(ref ultraGrid1, "POTWRAPSTATE", ref vlist2);
- }
- if (ClsControlPack.GridContainsColumn(ultraGrid1, "BILLETSECTION"))
- {
- ValueList vlist3 = ClsBusinessPack.GetValuelistBilletSection();
- ClsControlPack.SetGridValuelist(ref ultraGrid1, "BILLETSECTION", ref vlist3);
- }
- }
- catch { }
- }
- public void SetValuelistSteel(OpeBase ob)
- {
- try
- {
- ValueList vlist = ClsBusinessPack.GetValuelistSteel(ob);
- ClsControlPack.SetGridValuelist(ref ultraGrid1, "GRADECODE", ref vlist);
- }
- catch { }
- }
- protected virtual void SetControlDelegate()
- {
- ultraGrid1.ClickCellButton += new CellEventHandler(ultraGrid1_ClickCellButton);
- ultraGrid1.KeyDown += new KeyEventHandler(ultraGrid1_KeyDown);
- ultraGrid1.CellListSelect += new CellEventHandler(ultraGrid1_CellListSelect);
- ultraGrid1.AfterCellUpdate += new CellEventHandler(ultraGrid1_AfterCellUpdate);
- ultraGrid1.CellChange += new CellEventHandler(ultraGrid1_CellChange);
- }
- protected virtual void ultraGrid1_ClickCellButton(object sender, CellEventArgs e)
- {
- try
- {
- if (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;
- ultraGrid1.UpdateData();
- }
- }
- }
- catch { }
- }
- protected virtual void ultraGrid1_CellChange(object sender, CellEventArgs e)
- {
- try
- {
- if (!e.Cell.Column.Hidden && e.Cell.Column.CellActivation == Activation.AllowEdit)
- {
- ultraGrid1.UpdateData();
- if (string.IsNullOrEmpty(Convert.ToString(e.Cell.Text)))
- {
- ultraGrid1.PerformAction(UltraGridAction.ExitEditMode);
- ultraGrid1.PerformAction(UltraGridAction.EnterEditMode);
- }
- }
- }
- catch { }
- }
- protected virtual void ultraGrid1_KeyDown(object sender, KeyEventArgs e)
- {
- try
- {
- UltraGridCell cell = ultraGrid1.ActiveCell;
- if (e.KeyCode != Keys.Enter || cell.Column.CellActivation != Activation.AllowEdit) return;
- ultraGrid1.UpdateData();
- }
- catch { }
- }
- protected virtual void ultraGrid1_CellListSelect(object sender, CellEventArgs e)
- {
- try
- {
- if (!e.Cell.Column.Hidden && e.Cell.Column.CellActivation == Activation.AllowEdit)
- ultraGrid1.UpdateData();
- }
- catch { }
- }
- protected virtual void ultraGrid1_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;
- if (_htValueInitial != null && _htValueInitial.Contains(strKey)) valueInitial = _htValueInitial[strKey];
- if (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;
- }
- }
- catch { }
- }
- protected void SetUltraGridActiveCell(string ColumnName)
- {
- try
- {
- if (ultraGrid1.Rows.Count > 0)
- {
- ultraGrid1.Rows[0].Cells[ColumnName].Activated = true;
- ultraGrid1.PerformAction(UltraGridAction.EnterEditMode);
- }
- }
- catch { }
- }
- public virtual void ResetData()
- {
- ClsControlPack.ResetUltraDataSource(this.ultraDataSource1, ultraGrid1);
- try
- {
- InitHashtable(ref _htValueInitial);
- string strKey = "";
- object Value = null;
- for (int i = 0; i < ultraDataSource1.Band.Columns.Count; i++)
- {
- strKey = this.ultraDataSource1.Band.Columns[i].Key;
- try
- {
- Value = this.ultraDataSource1.Rows[0][strKey];
- _htValueInitial.Add(strKey, Value);
- }
- catch { }
- try
- {
- ultraGrid1.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(Hashtable ar)
- {
- try
- {
- if (ar == null || ar.Count == 0)
- {
- ResetData();
- return;
- }
- string strKey = "";
- object Value = DBNull.Value;
-
- InitHashtable(ref _htValueInitial);
- for (int i = 0; i < ultraDataSource1.Band.Columns.Count; i++)
- {
- strKey = this.ultraDataSource1.Band.Columns[i].Key;
- try
- {
- if (!_htValueInitial.Contains(strKey)) _htValueInitial.Add(strKey, "");
- if (ar.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"]));
- }
- }
- ultraDataSource1.Rows[0][i] = Value;
- _htValueInitial[strKey] = Value;
- }
- else
- {
- this.ultraDataSource1.Rows[0][i] = DBNull.Value;
- _htValueInitial[strKey] = DBNull.Value;
- }
- }
- catch { }
- try
- {
- ultraGrid1.Rows[0].Cells[strKey].Appearance.ResetBackColor();
- }
- catch { }
- }
- try
- {
- if (_htValueChanged != null) _htValueChanged.Clear();
- if (_htDatatypeChanged != null) _htDatatypeChanged.Clear();
- if (_htCaptionChanged != null) _htCaptionChanged.Clear();
- }
- catch { }
- }
- catch { }
- }
- protected void InitHashtable(ref Hashtable htbl)
- {
- if (htbl == null) htbl = new Hashtable();
- }
- }
- }
|