| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113 |
- using System;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Windows.Forms;
- using Core.StlMes.Client.LgClassModel;
- using CoreFS.CA06;
- using Infragistics.Win;
- using Infragistics.Win.Misc;
- using Infragistics.Win.UltraWinGrid;
- //using Core.Mes.Client.Comm;
- using System.Collections;
- using Core.Mes.Client.Comm;
- using Core.Mes.Client.Comm.Server;
- namespace Core.StlMes.Client.LgCommon
- {
- public delegate void SetHopperHandler(); //设置料仓后调用控件的SetHopperInfo
- /* //##################################################################################################
- * 名称:加料公用控件(大部分功能直接在设计器属性字段设置)
- *
- * 作者:肖桦军
- *
- * 完成日期:2012-10-09
- *
- * 关于调用:
- *
- * 1、在窗体上拖入此控件,设置相关属性(料仓个数、显示参数)
- *
- * 2、在窗体构造函数或者装载事件设置 ob、DEVICE_POSITION 属性
- *
- * 3、在设计器或者代码中(构造函数或者FormLoad)设置MtrlCategory、HpprCategory 属性
- *
- * 4、在构造函数或者窗体装载事件中设置SetHopper代理(处理设置料仓后刷新显示)
- *
- * 5、在窗体SetData线程中更新 HeatProcessNo 属性(实时的处理信息)
- *
- * 6、在窗体SetData线程中调用SetAdditiveData()填充数据
- */
- //#####################################################################################################
-
- public partial class ucAdditive : UserControl
- {
- private string _Caption = ""; //显示标题
- private int _HopperNum = 20; //料斗数目
- private int _ItemsPerRow = 2; //每行显示料斗数目
- private bool _ExPanded = true; //是否展开
- private bool _Expandable = false; //是否可收缩
- private int _ExPandedHeight = 0; //展开高度
- private bool _Editable = false; //数值可以修改
- private bool _ShowCellButton = false; //显示编辑区域按钮
- private UIElementBorderStyle _BorderStyle = UIElementBorderStyle.InsetSoft;
- private int _ZoneValueWidth = 72; //料斗数值框宽度
- private int _ZoneCaptionWidth = 72; //料斗标签框宽度
- private int _VerticalSpacing = 1; //料斗垂直间距
- private int _HorizontalSpacing = 1; //料斗水平间距
- private int _LeftSpacing = 1; //料斗区域左边距
- private int _RightSpacing = 1; //料斗区域右边距
- private int _TopSpacing = 1; //料斗区域顶距
- private int _BottomSpacing = 1; //料斗区域底距
- private string _DEVICE_POSITION = ""; //设备位置
- private string _HeatProcessNo = ""; //实时加热处理号
- private OpeBase _ob;
- private MaterialCategory _MtrlCategory = MaterialCategory.FL;
- private HopperCategory _HpprCategory = HopperCategory.Automatic;
- public SetHopperHandler SetHopper = null; //设置料仓后调用控件的SetHopperInfo
- #region 属性
- /// <summary>
- /// 设备位置
- /// </summary>
- [Description("设备位置")]
- public string DEVICE_POSITION
- {
- get { return _DEVICE_POSITION; }
- set { if (value != _DEVICE_POSITION) _DEVICE_POSITION = value; }
- }
- [Browsable(false)]
- public OpeBase ob
- {
- get { return _ob; }
- set { if (value != _ob) _ob = value; }
- }
- /// <summary>
- /// 实时加热处理号
- /// </summary>
- [Description("实时加热处理号")]
- [Browsable(false)]
- public string HeatProcessNo
- {
- get { return _HeatProcessNo; }
- set { if (value != _HeatProcessNo) _HeatProcessNo = value; }
- }
- /// <summary>
- /// 物料类别
- /// </summary>
- [Description("物料类别")]
- public MaterialCategory MtrlCategory
- {
- get { return _MtrlCategory; }
- set { if (value != _MtrlCategory) _MtrlCategory = value; }
- }
- /// <summary>
- /// 投料分类
- /// </summary>
- [Description("投料分类")]
- public HopperCategory HpprCategory
- {
- get { return _HpprCategory; }
- set { if (value != _HpprCategory) _HpprCategory = value; }
- }
- /// <summary>
- /// 显示标题
- /// </summary>
- [Description("显示标题")]
- public string Caption
- {
- get { return _Caption; }
- set
- {
- if (!value.Equals(_Caption))
- {
- _Caption = value;
- MainContainer.Text = value;
- }
- }
- }
- /// <summary>
- /// 料斗数目(10 - 100)
- /// </summary>
- [Description("料斗数目(10 - 100)")]
- public int HopperNum
- {
- get { return _HopperNum; }
- set
- {
- if (value < 10) value = 10;
- else if (value > 100) value = 100;
- if (value != _HopperNum)
- {
- _HopperNum = value;
- if (_ItemsPerRow > value) _ItemsPerRow = value;
- this.ResetLayout();
- }
- }
- }
- /// <summary>
- /// 每行显示料斗数目(1 - HopperNum)
- /// </summary>
- [Description("料斗数目(每行显示料斗数目(1 - HopperNum))")]
- public int ItemsPerRow
- {
- get { return _ItemsPerRow; }
- set
- {
- if (value < 1) value = 1;
- else if (value > _HopperNum) value = _HopperNum;
- if (value != _ItemsPerRow)
- {
- _ItemsPerRow = value;
- this.ResetLayout();
- }
- }
- }
- /// <summary>
- /// 展开状态
- /// </summary>
- [Description("展开状态")]
- public bool ExPanded
- {
- get { return _ExPanded; }
- set
- {
- if (!value && !_Expandable) value = true;
- if (value != _ExPanded)
- {
- _ExPanded = value;
- MainContainer.Expanded = value;
- }
- }
- }
- /// <summary>
- /// 是否可收缩
- /// </summary>
- [Description("是否可收缩")]
- public bool Expandable
- {
- get { return _Expandable; }
- set
- {
- if (value != _Expandable)
- {
- _Expandable = value;
- if (!value)
- {
- MainContainer.ExpansionIndicator = GroupBoxExpansionIndicator.None;
- MainContainer.HeaderClickAction = GroupBoxHeaderClickAction.None;
- ExPanded = true;
- }
- else
- {
- MainContainer.ExpansionIndicator = GroupBoxExpansionIndicator.Far;
- MainContainer.HeaderClickAction = GroupBoxHeaderClickAction.ToggleExpansion;
- if (string.IsNullOrEmpty(_Caption)) Caption = "投料类别";
- if (value) _ExPanded = MainContainer.Expanded;
- }
- MainContainer.Invalidate();
- }
- }
- }
- [Description("展开高度")]
- public int ExPandedHeight
- {
- get { return _ExPandedHeight; }
- }
- /// <summary>
- /// 数值可以修改
- /// </summary>
- [Description("数值可以修改")]
- public bool Editable
- {
- get { return _Editable; }
- set
- {
- if (value != _Editable)
- {
- if (!value)
- {
- ShowCellButton = false;
- }
- _Editable = value;
- this.SetEditable(value);
- }
- }
- }
- /// <summary>
- /// 显示编辑区域按钮
- /// </summary>
- [Description("显示编辑区域按钮")]
- public bool ShowCellButton
- {
- get { return _ShowCellButton; }
- set
- {
- if (!_Editable && value) value = false;
- if (value != _ShowCellButton)
- {
- _ShowCellButton = value;
- this.SetEditButton(value);
- }
- }
- }
- /// <summary>
- /// 料斗数值框宽度(20 - 200)
- /// </summary>
- [Description("料斗数值框宽度(20 - 200)")]
- public int ZoneValueWidth
- {
- get { return _ZoneValueWidth; }
- set
- {
- if (value < 20) value = 20;
- else if (value > 200) value = 200;
- if (value != _ZoneValueWidth)
- {
- _ZoneValueWidth = value;
- this.ResetLayout();
- }
- }
- }
- /// <summary>
- /// 料斗标签框宽度(20 - 200)
- /// </summary>
- [Description("料斗标签框宽度(20 - 200)")]
- public int ZoneCaptionWidth
- {
- get { return _ZoneCaptionWidth; }
- set
- {
- if (value < 20) value = 20;
- else if (value > 200) value = 200;
- if (value != _ZoneCaptionWidth)
- {
- _ZoneCaptionWidth = value;
- this.ResetLayout();
- }
- }
- }
- /// <summary>
- /// 料斗水平间距(0 - 100)
- /// </summary>
- [Description("料斗水平间距(0 - 100)")]
- public int HorizontalSpacing
- {
- get { return _HorizontalSpacing; }
- set
- {
- if (value < 0) value = 0;
- else if (value > 100) value = 100;
- if (value != _HorizontalSpacing)
- {
- _HorizontalSpacing = value;
- this.ResetLayout();
- }
- }
- }
- /// <summary>
- /// 料斗垂直间距(0 - 100)
- /// </summary>
- [Description("料斗垂直间距(0 - 100)")]
- public int VerticalSpacing
- {
- get { return _VerticalSpacing; }
- set
- {
- if (value < 0) value = 0;
- else if (value > 100) value = 100;
- if (value != _VerticalSpacing)
- {
- _VerticalSpacing = value;
- this.ResetLayout();
- }
- }
- }
- /// <summary>
- /// 料斗区域左边距(0 - 100)
- /// </summary>
- [Description("料斗区域左边距(0 - 100)")]
- public int LeftSpacing
- {
- get { return _LeftSpacing; }
- set
- {
- if (value < 0) value = 0;
- else if (value > 100) value = 100;
- if (value != _LeftSpacing)
- {
- _LeftSpacing = value;
- this.ResetLayout();
- }
- }
- }
- /// <summary>
- /// 料斗区域右边距(0 - 100)
- /// </summary>
- [Description("料斗区域右边距(0 - 100)")]
- public int RightSpacing
- {
- get { return _RightSpacing; }
- set
- {
- if (value < 0) value = 0;
- else if (value > 100) value = 100;
- if (value != _RightSpacing)
- {
- _RightSpacing = value;
- this.ResetLayout();
- }
- }
- }
- /// <summary>
- /// 料斗区域顶距(0 - 100)
- /// </summary>
- [Description("料斗区域顶距(0 - 100)")]
- public int TopSpacing
- {
- get { return _TopSpacing; }
- set
- {
- if (value < 0) value = 0;
- else if (value > 100) value = 100;
- if (value != _TopSpacing)
- {
- _TopSpacing = value;
- this.ResetLayout();
- }
- }
- }
- /// <summary>
- /// 料斗区域底距(0 - 100)
- /// </summary>
- [Description("料斗区域底距(0 - 100)")]
- public int BottomSpacing
- {
- get { return _BottomSpacing; }
- set
- {
- if (value < 0) value = 0;
- else if (value > 100) value = 100;
- if (value != _BottomSpacing)
- {
- _BottomSpacing = value;
- this.ResetLayout();
- }
- }
- }
- [Description("边框样式")]
- public new UIElementBorderStyle BorderStyle
- {
- get { return _BorderStyle; }
- set
- {
- if (value != _BorderStyle)
- {
- _BorderStyle = value;
- MidContainer.BorderStyle = value;
- }
- }
- }
- #endregion
- #region 构造函数
- public ucAdditive()
- {
- InitializeComponent();
- this.Caption = "投料类别";
- this.SetDelegate();
- this.ResetLayout();
- }
- #endregion
- #region 重新生成框架
- private void ResetSource()
- {
- try
- {
- ultraDataSource1.Rows.Clear();
- ultraDataSource1.Band.Columns.Clear();
- }
- catch { }
- }
- private void ResetLayout()
- {
- try
- {
- ultraGrid1.BeginUpdate();
- this.ResetSource();
- for (int i = 0; i < _HopperNum; i++)
- {
- ultraDataSource1.Band.Columns.Add(Convert.ToString(i + 1), typeof(string));
- }
- int iOriginX = 0, iOriginY = 0;
- for (int i = 0; i < _HopperNum; i++)
- {
- try
- {
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].CellActivation = (_Editable ? Activation.AllowEdit : Activation.NoEdit);
- if (_ShowCellButton) ultraGrid1.DisplayLayout.Bands[0].Columns[i].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.EditButton;
- else ultraGrid1.DisplayLayout.Bands[0].Columns[i].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Default;
- }
- catch { }
- try
- {
- int iVerCount = (int)Math.Ceiling((float)_HopperNum / (float)_ItemsPerRow);
- iOriginX = i % _ItemsPerRow;
- iOriginY = i / _ItemsPerRow;
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].CellAppearance.TextVAlign = VAlign.Middle;
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Appearance.TextHAlign = HAlign.Left;
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Appearance.TextVAlign = VAlign.Middle;
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Caption = "";
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Tag = "";
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Tag = ultraGrid1.DisplayLayout.Bands[0].Columns[i].Key;
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.SpanX = 2;
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.SpanY = 1;
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.OriginX = iOriginX * 2;
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.OriginY = iOriginY;
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.PreferredCellSize = new Size(_ZoneValueWidth, 0);
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.PreferredLabelSize = new Size(_ZoneCaptionWidth, 0);
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.LabelInsets.Left = (iOriginX == 0 ? _LeftSpacing : _HorizontalSpacing);
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.LabelInsets.Top = (iOriginY == 0 ? _TopSpacing : _VerticalSpacing);
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.CellInsets.Top = (iOriginY == 0 ? _TopSpacing : _VerticalSpacing);
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.CellInsets.Right = (iOriginX == _ItemsPerRow - 1 ? _RightSpacing : 0);
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.LabelInsets.Bottom = (iOriginY == iVerCount - 1 ? _BottomSpacing : 0);
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.CellInsets.Bottom = (iOriginY == iVerCount - 1 ? _BottomSpacing : 0);
- }
- catch { }
- }
- ClsControlPack.InitUltraDataSource(ultraDataSource1);
- }
- catch { }
- finally
- {
- ultraGrid1.EndUpdate();
- }
- }
- #endregion
- #region 窗体调用(填充加料数据、读取并显示料斗设置)
- /// <summary>
- /// 加料数据填充
- /// </summary>
- /// <param name="additiveBuffer">加料数据集</param>
- public void SetAdditiveData(CommonAdditive additiveBuffer)
- {
- try
- {
- string strKey = ""; //料仓ID
- string strCode = ""; //某个料仓配置的物料编码
- string strType = ""; //某个料仓配置的物料类别
- bool Added = false; //表示某个料仓是否有加料
- for (int idx = 0; idx < ultraDataSource1.Band.Columns.Count; idx++)
- {
- try
- {
- strKey = ultraDataSource1.Band.Columns[idx].Key;
- if (additiveBuffer == null)
- {
- ultraDataSource1.Rows[0][strKey] = "";
- continue;
- }
- strCode = Convert.ToString(ultraGrid1.DisplayLayout.Bands[0].Columns[strKey].Tag);
- strType = Convert.ToString(ultraGrid1.DisplayLayout.Bands[0].Columns[strKey].Header.Tag);
- if (strKey.Equals(strCode)) //料斗没有设置物料
- {
- ultraDataSource1.Rows[0][strKey] = "";
- continue;
- }
- for (int i = 0; i < additiveBuffer.hList.Count; i++)
- {
- JOB_COMMON_ADDITIVES addt = (JOB_COMMON_ADDITIVES)additiveBuffer.hList[i];
- if (_HpprCategory == HopperCategory.Automatic) //自动加料才判断物料类别
- {
- if (addt == null || addt.HOPPERNUMID != strKey || addt.JMTYPE != "1") continue; //加料类型为1表示自动加料、料仓号匹配
- if (addt.MATERIELTYPE != strType || addt.MATERIELCODE != strCode) continue; //物料类别、物料编码匹配
- if (_MtrlCategory == MaterialCategory.FL && addt.MATERIELTYPE != "FL") continue;
- if (_MtrlCategory == MaterialCategory.HJ && addt.MATERIELTYPE != "HJ") continue;
- if (_MtrlCategory == MaterialCategory.WS && addt.MATERIELTYPE != "WS") continue;
- if (_MtrlCategory == MaterialCategory.FL_HJ && addt.MATERIELTYPE != "FL" && addt.MATERIELTYPE != "HJ") continue;
- if (_MtrlCategory == MaterialCategory.FL_WS && addt.MATERIELTYPE != "FL" && addt.MATERIELTYPE != "WS") continue;
- if (_MtrlCategory == MaterialCategory.HJ_WS && addt.MATERIELTYPE != "HJ" && addt.MATERIELTYPE != "WS") continue;
- if (_MtrlCategory == MaterialCategory.FL_HJ_WS && addt.MATERIELTYPE != "FL" && addt.MATERIELTYPE != "HJ" && addt.MATERIELTYPE != "WS") continue;
- }
- else if (_HpprCategory == HopperCategory.Manual)
- {
- if (addt == null || addt.MATERIELTYPE != strType || addt.MATERIELCODE != strCode || addt.JMTYPE != "2") continue;
- }
- try
- {
- ultraDataSource1.Rows[0][strKey] = addt.JMWGT;
- Added = true;
- break;
- }
- catch { }
- }
- }
- catch { }
- if (!Added) ultraDataSource1.Rows[0][strKey] = "";//没有加料
- else if (Added) Added = false; //清除加料标志,跳转到下一料仓
- }
- }
- catch { }
- finally
- {
- ultraGrid1.UpdateData();
- }
- }
- /// <summary>
- /// 读取并设置仓对应物料
- /// </summary>
- /// <param name="tblConfig">设置表</param>
- /// <param name="tblMaterial">物料基础表</param>
- public void SetHopperInfo(DataTable tblConfig, DataTable tblMaterial)
- {
- try
- {
- string HopperID = "";
- string Filter = "";
- DataRow[] rows = null;
- if (_HpprCategory == HopperCategory.Automatic)
- {
- if (_MtrlCategory == MaterialCategory.FL) Filter = "MATERIELTYPE = 'FL'";
- else if (_MtrlCategory == MaterialCategory.HJ) Filter = "MATERIELTYPE = 'HJ'";
- else if (_MtrlCategory == MaterialCategory.WS) Filter = "MATERIELTYPE = 'WS'";
- else if (_MtrlCategory == MaterialCategory.FL_HJ) Filter = "MATERIELTYPE = 'FL' or MATERIELTYPE = 'HJ'";
- else if (_MtrlCategory == MaterialCategory.FL_WS) Filter = "MATERIELTYPE = 'FL' or MATERIELTYPE = 'WS'";
- else if (_MtrlCategory == MaterialCategory.HJ_WS) Filter = "MATERIELTYPE = 'HJ' or MATERIELTYPE = 'WS'";
- else if (_MtrlCategory == MaterialCategory.FL_HJ_WS) Filter = "MATERIELTYPE = 'FL' or MATERIELTYPE = 'HJ' or MATERIELTYPE = 'WS'";
- else Filter = "MATERIELTYPE = '?'";
- Filter = "(" + Filter + ") and JMTYPE = '1'";
- for (int i = 0; i < ultraGrid1.DisplayLayout.Bands[0].Columns.Count; i++)
- {
- try
- {
- if (tblConfig == null || tblConfig.Rows.Count == 0)
- {
- try
- {
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Tag = ultraGrid1.DisplayLayout.Bands[0].Columns[i].Key;
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Caption = "";
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Tag = "";
- }
- catch { }
- break;
- }
- HopperID = ultraGrid1.DisplayLayout.Bands[0].Columns[i].Key;
- rows = tblConfig.Select(Filter + " and MSNUMID = '" + HopperID + "'");
- if (rows.Length > 0)
- {
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Tag = Convert.ToString(rows[0]["MATERIELCODE"]); //保存物料编码
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Caption = Convert.ToString(rows[0]["MATERIELFORSHORT"]); //保存物料简称
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Tag = Convert.ToString(rows[0]["MATERIELTYPE"]); //保存物料类别
- }
- else
- {
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Tag = ultraGrid1.DisplayLayout.Bands[0].Columns[i].Key;
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Caption = "";
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Tag = "";
- }
- }
- catch { }
- }
- }
- else if (_HpprCategory == HopperCategory.Manual)
- {
- if (tblConfig == null || tblConfig.Rows.Count == 0 || tblMaterial == null)
- {
- for (int i = 0; i < ultraGrid1.DisplayLayout.Bands[0].Columns.Count; i++)
- {
- try
- {
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Tag = ultraGrid1.DisplayLayout.Bands[0].Columns[i].Key;
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Caption = "";
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Tag = "";
- }
- catch { }
- }
- }
- else
- {
- string strConfig = Convert.ToString(tblConfig.Rows[0]["CONFGCODE"]).Trim();
- string[] strCode = strConfig.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < ultraGrid1.DisplayLayout.Bands[0].Columns.Count; i++)
- {
- try
- {
- if (i >= strCode.Length)
- {
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Tag = ultraGrid1.DisplayLayout.Bands[0].Columns[i].Key;
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Caption = "";
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Tag = "";
- }
- else
- {
- rows = tblMaterial.Select("MATERIELCODE = '" + strCode[i].Trim() + "'");
- if (rows.Length > 0)
- {
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Tag = Convert.ToString(rows[0]["MATERIELCODE"]); //保存物料编码
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Caption = Convert.ToString(rows[0]["MATERIELFORSHORT"]); //保存物料简称
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Tag = Convert.ToString(rows[0]["MATERIELTYPE"]); //保存物料类别
- }
- else
- {
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Tag = ultraGrid1.DisplayLayout.Bands[0].Columns[i].Key;
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Caption = "";
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Tag = "";
- }
- }
- }
- catch { }
- }
- }
- }
- }
- catch { }
- }
- public void ResetData()
- {
- ClsControlPack.ResetUltraDataSource(ultraDataSource1);
- }
- #endregion
- #region 相关属性设置响应
- private void SetEditable(bool Editable)
- {
- try
- {
- for (int i = 0; i < ultraGrid1.DisplayLayout.Bands[0].Columns.Count; i++)
- {
- try
- {
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].CellActivation = (Editable ? Activation.AllowEdit : Activation.NoEdit);
- }
- catch { }
- }
- }
- catch { }
- }
- private void SetEditButton(bool ShowEditButton)
- {
- try
- {
- for (int i = 0; i < ultraGrid1.DisplayLayout.Bands[0].Columns.Count; i++)
- {
- try
- {
- if (ShowEditButton)
- {
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.EditButton;
- }
- else
- {
- ultraGrid1.DisplayLayout.Bands[0].Columns[i].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Default;
- }
- }
- catch { }
- }
- }
- catch { }
- }
- #endregion
- #region 事件
- private void SetDelegate()
- {
- this.Resize += new System.EventHandler(this.ucAdditive_Resize);
- this.MainContainer.ExpandedStateChanged += new System.EventHandler(this.ExpandedStateChanged);
- this.ultraGrid1.DoubleClickHeader += new Infragistics.Win.UltraWinGrid.DoubleClickHeaderEventHandler(this.ultraGrid1_DoubleClickHeader);
- this.ultraGrid1.DoubleClickCell += new Infragistics.Win.UltraWinGrid.DoubleClickCellEventHandler(this.ultraGrid1_DoubleClickCell);
- this.ultraGrid1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ultraGrid1_KeyDown);
- this.ultraGrid1.ClickCellButton += new Infragistics.Win.UltraWinGrid.CellEventHandler(this.ultraGrid1_ClickCellButton);
- }
- private void ucAdditive_Resize(object sender, EventArgs e)
- {
- try
- {
- if (_Expandable && !_ExPanded)
- {
- this.Height = MainContainer.Height; //可收缩,处于收缩状态,不允许修改大小
- if (_ExPandedHeight == 0 && this.Parent != null) _ExPandedHeight = this.Parent.Height;
- }
- else if (_Expandable && _ExPanded) _ExPandedHeight = this.Height; //可收缩,处于展开状态,记录高度变化
- else if (!Expandable) _ExPandedHeight = this.Height; //不可收缩,记录高度变化
- }
- catch { }
- }
- private void ExpandedStateChanged(object sender, EventArgs e)
- {
- try
- {
- ExPanded = MainContainer.Expanded;
- if (MainContainer.Expanded) this.Height = _ExPandedHeight;
- else this.Height = MainContainer.Height;
- }
- catch { }
- }
- private void ultraGrid1_DoubleClickHeader(object sender, DoubleClickHeaderEventArgs e)
- {
- try
- {
- if (_HpprCategory == HopperCategory.Automatic)
- {
- frmSetHopper frm = new frmSetHopper(_DEVICE_POSITION, ob);
- frm.ShowDialog();
- if (this.SetHopper != null)
- this.Invoke(this.SetHopper);
- }
- else if (_HpprCategory == HopperCategory.Manual)
- {
- string strOriginal = ""; //原始物料编码
- if (Convert.ToString(e.Header.Column.Tag) != e.Header.Column.Key)
- strOriginal = Convert.ToString(e.Header.Column.Tag);
- string strName = Convert.ToString(e.Header.Caption); //物料名称
- frmSetMaterialName frm = new frmSetMaterialName(strName, "1", ob);
- frm.ShowDialog();
- if (frm.bChange)
- {
- string strMaterielCode = frm.m_szWLBM;
- try
- {
- ServerHelper.SetData("Core.LgMes.Server.LgDeviceManager.StlAdditive.UpdateInterFaceConfig",
- new object[]
- {
- new object[]
- {
- _DEVICE_POSITION, strOriginal, strMaterielCode
- }
- }, ob);
- if (this.SetHopper != null)
- this.Invoke(this.SetHopper);
- }
- catch (Exception ex)
- {
- if (ex is MESException)
- {
- }
- else
- MessageBox.Show("手投料物料配置失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- }
- catch { }
- }
- private void ultraGrid1_KeyDown(object sender, KeyEventArgs e)
- {
- try
- {
- if (!_Editable) return;
- if (e.KeyCode != Keys.Enter || string.IsNullOrEmpty(_HeatProcessNo)) return; //回车、有生产任务
- UltraGridCell cell = ultraGrid1.ActiveCell;
- if (ultraGrid1.Rows.Count == 0 || cell == null || cell.Row.Index != 0) return; //行数异常
- if (Convert.ToString(cell.Column.Tag) == cell.Column.Key) return; //没有设置物料编码
- if (string.IsNullOrEmpty(cell.Column.Header.Caption)) return; //无物料名称
- string Value = cell.Text.Trim(); //V6投料量
- if (string.IsNullOrEmpty(Value))
- {
- MessageBox.Show("请输入消耗量!\n如果需要清空数据,请输入原有消耗量的负数。(如加料量为800,要清空此数值,请输入-800然后确认!)", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- cell.Activated = true;
- return;
- }
- if (!ClsDataAccessPack.CheckNumValidate(Value))
- {
- MessageBox.Show("不是有效的数值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- ultraGrid1.PerformAction(UltraGridAction.EnterEditMode);
- cell.Activated = true;
- return;
- }
- string TableName = ClsBusinessPack.GetTableName(_HeatProcessNo.Substring(0, 1), TableSort.Feeding); //V1表名
- string MaterielCode = Convert.ToString(cell.Column.Tag); //V3物料编码
- string MaterielType = Convert.ToString(cell.Column.Header.Tag); //V4物料类型
- string HopperID = cell.Column.Key; //V8料仓编号
- string strMsg = "";
- bool bSuccess = ClsBusinessPack.SaveAdditiveData(_HeatProcessNo, HopperID, MaterielType, MaterielCode, Value, _HpprCategory, out strMsg, ob);
- if (!bSuccess)
- {
- MessageBox.Show("数据保存失败!\n" + strMsg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- }
- else
- {
- ultraGrid1.PerformAction(UltraGridAction.ExitEditMode);
- }
- }
- catch { }
- }
- private void ultraGrid1_ClickCellButton(object sender, CellEventArgs e)
- {
- try
- {
- if (!_Editable || !_ShowCellButton || string.IsNullOrEmpty(_HeatProcessNo)) return;
- UltraGridCell cell = e.Cell;
- if (ultraGrid1.Rows.Count == 0 || cell == null || cell.Row.Index != 0) return; //行数异常
- if (Convert.ToString(cell.Column.Tag) == cell.Column.Key) return; //没有设置物料编码
- if (string.IsNullOrEmpty(cell.Column.Header.Caption)) return; //无物料名称
- frmInputDecimal frm = new frmInputDecimal(Convert.ToString(cell.Value));
- frm.Location = ClsControlPack.GetChildWindowLocation(frm.Size);
- if (frm.ShowDialog() == DialogResult.OK)
- {
- if (!frm.ValueChanged) return;
- string Value = frm.Value; //V6投料量
- if (string.IsNullOrEmpty(Value))
- {
- MessageBox.Show("请输入消耗量!\n如果需要清空数据,请输入原有消耗量的负数。(如加料量为800,要清空此数值,请输入-800然后确认!)", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- cell.Activated = true;
- return;
- }
- if (!ClsDataAccessPack.CheckNumValidate(Value))
- {
- MessageBox.Show("不是有效的数值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- ultraGrid1.PerformAction(UltraGridAction.EnterEditMode);
- cell.Activated = true;
- return;
- }
- string TableName = ClsBusinessPack.GetTableName(_HeatProcessNo.Substring(0, 1), TableSort.Feeding); //V1表名
- string MaterielCode = Convert.ToString(cell.Column.Tag); //V3物料编码
- string MaterielType = Convert.ToString(cell.Column.Header.Tag); //V4物料类型
- string HopperID = cell.Column.Key; //V8料仓编号
- string strMsg = "";
- bool bSuccess = ClsBusinessPack.SaveAdditiveData(_HeatProcessNo, HopperID, MaterielType, MaterielCode, Value, _HpprCategory, out strMsg, ob);
- if (!bSuccess)
- {
- MessageBox.Show("数据保存失败!\n" + strMsg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- }
- else
- {
- ultraGrid1.PerformAction(UltraGridAction.ExitEditMode);
- }
- }
- }
- catch { }
- }
- #endregion
- private void ultraGrid1_DoubleClickCell(object sender, DoubleClickCellEventArgs e)
- {
- try
- {
- if (_HeatProcessNo == "") return;
- string strOriginal = ""; //原始物料编码
- string HopperID = e.Cell.Column.Key.ToString(); //料斗号
- if (Convert.ToString(e.Cell.Column.Header.Column.Tag) != e.Cell.Column.Header.Column.Key)
- strOriginal = Convert.ToString(e.Cell.Column.Header.Column.Tag);
- if (strOriginal == "") return;
- string strName = Convert.ToString(e.Cell.Column.Header.Caption); //物料名称
- frmSelectWeight frm = new frmSelectWeight(ob);
- frm.HeatProcessNo = _HeatProcessNo;
- frm.MaterName = strName;
- frm.sWeight = e.Cell.Value.ToString();
- frm.ShowDialog();
- if (frm.flag)
- {
- string strErr = "";
- string strSqlID = "";
- //object[] sArgs = null;
- if (frm.Weight == "") return;
- //if (frm.isCancel)
- //{
- // strSqlID = "BofHJMater.Delete";
- // sArgs = new object[3];
- // sArgs[0] = frm.vProcessNo; //加热处理号
- // sArgs[1] = strOriginal; //物料编码
- // sArgs[2] = HopperID; //料斗号
- //}
- //else
- //{
- Hashtable ht = new Hashtable();
- strSqlID = "STL_JOB0015";
- ht.Add("I1", frm.vProcessNo); //加热处理号
- ht.Add("I2", _HeatProcessNo.Substring(5, 8)); //炉号
- ht.Add("I3", _HeatProcessNo.Substring(1, 2)); //岗位号
- ht.Add("I4", _HeatProcessNo.Substring(3, 2)); //处理次数
- ht.Add("I5", strOriginal); //物料编码
- ht.Add("I6", strName); //物料名称
- ht.Add("I7", frm.Weight); //物料重量
- ht.Add("I8", frm.VDate); //加料时间
- ht.Add("I9", HopperID); //料斗号
- ht.Add("I10", frm.Weightno); //计量单号
- ht.Add("I11", frm.isCancel?"2":"1"); //1为保存,2为取消
- ht.Add("O1", "");
- ht.Add("O2", "");
- // }
- try
- {
- //CommonClientToServer ccTs = new CommonClientToServer();
- //ccTs.ob = ob;
- //string strRCode = ccTs.ExecuteProcedureFunctions("Core.LgMes.Server.Common.ComDBProcedure",
- // "ExecProcWithCollParam", strSqlID, sArgs, out strErr);
- CommonClientToServer ccTs = new CommonClientToServer();
- ccTs.ob = ob;
- CoreClientParam ccp = ccTs.ExecuteProcedureFunctionsSqlID("Core.Mes.Server.Common.ComDataAccess",
- "executeProcedure", strSqlID, 5, ht, out strErr);
- if (strErr != "")
- {
- MessageBox.Show("操作失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- else
- {
- //strErr = "";
- //strSqlID = "BofHJMater.StatusChange";
- //object[] sArgs1 = new object[6];
- //sArgs1[0] = frm.vProcessNo; //加热处理号
- //sArgs1[1] = _HeatProcessNo.Substring(5, 8); //炉号
- //sArgs1[2] = strOriginal; //物料编码
- //sArgs1[3] = strName; //物料名称
- //if (frm.isCancel)
- //{
- // sArgs1[4] = "2";
- //}
- //else
- //{
- // sArgs1[4] = "1";
- //}
- //sArgs1[5] = frm.Weightno; //计量编号
- //CommonClientToServer ccts = new CommonClientToServer();
- //ccts.ob = ob;
- //string Code = ccts.ExecuteProcedureFunctions("Core.LgMes.Server.Common.ComDBMcmsQuery",
- // "ExecProcWithCollParam", strSqlID, sArgs1, out strErr);
- MessageBox.Show("操作成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- }
- }
- catch { }
- }
- }
- catch { }
- }
- }
- /// <summary>
- /// 物料分类
- /// </summary>
- public enum MaterialCategory
- {
- /// <summary>
- /// 辅料
- /// </summary>
- FL,
- /// <summary>
- /// 合金
- /// </summary>
- HJ,
- /// <summary>
- /// 喂丝
- /// </summary>
- WS,
- /// <summary>
- /// 辅料 + 合金
- /// </summary>
- FL_HJ,
- /// <summary>
- /// 辅料 + 喂丝
- /// </summary>
- FL_WS,
- /// <summary>
- /// 合金 + 喂丝
- /// </summary>
- HJ_WS,
- /// <summary>
- /// 辅料 + 合金 + 合金
- /// </summary>
- FL_HJ_WS
- }
- /// <summary>
- /// 投料分类
- /// </summary>
- public enum HopperCategory : int
- {
- /// <summary>
- /// 自动投料(系统采集)
- /// </summary>
- Automatic = 1,
- /// <summary>
- /// 手投料(人工录入)
- /// </summary>
- Manual = 2
- }
- }
|