F_PM_0906.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. /*******************************************************************************
  2. * Copyright(c) 2018 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PM_0906.cs
  5. * 2.功能描述:新建编辑成型破损原因
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 周兴 2018/3/26 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Collections;
  12. using System.Data;
  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.Basics.Library;
  18. using Dongke.IBOSS.PRD.Client.CommonModule;
  19. using Dongke.IBOSS.PRD.Client.DataModels;
  20. using Dongke.IBOSS.PRD.WCF.DataModels;
  21. using Dongke.IBOSS.PRD.WCF.Proxys;
  22. namespace Dongke.IBOSS.PRD.Client.PMModule
  23. {
  24. public partial class F_PM_0906 : FormBase
  25. {
  26. #region 成员变量
  27. private static F_PM_0906 _instance; // 窗体的实例
  28. private byte _valueFalg; // 有效标识
  29. private string _scrapType; // 报损类型
  30. private DataTable _dtSourse; // 数据源
  31. private Hashtable _nodesStatus = new Hashtable(); // 数据字典Treeview改变前的状态
  32. private string _selectNodeFullPath; // 数据字典TreeView选中节点的路径
  33. private DataTable _initDataSource; // 初始加载的数据源
  34. #endregion
  35. #region 属性
  36. /// <summary>
  37. /// 数据字典TreeView改变前的状态
  38. /// </summary>
  39. public Hashtable NodesStatus
  40. {
  41. get
  42. {
  43. return _nodesStatus;
  44. }
  45. set
  46. {
  47. _nodesStatus = value;
  48. }
  49. }
  50. /// <summary>
  51. /// 数据字典TreeView选中节点的路径
  52. /// </summary>
  53. public string SelectNodeFullPath
  54. {
  55. get
  56. {
  57. return _selectNodeFullPath;
  58. }
  59. set
  60. {
  61. _selectNodeFullPath = value;
  62. }
  63. }
  64. #endregion
  65. #region 构造函数
  66. private F_PM_0906()
  67. {
  68. InitializeComponent();
  69. // 窗口标题
  70. this.Text = FormTitles.F_MST_0906;
  71. // 按钮
  72. this.btnSave.Text = ButtonText.BTN_SAVE;
  73. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  74. }
  75. /// <summary>
  76. /// 单例模式提供实例
  77. /// </summary>
  78. /// <returns></returns>
  79. public static F_PM_0906 Instance
  80. {
  81. get
  82. {
  83. if (_instance == null)
  84. {
  85. _instance = new F_PM_0906();
  86. }
  87. return _instance;
  88. }
  89. }
  90. #endregion
  91. #region 事件
  92. /// <summary>
  93. /// 窗体加载事件
  94. /// </summary>
  95. /// <param name="sender"></param>
  96. /// <param name="e"></param>
  97. private void F_PM_0906_Load(object sender, EventArgs e)
  98. {
  99. try
  100. {
  101. // 屏蔽根据数据源的实际情况,自动生成datagridview表格列
  102. this.dgvScrapReason.AutoGenerateColumns = false;
  103. this.btnSave.Enabled = false;
  104. //生成树形结构
  105. this.CreateScrapTypeTree();
  106. // 获取报损原因数据
  107. this.GetScrapTypeData();
  108. // 窗体显示的时候鼠标停在第一个子节点
  109. this.tvwScrapType.SelectedNode = tvwScrapType.Nodes[0];
  110. this.dgvScrapReason.IsSetInputColumnsColor = true;
  111. //权限控制
  112. FormPermissionManager.FormPermissionControl(this.Name, this,
  113. LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  114. this.dgvScrapReason.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
  115. }
  116. catch (Exception ex)
  117. {
  118. // 对异常进行共通处理
  119. ExceptionManager.HandleEventException(this.ToString(),
  120. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  121. }
  122. }
  123. /// <summary>
  124. /// 根据是否选中停用数据,加载数据
  125. /// </summary>
  126. /// <param name="sender"></param>
  127. /// <param name="e"></param>
  128. private void chkDisplayDisabledData_CheckedChanged(object sender, EventArgs e)
  129. {
  130. try
  131. {
  132. this.RefreshData();
  133. this.SetSaveBtnStatus();
  134. this.dgvScrapReason.IsSetInputColumnsColor = true;
  135. }
  136. catch (Exception ex)
  137. {
  138. // 对异常进行共通处理
  139. ExceptionManager.HandleEventException(this.ToString(),
  140. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  141. }
  142. }
  143. /// <summary>
  144. /// 窗体关闭事件
  145. /// </summary>
  146. /// <param name="sender"></param>
  147. /// <param name="e"></param>
  148. private void F_PM_0906_FormClosed(object sender, FormClosedEventArgs e)
  149. {
  150. _instance = null;
  151. }
  152. #endregion
  153. #region 私有方法
  154. /// <summary>
  155. /// 根据取得的数据字典数据,生成树形结构
  156. /// </summary>
  157. private void CreateScrapTypeTree()
  158. {
  159. try
  160. {
  161. if (this.tvwScrapType.Nodes.Count > Constant.INT_IS_ZERO)
  162. {
  163. // 添加节点前,保存状态
  164. SaveTreeNodesStatus(this.tvwScrapType.Nodes);
  165. }
  166. // 将所有节点清除
  167. this.tvwScrapType.Nodes.Clear();
  168. DataTable scrapTypeTable = new DataTable();
  169. scrapTypeTable.Columns.Add("ScrapType");
  170. scrapTypeTable.Columns.Add("ScrapTypeName");
  171. DataRow row = scrapTypeTable.NewRow();
  172. row["ScrapType"] = "0";
  173. row["ScrapTypeName"] = "开模报损";
  174. scrapTypeTable.Rows.Add(row);
  175. row = scrapTypeTable.NewRow();
  176. row["ScrapType"] = "1";
  177. row["ScrapTypeName"] = "普通报损";
  178. scrapTypeTable.Rows.Add(row);
  179. //生成树形结构
  180. foreach (DataRow newRootRow in scrapTypeTable.Rows)
  181. {
  182. TreeNode rootNode = new TreeNode();
  183. rootNode.Name = newRootRow["ScrapType"] + "";
  184. rootNode.Text = newRootRow["ScrapTypeName"] + "";
  185. rootNode.Tag = newRootRow["ScrapType"] + "";
  186. this.tvwScrapType.Nodes.Add(rootNode);
  187. }
  188. }
  189. catch (Exception ex)
  190. {
  191. throw ex;
  192. }
  193. }
  194. /// <summary>
  195. /// 获取报损原因数据
  196. /// </summary>
  197. private void GetScrapTypeData()
  198. {
  199. try
  200. {
  201. // 取得报损原因
  202. ClientRequestEntity cre = new ClientRequestEntity();
  203. cre.NameSpace = "MST_ScrapReason";
  204. cre.Name = "GetScrapReasonData";
  205. ServiceResultEntity result = new ServiceResultEntity();
  206. result = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() => { return SystemModuleProxy.Service.DoBarCodePrint(cre); }));
  207. // 没有数据时,直接返回
  208. if (result == null || result.Data == null || result.Data.Tables.Count <= 0)
  209. {
  210. return;
  211. }
  212. _initDataSource = result.Data.Tables[0];
  213. _dtSourse = result.Data.Tables[0];
  214. }
  215. catch (Exception ex)
  216. {
  217. throw ex;
  218. }
  219. }
  220. /// <summary>
  221. /// 保存事件
  222. /// </summary>
  223. /// <param name="sender"></param>
  224. /// <param name="e"></param>
  225. private void btnSave_Click(object sender, EventArgs e)
  226. {
  227. try
  228. {
  229. SaveScrapReason();
  230. }
  231. catch (Exception ex)
  232. {
  233. this.btnSave.Enabled = true;
  234. this.btnCancel.Enabled = true;
  235. // 对异常进行共通处理
  236. ExceptionManager.HandleEventException(this.ToString(),
  237. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  238. }
  239. }
  240. /// <summary>
  241. /// 关闭按钮事件
  242. /// </summary>
  243. /// <param name="sender"></param>
  244. /// <param name="e"></param>
  245. private void btnCancel_Click(object sender, EventArgs e)
  246. {
  247. this.Close();
  248. }
  249. /// <summary>
  250. /// 选择数据字典TreeView中的节点前判断,如果数据有改变提示保存
  251. /// </summary>
  252. /// <param name="sender"></param>
  253. /// <param name="e"></param>
  254. private void tvwDictionaryType_BeforeSelect(object sender, TreeViewCancelEventArgs e)
  255. {
  256. try
  257. {
  258. this.dgvScrapReason.AllowUserToAddRows = true;
  259. // 判断数据是否被修改过,修改过需要提示保存消息
  260. if (DataJudge.IsChange((DataTable)this.dgvScrapReason.DataSource))
  261. {
  262. DialogResult dialogResult = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text,
  263. MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  264. // 保存修改内容
  265. if (dialogResult == DialogResult.Yes)
  266. {
  267. SaveScrapReason();
  268. }
  269. else if (dialogResult == DialogResult.Cancel)
  270. {
  271. e.Cancel = true;
  272. }
  273. //选择否回滚
  274. else
  275. {
  276. ((DataTable)this.dgvScrapReason.DataSource).RejectChanges();
  277. }
  278. }
  279. }
  280. catch (Exception ex)
  281. {
  282. // 对异常进行共通处理
  283. ExceptionManager.HandleEventException(this.ToString(),
  284. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  285. }
  286. }
  287. /// <summary>
  288. /// 选择树中任意值,右边数据跟着变动
  289. /// </summary>
  290. /// <param name="sender"></param>
  291. /// <param name="e"></param>
  292. private void tvwDictionaryType_AfterSelect(object sender, TreeViewEventArgs e)
  293. {
  294. try
  295. {
  296. this.lblDictionaryType.Text = "当前选择的字典类型:" + e.Node.Text;
  297. //判断父节点是否存在,表格联动
  298. TreeNode node = this.tvwScrapType.SelectedNode;
  299. if (node != null)
  300. {
  301. this.dgvScrapReason.ReadOnly = false;
  302. this._dtSourse.AcceptChanges();
  303. this.RefreshData();
  304. }
  305. else
  306. {
  307. this.dgvScrapReason.DataSource = null;
  308. this.dgvScrapReason.ReadOnly = true;
  309. this.dgvScrapReason.AllowUserToAddRows = false;
  310. }
  311. }
  312. catch (Exception ex)
  313. {
  314. // 对异常进行共通处理
  315. ExceptionManager.HandleEventException(this.ToString(),
  316. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  317. }
  318. }
  319. /// <summary>
  320. /// 选中新行时,设置默认值
  321. /// </summary>
  322. /// <param name="sender"></param>
  323. /// <param name="e"></param>
  324. private void dgvScrapReason_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
  325. {
  326. // 设置有效属性为选中状态
  327. e.Row.Cells["ValueFlag"].Value = Constant.INT_IS_ONE;
  328. // 增加一行时,给类型赋值
  329. e.Row.Cells["ScrapType"].Value = this.tvwScrapType.SelectedNode.Tag + "";
  330. e.Row.Cells["DisplayNo"].Value = e.Row.Index + 1;
  331. }
  332. /// <summary>
  333. /// 数据字典信息输入格式控制
  334. /// </summary>
  335. /// <param name="sender"></param>
  336. /// <param name="e"></param>
  337. private void dgvScrapReason_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
  338. {
  339. try
  340. {
  341. // 只对文本框做控制
  342. if (e.Control is DataGridViewTextBoxEditingControl)
  343. {
  344. DataGridViewTextBoxEditingControl EditingControl = (DataGridViewTextBoxEditingControl)e.Control;
  345. EditingControl.KeyPress += new KeyPressEventHandler(dgvScrapReason_KeyPress);
  346. }
  347. }
  348. catch (Exception ex)
  349. {
  350. // 对异常进行共通处理
  351. ExceptionManager.HandleEventException(this.ToString(),
  352. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  353. }
  354. }
  355. /// <summary>
  356. /// 屏蔽除了数字以外的输入(显示顺序)
  357. /// </summary>
  358. /// <param name="sender"></param>
  359. /// <param name="e"></param>
  360. private void dgvScrapReason_KeyPress(object sender, KeyPressEventArgs e)
  361. {
  362. // 显示顺序列只允许输入数字和回格
  363. if ("DisplayNo".Equals(this.dgvScrapReason.Columns[this
  364. .dgvScrapReason.CurrentCell.ColumnIndex].Name))
  365. {
  366. if (e.KeyChar != '\b' && !char.IsDigit(e.KeyChar))
  367. {
  368. e.Handled = true;
  369. }
  370. }
  371. }
  372. /// <summary>
  373. /// 检查是否有重复的字典名称以及将为输入顺序设置成0
  374. /// </summary>
  375. /// <param name="sender"></param>
  376. /// <param name="e"></param>
  377. private void dgvScrapReason_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
  378. {
  379. try
  380. {
  381. if (!dgvScrapReason.CurrentRow.IsNewRow)
  382. {
  383. DataGridViewRow rowItem = dgvScrapReason.Rows[e.RowIndex];
  384. DataGridViewColumn columnItem = dgvScrapReason.Columns[e.ColumnIndex];
  385. object columnvalue = rowItem.Cells[columnItem.Name].EditedFormattedValue;
  386. // 破损原因
  387. if ("ScrapReason".Equals(columnItem.Name))
  388. {
  389. if (columnvalue != null || !string.IsNullOrEmpty(columnvalue.ToString().Trim()))
  390. {
  391. if (!Utility.IsUnique(columnvalue.ToString(),
  392. dgvScrapReason.CurrentRow.Index, this.dgvScrapReason, "ScrapReason"))
  393. {
  394. // 单元格的错误消息
  395. this.dgvScrapReason.CurrentRow.ErrorText = string.Format(
  396. Messages.MSG_CMN_W006, "报损原因");
  397. e.Cancel = true;
  398. this.btnSave.Enabled = false;
  399. return;
  400. }
  401. }
  402. }
  403. // 清除单元格的错误消息
  404. this.dgvScrapReason.CurrentRow.ErrorText = string.Empty;
  405. this.dgvScrapReason.IsSetInputColumnsColor = true;
  406. // 显示顺序为空时设置为0
  407. if ("DisplayNo".Equals(columnItem.Name)
  408. && string.IsNullOrEmpty(columnvalue.ToString()))
  409. {
  410. dgvScrapReason.CurrentCell.Value = Constant.INT_IS_ZERO;
  411. dgvScrapReason.RefreshEdit();
  412. }
  413. }
  414. }
  415. catch (Exception ex)
  416. {
  417. // 对异常进行共通处理
  418. ExceptionManager.HandleEventException(this.ToString(),
  419. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  420. }
  421. }
  422. /// <summary>
  423. /// 单元格校验:根据数据是否变化,设置保存按钮的可用状态
  424. /// </summary>
  425. /// <param name="sender"></param>
  426. /// <param name="e"></param>
  427. private void dgvScrapReason_CellValidated(object sender, DataGridViewCellEventArgs e)
  428. {
  429. try
  430. {
  431. this.SetSaveBtnStatus();
  432. }
  433. catch (Exception ex)
  434. {
  435. // 对异常进行共通处理
  436. ExceptionManager.HandleEventException(this.ToString(),
  437. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  438. }
  439. }
  440. /// <summary>
  441. /// 行校验,不能为空
  442. /// </summary>
  443. /// <param name="sender"></param>
  444. /// <param name="e"></param>
  445. private void dgvScrapReason_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
  446. {
  447. try
  448. {
  449. // 按Esc键时不校验
  450. if (!dgvScrapReason.IsCurrentRowDirty)
  451. {
  452. this.dgvScrapReason.IsSetInputColumnsColor = true;
  453. return;
  454. }
  455. DataGridViewRow row = dgvScrapReason.CurrentRow;
  456. if (!row.IsNewRow)
  457. {
  458. // 报损原因不能为空
  459. if (row.Cells["ScrapReason"].Value == null
  460. || string.IsNullOrEmpty(row.Cells["ScrapReason"].Value.ToString().Trim()))
  461. {
  462. // 单元格的错误消息
  463. this.dgvScrapReason.CurrentRow.ErrorText
  464. = string.Format(Messages.MSG_CMN_W005, "报损原因");
  465. e.Cancel = true;
  466. this.btnSave.Enabled = false;
  467. return;
  468. }
  469. // 显示顺序不能为空
  470. if (row.Cells["DisplayNo"].Value == null
  471. || string.IsNullOrEmpty(row.Cells["DisplayNo"].Value.ToString().Trim()))
  472. {
  473. this.dgvScrapReason.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "显示顺序");
  474. e.Cancel = true;
  475. this.btnSave.Enabled = false;
  476. return;
  477. }
  478. // 过滤掉数据字典名称,备注首尾的空格
  479. row.Cells["ScrapReason"].Value = row.Cells["ScrapReason"].Value.ToString().Trim();
  480. row.Cells["Remarks"].Value = row.Cells["Remarks"].Value == null ? "" : row.Cells["Remarks"].Value.ToString().Trim();
  481. // 清除单元格的错误消息
  482. this.dgvScrapReason.CurrentRow.ErrorText = string.Empty;
  483. }
  484. }
  485. catch (Exception ex)
  486. {
  487. // 对异常进行共通处理
  488. ExceptionManager.HandleEventException(this.ToString(),
  489. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  490. }
  491. }
  492. /// <summary>
  493. /// 行校验:根据数据是否变化,设置保存按钮的可用状态
  494. /// </summary>
  495. /// <param name="sender"></param>
  496. /// <param name="e"></param>
  497. private void dgvScrapReason_RowValidated(object sender, DataGridViewCellEventArgs e)
  498. {
  499. try
  500. {
  501. this.SetSaveBtnStatus();
  502. }
  503. catch (Exception ex)
  504. {
  505. // 对异常进行共通处理
  506. ExceptionManager.HandleEventException(this.ToString(),
  507. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  508. }
  509. }
  510. /// <summary>
  511. /// 刷新数据
  512. /// </summary>
  513. private object RefreshData()
  514. {
  515. try
  516. {
  517. // 获取相应节点数据
  518. this._scrapType = this.tvwScrapType.SelectedNode.Tag.ToString();
  519. // 获取是否查询正常数据的标识
  520. this._valueFalg = Convert.ToByte(this.chkDisplayDisabledData.Checked);
  521. // 获取查询的数据集
  522. StringBuilder sbFilter = new StringBuilder();
  523. sbFilter.Append(" 1=1");
  524. if (this._valueFalg == Constant.INT_IS_ZERO)
  525. {
  526. sbFilter.Append(" and ValueFlag = 1");
  527. }
  528. if (this._scrapType != "")
  529. {
  530. sbFilter.Append(" and ScrapType = '" + _scrapType + "'");
  531. }
  532. this._dtSourse.DefaultView.RowFilter = sbFilter.ToString();
  533. // 选中新行时,自动显示顺序
  534. this._dtSourse.TableNewRow += new DataTableNewRowEventHandler(Table_SelectNewRow);
  535. this.dgvScrapReason.DataSource = this._dtSourse;
  536. this.dgvScrapReason.IsSetInputColumnsColor = true;
  537. return Constant.INT_IS_ZERO;
  538. }
  539. catch (Exception ex)
  540. {
  541. throw ex;
  542. }
  543. }
  544. /// <summary>
  545. /// 保存的共同方法
  546. /// </summary>
  547. private void SaveScrapReason()
  548. {
  549. try
  550. {
  551. // 异步处理
  552. ClientRequestEntity cre = new ClientRequestEntity();
  553. cre.NameSpace = "MST_ScrapReason";
  554. cre.Name = "SaveScrapReasonData";
  555. DataTable returnTable = (DataTable)this.dgvScrapReason.DataSource;
  556. cre.Data = new DataSet();
  557. cre.Data.Tables.Add(returnTable.Copy());
  558. ServiceResultEntity result = new ServiceResultEntity();
  559. result = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() => { return SystemModuleProxy.Service.DoBarCodePrint(cre); }));
  560. int resultRow = (int)result.Result;
  561. // 如果保存出错,不关闭窗体
  562. if (resultRow > Constant.INT_IS_ZERO)
  563. {
  564. RefreshData();
  565. this._dtSourse.AcceptChanges();
  566. this.btnSave.Enabled = false;
  567. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "报损原因", "保存"),
  568. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  569. }
  570. else
  571. {
  572. this.btnSave.Enabled = false;
  573. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "报损原因", "保存"),
  574. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  575. }
  576. }
  577. catch (Exception ex)
  578. {
  579. throw ex;
  580. }
  581. }
  582. /// <summary>
  583. /// 增加一行,自动计算显示顺序
  584. /// </summary>
  585. /// <param name="sender"></param>
  586. /// <param name="e"></param>
  587. private void Table_SelectNewRow(object sender, DataTableNewRowEventArgs e)
  588. {
  589. DataTable itemTable = sender as DataTable;
  590. //判断最大值
  591. if (itemTable != null)
  592. {
  593. int maxValue = Utility.GetMaxValue(itemTable.DefaultView.ToTable(), "DisplayNo");
  594. if (maxValue < Constant.INT_IS_ZERO)
  595. {
  596. maxValue = Constant.INT_IS_ZERO;
  597. }
  598. // 判断显示顺序
  599. if (Constant.S_DISPLAYNO_MAX < maxValue + Constant.INT_IS_ONE)
  600. {
  601. e.Row["DisplayNo"] = maxValue;
  602. }
  603. else
  604. {
  605. e.Row["DisplayNo"] = ++maxValue;
  606. }
  607. e.Row["ScrapType"] = this.tvwScrapType.SelectedNode.Tag.ToString();
  608. }
  609. }
  610. /// <summary>
  611. /// 保存数据字典TreeView的状态
  612. /// </summary>
  613. /// <param name="nodes"></param>
  614. private void SaveTreeNodesStatus(TreeNodeCollection nodes)
  615. {
  616. try
  617. {
  618. foreach (TreeNode node in nodes)
  619. {
  620. // 保存所有节点折叠,展开状态
  621. if (node.IsExpanded)
  622. {
  623. this.NodesStatus[node.FullPath] = true;
  624. }
  625. else
  626. {
  627. this.NodesStatus.Remove(node.FullPath);
  628. }
  629. // 当节点处于选中状态时获取根树节点到当前树节点的路径
  630. if (node.IsSelected)
  631. {
  632. SelectNodeFullPath = node.FullPath;
  633. }
  634. SaveTreeNodesStatus(node.Nodes);
  635. }
  636. }
  637. catch (Exception ex)
  638. {
  639. throw ex;
  640. }
  641. }
  642. /// <summary>
  643. /// 还原保存前产品类型TreeView的状态
  644. /// </summary>
  645. /// <param name="nodes">节点</param>
  646. private void SetTreeNodesStatus(TreeNodeCollection nodes)
  647. {
  648. try
  649. {
  650. foreach (TreeNode node in nodes)
  651. {
  652. if (this.NodesStatus[node.FullPath] != null)
  653. {
  654. // 展开树节点
  655. node.Expand();
  656. }
  657. // 节点路径和前选中的路径相同 设置节点为选中状态
  658. if (node.FullPath == SelectNodeFullPath)
  659. {
  660. this.tvwScrapType.SelectedNode = node;
  661. }
  662. SetTreeNodesStatus(node.Nodes);
  663. }
  664. }
  665. catch (Exception ex)
  666. {
  667. throw ex;
  668. }
  669. }
  670. /// <summary>
  671. /// 设置保存按钮的可用状态
  672. /// </summary>
  673. private void SetSaveBtnStatus()
  674. {
  675. if (DataJudge.IsChange((DataTable)this.dgvScrapReason.DataSource))
  676. {
  677. this.btnSave.Enabled = true;
  678. }
  679. else
  680. {
  681. this.btnSave.Enabled = false;
  682. }
  683. }
  684. #endregion
  685. }
  686. }