| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574 |
- using Core.Mes.Client.Comm.Control;
- using Core.Mes.Client.Comm.Format;
- using Core.Mes.Client.Comm.Server;
- using Core.Mes.Client.Comm.Tool;
- using Core.StlMes.Client.PnCost.Models;
- using CoreFS.CA06;
- using Infragistics.Win.UltraWinGrid;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Xml;
- namespace Core.StlMes.Client.PnCost
- {
- public partial class frmBasePlineReback : FrmBase
- {
- #region 定义变量
- private DataTable dt;
- #endregion
- #region 初始化
- public frmBasePlineReback()
- {
- OpeBase ob = new OpeBase();
- System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
- xmlDoc.Load(Environment.CurrentDirectory + "\\data\\comm.core");
- XmlNode xn = xmlDoc.SelectSingleNode("CommunicationConfig");
- foreach (XmlNode node in xn.ChildNodes)
- {
- if (((XmlElement)node).GetAttribute("name") == "PSSServer")
- {
- ob.MainUrl = node.SelectSingleNode("url").InnerText;
- }
- }
- dt = ServerHelper.GetData("com.steering.pss.pncost.base.ComBasePlineReback.queryPliao",
- new object[] { "" }, ob);
- Test(dt);
- BindData(dt, dataTable1);
- ultraCheckEditor1.Checked = false;
- ultraTextEditor1.Enabled = false;
- this.ultraGrid1.CellChange += new Infragistics.Win.UltraWinGrid.CellEventHandler(this.ultraGrid1_CellChange);//事件初始化
- }
- #endregion
- #region 方法
- public override void ToolBar_Click(object sender, string ToolbarKey)
- {
- base.ToolBar_Click(sender, ToolbarKey);
- switch (ToolbarKey)
- {
- case "Query":
- Query();
- break;
- case "Save":
- Save();
- break;
- case "Close":
- this.Close();
- break;
- }
- }
-
- /// 查询方法
- /// <summary>
- /// 查询方法
- /// </summary>
- private void Query()
- {
- #region 条件验证
- //产线
- string strPei = "";
- if (ultraCheckEditor1.Checked)//产线是否选择
- {
- if (ultraTextEditor1.Text == "")//产线是否输入
- {
- MessageUtil.ShowWarning("请输入产线!");
- return;
- }
- else
- {
- strPei = ultraTextEditor1.Text.Trim();//配料方案
- }
- }
- #endregion
- dt = ServerHelper.GetData("com.steering.pss.pncost.base.ComBasePlineReback.queryPliao",
- new object[] { strPei }, ob);
- BindData(dt, dataTable1);
- if (ultraGrid1.Rows.Count == 0)
- {
- return;
- }
- for (int i = 0; i < ultraGrid1.Rows.Count; i++)
- {
- ultraGrid1.Rows[i].Cells["CHK"].Value = false;
- GridEdite(ultraGrid1.Rows[i]);
- }
- ultraGrid1.UpdateData();
- ultraGrid1.ActiveRow = ultraGrid1.Rows[0];
- }
- /// 保存方法
- /// <summary>
- /// 保存方法
- /// </summary>
- private void Save()
- {
- string stringnew = "";
- string xuanze = "false";
- try
- {
- #region 验证信息
- ultraGrid1.UpdateData();
- for (int i = 0; i < ultraGrid1.Rows.Count; i++)
- {
- if (ultraGrid1.Rows[i].Cells["CHK"].Value.ToString() == "True")
- {
- //string PERCENT = "";//回收率
- //for (int j = 0; j < ultraGrid1.Rows[i].Cells.Count; j++)
- //{
- // if (ultraGrid1.Rows[i].Cells[j].Column.Key.Contains("PERCENT"))
- // {
- // PERCENT = (Convert.ToDecimal(ultraGrid1.Rows[i].Cells[j].Value.ToString3()) +
- // Convert.ToDecimal(PERCENT.ToString3())).ToString3();
- // }
- //}
- //if (Convert.ToDecimal(PERCENT)>100)
- //{
- // MessageUtil.ShowWarning("选择的记录回收率之和不能大于100, 请重新输入!");
- // return;
- //}
- xuanze = "true";
- }
- }
- if (xuanze == "false")
- {
- MessageUtil.ShowWarning("请选择你要保存的记录!");
- return;
- }
- if (MessageUtil.ShowYesNoAndQuestion("是否确认保存?") == System.Windows.Forms.DialogResult.No)
- {
- return;
- }
- #endregion
- for (int i = 0; i < ultraGrid1.Rows.Count; i++)
- {
- if (ultraGrid1.Rows[i].Cells["CHK"].Value.ToString() == "True")
- {
- string plinecode = ultraGrid1.Rows[i].Cells["PLINE_NAME"].Tag.ToString2();
- stringnew = ultraGrid1.Rows[i].Cells["PLINE_NAME"].Tag.ToString2();
- string itemcode = "";
- string itemname = "";
- for (int j = 0; j < ultraGrid1.Rows[i].Cells.Count; j++)
- {
- if (ultraGrid1.Rows[i].Cells[j].Column.Key.Contains("PROPORTION"))
- {
- string pro = ultraGrid1.Rows[i].Cells[j].Column.Key.ToString2();
- string percent = "PERCENT" + pro.Substring(pro.Length - 1);
- itemcode = ultraGrid1.Rows[i].Cells[j].Column.Tag.ToString2();
- var items = dt.Rows.Cast<DataRow>().GroupBy(a => new { itemCode = a["ITEM_CODE"].ToString(), itemName = a["ITEM_NAME"].ToString() })
- .Select(a => a.Key).ToList();
- for (int x = 0; x < items.Count; x++)
- {
- if (itemcode == items[x].itemCode)
- {
- itemname = items[x].itemName;
- }
- }
- DataTable data = ServerHelper.GetData("com.steering.pss.pncost.base.ComBasePlineReback.queryNum", new Object[] { plinecode, itemcode }, ob);
- if (data.Rows[0][0].ToString() == "1")//判断是新增还是修改的保存
- {
- CostBasePlineRebackEntity parm = new CostBasePlineRebackEntity();//修改
- parm.PlineCode = ultraGrid1.Rows[i].Cells["PLINE_NAME"].Tag.ToString();
- parm.PlineName = ultraGrid1.Rows[i].Cells["PLINE_NAME"].Value.ToString();
- parm.ItemCode = itemcode;
- parm.ItemName = itemname;
- parm.Proportion = Convert.ToDecimal(ultraGrid1.Rows[i].Cells[j].Value.ToString3());
- parm.Percent = Convert.ToDecimal(ultraGrid1.Rows[i].Cells[percent].Value.ToString3());
- parm.UpdateName = this.UserInfo.GetUserName();
- string JsonStr = JSONFormat.Format(parm);
- ServerHelper.SetData("com.steering.pss.pncost.base.ComBasePlineReback.usave", new object[] { JsonStr }, ob);
- }
- else
- {//新增
- CostBasePlineRebackEntity parm = new CostBasePlineRebackEntity();//新增
- parm.PlineCode = ultraGrid1.Rows[i].Cells["PLINE_NAME"].Tag.ToString();
- parm.PlineName = ultraGrid1.Rows[i].Cells["PLINE_NAME"].Value.ToString();
- parm.ItemCode = itemcode;
- parm.ItemName = itemname;
- parm.Proportion = Convert.ToDecimal(ultraGrid1.Rows[i].Cells[j].Value.ToString3());
- parm.Percent = Convert.ToDecimal(ultraGrid1.Rows[i].Cells[percent].Value.ToString3());
- parm.CreateName = this.UserInfo.GetUserName();
- string JsonStr = JSONFormat.Format(parm);
- ServerHelper.SetData("com.steering.pss.pncost.base.ComBasePlineReback.isave", new object[] { JsonStr }, ob);
- }
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- MessageUtil.ShowError("保存失败!'" + ex.Message + "'");
- return;
- }
- MessageUtil.ShowTips("保存成功!");
- Query();
- for (int i = 0; i < ultraGrid1.Rows.Count; i++)
- {
- if (ultraGrid1.Rows[i].Cells["PLINE_NAME"].Tag.ToString2() == stringnew)
- {
- ultraGrid1.Rows[i].Activate();
- }
- }
- }
- Infragistics.Win.UltraWinGrid.UltraGridBand ultraGridBand1 = new Infragistics.Win.UltraWinGrid.UltraGridBand("Table1", -1);
- /// 样式初始化
- /// <summary>
- /// 样式初始化
- /// </summary>
- private void Test(DataTable dt)
- {
- this.components = new System.ComponentModel.Container();
- Infragistics.Win.Appearance appearance1 = new Infragistics.Win.Appearance();
- Infragistics.Win.Appearance appearance2 = new Infragistics.Win.Appearance();
- Infragistics.Win.Appearance appearance4 = new Infragistics.Win.Appearance();
- Infragistics.Win.Appearance appearance3 = new Infragistics.Win.Appearance();
- Infragistics.Win.Appearance appearance7 = new Infragistics.Win.Appearance();
- Infragistics.Win.Appearance appearance10 = new Infragistics.Win.Appearance();
- Infragistics.Win.Appearance appearance12 = new Infragistics.Win.Appearance();
- Infragistics.Win.Appearance appearance8 = new Infragistics.Win.Appearance();
- Infragistics.Win.Appearance appearance6 = new Infragistics.Win.Appearance();
- Infragistics.Win.Appearance appearance5 = new Infragistics.Win.Appearance();
- Infragistics.Win.Appearance appearance11 = new Infragistics.Win.Appearance();
- Infragistics.Win.Appearance appearance9 = new Infragistics.Win.Appearance();
- this.ultraGrid1 = new Infragistics.Win.UltraWinGrid.UltraGrid();
- this.dataSet1 = new System.Data.DataSet();
- this.dataTable1 = new System.Data.DataTable();
- this.ultraTextEditor1 = new Infragistics.Win.UltraWinEditors.UltraTextEditor();
- this.ultraCheckEditor1 = new Infragistics.Win.UltraWinEditors.UltraCheckEditor();
- this.ultraPanel1 = new Infragistics.Win.Misc.UltraPanel();
- DataColumn dataColumn7 = new System.Data.DataColumn();
- DataColumn dataColumn8 = new System.Data.DataColumn();
- ((System.ComponentModel.ISupportInitialize)(this.ultraGrid1)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.dataTable1)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.ultraTextEditor1)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.ultraCheckEditor1)).BeginInit();
- this.ultraPanel1.ClientArea.SuspendLayout();
- this.ultraPanel1.SuspendLayout();
- this.SuspendLayout();
- this.ultraGrid1.DataSource = this.dataSet1;
- appearance1.BackColor = System.Drawing.SystemColors.Window;
- appearance1.BorderColor = System.Drawing.SystemColors.InactiveCaption;
- this.ultraGrid1.DisplayLayout.Appearance = appearance1;
- ultraGridBand1.RowLayoutStyle = Infragistics.Win.UltraWinGrid.RowLayoutStyle.GroupLayout;
- CreateGridColumn(dt, dataTable1, ultraGridBand1);
- this.ultraGrid1.DisplayLayout.BandsSerializer.Add(ultraGridBand1);
- this.ultraGrid1.DisplayLayout.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
- this.ultraGrid1.DisplayLayout.CaptionVisible = Infragistics.Win.DefaultableBoolean.False;
- appearance2.BackColor = System.Drawing.SystemColors.ActiveBorder;
- appearance2.BackColor2 = System.Drawing.SystemColors.ControlDark;
- appearance2.BackGradientStyle = Infragistics.Win.GradientStyle.Vertical;
- appearance2.BorderColor = System.Drawing.SystemColors.Window;
- this.ultraGrid1.DisplayLayout.GroupByBox.Appearance = appearance2;
- appearance4.ForeColor = System.Drawing.SystemColors.GrayText;
- this.ultraGrid1.DisplayLayout.GroupByBox.BandLabelAppearance = appearance4;
- this.ultraGrid1.DisplayLayout.GroupByBox.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
- appearance3.BackColor = System.Drawing.SystemColors.ControlLightLight;
- appearance3.BackColor2 = System.Drawing.SystemColors.Control;
- appearance3.BackGradientStyle = Infragistics.Win.GradientStyle.Horizontal;
- appearance3.ForeColor = System.Drawing.SystemColors.GrayText;
- this.ultraGrid1.DisplayLayout.GroupByBox.PromptAppearance = appearance3;
- this.ultraGrid1.DisplayLayout.MaxColScrollRegions = 1;
- this.ultraGrid1.DisplayLayout.MaxRowScrollRegions = 1;
- appearance7.BackColor = System.Drawing.SystemColors.Window;
- appearance7.ForeColor = System.Drawing.SystemColors.ControlText;
- this.ultraGrid1.DisplayLayout.Override.ActiveCellAppearance = appearance7;
- appearance10.BackColor = System.Drawing.SystemColors.Highlight;
- appearance10.ForeColor = System.Drawing.SystemColors.HighlightText;
- this.ultraGrid1.DisplayLayout.Override.ActiveRowAppearance = appearance10;
- this.ultraGrid1.DisplayLayout.Override.BorderStyleCell = Infragistics.Win.UIElementBorderStyle.Dotted;
- this.ultraGrid1.DisplayLayout.Override.BorderStyleRow = Infragistics.Win.UIElementBorderStyle.Dotted;
- appearance12.BackColor = System.Drawing.SystemColors.Window;
- this.ultraGrid1.DisplayLayout.Override.CardAreaAppearance = appearance12;
- appearance8.BorderColor = System.Drawing.Color.Silver;
- appearance8.TextTrimming = Infragistics.Win.TextTrimming.EllipsisCharacter;
- this.ultraGrid1.DisplayLayout.Override.CellAppearance = appearance8;
- this.ultraGrid1.DisplayLayout.Override.CellClickAction = Infragistics.Win.UltraWinGrid.CellClickAction.EditAndSelectText;
- this.ultraGrid1.DisplayLayout.Override.CellPadding = 0;
- appearance6.BackColor = System.Drawing.SystemColors.Control;
- appearance6.BackColor2 = System.Drawing.SystemColors.ControlDark;
- appearance6.BackGradientAlignment = Infragistics.Win.GradientAlignment.Element;
- appearance6.BackGradientStyle = Infragistics.Win.GradientStyle.Horizontal;
- appearance6.BorderColor = System.Drawing.SystemColors.Window;
- this.ultraGrid1.DisplayLayout.Override.GroupByRowAppearance = appearance6;
- appearance5.TextHAlignAsString = "Left";
- this.ultraGrid1.DisplayLayout.Override.HeaderAppearance = appearance5;
- this.ultraGrid1.DisplayLayout.Override.HeaderClickAction = Infragistics.Win.UltraWinGrid.HeaderClickAction.SortMulti;
- this.ultraGrid1.DisplayLayout.Override.HeaderStyle = Infragistics.Win.HeaderStyle.WindowsXPCommand;
- appearance11.BackColor = System.Drawing.SystemColors.Window;
- appearance11.BorderColor = System.Drawing.Color.Silver;
- this.ultraGrid1.DisplayLayout.Override.RowAppearance = appearance11;
- this.ultraGrid1.DisplayLayout.Override.RowSelectors = Infragistics.Win.DefaultableBoolean.False;
- appearance9.BackColor = System.Drawing.SystemColors.ControlLight;
- this.ultraGrid1.DisplayLayout.Override.TemplateAddRowAppearance = appearance9;
- this.ultraGrid1.DisplayLayout.ScrollBounds = Infragistics.Win.UltraWinGrid.ScrollBounds.ScrollToFill;
- this.ultraGrid1.DisplayLayout.ScrollStyle = Infragistics.Win.UltraWinGrid.ScrollStyle.Immediate;
- this.ultraGrid1.DisplayLayout.ViewStyleBand = Infragistics.Win.UltraWinGrid.ViewStyleBand.OutlookGroupBy;
- this.ultraGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
- this.ultraGrid1.Location = new System.Drawing.Point(0, 0);
- this.ultraGrid1.Name = "ultraGrid1";
- this.ultraGrid1.Size = new System.Drawing.Size(666, 405);
- this.ultraGrid1.TabIndex = 0;
- this.ultraGrid1.Text = "ultraGrid1";
- this.dataSet1.DataSetName = "NewDataSet";
- this.dataSet1.Tables.AddRange(new System.Data.DataTable[] {
- this.dataTable1});
- this.dataTable1.TableName = "Table1";
- // ultraTextEditor1
- //
- this.ultraTextEditor1.Location = new System.Drawing.Point(87, 10);
- this.ultraTextEditor1.Name = "ultraTextEditor1";
- this.ultraTextEditor1.Size = new System.Drawing.Size(100, 21);
- this.ultraTextEditor1.TabIndex = 3;
- //
- // ultraCheckEditor1
- //
- this.ultraCheckEditor1.Location = new System.Drawing.Point(24, 12);
- this.ultraCheckEditor1.Name = "ultraCheckEditor1";
- this.ultraCheckEditor1.Size = new System.Drawing.Size(57, 20);
- this.ultraCheckEditor1.TabIndex = 2;
- this.ultraCheckEditor1.Text = "产线";
- this.ultraCheckEditor1.CheckedChanged += new System.EventHandler(this.ultraCheckEditor1_CheckedChanged);
- //
- // ultraPanel1
- //
- //
- // ultraPanel1.ClientArea
- //
- this.ultraPanel1.ClientArea.Controls.Add(this.ultraCheckEditor1);
- this.ultraPanel1.ClientArea.Controls.Add(this.ultraTextEditor1);
- this.ultraPanel1.Dock = System.Windows.Forms.DockStyle.Top;
- this.ultraPanel1.Location = new System.Drawing.Point(0, 0);
- this.ultraPanel1.Name = "ultraPanel1";
- this.ultraPanel1.Size = new System.Drawing.Size(666, 47);
- this.ultraPanel1.TabIndex = 4;
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(666, 405);
- this.Controls.Add(this.ultraGrid1);
- this.Controls.Add(this.ultraPanel1);
- this.Name = "frmBasePlineReback";
- this.Text = "frmBasePlineReback";
- ((System.ComponentModel.ISupportInitialize)(this.ultraGrid1)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.ultraTextEditor1)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.ultraCheckEditor1)).EndInit();
- this.ultraPanel1.ClientArea.ResumeLayout(false);
- this.ultraPanel1.ClientArea.PerformLayout();
- this.ultraPanel1.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.dataTable1)).EndInit();
- this.ResumeLayout(false);
- }
- /// 设置样式
- /// <summary>
- /// 设置样式
- /// </summary>
- private void CreateGridColumn(DataTable dt, DataTable dtSource, UltraGridBand ultraGridBand1)
- {
- Infragistics.Win.UltraWinGrid.UltraGridColumn ultraGridColumn1 = new Infragistics.Win.UltraWinGrid.UltraGridColumn("CHK");
- ultraGridColumn1.Header.Caption = "选择";
- ultraGridColumn1.CellAppearance.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
- Infragistics.Win.UltraWinGrid.UltraGridColumn ultraGridColumn2 = new Infragistics.Win.UltraWinGrid.UltraGridColumn("PLINE_NAME", -1, null, 0, Infragistics.Win.UltraWinGrid.SortIndicator.Ascending, false);
- ultraGridColumn2.Header.Caption = "产线";
- ultraGridColumn2.CellActivation = Activation.ActivateOnly;
- Infragistics.Win.UltraWinGrid.UltraGridColumn ultraGridColumn5 = new Infragistics.Win.UltraWinGrid.UltraGridColumn("PROCESS_DESC");
- ultraGridColumn5.Header.Caption = "工序";
- ultraGridColumn5.CellActivation = Activation.ActivateOnly;
- ultraGridColumn1.Header.VisiblePosition = 0;
- ultraGridColumn1.RowLayoutColumnInfo.OriginX = 0;
- ultraGridColumn1.RowLayoutColumnInfo.OriginY = 0;
- ultraGridColumn1.RowLayoutColumnInfo.PreferredCellSize = new System.Drawing.Size(49, 0);
- ultraGridColumn1.RowLayoutColumnInfo.PreferredLabelSize = new System.Drawing.Size(0, 48);
- ultraGridColumn1.RowLayoutColumnInfo.SpanX = 1;
- ultraGridColumn1.RowLayoutColumnInfo.SpanY = 2;
- ultraGridColumn2.Header.VisiblePosition = 1;
- ultraGridColumn2.RowLayoutColumnInfo.OriginX = 1;
- ultraGridColumn2.RowLayoutColumnInfo.OriginY = 0;
- ultraGridColumn2.RowLayoutColumnInfo.PreferredCellSize = new System.Drawing.Size(175, 16);
- ultraGridColumn2.RowLayoutColumnInfo.PreferredLabelSize = new System.Drawing.Size(0, 48);
- ultraGridColumn2.RowLayoutColumnInfo.SpanX = 3;
- ultraGridColumn2.RowLayoutColumnInfo.SpanY = 2;
- ultraGridColumn5.Header.VisiblePosition = 2;
- ultraGridColumn5.RowLayoutColumnInfo.OriginX = 4;
- ultraGridColumn5.RowLayoutColumnInfo.OriginY = 0;
- ultraGridColumn5.RowLayoutColumnInfo.PreferredCellSize = new System.Drawing.Size(75, 16);
- ultraGridColumn5.RowLayoutColumnInfo.PreferredLabelSize = new System.Drawing.Size(0, 48);
- ultraGridColumn5.RowLayoutColumnInfo.SpanX = 2;
- ultraGridColumn5.RowLayoutColumnInfo.SpanY = 2;
- object[] gridColumns = new object[dt.Rows.Cast<DataRow>().GroupBy(a => a["ITEM_CODE"]).Count() * 2 + 3];
- gridColumns[0] = ultraGridColumn1;
- gridColumns[1] = ultraGridColumn2;
- gridColumns[2] = ultraGridColumn5;
- dtSource.Columns.Add("CHK", typeof(bool));
- dtSource.Columns.Add("PLINE_NAME");
- dtSource.Columns.Add("PROCESS_DESC");
- UltraGridGroup[] gridGroups = new UltraGridGroup[dt.Rows.Cast<DataRow>().GroupBy(a => new { itemCode = a["ITEM_CODE"].ToString(), itemName = a["ITEM_NAME"].ToString() }).Count()];
- var items = dt.Rows.Cast<DataRow>().GroupBy(a => new { itemCode = a["ITEM_CODE"].ToString(), itemName = a["ITEM_NAME"].ToString() })
- .Select(a => a.Key).ToList();
- for (int i = 0; i < items.Count; i++)
- {
- Infragistics.Win.UltraWinGrid.UltraGridColumn ultraGridColumn3 = new Infragistics.Win.UltraWinGrid.UltraGridColumn("PROPORTION" + i);
- ultraGridColumn3.Tag = items[i].itemCode;
- //ultraGridColumn3.DataType = typeof(decimal);
- ultraGridColumn3.MaskInput = "nn.nn";
- ultraGridColumn3.Hidden = true;
- Infragistics.Win.UltraWinGrid.UltraGridColumn ultraGridColumn4 = new Infragistics.Win.UltraWinGrid.UltraGridColumn("PERCENT" + i);
- ultraGridColumn4.Tag = items[i].itemCode;
- //ultraGridColumn4.DataType = typeof(decimal);
- ultraGridColumn4.MaskInput = "nn.nn";
- ultraGridColumn4.CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right;
- ultraGridColumn4.CellAppearance.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
- ultraGridColumn3.Header.VisiblePosition = i * 2 + 3; //4
- ultraGridColumn3.RowLayoutColumnInfo.OriginX = 0;
- ultraGridColumn3.RowLayoutColumnInfo.OriginY = 0;
- ultraGridColumn3.RowLayoutColumnInfo.ParentGroupIndex = i;
- ultraGridColumn3.RowLayoutColumnInfo.ParentGroupKey = "NewGroup" + i;
- ultraGridColumn3.RowLayoutColumnInfo.PreferredCellSize = new System.Drawing.Size(90, 0);
- ultraGridColumn3.RowLayoutColumnInfo.PreferredLabelSize = new System.Drawing.Size(0, 24);
- ultraGridColumn3.RowLayoutColumnInfo.SpanX = 1;
- ultraGridColumn3.RowLayoutColumnInfo.SpanY = 1;
- ultraGridColumn3.Header.Caption = "(1-成材率)占比(%)";
- ultraGridColumn4.Header.VisiblePosition = i * 2 + 4; //5
- ultraGridColumn4.RowLayoutColumnInfo.OriginX = 1;
- ultraGridColumn4.RowLayoutColumnInfo.OriginY = 0;
- ultraGridColumn4.RowLayoutColumnInfo.ParentGroupIndex = i;
- ultraGridColumn4.RowLayoutColumnInfo.ParentGroupKey = "NewGroup" + i;
- ultraGridColumn4.RowLayoutColumnInfo.PreferredCellSize = new System.Drawing.Size(80, 0);//设置宽度
- ultraGridColumn4.RowLayoutColumnInfo.PreferredLabelSize = new System.Drawing.Size(0, 24);
- ultraGridColumn4.RowLayoutColumnInfo.SpanX = 1;//span跟上面的宽度不一样
- ultraGridColumn4.RowLayoutColumnInfo.SpanY = 1;
- ultraGridColumn4.Header.Caption = "回收率(%)";
- gridColumns[i * 2 + 3] = ultraGridColumn3;
- gridColumns[i * 2 + 4] = ultraGridColumn4;
- Infragistics.Win.UltraWinGrid.UltraGridGroup ultraGridGroup3 = new Infragistics.Win.UltraWinGrid.UltraGridGroup("NewGroup" + i, 7308663 + i);
- ultraGridGroup3.Key = "NewGroup" + i;
- ultraGridGroup3.RowLayoutGroupInfo.LabelSpan = 1;
- ultraGridGroup3.RowLayoutGroupInfo.OriginX = i * 2 + 6;
- ultraGridGroup3.RowLayoutGroupInfo.OriginY = 0;
- ultraGridGroup3.RowLayoutGroupInfo.PreferredLabelSize = new System.Drawing.Size(0, 24);
- ultraGridGroup3.RowLayoutGroupInfo.SpanX = 2;
- ultraGridGroup3.RowLayoutGroupInfo.SpanY = 2;
- ultraGridGroup3.Header.Caption = items[i].itemName;
- gridGroups[i] = ultraGridGroup3;
- dtSource.Columns.Add("PROPORTION" + i, typeof(decimal));
- dtSource.Columns.Add("PERCENT" + i, typeof(decimal));
- }
- ultraGridBand1.Columns.AddRange(gridColumns);
- ultraGridBand1.Groups.AddRange(gridGroups);
- }
- /// 绑定值
- /// <summary>
- /// 绑定值
- /// </summary>
- private void BindData(DataTable dt, DataTable dtSource)
- {
- dtSource.Clear();
- //ultraGrid1.BeginUpdate();
- var plines = dt.Rows.Cast<DataRow>().GroupBy(a => new { chk = a["CHK"].ToString(), plineName = a["PLINE_NAME"].ToString(), PROCESS_DESC = a["PROCESS_DESC"].ToString() })
- .Select(a => a.Key).ToList();
- for (int i = 0; i < plines.Count; i++)
- {
- DataRow dr = dtSource.NewRow();
- dr["CHK"] = bool.Parse(plines[i].chk);
- dr["PLINE_NAME"] = plines[i].plineName;
- dr["PROCESS_DESC"] = plines[i].PROCESS_DESC;
- dtSource.Rows.Add(dr);
- }
- foreach (var row in ultraGrid1.Rows)
- {
- foreach (var cell in row.Cells)
- {
- DataRow[] drItem = dt.Select("ITEM_CODE = '" + cell.Column.Tag + "' AND PLINE_NAME = '" + row.Cells["PLINE_NAME"].Value + "'");
- DataRow[] drPline = dt.Select("PLINE_NAME = '" + row.Cells["PLINE_NAME"].Value + "'");
- if (cell.Column.Key.Contains("PROPORTION"))
- {
- cell.Value = drItem[0]["PROPORTION"];
- }
- else if (cell.Column.Key.Contains("PERCENT"))
- {
- cell.Value = drItem[0]["PERCENT"];
- }
- else if (cell.Column.Key == "PLINE_NAME")
- {
- cell.Tag = drPline[0]["PLINE_CODE"];
- }
- }
- }
- ultraGrid1.UpdateData();
- //ultraGrid1.EndUpdate();
- }
- #endregion
- #region 事件
- /// 选择事件
- /// <summary>
- /// 选择事件
- /// </summary>
- private void ultraGrid1_CellChange(object sender, CellEventArgs e)
- {
- ultraGrid1.UpdateData();
- if (e.Cell.Column.Key == "CHK")
- {
- GridEdite(e.Cell.Row);
- }
- }
- /// 选择判断
- /// <summary>
- /// 选择判断
- /// </summary>
- private void GridEdite(UltraGridRow row)
- {
- if (row.GetValue("CHK") == "True")
- {
- foreach (UltraGridCell cell in row.Cells)
- {
- if (cell.Column.CellActivation == Activation.AllowEdit)
- {
- cell.Activation = Activation.AllowEdit;
- }
- }
- }
- else
- {
- foreach (UltraGridCell cell in row.Cells)
- {
- if (cell.Column.Key == "CHK") continue;
- if (cell.Column.CellActivation == Activation.AllowEdit)
- {
- cell.Activation = Activation.ActivateOnly;
- }
- }
- }
- }
- /// 产线选择事件
- /// <summary>
- /// 产线选择事件
- /// </summary>
- private void ultraCheckEditor1_CheckedChanged(object sender, EventArgs e)
- {
- ultraTextEditor1.Enabled = this.ultraCheckEditor1.Checked;
- }
- #endregion
- }
- }
|