ucResBase.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. using System;
  2. using System.Collections;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using CoreFS.CA06;
  6. using Infragistics.Win;
  7. using Infragistics.Win.UltraWinGrid;
  8. namespace Core.StlMes.Client.LgCommon
  9. {
  10. public partial class ucResBase : UserControl
  11. {
  12. private Hashtable _htValueInitial = null; //初始值
  13. private Hashtable _htValueChanged = null; //修改后的值
  14. private Hashtable _htDatatypeChanged = null; //修改字段数据类型
  15. private Hashtable _htCaptionChanged = null; //修改字段中文名
  16. /// <summary>
  17. /// 初始值
  18. /// </summary>
  19. public Hashtable htValueInitial
  20. {
  21. get { return _htValueInitial; }
  22. }
  23. /// <summary>
  24. /// 值发生变化列表
  25. /// </summary>
  26. public Hashtable htValueChanged
  27. {
  28. get
  29. {
  30. ultraGrid1.UpdateData();
  31. return _htValueChanged;
  32. }
  33. }
  34. /// <summary>
  35. /// 修改字段数据类型
  36. /// </summary>
  37. public Hashtable htDatatypeChanged
  38. {
  39. get
  40. {
  41. ultraGrid1.UpdateData();
  42. return _htDatatypeChanged;
  43. }
  44. }
  45. /// <summary>
  46. /// 值发生变化的字段名
  47. /// </summary>
  48. public Hashtable htCaptionChanged
  49. {
  50. get
  51. {
  52. ultraGrid1.UpdateData();
  53. return _htCaptionChanged;
  54. }
  55. }
  56. /// <summary>
  57. /// 有值发生变化
  58. /// </summary>
  59. public bool HasChanged
  60. {
  61. get
  62. {
  63. ultraGrid1.UpdateData();
  64. return (_htValueChanged != null && _htValueChanged.Count > 0);
  65. }
  66. }
  67. public ucResBase()
  68. {
  69. InitializeComponent();
  70. ClsControlPack.SetUltraGridStyle(ultraGrid1, 1);
  71. ClsControlPack.InitUserControl(this.ultraDataSource1, ultraGrid1);
  72. }
  73. protected override void OnLoad(EventArgs e)
  74. {
  75. base.OnLoad(e);
  76. //SetControlDelegate();
  77. InitValuelist();
  78. ResetData();
  79. }
  80. protected virtual void InitValuelist()
  81. {
  82. try
  83. {
  84. if (ClsControlPack.GridContainsColumn(ultraGrid1, "SHIFTCODE"))
  85. {
  86. ValueList vlist = ClsBusinessPack.GetValuelistShift();
  87. ClsControlPack.SetGridValuelist(ref ultraGrid1, "SHIFTCODE", ref vlist);
  88. }
  89. if (ClsControlPack.GridContainsColumn(ultraGrid1, "POTDISTINCTION"))
  90. {
  91. ValueList vlist1 = ClsBusinessPack.GetValuelistPotLevel();
  92. ClsControlPack.SetGridValuelist(ref ultraGrid1, "POTDISTINCTION", ref vlist1);
  93. }
  94. if (ClsControlPack.GridContainsColumn(ultraGrid1, "POTWRAPSTATE"))
  95. {
  96. ValueList vlist2 = ClsBusinessPack.GetValuelistPotStatus();
  97. ClsControlPack.SetGridValuelist(ref ultraGrid1, "POTWRAPSTATE", ref vlist2);
  98. }
  99. if (ClsControlPack.GridContainsColumn(ultraGrid1, "BILLETSECTION"))
  100. {
  101. ValueList vlist3 = ClsBusinessPack.GetValuelistBilletSection();
  102. ClsControlPack.SetGridValuelist(ref ultraGrid1, "BILLETSECTION", ref vlist3);
  103. }
  104. }
  105. catch { }
  106. }
  107. public void SetValuelistSteel(OpeBase ob)
  108. {
  109. try
  110. {
  111. ValueList vlist = ClsBusinessPack.GetValuelistSteel(ob);
  112. ClsControlPack.SetGridValuelist(ref ultraGrid1, "GRADECODE", ref vlist);
  113. }
  114. catch { }
  115. }
  116. protected virtual void SetControlDelegate()
  117. {
  118. ultraGrid1.ClickCellButton += new CellEventHandler(ultraGrid1_ClickCellButton);
  119. ultraGrid1.KeyDown += new KeyEventHandler(ultraGrid1_KeyDown);
  120. ultraGrid1.CellListSelect += new CellEventHandler(ultraGrid1_CellListSelect);
  121. ultraGrid1.AfterCellUpdate += new CellEventHandler(ultraGrid1_AfterCellUpdate);
  122. ultraGrid1.CellChange += new CellEventHandler(ultraGrid1_CellChange);
  123. }
  124. protected virtual void ultraGrid1_ClickCellButton(object sender, CellEventArgs e)
  125. {
  126. try
  127. {
  128. if (e.Cell.Column.DataType == typeof(DateTime))
  129. {
  130. frmSetTime frm = new frmSetTime(e.Cell.Value);
  131. frm.Location = ClsControlPack.GetChildWindowLocation(frm.Size);
  132. if (frm.ShowDialog() == DialogResult.OK)
  133. {
  134. e.Cell.Value = frm.SelectDate;
  135. ultraGrid1.UpdateData();
  136. }
  137. }
  138. }
  139. catch { }
  140. }
  141. protected virtual void ultraGrid1_CellChange(object sender, CellEventArgs e)
  142. {
  143. try
  144. {
  145. if (!e.Cell.Column.Hidden && e.Cell.Column.CellActivation == Activation.AllowEdit)
  146. {
  147. ultraGrid1.UpdateData();
  148. if (string.IsNullOrEmpty(Convert.ToString(e.Cell.Text)))
  149. {
  150. ultraGrid1.PerformAction(UltraGridAction.ExitEditMode);
  151. ultraGrid1.PerformAction(UltraGridAction.EnterEditMode);
  152. }
  153. }
  154. }
  155. catch { }
  156. }
  157. protected virtual void ultraGrid1_KeyDown(object sender, KeyEventArgs e)
  158. {
  159. try
  160. {
  161. UltraGridCell cell = ultraGrid1.ActiveCell;
  162. if (e.KeyCode != Keys.Enter || cell.Column.CellActivation != Activation.AllowEdit) return;
  163. ultraGrid1.UpdateData();
  164. }
  165. catch { }
  166. }
  167. protected virtual void ultraGrid1_CellListSelect(object sender, CellEventArgs e)
  168. {
  169. try
  170. {
  171. if (!e.Cell.Column.Hidden && e.Cell.Column.CellActivation == Activation.AllowEdit)
  172. ultraGrid1.UpdateData();
  173. }
  174. catch { }
  175. }
  176. protected virtual void ultraGrid1_AfterCellUpdate(object sender, CellEventArgs e)
  177. {
  178. try
  179. {
  180. if (!e.Cell.Column.Hidden && e.Cell.Column.CellActivation == Activation.AllowEdit)
  181. {
  182. InitHashtable(ref _htValueChanged);
  183. InitHashtable(ref _htDatatypeChanged);
  184. InitHashtable(ref _htCaptionChanged);
  185. string strKey = e.Cell.Column.Key.ToUpper();
  186. string strCaption = e.Cell.Column.Header.Caption;
  187. Type type = e.Cell.Column.DataType;
  188. object value = e.Cell.Value;
  189. object valueInitial = null;
  190. if (_htValueInitial != null && _htValueInitial.Contains(strKey)) valueInitial = _htValueInitial[strKey];
  191. if (value.Equals(valueInitial))
  192. {
  193. if (_htValueChanged.Contains(strKey)) _htValueChanged.Remove(strKey);
  194. if (_htDatatypeChanged.Contains(strKey)) _htDatatypeChanged.Remove(strKey);
  195. if (_htCaptionChanged.Contains(strKey)) _htCaptionChanged.Remove(strKey);
  196. try
  197. {
  198. e.Cell.Appearance.ResetBackColor();
  199. }
  200. catch { }
  201. return;
  202. }
  203. try
  204. {
  205. e.Cell.Appearance.BackColor = Color.Orange;
  206. }
  207. catch { }
  208. if (!_htValueChanged.Contains(strKey))
  209. _htValueChanged.Add(strKey, value);
  210. else _htValueChanged[strKey] = value;
  211. if (!_htDatatypeChanged.Contains(strKey))
  212. _htDatatypeChanged.Add(strKey, type);
  213. else _htDatatypeChanged[strKey] = type;
  214. if (!_htCaptionChanged.Contains(strKey))
  215. _htCaptionChanged.Add(strKey, strCaption);
  216. else _htCaptionChanged[strKey] = strCaption;
  217. }
  218. }
  219. catch { }
  220. }
  221. protected void SetUltraGridActiveCell(string ColumnName)
  222. {
  223. try
  224. {
  225. if (ultraGrid1.Rows.Count > 0)
  226. {
  227. ultraGrid1.Rows[0].Cells[ColumnName].Activated = true;
  228. ultraGrid1.PerformAction(UltraGridAction.EnterEditMode);
  229. }
  230. }
  231. catch { }
  232. }
  233. public virtual void ResetData()
  234. {
  235. ClsControlPack.ResetUltraDataSource(this.ultraDataSource1, ultraGrid1);
  236. try
  237. {
  238. InitHashtable(ref _htValueInitial);
  239. string strKey = "";
  240. object Value = null;
  241. for (int i = 0; i < ultraDataSource1.Band.Columns.Count; i++)
  242. {
  243. strKey = this.ultraDataSource1.Band.Columns[i].Key;
  244. try
  245. {
  246. Value = this.ultraDataSource1.Rows[0][strKey];
  247. _htValueInitial.Add(strKey, Value);
  248. }
  249. catch { }
  250. try
  251. {
  252. ultraGrid1.Rows[0].Cells[strKey].Appearance.ResetBackColor();
  253. }
  254. catch { }
  255. }
  256. }
  257. catch { }
  258. finally
  259. {
  260. if (_htValueChanged != null) _htValueChanged.Clear();
  261. if (_htDatatypeChanged != null) _htDatatypeChanged.Clear();
  262. if (_htCaptionChanged != null) _htCaptionChanged.Clear();
  263. }
  264. }
  265. public virtual void SetData(Hashtable ar)
  266. {
  267. try
  268. {
  269. if (ar == null || ar.Count == 0)
  270. {
  271. ResetData();
  272. return;
  273. }
  274. string strKey = "";
  275. object Value = DBNull.Value;
  276. InitHashtable(ref _htValueInitial);
  277. for (int i = 0; i < ultraDataSource1.Band.Columns.Count; i++)
  278. {
  279. strKey = this.ultraDataSource1.Band.Columns[i].Key;
  280. try
  281. {
  282. if (!_htValueInitial.Contains(strKey)) _htValueInitial.Add(strKey, "");
  283. if (ar.Contains(strKey))
  284. {
  285. Value = ar[strKey];
  286. if (strKey == "FACT_ROUTE")
  287. Value = ClsBusinessPack.analysPath(Convert.ToString(Value));
  288. if (strKey == "OPTDATE")
  289. Value = Convert.ToDateTime(Value).ToString("yyyy-MM-dd HH:mm:ss");
  290. if (strKey == "SUPPLYOXYGENTIME")
  291. {
  292. if (Value != "")
  293. {
  294. TimeSpan ts = new TimeSpan(0, 0, Convert.ToInt32(Value));
  295. string tsMin = ts.Minutes.ToString();
  296. string tsSen = ts.Seconds.ToString();
  297. Value = tsMin + "′" + tsSen + "″";
  298. }
  299. else
  300. {
  301. Value =ClsDataAccessPack.GetTimeSpan(Convert.ToDateTime(ar["OPENOXYGENTIME"]), Convert.ToDateTime(ar["STOPOXYGENTIME"]));
  302. }
  303. }
  304. ultraDataSource1.Rows[0][i] = Value;
  305. _htValueInitial[strKey] = Value;
  306. }
  307. else
  308. {
  309. this.ultraDataSource1.Rows[0][i] = DBNull.Value;
  310. _htValueInitial[strKey] = DBNull.Value;
  311. }
  312. }
  313. catch { }
  314. try
  315. {
  316. ultraGrid1.Rows[0].Cells[strKey].Appearance.ResetBackColor();
  317. }
  318. catch { }
  319. }
  320. try
  321. {
  322. if (_htValueChanged != null) _htValueChanged.Clear();
  323. if (_htDatatypeChanged != null) _htDatatypeChanged.Clear();
  324. if (_htCaptionChanged != null) _htCaptionChanged.Clear();
  325. }
  326. catch { }
  327. }
  328. catch { }
  329. }
  330. protected void InitHashtable(ref Hashtable htbl)
  331. {
  332. if (htbl == null) htbl = new Hashtable();
  333. }
  334. }
  335. }