FrmProductGrade.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. using Core.Mes.Client.Comm.Control;
  2. using Core.Mes.Client.Comm.Server;
  3. using Core.Mes.Client.Comm.Tool;
  4. using CoreFS.CA06;
  5. using Infragistics.Win.UltraWinEditors;
  6. using Infragistics.Win.UltraWinGrid;
  7. using System;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Windows.Forms;
  14. namespace Core.StlMes.Client.Qcm
  15. {
  16. public partial class FrmProductGrade : FrmBase
  17. {
  18. List<int> list = new List<int>();
  19. int number = 0;
  20. private int _index; //临时索引列
  21. public FrmProductGrade()
  22. {
  23. InitializeComponent();
  24. ExceptionHelper.RegistException();
  25. }
  26. public void PopupLoad(string customInfo, OpeBase ob)
  27. {
  28. this.CustomInfo = customInfo;
  29. this.ob = ob;
  30. this.OnLoad(EventArgs.Empty);
  31. }
  32. private void FrmProductGrade_Load(object sender, EventArgs e)
  33. {
  34. BindcmbType();
  35. }
  36. private void BindcmbType()
  37. {
  38. #region 下拉列表
  39. DataTable dt1 = new DataTable();
  40. dt1.Columns.Add("xiaid");
  41. DataRow dr1 = dt1.NewRow();
  42. dr1["xiaid"] = ">";
  43. dt1.Rows.Add(dr1);
  44. DataRow dr2 = dt1.NewRow();
  45. dr2["xiaid"] = ">=";
  46. dt1.Rows.Add(dr2);
  47. DataRow dr3 = dt1.NewRow();
  48. dr3["xiaid"] = "=";
  49. dt1.Rows.Add(dr3);
  50. DataRow dr4 = dt1.NewRow();
  51. dr4["xiaid"] = " ";
  52. dt1.Rows.Add(dr4);
  53. dt1.Columns["xiaid"].Caption = "符号";
  54. xiaxian.DataSource = dt1;
  55. xiaxian.ValueMember = "xiaid";
  56. DataTable dt2 = new DataTable();
  57. dt2.Columns.Add("shangid");
  58. DataRow dr5 = dt2.NewRow();
  59. dr5["shangid"] = "<";
  60. dt2.Rows.Add(dr5);
  61. DataRow dr6 = dt2.NewRow();
  62. dr6["shangid"] = "<=";
  63. dt2.Rows.Add(dr6);
  64. DataRow dr7 = dt2.NewRow();
  65. dr7["shangid"] = " ";
  66. dt2.Rows.Add(dr7);
  67. dt2.Columns["shangid"].Caption = "符号";
  68. shangxian.DataSource = dt2;
  69. shangxian.ValueMember = "shangid";
  70. DataTable dt3 = ServerHelper.GetData("com.steering.pss.qcm.CoreDropList.GetDropFenLei", new Object[] { }, this.ob);
  71. int num = dt3.Rows.Count;
  72. DataTable dt4 = new DataTable();
  73. dt4.Columns.Add("fenlei");
  74. dt4.Columns.Add("fenname");
  75. DataRow dr;
  76. for (int i = 0; i < num; i++)
  77. {
  78. dr = dt4.NewRow();
  79. dr["fenlei"] = dt3.Rows[i]["BASENAME"];
  80. dr["fenname"] = dt3.Rows[i]["BASECODE"];
  81. dt4.Rows.Add(dr);
  82. }
  83. dt4.Columns["fenlei"].Caption = "钢种类型";
  84. dt4.Columns["fenname"].Caption = "钢种代码";
  85. fenleinumber.DataSource = dt4;
  86. fenleinumber.ValueMember = "fenname";
  87. fenleinumber.DisplayMember = "fenlei";
  88. ClsBaseInfo.SetComboItemHeight(fenleinumber);
  89. DataTable dt5 = ServerHelper.GetData("com.steering.pss.qcm.CoreDropList.GetSelect", new Object[] { }, this.ob);
  90. int num1 = dt5.Rows.Count;
  91. DataTable dt6 = new DataTable();
  92. dt6.Columns.Add("id");
  93. dt6.Columns.Add("name");
  94. for (int i = 0; i < num1; i++)
  95. {
  96. dr = dt6.NewRow();
  97. dr["id"] = dt5.Rows[i]["CHEM_CODE"];
  98. dr["name"] = dt5.Rows[i]["CHEM_NAME"];
  99. dt6.Rows.Add(dr);
  100. }
  101. dt6.Columns["id"].Caption = "类型";
  102. dt6.Columns["name"].Caption = "名字";
  103. yuanfenlei.DataSource = dt6;
  104. yuanfenlei.ValueMember = "id";
  105. yuanfenlei.DisplayMember = "name";
  106. #endregion
  107. }
  108. /// <summary>
  109. /// 初始下拉框
  110. /// </summary>
  111. /// <param name="dt">数据表</param>
  112. /// <param name="uce">下拉框</param>
  113. /// <param name="methodId">方法名</param>
  114. /// <param name="desc">描述</param>
  115. /// <param name="code">代码</param>
  116. private void InitDropList(ref DataTable dt, UltraComboEditor uce, string methodId, string desc)
  117. {
  118. dt = ServerHelper.GetData(methodId, null, this.ob);
  119. if (dt != null && dt.Rows.Count > 0)
  120. {
  121. uce.DataSource = dt;
  122. uce.Text = desc;
  123. uce.DisplayMember = desc;
  124. }
  125. }
  126. public override void ToolBar_Click(object sender, string ToolbarKey)
  127. {
  128. switch (ToolbarKey)
  129. {
  130. case "doQuery":
  131. try
  132. {
  133. this.Cursor = Cursors.WaitCursor;
  134. doQuery(false);
  135. }
  136. finally
  137. {
  138. this.Cursor = Cursors.Default;
  139. }
  140. break;
  141. case "doSave":
  142. doSave();
  143. break;
  144. case "QueryKey":
  145. try
  146. {
  147. this.Cursor = Cursors.WaitCursor;
  148. doQuery(true);
  149. }
  150. finally
  151. {
  152. this.Cursor = Cursors.Default;
  153. }
  154. break;
  155. case "doDelete":
  156. this.doDeleteOrResume(true);
  157. break;
  158. case "doResume":
  159. this.doDeleteOrResume(false);
  160. break;
  161. case "Refresh":
  162. BindcmbType();
  163. break;
  164. case "Export":
  165. GridHelper.ulGridToExcel(ultraGrid2, "钢种信息");
  166. break;
  167. case "doClose":
  168. this.Close();
  169. break;
  170. }
  171. }
  172. private void doSave()
  173. {
  174. number = 0;
  175. int count = 0;
  176. foreach (UltraGridRow row in ultraGrid2.Rows)
  177. {
  178. if (row.GetValue("cb") == "True")
  179. {
  180. count++;
  181. }
  182. foreach (UltraGridRow row2 in row.ChildBands[0].Rows)
  183. {
  184. if (row2.GetValue("check2") == "True")
  185. {
  186. count++;
  187. }
  188. }
  189. }
  190. if (count == 0)
  191. {
  192. MessageBox.Show("您当前没有勾选任何行!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  193. return;
  194. }
  195. int chkCnt = ultraGrid2.Rows.AsQueryable().Where("cb = 'True'").Count();
  196. int dstCnt = ultraGrid2.Rows.AsQueryable().Where("cb = 'True'")
  197. .Select(a => a.GetValue("GRADENAME")).Distinct().Count();
  198. if (chkCnt != dstCnt)
  199. {
  200. MessageUtil.ShowWarning("钢种名称不能重复!");
  201. return;
  202. }
  203. save();
  204. }
  205. private bool CheckGrd(UltraGridRow row)
  206. {
  207. if (row.Cells["COEFFICIENT"].Value.ToString().Length > 5)
  208. {
  209. MessageBox.Show("钢种系数填写错误,总长度4位 小数2位!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  210. return false;
  211. }
  212. if (row.Cells["GRADENAME"].Value.ToString() == "")
  213. {
  214. MessageBox.Show("请输入钢种名称!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  215. return false;
  216. }
  217. if (row.GetValue("VALIDFLAG") == "")
  218. {
  219. if (isExistGradeName(row.Cells["GRADENAME"].Value.ToString()) == true)
  220. {
  221. MessageUtil.ShowWarning("系统已存在钢种名称[" + row.Cells["GRADENAME"].Value.ToString() + "]!");
  222. row.Cells["GRADENAME"].Activate();
  223. return false;
  224. }
  225. }
  226. else
  227. {
  228. if (row.Cells["GRADENAME"].Value.ToString() != row.Cells["GRADENAME_OLD"].Value.ToString())
  229. {
  230. if (isExistGradeName(row.Cells["GRADENAME"].Value.ToString()) == true)
  231. {
  232. MessageUtil.ShowWarning("系统已存在钢种名称[" + row.Cells["GRADENAME"].Value.ToString() + "]!");
  233. row.Cells["GRADENAME"].Activate();
  234. return false;
  235. }
  236. }
  237. }
  238. if (row.Cells["ASSORTMENT_NAME"].Value.ToString() == "")
  239. {
  240. MessageBox.Show("请输入钢种分类名称!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  241. return false;
  242. }
  243. if (row.Cells["COEFFICIENT"].Value.ToString() == "")
  244. {
  245. MessageBox.Show("请输入钢种系数!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  246. return false;
  247. }
  248. return true;
  249. }
  250. private bool CheckGrdChm(UltraGridRow row, string gradeCode)
  251. {
  252. if (row.Cells["CHEM_NAME"].Value.ToString() == "")
  253. {
  254. MessageBox.Show("请选择化学元素描述!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  255. return false;
  256. }
  257. if (row.Cells["STDMIN"].Value.ToString().Length > 10)
  258. {
  259. MessageBox.Show("范围下限值最大只能输入十位数!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  260. return false;
  261. }
  262. if (row.Cells["STDMAX"].Value.ToString().Length > 10)
  263. {
  264. MessageBox.Show("范围上限值最大只能输入十位数!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  265. return false;
  266. }
  267. if (row.Cells["STDMIN_SIGN"].Value.ToString() != "")
  268. {
  269. try
  270. {
  271. double.Parse(row.Cells["STDMIN"].Value.ToString());
  272. }
  273. catch
  274. {
  275. MessageBox.Show("范围下限值类型输入错误!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  276. return false;
  277. }
  278. }
  279. if (row.Cells["STDMAX_SIGN"].Value.ToString() != "")
  280. {
  281. try
  282. {
  283. double.Parse(row.Cells["STDMAX"].Value.ToString());
  284. }
  285. catch
  286. {
  287. MessageBox.Show("范围上限值类型输入错误!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  288. return false;
  289. }
  290. }
  291. if (row.Cells["STDMIN_SIGN"].Value.ToString() != "" && row.Cells["STDMAX_SIGN"].Value.ToString() != "")
  292. {
  293. try
  294. {
  295. if (double.Parse(row.Cells["STDMIN"].Value.ToString()) > double.Parse(row.Cells["STDMAX"].Value.ToString()))
  296. {
  297. MessageBox.Show("成分的最小值不能比最大值大!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  298. return false;
  299. }
  300. }
  301. catch
  302. {
  303. MessageBox.Show("输入类型错误!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  304. return false;
  305. }
  306. }
  307. if (row.GetValue("VALIDFLAG") == "")
  308. {
  309. DataTable dtbs = ServerHelper.GetData("com.steering.pss.qcm.CoreSpecificationsGradeChem.SelectCode",
  310. new Object[] { gradeCode, row.Cells["CHEM_CODE"].Value.ToString() }, this.ob);
  311. if (Convert.ToInt32(dtbs.Rows[0][0]) > 0)
  312. {
  313. MessageBox.Show("此条记录已存在,请核实!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  314. return false;
  315. }
  316. }
  317. else
  318. {
  319. if (row.GetValue("CHEM_CODE") != row.GetValue("CHEM_CODE_OLD"))
  320. {
  321. DataTable dtbs = ServerHelper.GetData("com.steering.pss.qcm.CoreSpecificationsGradeChem.SelectCode",
  322. new Object[] { gradeCode, row.Cells["CHEM_CODE"].Value.ToString() }, this.ob);
  323. if (Convert.ToInt32(dtbs.Rows[0][0]) > 0)
  324. {
  325. MessageBox.Show("此条记录已存在,请核实!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  326. return false;
  327. }
  328. }
  329. }
  330. return true;
  331. }
  332. private void save()
  333. {
  334. ultraGrid2.UpdateData();
  335. ArrayList listGrds = new ArrayList();
  336. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  337. {
  338. ArrayList parm = new ArrayList();
  339. if (Convert.ToBoolean(ultraGrid2.Rows[i].Cells["cb"].Value))
  340. {
  341. if (CheckGrd(ultraGrid2.Rows[i]) == false) return;
  342. parm.Add(ultraGrid2.Rows[i].Cells["GRADENAME"].Value.ToString());
  343. parm.Add(ultraGrid2.Rows[i].Cells["ASSORTMENT_CODE"].Value.ToString());
  344. parm.Add(ultraGrid2.Rows[i].Cells["ASSORTMENT_NAME"].Text.ToString());
  345. parm.Add(ultraGrid2.Rows[i].Cells["COEFFICIENT"].Value.ToString());
  346. parm.Add(this.UserInfo.GetUserName());
  347. parm.Add(ultraGrid2.Rows[i].Cells["MEMO"].Value.ToString());
  348. parm.Add(ultraGrid2.Rows[i].GetValue("ALLOW_BUY") == "True" ? "1" : "0");
  349. parm.Add(ultraGrid2.Rows[i].Cells["GRADECODE"].Value.ToString());
  350. parm.Add(ultraGrid2.Rows[i].Cells["VALIDFLAG"].Value.ToString());
  351. //主表修改
  352. number++;
  353. }
  354. if (ultraGrid2.Rows[i].ChildBands[0].Rows.Count > 0)
  355. {
  356. ArrayList listGrdChms = new ArrayList();
  357. for (int j = 0; j < ultraGrid2.Rows[i].ChildBands[0].Rows.Count; j++)
  358. {
  359. Infragistics.Win.UltraWinGrid.UltraGridRow minrow = ultraGrid2.Rows[i].ChildBands[0].Rows[j];
  360. if (Convert.ToBoolean(minrow.Cells["check2"].Value))
  361. {
  362. if (CheckGrdChm(minrow, ultraGrid2.Rows[i].GetValue("GRADECODE")) == false)
  363. {
  364. return;
  365. }
  366. ArrayList minParm = new ArrayList();
  367. minParm.Add(ultraGrid2.Rows[i].Cells["assortment_code"].Value.ToString());
  368. minParm.Add(ultraGrid2.Rows[i].Cells["ASSORTMENT_NAME"].Value.ToString());
  369. minParm.Add(ultraGrid2.Rows[i].Cells["COEFFICIENT"].Value.ToString());
  370. minParm.Add(minrow.Cells["STDMIN_SIGN"].Value.ToString());
  371. minParm.Add(minrow.Cells["STDMIN"].Value.ToString());
  372. minParm.Add(minrow.Cells["STDMAX_SIGN"].Value.ToString());
  373. minParm.Add(minrow.Cells["STDMAX"].Value.ToString());
  374. minParm.Add(this.UserInfo.GetUserName());
  375. minParm.Add(minrow.Cells["memo"].Value.ToString());
  376. minParm.Add(ultraGrid2.Rows[i].Cells["GRADENAME"].Value.ToString());
  377. minParm.Add(minrow.Cells["CHEM_NAME"].Text.ToString());
  378. minParm.Add(ultraGrid2.Rows[i].Cells["GRADECODE"].Value.ToString());
  379. minParm.Add(minrow.Cells["CHEM_CODE"].Text.ToString());
  380. minParm.Add(minrow.Cells["VALIDFLAG"].Text.ToString());
  381. //从表修改
  382. number++;
  383. listGrdChms.Add(minParm);
  384. }
  385. }
  386. if (listGrdChms.Count > 0)
  387. {
  388. parm.Add(listGrdChms);
  389. }
  390. }
  391. if (parm.Count > 0)
  392. {
  393. listGrds.Add(parm);
  394. }
  395. }
  396. if (MessageUtil.ShowYesNoAndQuestion("是否保存数据?") == DialogResult.No)
  397. {
  398. return;
  399. }
  400. string gradeCode = ServerHelper.SetDataReturnObj("com.steering.pss.qcm.CoreSpecificationsGrade.save",
  401. new Object[] { listGrds }, this.ob).ToString();
  402. if (number > 0)
  403. {
  404. doQuery(false);
  405. MessageBox.Show("保存成功", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  406. }
  407. UltraGridRow[] rows = ultraGrid2.Rows.AsQueryable().Where("GRADECODE = '" + gradeCode + "'").ToArray();
  408. if (rows.Length > 0)
  409. {
  410. rows[0].Activate();
  411. rows[0].ExpandAll();
  412. }
  413. }
  414. private bool isExistGradeName(string gradeName)
  415. {
  416. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreSpecificationsGrade.isExistGradeName",
  417. new object[] { gradeName }, ob);
  418. if (dt.Rows[0][0].ToString() == "0")
  419. {
  420. return false;
  421. }
  422. return true;
  423. }
  424. /// <summary>
  425. /// 删除或恢复
  426. /// </summary>
  427. /// <param name="isDelete">true删除 false恢复</param>
  428. private void doDeleteOrResume(bool flag)
  429. {
  430. ultraGrid2.UpdateData();
  431. int numb = 0;
  432. if (ultraGrid2.Rows.Count == 0)
  433. {
  434. MessageBox.Show("您当前没有勾选任何行!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  435. return;
  436. }
  437. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  438. {
  439. if (Convert.ToBoolean(ultraGrid2.Rows[i].Cells["cb"].Value))
  440. {
  441. if (ultraGrid2.Rows[i].ChildBands[0].Rows.Count > 0 && flag)
  442. {
  443. MessageBox.Show("子表数据必须删除!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  444. return;
  445. }
  446. string tishi = "";
  447. if (flag)
  448. tishi = "删除";
  449. else
  450. tishi = "恢复";
  451. if (numb == 0)
  452. {
  453. if (MessageBox.Show(tishi + "勾选记录,您是否继续?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  454. {
  455. return;
  456. }
  457. }
  458. numb++;
  459. ArrayList listBase = new ArrayList();
  460. if (flag == true)
  461. {
  462. listBase.Add(UserInfo.GetUserName());
  463. }
  464. listBase.Add(ultraGrid2.Rows[i].Cells["GRADECODE"].Text.Trim().ToString());
  465. //主表删除
  466. int count = ServerHelper.SetData("com.steering.pss.qcm.CoreSpecificationsGrade.deleteLineInfo", new Object[] { listBase, flag }, this.ob);
  467. }
  468. if (ultraGrid2.Rows[i].ChildBands[0].Rows.Count > 0)
  469. {
  470. for (int j = 0; j < ultraGrid2.Rows[i].ChildBands[0].Rows.Count; j++)
  471. {
  472. if (Convert.ToBoolean(ultraGrid2.Rows[i].ChildBands[0].Rows[j].Cells["check2"].Value))
  473. {
  474. string tishi = "";
  475. if (flag)
  476. tishi = "删除";
  477. else
  478. tishi = "恢复";
  479. if (numb == 0)
  480. {
  481. if (MessageBox.Show(tishi + "勾选记录,您是否继续?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  482. {
  483. return;
  484. }
  485. }
  486. numb++;
  487. ArrayList listChild = new ArrayList();
  488. if (flag == true)
  489. {
  490. listChild.Add(UserInfo.GetUserName());
  491. listChild.Add(System.DateTime.Now);
  492. }
  493. listChild.Add(ultraGrid2.Rows[i].ChildBands[0].Rows[j].Cells["GRADECODE"].Text.Trim().ToString());
  494. listChild.Add(ultraGrid2.Rows[i].ChildBands[0].Rows[j].Cells["CHEM_CODE"].Value.ToString());
  495. //从表删除
  496. int count1 = ServerHelper.SetData("com.steering.pss.qcm.CoreSpecificationsGradeChem.deleteLineInfo", new Object[] { listChild, flag }, this.ob);
  497. }
  498. }
  499. }
  500. }
  501. if (numb == 0)
  502. {
  503. MessageBox.Show("请选择需要处理的数据行!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  504. return;
  505. }
  506. doQuery(false);
  507. }
  508. /// <summary>
  509. /// 查询方法,比较通用的查询方法
  510. /// </summary>
  511. private void doQuery(bool flag)
  512. {
  513. bool validFlag = flag;
  514. string titleName = "";
  515. string gradeName = labelTextBox1.Checked ? labelTextBox1.Text.Trim() : "";
  516. DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreSpecificationsGrade.getLineList",
  517. new Object[] { validFlag, titleName, gradeName }, this.ob);
  518. dataTable2.Clear();
  519. GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true);
  520. //从表的记录也要查询出来。
  521. DataTable mindt = ServerHelper.GetData("com.steering.pss.qcm.CoreSpecificationsGradeChem.getLineList",
  522. new Object[] { validFlag, titleName, gradeName }, this.ob);
  523. GridHelper.CopyDataToDatatable(ref mindt, ref this.dataTable2, true);
  524. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  525. {
  526. for (int j = 0; j < ultraGrid2.Rows[i].Cells.Count; j++)
  527. {
  528. if (ultraGrid2.Rows[i].Cells[j].Column.Key == "cb") continue;
  529. ultraGrid2.Rows[i].Cells[j].Activation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly;
  530. }
  531. if (ultraGrid2.Rows[i].ChildBands != null && ultraGrid2.Rows[i].ChildBands[0].Rows.Count > 0)
  532. {
  533. for (int j = 0; j < ultraGrid2.Rows[i].ChildBands[0].Rows.Count; j++)
  534. {
  535. for (int k = 0; k < ultraGrid2.Rows[i].ChildBands[0].Rows[j].Cells.Count; k++)
  536. {
  537. if (ultraGrid2.Rows[i].ChildBands[0].Rows[j].Cells[k].Column.Key == "check2") continue;
  538. ultraGrid2.Rows[i].ChildBands[0].Rows[j].Cells[k].Activation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly;
  539. }
  540. }
  541. }
  542. }
  543. UltraGridColumn[] col = new UltraGridColumn[] { this.ultraGrid2.DisplayLayout.Bands[0].Columns["MEMO"] };
  544. //GridHelper.RefreshAndAutoSizeExceptRows(ultraGrid2, col);
  545. //不同颜色区分是否有效数据
  546. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  547. Infragistics.Win.UltraWinGrid.UltraGridRow minrow = null;
  548. for (int i = 0; i < ultraGrid2.Rows.Count; i++)
  549. {
  550. row = ultraGrid2.Rows[i];
  551. if (row.ChildBands != null && row.ChildBands[0].Rows.Count > 0)
  552. {
  553. for (int j = 0; j < row.ChildBands[0].Rows.Count; j++)
  554. {
  555. minrow = row.ChildBands[0].Rows[j];
  556. if (!minrow.Cells["VALIDFLAG"].Value.ToString().Equals("1"))
  557. {
  558. minrow.Appearance.ForeColor = Color.Red;
  559. }
  560. else
  561. {
  562. minrow.Appearance.ForeColor = Color.Black;
  563. }
  564. }
  565. }
  566. if (!row.Cells["VALIDFLAG"].Value.ToString().Equals("1"))
  567. {
  568. row.Appearance.ForeColor = Color.Red;
  569. }
  570. else
  571. {
  572. row.Appearance.ForeColor = Color.Black;
  573. }
  574. }
  575. }
  576. private void ultraGrid2_CellChange(object sender, CellEventArgs e)
  577. {
  578. this.ultraGrid2.UpdateData();
  579. //勾选 全选
  580. if (e.Cell.Column.Key.Equals("cb"))
  581. {
  582. if (e.Cell.Row.ChildBands[0] != null)
  583. {
  584. foreach (UltraGridRow row in e.Cell.Row.ChildBands[0].Rows)
  585. {
  586. row.Cells["check2"].Value = e.Cell.Value;
  587. }
  588. }
  589. }
  590. if (e.Cell.Column.Key.Equals("check2"))
  591. {//勾选从表(取消勾选)
  592. int flag = 0; //判断从表状态参数
  593. foreach (UltraGridRow row in e.Cell.Row.ParentRow.ChildBands[0].Rows)
  594. {
  595. if (Convert.ToBoolean(row.Cells["check2"].Value))
  596. {
  597. flag += 1; //从表勾选了 状态参数+1
  598. }
  599. }
  600. if (flag < e.Cell.Row.ParentRow.ChildBands[0].Rows.Count)
  601. {//状态参数小于从表的行数,说明未全勾选,主表未半选状态
  602. e.Cell.Row.ParentRow.Cells["cb"].Value = null;
  603. }
  604. else if (flag == 0) //从表取消全部勾选,主表不勾选
  605. {
  606. e.Cell.Row.ParentRow.Cells["cb"].Value = false;
  607. }
  608. else //否则主表未全选状态
  609. {
  610. e.Cell.Row.ParentRow.Cells["cb"].Value = true;
  611. }
  612. }
  613. if (e.Cell.Column.Key.Equals("ASSORTMENT_NAME"))
  614. {
  615. e.Cell.Row.Cells["ASSORTMENT_CODE"].Value = e.Cell.Row.Cells["ASSORTMENT_NAME"].Value;
  616. }
  617. if (e.Cell.Column.Key.Equals("CHEM_NAME"))
  618. {
  619. e.Cell.Row.Cells["CHEM_CODE"].Value = e.Cell.Row.Cells["CHEM_NAME"].Value;
  620. }
  621. if (e.Cell.Column.Key.Equals("cb"))
  622. {
  623. Activation activation = Activation.NoEdit;
  624. if (Convert.ToBoolean(e.Cell.Value))
  625. {
  626. activation = Activation.AllowEdit;
  627. }
  628. CellsCollection cells = e.Cell.Row.Cells;
  629. for (int i = 0; i < cells.Count; i++)
  630. {
  631. if (!cells[i].Column.Key.Equals("cb")) //i!=9
  632. {
  633. e.Cell.Row.Cells[i].Activation = activation;
  634. }
  635. }
  636. }
  637. if (e.Cell.Column.Key.Equals("check2"))
  638. {
  639. Activation activation = Activation.ActivateOnly;
  640. if (Convert.ToBoolean(e.Cell.Value))
  641. {
  642. activation = Activation.AllowEdit;
  643. }
  644. CellsCollection cells = e.Cell.Row.Cells;
  645. for (int i = 0; i < cells.Count; i++)
  646. {
  647. if (!cells[i].Column.Key.Equals("check2"))
  648. {
  649. e.Cell.Row.Cells[i].Activation = activation;
  650. }
  651. }
  652. }
  653. }
  654. private void ultraGrid2_AfterRowInsert(object sender, RowEventArgs e)
  655. {
  656. for (int i = 0; i < e.Row.Cells.Count; i++)
  657. {
  658. if (i == 8) break;
  659. e.Row.Cells[i].Activation = Activation.NoEdit;
  660. }
  661. if (e.Row.HasParent())
  662. {
  663. e.Row.Cells["GRADECODE"].Value = e.Row.ParentRow.Cells["GRADECODE"].Value.ToString();
  664. }
  665. else
  666. {
  667. e.Row.Cells["GRADECODE"].Value = ++_index;
  668. }
  669. }
  670. private void labelTextBox1_TextBox_KeyDown(object sender, KeyEventArgs e)
  671. {
  672. if (e.KeyCode == Keys.Enter)
  673. {
  674. this.doQuery(false);
  675. }
  676. }
  677. }
  678. }