ucNewTemperature.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using Core.Mes.Client.Comm.Server;
  10. using Core.Mes.Client.Comm.Tool;
  11. using Core.StlMes.Client.LgClassModel;
  12. using CoreFS.CA06;
  13. using Infragistics.Win.UltraWinGrid;
  14. namespace Core.StlMes.Client.LgCommon.公共自定义控件.温度
  15. {
  16. public partial class ucNewTemperature : UserControl
  17. {
  18. public ucNewTemperature()
  19. {
  20. InitializeComponent();
  21. }
  22. private string _stove = "";
  23. private string _station = "";
  24. private string _disposalTime = "";
  25. private bool _changed = false;
  26. private OpeBase _ob;
  27. public bool Changed
  28. {
  29. get
  30. {
  31. return _changed ? _changed : datas != null && datas.Any() && datas.Any(p => p.NewRow);
  32. }
  33. }
  34. public bool CanSave
  35. {
  36. get { return datas.All(p => p.Valid); }
  37. }
  38. private List<StlTempsamplingEntity> datas;
  39. public bool SaveDate()
  40. {
  41. if (_ob == null) return false;
  42. if (!Changed || datas ==null) return true;
  43. if (!CanSave)
  44. {
  45. MessageBox.Show("温度数据不正确,无法保存温度数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  46. return true;
  47. }
  48. try
  49. {
  50. ServerHelper.SetData("Core.LgMes.Server.LgDeviceManager.StlTemperature.SaveStlTemperature", new object[] { datas, _stove,
  51. _station,_disposalTime }, _ob);
  52. Refresh();
  53. return true;
  54. }
  55. catch (Exception ex)
  56. {
  57. return false;
  58. }
  59. }
  60. public void SetData(string Stove, string station, string disposalTime, OpeBase ob)
  61. {
  62. _stove = Stove;
  63. _station = station;
  64. _disposalTime = disposalTime;
  65. if (_ob==null) _ob = ob;
  66. Refresh();
  67. }
  68. private void Refresh()
  69. {
  70. if (_ob == null) return;
  71. datas =
  72. EntityHelper.GetData<StlTempsamplingEntity>(
  73. "Core.LgMes.Server.LgDeviceManager.StlTemperature.GetStlTemperature",
  74. new[]
  75. {
  76. _stove,
  77. _station,
  78. _disposalTime
  79. }, _ob) ?? new DataSourceList<StlTempsamplingEntity>();
  80. ugTem.DataBindings.Clear();
  81. ugTem.DataSource = datas;
  82. if (datas.Count >= 0)
  83. {
  84. ClsControlPack.RefreshAndAutoSize(ugTem);
  85. }
  86. _changed = false;
  87. }
  88. private void tsmAdd_Click(object sender, EventArgs e)
  89. {
  90. if (datas == null) return;
  91. datas.Add(new StlTempsamplingEntity() {NewRow = true,Valid = false,Startdate = DateTime.Now,Enddate = DateTime.Now});
  92. ugTem.DataBind();
  93. ugTem.Rows[ugTem.Rows.Count - 1].Appearance.BackColor = Color.Orange;
  94. if (ugTem.Rows.Count <= 1)
  95. {
  96. ClsControlPack.RefreshAndAutoSize(ugTem);
  97. }
  98. }
  99. private void tsmDelete_Click(object sender, EventArgs e)
  100. {
  101. if (ugTem.ActiveRow == null)
  102. {
  103. MessageBox.Show("请选中一行再进行删除");
  104. return;
  105. }
  106. StlTempsamplingEntity StlTempsamplingEntity = ugTem.ActiveRow.ListObject as StlTempsamplingEntity;
  107. if (StlTempsamplingEntity != null && !StlTempsamplingEntity.NewRow)
  108. {
  109. _changed = true;
  110. }
  111. datas.RemoveAt(ugTem.ActiveRow.Index);
  112. }
  113. private void ugTem_KeyPress(object sender, KeyPressEventArgs e)
  114. {
  115. try
  116. {
  117. ugTem.UpdateData();
  118. }
  119. catch (Exception)
  120. {
  121. }
  122. }
  123. private void ugTem_AfterRowInsert(object sender, Infragistics.Win.UltraWinGrid.RowEventArgs e)
  124. {
  125. e.Row.Appearance.BackColor = Color.Orange;
  126. }
  127. private void ugTem_BeforeRowsDeleted(object sender, Infragistics.Win.UltraWinGrid.BeforeRowsDeletedEventArgs e)
  128. {
  129. if (e.Rows != null)
  130. {
  131. StlTempsamplingEntity StlTempsamplingEntity = e.Rows[0].ListObject as StlTempsamplingEntity;
  132. if (StlTempsamplingEntity != null && !StlTempsamplingEntity.NewRow)
  133. {
  134. _changed = true;
  135. }
  136. }
  137. }
  138. private void ugTem_ClickCellButton(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
  139. {
  140. e.Cell.Value = DateTime.Now;
  141. }
  142. private void ugTem_AfterCellUpdate(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
  143. {
  144. StlTempsamplingEntity StlTempsamplingEntity = ugTem.ActiveRow.ListObject as StlTempsamplingEntity;
  145. if (StlTempsamplingEntity != null)
  146. {
  147. if (StlTempsamplingEntity.Startdate == null || StlTempsamplingEntity.Enddate == null ||
  148. StlTempsamplingEntity.Startdate > StlTempsamplingEntity.Enddate
  149. || StlTempsamplingEntity.Samplingname == ""
  150. || StlTempsamplingEntity.Samplingvalue == null
  151. )
  152. {
  153. ugTem.Rows[ugTem.ActiveRow.Index].Appearance.BackColor = Color.Orange;
  154. StlTempsamplingEntity.Valid = false;
  155. }
  156. else
  157. {
  158. ugTem.Rows[ugTem.ActiveRow.Index].Appearance.BackColor = Color.LightGreen;
  159. StlTempsamplingEntity.Valid = true;
  160. }
  161. }
  162. else
  163. {
  164. ugTem.Rows[ugTem.ActiveRow.Index].Appearance.BackColor = Color.Orange;
  165. StlTempsamplingEntity.Valid = false;
  166. _changed = true;
  167. }
  168. }
  169. private void ugTem_CellChange(object sender, CellEventArgs e)
  170. {
  171. try
  172. {
  173. ugTem.UpdateData();
  174. }
  175. catch (Exception)
  176. {
  177. }
  178. }
  179. private void ugTem_MouseDown(object sender, MouseEventArgs e)
  180. {
  181. if (e.Button == MouseButtons.Right)
  182. {
  183. var uieOver = ugTem.DisplayLayout.UIElement.ElementFromPoint(new Point(e.X, e.Y));
  184. if (uieOver != null)
  185. {
  186. UltraGridRow ugrOver = uieOver.GetContext(typeof(UltraGridRow), true) as UltraGridRow;
  187. ugTem.ActiveRow = ugrOver;
  188. }
  189. }
  190. }
  191. }
  192. }