F_PM_1702.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PM_1702.cs
  5. * 2.功能描述:新建/编辑温湿记录信息
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 庄天威 2014/11/18 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Data;
  12. using System.Windows.Forms;
  13. using Dongke.IBOSS.PRD.Basics.BaseControls;
  14. using Dongke.IBOSS.PRD.Basics.BaseResources;
  15. using Dongke.IBOSS.PRD.Client.CommonModule;
  16. using Dongke.IBOSS.PRD.Client.DataModels;
  17. using Dongke.IBOSS.PRD.WCF.DataModels;
  18. using Dongke.IBOSS.PRD.WCF.Proxys;
  19. using Dongke.IBOSS.PRD.WCF.Proxys.PMModuleService;
  20. using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
  21. namespace Dongke.IBOSS.PRD.Client.PMModule
  22. {
  23. public partial class F_PM_1702 : FormBase
  24. {
  25. #region 成员变量
  26. // 窗体模式ID
  27. private Constant.FormMode _formType;
  28. // 操作实体ID
  29. private DateTime? _recordTime;
  30. // 操作实体信息
  31. private CelsiusRecordEntity _crEntity = new CelsiusRecordEntity();
  32. // 页面数据源
  33. private DataTable _dtSourse;
  34. #endregion
  35. #region 构造函数
  36. public F_PM_1702(Constant.FormMode formType, DateTime recordTime)
  37. {
  38. InitializeComponent();
  39. _formType = formType;
  40. _recordTime = recordTime;
  41. }
  42. #endregion
  43. #region 事件处理
  44. private void F_PM_1702_Load(object sender, EventArgs e)
  45. {
  46. try
  47. {
  48. if (this._formType == Constant.FormMode.Add)
  49. {
  50. this.Text = FormTitles.F_PM_1702_ADD;
  51. this.dgvCelsiusRecord.AllowUserToDeleteRows = true;
  52. }
  53. else if (this._formType == Constant.FormMode.Edit)
  54. {
  55. this.Text = FormTitles.F_PM_1702_EDIT;
  56. this.dtpRecordTime.Enabled = false;
  57. this.btnAddDetail.Enabled = false;
  58. this.btnAddDetail.Visible = false;
  59. }
  60. //设定按钮的文本值
  61. this.btnSave.Text = ButtonText.BTN_SAVE;
  62. this.btnCancel.Text = ButtonText.BTN_CANCEL;
  63. this.dgvCelsiusRecord.AutoGenerateColumns = false;
  64. this.BindPage();
  65. this.dgvCelsiusRecord.IsSetInputColumnsColor = true;
  66. }
  67. catch (Exception ex)
  68. {
  69. // 对异常进行共通处理
  70. ExceptionManager.HandleEventException(this.ToString(),
  71. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  72. }
  73. }
  74. private void btnAddDetail_Click(object sender, EventArgs e)
  75. {
  76. try
  77. {
  78. ThermometerEntity TEntity = new ThermometerEntity();
  79. TEntity.SelectUserId = LogInUserInfo.CurrentUser.CurrentUserEntity.UserID;
  80. TEntity.ValueFlag = 1;
  81. DataSet dsThermometer = SystemModuleProxy.Service.GetThermometer(TEntity);
  82. if (dsThermometer != null && dsThermometer.Tables.Count != 0)
  83. {
  84. foreach (DataRow drFor in dsThermometer.Tables[0].Rows)
  85. {
  86. DataRow drNewFor = _dtSourse.NewRow();
  87. drNewFor["ThermometerID"] = drFor["ThermometerID"];
  88. drNewFor["ThermometerCode"] = drFor["ThermometerCode"];
  89. _dtSourse.Rows.Add(drNewFor);
  90. }
  91. }
  92. if (this._dtSourse.Rows.Count > 0)
  93. {
  94. this.dtpRecordTime.Enabled = false;
  95. this.btnAddDetail.Enabled = false;
  96. this.dgvCelsiusRecord.IsSetInputColumnsColor = true;
  97. }
  98. else
  99. {
  100. // 提示未查找到数据
  101. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  102. MessageBoxButtons.OK, MessageBoxIcon.Information);
  103. }
  104. }
  105. catch (Exception ex)
  106. {
  107. // 对异常进行共通处理
  108. ExceptionManager.HandleEventException(this.ToString(),
  109. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  110. }
  111. }
  112. private void btnSubmit_Click(object sender, EventArgs e)
  113. {
  114. try
  115. {
  116. //首先验证数据合法性
  117. //if (this.ValidationInput() == false)
  118. //{
  119. // return;
  120. //}
  121. //进行添加操作
  122. int ReturnRow = (int)DoAsync(() =>
  123. {
  124. return EntityToServer();
  125. });
  126. if (ReturnRow > 0)
  127. {
  128. // 提示信息
  129. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "温湿记录", "保存"),
  130. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  131. this.DialogResult = DialogResult.OK;
  132. }
  133. else
  134. {
  135. // 提示信息
  136. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "温湿记录", "保存"),
  137. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  138. }
  139. }
  140. catch (Exception ex)
  141. {
  142. // 对异常进行共通处理
  143. ExceptionManager.HandleEventException(this.ToString(),
  144. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  145. }
  146. }
  147. private void btnClose_Click(object sender, EventArgs e)
  148. {
  149. this.DialogResult = DialogResult.OK;
  150. }
  151. #endregion
  152. #region 私有方法/函数
  153. /// <summary>
  154. /// 绑定需要操作的实体信息
  155. /// </summary>
  156. private void BindPage()
  157. {
  158. try
  159. {
  160. if (this._recordTime != null)
  161. {
  162. this._crEntity.InsertTime = this._recordTime;
  163. }
  164. else
  165. {
  166. this._crEntity.InsertTime = this.dtpRecordTime.Value;
  167. }
  168. this._crEntity.PurviewType = 12;// 操作权限
  169. DataSet dsCelsius = PMModuleProxy.Service.GetCelsiusRecord(this._crEntity);
  170. if (dsCelsius != null && dsCelsius.Tables.Count != 0)
  171. {
  172. this.dgvCelsiusRecord.DataSource = dsCelsius.Tables[0];
  173. this.dtpRecordTime.Value = Convert.ToDateTime(this._recordTime);
  174. this._dtSourse = dsCelsius.Tables[0];
  175. }
  176. }
  177. catch (Exception ex)
  178. {
  179. throw ex;
  180. }
  181. }
  182. /// <summary>
  183. /// 验证必填项
  184. /// </summary>
  185. /// <returns>是否通过</returns>
  186. private bool ValidationInput()
  187. {
  188. try
  189. {
  190. if (this.dgvCelsiusRecord.Rows.Count == 0)
  191. {
  192. this.btnAddDetail.Focus();
  193. return false;
  194. }
  195. foreach (DataGridViewRow gvrFor in this.dgvCelsiusRecord.Rows)
  196. {
  197. if (gvrFor.Cells["Celsius"].Value == DBNull.Value || gvrFor.Cells["Celsius"].Value == null
  198. || gvrFor.Cells["Humidity"].Value == DBNull.Value || gvrFor.Cells["Humidity"].Value == null)
  199. {
  200. this.dgvCelsiusRecord.Rows[gvrFor.Index].Selected = true;
  201. return false;
  202. }
  203. }
  204. return true;
  205. }
  206. catch (Exception ex)
  207. {
  208. throw ex;
  209. }
  210. }
  211. /// <summary>
  212. /// 与服务交互操作
  213. /// </summary>
  214. /// <returns></returns>
  215. private int EntityToServer()
  216. {
  217. try
  218. {
  219. DateTime dt = this.dtpRecordTime.Value;
  220. dt = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, 0);
  221. return PMModuleProxy.Service.EditCelsiusRecord(dt,
  222. (DataTable)this.dgvCelsiusRecord.DataSource);
  223. }
  224. catch (Exception ex)
  225. {
  226. throw ex;
  227. }
  228. }
  229. #endregion
  230. }
  231. }