| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using Core.Mes.Client.Comm.Tool;
- using Core.StlMes.Client.LgResMgt.库存位置;
- using CoreFS.CA06;
- using Infragistics.Win;
- using Infragistics.Win.UltraWinGrid;
- using Resources = Core.StlMes.Client.LgResMgt.Properties.Resources;
- namespace Core.StlMes.Client.LgResMgt
- {
- public partial class StorageInfoSelect : FrmBase
- {
- private int _height = 200;
- private readonly string _storageNo;
- private string GridText;
- private YdmBsStorageSettingEntity ydmBsStorageSettingEntity;
- public StorageInfoSelect(string storageNo, OpeBase _ob)
- {
- InitializeComponent();
- ob = _ob;
- _storageNo = storageNo;
- RefreshData();
- }
- public LocationInfo SelectLocation { get; set; }
- public void RefreshData()
- {
- GetStorageSetting();
- dtData.Rows.Clear();
- dtData.Columns.Clear();
- var locationInfos = EntityHelper.GetData<LocationInfo>(
- "Core.LgMes.Server.LgDeviceManager.StorageManage.GetStorageLocationInfoNew",
- new[] {_storageNo}, ob);
- GridText = string.Format(@"可用空料位: {0} 满料位:{1} 总炉数: {2} 总支数: {3} 总吨数 {4}",
- locationInfos.Count(p => (p.ActCount == null) || (p.ActCount <= 0)),
- locationInfos.Count(p => (p.ActCount != null) && (p.ActCount > 0)),
- locationInfos.Sum(p => p.JudgeStoveNoCount),
- locationInfos.Sum(p => p.ActCount),
- locationInfos.Sum(p => p.ActWeight)
- );
- ugStorageInfo.Text = GridText;
- if (ydmBsStorageSettingEntity.ColumnRowNum == "0")
- {
- //老逻辑 列名 是按字母顺序分配
- OldLogic(locationInfos);
- }
- else
- {
- NewLogic(locationInfos);
- }
- }
- private string getColumsName(bool isSingleArea, string area, string col)
- {
- return (isSingleArea ? "" : area + "_") + col;
- }
- private void NewLogic(DataSourceList<LocationInfo> locationInfos)
- {
- var emptyRow = new List<int>();
- var emptyColums = new List<string>();
- var isSingleArea = locationInfos.Select(p => p.AreaNo).Distinct().Count() == 1;
- locationInfos.OrderBy(p => p.AreaNo).GroupBy(p => p.AreaNo).ToList().ForEach(
- areaData =>
- {
- var maxColums = 0;
- if (ydmBsStorageSettingEntity.ColumnReverse == "0")
- {
- var list = areaData
- .Where(p => StringUtil.IsInt(p.ColNo));
- if (list.Any())
- maxColums = list.Select(p => int.Parse(p.ColNo.ToString2())).Max();
- }
- else
- {
- var list = areaData
- .Where(p => StringUtil.IsInt(p.RowNo));
- if (list.Any())
- maxColums = list.Select(p => int.Parse(p.RowNo.ToString2())).Max();
- }
- for (var i = 1; i <= maxColums; i++)
- {
- var name = getColumsName(isSingleArea, areaData.Key, i + "");
- dtData.Columns.Add(
- new DataColumn(name));
- emptyColums.Add(name);
- }
- }
- );
- var maxRow = 0;
- if (ydmBsStorageSettingEntity.ColumnReverse == "0")
- {
- var list = locationInfos
- .Where(p => StringUtil.IsInt(p.RowNo));
- if (list.Any())
- maxRow = list.Select(p => int.Parse(p.RowNo.ToString2())).Max();
- }
- else
- {
- var list = locationInfos
- .Where(p => StringUtil.IsInt(p.ColNo));
- if (list.Any())
- maxRow = list.Select(p => int.Parse(p.ColNo.ToString2())).Max();
- }
- for (var i = 0; i < maxRow; i++)
- {
- dtData.Rows.Add(dtData.NewRow());
- emptyRow.Add(i);
- }
- locationInfos.ForEach(p =>
- {
- int rowindex;
- if (
- int.TryParse(ydmBsStorageSettingEntity.ColumnReverse == "0" ? p.RowNo : p.ColNo, out rowindex) &&
- (rowindex > 0))
- {
- int column;
- if (
- !int.TryParse(ydmBsStorageSettingEntity.ColumnReverse == "0" ? p.ColNo : p.RowNo, out column) &&
- (rowindex > 0)) return;
- var colum = getColumsName(isSingleArea, p.AreaNo, column + "");
- ugStorageInfo.Rows[rowindex - 1].Cells[colum].Tag = p;
- if (emptyRow.Contains(rowindex - 1)) emptyRow.Remove(rowindex - 1);
- if (emptyColums.Contains(colum)) emptyColums.Remove(colum);
- string data = ydmBsStorageSettingEntity.CellShow == "1" ? colum + "_" + rowindex : p.LocationName;
- int maxLen = 0;
- int.TryParse(ugStorageInfo.DisplayLayout.Bands[0].Columns[colum].Tag.ToString3(), out maxLen);
- int dataLen = System.Text.Encoding.Default.GetBytes(data).Length;
- if (dataLen > maxLen) ugStorageInfo.DisplayLayout.Bands[0].Columns[colum].Tag = dataLen;
- ugStorageInfo.Rows[rowindex - 1].Cells[colum].Value =
- ImageText(
- p.ActCount.ToString3(),
- data);
- }
- });
- if (ydmBsStorageSettingEntity.EmptyRowSort >= 0)
- for (var i = emptyRow.Count - 1; i >= 0; i--)
- {
- var currentlist = new List<int> { emptyRow[i] };
- while ((i > 0) && (emptyRow[i] - emptyRow[i - 1] == 1))
- currentlist.Add(emptyRow[--i]);
- for (var j = currentlist.Count - 1; j >= ydmBsStorageSettingEntity.EmptyRowSort; j--)
- ugStorageInfo.Rows[currentlist[j]].Delete(false);
- }
- if (ydmBsStorageSettingEntity.EmptyColumnSort >= 0)
- for (var i = emptyColums.Count - 1; i >= 0; i--)
- {
- var currentlist = new List<string> { emptyColums[i] };
- while ((i > 0) &&
- (ugStorageInfo.DisplayLayout.Bands[0].Columns[emptyColums[i]].Index -
- ugStorageInfo.DisplayLayout.Bands[0].Columns[emptyColums[i - 1]].Index == 1))
- currentlist.Add(emptyColums[--i]);
- for (var j = currentlist.Count - 1; j >= ydmBsStorageSettingEntity.EmptyColumnSort; j--)
- ugStorageInfo.DisplayLayout.Bands[0].Columns[currentlist[j]].Hidden = true;
- for (var j = int.Parse(ydmBsStorageSettingEntity.EmptyColumnSort.ToString2()) - 1; j >= 0; j--)
- ugStorageInfo.DisplayLayout.Bands[0].Columns[currentlist[j]].Header.Caption = "...";
- }
- SetGridFormat();
- }
- private void OldLogic(DataSourceList<LocationInfo> locationInfos)
- {
- locationInfos.OrderBy(p => p.AreaNo).GroupBy(p => p.AreaNo).ToList().ForEach(
- areaYdmBsLocationEntities =>
- {
- var maxRow = 0;
- foreach (
- IGrouping<string, YdmBsLocationEntity> rowYdmBsLocationEntities in
- areaYdmBsLocationEntities.OrderBy(p => p.RowNo).GroupBy(p => p.RowNo))
- {
- var columnName = NunberToChar(areaYdmBsLocationEntities.Key, 1) +
- NunberToChar(rowYdmBsLocationEntities.Key);
- if (!dtData.Columns.Contains(columnName))
- dtData.Columns.Add(
- new DataColumn(columnName));
- foreach (var ydmBsLocationEntity in rowYdmBsLocationEntities)
- {
- var rowindex = 0;
- if (!int.TryParse(ydmBsLocationEntity.ColNo, out rowindex)) continue;
- for (var i = dtData.Rows.Count; i < rowindex; i++)
- dtData.Rows.Add(dtData.NewRow());
- var locationMatGpMAndStorageEntitys =
- locationInfos.Where(p => p.LocationNo == ydmBsLocationEntity.LocationNo).ToList();
- if (locationMatGpMAndStorageEntitys.Any())
- ugStorageInfo.Rows[rowindex - 1].Cells[columnName].Tag =
- locationMatGpMAndStorageEntitys[0];
- else
- ugStorageInfo.Rows[rowindex - 1].Cells[columnName].Tag =
- ydmBsLocationEntity.LocationName.Replace("\n", "").Replace("\r", "");
- dtData.Rows[rowindex - 1][columnName] =
- ImageText(
- locationMatGpMAndStorageEntitys.Where(p => p.ActCount != null)
- .Select(p => p.ActCount)
- .Sum()
- .ToString(),
- ydmBsStorageSettingEntity.CellShow == "1" ? ugStorageInfo.DisplayLayout.Bands[0].Columns[columnName].Header.Caption +
- rowindex : ydmBsLocationEntity.LocationName);
- }
- }
- }
- );
- SetGridFormat();
- }
- private void SetGridFormat()
- {
- ugStorageInfo.DisplayLayout.Override.AllowRowFiltering = DefaultableBoolean.False;
- ugStorageInfo.DisplayLayout.Override.RowSelectorHeaderStyle = RowSelectorHeaderStyle.ExtendFirstColumn;
- ugStorageInfo.DisplayLayout.Override.RowSelectorWidth = 20;
- foreach (var ugc in ugStorageInfo.DisplayLayout.Bands[0].Columns)
- {
- int maxLen = 0;
- int.TryParse(ugc.Tag.ToString3(), out maxLen);
- ugc.SortIndicator = SortIndicator.Disabled;
- ugc.CellActivation = Activation.NoEdit;
- ugc.Width = maxLen > 8 ? (int)(maxLen * 8.8d) : 72;
- ugc.EditorComponent = ut1;
- }
- //ugStorageInfo.DisplayLayout.Override.RowSizing = RowSizing.AutoFree;
- ugStorageInfo.DisplayLayout.Override.DefaultRowHeight = 52 + (ydmBsStorageSettingEntity.CellShow == "3" ? 15 : 0);
- }
- private void GetStorageSetting()
- {
- List<YdmBsStorageSettingEntity> lists = EntityHelper.GetData<YdmBsStorageSettingEntity>(
- "Core.LgMes.Server.LgDeviceManager.StorageManage.GetStorageSetting",
- new object[] {_storageNo},
- ob);
- if (lists.Any())
- ydmBsStorageSettingEntity = lists[0];
- else
- ydmBsStorageSettingEntity = new YdmBsStorageSettingEntity
- {
- StorageNo = _storageNo,
- GroupArea = "1",
- ColumnReverse = "1",
- CellShow = "1",
- CellHight = 34,
- CellWight = 45,
- CellFullImage = ut1.EditInfo.EncodeImage(Resources.Full_Shelf),
- CellEmptyImage = ut1.EditInfo.EncodeImage(Resources.Empty_Shelf),
- EmptyColumnSort = 0,
- EmptyRowSort = 0,
- ColumnRowNum = "0"
- };
- }
- public string ImageText(string type, string title)
- {
- var encodedImage = type == "0"
- ? ydmBsStorageSettingEntity.CellEmptyImage
- : ydmBsStorageSettingEntity.CellFullImage;
- /*
- string ImageFormat = " <p style=\"text-align:Center;\"><img title=\"{2}\"" +
- " style=\"width:45px; height:34px;\" " +
- "data=\"{1}\"/><br/><span style=\"font-weight:bold;font-family:宋体; font-size:+0pt;\">{0}</span><br/></p>";*/
- var sb = new StringBuilder();
- sb.Append(" <p style=\"text-align:Center;\">");
- if (ydmBsStorageSettingEntity.CellShow == "3")
- {
- sb.Append("<span style=\"font-weight:bold;font-family:宋体; font-size:+0pt;\">");
- sb.Append("[" + type + "]");
- sb.Append("</span>");
- sb.Append("<br/>");
- }
- sb.Append(string.Format(" <img title=\"{0}\" style=\"width:45px; height:34px;\" data=\"{3}\"/> ", title,
- ydmBsStorageSettingEntity.CellWight, ydmBsStorageSettingEntity.CellHight,
- encodedImage));
- if (ydmBsStorageSettingEntity.CellShow != "0")
- {
- sb.Append("<br/>");
- sb.Append("<span style=\"font-weight:bold;font-family:宋体; font-size:+0pt;\">");
- sb.Append(title);
- sb.Append("</span>");
- sb.Append("<br/>");
- }
- sb.Append("</p>");
- return sb.ToString2();
- }
- private void ugStorageInfo_AfterCellActivate(object sender, EventArgs e)
- {
- var LocationText = "";
- // matGpMAndStorageEntityBindingSource.DataSource = new List<MatGpMAndStorageEntity>();
- if (ugStorageInfo.ActiveCell.Tag != null)
- {
- var locaiton =
- ugStorageInfo.ActiveCell.Tag as LocationInfo;
- if (locaiton != null)
- {
- var name = locaiton.LocationName +
- (string.IsNullOrWhiteSpace(locaiton.Memo) ? "" : "(" + locaiton.Memo + ")");
- if ((locaiton.ActCount == null) || (locaiton.ActCount <= 0))
- LocationText = string.Format(@" 当前料位: {0} 空料架", name);
- else
- LocationText = string.Format(@" 当前料位: {0} 料位炉数: {1} 料位支数: {2} 料位吨数 {3}",
- name,
- locaiton.JudgeStoveNoCount,
- locaiton.ActCount,
- locaiton.ActWeight
- );
- }
- }
- ugStorageInfo.Text = GridText + LocationText;
- // ClsControlPack.RefreshAndAutoSize(ugLocationDetail);
- // ugStorageInfo.ActiveCell.Tag
- }
- private string NunberToChar(string numberstr, int dif = 0)
- {
- try
- {
- var number = int.Parse(numberstr) - dif;
- if ((1 <= number) && (36 >= number))
- {
- var num = number + 64;
- var asciiEncoding = new ASCIIEncoding();
- byte[] btNumber = {(byte) num};
- return asciiEncoding.GetString(btNumber);
- }
- if (number == 0) return "";
- return "#";
- }
- catch (Exception)
- {
- return "#";
- }
- }
- private void ugStorageInfo_DoubleClick(object sender, EventArgs e)
- {
- if (ugStorageInfo.ActiveCell == null) return;
- var locationInfo = ugStorageInfo.ActiveCell.Tag as LocationInfo;
- if (locationInfo != null)
- {
- SelectLocation = locationInfo;
- DialogResult = DialogResult.OK;
- }
- }
- }
- }
|