F_PM_0108.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PM_0108.cs
  5. * 2.功能描述:注浆明细条码绑定
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈晓野 2015/04/03 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Reflection;
  14. using System.Text;
  15. using System.Windows.Forms;
  16. using Dongke.IBOSS.PRD.Basics.BaseControls;
  17. using Dongke.IBOSS.PRD.Basics.BaseResources;
  18. using Dongke.IBOSS.PRD.Basics.Library;
  19. using Dongke.IBOSS.PRD.Client.CommonModule;
  20. using Dongke.IBOSS.PRD.Client.Controls;
  21. using Dongke.IBOSS.PRD.WCF.DataModels;
  22. using Dongke.IBOSS.PRD.WCF.Proxys;
  23. namespace Dongke.IBOSS.PRD.Client.PMModule
  24. {
  25. /// <summary>
  26. /// 注浆明细条码绑定
  27. /// </summary>
  28. public partial class F_PM_0108 : DKFormBase
  29. {
  30. #region 成员变量
  31. private bool _isSave = false; // 保存标识
  32. #endregion
  33. #region 构造函数
  34. /// <summary>
  35. /// 构造函数
  36. /// </summary>
  37. public F_PM_0108()
  38. {
  39. this.InitializeComponent();
  40. // 功能按钮文本赋值
  41. this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
  42. this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
  43. this.btnSave.Text = ButtonText.BTN_SAVE;
  44. this.btnClose.Text = ButtonText.BTN_CLOSE;
  45. this.dgvDetail.AutoGenerateColumns = false;
  46. this.btnBindBarCode.Text = ButtonText.BTN_BINDBARCODE;
  47. this.btnClearBarCode.Text = ButtonText.BTN_CLEARBARCODE;
  48. }
  49. #endregion
  50. #region 属性
  51. /// <summary>
  52. /// 窗体状态
  53. /// </summary>
  54. public Constant.FormMode FormMode
  55. {
  56. get;
  57. set;
  58. }
  59. /// <summary>
  60. /// 注浆登记ID
  61. /// </summary>
  62. public DataRow DrRow
  63. {
  64. get;
  65. set;
  66. }
  67. #endregion
  68. #region 事件
  69. /// <summary>
  70. /// 窗体加载
  71. /// </summary>
  72. private void F_PM_0108_Load(object sender, EventArgs e)
  73. {
  74. try
  75. {
  76. // 设置列表未注浆原因选项数据源
  77. this.InitializeData();
  78. }
  79. catch (Exception ex)
  80. {
  81. // 对异常进行共通处理
  82. ExceptionManager.HandleEventException(this.ToString(),
  83. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  84. }
  85. }
  86. /// <summary>
  87. /// 窗体首次显示事件
  88. /// </summary>
  89. /// <param name="sender"></param>
  90. /// <param name="e"></param>
  91. private void F_PM_0108_Shown(object sender, EventArgs e)
  92. {
  93. if (FormMode == Constant.FormMode.Add)
  94. {
  95. scbGroutingLine.ShowSearchForm();
  96. }
  97. }
  98. /// <summary>
  99. /// 提交选择列内容的修改
  100. /// </summary>
  101. /// <param name="sender"></param>
  102. /// <param name="e"></param>
  103. private void dgvDetail_CurrentCellDirtyStateChanged(object sender, EventArgs e)
  104. {
  105. try
  106. {
  107. if (this.dgvDetail.CurrentRow != null && this.dgvDetail.IsCurrentCellDirty)
  108. {
  109. if ("ScrapFlag".Equals(this.dgvDetail.Columns
  110. [this.dgvDetail.CurrentCell.ColumnIndex].Name))
  111. {
  112. this.dgvDetail.CommitEdit(DataGridViewDataErrorContexts.Commit);
  113. }
  114. //else if ("BarCode".Equals(this.dgvDetail.Columns
  115. // [this.dgvDetail.CurrentCell.ColumnIndex].Name))
  116. //{
  117. // this.dgvDetail.CommitEdit(DataGridViewDataErrorContexts.Commit);
  118. //}
  119. }
  120. }
  121. catch (Exception ex)
  122. {
  123. // 对异常进行共通处理
  124. ExceptionManager.HandleEventException(this.ToString(),
  125. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  126. }
  127. }
  128. /// <summary>
  129. /// 排序后设置Grid状态
  130. /// </summary>
  131. /// <param name="sender"></param>
  132. /// <param name="e"></param>
  133. private void dgvDetail_Sorted(object sender, EventArgs e)
  134. {
  135. //this.SetEditGrid();
  136. }
  137. /// <summary>
  138. /// 自动列宽
  139. /// </summary>
  140. /// <param name="sender"></param>
  141. /// <param name="e"></param>
  142. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  143. {
  144. this.dgvDetail.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  145. }
  146. /// <summary>
  147. /// 页面关闭
  148. /// </summary>
  149. /// <param name="sender"></param>
  150. /// <param name="e"></param>
  151. private void tsbtnClose_Click(object sender, EventArgs e)
  152. {
  153. this.DialogResult = DialogResult.Cancel;
  154. this.Close();
  155. }
  156. /// <summary>
  157. /// 绑定条码
  158. /// </summary>
  159. /// <param name="sender"></param>
  160. /// <param name="e"></param>
  161. private void txtBarCodeStart_KeyPress(object sender, KeyPressEventArgs e)
  162. {
  163. if (e.KeyChar == Constant.SYSTEM_KEYBOARD_ENTER_VALUE)
  164. {
  165. this.btnBindBarCode_Click(sender, e);
  166. }
  167. }
  168. /// <summary>
  169. /// 绑定条码
  170. /// </summary>
  171. /// <param name="sender"></param>
  172. /// <param name="e"></param>
  173. private void btnBindBarCode_Click(object sender, EventArgs e)
  174. {
  175. try
  176. {
  177. string barcodeBegin = this.txtBarCodeStart.Text.Trim();
  178. if (barcodeBegin.Length <= 0)
  179. {
  180. DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_C_003, this.lblBarCodeStart.Text);
  181. this.txtBarCodeStart.Focus();
  182. return;
  183. }
  184. System.Text.RegularExpressions.Match mc =
  185. System.Text.RegularExpressions.Regex.Match(barcodeBegin, @"^([a-zA-Z]*|[a-zA-Z0-9]*[a-zA-Z]+)([0-9]{10,})$");
  186. if (!mc.Success)
  187. {
  188. DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_C_005, barcodeBegin);
  189. this.txtBarCodeStart.Focus();
  190. return;
  191. }
  192. string strLetter = mc.Groups[1].Value;
  193. string strDigit = mc.Groups[2].Value;
  194. decimal digit = Convert.ToDecimal(strDigit);
  195. int len = strDigit.Length;
  196. foreach (DataGridViewRow row in this.dgvDetail.Rows)
  197. {
  198. string barcode = strLetter + (digit++).ToString().PadLeft(len, '0');
  199. row.Cells["BarCode"].Value = barcode;
  200. DataRowView dataRow = row.DataBoundItem as DataRowView;
  201. if (dataRow != null)
  202. {
  203. dataRow.EndEdit();
  204. }
  205. }
  206. }
  207. catch (Exception ex)
  208. {
  209. // 对异常进行共通处理
  210. ExceptionManager.HandleEventException(this.ToString(),
  211. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  212. }
  213. }
  214. /// <summary>
  215. /// 清空条码
  216. /// </summary>
  217. /// <param name="sender"></param>
  218. /// <param name="e"></param>
  219. private void btnClearBarCode_Click(object sender, EventArgs e)
  220. {
  221. try
  222. {
  223. this.txtBarCodeStart.Clear();
  224. foreach (DataGridViewRow row in this.dgvDetail.Rows)
  225. {
  226. if (!row.Cells["BarCode"].ReadOnly)
  227. {
  228. row.Cells["BarCode"].Value = DBNull.Value;
  229. }
  230. }
  231. }
  232. catch (Exception ex)
  233. {
  234. // 对异常进行共通处理
  235. ExceptionManager.HandleEventException(this.ToString(),
  236. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  237. }
  238. }
  239. /// <summary>
  240. /// 保存数据
  241. /// </summary>
  242. private void btnSave_Click(object sender, EventArgs e)
  243. {
  244. try
  245. {
  246. // 验证条码重复
  247. DataTable dtDetail = dgvDetail.DataSource as DataTable;
  248. if (dtDetail == null || dtDetail.Rows.Count == 0)
  249. {
  250. MessageBox.Show(string.Format(Messages.W_CMN_C_006, "没有任何数据"),
  251. this.Text,
  252. MessageBoxButtons.OK,
  253. MessageBoxIcon.Warning);
  254. return;
  255. }
  256. DataRow[] drs = null;
  257. foreach (DataRow row in dtDetail.Rows)
  258. {
  259. string barcode = row["Barcode"].ToString().Trim();
  260. if (string.IsNullOrWhiteSpace(barcode))
  261. {
  262. row["Barcode"] = DBNull.Value;
  263. continue;
  264. }
  265. else
  266. {
  267. row["Barcode"] = barcode;
  268. }
  269. drs = dtDetail.Select("Barcode = '" + barcode + "' AND groutinglinedetailid <> " + row["groutinglinedetailid"]);
  270. if (drs != null && drs.Length > 0)
  271. {
  272. MessageBox.Show("有重复条码【" + barcode + "】",
  273. this.Text,
  274. MessageBoxButtons.OK,
  275. MessageBoxIcon.Warning);
  276. return;
  277. }
  278. }
  279. // 异步处理,获取信息
  280. ClientRequestEntity cre = new ClientRequestEntity();
  281. cre.NameSpace = "F_PM_0108";
  282. cre.Name = "SaveBarcodeDraft";
  283. cre.Properties["groutingdate"] = dtpGroutingDate.Value;
  284. cre.Properties["groutinglineid"] = scbGroutingLine.SearchedPKMember;
  285. cre.Properties["groutingbatchno"] = txtGroutingBatchno.Text.Trim();
  286. cre.Data = new DataSet();
  287. cre.Data.Tables.Add(dtDetail.Copy());
  288. // 调用服务器端获取数据集
  289. ServiceResultEntity sre = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() =>
  290. {
  291. return PMModuleProxyNew.Service.HandleRequest(cre);
  292. }));
  293. if (sre.OtherStatus > 0)
  294. {
  295. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, Text, "保存"),
  296. this.Text,
  297. MessageBoxButtons.OK,
  298. MessageBoxIcon.Information);
  299. _isSave = true;
  300. if (FormMode == Constant.FormMode.Add)
  301. {
  302. txtGroutingBatchno.Text = (cre.Properties["groutingbatchno"].ToNullableInt32() + 1) + "";
  303. txtBarCodeStart.Text = string.Empty;
  304. foreach (DataRow row in dtDetail.Rows)
  305. {
  306. row["Barcode"] = DBNull.Value;
  307. }
  308. }
  309. else
  310. {
  311. Close();
  312. }
  313. }
  314. else if (sre.OtherStatus < 0 && !string.IsNullOrEmpty(sre.Message))
  315. {
  316. // 提示未查找到数据
  317. MessageBox.Show(string.Format(Messages.W_CMN_C_006, sre.Message),
  318. this.Text,
  319. MessageBoxButtons.OK,
  320. MessageBoxIcon.Warning);
  321. }
  322. else
  323. {
  324. // 提示未查找到数据
  325. MessageBox.Show(Messages.MSG_CMN_W007,
  326. this.Text,
  327. MessageBoxButtons.OK,
  328. MessageBoxIcon.Warning);
  329. }
  330. }
  331. catch (Exception ex)
  332. {
  333. //this.SetEditGrid();
  334. // 对异常进行共通处理
  335. ExceptionManager.HandleEventException(this.ToString(),
  336. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  337. }
  338. }
  339. /// <summary>
  340. /// 成型线改变事件
  341. /// </summary>
  342. /// <param name="sender"></param>
  343. /// <param name="e"></param>
  344. private void scbGroutingLine_TextValueChanged(object sender, WinForm.Controls.ScbSearchBox.TextChangeEventArgs e)
  345. {
  346. try
  347. {
  348. dgvDetail.DataSource = null;
  349. if (scbGroutingLine.SearchedPKMember != 0)
  350. {
  351. // 异步处理,获取信息
  352. ClientRequestEntity cre = new ClientRequestEntity();
  353. cre.NameSpace = "F_PM_0108";
  354. cre.Name = "GetGroutingLineByGroutingID";
  355. cre.Properties["groutinglineid"] = scbGroutingLine.SearchedPKMember;
  356. cre.Properties["groutingdate"] = dtpGroutingDate.Value;
  357. // 调用服务器端获取数据集
  358. ServiceResultEntity sre = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() =>
  359. {
  360. return PMModuleProxyNew.Service.HandleRequest(cre);
  361. }));
  362. if (sre.Data != null && sre.Data.Tables.Count > 0)
  363. {
  364. dgvDetail.DataSource = sre.Data.Tables[0];
  365. txtGroutingBatchno.Text = sre.Result + "";
  366. }
  367. }
  368. }
  369. catch (Exception ex)
  370. {
  371. //this.SetEditGrid();
  372. // 对异常进行共通处理
  373. ExceptionManager.HandleEventException(this.ToString(),
  374. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  375. }
  376. }
  377. /// <summary>
  378. /// 关闭窗体
  379. /// </summary>
  380. private void btnCancel_Click(object sender, EventArgs e)
  381. {
  382. this.Close();
  383. }
  384. /// <summary>
  385. /// 窗体关闭事件
  386. /// </summary>
  387. /// <param name="sender"></param>
  388. /// <param name="e"></param>
  389. private void F_PM_0108_FormClosing(object sender, FormClosingEventArgs e)
  390. {
  391. if (_isSave)
  392. {
  393. DialogResult = DialogResult.OK;
  394. }
  395. }
  396. #endregion
  397. #region 私有方法
  398. /// <summary>
  399. /// 取得注浆日报信息
  400. /// </summary>
  401. private void InitializeData()
  402. {
  403. try
  404. {
  405. if (FormMode == Constant.FormMode.Add)
  406. {
  407. this.Text = FormTitles.F_PM_0107_ADD;
  408. dtpGroutingDate.Value = DateTime.Now.Date.AddDays(1);
  409. dtpGroutingDate.MinDate = DateTime.Now.Date;
  410. }
  411. else if (FormMode == Constant.FormMode.Edit)
  412. {
  413. this.Text = FormTitles.F_PM_0107_EDIT;
  414. dtpGroutingDate.Value = Convert.ToDateTime(DrRow["groutingdate"]);
  415. scbGroutingLine.Text = DrRow["GroutingLineCode"] + "";
  416. scbGroutingLine.SearchedPKMember = Convert.ToInt32(DrRow["groutinglineid"]);
  417. txtGroutingBatchno.Text = DrRow["GroutingBatchno"] + "";
  418. dtpGroutingDate.Enabled = false;
  419. scbGroutingLine.Enabled = false;
  420. txtGroutingBatchno.ReadOnly = true;
  421. // 异步处理,获取信息
  422. ClientRequestEntity cre = new ClientRequestEntity();
  423. cre.NameSpace = "F_PM_0108";
  424. cre.Name = "GetBarcodeDraft";
  425. cre.Properties["groutinglineid"] = DrRow["groutinglineid"];
  426. cre.Properties["groutingbatchno"] = DrRow["groutingbatchno"];
  427. cre.Properties["groutingdate"] = DrRow["groutingdate"];
  428. // 调用服务器端获取数据集
  429. ServiceResultEntity sre = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() =>
  430. {
  431. return PMModuleProxyNew.Service.HandleRequest(cre);
  432. }));
  433. if (sre.Data != null && sre.Data.Tables.Count > 0)
  434. {
  435. dgvDetail.DataSource = sre.Data.Tables[0];
  436. }
  437. }
  438. }
  439. catch (Exception ex)
  440. {
  441. throw ex;
  442. }
  443. }
  444. #endregion
  445. }
  446. }