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( "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 locationInfos) { var emptyRow = new List(); var emptyColums = new List(); 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 { 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 { 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 locationInfos) { locationInfos.OrderBy(p => p.AreaNo).GroupBy(p => p.AreaNo).ToList().ForEach( areaYdmBsLocationEntities => { var maxRow = 0; foreach ( IGrouping 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 lists = EntityHelper.GetData( "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 = "


{0}

";*/ var sb = new StringBuilder(); sb.Append("

"); if (ydmBsStorageSettingEntity.CellShow == "3") { sb.Append(""); sb.Append("[" + type + "]"); sb.Append(""); sb.Append("
"); } sb.Append(string.Format(" ", title, ydmBsStorageSettingEntity.CellWight, ydmBsStorageSettingEntity.CellHight, encodedImage)); if (ydmBsStorageSettingEntity.CellShow != "0") { sb.Append("
"); sb.Append(""); sb.Append(title); sb.Append(""); sb.Append("
"); } sb.Append("

"); return sb.ToString2(); } private void ugStorageInfo_AfterCellActivate(object sender, EventArgs e) { var LocationText = ""; // matGpMAndStorageEntityBindingSource.DataSource = new List(); 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; } } } }