F_MST_0602.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_MST_0602.cs
  5. * 2.功能描述:新建/编辑温湿计信息
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 任海 2014/12/25 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.WCF.DataModels;
  17. using Dongke.IBOSS.PRD.WCF.Proxys;
  18. using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
  19. namespace Dongke.IBOSS.PRD.Client.SystemModule
  20. {
  21. /// <summary>
  22. /// 新建/编辑温湿计信息
  23. /// </summary>
  24. public partial class F_MST_0602 : FormBase
  25. {
  26. #region 成员变量
  27. //页面状态
  28. private Constant.FormMode _formStatus;
  29. // 温湿计ID
  30. private int? _formThermometerID;
  31. // 当前编辑实体
  32. private ThermometerEntity _thermometerEntity = new ThermometerEntity();
  33. #endregion
  34. #region 构造函数
  35. public F_MST_0602(Constant.FormMode status, int ThermometerID)
  36. {
  37. InitializeComponent();
  38. this._formStatus = status;
  39. this._formThermometerID = ThermometerID;
  40. if (this._formStatus == Constant.FormMode.Add)
  41. {
  42. this.Text = FormTitles.F_MST_0602_ADD;
  43. }
  44. else
  45. {
  46. this.Text = FormTitles.F_MST_0602_EDIT;
  47. }
  48. this.btnSave.Text = ButtonText.BTN_SAVE;
  49. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  50. }
  51. #endregion
  52. #region 事件处理
  53. /// <summary>
  54. /// 页面加载事件
  55. /// </summary>
  56. /// <param name="sender"></param>
  57. /// <param name="e"></param>
  58. private void F_MST_0602_Load(object sender, System.EventArgs e)
  59. {
  60. try
  61. {
  62. //如果是修改,要绑定选中的信息
  63. if (this._formStatus == Constant.FormMode.Edit)
  64. {
  65. this.BindPage();
  66. }
  67. //如果是新建,选项默认值设定
  68. if (this._formStatus == Constant.FormMode.Add)
  69. {
  70. this.cbValueFlag.Checked = true;
  71. }
  72. this.txtBuildingNo.Focus();
  73. }
  74. catch (Exception ex)
  75. {
  76. // 对异常进行共通处理
  77. ExceptionManager.HandleEventException(this.ToString(),
  78. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  79. }
  80. }
  81. /// <summary>
  82. /// 提交操作
  83. /// </summary>
  84. /// <param name="sender"></param>
  85. /// <param name="e"></param>
  86. private void btnSave_Click(object sender, System.EventArgs e)
  87. {
  88. try
  89. {
  90. //基础数据验证
  91. int ErrorId = ValidationText();
  92. if (ErrorId != Constant.INT_IS_ZERO)
  93. {
  94. string errorAddress = "";
  95. switch (ErrorId)
  96. {
  97. case 1:
  98. this.txtBuildingNo.Focus();
  99. errorAddress = "楼号";
  100. break;
  101. case 3:
  102. this.txtFloorNo.Focus();
  103. errorAddress = "楼层";
  104. break;
  105. case 6:
  106. this.txtLocationCode.Focus();
  107. errorAddress = "位置编码";
  108. break;
  109. case 7:
  110. this.txtManagerName.Focus();
  111. errorAddress = "责任人";
  112. break;
  113. default:
  114. break;
  115. };
  116. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, errorAddress),
  117. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  118. return;
  119. }
  120. //为实体绑定属性
  121. this.BindEntity();
  122. if (this._formStatus == Constant.FormMode.Add)
  123. {
  124. int MyReturn = (int)DoAsync(new BaseAsyncMethod(() =>
  125. {
  126. return SystemModuleProxy.Service.AddThermometerEntity(this._thermometerEntity);
  127. }));
  128. if (MyReturn == Constant.INT_IS_ONE)
  129. {
  130. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "温湿计信息", "保存"),
  131. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  132. this.PageInitialization();
  133. }
  134. else
  135. {
  136. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "温湿计信息", "保存"),
  137. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  138. }
  139. }
  140. else if (this._formStatus == Constant.FormMode.Edit)
  141. {
  142. int MyReturn = (int)DoAsync(new BaseAsyncMethod(() =>
  143. {
  144. return SystemModuleProxy.Service.UpdateThermometerEntity(this._thermometerEntity);
  145. }));
  146. if (MyReturn == Constant.INT_IS_ONE)
  147. {
  148. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "温湿计信息", "编辑"),
  149. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  150. this.Close();
  151. }
  152. else
  153. {
  154. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "温湿计信息", "编辑"),
  155. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  156. }
  157. }
  158. }
  159. catch (Exception ex)
  160. {
  161. // 对异常进行共通处理
  162. ExceptionManager.HandleEventException(this.ToString(),
  163. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  164. }
  165. }
  166. /// <summary>
  167. /// 窗体关闭
  168. /// </summary>
  169. /// <param name="sender"></param>
  170. /// <param name="e"></param>
  171. private void btnCancel_Click(object sender, System.EventArgs e)
  172. {
  173. this.DialogResult = DialogResult.OK;
  174. }
  175. /// <summary>
  176. /// 楼号变更
  177. /// </summary>
  178. private void txtBuildingNo_TextChanged(object sender, EventArgs e)
  179. {
  180. this.txtThermometerCode.Text = this.txtBuildingNo.Text + this.txtFloorNo.Text.PadLeft(2, '0')
  181. + "-" + this.txtLocationCode.Text.Trim();
  182. }
  183. /// <summary>
  184. /// 楼层变更
  185. /// </summary>
  186. private void txtFloorNo_TextChanged(object sender, EventArgs e)
  187. {
  188. this.txtThermometerCode.Text = this.txtBuildingNo.Text + this.txtFloorNo.Text.PadLeft(2, '0')
  189. + "-" + this.txtLocationCode.Text.Trim();
  190. }
  191. /// <summary>
  192. /// 位置变更
  193. /// </summary>
  194. private void txtLocationCode_TextChanged(object sender, EventArgs e)
  195. {
  196. this.txtThermometerCode.Text = this.txtBuildingNo.Text + this.txtFloorNo.Text.PadLeft(2, '0')
  197. + "-" + this.txtLocationCode.Text.Trim();
  198. }
  199. #endregion
  200. #region 私有方法/函数
  201. /// <summary>
  202. /// 绑定需要操作的实体信息
  203. /// </summary>
  204. private void BindPage()
  205. {
  206. try
  207. {
  208. if (this._formThermometerID != 0 && this._formThermometerID != null)
  209. {
  210. this._thermometerEntity.ThermometerID = this._formThermometerID;
  211. DataSet srEntity = SystemModuleProxy.Service.GetThermometer(_thermometerEntity);
  212. if (srEntity != null && srEntity.Tables.Count != 0
  213. && srEntity.Tables[0].Rows.Count != 0)
  214. {
  215. DataSet dsEntityData = (DataSet)srEntity;
  216. DataRow drEntityRow = dsEntityData.Tables[0].Rows[0];
  217. this.txtBuildingNo.Text = drEntityRow["BuildingNo"].ToString();
  218. this.txtFloorNo.Text = drEntityRow["FloorNo"].ToString();
  219. this.txtLocationCode.Text = drEntityRow["LocationCode"].ToString();
  220. this.txtThermometerCode.Text = drEntityRow["ThermometerCode"].ToString();
  221. this.txtManagerName.Text = drEntityRow["ManagerName"].ToString();
  222. this.txtRemarks.Text = drEntityRow["Remarks"].ToString();
  223. if (Convert.ToInt32(drEntityRow["ValueFlag"]) == Constant.INT_IS_ONE)
  224. {
  225. this.cbValueFlag.Checked = true;
  226. }
  227. else
  228. {
  229. this.cbValueFlag.Checked = false;
  230. }
  231. //将时间戳给到要修改的实体中
  232. this._thermometerEntity.OPTimeStamp = Convert.ToDateTime(drEntityRow["OPTimeStamp"]);
  233. }
  234. }
  235. }
  236. catch (Exception ex)
  237. {
  238. // 对异常进行共通处理
  239. ExceptionManager.HandleEventException(this.ToString(),
  240. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  241. }
  242. }
  243. /// <summary>
  244. /// 为实体绑定页面属性
  245. /// </summary>
  246. private void BindEntity()
  247. {
  248. try
  249. {
  250. this._thermometerEntity.BuildingNo = this.txtBuildingNo.Text.Trim();
  251. this._thermometerEntity.FloorNo = this.txtFloorNo.Text.Trim();
  252. this._thermometerEntity.LocationCode = this.txtLocationCode.Text.Trim();
  253. this._thermometerEntity.ManagerName = this.txtManagerName.Text.Trim();
  254. this._thermometerEntity.Remarks = this.txtRemarks.Text.Trim();
  255. this._thermometerEntity.ThermometerCode = this.txtThermometerCode.Text.Trim();
  256. if (this.cbValueFlag.Checked)
  257. {
  258. this._thermometerEntity.ValueFlag = 1;
  259. }
  260. else
  261. {
  262. this._thermometerEntity.ValueFlag = 0;
  263. }
  264. }
  265. catch (Exception ex)
  266. {
  267. // 对异常进行共通处理
  268. ExceptionManager.HandleEventException(this.ToString(),
  269. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  270. }
  271. }
  272. /// <summary>
  273. /// 页面控件初始化
  274. /// </summary>
  275. private void PageInitialization()
  276. {
  277. this.txtBuildingNo.Text = string.Empty;
  278. this.txtFloorNo.Text = string.Empty;
  279. this.txtLocationCode.Text = string.Empty;
  280. this.txtManagerName.Text = string.Empty;
  281. this.txtRemarks.Text = string.Empty;
  282. this.txtThermometerCode.Text = string.Empty;
  283. }
  284. /// <summary>
  285. /// 验证添加项
  286. /// </summary>
  287. private int ValidationText()
  288. {
  289. int ErrorID = 0;
  290. if (this.txtBuildingNo.Text == string.Empty)
  291. {
  292. ErrorID = 1;
  293. }
  294. if (this.txtFloorNo.Text == string.Empty)
  295. {
  296. ErrorID = 3;
  297. }
  298. if (this.txtLocationCode.Text == string.Empty)
  299. {
  300. ErrorID = 6;
  301. }
  302. if (this.txtManagerName.Text == string.Empty)
  303. {
  304. ErrorID = 7;
  305. }
  306. return ErrorID;
  307. }
  308. #endregion
  309. }
  310. }