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; //修改字段中文名
///
/// 初始值
///
public Hashtable htValueInitial
{
get { return _htValueInitial; }
}
///
/// 值发生变化列表
///
public Hashtable htValueChanged
{
get
{
ultraGrid1.UpdateData();
return _htValueChanged;
}
}
///
/// 修改字段数据类型
///
public Hashtable htDatatypeChanged
{
get
{
ultraGrid1.UpdateData();
return _htDatatypeChanged;
}
}
///
/// 值发生变化的字段名
///
public Hashtable htCaptionChanged
{
get
{
ultraGrid1.UpdateData();
return _htCaptionChanged;
}
}
///
/// 有值发生变化
///
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();
}
}
}