F_PM_1701.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PM_1701.cs
  5. * 2.功能描述:温湿度记录
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 庄天威 2014/09/17 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Windows.Forms;
  14. using Dongke.IBOSS.PRD.Basics.BaseResources;
  15. using Dongke.IBOSS.PRD.Basics.DockPanel;
  16. using Dongke.IBOSS.PRD.WCF.Proxys;
  17. using Dongke.IBOSS.PRD.WCF.Proxys.PMModuleService;
  18. using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
  19. using Dongke.IBOSS.PRD.Client.CommonModule;
  20. using Dongke.IBOSS.PRD.WCF.DataModels;
  21. namespace Dongke.IBOSS.PRD.Client.PMModule
  22. {
  23. public partial class F_PM_1701 : DockPanelBase
  24. {
  25. #region 成员变量
  26. //单例模式
  27. private static F_PM_1701 _instance;
  28. #endregion
  29. #region 构造函数
  30. public F_PM_1701()
  31. {
  32. InitializeComponent();
  33. }
  34. #endregion
  35. #region 单例模式
  36. /// <summary>
  37. /// 单例模式,防止重复创建窗体
  38. /// </summary>
  39. public static F_PM_1701 Instance
  40. {
  41. get
  42. {
  43. if (_instance == null)
  44. {
  45. _instance = new F_PM_1701();
  46. }
  47. return _instance;
  48. }
  49. }
  50. #endregion
  51. #region 事件
  52. /// <summary>
  53. /// 窗体加载
  54. /// </summary>
  55. private void F_PM_1701_Load(object sender, EventArgs e)
  56. {
  57. // 加载权限
  58. FormPermissionManager.FormPermissionControl(this.Name, this,
  59. Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData,
  60. Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  61. this.dgvCelsiusRecord.AutoGenerateColumns = false;
  62. this.Text = FormTitles.F_PM_1701;
  63. }
  64. /// <summary>
  65. /// 获取数据
  66. /// </summary>
  67. private void btnSearch_Click(object sender, System.EventArgs e)
  68. {
  69. try
  70. {
  71. DataSet dsThermometer = (DataSet)DoAsync(new Dongke.IBOSS.PRD.Basics.DockPanel.AsyncMethod(() =>
  72. {
  73. return this.GetCelsiusRecord();
  74. }));
  75. if (dsThermometer != null)
  76. {
  77. if (dsThermometer.Tables.Count != Constant.INT_IS_ZERO)
  78. {
  79. this.dgvCelsiusRecord.DataSource = ((DataSet)dsThermometer).Tables[Constant.INT_IS_ZERO];
  80. this.dgvCelsiusRecord.ReadOnly = true;
  81. if (this.dgvCelsiusRecord.Rows.Count == Constant.INT_IS_ZERO)
  82. {
  83. // 提示未查找到数据
  84. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  85. MessageBoxButtons.OK, MessageBoxIcon.Information);
  86. }
  87. }
  88. }
  89. else
  90. {
  91. this.dgvCelsiusRecord.DataSource = null;
  92. // 提示未查找到数据
  93. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  94. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  95. }
  96. }
  97. catch (Exception ex)
  98. {
  99. // 对异常进行共通处理
  100. ExceptionManager.HandleEventException(this.ToString(),
  101. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  102. }
  103. }
  104. /// <summary>
  105. /// 清空条件
  106. /// </summary>
  107. private void btnClearCondition_Click(object sender, EventArgs e)
  108. {
  109. this.txtRemarks.Text = "";
  110. this.dkThermometer.Text = "";
  111. this.dkThermometer.ThermometerID = null;
  112. }
  113. /// <summary>
  114. /// 窗体关闭
  115. /// </summary>
  116. /// <param name="sender"></param>
  117. /// <param name="e"></param>
  118. private void F_PM_1701_FormClosed(object sender, FormClosedEventArgs e)
  119. {
  120. _instance = null;
  121. }
  122. /// <summary>
  123. /// 新建信息
  124. /// </summary>
  125. /// <param name="sender"></param>
  126. /// <param name="e"></param>
  127. private void tsbtnAdd_Click(object sender, EventArgs e)
  128. {
  129. try
  130. {
  131. F_PM_1702 frmFPM1702 = new F_PM_1702(Constant.FormMode.Add, DateTime.Now);
  132. DialogResult dialogresult = frmFPM1702.ShowDialog();
  133. if (dialogresult.Equals(DialogResult.OK))
  134. {
  135. this.dgvCelsiusRecord.DataSource = null;
  136. DataSet dsCelsiusRecord = (DataSet)DoAsync(new Dongke.IBOSS.PRD.Basics.DockPanel.AsyncMethod(() =>
  137. {
  138. return this.GetCelsiusRecord();
  139. }));
  140. if (dsCelsiusRecord != null)
  141. {
  142. if (dsCelsiusRecord.Tables.Count != Constant.INT_IS_ZERO)
  143. {
  144. this.dgvCelsiusRecord.DataSource = ((DataSet)dsCelsiusRecord).Tables[Constant.INT_IS_ZERO];
  145. this.dgvCelsiusRecord.ReadOnly = true;
  146. }
  147. }
  148. else
  149. {
  150. this.dgvCelsiusRecord.DataSource = null;
  151. }
  152. }
  153. }
  154. catch (Exception ex)
  155. {
  156. // 对异常进行共通处理
  157. ExceptionManager.HandleEventException(this.ToString(),
  158. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  159. }
  160. }
  161. /// <summary>
  162. /// 编辑信息
  163. /// </summary>
  164. /// <param name="sender"></param>
  165. /// <param name="e"></param>
  166. private void tsbtnEdit_Click(object sender, EventArgs e)
  167. {
  168. try
  169. {
  170. DataGridViewRow currentRow = this.dgvCelsiusRecord.CurrentRow;
  171. if (currentRow != null)
  172. {
  173. DateTime recordTime = Convert.ToDateTime(currentRow.Cells["RecordDate"].Value);
  174. F_PM_1702 frmFPM1702 = new F_PM_1702(Constant.FormMode.Edit, recordTime);
  175. DialogResult dialogresult = frmFPM1702.ShowDialog();
  176. if (dialogresult.Equals(DialogResult.OK))
  177. {
  178. this.dgvCelsiusRecord.DataSource = null;
  179. object obDailyResult = DoAsync(new AsyncMethod(GetCelsiusRecord));
  180. if (obDailyResult != null)
  181. {
  182. DataSet dsCelsiusRecord = (DataSet)obDailyResult;
  183. if (dsCelsiusRecord.Tables.Count != Constant.INT_IS_ZERO)
  184. {
  185. this.dgvCelsiusRecord.DataSource = dsCelsiusRecord.Tables[Constant.INT_IS_ZERO];
  186. this.dgvCelsiusRecord.ReadOnly = true;
  187. }
  188. }
  189. else
  190. {
  191. this.dgvCelsiusRecord.DataSource = null;
  192. }
  193. }
  194. }
  195. else
  196. {
  197. MessageBox.Show(Messages.MSG_CMN_W020, this.Text,
  198. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  199. }
  200. }
  201. catch (Exception ex)
  202. {
  203. // 对异常进行共通处理
  204. ExceptionManager.HandleEventException(this.ToString(),
  205. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  206. }
  207. }
  208. /// <summary>
  209. /// 编辑信息
  210. /// </summary>
  211. private void dgvThermometer_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  212. {
  213. try
  214. {
  215. if (!this.tsbtnEdit.Visible || e.RowIndex == -Constant.INT_IS_ONE || e.ColumnIndex == -Constant.INT_IS_ONE)
  216. {
  217. return;
  218. }
  219. DateTime recordTime = Convert.ToDateTime(this.dgvCelsiusRecord.Rows[e.RowIndex].Cells["RecordDate"].Value);
  220. F_PM_1702 frmFPM1702 = new F_PM_1702(Constant.FormMode.Edit, recordTime);
  221. DialogResult dialogresult = frmFPM1702.ShowDialog();
  222. if (dialogresult.Equals(DialogResult.OK))
  223. {
  224. this.dgvCelsiusRecord.DataSource = null;
  225. object obDailyResult = DoAsync(new AsyncMethod(GetCelsiusRecord));
  226. if (obDailyResult != null)
  227. {
  228. DataSet dsCelsiusRecord = (DataSet)obDailyResult;
  229. if (dsCelsiusRecord.Tables.Count != Constant.INT_IS_ZERO)
  230. {
  231. this.dgvCelsiusRecord.DataSource = dsCelsiusRecord.Tables[Constant.INT_IS_ZERO];
  232. this.dgvCelsiusRecord.ReadOnly = true;
  233. }
  234. }
  235. else
  236. {
  237. this.dgvCelsiusRecord.DataSource = null;
  238. }
  239. }
  240. }
  241. catch (Exception ex)
  242. {
  243. // 对异常进行共通处理
  244. ExceptionManager.HandleEventException(this.ToString(),
  245. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  246. }
  247. }
  248. /// <summary>
  249. /// 删除
  250. /// </summary>
  251. /// <param name="sender"></param>
  252. /// <param name="e"></param>
  253. private void tsbtnDelete_Click(object sender, EventArgs e)
  254. {
  255. try
  256. {
  257. DialogResult dr = MessageBox.Show("是否删除当前选择数据。", this.Text,
  258. MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  259. if (dr != DialogResult.Yes)
  260. {
  261. return;
  262. }
  263. DataGridViewRow currentRow = this.dgvCelsiusRecord.CurrentRow;
  264. if (currentRow != null)
  265. {
  266. int recordID = Convert.ToInt32(currentRow.Cells["RecordID"].Value);
  267. int result = (int)DoAsync(new Dongke.IBOSS.PRD.Basics.DockPanel.AsyncMethod(() =>
  268. {
  269. return PMModuleProxy.Service.DeleteCelsiusRecord(recordID);
  270. }));
  271. if (result == 0)
  272. {
  273. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "数据不存在"), this.Text,
  274. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  275. }
  276. this.dgvCelsiusRecord.DataSource = null;
  277. object obDailyResult = DoAsync(new AsyncMethod(GetCelsiusRecord));
  278. if (obDailyResult != null)
  279. {
  280. DataSet dsCelsiusRecord = (DataSet)obDailyResult;
  281. if (dsCelsiusRecord.Tables.Count != Constant.INT_IS_ZERO)
  282. {
  283. this.dgvCelsiusRecord.DataSource = dsCelsiusRecord.Tables[Constant.INT_IS_ZERO];
  284. this.dgvCelsiusRecord.ReadOnly = true;
  285. }
  286. }
  287. else
  288. {
  289. this.dgvCelsiusRecord.DataSource = null;
  290. }
  291. }
  292. else
  293. {
  294. MessageBox.Show(Messages.MSG_CMN_W020, this.Text,
  295. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  296. }
  297. }
  298. catch (Exception ex)
  299. {
  300. // 对异常进行共通处理
  301. ExceptionManager.HandleEventException(this.ToString(),
  302. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  303. }
  304. }
  305. /// <summary>
  306. /// 关闭按钮事件
  307. /// </summary>
  308. /// <param name="sender"></param>
  309. /// <param name="e"></param>
  310. private void tsbtnClose_Click(object sender, EventArgs e)
  311. {
  312. this.Close();
  313. }
  314. /// <summary>
  315. /// 自动列宽事件
  316. /// </summary>
  317. /// <param name="sender"></param>
  318. /// <param name="e"></param>
  319. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  320. {
  321. this.dgvCelsiusRecord.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  322. }
  323. #endregion
  324. #region 私有方法
  325. /// <summary>
  326. /// 根据界面查询条件获取数据集
  327. /// </summary>
  328. private DataSet GetCelsiusRecord()
  329. {
  330. try
  331. {
  332. CelsiusRecordEntity crEntity = new CelsiusRecordEntity();
  333. if(this.dkThermometer.ThermometerID != null)
  334. {
  335. crEntity.ThermometerID = this.dkThermometer.ThermometerID;
  336. }
  337. crEntity.RecordDate = this.txtRecordDateStart.Value.Date;
  338. crEntity.RecordDateEnd = this.txtRecordDateEnd.Value.Date.AddDays(1);
  339. crEntity.PurviewType = 12;// 操作权限
  340. if(string.IsNullOrWhiteSpace(this.txtRemarks.Text))
  341. {
  342. crEntity.Remarks = this.txtRemarks.Text;
  343. }
  344. return PMModuleProxy.Service.GetCelsiusRecord(crEntity);
  345. }
  346. catch (Exception ex)
  347. {
  348. throw ex;
  349. }
  350. }
  351. #endregion
  352. }
  353. }