F_PM_0102.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PM_0102.cs
  5. * 2.功能描述:注浆登记
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈晓野 2015/03/25 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Data;
  12. using System.Reflection;
  13. using System.Text;
  14. using System.Windows.Forms;
  15. using Dongke.IBOSS.PRD.Basics.BaseControls;
  16. using Dongke.IBOSS.PRD.Basics.BaseResources;
  17. using Dongke.IBOSS.PRD.Client.CommonModule;
  18. using Dongke.IBOSS.PRD.Client.Controls;
  19. using Dongke.IBOSS.PRD.WCF.DataModels;
  20. using Dongke.IBOSS.PRD.WCF.Proxys;
  21. using Dongke.IBOSS.PRD.Basics.Library;
  22. using System.Collections.Generic;
  23. using System.Linq;
  24. namespace Dongke.IBOSS.PRD.Client.PMModule
  25. {
  26. /// <summary>
  27. /// 注浆登记新建和编辑页面
  28. /// </summary>
  29. public partial class F_PM_0102 : DKFormBase
  30. {
  31. #region 成员变量
  32. // 窗体模式ID
  33. private Constant.FormMode _formMode = Constant.FormMode.Add;
  34. // 未注浆原因,传给选择页面
  35. private DataTable _dtNotGroutingRreason;
  36. // 注浆日报ID
  37. private int _dailyId;
  38. // 注浆日期
  39. private DateTime _groutingDate = DateTime.Now.Date;
  40. // 账务日期
  41. private DateTime _accountDate = DateTime.Now.Date;
  42. //private decimal? _logoid = null;
  43. private bool _canEdit = true;
  44. #endregion
  45. #region 构造函数
  46. /// <summary>
  47. /// 构造函数
  48. /// </summary>
  49. public F_PM_0102()
  50. :this(0)
  51. {
  52. }
  53. /// <summary>
  54. /// 构造函数
  55. /// </summary>
  56. /// <param name="dailyID">注浆日报ID:新建时为0</param>
  57. public F_PM_0102(int dailyID)
  58. {
  59. this.InitializeComponent();
  60. this._dailyId = dailyID;
  61. this.InitializeControls();
  62. }
  63. #endregion
  64. #region 属性
  65. /// <summary>
  66. /// 注浆登记的ID(多个用【,】隔开)
  67. /// </summary>
  68. public string GroutingDailyIDs
  69. {
  70. get;
  71. private set;
  72. }
  73. #endregion
  74. #region 事件
  75. /// <summary>
  76. /// 窗体加载
  77. /// </summary>
  78. private void F_PM_0102_Load(object sender, EventArgs e)
  79. {
  80. try
  81. {
  82. this.lblGroutingDateValue.Text = string.Empty;
  83. DataSet logoInfo = SystemModuleProxy.Service.GetLogoInfo();
  84. if (logoInfo != null && logoInfo.Tables.Count > 0)
  85. {
  86. this.cmbLogo.DataSource = logoInfo.Tables[0];
  87. this.cmbLogo.DisplayMember = "LogoNameCode";
  88. this.cmbLogo.ValueMember = "LogoID";
  89. this.colLogo.DataSource = logoInfo.Tables[0].Copy();
  90. this.colLogo.DisplayMember = "LogoNameCode";
  91. this.colLogo.ValueMember = "LogoID";
  92. //if(logoInfo.Tables[0].Rows.Count > 0)
  93. //{
  94. // _logoid = Convert.ToDecimal(logoInfo.Tables[0].Rows[0]["LogoID"]);
  95. //}
  96. }
  97. // 设置列表未注浆原因选项数据源
  98. this.InitializeData();
  99. }
  100. catch (Exception ex)
  101. {
  102. // 对异常进行共通处理
  103. ExceptionManager.HandleEventException(this.ToString(),
  104. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  105. }
  106. }
  107. /// <summary>
  108. /// 全线注浆按钮按下,生成该成型班长的所有注浆信息
  109. /// </summary>
  110. /// <param name="sender"></param>
  111. /// <param name="e"></param>
  112. private void tsbtnAllGrouting_Click(object sender, EventArgs e)
  113. {
  114. try
  115. {
  116. // 获取登录用户所有的注浆信息,并绑定
  117. this.txtGrouting.Clear();
  118. this.dgvDetail.DataSource = null;
  119. this.DataSource = null;
  120. this.DataSource = this.GetGroutingDailyInfo(null, null);
  121. if (this.DataSource != null && this.DataSource.Tables.Count == 2)
  122. {
  123. StringBuilder groutingLines = new StringBuilder();
  124. foreach (DataRow row in this.DataSource.Tables[0].Rows)
  125. {
  126. if (groutingLines.Length > 0)
  127. {
  128. groutingLines.Append(", ");
  129. }
  130. groutingLines.Append(string.Format("{0}({1})", row["GroutingLineCode"], row["MouldQuantity"]));
  131. }
  132. this.DataSource.Tables[1].Columns.Add("NoGroutingRreason", typeof(decimal));
  133. this.DataSource.Tables[1].Columns.Add("Remarks", typeof(string));
  134. //DataColumn dc = new DataColumn("LogoID", typeof(decimal));
  135. //if (_logoid.HasValue)
  136. //{
  137. // dc.DefaultValue = _logoid.Value;
  138. //}
  139. //this.DataSource.Tables[1].Columns.Add(dc);
  140. this.txtGrouting.Text = groutingLines.ToString();
  141. this.dgvDetail.DataSource = this.DataSource.Tables[1];
  142. this.dgvDetail.IsSetInputColumnsColor = true;
  143. // 按钮状态
  144. this.tsbtnAllGrouting.Enabled = false;
  145. this.tsbtnGrouting.Enabled = false;
  146. this.tsbtnClearDetail.Enabled = true;
  147. this.tsbtnChangeGroutingUser.Enabled = true;
  148. this.btnSave.Enabled = true;
  149. }
  150. }
  151. catch (Exception ex)
  152. {
  153. // 对异常进行共通处理
  154. ExceptionManager.HandleEventException(this.ToString(),
  155. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  156. }
  157. }
  158. /// <summary>
  159. /// 部分注浆按钮按下,弹出选择成型线窗体
  160. /// </summary>
  161. /// <param name="sender"></param>
  162. /// <param name="e"></param>
  163. private void tsbtnGrouting_Click(object sender, EventArgs e)
  164. {
  165. try
  166. {
  167. // 打开选择成型线页面
  168. F_PM_0104_1 frmPM0104 = new F_PM_0104_1();
  169. frmPM0104.NotGroutingRreason = this._dtNotGroutingRreason;
  170. DialogResult dialogResult = frmPM0104.ShowDialog();
  171. if (DialogResult.OK == dialogResult && frmPM0104.GroutingInfo.Length > 0)
  172. {
  173. // 根据选择成型线页面返回成型线,取得注浆明细数据
  174. string groutingLineIDs = string.Empty;
  175. foreach (DataRow dataRow in frmPM0104.GroutingInfo)
  176. {
  177. if (groutingLineIDs.Length > 0)
  178. {
  179. groutingLineIDs += ",";
  180. }
  181. groutingLineIDs += dataRow["GroutingLineID"].ToString();
  182. }
  183. this.txtGrouting.Clear();
  184. this.dgvDetail.DataSource = null;
  185. this.DataSource = null;
  186. this.DataSource = this.GetGroutingDailyInfo(frmPM0104.GroutingDate, groutingLineIDs);
  187. // 组成页面的注浆日期、注浆成型线显示信息,并且绑定注浆信息的数据源
  188. if (this.DataSource != null && this.DataSource.Tables.Count == 2)
  189. {
  190. StringBuilder groutingLines = new StringBuilder();
  191. // 根据成型线选择注浆原因,控制注浆列表的未注浆选择列
  192. this.DataSource.Tables[1].Columns.Add("NoGroutingRreason", typeof(decimal));
  193. this.DataSource.Tables[1].Columns.Add("Remarks", typeof(string));
  194. //DataColumn dc = new DataColumn("LogoID", typeof(decimal));
  195. //if (_logoid.HasValue)
  196. //{
  197. // dc.DefaultValue = _logoid.Value;
  198. //}
  199. //this.DataSource.Tables[1].Columns.Add(dc);
  200. foreach (DataRow dataRow in frmPM0104.GroutingInfo)
  201. {
  202. string sqlWhere = "GroutingLineID = " + dataRow["GroutingLineID"].ToString();
  203. DataRow[] drLines = this.DataSource.Tables[0].Select(sqlWhere);
  204. if (drLines == null || drLines.Length == 0)
  205. {
  206. continue;
  207. }
  208. DataRow[] drs = this.DataSource.Tables[1].Select("GroutingLineID = " + dataRow["GroutingLineID"].ToString());
  209. if (drs == null || drs.Length == 0)
  210. {
  211. drLines[0].Delete();
  212. continue;
  213. }
  214. if (groutingLines.Length > 0)
  215. {
  216. groutingLines.Append(", ");
  217. }
  218. groutingLines.Append(string.Format("{0}({1})[{2}]", drLines[0]["GroutingLineCode"], drLines[0]["MouldQuantity"], drLines[0]["monitorcode"]));
  219. drLines[0]["UserID"] = dataRow["GroutingUserID"];
  220. drLines[0]["UserCode"] = dataRow["GroutingUserCode"];
  221. string canManyTimes = drLines[0]["CanManyTimes"].ToString();
  222. int num = System.Convert.ToInt32(dataRow["GroutingNum"]);
  223. int batchNo = System.Convert.ToInt32(drLines[0]["GroutingBatchNo"]);
  224. if (num > 1 && "1" == canManyTimes)
  225. {
  226. for (int i = 1; i < num; i++)
  227. {
  228. DataRow newRow = this.DataSource.Tables[0].Rows.Add(drLines[0].ItemArray);
  229. newRow["GroutingBatchNo"] = batchNo + i;
  230. }
  231. }
  232. foreach (DataRow detailDataRow in drs)
  233. {
  234. detailDataRow["GroutingUserID"] = dataRow["GroutingUserID"];
  235. detailDataRow["GroutingUserCode"] = dataRow["GroutingUserCode"];
  236. object NoGroutingRreason = dataRow["NoGroutingRreason"];
  237. if (NoGroutingRreason != null && NoGroutingRreason != DBNull.Value)
  238. {
  239. detailDataRow["GroutingFlag"] = (int)Constant.GroutingFlag.No;
  240. detailDataRow["NoGroutingRreason"] = dataRow["NoGroutingRreason"];
  241. }
  242. if (num > 1 && "1" == canManyTimes)
  243. {
  244. for (int i = 1; i < num; i++)
  245. {
  246. DataRow newRow = this.DataSource.Tables[1].Rows.Add(detailDataRow.ItemArray);
  247. newRow["GroutingBatchNo"] = batchNo + i;
  248. }
  249. }
  250. }
  251. }
  252. this.DataSource.AcceptChanges();
  253. this.DataSource.Tables[1].DefaultView.Sort = "GroutingLineCode, GroutingBatchNo, GroutingMouldCode";
  254. this.txtGrouting.Text = groutingLines.ToString();
  255. this.dgvDetail.DataSource = this.DataSource.Tables[1];
  256. this.dgvDetail.IsSetInputColumnsColor = true;
  257. // 按钮状态
  258. this.tsbtnAllGrouting.Enabled = false;
  259. this.tsbtnGrouting.Enabled = false;
  260. this.tsbtnClearDetail.Enabled = true;
  261. this.tsbtnChangeGroutingUser.Enabled = true;
  262. this.btnSave.Enabled = true;
  263. }
  264. }
  265. }
  266. catch (Exception ex)
  267. {
  268. // 对异常进行共通处理
  269. ExceptionManager.HandleEventException(this.ToString(),
  270. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  271. }
  272. }
  273. /// <summary>
  274. /// 更改成型工按钮按下,整个成型线更换成型工
  275. /// </summary>
  276. /// <param name="sender"></param>
  277. /// <param name="e"></param>
  278. private void tsbtnChangeGroutingUser_Click(object sender, EventArgs e)
  279. {
  280. try
  281. {
  282. }
  283. catch (Exception ex)
  284. {
  285. // 对异常进行共通处理
  286. ExceptionManager.HandleEventException(this.ToString(),
  287. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  288. }
  289. }
  290. /// <summary>
  291. /// 清空注浆明细按钮按钮,清空注浆信息,可以重新进行注浆
  292. /// </summary>
  293. /// <param name="sender"></param>
  294. /// <param name="e"></param>
  295. private void tsbtnClearDetail_Click(object sender, EventArgs e)
  296. {
  297. this.txtGrouting.Clear();
  298. this.dgvDetail.DataSource = null;
  299. this.DataSource = null;
  300. this.lblGroutingDateValue.Text = this._accountDate.Date.ToString(Constant.S_DATE_YYYY_MM_DD);
  301. // 清空注浆信息后,清空明细、更换成型工按钮不可用
  302. this.tsbtnAllGrouting.Enabled = true;
  303. this.tsbtnGrouting.Enabled = true;
  304. this.tsbtnClearDetail.Enabled = false;
  305. this.tsbtnChangeGroutingUser.Enabled = false;
  306. this.btnSave.Enabled = false;
  307. }
  308. /// <summary>
  309. /// 提交选择列内容的修改
  310. /// </summary>
  311. /// <param name="sender"></param>
  312. /// <param name="e"></param>
  313. private void dgvDetail_CurrentCellDirtyStateChanged(object sender, EventArgs e)
  314. {
  315. try
  316. {
  317. if (this.dgvDetail.CurrentRow != null && this.dgvDetail.IsCurrentCellDirty)
  318. {
  319. if ("GroutingFlag".Equals(this.dgvDetail.Columns
  320. [this.dgvDetail.CurrentCell.ColumnIndex].Name))
  321. {
  322. this.dgvDetail.CommitEdit(DataGridViewDataErrorContexts.Commit);
  323. }
  324. }
  325. }
  326. catch (Exception ex)
  327. {
  328. // 对异常进行共通处理
  329. ExceptionManager.HandleEventException(this.ToString(),
  330. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  331. }
  332. }
  333. /// <summary>
  334. /// 未注浆时,未注浆原因才可以输入
  335. /// </summary>
  336. private void dgvDetail_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  337. {
  338. try
  339. {
  340. if (e.RowIndex != Constant.INT_IS_NEGATIE_ONE && this._canEdit)
  341. {
  342. DataGridViewRow dataGridViewRow = this.dgvDetail.Rows[e.RowIndex];
  343. // 如果是改变了注浆标识,则对未注浆原因进行控制输入
  344. if ( "GroutingFlag".Equals(this.dgvDetail.Columns[e.ColumnIndex].Name))
  345. {
  346. // 选择了未注浆
  347. if (((int)Constant.GroutingFlag.Yes).ToString() != dataGridViewRow.Cells["GroutingFlag"].Value.ToString())
  348. {
  349. dataGridViewRow.Cells["NoGroutingRreason"].ReadOnly = false;
  350. }
  351. else
  352. {
  353. dataGridViewRow.Cells["NoGroutingRreason"].ReadOnly = true;
  354. this.dgvDetail.Rows[e.RowIndex].Cells["NoGroutingRreason"].Value = DBNull.Value;
  355. }
  356. }
  357. }
  358. }
  359. catch (Exception ex)
  360. {
  361. // 对异常进行共通处理
  362. ExceptionManager.HandleEventException(this.ToString(),
  363. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  364. }
  365. }
  366. /// <summary>
  367. /// 排序后设置Grid状态
  368. /// </summary>
  369. /// <param name="sender"></param>
  370. /// <param name="e"></param>
  371. private void dgvDetail_Sorted(object sender, EventArgs e)
  372. {
  373. this.SetEditGrid();
  374. this.dgvDetail.IsSetInputColumnsColor = true;
  375. }
  376. /// <summary>
  377. /// 自动列宽
  378. /// </summary>
  379. /// <param name="sender"></param>
  380. /// <param name="e"></param>
  381. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  382. {
  383. this.dgvDetail.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  384. }
  385. /// <summary>
  386. /// 页面关闭
  387. /// </summary>
  388. /// <param name="sender"></param>
  389. /// <param name="e"></param>
  390. private void tsbtnClose_Click(object sender, EventArgs e)
  391. {
  392. this.DialogResult = DialogResult.Cancel;
  393. this.Close();
  394. }
  395. /// <summary>
  396. /// 保存数据
  397. /// </summary>
  398. private void btnSave_Click(object sender, EventArgs e)
  399. {
  400. // 没有注浆数据
  401. if (this.DataSource == null || this.DataSource.Tables.Count != 2)
  402. {
  403. return;
  404. }
  405. try
  406. {
  407. DataRow[] noGroutingDataRow = this.DataSource.Tables[1].Select("GroutingFlag = 0 AND NoGroutingRreason IS NULL");
  408. if (noGroutingDataRow != null && noGroutingDataRow.Length > 0)
  409. {
  410. string mc = null;
  411. foreach (DataRow dataRow in noGroutingDataRow)
  412. {
  413. if (mc != null)
  414. {
  415. mc += ",";
  416. }
  417. mc += dataRow["GroutingMouldCode"].ToString();
  418. }
  419. DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_C_006,
  420. "以下模具编号既没有注浆也没有未注浆原因" + Environment.NewLine + mc);
  421. return;
  422. }
  423. // 使用HashSet<T>来去重
  424. HashSet<string> uniqueValues = new HashSet<string>();
  425. HashSet<int> logoid = new HashSet<int>();
  426. //产品编码
  427. string goodscode = string.Empty;
  428. //遍历页面值
  429. foreach (DataRow row in DataSource.Tables[1].Rows)
  430. {
  431. //找到指定要去重的列名
  432. string value = row.Field<string>("GOODSCODE");
  433. int value2 = int.Parse(row.Field<decimal>("LOGOID").ToString());
  434. // 将值添加到HashSet中,它会自动去重
  435. uniqueValues.Add(value);
  436. logoid.Add(value2);
  437. }
  438. //拼接产品编码
  439. foreach (var i in uniqueValues)
  440. {
  441. goodscode += "'" + i.Trim() + "',";
  442. }
  443. //去除最后的逗号
  444. goodscode = goodscode.TrimEnd(',');
  445. //请求服务
  446. //根据表中GOODSCODE去查找对应的商标
  447. ServiceResultEntity sreByid = DoAsync<ServiceResultEntity>(() =>
  448. {
  449. ClientRequestEntity cre = new ClientRequestEntity();
  450. cre.NameSpace = "F_PM_0102";
  451. cre.Name = "GetLogoInfoByLogoID";
  452. cre.Properties["GOODSCODE"] = goodscode;
  453. return SystemModuleProxy.Service.DoRequest(cre);
  454. });
  455. // 使用LINQ查询找出不在DataTable中的数字
  456. var missingNumbers = logoid.Except(sreByid.Data.Tables[0].AsEnumerable().Select(ex => int.Parse(ex[0].ToString()))).ToList();
  457. //当存在产品没有商标时
  458. if (missingNumbers.Count() > 0)
  459. {
  460. //拿到所有产品商标
  461. DataTable dt = (DataTable)colLogo.DataSource;
  462. //找到不符的商标
  463. DataRow[] foundRows = dt.Select("LOGOID = " + missingNumbers.FirstOrDefault());
  464. //弹窗警告
  465. DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_C_006,
  466. "产品编码 " + DataSource.Tables[1].Select("LOGOID = " + missingNumbers.FirstOrDefault())[0][12] + " 没有 " + foundRows[0][4] + " 商标");
  467. return;
  468. }
  469. DateTime? date = null;
  470. if (this._formMode == Constant.FormMode.Add)
  471. {
  472. date = this._groutingDate;
  473. }
  474. ServiceResultEntity sre = this.DoAsync<ServiceResultEntity>(() =>
  475. {
  476. return PMModuleProxyNew.Service.SetFPM0102Data(date, this.DataSource);
  477. }
  478. );
  479. if (sre.Status == Constant.ServiceResultStatus.Success)
  480. {
  481. DKMessageBox.ShowDialog(this, DKMessageCode.I_CMN_S_002);
  482. if (sre.Result != null)
  483. {
  484. this.GroutingDailyIDs = sre.Result.ToString();
  485. }
  486. this.DialogResult = DialogResult.OK;
  487. this.Close();
  488. return;
  489. }
  490. if (sre.Status == Constant.ServiceResultStatus.Other)
  491. {
  492. DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_S_004, sre.Message);
  493. }
  494. this.SetEditGrid();
  495. }
  496. catch (Exception ex)
  497. {
  498. this.SetEditGrid();
  499. // 对异常进行共通处理
  500. ExceptionManager.HandleEventException(this.ToString(),
  501. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  502. }
  503. }
  504. /// <summary>
  505. /// 关闭窗体
  506. /// </summary>
  507. private void btnCancel_Click(object sender, EventArgs e)
  508. {
  509. this.DialogResult = DialogResult.Cancel;
  510. this.Close();
  511. }
  512. /// <summary>
  513. /// 设置注浆状态和未注浆原因
  514. /// </summary>
  515. /// <param name="sender"></param>
  516. /// <param name="e"></param>
  517. private void btnNGRSetting_Click(object sender, EventArgs e)
  518. {
  519. if (this.cboNoGroutingRreason.SelectedIndex < 0 || !this._canEdit)
  520. {
  521. return;
  522. }
  523. try
  524. {
  525. object noGroutingRreason = null;
  526. // 未注浆原因
  527. if (Constant.CBO_SELECT_ALL_VALUE.ToString() != this.cboNoGroutingRreason.SelectedValue.ToString())
  528. {
  529. noGroutingRreason = this.cboNoGroutingRreason.SelectedValue;
  530. }
  531. foreach (DataGridViewRow row in this.dgvDetail.Rows)
  532. {
  533. if (!row.Cells["GroutingFlag"].ReadOnly)
  534. {
  535. if (noGroutingRreason == null)
  536. {
  537. row.Cells["NoGroutingRreason"].Value = DBNull.Value;
  538. row.Cells["GroutingFlag"].Value = (int)Constant.GroutingFlag.Yes;
  539. }
  540. else
  541. {
  542. row.Cells["NoGroutingRreason"].Value = noGroutingRreason;
  543. row.Cells["GroutingFlag"].Value = (int)Constant.GroutingFlag.No;
  544. }
  545. DataRowView dataRow = row.DataBoundItem as DataRowView;
  546. if (dataRow != null)
  547. {
  548. dataRow.EndEdit();
  549. }
  550. }
  551. }
  552. }
  553. catch (Exception ex)
  554. {
  555. // 对异常进行共通处理
  556. ExceptionManager.HandleEventException(this.ToString(),
  557. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  558. }
  559. }
  560. #endregion
  561. #region 私有方法
  562. /// <summary>
  563. /// 初始化控件
  564. /// </summary>
  565. private void InitializeControls()
  566. {
  567. // 窗体名称赋值
  568. if (this._dailyId > 0)
  569. {
  570. this._formMode = Constant.FormMode.Edit;
  571. this.Text = FormTitles.F_PM_0102_EDIT;
  572. this.tsbtnAllGrouting.Enabled = false;
  573. this.tsbtnGrouting.Enabled = false;
  574. this.BarCode.Visible = true;
  575. this.ScrapFlag.Visible = true;
  576. }
  577. else
  578. {
  579. this._formMode = Constant.FormMode.Add;
  580. this.Text = FormTitles.F_PM_0102_ADD;
  581. this.BarCode.Visible = false;
  582. this.ScrapFlag.Visible = false;
  583. }
  584. // 功能按钮文本赋值
  585. this.tsbtnAllGrouting.Text = ButtonText.TSBTN_ALLGROUTING;
  586. this.tsbtnGrouting.Text = ButtonText.TSBTN_GROUTING;
  587. this.tsbtnClearDetail.Text = ButtonText.TSBTN_CLEARDETAIL;
  588. this.tsbtnChangeGroutingUser.Text = ButtonText.TSBTN_CHANGEGROUTINGUSER;
  589. this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
  590. this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
  591. this.btnSave.Text = ButtonText.BTN_SAVE;
  592. this.btnClose.Text = ButtonText.BTN_CLOSE;
  593. this.dgvDetail.AutoGenerateColumns = false;
  594. }
  595. /// <summary>
  596. /// 设置列表中未注浆原因的数据源
  597. /// </summary>
  598. private void InitializeData()
  599. {
  600. try
  601. {
  602. // 获取成型线类型数据并绑定到控件上
  603. ServiceResultEntity sre = this.DoAsync<ServiceResultEntity>(() =>
  604. {
  605. return PMModuleProxyNew.Service.GetFPM0102IData(this._dailyId);
  606. }
  607. );
  608. if (sre.Status == Constant.ServiceResultStatus.Other)
  609. {
  610. DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_S_004, sre.Message);
  611. this.DialogResult = DialogResult.Cancel;
  612. this.Close();
  613. return;
  614. }
  615. if (sre.Status != Constant.ServiceResultStatus.Success)
  616. {
  617. return;
  618. }
  619. if (sre.Data != null && sre.Data.Tables.Count > 0)
  620. {
  621. // 设置全部注浆选项
  622. DataTable ngrDataTable = sre.Data.Tables[0].Copy();
  623. DataRow ngrDataRow = ngrDataTable.NewRow();
  624. ngrDataRow["DictionaryID"] = Constant.CBO_SELECT_ALL_VALUE;
  625. ngrDataRow["DictionaryValue"] = "全部注浆";
  626. ngrDataRow["DisplayNo"] = 0;
  627. ngrDataTable.Rows.InsertAt(ngrDataRow, 0);
  628. this.cboNoGroutingRreason.ValueMember = "DictionaryID";
  629. this.cboNoGroutingRreason.DisplayMember = "DictionaryValue";
  630. this.cboNoGroutingRreason.DataSource = ngrDataTable;
  631. this._dtNotGroutingRreason = sre.Data.Tables[0];
  632. // 设置空选项
  633. DataRow dataRow = this._dtNotGroutingRreason.NewRow();
  634. dataRow["DictionaryID"] = DBNull.Value;
  635. dataRow["DictionaryValue"] = Constant.CBO_SELECT_EMPTY_NAME;
  636. dataRow["DisplayNo"] = 0;
  637. this._dtNotGroutingRreason.Rows.InsertAt(dataRow, 0);
  638. }
  639. this.NoGroutingRreason.ValueMember = "DictionaryID";
  640. this.NoGroutingRreason.DisplayMember = "DictionaryValue";
  641. this.NoGroutingRreason.DataSource = this._dtNotGroutingRreason;
  642. if (this._formMode == Constant.FormMode.Edit)
  643. {
  644. _canEdit = ((int)sre.Result == 1);
  645. // 编辑时,修改未注浆原因
  646. if (_canEdit)
  647. {
  648. this.lblNoGroutingRreason.Visible = true;
  649. this.cboNoGroutingRreason.Visible = true;
  650. this.btnNGRSetting.Visible = true;
  651. }
  652. else
  653. {
  654. this.txtGrouting1.Visible = true;
  655. this.txtGrouting.Visible = false;
  656. this.gbxInfo.Height -= 30;// 67;
  657. this.dgvDetail.Top -= 30;
  658. this.dgvDetail.Height += 30;
  659. }
  660. sre.Data.Tables.RemoveAt(0);
  661. this.DataSource = sre.Data;
  662. if (this.DataSource != null && this.DataSource.Tables.Count == 2)
  663. {
  664. DataRow gdDataRow = this.DataSource.Tables[0].Rows[0];
  665. this.txtGrouting.Text = string.Format("{0}({1})", gdDataRow["GroutingLineCode"], gdDataRow["MouldQuantity"]);
  666. this.txtGrouting1.Text = this.txtGrouting.Text;
  667. this._groutingDate = Convert.ToDateTime(gdDataRow["GroutingDate"]);
  668. //this._accountDate = this._groutingDate;
  669. this.dgvDetail.DataSource = this.DataSource.Tables[1];
  670. this.SetEditGrid();
  671. this.dgvDetail.IsSetInputColumnsColor = true;
  672. // 按钮状态
  673. this.btnSave.Enabled = true;
  674. }
  675. // 编辑时,修改未注浆原因
  676. if (!_canEdit)
  677. {
  678. this.txtGrouting1.Text += System.Environment.NewLine + System.Environment.NewLine + sre.Message;
  679. this.txtGrouting1.ForeColor = System.Drawing.Color.Red;
  680. }
  681. this.dgvDetail.Focus();
  682. }
  683. else
  684. {
  685. if (sre.Result != null)
  686. {
  687. this._accountDate = Convert.ToDateTime(sre.Result);
  688. this._groutingDate = this._accountDate;
  689. }
  690. }
  691. this.lblGroutingDateValue.Text = this._groutingDate.ToString(Constant.S_DATE_YYYY_MM_DD);
  692. }
  693. catch (Exception ex)
  694. {
  695. throw ex;
  696. }
  697. }
  698. /// <summary>
  699. /// 取得可注浆信息
  700. /// </summary>
  701. /// <param name="groutingDate">注浆日期</param>
  702. /// <param name="groutingIDs">成型线ID(多个用【,】隔开)</param>
  703. /// <returns>可注浆信息</returns>
  704. private DataSet GetGroutingDailyInfo(DateTime? groutingDate, string groutingLineIDs)
  705. {
  706. try
  707. {
  708. // 根据注浆日期、成型线获取所有可注浆模具信息
  709. ServiceResultEntity sre = this.DoAsync<ServiceResultEntity>(() =>
  710. {
  711. return PMModuleProxyNew.Service.GetFPM0102_GroutingLine(groutingDate, groutingLineIDs);
  712. }
  713. );
  714. // 取注浆日期
  715. if (sre.Result != null)
  716. {
  717. this._groutingDate = Convert.ToDateTime(sre.Result);
  718. }
  719. else if (groutingDate.HasValue)
  720. {
  721. this._groutingDate = groutingDate.Value.Date;
  722. }
  723. else
  724. {
  725. this._groutingDate = DateTime.Now.Date;
  726. }
  727. this.lblGroutingDateValue.Text = this._groutingDate.ToString(Constant.S_DATE_YYYY_MM_DD);
  728. // 异常情况处理
  729. if (sre.Status > Constant.ServiceResultStatus.Success)
  730. {
  731. DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_S_004, sre.Message);
  732. return null;
  733. }
  734. return sre.Data;
  735. }
  736. catch (Exception ex)
  737. {
  738. throw ex;
  739. }
  740. }
  741. /// <summary>
  742. /// 编辑模式下设置Grid编辑状态
  743. /// </summary>
  744. private void SetEditGrid()
  745. {
  746. if(this._formMode != Constant.FormMode.Edit)
  747. {
  748. return;
  749. }
  750. foreach (DataGridViewRow row in this.dgvDetail.Rows)
  751. {
  752. // 交坯后,不能编辑
  753. object deliverFlag = (row.DataBoundItem as DataRowView)["DeliverFlag"];
  754. if (deliverFlag != null && "1" == deliverFlag.ToString())
  755. {
  756. row.Cells["colLogo"].ReadOnly = true;
  757. row.Cells["GroutingFlag"].ReadOnly = true;
  758. row.Cells["NoGroutingRreason"].ReadOnly = true;
  759. }
  760. // 绑定条码后,不能编辑
  761. object barCode = row.Cells["BarCode"].Value;
  762. object scrapFlag = row.Cells["ScrapFlag"].Value;
  763. if ((barCode != null && !string.IsNullOrWhiteSpace(barCode.ToString())) ||
  764. (scrapFlag != null && ((int)Constant.GroutingScrapFlag.Yes).ToString() == scrapFlag.ToString()))
  765. {
  766. row.Cells["GroutingFlag"].ReadOnly = true;
  767. row.Cells["NoGroutingRreason"].ReadOnly = true;
  768. row.Cells["NoGroutingRreason"].Value = DBNull.Value;
  769. //row.Cells["Remarks"].ReadOnly = false;
  770. continue;
  771. }
  772. // 未注浆,可以输入未注浆原因
  773. if (((int)Constant.GroutingFlag.No).ToString() == row.Cells["GroutingFlag"].Value.ToString())
  774. {
  775. row.Cells["NoGroutingRreason"].ReadOnly = false;
  776. }
  777. else
  778. {
  779. row.Cells["NoGroutingRreason"].Value = DBNull.Value;
  780. row.Cells["NoGroutingRreason"].ReadOnly = true;
  781. }
  782. }
  783. if (!this._canEdit)
  784. {
  785. dgvDetail.Columns["GroutingFlag"].ReadOnly = true;
  786. dgvDetail.Columns["NoGroutingRreason"].ReadOnly = true;
  787. }
  788. }
  789. #endregion
  790. private void c_Button1_Click(object sender, EventArgs e)
  791. {
  792. if (this.cmbLogo.SelectedIndex < 0)
  793. {
  794. return;
  795. }
  796. try
  797. {
  798. foreach (DataGridViewRow row in this.dgvDetail.Rows)
  799. {
  800. if (!row.Cells["colLogo"].ReadOnly)
  801. {
  802. row.Cells["colLogo"].Value = this.cmbLogo.SelectedValue;
  803. DataRowView dataRow = row.DataBoundItem as DataRowView;
  804. if (dataRow != null)
  805. {
  806. dataRow.EndEdit();
  807. }
  808. }
  809. }
  810. }
  811. catch (Exception ex)
  812. {
  813. // 对异常进行共通处理
  814. ExceptionManager.HandleEventException(this.ToString(),
  815. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  816. }
  817. }
  818. }
  819. }