F_MST_0302.cs 36 KB

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