F_PM_0906.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  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. cre.Properties["ALL"] = "1";
  206. ServiceResultEntity result = new ServiceResultEntity();
  207. result = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() => { return SystemModuleProxy.Service.DoBarCodePrint(cre); }));
  208. // 没有数据时,直接返回
  209. if (result == null || result.Data == null || result.Data.Tables.Count <= 0)
  210. {
  211. return;
  212. }
  213. _initDataSource = result.Data.Tables[0];
  214. _dtSourse = result.Data.Tables[0];
  215. }
  216. catch (Exception ex)
  217. {
  218. throw ex;
  219. }
  220. }
  221. /// <summary>
  222. /// 保存事件
  223. /// </summary>
  224. /// <param name="sender"></param>
  225. /// <param name="e"></param>
  226. private void btnSave_Click(object sender, EventArgs e)
  227. {
  228. try
  229. {
  230. SaveScrapReason();
  231. }
  232. catch (Exception ex)
  233. {
  234. this.btnSave.Enabled = true;
  235. this.btnCancel.Enabled = true;
  236. // 对异常进行共通处理
  237. ExceptionManager.HandleEventException(this.ToString(),
  238. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  239. }
  240. }
  241. /// <summary>
  242. /// 关闭按钮事件
  243. /// </summary>
  244. /// <param name="sender"></param>
  245. /// <param name="e"></param>
  246. private void btnCancel_Click(object sender, EventArgs e)
  247. {
  248. this.Close();
  249. }
  250. /// <summary>
  251. /// 选择数据字典TreeView中的节点前判断,如果数据有改变提示保存
  252. /// </summary>
  253. /// <param name="sender"></param>
  254. /// <param name="e"></param>
  255. private void tvwDictionaryType_BeforeSelect(object sender, TreeViewCancelEventArgs e)
  256. {
  257. try
  258. {
  259. this.dgvScrapReason.AllowUserToAddRows = true;
  260. // 判断数据是否被修改过,修改过需要提示保存消息
  261. if (DataJudge.IsChange((DataTable)this.dgvScrapReason.DataSource))
  262. {
  263. DialogResult dialogResult = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text,
  264. MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  265. // 保存修改内容
  266. if (dialogResult == DialogResult.Yes)
  267. {
  268. SaveScrapReason();
  269. }
  270. else if (dialogResult == DialogResult.Cancel)
  271. {
  272. e.Cancel = true;
  273. }
  274. //选择否回滚
  275. else
  276. {
  277. ((DataTable)this.dgvScrapReason.DataSource).RejectChanges();
  278. }
  279. }
  280. }
  281. catch (Exception ex)
  282. {
  283. // 对异常进行共通处理
  284. ExceptionManager.HandleEventException(this.ToString(),
  285. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  286. }
  287. }
  288. /// <summary>
  289. /// 选择树中任意值,右边数据跟着变动
  290. /// </summary>
  291. /// <param name="sender"></param>
  292. /// <param name="e"></param>
  293. private void tvwDictionaryType_AfterSelect(object sender, TreeViewEventArgs e)
  294. {
  295. try
  296. {
  297. this.lblDictionaryType.Text = "当前选择的字典类型:" + e.Node.Text;
  298. //判断父节点是否存在,表格联动
  299. TreeNode node = this.tvwScrapType.SelectedNode;
  300. if (node != null)
  301. {
  302. this.dgvScrapReason.ReadOnly = false;
  303. this._dtSourse.AcceptChanges();
  304. this.RefreshData();
  305. }
  306. else
  307. {
  308. this.dgvScrapReason.DataSource = null;
  309. this.dgvScrapReason.ReadOnly = true;
  310. this.dgvScrapReason.AllowUserToAddRows = false;
  311. }
  312. }
  313. catch (Exception ex)
  314. {
  315. // 对异常进行共通处理
  316. ExceptionManager.HandleEventException(this.ToString(),
  317. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  318. }
  319. }
  320. /// <summary>
  321. /// 选中新行时,设置默认值
  322. /// </summary>
  323. /// <param name="sender"></param>
  324. /// <param name="e"></param>
  325. private void dgvScrapReason_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
  326. {
  327. // 设置有效属性为选中状态
  328. e.Row.Cells["ValueFlag"].Value = Constant.INT_IS_ONE;
  329. // 增加一行时,给类型赋值
  330. e.Row.Cells["ScrapType"].Value = this.tvwScrapType.SelectedNode.Tag + "";
  331. e.Row.Cells["DisplayNo"].Value = e.Row.Index + 1;
  332. }
  333. /// <summary>
  334. /// 数据字典信息输入格式控制
  335. /// </summary>
  336. /// <param name="sender"></param>
  337. /// <param name="e"></param>
  338. private void dgvScrapReason_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
  339. {
  340. try
  341. {
  342. // 只对文本框做控制
  343. if (e.Control is DataGridViewTextBoxEditingControl)
  344. {
  345. DataGridViewTextBoxEditingControl EditingControl = (DataGridViewTextBoxEditingControl)e.Control;
  346. EditingControl.KeyPress += new KeyPressEventHandler(dgvScrapReason_KeyPress);
  347. }
  348. }
  349. catch (Exception ex)
  350. {
  351. // 对异常进行共通处理
  352. ExceptionManager.HandleEventException(this.ToString(),
  353. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  354. }
  355. }
  356. /// <summary>
  357. /// 屏蔽除了数字以外的输入(显示顺序)
  358. /// </summary>
  359. /// <param name="sender"></param>
  360. /// <param name="e"></param>
  361. private void dgvScrapReason_KeyPress(object sender, KeyPressEventArgs e)
  362. {
  363. // 显示顺序列只允许输入数字和回格
  364. if ("DisplayNo".Equals(this.dgvScrapReason.Columns[this
  365. .dgvScrapReason.CurrentCell.ColumnIndex].Name))
  366. {
  367. if (e.KeyChar != '\b' && !char.IsDigit(e.KeyChar))
  368. {
  369. e.Handled = true;
  370. }
  371. }
  372. }
  373. /// <summary>
  374. /// 检查是否有重复的字典名称以及将为输入顺序设置成0
  375. /// </summary>
  376. /// <param name="sender"></param>
  377. /// <param name="e"></param>
  378. private void dgvScrapReason_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
  379. {
  380. try
  381. {
  382. if (!dgvScrapReason.CurrentRow.IsNewRow)
  383. {
  384. DataGridViewRow rowItem = dgvScrapReason.Rows[e.RowIndex];
  385. DataGridViewColumn columnItem = dgvScrapReason.Columns[e.ColumnIndex];
  386. object columnvalue = rowItem.Cells[columnItem.Name].EditedFormattedValue;
  387. // 破损原因
  388. if ("ScrapReason".Equals(columnItem.Name))
  389. {
  390. if (columnvalue != null || !string.IsNullOrEmpty(columnvalue.ToString().Trim()))
  391. {
  392. if (!Utility.IsUnique(columnvalue.ToString(),
  393. dgvScrapReason.CurrentRow.Index, this.dgvScrapReason, "ScrapReason"))
  394. {
  395. // 单元格的错误消息
  396. this.dgvScrapReason.CurrentRow.ErrorText = string.Format(
  397. Messages.MSG_CMN_W006, "报损原因");
  398. e.Cancel = true;
  399. this.btnSave.Enabled = false;
  400. return;
  401. }
  402. }
  403. }
  404. // 清除单元格的错误消息
  405. this.dgvScrapReason.CurrentRow.ErrorText = string.Empty;
  406. this.dgvScrapReason.IsSetInputColumnsColor = true;
  407. // 显示顺序为空时设置为0
  408. if ("DisplayNo".Equals(columnItem.Name)
  409. && string.IsNullOrEmpty(columnvalue.ToString()))
  410. {
  411. dgvScrapReason.CurrentCell.Value = Constant.INT_IS_ZERO;
  412. dgvScrapReason.RefreshEdit();
  413. }
  414. }
  415. }
  416. catch (Exception ex)
  417. {
  418. // 对异常进行共通处理
  419. ExceptionManager.HandleEventException(this.ToString(),
  420. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  421. }
  422. }
  423. /// <summary>
  424. /// 单元格校验:根据数据是否变化,设置保存按钮的可用状态
  425. /// </summary>
  426. /// <param name="sender"></param>
  427. /// <param name="e"></param>
  428. private void dgvScrapReason_CellValidated(object sender, DataGridViewCellEventArgs e)
  429. {
  430. try
  431. {
  432. this.SetSaveBtnStatus();
  433. }
  434. catch (Exception ex)
  435. {
  436. // 对异常进行共通处理
  437. ExceptionManager.HandleEventException(this.ToString(),
  438. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  439. }
  440. }
  441. /// <summary>
  442. /// 行校验,不能为空
  443. /// </summary>
  444. /// <param name="sender"></param>
  445. /// <param name="e"></param>
  446. private void dgvScrapReason_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
  447. {
  448. try
  449. {
  450. // 按Esc键时不校验
  451. if (!dgvScrapReason.IsCurrentRowDirty)
  452. {
  453. this.dgvScrapReason.IsSetInputColumnsColor = true;
  454. return;
  455. }
  456. DataGridViewRow row = dgvScrapReason.CurrentRow;
  457. if (!row.IsNewRow)
  458. {
  459. // 报损原因不能为空
  460. if (row.Cells["ScrapReason"].Value == null
  461. || string.IsNullOrEmpty(row.Cells["ScrapReason"].Value.ToString().Trim()))
  462. {
  463. // 单元格的错误消息
  464. this.dgvScrapReason.CurrentRow.ErrorText
  465. = string.Format(Messages.MSG_CMN_W005, "报损原因");
  466. e.Cancel = true;
  467. this.btnSave.Enabled = false;
  468. return;
  469. }
  470. // 显示顺序不能为空
  471. if (row.Cells["DisplayNo"].Value == null
  472. || string.IsNullOrEmpty(row.Cells["DisplayNo"].Value.ToString().Trim()))
  473. {
  474. this.dgvScrapReason.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "显示顺序");
  475. e.Cancel = true;
  476. this.btnSave.Enabled = false;
  477. return;
  478. }
  479. // 过滤掉数据字典名称,备注首尾的空格
  480. row.Cells["ScrapReason"].Value = row.Cells["ScrapReason"].Value.ToString().Trim();
  481. row.Cells["Remarks"].Value = row.Cells["Remarks"].Value == null ? "" : row.Cells["Remarks"].Value.ToString().Trim();
  482. // 清除单元格的错误消息
  483. this.dgvScrapReason.CurrentRow.ErrorText = string.Empty;
  484. }
  485. }
  486. catch (Exception ex)
  487. {
  488. // 对异常进行共通处理
  489. ExceptionManager.HandleEventException(this.ToString(),
  490. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  491. }
  492. }
  493. /// <summary>
  494. /// 行校验:根据数据是否变化,设置保存按钮的可用状态
  495. /// </summary>
  496. /// <param name="sender"></param>
  497. /// <param name="e"></param>
  498. private void dgvScrapReason_RowValidated(object sender, DataGridViewCellEventArgs e)
  499. {
  500. try
  501. {
  502. this.SetSaveBtnStatus();
  503. }
  504. catch (Exception ex)
  505. {
  506. // 对异常进行共通处理
  507. ExceptionManager.HandleEventException(this.ToString(),
  508. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  509. }
  510. }
  511. /// <summary>
  512. /// 刷新数据
  513. /// </summary>
  514. private object RefreshData()
  515. {
  516. try
  517. {
  518. // 获取相应节点数据
  519. this._scrapType = this.tvwScrapType.SelectedNode.Tag.ToString();
  520. // 获取是否查询正常数据的标识
  521. this._valueFalg = Convert.ToByte(this.chkDisplayDisabledData.Checked);
  522. // 获取查询的数据集
  523. StringBuilder sbFilter = new StringBuilder();
  524. sbFilter.Append(" 1=1");
  525. if (this._valueFalg == Constant.INT_IS_ZERO)
  526. {
  527. sbFilter.Append(" and ValueFlag = 1");
  528. }
  529. if (this._scrapType != "")
  530. {
  531. sbFilter.Append(" and ScrapType = '" + _scrapType + "'");
  532. }
  533. this._dtSourse.DefaultView.RowFilter = sbFilter.ToString();
  534. // 选中新行时,自动显示顺序
  535. this._dtSourse.TableNewRow += new DataTableNewRowEventHandler(Table_SelectNewRow);
  536. this.dgvScrapReason.DataSource = this._dtSourse;
  537. this.dgvScrapReason.IsSetInputColumnsColor = true;
  538. return Constant.INT_IS_ZERO;
  539. }
  540. catch (Exception ex)
  541. {
  542. throw ex;
  543. }
  544. }
  545. /// <summary>
  546. /// 保存的共同方法
  547. /// </summary>
  548. private void SaveScrapReason()
  549. {
  550. try
  551. {
  552. // 异步处理
  553. ClientRequestEntity cre = new ClientRequestEntity();
  554. cre.NameSpace = "MST_ScrapReason";
  555. cre.Name = "SaveScrapReasonData";
  556. DataTable returnTable = (DataTable)this.dgvScrapReason.DataSource;
  557. cre.Data = new DataSet();
  558. cre.Data.Tables.Add(returnTable.Copy());
  559. ServiceResultEntity result = new ServiceResultEntity();
  560. result = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() => { return SystemModuleProxy.Service.DoBarCodePrint(cre); }));
  561. int resultRow = (int)result.Result;
  562. // 如果保存出错,不关闭窗体
  563. if (resultRow > Constant.INT_IS_ZERO)
  564. {
  565. RefreshData();
  566. this._dtSourse.AcceptChanges();
  567. this.btnSave.Enabled = false;
  568. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "报损原因", "保存"),
  569. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  570. }
  571. else
  572. {
  573. this.btnSave.Enabled = false;
  574. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "报损原因", "保存"),
  575. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  576. }
  577. }
  578. catch (Exception ex)
  579. {
  580. throw ex;
  581. }
  582. }
  583. /// <summary>
  584. /// 增加一行,自动计算显示顺序
  585. /// </summary>
  586. /// <param name="sender"></param>
  587. /// <param name="e"></param>
  588. private void Table_SelectNewRow(object sender, DataTableNewRowEventArgs e)
  589. {
  590. DataTable itemTable = sender as DataTable;
  591. //判断最大值
  592. if (itemTable != null)
  593. {
  594. int maxValue = Utility.GetMaxValue(itemTable.DefaultView.ToTable(), "DisplayNo");
  595. if (maxValue < Constant.INT_IS_ZERO)
  596. {
  597. maxValue = Constant.INT_IS_ZERO;
  598. }
  599. // 判断显示顺序
  600. if (Constant.S_DISPLAYNO_MAX < maxValue + Constant.INT_IS_ONE)
  601. {
  602. e.Row["DisplayNo"] = maxValue;
  603. }
  604. else
  605. {
  606. e.Row["DisplayNo"] = ++maxValue;
  607. }
  608. e.Row["ScrapType"] = this.tvwScrapType.SelectedNode.Tag.ToString();
  609. }
  610. }
  611. /// <summary>
  612. /// 保存数据字典TreeView的状态
  613. /// </summary>
  614. /// <param name="nodes"></param>
  615. private void SaveTreeNodesStatus(TreeNodeCollection nodes)
  616. {
  617. try
  618. {
  619. foreach (TreeNode node in nodes)
  620. {
  621. // 保存所有节点折叠,展开状态
  622. if (node.IsExpanded)
  623. {
  624. this.NodesStatus[node.FullPath] = true;
  625. }
  626. else
  627. {
  628. this.NodesStatus.Remove(node.FullPath);
  629. }
  630. // 当节点处于选中状态时获取根树节点到当前树节点的路径
  631. if (node.IsSelected)
  632. {
  633. SelectNodeFullPath = node.FullPath;
  634. }
  635. SaveTreeNodesStatus(node.Nodes);
  636. }
  637. }
  638. catch (Exception ex)
  639. {
  640. throw ex;
  641. }
  642. }
  643. /// <summary>
  644. /// 还原保存前产品类型TreeView的状态
  645. /// </summary>
  646. /// <param name="nodes">节点</param>
  647. private void SetTreeNodesStatus(TreeNodeCollection nodes)
  648. {
  649. try
  650. {
  651. foreach (TreeNode node in nodes)
  652. {
  653. if (this.NodesStatus[node.FullPath] != null)
  654. {
  655. // 展开树节点
  656. node.Expand();
  657. }
  658. // 节点路径和前选中的路径相同 设置节点为选中状态
  659. if (node.FullPath == SelectNodeFullPath)
  660. {
  661. this.tvwScrapType.SelectedNode = node;
  662. }
  663. SetTreeNodesStatus(node.Nodes);
  664. }
  665. }
  666. catch (Exception ex)
  667. {
  668. throw ex;
  669. }
  670. }
  671. /// <summary>
  672. /// 设置保存按钮的可用状态
  673. /// </summary>
  674. private void SetSaveBtnStatus()
  675. {
  676. if (DataJudge.IsChange((DataTable)this.dgvScrapReason.DataSource))
  677. {
  678. this.btnSave.Enabled = true;
  679. }
  680. else
  681. {
  682. this.btnSave.Enabled = false;
  683. }
  684. }
  685. #endregion
  686. }
  687. }