frmBasePlineReback.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. using Core.Mes.Client.Comm.Control;
  2. using Core.Mes.Client.Comm.Format;
  3. using Core.Mes.Client.Comm.Server;
  4. using Core.Mes.Client.Comm.Tool;
  5. using Core.StlMes.Client.PnCost.Models;
  6. using CoreFS.CA06;
  7. using Infragistics.Win.UltraWinGrid;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Data;
  12. using System.Drawing;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Windows.Forms;
  16. using System.Xml;
  17. namespace Core.StlMes.Client.PnCost
  18. {
  19. public partial class frmBasePlineReback : FrmBase
  20. {
  21. #region 定义变量
  22. private DataTable dt;
  23. #endregion
  24. #region 初始化
  25. public frmBasePlineReback()
  26. {
  27. OpeBase ob = new OpeBase();
  28. System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
  29. xmlDoc.Load(Environment.CurrentDirectory + "\\data\\comm.core");
  30. XmlNode xn = xmlDoc.SelectSingleNode("CommunicationConfig");
  31. foreach (XmlNode node in xn.ChildNodes)
  32. {
  33. if (((XmlElement)node).GetAttribute("name") == "PSSServer")
  34. {
  35. ob.MainUrl = node.SelectSingleNode("url").InnerText;
  36. }
  37. }
  38. dt = ServerHelper.GetData("com.steering.pss.pncost.base.ComBasePlineReback.queryPliao",
  39. new object[] { "" }, ob);
  40. Test(dt);
  41. BindData(dt, dataTable1);
  42. ultraCheckEditor1.Checked = false;
  43. ultraTextEditor1.Enabled = false;
  44. this.ultraGrid1.CellChange += new Infragistics.Win.UltraWinGrid.CellEventHandler(this.ultraGrid1_CellChange);//事件初始化
  45. }
  46. #endregion
  47. #region 方法
  48. public override void ToolBar_Click(object sender, string ToolbarKey)
  49. {
  50. base.ToolBar_Click(sender, ToolbarKey);
  51. switch (ToolbarKey)
  52. {
  53. case "Query":
  54. Query();
  55. break;
  56. case "Save":
  57. Save();
  58. break;
  59. case "Close":
  60. this.Close();
  61. break;
  62. }
  63. }
  64. /// 查询方法
  65. /// <summary>
  66. /// 查询方法
  67. /// </summary>
  68. private void Query()
  69. {
  70. #region 条件验证
  71. //产线
  72. string strPei = "";
  73. if (ultraCheckEditor1.Checked)//产线是否选择
  74. {
  75. if (ultraTextEditor1.Text == "")//产线是否输入
  76. {
  77. MessageUtil.ShowWarning("请输入产线!");
  78. return;
  79. }
  80. else
  81. {
  82. strPei = ultraTextEditor1.Text.Trim();//配料方案
  83. }
  84. }
  85. #endregion
  86. dt = ServerHelper.GetData("com.steering.pss.pncost.base.ComBasePlineReback.queryPliao",
  87. new object[] { strPei }, ob);
  88. BindData(dt, dataTable1);
  89. if (ultraGrid1.Rows.Count == 0)
  90. {
  91. return;
  92. }
  93. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  94. {
  95. ultraGrid1.Rows[i].Cells["CHK"].Value = false;
  96. GridEdite(ultraGrid1.Rows[i]);
  97. }
  98. ultraGrid1.UpdateData();
  99. ultraGrid1.ActiveRow = ultraGrid1.Rows[0];
  100. }
  101. /// 保存方法
  102. /// <summary>
  103. /// 保存方法
  104. /// </summary>
  105. private void Save()
  106. {
  107. string stringnew = "";
  108. string xuanze = "false";
  109. try
  110. {
  111. #region 验证信息
  112. ultraGrid1.UpdateData();
  113. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  114. {
  115. if (ultraGrid1.Rows[i].Cells["CHK"].Value.ToString() == "True")
  116. {
  117. //string PERCENT = "";//回收率
  118. //for (int j = 0; j < ultraGrid1.Rows[i].Cells.Count; j++)
  119. //{
  120. // if (ultraGrid1.Rows[i].Cells[j].Column.Key.Contains("PERCENT"))
  121. // {
  122. // PERCENT = (Convert.ToDecimal(ultraGrid1.Rows[i].Cells[j].Value.ToString3()) +
  123. // Convert.ToDecimal(PERCENT.ToString3())).ToString3();
  124. // }
  125. //}
  126. //if (Convert.ToDecimal(PERCENT)>100)
  127. //{
  128. // MessageUtil.ShowWarning("选择的记录回收率之和不能大于100, 请重新输入!");
  129. // return;
  130. //}
  131. xuanze = "true";
  132. }
  133. }
  134. if (xuanze == "false")
  135. {
  136. MessageUtil.ShowWarning("请选择你要保存的记录!");
  137. return;
  138. }
  139. if (MessageUtil.ShowYesNoAndQuestion("是否确认保存?") == System.Windows.Forms.DialogResult.No)
  140. {
  141. return;
  142. }
  143. #endregion
  144. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  145. {
  146. if (ultraGrid1.Rows[i].Cells["CHK"].Value.ToString() == "True")
  147. {
  148. string plinecode = ultraGrid1.Rows[i].Cells["PLINE_NAME"].Tag.ToString2();
  149. stringnew = ultraGrid1.Rows[i].Cells["PLINE_NAME"].Tag.ToString2();
  150. string itemcode = "";
  151. string itemname = "";
  152. for (int j = 0; j < ultraGrid1.Rows[i].Cells.Count; j++)
  153. {
  154. if (ultraGrid1.Rows[i].Cells[j].Column.Key.Contains("PROPORTION"))
  155. {
  156. string pro = ultraGrid1.Rows[i].Cells[j].Column.Key.ToString2();
  157. string percent = "PERCENT" + pro.Substring(pro.Length - 1);
  158. itemcode = ultraGrid1.Rows[i].Cells[j].Column.Tag.ToString2();
  159. var items = dt.Rows.Cast<DataRow>().GroupBy(a => new { itemCode = a["ITEM_CODE"].ToString(), itemName = a["ITEM_NAME"].ToString() })
  160. .Select(a => a.Key).ToList();
  161. for (int x = 0; x < items.Count; x++)
  162. {
  163. if (itemcode == items[x].itemCode)
  164. {
  165. itemname = items[x].itemName;
  166. }
  167. }
  168. DataTable data = ServerHelper.GetData("com.steering.pss.pncost.base.ComBasePlineReback.queryNum", new Object[] { plinecode, itemcode }, ob);
  169. if (data.Rows[0][0].ToString() == "1")//判断是新增还是修改的保存
  170. {
  171. CostBasePlineRebackEntity parm = new CostBasePlineRebackEntity();//修改
  172. parm.PlineCode = ultraGrid1.Rows[i].Cells["PLINE_NAME"].Tag.ToString();
  173. parm.PlineName = ultraGrid1.Rows[i].Cells["PLINE_NAME"].Value.ToString();
  174. parm.ItemCode = itemcode;
  175. parm.ItemName = itemname;
  176. parm.Proportion = Convert.ToDecimal(ultraGrid1.Rows[i].Cells[j].Value.ToString3());
  177. parm.Percent = Convert.ToDecimal(ultraGrid1.Rows[i].Cells[percent].Value.ToString3());
  178. parm.UpdateName = this.UserInfo.GetUserName();
  179. string JsonStr = JSONFormat.Format(parm);
  180. ServerHelper.SetData("com.steering.pss.pncost.base.ComBasePlineReback.usave", new object[] { JsonStr }, ob);
  181. }
  182. else
  183. {//新增
  184. CostBasePlineRebackEntity parm = new CostBasePlineRebackEntity();//新增
  185. parm.PlineCode = ultraGrid1.Rows[i].Cells["PLINE_NAME"].Tag.ToString();
  186. parm.PlineName = ultraGrid1.Rows[i].Cells["PLINE_NAME"].Value.ToString();
  187. parm.ItemCode = itemcode;
  188. parm.ItemName = itemname;
  189. parm.Proportion = Convert.ToDecimal(ultraGrid1.Rows[i].Cells[j].Value.ToString3());
  190. parm.Percent = Convert.ToDecimal(ultraGrid1.Rows[i].Cells[percent].Value.ToString3());
  191. parm.CreateName = this.UserInfo.GetUserName();
  192. string JsonStr = JSONFormat.Format(parm);
  193. ServerHelper.SetData("com.steering.pss.pncost.base.ComBasePlineReback.isave", new object[] { JsonStr }, ob);
  194. }
  195. }
  196. }
  197. }
  198. }
  199. }
  200. catch (Exception ex)
  201. {
  202. MessageUtil.ShowError("保存失败!'" + ex.Message + "'");
  203. return;
  204. }
  205. MessageUtil.ShowTips("保存成功!");
  206. Query();
  207. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  208. {
  209. if (ultraGrid1.Rows[i].Cells["PLINE_NAME"].Tag.ToString2() == stringnew)
  210. {
  211. ultraGrid1.Rows[i].Activate();
  212. }
  213. }
  214. }
  215. Infragistics.Win.UltraWinGrid.UltraGridBand ultraGridBand1 = new Infragistics.Win.UltraWinGrid.UltraGridBand("Table1", -1);
  216. /// 样式初始化
  217. /// <summary>
  218. /// 样式初始化
  219. /// </summary>
  220. private void Test(DataTable dt)
  221. {
  222. this.components = new System.ComponentModel.Container();
  223. Infragistics.Win.Appearance appearance1 = new Infragistics.Win.Appearance();
  224. Infragistics.Win.Appearance appearance2 = new Infragistics.Win.Appearance();
  225. Infragistics.Win.Appearance appearance4 = new Infragistics.Win.Appearance();
  226. Infragistics.Win.Appearance appearance3 = new Infragistics.Win.Appearance();
  227. Infragistics.Win.Appearance appearance7 = new Infragistics.Win.Appearance();
  228. Infragistics.Win.Appearance appearance10 = new Infragistics.Win.Appearance();
  229. Infragistics.Win.Appearance appearance12 = new Infragistics.Win.Appearance();
  230. Infragistics.Win.Appearance appearance8 = new Infragistics.Win.Appearance();
  231. Infragistics.Win.Appearance appearance6 = new Infragistics.Win.Appearance();
  232. Infragistics.Win.Appearance appearance5 = new Infragistics.Win.Appearance();
  233. Infragistics.Win.Appearance appearance11 = new Infragistics.Win.Appearance();
  234. Infragistics.Win.Appearance appearance9 = new Infragistics.Win.Appearance();
  235. this.ultraGrid1 = new Infragistics.Win.UltraWinGrid.UltraGrid();
  236. this.dataSet1 = new System.Data.DataSet();
  237. this.dataTable1 = new System.Data.DataTable();
  238. this.ultraTextEditor1 = new Infragistics.Win.UltraWinEditors.UltraTextEditor();
  239. this.ultraCheckEditor1 = new Infragistics.Win.UltraWinEditors.UltraCheckEditor();
  240. this.ultraPanel1 = new Infragistics.Win.Misc.UltraPanel();
  241. DataColumn dataColumn7 = new System.Data.DataColumn();
  242. DataColumn dataColumn8 = new System.Data.DataColumn();
  243. ((System.ComponentModel.ISupportInitialize)(this.ultraGrid1)).BeginInit();
  244. ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
  245. ((System.ComponentModel.ISupportInitialize)(this.dataTable1)).BeginInit();
  246. ((System.ComponentModel.ISupportInitialize)(this.ultraTextEditor1)).BeginInit();
  247. ((System.ComponentModel.ISupportInitialize)(this.ultraCheckEditor1)).BeginInit();
  248. this.ultraPanel1.ClientArea.SuspendLayout();
  249. this.ultraPanel1.SuspendLayout();
  250. this.SuspendLayout();
  251. this.ultraGrid1.DataSource = this.dataSet1;
  252. appearance1.BackColor = System.Drawing.SystemColors.Window;
  253. appearance1.BorderColor = System.Drawing.SystemColors.InactiveCaption;
  254. this.ultraGrid1.DisplayLayout.Appearance = appearance1;
  255. ultraGridBand1.RowLayoutStyle = Infragistics.Win.UltraWinGrid.RowLayoutStyle.GroupLayout;
  256. CreateGridColumn(dt, dataTable1, ultraGridBand1);
  257. this.ultraGrid1.DisplayLayout.BandsSerializer.Add(ultraGridBand1);
  258. this.ultraGrid1.DisplayLayout.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
  259. this.ultraGrid1.DisplayLayout.CaptionVisible = Infragistics.Win.DefaultableBoolean.False;
  260. appearance2.BackColor = System.Drawing.SystemColors.ActiveBorder;
  261. appearance2.BackColor2 = System.Drawing.SystemColors.ControlDark;
  262. appearance2.BackGradientStyle = Infragistics.Win.GradientStyle.Vertical;
  263. appearance2.BorderColor = System.Drawing.SystemColors.Window;
  264. this.ultraGrid1.DisplayLayout.GroupByBox.Appearance = appearance2;
  265. appearance4.ForeColor = System.Drawing.SystemColors.GrayText;
  266. this.ultraGrid1.DisplayLayout.GroupByBox.BandLabelAppearance = appearance4;
  267. this.ultraGrid1.DisplayLayout.GroupByBox.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
  268. appearance3.BackColor = System.Drawing.SystemColors.ControlLightLight;
  269. appearance3.BackColor2 = System.Drawing.SystemColors.Control;
  270. appearance3.BackGradientStyle = Infragistics.Win.GradientStyle.Horizontal;
  271. appearance3.ForeColor = System.Drawing.SystemColors.GrayText;
  272. this.ultraGrid1.DisplayLayout.GroupByBox.PromptAppearance = appearance3;
  273. this.ultraGrid1.DisplayLayout.MaxColScrollRegions = 1;
  274. this.ultraGrid1.DisplayLayout.MaxRowScrollRegions = 1;
  275. appearance7.BackColor = System.Drawing.SystemColors.Window;
  276. appearance7.ForeColor = System.Drawing.SystemColors.ControlText;
  277. this.ultraGrid1.DisplayLayout.Override.ActiveCellAppearance = appearance7;
  278. appearance10.BackColor = System.Drawing.SystemColors.Highlight;
  279. appearance10.ForeColor = System.Drawing.SystemColors.HighlightText;
  280. this.ultraGrid1.DisplayLayout.Override.ActiveRowAppearance = appearance10;
  281. this.ultraGrid1.DisplayLayout.Override.BorderStyleCell = Infragistics.Win.UIElementBorderStyle.Dotted;
  282. this.ultraGrid1.DisplayLayout.Override.BorderStyleRow = Infragistics.Win.UIElementBorderStyle.Dotted;
  283. appearance12.BackColor = System.Drawing.SystemColors.Window;
  284. this.ultraGrid1.DisplayLayout.Override.CardAreaAppearance = appearance12;
  285. appearance8.BorderColor = System.Drawing.Color.Silver;
  286. appearance8.TextTrimming = Infragistics.Win.TextTrimming.EllipsisCharacter;
  287. this.ultraGrid1.DisplayLayout.Override.CellAppearance = appearance8;
  288. this.ultraGrid1.DisplayLayout.Override.CellClickAction = Infragistics.Win.UltraWinGrid.CellClickAction.EditAndSelectText;
  289. this.ultraGrid1.DisplayLayout.Override.CellPadding = 0;
  290. appearance6.BackColor = System.Drawing.SystemColors.Control;
  291. appearance6.BackColor2 = System.Drawing.SystemColors.ControlDark;
  292. appearance6.BackGradientAlignment = Infragistics.Win.GradientAlignment.Element;
  293. appearance6.BackGradientStyle = Infragistics.Win.GradientStyle.Horizontal;
  294. appearance6.BorderColor = System.Drawing.SystemColors.Window;
  295. this.ultraGrid1.DisplayLayout.Override.GroupByRowAppearance = appearance6;
  296. appearance5.TextHAlignAsString = "Left";
  297. this.ultraGrid1.DisplayLayout.Override.HeaderAppearance = appearance5;
  298. this.ultraGrid1.DisplayLayout.Override.HeaderClickAction = Infragistics.Win.UltraWinGrid.HeaderClickAction.SortMulti;
  299. this.ultraGrid1.DisplayLayout.Override.HeaderStyle = Infragistics.Win.HeaderStyle.WindowsXPCommand;
  300. appearance11.BackColor = System.Drawing.SystemColors.Window;
  301. appearance11.BorderColor = System.Drawing.Color.Silver;
  302. this.ultraGrid1.DisplayLayout.Override.RowAppearance = appearance11;
  303. this.ultraGrid1.DisplayLayout.Override.RowSelectors = Infragistics.Win.DefaultableBoolean.False;
  304. appearance9.BackColor = System.Drawing.SystemColors.ControlLight;
  305. this.ultraGrid1.DisplayLayout.Override.TemplateAddRowAppearance = appearance9;
  306. this.ultraGrid1.DisplayLayout.ScrollBounds = Infragistics.Win.UltraWinGrid.ScrollBounds.ScrollToFill;
  307. this.ultraGrid1.DisplayLayout.ScrollStyle = Infragistics.Win.UltraWinGrid.ScrollStyle.Immediate;
  308. this.ultraGrid1.DisplayLayout.ViewStyleBand = Infragistics.Win.UltraWinGrid.ViewStyleBand.OutlookGroupBy;
  309. this.ultraGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
  310. this.ultraGrid1.Location = new System.Drawing.Point(0, 0);
  311. this.ultraGrid1.Name = "ultraGrid1";
  312. this.ultraGrid1.Size = new System.Drawing.Size(666, 405);
  313. this.ultraGrid1.TabIndex = 0;
  314. this.ultraGrid1.Text = "ultraGrid1";
  315. this.dataSet1.DataSetName = "NewDataSet";
  316. this.dataSet1.Tables.AddRange(new System.Data.DataTable[] {
  317. this.dataTable1});
  318. this.dataTable1.TableName = "Table1";
  319. // ultraTextEditor1
  320. //
  321. this.ultraTextEditor1.Location = new System.Drawing.Point(87, 10);
  322. this.ultraTextEditor1.Name = "ultraTextEditor1";
  323. this.ultraTextEditor1.Size = new System.Drawing.Size(100, 21);
  324. this.ultraTextEditor1.TabIndex = 3;
  325. //
  326. // ultraCheckEditor1
  327. //
  328. this.ultraCheckEditor1.Location = new System.Drawing.Point(24, 12);
  329. this.ultraCheckEditor1.Name = "ultraCheckEditor1";
  330. this.ultraCheckEditor1.Size = new System.Drawing.Size(57, 20);
  331. this.ultraCheckEditor1.TabIndex = 2;
  332. this.ultraCheckEditor1.Text = "产线";
  333. this.ultraCheckEditor1.CheckedChanged += new System.EventHandler(this.ultraCheckEditor1_CheckedChanged);
  334. //
  335. // ultraPanel1
  336. //
  337. //
  338. // ultraPanel1.ClientArea
  339. //
  340. this.ultraPanel1.ClientArea.Controls.Add(this.ultraCheckEditor1);
  341. this.ultraPanel1.ClientArea.Controls.Add(this.ultraTextEditor1);
  342. this.ultraPanel1.Dock = System.Windows.Forms.DockStyle.Top;
  343. this.ultraPanel1.Location = new System.Drawing.Point(0, 0);
  344. this.ultraPanel1.Name = "ultraPanel1";
  345. this.ultraPanel1.Size = new System.Drawing.Size(666, 47);
  346. this.ultraPanel1.TabIndex = 4;
  347. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  348. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  349. this.ClientSize = new System.Drawing.Size(666, 405);
  350. this.Controls.Add(this.ultraGrid1);
  351. this.Controls.Add(this.ultraPanel1);
  352. this.Name = "frmBasePlineReback";
  353. this.Text = "frmBasePlineReback";
  354. ((System.ComponentModel.ISupportInitialize)(this.ultraGrid1)).EndInit();
  355. ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit();
  356. ((System.ComponentModel.ISupportInitialize)(this.ultraTextEditor1)).EndInit();
  357. ((System.ComponentModel.ISupportInitialize)(this.ultraCheckEditor1)).EndInit();
  358. this.ultraPanel1.ClientArea.ResumeLayout(false);
  359. this.ultraPanel1.ClientArea.PerformLayout();
  360. this.ultraPanel1.ResumeLayout(false);
  361. ((System.ComponentModel.ISupportInitialize)(this.dataTable1)).EndInit();
  362. this.ResumeLayout(false);
  363. }
  364. /// 设置样式
  365. /// <summary>
  366. /// 设置样式
  367. /// </summary>
  368. private void CreateGridColumn(DataTable dt, DataTable dtSource, UltraGridBand ultraGridBand1)
  369. {
  370. Infragistics.Win.UltraWinGrid.UltraGridColumn ultraGridColumn1 = new Infragistics.Win.UltraWinGrid.UltraGridColumn("CHK");
  371. ultraGridColumn1.Header.Caption = "选择";
  372. ultraGridColumn1.CellAppearance.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
  373. Infragistics.Win.UltraWinGrid.UltraGridColumn ultraGridColumn2 = new Infragistics.Win.UltraWinGrid.UltraGridColumn("PLINE_NAME", -1, null, 0, Infragistics.Win.UltraWinGrid.SortIndicator.Ascending, false);
  374. ultraGridColumn2.Header.Caption = "产线";
  375. ultraGridColumn2.CellActivation = Activation.ActivateOnly;
  376. Infragistics.Win.UltraWinGrid.UltraGridColumn ultraGridColumn5 = new Infragistics.Win.UltraWinGrid.UltraGridColumn("PROCESS_DESC");
  377. ultraGridColumn5.Header.Caption = "工序";
  378. ultraGridColumn5.CellActivation = Activation.ActivateOnly;
  379. ultraGridColumn1.Header.VisiblePosition = 0;
  380. ultraGridColumn1.RowLayoutColumnInfo.OriginX = 0;
  381. ultraGridColumn1.RowLayoutColumnInfo.OriginY = 0;
  382. ultraGridColumn1.RowLayoutColumnInfo.PreferredCellSize = new System.Drawing.Size(49, 0);
  383. ultraGridColumn1.RowLayoutColumnInfo.PreferredLabelSize = new System.Drawing.Size(0, 48);
  384. ultraGridColumn1.RowLayoutColumnInfo.SpanX = 1;
  385. ultraGridColumn1.RowLayoutColumnInfo.SpanY = 2;
  386. ultraGridColumn2.Header.VisiblePosition = 1;
  387. ultraGridColumn2.RowLayoutColumnInfo.OriginX = 1;
  388. ultraGridColumn2.RowLayoutColumnInfo.OriginY = 0;
  389. ultraGridColumn2.RowLayoutColumnInfo.PreferredCellSize = new System.Drawing.Size(175, 16);
  390. ultraGridColumn2.RowLayoutColumnInfo.PreferredLabelSize = new System.Drawing.Size(0, 48);
  391. ultraGridColumn2.RowLayoutColumnInfo.SpanX = 3;
  392. ultraGridColumn2.RowLayoutColumnInfo.SpanY = 2;
  393. ultraGridColumn5.Header.VisiblePosition = 2;
  394. ultraGridColumn5.RowLayoutColumnInfo.OriginX = 4;
  395. ultraGridColumn5.RowLayoutColumnInfo.OriginY = 0;
  396. ultraGridColumn5.RowLayoutColumnInfo.PreferredCellSize = new System.Drawing.Size(75, 16);
  397. ultraGridColumn5.RowLayoutColumnInfo.PreferredLabelSize = new System.Drawing.Size(0, 48);
  398. ultraGridColumn5.RowLayoutColumnInfo.SpanX = 2;
  399. ultraGridColumn5.RowLayoutColumnInfo.SpanY = 2;
  400. object[] gridColumns = new object[dt.Rows.Cast<DataRow>().GroupBy(a => a["ITEM_CODE"]).Count() * 2 + 3];
  401. gridColumns[0] = ultraGridColumn1;
  402. gridColumns[1] = ultraGridColumn2;
  403. gridColumns[2] = ultraGridColumn5;
  404. dtSource.Columns.Add("CHK", typeof(bool));
  405. dtSource.Columns.Add("PLINE_NAME");
  406. dtSource.Columns.Add("PROCESS_DESC");
  407. UltraGridGroup[] gridGroups = new UltraGridGroup[dt.Rows.Cast<DataRow>().GroupBy(a => new { itemCode = a["ITEM_CODE"].ToString(), itemName = a["ITEM_NAME"].ToString() }).Count()];
  408. var items = dt.Rows.Cast<DataRow>().GroupBy(a => new { itemCode = a["ITEM_CODE"].ToString(), itemName = a["ITEM_NAME"].ToString() })
  409. .Select(a => a.Key).ToList();
  410. for (int i = 0; i < items.Count; i++)
  411. {
  412. Infragistics.Win.UltraWinGrid.UltraGridColumn ultraGridColumn3 = new Infragistics.Win.UltraWinGrid.UltraGridColumn("PROPORTION" + i);
  413. ultraGridColumn3.Tag = items[i].itemCode;
  414. //ultraGridColumn3.DataType = typeof(decimal);
  415. ultraGridColumn3.MaskInput = "nn.nn";
  416. ultraGridColumn3.Hidden = true;
  417. Infragistics.Win.UltraWinGrid.UltraGridColumn ultraGridColumn4 = new Infragistics.Win.UltraWinGrid.UltraGridColumn("PERCENT" + i);
  418. ultraGridColumn4.Tag = items[i].itemCode;
  419. //ultraGridColumn4.DataType = typeof(decimal);
  420. ultraGridColumn4.MaskInput = "nn.nn";
  421. ultraGridColumn4.CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right;
  422. ultraGridColumn4.CellAppearance.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
  423. ultraGridColumn3.Header.VisiblePosition = i * 2 + 3; //4
  424. ultraGridColumn3.RowLayoutColumnInfo.OriginX = 0;
  425. ultraGridColumn3.RowLayoutColumnInfo.OriginY = 0;
  426. ultraGridColumn3.RowLayoutColumnInfo.ParentGroupIndex = i;
  427. ultraGridColumn3.RowLayoutColumnInfo.ParentGroupKey = "NewGroup" + i;
  428. ultraGridColumn3.RowLayoutColumnInfo.PreferredCellSize = new System.Drawing.Size(90, 0);
  429. ultraGridColumn3.RowLayoutColumnInfo.PreferredLabelSize = new System.Drawing.Size(0, 24);
  430. ultraGridColumn3.RowLayoutColumnInfo.SpanX = 1;
  431. ultraGridColumn3.RowLayoutColumnInfo.SpanY = 1;
  432. ultraGridColumn3.Header.Caption = "(1-成材率)占比(%)";
  433. ultraGridColumn4.Header.VisiblePosition = i * 2 + 4; //5
  434. ultraGridColumn4.RowLayoutColumnInfo.OriginX = 1;
  435. ultraGridColumn4.RowLayoutColumnInfo.OriginY = 0;
  436. ultraGridColumn4.RowLayoutColumnInfo.ParentGroupIndex = i;
  437. ultraGridColumn4.RowLayoutColumnInfo.ParentGroupKey = "NewGroup" + i;
  438. ultraGridColumn4.RowLayoutColumnInfo.PreferredCellSize = new System.Drawing.Size(80, 0);//设置宽度
  439. ultraGridColumn4.RowLayoutColumnInfo.PreferredLabelSize = new System.Drawing.Size(0, 24);
  440. ultraGridColumn4.RowLayoutColumnInfo.SpanX = 1;//span跟上面的宽度不一样
  441. ultraGridColumn4.RowLayoutColumnInfo.SpanY = 1;
  442. ultraGridColumn4.Header.Caption = "回收率(%)";
  443. gridColumns[i * 2 + 3] = ultraGridColumn3;
  444. gridColumns[i * 2 + 4] = ultraGridColumn4;
  445. Infragistics.Win.UltraWinGrid.UltraGridGroup ultraGridGroup3 = new Infragistics.Win.UltraWinGrid.UltraGridGroup("NewGroup" + i, 7308663 + i);
  446. ultraGridGroup3.Key = "NewGroup" + i;
  447. ultraGridGroup3.RowLayoutGroupInfo.LabelSpan = 1;
  448. ultraGridGroup3.RowLayoutGroupInfo.OriginX = i * 2 + 6;
  449. ultraGridGroup3.RowLayoutGroupInfo.OriginY = 0;
  450. ultraGridGroup3.RowLayoutGroupInfo.PreferredLabelSize = new System.Drawing.Size(0, 24);
  451. ultraGridGroup3.RowLayoutGroupInfo.SpanX = 2;
  452. ultraGridGroup3.RowLayoutGroupInfo.SpanY = 2;
  453. ultraGridGroup3.Header.Caption = items[i].itemName;
  454. gridGroups[i] = ultraGridGroup3;
  455. dtSource.Columns.Add("PROPORTION" + i, typeof(decimal));
  456. dtSource.Columns.Add("PERCENT" + i, typeof(decimal));
  457. }
  458. ultraGridBand1.Columns.AddRange(gridColumns);
  459. ultraGridBand1.Groups.AddRange(gridGroups);
  460. }
  461. /// 绑定值
  462. /// <summary>
  463. /// 绑定值
  464. /// </summary>
  465. private void BindData(DataTable dt, DataTable dtSource)
  466. {
  467. dtSource.Clear();
  468. //ultraGrid1.BeginUpdate();
  469. var plines = dt.Rows.Cast<DataRow>().GroupBy(a => new { chk = a["CHK"].ToString(), plineName = a["PLINE_NAME"].ToString(), PROCESS_DESC = a["PROCESS_DESC"].ToString() })
  470. .Select(a => a.Key).ToList();
  471. for (int i = 0; i < plines.Count; i++)
  472. {
  473. DataRow dr = dtSource.NewRow();
  474. dr["CHK"] = bool.Parse(plines[i].chk);
  475. dr["PLINE_NAME"] = plines[i].plineName;
  476. dr["PROCESS_DESC"] = plines[i].PROCESS_DESC;
  477. dtSource.Rows.Add(dr);
  478. }
  479. foreach (var row in ultraGrid1.Rows)
  480. {
  481. foreach (var cell in row.Cells)
  482. {
  483. DataRow[] drItem = dt.Select("ITEM_CODE = '" + cell.Column.Tag + "' AND PLINE_NAME = '" + row.Cells["PLINE_NAME"].Value + "'");
  484. DataRow[] drPline = dt.Select("PLINE_NAME = '" + row.Cells["PLINE_NAME"].Value + "'");
  485. if (cell.Column.Key.Contains("PROPORTION"))
  486. {
  487. cell.Value = drItem[0]["PROPORTION"];
  488. }
  489. else if (cell.Column.Key.Contains("PERCENT"))
  490. {
  491. cell.Value = drItem[0]["PERCENT"];
  492. }
  493. else if (cell.Column.Key == "PLINE_NAME")
  494. {
  495. cell.Tag = drPline[0]["PLINE_CODE"];
  496. }
  497. }
  498. }
  499. ultraGrid1.UpdateData();
  500. //ultraGrid1.EndUpdate();
  501. }
  502. #endregion
  503. #region 事件
  504. /// 选择事件
  505. /// <summary>
  506. /// 选择事件
  507. /// </summary>
  508. private void ultraGrid1_CellChange(object sender, CellEventArgs e)
  509. {
  510. ultraGrid1.UpdateData();
  511. if (e.Cell.Column.Key == "CHK")
  512. {
  513. GridEdite(e.Cell.Row);
  514. }
  515. }
  516. /// 选择判断
  517. /// <summary>
  518. /// 选择判断
  519. /// </summary>
  520. private void GridEdite(UltraGridRow row)
  521. {
  522. if (row.GetValue("CHK") == "True")
  523. {
  524. foreach (UltraGridCell cell in row.Cells)
  525. {
  526. if (cell.Column.CellActivation == Activation.AllowEdit)
  527. {
  528. cell.Activation = Activation.AllowEdit;
  529. }
  530. }
  531. }
  532. else
  533. {
  534. foreach (UltraGridCell cell in row.Cells)
  535. {
  536. if (cell.Column.Key == "CHK") continue;
  537. if (cell.Column.CellActivation == Activation.AllowEdit)
  538. {
  539. cell.Activation = Activation.ActivateOnly;
  540. }
  541. }
  542. }
  543. }
  544. /// 产线选择事件
  545. /// <summary>
  546. /// 产线选择事件
  547. /// </summary>
  548. private void ultraCheckEditor1_CheckedChanged(object sender, EventArgs e)
  549. {
  550. ultraTextEditor1.Enabled = this.ultraCheckEditor1.Checked;
  551. }
  552. #endregion
  553. }
  554. }