F_PC_0101_1_6.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PC_0101_1_6.cs
  5. * 2.功能描述:操作时间及备注录入
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2015/09/25 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Windows.Forms;
  12. using System.Data;
  13. using Dongke.IBOSS.PRD.Basics.BaseControls;
  14. using Dongke.IBOSS.PRD.Basics.BaseResources;
  15. using Dongke.IBOSS.PRD.WCF.Proxys;
  16. using Dongke.IBOSS.PRD.Client.CommonModule;
  17. namespace Dongke.IBOSS.PRD.Client.PCModule
  18. {
  19. public partial class F_PC_0101_1_6 : FormBase
  20. {
  21. #region 成员变量
  22. // 窗体标题
  23. private string _titleStr = "";
  24. // 实例窗体
  25. //private F_PC_0101 _fpc0101;
  26. private DataTable _dtBindSource = null;
  27. //默认模具编号
  28. private string _defaultNo = "";
  29. //成型线ID
  30. private int _groutingLineID = 0;
  31. private DataTable _orgdtBindSource = null;
  32. private int _lastGMouldRecordID = 0;
  33. #endregion
  34. #region 构造函数
  35. //public F_PC_0101_1_6(F_PC_0101 fpc0101, string titleStr)
  36. //{
  37. // InitializeComponent();
  38. // this._titleStr = titleStr;
  39. // this._fpc0101 = fpc0101;
  40. // this._fpc0101.SetTimeOrRemarks(null, "");
  41. // this.Text = _titleStr;
  42. // this.btnSave.Text = ButtonText.BTN_SAVE;
  43. //}
  44. public F_PC_0101_1_6(DataTable dtBindSource, string titleStr)
  45. {
  46. InitializeComponent();
  47. _dtBindSource = dtBindSource;
  48. _orgdtBindSource = dtBindSource.Copy();
  49. if (!this._dtBindSource.Columns.Contains("NewFlag"))
  50. {
  51. DataColumn colNew = new DataColumn();
  52. colNew.ColumnName = "NewFlag";
  53. colNew.DefaultValue = 0;
  54. _dtBindSource.Columns.Add(colNew);
  55. }
  56. if (!this._orgdtBindSource.Columns.Contains("NewFlag"))
  57. {
  58. DataColumn colNew2 = new DataColumn();
  59. colNew2.ColumnName = "NewFlag";
  60. colNew2.DefaultValue = 0;
  61. _orgdtBindSource.Columns.Add(colNew2);
  62. }
  63. if (dtBindSource != null && dtBindSource.Rows.Count > 0)
  64. {
  65. string[] subSplit = dtBindSource.Rows[0]["GroutingMouldCode"].ToString().Split('-');
  66. for (int i = 0; i < subSplit.Length; i++)
  67. {
  68. if (i != subSplit.Length - 1)
  69. {
  70. _defaultNo += subSplit[i] + "-";
  71. }
  72. }
  73. //_defaultNo = dtBindSource.Rows[0]["GroutingMouldCode"].ToString().Split('-')[0] + "-";
  74. }
  75. this.Text = titleStr;
  76. this.btnSave.Text = ButtonText.BTN_SAVE;
  77. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  78. _groutingLineID = Convert.ToInt32(dtBindSource.Rows[0]["groutingLineID"].ToString());
  79. _lastGMouldRecordID = Convert.ToInt32(dtBindSource.Rows[0]["lastGMouldRecordID"].ToString());
  80. this.txtGroutingLineCode.Text = dtBindSource.Rows[0]["GroutingLineCode"].ToString();
  81. this.txtRecordRemarks.Text = dtBindSource.Rows[0]["RecordRemarks"].ToString();
  82. }
  83. #endregion
  84. #region 事件
  85. /// <summary>
  86. /// 保存按钮事件
  87. /// </summary>
  88. /// <param name="sender"></param>
  89. /// <param name="e"></param>
  90. private void btnSave_Click(object sender, EventArgs e)
  91. {
  92. try
  93. {
  94. //if (this.dkGoodsCode.GoodsID == null)
  95. //{
  96. // MessageBox.Show("产品编码是必填项");
  97. // return;
  98. //}
  99. DataTable dtName = this.dgvGroutingLineDetail.DataSource as DataTable;
  100. dtName.Copy();
  101. dtName.TableName = "GMouldRecord";
  102. if(dtName.Rows.Count==0)
  103. {
  104. return;
  105. }
  106. //this._orgdtBindSource.Merge(dtName);
  107. DataTable dtSave = dtName.Copy();
  108. dtSave.Merge(this._orgdtBindSource);
  109. if (dtSave.Rows.Count > 0)
  110. {
  111. dtSave.Rows[0]["RecordRemarks"] = this.txtRecordRemarks.Text.Trim();
  112. }
  113. int returnRow = (int)DoAsync(new BaseAsyncMethod(() =>
  114. {
  115. return PCModuleProxy.Service.UpdateAllLineEndGroutingLineDetail(dtSave, Convert.ToInt32(this.dkGoodsCode.GoodsID));
  116. }));
  117. if (returnRow > 0)
  118. {
  119. //停用成功
  120. //MessageBox.Show(this.Text + "成功");
  121. MessageBox.Show(this.Text + "成功", this.Text,
  122. MessageBoxButtons.OK, MessageBoxIcon.Information);
  123. this.DialogResult = DialogResult.OK;
  124. }
  125. else if (returnRow == -500)
  126. {
  127. //停用成功
  128. // MessageBox.Show("数据已经被修改,请重新编辑");
  129. MessageBox.Show("数据已经被修改,请重新编辑", this.Text,
  130. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  131. this.DialogResult = DialogResult.No;
  132. }
  133. else if (returnRow == -500)
  134. {
  135. //停用成功
  136. //MessageBox.Show(this.Text + "失败");
  137. MessageBox.Show(this.Text + "失败", this.Text,
  138. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  139. this.DialogResult = DialogResult.No;
  140. }
  141. }
  142. catch (Exception ex)
  143. {
  144. // 对异常进行共通处理
  145. ExceptionManager.HandleEventException(this.ToString(),
  146. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  147. }
  148. }
  149. /// <summary>
  150. /// 窗体加载事件
  151. /// </summary>
  152. /// <param name="sender"></param>
  153. /// <param name="e"></param>
  154. private void F_PC_0101_1_2_Load(object sender, EventArgs e)
  155. {
  156. this.dgvGroutingLineDetail.AutoGenerateColumns = false;
  157. DateTime accountDate = (DateTime)DoAsync(new BaseAsyncMethod(() =>
  158. {
  159. return CommonModuleProxy.Service.GetAccountDate();
  160. }));
  161. this.txtDateStart.Value = accountDate;
  162. _dtBindSource.Rows.Clear();//
  163. this.dgvGroutingLineDetail.DataSource = _dtBindSource;
  164. // 设置可输入单元格的颜色
  165. this.dgvGroutingLineDetail.IsSetInputColumnsColor = true;
  166. }
  167. /// <summary>
  168. /// 追加模具
  169. /// </summary>
  170. /// <param name="sender"></param>
  171. /// <param name="e"></param>
  172. private void btnAddMould_Click(object sender, EventArgs e)
  173. {
  174. try
  175. {
  176. if (dkGoodsCode.GoodsID == null)
  177. {
  178. MessageBox.Show("产品编码是必填项", this.Text,
  179. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  180. return;
  181. }
  182. if (txtBeginNum.Text.Trim() == "")
  183. {
  184. MessageBox.Show("起始模具号是必填项", this.Text,
  185. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  186. return;
  187. }
  188. if (txtCount.Text.Trim() == "")
  189. {
  190. MessageBox.Show("模具数量是必填项", this.Text,
  191. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  192. return;
  193. }
  194. if (txtStandardGroutingCount.Text.Trim() == "")
  195. {
  196. MessageBox.Show("标准注浆次数", this.Text,
  197. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  198. return;
  199. }
  200. int startNo = Convert.ToInt32(txtBeginNum.Text);
  201. int addCount = Convert.ToInt32(txtCount.Text);
  202. string filterNum = "";
  203. bool isError = false;
  204. //声明临时表格,遍成每个模具编号是否重复,如果不重复则进行数据添加
  205. for (int i = 0; i < Convert.ToInt32(addCount); i++)
  206. {
  207. filterNum = string.Format("{0}{1}", this._defaultNo, startNo.ToString().PadLeft(3, '0'));
  208. DataRow[] r = _dtBindSource.Select("GroutingMouldCode='" + filterNum + "'");
  209. if (r.Length > 0)
  210. {
  211. isError = true;
  212. break;
  213. }
  214. startNo = startNo + 1;
  215. }
  216. if (isError)
  217. {
  218. MessageBox.Show("存在相同的模具编号" + filterNum);
  219. return;
  220. }
  221. startNo = Convert.ToInt32(txtBeginNum.Text);
  222. for (int i = 0; i < Convert.ToInt32(addCount); i++)
  223. {
  224. filterNum = string.Format("{0}{1}", this._defaultNo, startNo.ToString().PadLeft(3, '0'));
  225. DataRow dr = _dtBindSource.NewRow();
  226. dr["GroutingLineID"] = this._groutingLineID;
  227. dr["GroutingMouldCode"] = filterNum;
  228. dr["GOODSCODE"] = this.dkGoodsCode.Text;
  229. dr["GoodsID"] = this.dkGoodsCode.GoodsID;
  230. dr["lastGMouldRecordID"] = this._lastGMouldRecordID;
  231. dr["StandardGroutingCount"] = txtStandardGroutingCount.DataValue.Value;
  232. dr["GroutingCount"] = 0;
  233. dr["GMOULDSTATUSNAME"] = "正常";
  234. dr["GMouldStatus"] = 1;
  235. dr["NewFlag"] = 1;//1代表新建
  236. _dtBindSource.Rows.Add(dr);
  237. startNo = startNo + 1;
  238. }
  239. _dtBindSource.AcceptChanges();
  240. this.dgvGroutingLineDetail.IsSetInputColumnsColor = true;
  241. }
  242. catch (Exception ex)
  243. {
  244. // 对异常进行共通处理
  245. ExceptionManager.HandleEventException(this.ToString(),
  246. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  247. }
  248. }
  249. /// <summary>
  250. /// 删除模具按钮事件
  251. /// </summary>
  252. /// <param name="sender"></param>
  253. /// <param name="e"></param>
  254. private void btnDeleteSelected_Click(object sender, EventArgs e)
  255. {
  256. try
  257. {
  258. if (this.dgvGroutingLineDetail.CurrentCell != null)
  259. {
  260. if (this._dtBindSource == null || this._dtBindSource.Rows.Count == Constant.INT_IS_ZERO)
  261. {
  262. return;
  263. }
  264. string NewFlag = this.dgvGroutingLineDetail.Rows[this.dgvGroutingLineDetail.CurrentCell.RowIndex].Cells["NewFlag"].Value.ToString();
  265. if (NewFlag == "0")
  266. {
  267. MessageBox.Show(Messages.MSG_PC_W002, this.Text,
  268. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  269. return;
  270. }
  271. this._dtBindSource.Rows[this.dgvGroutingLineDetail.CurrentCell.RowIndex].Delete();
  272. this._dtBindSource.AcceptChanges();
  273. this.dgvGroutingLineDetail.IsSetInputColumnsColor = true;
  274. }
  275. }
  276. catch (Exception ex)
  277. {
  278. // 对异常进行共通处理
  279. ExceptionManager.HandleEventException(this.ToString(),
  280. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  281. }
  282. }
  283. /// <summary>
  284. /// 排序事件
  285. /// </summary>
  286. /// <param name="sender"></param>
  287. /// <param name="e"></param>
  288. private void dgvGroutingLineDetail_Sorted(object sender, EventArgs e)
  289. {
  290. this.dgvGroutingLineDetail.IsSetInputColumnsColor = true;
  291. }
  292. #endregion
  293. }
  294. }