F_MST_0402.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958
  1. /*******************************************************************************
  2. * Copyright(c) 2014 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_MST_0402.cs
  5. * 2.功能描述:数据字典
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 任海 2014/09/15 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Data;
  12. using System.Text;
  13. using System.Windows.Forms;
  14. using System.Collections;
  15. using Dongke.IBOSS.PRD.Basics.BaseResources;
  16. using Dongke.IBOSS.PRD.Client.CommonModule;
  17. using Dongke.IBOSS.PRD.Basics.BaseControls;
  18. using Dongke.IBOSS.PRD.WCF.Proxys;
  19. using Dongke.IBOSS.PRD.Basics.Library;
  20. using Dongke.IBOSS.PRD.Client.DataModels;
  21. namespace Dongke.IBOSS.PRD.Client.SystemModule
  22. {
  23. /// <summary>
  24. /// 数据字典
  25. /// </summary>
  26. public partial class F_MST_0402 : FormBase
  27. {
  28. #region 成员变量
  29. // 窗体的单例模式
  30. private static F_MST_0402 _instance;
  31. // 相应节点数据
  32. private string _dictionaryType;
  33. // 有效标识
  34. private byte _valueFalg;
  35. // 数据字典Treeview改变前的状态
  36. private Hashtable _nodesStatus = new Hashtable();
  37. // 数据字典TreeView选中节点的路径
  38. private string _selectNodeFullPath;
  39. // 数据字典TreeView选中节点的名称
  40. //private string _selectNode;
  41. // 字典数据源
  42. private DataTable _dtSourse;
  43. #endregion
  44. #region 属性
  45. /// <summary>
  46. /// 数据字典TreeView改变前的状态
  47. /// </summary>
  48. public Hashtable NodesStatus
  49. {
  50. get
  51. {
  52. return _nodesStatus;
  53. }
  54. set
  55. {
  56. _nodesStatus = value;
  57. }
  58. }
  59. /// <summary>
  60. /// 数据字典TreeView选中节点的路径
  61. /// </summary>
  62. public string SelectNodeFullPath
  63. {
  64. get
  65. {
  66. return _selectNodeFullPath;
  67. }
  68. set
  69. {
  70. _selectNodeFullPath = value;
  71. }
  72. }
  73. #endregion
  74. #region 构造函数
  75. /// <summary>
  76. /// 构造函数
  77. /// </summary>
  78. public F_MST_0402()
  79. {
  80. InitializeComponent();
  81. // 窗口标题
  82. this.Text = FormTitles.F_MST_0402;
  83. // 按钮
  84. this.btnSave.Text = ButtonText.BTN_SAVE;
  85. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  86. }
  87. #endregion
  88. #region 单例模式
  89. /// <summary>
  90. /// 单例模式,防止重复创建窗体
  91. /// </summary>
  92. /// <returns></returns>
  93. public static F_MST_0402 Instance
  94. {
  95. get
  96. {
  97. if (_instance == null)
  98. {
  99. _instance = new F_MST_0402();
  100. }
  101. return _instance;
  102. }
  103. }
  104. #endregion
  105. #region 事件
  106. /// <summary>
  107. /// 页面加载
  108. /// </summary>
  109. /// <param name="sender"></param>
  110. /// <param name="e"></param>
  111. private void F_MST_0402_Load(object sender, EventArgs e)
  112. {
  113. try
  114. {
  115. // 屏蔽根据数据源的实际情况,自动生成datagridview表格列
  116. this.dgvDataDictionary.AutoGenerateColumns = false;
  117. this.btnSave.Enabled = false;
  118. //生成树形结构
  119. this.CreateDataDictionaryTree();
  120. this.GetAllDataDictionary();
  121. // 窗体显示的时候鼠标停在第一个子节点
  122. this.tvwDictionaryType.SelectedNode = tvwDictionaryType.Nodes[0].Nodes[0];
  123. this.dgvDataDictionary.IsSetInputColumnsColor = true;
  124. //权限控制
  125. FormPermissionManager.FormPermissionControl(this.Name, this,
  126. LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  127. this.dgvDataDictionary.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
  128. }
  129. catch (Exception ex)
  130. {
  131. // 对异常进行共通处理
  132. ExceptionManager.HandleEventException(this.ToString(),
  133. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  134. }
  135. }
  136. /// <summary>
  137. /// 点击窗体右上方关闭按钮
  138. /// </summary>
  139. /// <param name="sender"></param>
  140. /// <param name="e"></param>
  141. private void FrmDataDictionary_FormClosing(object sender, FormClosingEventArgs e)
  142. {
  143. try
  144. {
  145. // 关闭的时候需要判断是否有数据变化
  146. if (DataJudge.IsChange((DataTable)this.dgvDataDictionary.DataSource))
  147. {
  148. DialogResult dialogResult = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text,
  149. MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  150. // 保存改变的数据
  151. if (dialogResult == DialogResult.Yes)
  152. {
  153. // 异步处理
  154. int result = (int)DoAsync(new BaseAsyncMethod(SaveDataDictionaryData));
  155. // 如果保存出错,不关闭窗体
  156. if (Convert.ToInt32(result) <= Constant.INT_IS_ZERO)
  157. {
  158. e.Cancel = true;
  159. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "数据字典", "保存"),
  160. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  161. }
  162. else
  163. {
  164. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "数据字典", "保存"),
  165. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  166. }
  167. }
  168. else if (dialogResult == DialogResult.Cancel)
  169. {
  170. e.Cancel = true;
  171. }
  172. //选择否回滚
  173. else
  174. {
  175. ((DataTable)this.dgvDataDictionary.DataSource).RejectChanges();
  176. }
  177. }
  178. }
  179. catch (Exception ex)
  180. {
  181. // 对异常进行共通处理
  182. ExceptionManager.HandleEventException(this.ToString(),
  183. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  184. }
  185. }
  186. /// <summary>
  187. /// 窗体关闭后,释放单例资源
  188. /// </summary>
  189. /// <param name="sender"></param>
  190. /// <param name="e"></param>
  191. private void FrmDataDictionary_FormClosed(object sender, FormClosedEventArgs e)
  192. {
  193. _instance = null;
  194. }
  195. /// <summary>
  196. /// 节点收缩之后,显示关闭图标
  197. /// </summary>
  198. /// <param name="sender"></param>
  199. /// <param name="e"></param>
  200. private void tvwDictionaryType_AfterCollapse(object sender, TreeViewEventArgs e)
  201. {
  202. e.Node.SelectedImageIndex = Constant.INT_IS_ZERO;
  203. e.Node.ImageIndex = Constant.INT_IS_ZERO;
  204. }
  205. /// <summary>
  206. /// 节点展开之后,显示打开图标
  207. /// </summary>
  208. /// <param name="sender"></param>
  209. /// <param name="e"></param>
  210. private void tvwDictionaryType_AfterExpand(object sender, TreeViewEventArgs e)
  211. {
  212. e.Node.SelectedImageIndex = Constant.INT_IS_TWO;
  213. e.Node.ImageIndex = Constant.INT_IS_TWO;
  214. }
  215. /// <summary>
  216. /// 选择数据字典TreeView中的节点前判断,如果数据有改变提示保存
  217. /// </summary>
  218. /// <param name="sender"></param>
  219. /// <param name="e"></param>
  220. private void tvwDictionaryType_BeforeSelect(object sender, TreeViewCancelEventArgs e)
  221. {
  222. try
  223. {
  224. this.dgvDataDictionary.AllowUserToAddRows = true;
  225. // 判断数据是否被修改过,修改过需要提示保存消息
  226. if (DataJudge.IsChange((DataTable)this.dgvDataDictionary.DataSource))
  227. {
  228. DialogResult dialogResult = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text,
  229. MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  230. // 保存修改内容
  231. if (dialogResult == DialogResult.Yes)
  232. {
  233. // 异步处理
  234. int result = (int)DoAsync(new BaseAsyncMethod(SaveDataDictionaryData));
  235. // 如果保存出错,不关闭窗体
  236. if (Convert.ToInt32(result) > Constant.INT_IS_ZERO)
  237. {
  238. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "数据字典", "保存"),
  239. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  240. }
  241. else
  242. {
  243. this.btnSave.Enabled = false;
  244. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "数据字典", "保存"),
  245. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  246. }
  247. }
  248. else if (dialogResult == DialogResult.Cancel)
  249. {
  250. e.Cancel = true;
  251. }
  252. //选择否回滚
  253. else
  254. {
  255. ((DataTable)this.dgvDataDictionary.DataSource).RejectChanges();
  256. }
  257. }
  258. }
  259. catch (Exception ex)
  260. {
  261. // 对异常进行共通处理
  262. ExceptionManager.HandleEventException(this.ToString(),
  263. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  264. }
  265. }
  266. /// <summary>
  267. /// 选择树中任意值,右边数据跟着变动
  268. /// </summary>
  269. /// <param name="sender"></param>
  270. /// <param name="e"></param>
  271. private void tvwDictionaryType_AfterSelect(object sender, TreeViewEventArgs e)
  272. {
  273. try
  274. {
  275. this.lblDictionaryType.Text = "当前选择的字典类型:" + e.Node.Text;
  276. //判断父节点是否存在,表格联动
  277. TreeNode node = tvwDictionaryType.SelectedNode.Parent;
  278. if (node != null)
  279. {
  280. this.dgvDataDictionary.ReadOnly = false;
  281. this._dtSourse.AcceptChanges();
  282. this.RefreshData();
  283. }
  284. else
  285. {
  286. this.dgvDataDictionary.DataSource = null;
  287. this.dgvDataDictionary.ReadOnly = true;
  288. this.dgvDataDictionary.AllowUserToAddRows = false;
  289. }
  290. }
  291. catch (Exception ex)
  292. {
  293. // 对异常进行共通处理
  294. ExceptionManager.HandleEventException(this.ToString(),
  295. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  296. }
  297. }
  298. /// <summary>
  299. /// 数据字典信息输入格式控制
  300. /// </summary>
  301. /// <param name="sender"></param>
  302. /// <param name="e"></param>
  303. private void dgvDataDictionary_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
  304. {
  305. try
  306. {
  307. // 只对文本框做控制
  308. if (e.Control is DataGridViewTextBoxEditingControl)
  309. {
  310. DataGridViewTextBoxEditingControl EditingControl = (DataGridViewTextBoxEditingControl)e.Control;
  311. EditingControl.KeyPress += new KeyPressEventHandler(dgvDataDictionary_KeyPress);
  312. }
  313. }
  314. catch (Exception ex)
  315. {
  316. // 对异常进行共通处理
  317. ExceptionManager.HandleEventException(this.ToString(),
  318. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  319. }
  320. }
  321. /// <summary>
  322. /// 选中新行时,设置默认值
  323. /// </summary>
  324. /// <param name="sender"></param>
  325. /// <param name="e"></param>
  326. private void dgvDataDictionary_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
  327. {
  328. // 设置有效属性为选中状态
  329. e.Row.Cells["ValueFlag"].Value = Constant.INT_IS_ONE;
  330. // 增加一行时,给字典类型赋值
  331. e.Row.Cells["DictionaryType"].Value = tvwDictionaryType.SelectedNode.Tag.ToString();
  332. e.Row.Cells["DisplayNo"].Value = e.Row.Index + 1;
  333. }
  334. /// <summary>
  335. /// 屏蔽除了数字以外的输入(显示顺序)
  336. /// </summary>
  337. /// <param name="sender"></param>
  338. /// <param name="e"></param>
  339. private void dgvDataDictionary_KeyPress(object sender, KeyPressEventArgs e)
  340. {
  341. // 显示顺序列只允许输入数字和回格
  342. if ("DisplayNo".Equals(this.dgvDataDictionary.Columns[this
  343. .dgvDataDictionary.CurrentCell.ColumnIndex].Name))
  344. {
  345. if (e.KeyChar != '\b' && !char.IsDigit(e.KeyChar))
  346. {
  347. e.Handled = true;
  348. }
  349. }
  350. }
  351. /// <summary>
  352. /// 检查是否有重复的字典名称以及将为输入顺序设置成0
  353. /// </summary>
  354. /// <param name="sender"></param>
  355. /// <param name="e"></param>
  356. private void dgvDataDictionary_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
  357. {
  358. try
  359. {
  360. if (!dgvDataDictionary.CurrentRow.IsNewRow)
  361. {
  362. DataGridViewRow rowItem = dgvDataDictionary.Rows[e.RowIndex];
  363. DataGridViewColumn columnItem = dgvDataDictionary.Columns[e.ColumnIndex];
  364. object columnvalue = rowItem.Cells[columnItem.Name].EditedFormattedValue;
  365. // 字典名称
  366. if ("DictionaryValue".Equals(columnItem.Name))
  367. {
  368. if (columnvalue != null || !string.IsNullOrEmpty(columnvalue.ToString().Trim()))
  369. {
  370. if (!Utility.IsUnique(columnvalue.ToString(),
  371. dgvDataDictionary.CurrentRow.Index, this.dgvDataDictionary, "DictionaryValue"))
  372. {
  373. // 单元格的错误消息
  374. this.dgvDataDictionary.CurrentRow.ErrorText = string.Format(
  375. Messages.MSG_CMN_W006, "字典名称");
  376. e.Cancel = true;
  377. this.btnSave.Enabled = false;
  378. return;
  379. }
  380. }
  381. }
  382. // 清除单元格的错误消息
  383. this.dgvDataDictionary.CurrentRow.ErrorText = string.Empty;
  384. this.dgvDataDictionary.IsSetInputColumnsColor = true;
  385. // 显示顺序为空时设置为0
  386. if ("DisplayNo".Equals(columnItem.Name)
  387. && string.IsNullOrEmpty(columnvalue.ToString()))
  388. {
  389. dgvDataDictionary.CurrentCell.Value = Constant.INT_IS_ZERO;
  390. dgvDataDictionary.RefreshEdit();
  391. }
  392. }
  393. }
  394. catch (Exception ex)
  395. {
  396. // 对异常进行共通处理
  397. ExceptionManager.HandleEventException(this.ToString(),
  398. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  399. }
  400. }
  401. /// <summary>
  402. /// 单元格校验:根据数据是否变化,设置保存按钮的可用状态
  403. /// </summary>
  404. /// <param name="sender"></param>
  405. /// <param name="e"></param>
  406. private void dgvDataDictionary_CellValidated(object sender, DataGridViewCellEventArgs e)
  407. {
  408. try
  409. {
  410. this.SetSaveBtnStatus();
  411. }
  412. catch (Exception ex)
  413. {
  414. // 对异常进行共通处理
  415. ExceptionManager.HandleEventException(this.ToString(),
  416. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  417. }
  418. }
  419. /// <summary>
  420. /// 行校验,不能为空
  421. /// </summary>
  422. /// <param name="sender"></param>
  423. /// <param name="e"></param>
  424. private void dgvDataDictionary_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
  425. {
  426. try
  427. {
  428. // 按Esc键时不校验
  429. if (!dgvDataDictionary.IsCurrentRowDirty)
  430. {
  431. this.dgvDataDictionary.IsSetInputColumnsColor = true;
  432. return;
  433. }
  434. DataGridViewRow row = dgvDataDictionary.CurrentRow;
  435. if (!row.IsNewRow)
  436. {
  437. // 数据字典类型不能为空
  438. if (row.Cells["DictionaryValue"].Value == null
  439. || string.IsNullOrEmpty(row.Cells["DictionaryValue"].Value.ToString().Trim()))
  440. {
  441. // 单元格的错误消息
  442. this.dgvDataDictionary.CurrentRow.ErrorText
  443. = string.Format(Messages.MSG_CMN_W005, "字典名称");
  444. e.Cancel = true;
  445. this.btnSave.Enabled = false;
  446. return;
  447. }
  448. // 显示顺序不能为空
  449. if (row.Cells["DisplayNo"].Value == null
  450. || string.IsNullOrEmpty(row.Cells["DisplayNo"].Value.ToString().Trim()))
  451. {
  452. this.dgvDataDictionary.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "显示顺序");
  453. e.Cancel = true;
  454. this.btnSave.Enabled = false;
  455. return;
  456. }
  457. // 过滤掉数据字典名称,备注首尾的空格
  458. row.Cells["DictionaryValue"].Value = row.Cells["DictionaryValue"].Value.ToString().Trim();
  459. row.Cells["Remarks"].Value =row.Cells["Remarks"].Value==null?"": row.Cells["Remarks"].Value.ToString().Trim();
  460. // 清除单元格的错误消息
  461. this.dgvDataDictionary.CurrentRow.ErrorText = string.Empty;
  462. }
  463. }
  464. catch (Exception ex)
  465. {
  466. // 对异常进行共通处理
  467. ExceptionManager.HandleEventException(this.ToString(),
  468. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  469. }
  470. }
  471. /// <summary>
  472. /// 行校验:根据数据是否变化,设置保存按钮的可用状态
  473. /// </summary>
  474. /// <param name="sender"></param>
  475. /// <param name="e"></param>
  476. private void dgvDataDictionary_RowValidated(object sender, DataGridViewCellEventArgs e)
  477. {
  478. try
  479. {
  480. this.SetSaveBtnStatus();
  481. }
  482. catch (Exception ex)
  483. {
  484. // 对异常进行共通处理
  485. ExceptionManager.HandleEventException(this.ToString(),
  486. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  487. }
  488. }
  489. /// <summary>
  490. /// 增加一行,自动计算显示顺序
  491. /// </summary>
  492. /// <param name="sender"></param>
  493. /// <param name="e"></param>
  494. private void Table_SelectNewRow(object sender, DataTableNewRowEventArgs e)
  495. {
  496. DataTable itemTable = sender as DataTable;
  497. //判断最大值
  498. if (itemTable != null)
  499. {
  500. int maxValue = Utility.GetMaxValue(itemTable.DefaultView.ToTable(), "DisplayNo");
  501. if (maxValue < Constant.INT_IS_ZERO)
  502. {
  503. maxValue = Constant.INT_IS_ZERO;
  504. }
  505. // 判断显示顺序
  506. if (Constant.S_DISPLAYNO_MAX < maxValue + Constant.INT_IS_ONE)
  507. {
  508. e.Row["DisplayNo"] = maxValue;
  509. }
  510. else
  511. {
  512. e.Row["DisplayNo"] = ++maxValue;
  513. }
  514. e.Row["DictionaryType"] = tvwDictionaryType.SelectedNode.Tag.ToString();
  515. }
  516. }
  517. /// <summary>
  518. /// 根据是否选中停用数据,加载数据
  519. /// </summary>
  520. /// <param name="sender"></param>
  521. /// <param name="e"></param>
  522. private void chkDisplayDisabledData_CheckedChanged(object sender, EventArgs e)
  523. {
  524. try
  525. {
  526. this.RefreshData();
  527. this.SetSaveBtnStatus();
  528. this.dgvDataDictionary.IsSetInputColumnsColor = true;
  529. }
  530. catch (Exception ex)
  531. {
  532. // 对异常进行共通处理
  533. ExceptionManager.HandleEventException(this.ToString(),
  534. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  535. }
  536. }
  537. /// <summary>
  538. /// 保存数据字典数据
  539. /// </summary>
  540. /// <param name="sender"></param>
  541. /// <param name="e"></param>
  542. private void btnSave_Click(object sender, EventArgs e)
  543. {
  544. try
  545. {
  546. // 异步处理
  547. this.btnSave.Enabled = false;
  548. this.btnCancel.Enabled = false;
  549. int result = (int)DoAsync(new BaseAsyncMethod(SaveDataDictionaryData));
  550. this.btnSave.Enabled = true;
  551. this.btnCancel.Enabled = true;
  552. // 数据字典数据保存成功
  553. if (result > Constant.INT_IS_ZERO)
  554. {
  555. RefreshData();
  556. this._dtSourse.AcceptChanges();
  557. this.btnSave.Enabled = false;
  558. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "数据字典", "保存"),
  559. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  560. }
  561. //数据字典数据存在相同的数据
  562. else if (result == (int)Constant.RETURN_IS_EXIST)
  563. {
  564. MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "数据字典名称"),
  565. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  566. return;
  567. }
  568. else
  569. {
  570. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "数据字典", "保存"),
  571. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  572. }
  573. }
  574. catch (Exception ex)
  575. {
  576. this.btnSave.Enabled = true;
  577. this.btnCancel.Enabled = true;
  578. // 对异常进行共通处理
  579. ExceptionManager.HandleEventException(this.ToString(),
  580. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  581. }
  582. }
  583. /// <summary>
  584. /// 点击关闭按钮
  585. /// </summary>
  586. /// <param name="sender"></param>
  587. /// <param name="e"></param>
  588. private void btnCancel_Click(object sender, EventArgs e)
  589. {
  590. this.Close();
  591. }
  592. /// <summary>
  593. /// 单元格输入时,给自动生成的行设置颜色
  594. /// </summary>
  595. /// <param name="sender"></param>
  596. /// <param name="e"></param>
  597. private void dgvDataDictionary_UserAddedRow(object sender, DataGridViewRowEventArgs e)
  598. {
  599. this.dgvDataDictionary.IsSetInputColumnsColor = true;
  600. }
  601. /// <summary>
  602. /// 排序时设置列表的颜色
  603. /// </summary>
  604. /// <returns></returns>
  605. private void dgvDataDictionary_Sorted(object sender, EventArgs e)
  606. {
  607. this.dgvDataDictionary.IsSetInputColumnsColor = true;
  608. }
  609. #endregion
  610. #region 私有方法
  611. /// <summary>
  612. /// 数据字典左侧树的数据取得
  613. /// </summary>
  614. /// <returns></returns>
  615. private DataSet GetDataDictionaryData()
  616. {
  617. try
  618. {
  619. return SystemModuleProxy.Service.GetDataDictionaryTreeData();
  620. }
  621. catch (Exception ex)
  622. {
  623. throw ex;
  624. }
  625. }
  626. /// <summary>
  627. /// 根据取得的数据字典数据,生成树形结构
  628. /// </summary>
  629. private void CreateDataDictionaryTree()
  630. {
  631. try
  632. {
  633. // 取得数据字典数据
  634. DataSet dataDictionaryData = (DataSet)DoAsync(new BaseAsyncMethod(GetDataDictionaryData));
  635. // 没有数据字典数据时,直接返回
  636. if (dataDictionaryData == null || dataDictionaryData.Tables[0].Rows.Count < Constant.INT_IS_ONE)
  637. {
  638. return;
  639. }
  640. if (this.tvwDictionaryType.Nodes.Count > Constant.INT_IS_ZERO)
  641. {
  642. // 添加节点前,保存状态
  643. SaveTreeNodesStatus(this.tvwDictionaryType.Nodes);
  644. }
  645. // 将所有节点清除
  646. this.tvwDictionaryType.Nodes.Clear();
  647. //生成树形结构
  648. if (dataDictionaryData != null)
  649. {
  650. if (dataDictionaryData.Tables.Count >= Constant.INT_IS_TWO)
  651. {
  652. foreach (DataRow newRootRow in dataDictionaryData.Tables[0].Rows)
  653. {
  654. TreeNode rootNode = new TreeNode();
  655. rootNode.Name = newRootRow["DataDictionaryClass"].ToString().Trim();
  656. rootNode.Text = newRootRow["DataDictionaryClassName"].ToString().Trim();
  657. rootNode.Tag = newRootRow["DataDictionaryClass"].ToString().Trim();
  658. string strWhere = "DataDictionaryClass ='" + newRootRow["DataDictionaryClass"].ToString() + "'";
  659. DataRow[] dataDictionaryRows = dataDictionaryData.Tables[1].Select(strWhere, "DisplayNo");
  660. // 显示子节点
  661. InitTreeView(dataDictionaryData.Tables[1], dataDictionaryRows, rootNode);
  662. this.tvwDictionaryType.Nodes.Add(rootNode);
  663. }
  664. }
  665. }
  666. this.dgvDataDictionary.IsSetInputColumnsColor = true;
  667. }
  668. catch (Exception ex)
  669. {
  670. throw ex;
  671. }
  672. }
  673. /// <summary>
  674. /// 递归显示数据字典树形目录
  675. /// </summary>
  676. /// <param name="typeData">数据字典数据源</param>
  677. /// <param name="rows"></param>
  678. /// <param name="node"></param>
  679. private void InitTreeView(DataTable dtTable, DataRow[] rows, TreeNode node)
  680. {
  681. try
  682. {
  683. foreach (DataRow row in rows)
  684. {
  685. TreeNode sNode = new TreeNode();
  686. // 新建树节点并添加
  687. sNode = new TreeNode();
  688. sNode.Text = row["DataDictionaryTypeName"].ToString().Trim();
  689. sNode.Name = row["DataDictionaryType"].ToString().Trim();
  690. sNode.Tag = row["DataDictionaryType"].ToString().Trim();
  691. //节点图像索引
  692. sNode.ImageIndex = Constant.INT_IS_ONE;
  693. sNode.SelectedImageIndex = Constant.INT_IS_ONE;
  694. node.Nodes.Add(sNode);
  695. }
  696. }
  697. catch (Exception ex)
  698. {
  699. throw ex;
  700. }
  701. }
  702. /// <summary>
  703. /// 加入节点在原有树中
  704. /// </summary>
  705. private void InitTreeLeafView(DataRow[] rows, TreeNode node)
  706. {
  707. try
  708. {
  709. foreach (DataRow row in rows)
  710. {
  711. TreeNode sNode = null;
  712. if (node == null)
  713. {
  714. return;
  715. }
  716. else
  717. {
  718. // 加入节点在原有树中
  719. sNode = node.Nodes.Add(row["DataDictionaryTypeName"].ToString());
  720. sNode.Name = row["DataDictionaryType"].ToString();
  721. sNode.Tag = row["DataDictionaryType"].ToString();
  722. }
  723. }
  724. }
  725. catch (Exception ex)
  726. {
  727. throw ex;
  728. }
  729. }
  730. /// <summary>
  731. /// 保存数据字典TreeView的状态
  732. /// </summary>
  733. /// <param name="nodes"></param>
  734. private void SaveTreeNodesStatus(TreeNodeCollection nodes)
  735. {
  736. try
  737. {
  738. foreach (TreeNode node in nodes)
  739. {
  740. // 保存所有节点折叠,展开状态
  741. if (node.IsExpanded)
  742. {
  743. this.NodesStatus[node.FullPath] = true;
  744. }
  745. else
  746. {
  747. this.NodesStatus.Remove(node.FullPath);
  748. }
  749. // 当节点处于选中状态时获取根树节点到当前树节点的路径
  750. if (node.IsSelected)
  751. {
  752. SelectNodeFullPath = node.FullPath;
  753. }
  754. SaveTreeNodesStatus(node.Nodes);
  755. }
  756. }
  757. catch (Exception ex)
  758. {
  759. throw ex;
  760. }
  761. }
  762. /// <summary>
  763. /// 还原保存前产品类型TreeView的状态
  764. /// </summary>
  765. /// <param name="nodes">节点</param>
  766. private void SetTreeNodesStatus(TreeNodeCollection nodes)
  767. {
  768. try
  769. {
  770. foreach (TreeNode node in nodes)
  771. {
  772. if (this.NodesStatus[node.FullPath] != null)
  773. {
  774. // 展开树节点
  775. node.Expand();
  776. }
  777. // 节点路径和前选中的路径相同 设置节点为选中状态
  778. if (node.FullPath == SelectNodeFullPath)
  779. {
  780. this.tvwDictionaryType.SelectedNode = node;
  781. }
  782. SetTreeNodesStatus(node.Nodes);
  783. }
  784. }
  785. catch (Exception ex)
  786. {
  787. throw ex;
  788. }
  789. }
  790. /// <summary>
  791. /// 刷新数据
  792. /// </summary>
  793. private object RefreshData()
  794. {
  795. try
  796. {
  797. // 获取相应节点数据
  798. this._dictionaryType = this.tvwDictionaryType.SelectedNode.Tag.ToString();
  799. // 获取是否查询正常数据的标识
  800. this._valueFalg = Convert.ToByte(this.chkDisplayDisabledData.Checked);
  801. // 获取查询的数据集
  802. base.DataSource = (DataSet)DoAsync(new BaseAsyncMethod(GetDictionaryDate));
  803. // 获取查询的数据集
  804. StringBuilder sbFilter = new StringBuilder();
  805. sbFilter.Append(" 1=1");
  806. if (this._valueFalg == Constant.INT_IS_ZERO)
  807. {
  808. sbFilter.Append(" and ValueFlag = 1");
  809. }
  810. if (this._dictionaryType != "")
  811. {
  812. sbFilter.Append(" and DictionaryType = '" + _dictionaryType + "'");
  813. }
  814. this._dtSourse.DefaultView.RowFilter = sbFilter.ToString();
  815. if (this._dtSourse.DefaultView.ToTable().Rows.Count > Constant.INT_IS_ZERO)
  816. {
  817. // 选中新行时,自动显示顺序
  818. this._dtSourse.TableNewRow += new DataTableNewRowEventHandler(Table_SelectNewRow);
  819. this.dgvDataDictionary.DataSource = this._dtSourse;
  820. this.dgvDataDictionary.IsSetInputColumnsColor = true;
  821. }
  822. else
  823. {
  824. this._dtSourse.TableNewRow += new DataTableNewRowEventHandler(Table_SelectNewRow);
  825. this.dgvDataDictionary.DataSource = this._dtSourse;
  826. this.dgvDataDictionary.IsSetInputColumnsColor = true;
  827. }
  828. return Constant.INT_IS_ZERO;
  829. }
  830. catch (Exception ex)
  831. {
  832. throw ex;
  833. }
  834. }
  835. /// <summary>
  836. /// 设置保存按钮的可用状态
  837. /// </summary>
  838. private void SetSaveBtnStatus()
  839. {
  840. if (DataJudge.IsChange((DataTable)this.dgvDataDictionary.DataSource))
  841. {
  842. this.btnSave.Enabled = true;
  843. }
  844. else
  845. {
  846. this.btnSave.Enabled = false;
  847. }
  848. }
  849. /// <summary>
  850. /// 保存数据字典数据
  851. /// </summary>
  852. /// <returns>受影响行数</returns>
  853. private object SaveDataDictionaryData()
  854. {
  855. try
  856. {
  857. // 获取当前dgvDataDictionary数据源
  858. DataTable dataDictionaryData = (DataTable)this.dgvDataDictionary.DataSource;
  859. int result = SystemModuleProxy.Service.SaveDictionaryData(dataDictionaryData);
  860. return result;
  861. }
  862. catch (Exception ex)
  863. {
  864. throw ex;
  865. }
  866. }
  867. /// <summary>
  868. /// 获取数据字典信息
  869. /// </summary>
  870. /// <returns></returns>
  871. private object GetDictionaryDate()
  872. {
  873. try
  874. {
  875. return SystemModuleProxy.Service.GetDictionaryData(_valueFalg, _dictionaryType);
  876. }
  877. catch (Exception ex)
  878. {
  879. throw ex;
  880. }
  881. }
  882. /// <summary>
  883. /// 获取数据字典的全部数据
  884. /// </summary>
  885. /// <param name="sUserInfo">用户信息</param>
  886. /// <returns></returns>
  887. /// <remarks>
  888. /// 2014.10.31 任海 新建
  889. /// </remarks>
  890. private void GetAllDataDictionary()
  891. {
  892. try
  893. {
  894. DataSet dsResultAccount = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  895. {
  896. return SystemModuleProxy.Service.GetAllDataDictionaryInfo();
  897. }));
  898. this._dtSourse = dsResultAccount.Tables[0];
  899. }
  900. catch (Exception ex)
  901. {
  902. throw ex;
  903. }
  904. }
  905. #endregion
  906. }
  907. }