F_MST_0405.cs 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043
  1. /*******************************************************************************
  2. * Copyright(c) 2014 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_MST_0405.cs
  5. * 2.功能描述:产品类别
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 冯雪 2014/09/11 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.Proxys;
  21. namespace Dongke.IBOSS.PRD.Client.SystemModule
  22. {
  23. /// <summary>
  24. /// 产品类别
  25. /// </summary>
  26. public partial class F_MST_0405 : FormBase
  27. {
  28. #region 成员变量
  29. // 窗体的单例模式
  30. private static F_MST_0405 _instance;
  31. // 产品类型Treeview改变前的状态
  32. private Hashtable _nodesStatus = new Hashtable();
  33. // 产品类型TreeView选中节点的路径
  34. private string _selectNodeFullPath;
  35. // 产品类型TreeView选中节点的名称
  36. private string _selectNode;
  37. // 产品类型TreeView选中索引
  38. //private int _index;
  39. // 产品类型TreeView选中ID
  40. private int _GoodsTypeID;
  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 this._nodesStatus;
  53. }
  54. set
  55. {
  56. this._nodesStatus = value;
  57. }
  58. }
  59. /// <summary>
  60. /// 产品类型TreeView选中节点的路径
  61. /// </summary>
  62. public string SelectNodeFullPath
  63. {
  64. get
  65. {
  66. return this._selectNodeFullPath;
  67. }
  68. set
  69. {
  70. this._selectNodeFullPath = value;
  71. }
  72. }
  73. #endregion
  74. #region 构造函数
  75. /// <summary>
  76. /// 窗体的构造函数
  77. /// </summary>
  78. public F_MST_0405()
  79. {
  80. InitializeComponent();
  81. // 窗体标题、按钮文字
  82. this.Text = FormTitles.F_MST_0405;
  83. this.btnSave.Text = ButtonText.BTN_SAVE;
  84. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  85. }
  86. #endregion
  87. #region 单例模式
  88. /// <summary>
  89. /// 单例模式,防止重复创建窗体
  90. /// </summary>
  91. public static F_MST_0405 Instance
  92. {
  93. get
  94. {
  95. if (_instance == null)
  96. {
  97. _instance = new F_MST_0405();
  98. }
  99. return _instance;
  100. }
  101. }
  102. #endregion
  103. #region 事件
  104. /// <summary>
  105. /// 窗体加载时发生
  106. /// </summary>
  107. /// <param name="sender"></param>
  108. /// <param name="e"></param>
  109. private void F_MST_0405_Load(object sender, EventArgs e)
  110. {
  111. try
  112. {
  113. // 加载权限
  114. FormPermissionManager.FormPermissionControl(this.Name, this,
  115. LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  116. // 设置表格不自动创建列
  117. this.dgvGoodsType.AutoGenerateColumns = false;
  118. // 设置保存按钮初始是不可点击
  119. this.btnSave.Enabled = false;
  120. // 获取全部产品类别信息
  121. this.GetAllGoodsTypeData();
  122. // 生成树形产品类型结构
  123. this.CreateGoodsTypeTree();
  124. // 窗体显示的时候鼠标停在第一个子节点
  125. this.tvwType.SelectedNode = tvwType.Nodes[0].Nodes[0];
  126. this.dgvGoodsType.IsSetInputColumnsColor = true;
  127. }
  128. catch (Exception ex)
  129. {
  130. // 对异常进行共通处理
  131. ExceptionManager.HandleEventException(this.ToString(),
  132. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  133. }
  134. }
  135. /// <summary>
  136. /// 窗体关闭后,释放单例资源
  137. /// </summary>
  138. /// <param name="sender"></param>
  139. /// <param name="e"></param>
  140. private void F_MST_0405_FormClosed(object sender, FormClosedEventArgs e)
  141. {
  142. _instance = null;
  143. }
  144. /// <summary>
  145. /// 点击右上角关闭按钮
  146. /// </summary>
  147. /// <param name="sender"></param>
  148. /// <param name="e"></param>
  149. private void F_MST_0405_FormClosing(object sender, FormClosingEventArgs e)
  150. {
  151. try
  152. {
  153. // 关闭的时候需要判断是否有数据变化
  154. if (DataJudge.IsChange((DataTable)this.dgvGoodsType.DataSource))
  155. {
  156. DialogResult dialogResult = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text,
  157. MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  158. // 保存改变的数据
  159. if (dialogResult == DialogResult.Yes)
  160. {
  161. DataGridViewRow row = dgvGoodsType.CurrentRow;
  162. if (!row.IsNewRow)
  163. {
  164. if (row.Cells["GoodsTypeCode"].Value == null
  165. || string.IsNullOrEmpty(row.Cells["GoodsTypeCode"].Value + string.Empty))
  166. {
  167. MessageBox.Show(string.Format(Messages.MSG_MST_W0405),
  168. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  169. e.Cancel = true;
  170. this.btnSave.Enabled = false;
  171. return;
  172. }
  173. }
  174. // 异步处理
  175. object result = DoAsync(new BaseAsyncMethod(this.SaveGoodsTypeData));
  176. // 如果保存出错,不关闭窗体
  177. if (Convert.ToInt32(result) > Constant.INT_IS_ZERO)
  178. {
  179. e.Cancel = true;
  180. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "产品类别", "保存"),
  181. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  182. }
  183. else if (Convert.ToInt32(result) == (int)Constant.RETURN_IS_EXIST)
  184. {
  185. e.Cancel = true;
  186. MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "产品类别名称"),
  187. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  188. }
  189. else
  190. {
  191. e.Cancel = true;
  192. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "产品类别", "保存"),
  193. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  194. }
  195. }
  196. else if (dialogResult == DialogResult.Cancel)
  197. {
  198. e.Cancel = true;
  199. }
  200. //选择否回滚
  201. else
  202. {
  203. ((DataTable)this.dgvGoodsType.DataSource).RejectChanges();
  204. }
  205. }
  206. }
  207. catch (Exception ex)
  208. {
  209. // 对异常进行共通处理
  210. ExceptionManager.HandleEventException(this.ToString(),
  211. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  212. }
  213. }
  214. /// <summary>
  215. /// 节点收缩之后,显示关闭图标
  216. /// </summary>
  217. /// <param name="sender"></param>
  218. /// <param name="e"></param>
  219. private void tvwType_BeforeCollapse(object sender, TreeViewCancelEventArgs e)
  220. {
  221. e.Node.SelectedImageIndex = Constant.INT_IS_ZERO;
  222. e.Node.ImageIndex = Constant.INT_IS_ZERO;
  223. }
  224. /// <summary>
  225. /// 节点展开之后,显示打开图标
  226. /// </summary>
  227. /// <param name="sender"></param>
  228. /// <param name="e"></param>
  229. private void tvwType_BeforeExpand(object sender, TreeViewCancelEventArgs e)
  230. {
  231. e.Node.SelectedImageIndex = Constant.INT_IS_TWO;
  232. e.Node.ImageIndex = Constant.INT_IS_TWO;
  233. }
  234. /// <summary>
  235. /// 选中新行时,设置默认值
  236. /// </summary>
  237. /// <param name="sender"></param>
  238. /// <param name="e"></param>
  239. private void dgvGoodsType_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
  240. {
  241. try
  242. {
  243. // 设置有效列为选中状态
  244. e.Row.Cells["ValueFlag"].Value = true;
  245. }
  246. catch (Exception ex)
  247. {
  248. // 对异常进行共通处理
  249. ExceptionManager.HandleEventException(this.ToString(),
  250. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  251. }
  252. }
  253. /// <summary>
  254. /// 选择产品类型TreeView中的节点前判断,如果数据有改变提示保存
  255. /// </summary>
  256. /// <param name="sender"></param>
  257. /// <param name="e"></param>
  258. private void tvwType_BeforeSelect(object sender, TreeViewCancelEventArgs e)
  259. {
  260. try
  261. {
  262. // 判断数据是否被修改过,修改过需要提示保存消息
  263. if (DataJudge.IsChange((DataTable)this.dgvGoodsType.DataSource))
  264. {
  265. DialogResult dialogResult = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text,
  266. MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  267. if (dialogResult == DialogResult.Yes)
  268. {
  269. int rowCount = (int)DoAsync(new BaseAsyncMethod(SaveGoodsTypeData));
  270. // 保存数据后提示
  271. if (rowCount > Constant.INT_IS_ZERO)
  272. {
  273. // 保存数据成功
  274. GetAllGoodsTypeData();
  275. this._dtSourse.AcceptChanges();
  276. this.btnSave.Enabled = false;
  277. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "产品类别", "保存"),
  278. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  279. // 生成产品类别树形结构
  280. TreeNode selectedNode = this.tvwType.SelectedNode;
  281. // 重新加载窗体数据
  282. this.RefreshData();
  283. this.CreateGoodsTypeTree();
  284. this.tvwType.SelectedNode = selectedNode;
  285. //// 还原保存前产品类别TreeView的状态
  286. this.SetTreeNodesStatus(this.tvwType.Nodes);
  287. }
  288. else
  289. {
  290. // 保存数据失败
  291. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "产品类别", "保存"),
  292. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  293. }
  294. }
  295. else if (dialogResult == DialogResult.Cancel)
  296. {
  297. e.Cancel = true;
  298. }
  299. //选择否回滚
  300. else
  301. {
  302. ((DataTable)this.dgvGoodsType.DataSource).RejectChanges();
  303. }
  304. }
  305. }
  306. catch (Exception ex)
  307. {
  308. // 对异常进行共通处理
  309. ExceptionManager.HandleEventException(this.ToString(),
  310. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  311. }
  312. }
  313. /// <summary>
  314. /// 选择产品类别TreeView中的节点,DataGridView中显示相应的数据
  315. /// </summary>
  316. /// <param name="sender"></param>
  317. /// <param name="e"></param>
  318. private void tvwType_AfterSelect(object sender, TreeViewEventArgs e)
  319. {
  320. try
  321. {
  322. // 刷新DataGridView中的数据
  323. this.RefreshData();
  324. this.dgvGoodsType.Columns["GoodsTypeCode"].ReadOnly = true;
  325. foreach (DataGridViewRow gvrFor in this.dgvGoodsType.Rows)
  326. {
  327. if (gvrFor.IsNewRow == true)
  328. {
  329. break;
  330. }
  331. if (gvrFor.Cells["GoodsTypeCode"].Value.ToString().Length == Constant.INT_IS_THREE)
  332. {
  333. gvrFor.Cells["ValueFlag"].ReadOnly = true;
  334. break;
  335. }
  336. else
  337. {
  338. break;
  339. }
  340. }
  341. this._selectNodeFullPath = this.tvwType.SelectedNode.FullPath.Replace("\\", "→");
  342. this.dgvGoodsType.IsSetInputColumnsColor = true;
  343. }
  344. catch (Exception ex)
  345. {
  346. // 对异常进行共通处理
  347. ExceptionManager.HandleEventException(this.ToString(),
  348. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  349. }
  350. }
  351. /// <summary>
  352. /// 设置保存按钮的可用状态
  353. /// </summary>
  354. /// <param name="sender"></param>
  355. /// <param name="e"></param>
  356. private void dgvGoodsType_CellValidated(object sender, DataGridViewCellEventArgs e)
  357. {
  358. try
  359. {
  360. this.RefreshSaveBtnStatus();
  361. }
  362. catch (Exception ex)
  363. {
  364. // 对异常进行共通处理
  365. ExceptionManager.HandleEventException(this.ToString(),
  366. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  367. }
  368. }
  369. /// <summary>
  370. /// 单元格输入是否重复的校验
  371. /// </summary>
  372. /// <param name="sender"></param>
  373. /// <param name="e"></param>
  374. private void dgvGoodsType_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
  375. {
  376. try
  377. {
  378. if (this.ActiveControl != null && "btnClose".Equals(this.ActiveControl.Name))
  379. {
  380. return;
  381. }
  382. DataGridViewRow rowItem = this.dgvGoodsType.Rows[e.RowIndex];
  383. DataGridViewColumn columnItem = this.dgvGoodsType.Columns[e.ColumnIndex];
  384. if (!this.dgvGoodsType.CurrentRow.IsNewRow)
  385. {
  386. object value = rowItem.Cells[columnItem.Name].EditedFormattedValue;
  387. // 产品类型名称
  388. if ("GoodsTypeName".Equals(columnItem.Name))
  389. {
  390. if (value != null || !string.IsNullOrEmpty(value.ToString().Trim()))
  391. {
  392. if (!this.IsUnique(value.ToString(), this.dgvGoodsType.CurrentRow.Index))
  393. {
  394. // 增加单元格的错误消息
  395. this.dgvGoodsType.CurrentRow.ErrorText
  396. = string.Format(Messages.MSG_CMN_W006, "产品类别名称 ");
  397. e.Cancel = true;
  398. return;
  399. }
  400. }
  401. }
  402. else if (columnItem.Name == "ValueFlag")
  403. {
  404. if ((bool)value != true)
  405. {
  406. int isStop = SystemModuleProxy.Service.CheckGoodsTypeToUpdate(rowItem.Cells["GoodsTypeCode"].Value.ToString());
  407. if (isStop > Constant.INT_IS_ZERO)
  408. {
  409. // 增加单元格的错误消息
  410. this.dgvGoodsType.CurrentRow.ErrorText
  411. = "该类别包含子类别或商品,不可进行停用操作!";
  412. e.Cancel = true;
  413. return;
  414. }
  415. }
  416. }
  417. // 清除单元格的错误消息
  418. this.dgvGoodsType.CurrentRow.ErrorText = string.Empty;
  419. }
  420. this.dgvGoodsType.IsSetInputColumnsColor = true;
  421. }
  422. catch (Exception ex)
  423. {
  424. // 对异常进行共通处理
  425. ExceptionManager.HandleEventException(this.ToString(),
  426. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  427. }
  428. }
  429. /// <summary>
  430. /// 设置保存按钮的可用状态
  431. /// </summary>
  432. /// <param name="sender"></param>
  433. /// <param name="e"></param>
  434. private void dgvGoodsType_RowValidated(object sender, DataGridViewCellEventArgs e)
  435. {
  436. try
  437. {
  438. this.RefreshSaveBtnStatus();
  439. }
  440. catch (Exception ex)
  441. {
  442. // 对异常进行共通处理
  443. ExceptionManager.HandleEventException(this.ToString(),
  444. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  445. }
  446. }
  447. /// <summary>
  448. /// 行离开时校验不能为空的项目
  449. /// </summary>
  450. /// <param name="sender"></param>
  451. /// <param name="e"></param>
  452. private void dgvGoodsType_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
  453. {
  454. try
  455. {
  456. // 按Esc键时不校验
  457. if (!this.dgvGoodsType.IsCurrentRowDirty)
  458. {
  459. this.dgvGoodsType.IsSetInputColumnsColor = true;
  460. return;
  461. }
  462. DataGridViewRow row = this.dgvGoodsType.CurrentRow;
  463. if (!row.IsNewRow)
  464. {
  465. // 类别名称不能为空
  466. if (row.Cells["GoodsTypeName"].Value == null
  467. || string.IsNullOrEmpty(row.Cells["GoodsTypeName"].Value.ToString().Trim()))
  468. {
  469. // 增加单元格的错误消息
  470. this.dgvGoodsType.CurrentRow.ErrorText
  471. = string.Format(Messages.MSG_CMN_W005, "产品类别名称");
  472. e.Cancel = true;
  473. return;
  474. }
  475. // 过滤多余空格
  476. row.Cells["GoodsTypeName"].Value = row.Cells["GoodsTypeName"].Value.ToString().Trim();
  477. row.Cells["Remarks"].Value = row.Cells["Remarks"].Value.ToString().Trim();
  478. string BoolValueFlag = row.Cells["ValueFlag"].Value.ToString();
  479. if (BoolValueFlag == "True")
  480. {
  481. row.Cells["ValueFlag"].Value = '1';
  482. }
  483. else if (BoolValueFlag == "False")
  484. {
  485. row.Cells["ValueFlag"].Value = '0';
  486. }
  487. // 清除单元格的错误消息
  488. this.dgvGoodsType.CurrentRow.ErrorText = string.Empty;
  489. }
  490. }
  491. catch (Exception ex)
  492. {
  493. // 对异常进行共通处理
  494. ExceptionManager.HandleEventException(this.ToString(),
  495. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  496. }
  497. }
  498. /// <summary>
  499. /// 显示停用记录事件
  500. /// </summary>
  501. /// <param name="sender"></param>
  502. /// <param name="e"></param>
  503. private void chkDisplayDisabledData_CheckedChanged(object sender, EventArgs e)
  504. {
  505. try
  506. {
  507. this.RefreshData();
  508. this.dgvGoodsType.IsSetInputColumnsColor = true;
  509. }
  510. catch (Exception ex)
  511. {
  512. // 对异常进行共通处理
  513. ExceptionManager.HandleEventException(this.ToString(),
  514. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  515. }
  516. }
  517. /// <summary>
  518. /// 保存产品类型数据
  519. /// </summary>
  520. /// <param name="sender"></param>
  521. /// <param name="e"></param>
  522. private void btnSave_Click(object sender, EventArgs e)
  523. {
  524. try
  525. {
  526. int results = Conservation();
  527. if (results == Constant.INT_IS_ONE)
  528. {
  529. MessageBox.Show(string.Format(Messages.MSG_MST_W0405),
  530. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  531. this.btnSave.Enabled = false;
  532. return;
  533. }
  534. this.btnSave.Enabled = false;
  535. this.btnCancel.Enabled = false;
  536. int result = (int)DoAsync(new BaseAsyncMethod(this.SaveGoodsTypeData));
  537. this.btnSave.Enabled = true;
  538. this.btnCancel.Enabled = true;
  539. // 保存成功 2表示有数据被修改 3表示没有数据被修改
  540. if (result.Equals(Constant.INT_IS_TWO))
  541. {
  542. GetAllGoodsTypeData();
  543. this._dtSourse.AcceptChanges();
  544. this.btnSave.Enabled = false;
  545. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "产品类别管理", "保存"),
  546. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  547. }
  548. else if (result.Equals(Constant.INT_IS_FOUR))
  549. {
  550. MessageBox.Show(string.Format(Messages.MSG_CMN_X001),
  551. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  552. ((DataTable)this.dgvGoodsType.DataSource).RejectChanges();
  553. }
  554. else
  555. {
  556. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "产品类别管理", "保存"),
  557. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  558. return;
  559. }
  560. // 重新加载窗体数据
  561. this.RefreshData();
  562. this.CreateGoodsTypeTree();
  563. }
  564. catch (Exception ex)
  565. {
  566. this.btnSave.Enabled = true;
  567. this.btnCancel.Enabled = true;
  568. // 对异常进行共通处理
  569. ExceptionManager.HandleEventException(this.ToString(),
  570. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  571. }
  572. }
  573. /// <summary>
  574. /// 关闭窗体
  575. /// </summary>
  576. /// <param name="sender"></param>
  577. /// <param name="e"></param>
  578. private void btnCancel_Click(object sender, EventArgs e)
  579. {
  580. this.Close();
  581. }
  582. #endregion
  583. #region 私有方法
  584. /// <summary>
  585. /// 取得产品类别数据
  586. /// </summary>
  587. /// <returns></returns>
  588. private DataSet GetGoodsTypeData()
  589. {
  590. try
  591. {
  592. return SystemModuleProxy.Service.GetGoodsTypeData(0);
  593. }
  594. catch (Exception ex)
  595. {
  596. throw ex;
  597. }
  598. }
  599. /// <summary>
  600. /// 根据取得的产品类型数据,生成树形结构
  601. /// </summary>
  602. private void CreateGoodsTypeTree()
  603. {
  604. try
  605. {
  606. // 没有产品类型数据时,直接返回
  607. if (this._dtSourse == null || this._dtSourse.Rows.Count < Constant.INT_IS_ONE)
  608. {
  609. return;
  610. }
  611. // 将所有节点清除
  612. this.tvwType.Nodes.Clear();
  613. TreeNode goodsTypeNode = null;
  614. DataTable dtTree = this._dtSourse.Copy();
  615. dtTree.DefaultView.RowFilter = "valueflag = '1'";
  616. dtTree = dtTree.DefaultView.ToTable();
  617. DataRow[] goodsTypeRows = dtTree.Select(" LEN(GoodsTypeCode) = 3");
  618. // 显示子节点
  619. InitTreeView(dtTree, goodsTypeRows, goodsTypeNode);
  620. if (this.tvwType.SelectedNode == null)
  621. {
  622. this.tvwType.SelectedNode = this.tvwType.Nodes[0];
  623. }
  624. this.dgvGoodsType.IsSetInputColumnsColor = true;
  625. }
  626. catch (Exception ex)
  627. {
  628. throw ex;
  629. }
  630. }
  631. /// <summary>
  632. /// 保存产品类型TreeView的状态
  633. /// </summary>
  634. /// <param name="nodes"></param>
  635. private void SaveTreeNodesStatus(TreeNodeCollection nodes)
  636. {
  637. try
  638. {
  639. foreach (TreeNode node in nodes)
  640. {
  641. // 保存所有节点折叠,展开状态
  642. if (node.IsExpanded)
  643. {
  644. this.NodesStatus[node.FullPath] = true;
  645. }
  646. else
  647. {
  648. this.NodesStatus.Remove(node.FullPath);
  649. }
  650. // 当节点处于选中状态时获取根树节点到当前树节点的路径
  651. if (node.IsSelected)
  652. {
  653. SelectNodeFullPath = node.FullPath;
  654. }
  655. SaveTreeNodesStatus(node.Nodes);
  656. }
  657. }
  658. catch (Exception ex)
  659. {
  660. throw ex;
  661. }
  662. }
  663. /// <summary>
  664. /// 递归显示产品类型树形目录
  665. /// </summary>
  666. /// <param name="typeData">产品类数据源</param>
  667. /// <param name="rows"></param>
  668. /// <param name="node"></param>
  669. private void InitTreeView(DataTable typeData, DataRow[] rows, TreeNode node)
  670. {
  671. try
  672. {
  673. foreach (DataRow row in rows)
  674. {
  675. TreeNode sNode = null;
  676. if (node == null)
  677. {
  678. // 新建树节点并添加
  679. sNode = new TreeNode();
  680. sNode.Text = row["GoodsTypeName"].ToString();
  681. sNode.Name = row["GoodsTypeCode"].ToString();
  682. sNode.Tag = row["GoodsTypeID"].ToString();
  683. this.tvwType.Nodes.Add(sNode);
  684. }
  685. else
  686. {
  687. // 在原有树中加入节点
  688. sNode = node.Nodes.Add(row["GoodsTypeName"].ToString());
  689. sNode.Name = row["GoodsTypeCode"].ToString();
  690. sNode.Tag = row["GoodsTypeID"].ToString();
  691. }
  692. // 查找子节点
  693. string filterExpression = "GoodsTypeCode LIKE '" + row["GoodsTypeCode"].ToString()
  694. + "%' AND LEN(GoodsTypeCode) = " + (row["GoodsTypeCode"].ToString().Length + 3);
  695. DataRow[] subRows = typeData.Select(filterExpression);
  696. // 递归绑定子节点
  697. this.InitTreeView(typeData, subRows, sNode);
  698. }
  699. }
  700. catch (Exception ex)
  701. {
  702. throw ex;
  703. }
  704. }
  705. /// <summary>
  706. /// 保存产品类型数据
  707. /// </summary>
  708. /// <returns>影响行数</returns>
  709. private object SaveGoodsTypeData()
  710. {
  711. try
  712. {
  713. // 获取当前dataGoodsTypeData数据源
  714. DataTable dataGoodsTypeData = (DataTable)this.dgvGoodsType.DataSource;
  715. foreach (DataRow drFor in dataGoodsTypeData.Rows)
  716. {
  717. if (drFor["GoodsTypeFullName"] == null || drFor["GoodsTypeFullName"] == DBNull.Value)
  718. {
  719. drFor["GoodsTypeFullName"] = _selectNodeFullPath
  720. + "→" + drFor["GoodsTypeName"].ToString();
  721. }
  722. }
  723. int result = SystemModuleProxy.Service.SaveGoodsTypeData(dataGoodsTypeData);
  724. return result;
  725. }
  726. catch (Exception ex)
  727. {
  728. throw ex;
  729. }
  730. }
  731. /// <summary>
  732. /// 还原保存前产品类型TreeView的状态
  733. /// </summary>
  734. /// <param name="nodes">节点</param>
  735. private void SetTreeNodesStatus(TreeNodeCollection nodes)
  736. {
  737. try
  738. {
  739. foreach (TreeNode node in nodes)
  740. {
  741. if (this.NodesStatus[node.FullPath] != null)
  742. {
  743. // 展开树节点
  744. node.Expand();
  745. }
  746. // 节点路径和前选中的路径相同 设置节点为选中状态
  747. if (node.FullPath == SelectNodeFullPath)
  748. {
  749. this.tvwType.SelectedNode = node;
  750. }
  751. SetTreeNodesStatus(node.Nodes);
  752. }
  753. }
  754. catch (Exception ex)
  755. {
  756. throw ex;
  757. }
  758. }
  759. /// <summary>
  760. /// 刷新DataGridView中的数据
  761. /// </summary>
  762. private object RefreshData()
  763. {
  764. try
  765. {
  766. // 获取相应节点数据
  767. if (this.tvwType.SelectedNode != null
  768. && !string.IsNullOrEmpty(this.tvwType.SelectedNode.Name.Trim()))
  769. {
  770. this._selectNode = this.tvwType.SelectedNode.Name.Trim();
  771. this._GoodsTypeID = Convert.ToInt32(this.tvwType.SelectedNode.Tag);
  772. DataSet data = (DataSet)DoAsync(new BaseAsyncMethod(GetGoodsTypeIDData));
  773. if (data.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  774. {
  775. dgvGoodsType.AllowUserToAddRows = false;
  776. }
  777. else
  778. {
  779. dgvGoodsType.AllowUserToAddRows = true;
  780. }
  781. // 获取是否查询正常数据的标识
  782. byte valueFalg = Convert.ToByte(this.chkDisplayDisabledData.Checked);
  783. // 获取查询的数据集
  784. StringBuilder sbFilter = new StringBuilder();
  785. sbFilter.Append(" 1=1");
  786. if (valueFalg == 0)
  787. {
  788. sbFilter.Append(" and ValueFlag = '1'");
  789. }
  790. if (this._selectNode != "")
  791. {
  792. sbFilter.Append(" and GoodsTypeCode like '" + this._selectNode + "%'");
  793. }
  794. this._dtSourse.DefaultView.RowFilter = sbFilter.ToString();
  795. this.dgvGoodsType.AllowUserToModifyRows = true;
  796. // 选中新行时,自动计算产品种类编码
  797. this._dtSourse.TableNewRow += new DataTableNewRowEventHandler(Table_SelectNewRow);
  798. this.dgvGoodsType.DataSource = _dtSourse;
  799. this.dgvGoodsType.IsSetInputColumnsColor = true;
  800. }
  801. else
  802. {
  803. this.dgvGoodsType.AllowUserToModifyRows = false;
  804. }
  805. return Constant.INT_IS_ZERO;
  806. }
  807. catch (Exception ex)
  808. {
  809. throw ex;
  810. }
  811. }
  812. /// <summary>
  813. /// 按条件取得产品类型数据
  814. /// </summary>
  815. /// <returns></returns>
  816. private DataSet GetGoodsTypeByGTCode()
  817. {
  818. try
  819. {
  820. byte valueFlag = Convert.ToByte(this.chkDisplayDisabledData.Checked);
  821. DataSet dsTemp = SystemModuleProxy.Service.GetGoodsTyperData(valueFlag, this._selectNode);
  822. return dsTemp;
  823. }
  824. catch (Exception ex)
  825. {
  826. throw ex;
  827. }
  828. }
  829. /// <summary>
  830. /// 获取产品档案的ID
  831. /// </summary>
  832. /// <param name="GoodsTypeID">产品档案的ID</param>
  833. /// <returns></returns>
  834. /// <remarks>
  835. /// 2014.10.27 任海 新建
  836. /// </remarks>
  837. private DataSet GetGoodsTypeIDData()
  838. {
  839. try
  840. {
  841. return SystemModuleProxy.Service.GetGoodsTypeIDData(this._GoodsTypeID);
  842. }
  843. catch (Exception ex)
  844. {
  845. throw ex;
  846. }
  847. }
  848. /// <summary>
  849. /// 自动生成产品类型编码
  850. /// </summary>
  851. /// <param name="sender"></param>
  852. /// <param name="e"></param>
  853. private void Table_SelectNewRow(object sender, DataTableNewRowEventArgs e)
  854. {
  855. try
  856. {
  857. DataTable itemTable = sender as DataTable;
  858. DataTable itemTableF = itemTable.Copy();
  859. itemTableF.DefaultView.RowFilter = " GoodsTypeCode like '" + this._selectNode + "%'";
  860. itemTableF = itemTableF.DefaultView.ToTable();
  861. if (itemTableF != null && itemTableF.Rows.Count > Constant.INT_IS_ZERO)
  862. {
  863. // 获取本级商品种类中的最大编码
  864. string maxValue;
  865. if (itemTableF.Rows.Count > Constant.INT_IS_ONE)
  866. {
  867. DataTable filterDataTable = itemTableF.Clone();
  868. string selectNode = this.tvwType.SelectedNode.Name.Trim();
  869. DataRow[] dataRows = itemTableF.Select("LEN(GoodsTypeCode) = " + (selectNode + "000").Length);
  870. foreach (DataRow row in dataRows)
  871. {
  872. filterDataTable.Rows.Add(row.ItemArray);
  873. }
  874. maxValue = Utility.GetStringMaxValue(filterDataTable, "GoodsTypeCode");
  875. }
  876. else
  877. {
  878. maxValue = Utility.GetStringMaxValue(itemTableF, "GoodsTypeCode");
  879. }
  880. // 如果没有下级种类,编码长度加3
  881. if (itemTableF.Rows.Count == Constant.INT_IS_ONE)
  882. {
  883. e.Row["GoodsTypeCode"] = maxValue + "001";
  884. }
  885. else
  886. {
  887. e.Row["GoodsTypeCode"] = maxValue.Substring(0, maxValue.Length - 3)
  888. + ((Convert.ToInt32(maxValue.Substring(
  889. maxValue.Length - 3)) + 1)).ToString().PadLeft(3, '0');
  890. }
  891. }
  892. }
  893. catch (Exception ex)
  894. {
  895. // 对异常进行共通处理
  896. ExceptionManager.HandleEventException(this.ToString(),
  897. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  898. }
  899. }
  900. /// <summary>
  901. /// 校验值是否重复
  902. /// </summary>
  903. /// <param name="curCellValue"></param>
  904. /// <param name="curRow"></param>
  905. /// <returns></returns>
  906. private bool IsUnique(string curCellValue, int curRow)
  907. {
  908. //待修改
  909. foreach (DataGridViewRow rowItem in this.dgvGoodsType.Rows)
  910. {
  911. if (rowItem.Index == curRow)
  912. {
  913. continue;
  914. }
  915. // 类别编码
  916. if (rowItem.Cells["GoodsTypeCode"].Value != null)
  917. {
  918. if (rowItem.Cells["GoodsTypeCode"].Value.ToString().TrimEnd().
  919. Equals(curCellValue.TrimEnd()))
  920. {
  921. return false;
  922. }
  923. }
  924. }
  925. return true;
  926. }
  927. /// <summary>
  928. /// 设置TreeView选中节点
  929. /// </summary>
  930. /// <param name="treeView"></param>
  931. /// <param name="selectStr">选中节点文本</param>
  932. private void SelectTreeView(TreeView treeView, string selectStr)
  933. {
  934. treeView.Focus();
  935. for (int i = 0; i < treeView.Nodes.Count; i++)
  936. {
  937. for (int j = 0; j < treeView.Nodes[i].Nodes.Count; j++)
  938. {
  939. if (treeView.Nodes[i].Nodes[j].Text == selectStr)
  940. {
  941. treeView.SelectedNode = treeView.Nodes[i].Nodes[j];//选中
  942. //treeView.Nodes[i].Nodes[j].Checked = true;
  943. treeView.Nodes[i].Expand();//展开父级
  944. return;
  945. }
  946. }
  947. }
  948. }
  949. /// <summary>
  950. /// 保存时单元格必输项不能为空
  951. /// </summary>
  952. private int Conservation()
  953. {
  954. int isConservation = Constant.INT_IS_ZERO;
  955. DataTable dataGoodsData = (DataTable)dgvGoodsType.DataSource;
  956. foreach (DataRow drproductionData in dataGoodsData.Rows)
  957. {
  958. if (drproductionData["GoodsTypeCode"].ToString() == string.Empty)
  959. {
  960. isConservation = Constant.INT_IS_ONE;
  961. break;
  962. }
  963. }
  964. return isConservation;
  965. }
  966. /// <summary>
  967. /// 设置保存按钮的可用状态
  968. /// </summary>
  969. private void RefreshSaveBtnStatus()
  970. {
  971. // 数据有改变时,保存按钮可用,否则不可用
  972. if (DataJudge.IsChange((DataTable)this.dgvGoodsType.DataSource))
  973. {
  974. this.btnSave.Enabled = true;
  975. }
  976. else
  977. {
  978. this.btnSave.Enabled = false;
  979. }
  980. }
  981. /// <summary>
  982. /// 获取全部产品类别信息绑定到数据源中
  983. /// </summary>
  984. private void GetAllGoodsTypeData()
  985. {
  986. this._dtSourse = SystemModuleProxy.Service.GetAllGoodsTypeData().Tables[0];
  987. }
  988. #endregion
  989. }
  990. }