| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Windows.Forms;
- using Core.Mes.Client.Comm.Server;
- using Core.Mes.Client.Comm.Tool;
- using Core.StlMes.Client.LgClassModel;
- using CoreFS.CA06;
- using Infragistics.Win;
- using Infragistics.Win.UltraWinGrid;
- namespace Core.StlMes.Client.LgCommon
- {
- public partial class ucResAdditiveProcess : UserControl
- {
- public ucResAdditiveProcess()
- {
- InitializeComponent();
- ClsControlPack.RefreshAndAutoSize(ugData);
- }
- private OpeBase _ob;
- private DataTable columns;
- private string _stove = "";
- private string _station = "";
- private string _disposalTime = "";
- private LG_PROCESS _process;
- private bool flag = false;
- private bool _changed = false;
- public void SetOb(OpeBase ob)
- {
- _ob = ob;
- }
- public bool Changed
- {
- get
- {
- return _changed ? _changed : ugData.Rows.Count >= 0 && ugData.Rows.Any(p => (bool)p.Cells["NewRow"].Value);
- }
- }
- public bool CanSave
- {
- get
- {
- try
- {
- ugData.UpdateData();
- }
- catch (Exception)
- {
- return false;
- }
- return ugData.Rows.Count<=0 || ugData.Rows.All(p => (bool)p.Cells["Valid"].Value);
- }
- }
- public bool SaveDate()
- {
- if (_ob == null) return false;
- if (!Changed || dataTable1.Rows.Count<=0) return true;
- if (!CanSave)
- {
- MessageBox.Show(@"添加料过程数据不正确,无法保存添加料过程数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return true;
- }
- var data = dataTable1.AsEnumerable().Select(p =>
- {
- List<Dictionary<string, object>> datas = new List<Dictionary<string, object>>();
- for (int i = 3; i < p.ItemArray.Length; i++)
- {
- if (p[i] == DBNull.Value || p[i] == null || p[i].ToString().Trim()=="") continue;
- datas.Add(new Dictionary<string, object>()
- {
-
- { "Code", dataTable1.Columns[i].ColumnName },
- { "Value" , p[i] }
- });
- }
- return new Dictionary<string, object>()
- {
- { dataTable1.Columns[0].ColumnName, p[0] },
- { dataTable1.Columns[1].ColumnName, (p[1]==null|| string.IsNullOrEmpty(p[1].ToString()))?" ":p[1] },
- { dataTable1.Columns[2].ColumnName, p[2] },
- { "Data",datas }
- };
- }
- ).ToList();
- try
- {
- ServerHelper.SetData("Core.LgMes.Server.LgDeviceManager.StlAdditive.SaveAdditivesProcess", new object[] { data,_process.ToString(), _stove,
- _station,_disposalTime }, _ob);
- return true;
- }
- catch (Exception ex)
- {
- return false;
- }
- }
- public void SetData(LG_PROCESS PROCESS,string Stove, string station, string disposalTime)
- {
- _stove = Stove;
- _station = station;
- _disposalTime = disposalTime;
- _process = PROCESS;
- Refresh();
- }
- private void Refresh()
- {
- if (_ob == null) return;
- dataTable1.Rows.Clear();
- DataTable datas =
- ServerHelper.GetData(
- "Core.LgMes.Server.LgDeviceManager.StlAdditive.GetAdditivesProcess",
- new object[]
- {
- _process.ToString(),
- _stove,
- _station,
- _disposalTime
- }, _ob);
- if (datas==null ||datas.Rows.Count <= 0) return;
- foreach (DataRow row in datas.Rows)
- {
- var newRow = dataTable1.NewRow();
- newRow["JMDATE"] = row["JMDATE"];
- newRow["HOPPERNUMID"] = row["HOPPERNUMID"];
- newRow["MATERIELTYPE"] = row["MATERIELTYPE"];
- string code = row["MATERIELCODE"].ToString();
- string value = row["JMWGT"].ToString();
- if(!dataTable1.Columns.Contains(code)) continue;
- newRow[code] = value;
- if (CheckRowValid(newRow))
- {
- dataTable1.Rows.Add(newRow);
- var tempRow = ugData.Rows[ugData.Rows.Count - 1];
- tempRow.Cells["Valid"].Value = true;
- }
- }
-
- if (dataTable1.Rows.Count >= 0)
- {
- ClsControlPack.RefreshAndAutoSize(ugData);
- }
- _changed = false;
- }
- public void RefeshColumns(string strStationCode)
- {
- ugData.BeginUpdate();
- bool bSuccess;
- string strMsg;
- DataSet ds = ClsDataAccessPack.GetData("AddColumns.Select", new ArrayList { strStationCode, strStationCode }, out bSuccess, out strMsg, _ob);
- if (!bSuccess || ds.Tables.Count <= 0) return;
- columns = ds.Tables[0];
- ValueList vlist = new ValueList();
- foreach (DataRow row in columns.Rows)
- {
- string TypeCode = row["ITEM_TYPE"].ToString();
- string TypeName = row["ITEM_TYPE_NAME"].ToString();
- if (vlist.FindByDataValue(TypeCode) == null)
- {
- vlist.ValueListItems.Add(TypeCode, TypeName);
- }
- }
- ClsControlPack.SetGridValuelist(ref ugData, "MATERIELTYPE", ref vlist);
-
- while (this.dataTable1.Columns.Count > 3)
- {
- this.dataTable1.Columns.RemoveAt(3);
- }
- try
- {
- string strCode = "", strName = "";
- for (int i = 0; i < columns.Rows.Count; i++)
- {
- strCode = columns.Rows[i]["ITEM_CODE"].ToString();
- strName = columns.Rows[i]["ITEM_NAME"].ToString();
- if (string.IsNullOrEmpty(strName)) continue;
- if (!dataTable1.Columns.Contains(strCode))
- {
- DataColumn column = new DataColumn(strCode, typeof(string)) { Caption = strName };
- this.dataTable1.Columns.Add(column);
- ugData.DisplayLayout.Bands[0].Columns[strCode].CellAppearance.TextVAlign = VAlign.Middle;
- ugData.DisplayLayout.Bands[0].Columns[strCode].CellAppearance.TextHAlign = HAlign.Right;
- }
- }
- for (int i = 3; i < dataTable1.Columns.Count; i++)
- {
- List<string> codes = columns.AsEnumerable().Select(p => p["ITEM_CODE"].ToString()).Distinct().ToList();
- if (!codes.Contains(dataTable1.Columns[i].ColumnName))
- {
- dataTable1.Columns.RemoveAt(i--);
- }
-
- }
- }
- catch { }
- finally
- {
- try
- {
- SetAdditiveDataSummary();
-
- ugData.EndUpdate();
- _changed = false;
- }
- catch { }
- }
- }
- //物料
- public void SetAdditiveProcess(string strStationCode,string strDisposalTime)
- {
- bool bSuccess;
- string strMsg;
- DataSet ds = ClsDataAccessPack.GetData("AddColumns.Select", new ArrayList { strStationCode, strStationCode }, out bSuccess, out strMsg, _ob);
- if (!bSuccess || ds.Tables.Count<=0) return;
- ugData.BeginUpdate();
- columns = ds.Tables[0];
- ValueList vlist = new ValueList();
- foreach (DataRow row in columns.Rows)
- {
- string TypeCode = row["ITEM_TYPE"].ToString();
- string TypeName = row["ITEM_TYPE_NAME"].ToString();
- if (vlist.FindByDataValue(TypeCode)==null)
- {
- vlist.ValueListItems.Add(TypeCode, TypeName);
- }
- }
- ClsControlPack.SetGridValuelist(ref ugData, "MATERIELTYPE", ref vlist);
- this.dataTable1.Rows.Clear();
- while (this.dataTable1.Columns.Count>3)
- {
- this.dataTable1.Columns.RemoveAt(3);
- }
- try
- {
- string strCode = "", strName = "";
- for (int i = 0; i < columns.Rows.Count; i++)
- {
- strCode = columns.Rows[i]["ITEM_CODE"].ToString();
-
- strName = columns.Rows[i]["ITEM_NAME"].ToString();
- if(string.IsNullOrEmpty(strName)) continue;
- if (!dataTable1.Columns.Contains(strCode))
- {
- DataColumn column = new DataColumn(strCode, typeof(string)) {Caption = strName};
- this.dataTable1.Columns.Add(column);
- ugData.DisplayLayout.Bands[0].Columns[strCode].CellAppearance.TextVAlign = VAlign.Middle;
- ugData.DisplayLayout.Bands[0].Columns[strCode].CellAppearance.TextHAlign = HAlign.Right;
- }
- }
-
-
- }
- catch { }
- finally
- {
- try
- {
- // UltraGridRow row = ultraGrid1.DisplayLayout.Bands[0].AddNew();
- //DataRow drFL= dataTable1.NewRow();
- // drFL[0] = "配料方案";
- // row.Cells[0].Value = "配料方案";
- //this.dataTable1.Rows.Add(drFL);
-
- SetAdditiveDataSummary();
- ugData.EndUpdate();
- _changed = false;
- }
- catch { }
- }
- }
- private void SetAdditiveDataSummary()
- {
- try
- {
- UltraGridBand band = this.ugData.DisplayLayout.Bands[0];
- band.Summaries.Clear();
- SummarySettings summary = band.Summaries.Add(SummaryType.Count, band.Columns[0]);
- summary.SummaryDisplayArea = SummaryDisplayAreas.TopFixed;
- summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
- summary.Appearance.ForeColor = Color.DarkBlue;
- summary.Appearance.BackColor = Color.White;
- summary.Appearance.TextVAlign = VAlign.Middle;
- summary.Appearance.TextHAlign = HAlign.Center;
- summary.Appearance.FontData.Bold = DefaultableBoolean.True;
- summary.DisplayFormat = "投料合计:";
-
-
- if (columns != null && columns.Rows.Count > 0)
- {
- List<string> codes = columns.AsEnumerable().Select(p => p["ITEM_CODE"].ToString()).Distinct().ToList();
- for (int idx = 0; idx < codes.Count; idx++)
- {
- try
- {
- summary = band.Summaries.Add(SummaryType.Sum, band.Columns[codes[idx]]);
- summary.SummaryDisplayArea = SummaryDisplayAreas.TopFixed;
- summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
- summary.Appearance.FontData.Bold = DefaultableBoolean.True;
- summary.DisplayFormat = " {0:#####.###}";
- summary.Appearance.TextVAlign = VAlign.Middle;
- summary.Appearance.TextHAlign = HAlign.Right;
- summary.Appearance.ForeColor = Color.DarkBlue;
- summary.Appearance.BackColor = Color.White;
- }
- catch { }
- }
- }
- band.Override.SummaryFooterCaptionVisible = DefaultableBoolean.False;
- }
- catch { }
- }
-
-
- private void tsmAdd_Click(object sender, EventArgs e)
- {
- if (dataTable1.Columns.Count <= 3)
- {
- MessageBox.Show("请先配置添加料");
- return;
- }
- var dr1 = dataTable1.NewRow();
- dr1["JMDATE"] = DateTime.Now;
- dataTable1.Rows.Add(dr1);
- var tempRow = ugData.Rows[ugData.Rows.Count - 1];
- tempRow.Appearance.BackColor = Color.Orange;
- tempRow.Cells["Valid"].Value = false;
- if (dataTable1.Rows.Count <= 1)
- {
- ClsControlPack.RefreshAndAutoSize(ugData);
- }
- }
- private void tsmDelete_Click(object sender, EventArgs e)
- {
- if (ugData.ActiveRow == null)
- {
- MessageBox.Show("请选中一行再进行删除");
- return;
- }
- if (!(bool)ugData.ActiveRow.Cells["NewRow"].Value)
- {
- _changed = true;
- }
- dataTable1.Rows.RemoveAt(ugData.ActiveRow.Index);
- }
- private void ugTem_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (ugData.ActiveRow != null)
- {
- try
- {
- ugData.UpdateData();
- }
- catch (Exception)
- {
-
- }
-
-
- }
- }
-
- private void ugTem_BeforeRowsDeleted(object sender, Infragistics.Win.UltraWinGrid.BeforeRowsDeletedEventArgs e)
- {
- if (e.Rows != null)
- {
- StlTempsamplingEntity StlTempsamplingEntity = e.Rows[0].ListObject as StlTempsamplingEntity;
- if (StlTempsamplingEntity != null && !StlTempsamplingEntity.NewRow)
- {
- _changed = true;
- }
- }
- }
- private void ugTem_ClickCellButton(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
- {
- e.Cell.Value = DateTime.Now;
- }
- private void ugTem_AfterCellUpdate(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
- {
- var row = ugData.ActiveRow;
- if (row != null)
- {
- if (!CheckRowValid(row)
- )
- {
- row.Appearance.BackColor = Color.Orange;
- row.Cells["Valid"].Value = false;
- }
- else
- {
- row.Appearance.BackColor = Color.LightGreen;
- row.Cells["Valid"].Value = true;
- }
- if (!(bool)row.Cells["NewRow"].Value)
- {
- _changed = true;
- }
- }
- //StlTempsamplingEntity StlTempsamplingEntity = ugData.ActiveRow.ListObject as StlTempsamplingEntity;
- //if (StlTempsamplingEntity != null && StlTempsamplingEntity.NewRow)
- //{
- // if (StlTempsamplingEntity.Startdate == null || StlTempsamplingEntity.Enddate == null ||
- // StlTempsamplingEntity.Startdate > StlTempsamplingEntity.Enddate
- // || StlTempsamplingEntity.Samplingname == ""
- // || StlTempsamplingEntity.Samplingvalue == null
- // )
- // {
- // ugTem.Rows[ugTem.ActiveRow.Index].Appearance.BackColor = Color.Orange;
- // }
- // else
- // {
- // ugTem.Rows[ugTem.ActiveRow.Index].Appearance.BackColor = Color.LightGreen;
- // }
- //}
- }
- private bool CheckRowValid(UltraGridRow row)
- {
- if (row.Cells["JMDATE"].Value == null
- || row.Cells["MATERIELTYPE"].Value == null || row.Cells["MATERIELTYPE"].Value == DBNull.Value) return false;
- /* row.Cells["JMDATE"].Value == null
- || row.Cells["MATERIELTYPE"].Value == null*/
- if (row.Cells.Count <= 5) return false;
- for (int i = 3; i < row.Cells.Count-2; i++)
- {
- double data;
- if (row.Cells[i].Value != null && double.TryParse(row.Cells[i].Value.ToString(), out data))
- {
- return true;
- }
- }
- return false;
- }
- private bool CheckRowValid(DataRow row)
- {
- if (row["JMDATE"] == null
- || row["MATERIELTYPE"] == null) return false;
-
- if (row.ItemArray.Length <= 3) return false;
- for (int i = 3; i < row.ItemArray.Length; i++)
- {
- if( row[i]!=null && !string.IsNullOrEmpty(row[i].ToString()))
- {
- return true;
- }
- }
- return false;
- }
- private void ugTem_MouseDown(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Right)
- {
- UIElement uieOver = ugData.DisplayLayout.UIElement.ElementFromPoint(new Point(e.X, e.Y));
- if (uieOver != null)
- {
- UltraGridRow ugrOver = uieOver.GetContext(typeof(UltraGridRow), true) as UltraGridRow;
- ugData.ActiveRow = ugrOver;
- }
- }
- }
- private void ugData_CellChange(object sender, CellEventArgs e)
- {
- if (ugData.ActiveRow != null)
- {
- try
- {
- ugData.UpdateData();
- }
- catch (Exception)
- {
- }
- }
- if (e.Cell.Column.Key.Equals("MATERIELTYPE", StringComparison.CurrentCultureIgnoreCase))
- {
- for (int i = 3; i < e.Cell.Row.Cells.Count; i++)
- {
- var cell = e.Cell.Row.Cells[i];
- cell.IgnoreRowColActivation = true;
- if (cell.Activation == Activation.ActivateOnly)
- {
- cell.Value = null;
- }
- }
- }
- }
- private void ugData_InitializeRow(object sender, InitializeRowEventArgs e)
- {
- string type = e.Row.Cells["MATERIELTYPE"].Value.ToString();
- if (type == "") return;
- List<string> data =
- columns.AsEnumerable()
- .Where(p => p["ITEM_TYPE"].ToString() == type)
- .Select(p => p["ITEM_CODE"].ToString())
- .ToList();
- for (int i =3; i < e.Row.Cells.Count; i++)
- {
- var cell = e.Row.Cells[i];
- cell.IgnoreRowColActivation = true;
- if (data.Contains(cell.Column.Key))
- {
- cell.Activation = Activation.AllowEdit;
- cell.Appearance.ResetBackColor();
- cell.IgnoreRowColActivation = false;
- }
- else
- {
- cell.Activation = Activation.ActivateOnly;
- cell.Appearance.BackColor = Color.LightGray;
- cell.IgnoreRowColActivation = true;
- }
- }
- }
- }
- }
|