StorageInfoSelect.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Windows.Forms;
  7. using Core.Mes.Client.Comm.Tool;
  8. using Core.StlMes.Client.LgResMgt.库存位置;
  9. using CoreFS.CA06;
  10. using Infragistics.Win;
  11. using Infragistics.Win.UltraWinGrid;
  12. using Resources = Core.StlMes.Client.LgResMgt.Properties.Resources;
  13. namespace Core.StlMes.Client.LgResMgt
  14. {
  15. public partial class StorageInfoSelect : FrmBase
  16. {
  17. private int _height = 200;
  18. private readonly string _storageNo;
  19. private string GridText;
  20. private YdmBsStorageSettingEntity ydmBsStorageSettingEntity;
  21. public StorageInfoSelect(string storageNo, OpeBase _ob)
  22. {
  23. InitializeComponent();
  24. ob = _ob;
  25. _storageNo = storageNo;
  26. RefreshData();
  27. }
  28. public LocationInfo SelectLocation { get; set; }
  29. public void RefreshData()
  30. {
  31. GetStorageSetting();
  32. dtData.Rows.Clear();
  33. dtData.Columns.Clear();
  34. var locationInfos = EntityHelper.GetData<LocationInfo>(
  35. "Core.LgMes.Server.LgDeviceManager.StorageManage.GetStorageLocationInfoNew",
  36. new[] {_storageNo}, ob);
  37. GridText = string.Format(@"可用空料位: {0} 满料位:{1} 总炉数: {2} 总支数: {3} 总吨数 {4}",
  38. locationInfos.Count(p => (p.ActCount == null) || (p.ActCount <= 0)),
  39. locationInfos.Count(p => (p.ActCount != null) && (p.ActCount > 0)),
  40. locationInfos.Sum(p => p.JudgeStoveNoCount),
  41. locationInfos.Sum(p => p.ActCount),
  42. locationInfos.Sum(p => p.ActWeight)
  43. );
  44. ugStorageInfo.Text = GridText;
  45. if (ydmBsStorageSettingEntity.ColumnRowNum == "0")
  46. {
  47. //老逻辑 列名 是按字母顺序分配
  48. OldLogic(locationInfos);
  49. }
  50. else
  51. {
  52. NewLogic(locationInfos);
  53. }
  54. }
  55. private string getColumsName(bool isSingleArea, string area, string col)
  56. {
  57. return (isSingleArea ? "" : area + "_") + col;
  58. }
  59. private void NewLogic(DataSourceList<LocationInfo> locationInfos)
  60. {
  61. var emptyRow = new List<int>();
  62. var emptyColums = new List<string>();
  63. var isSingleArea = locationInfos.Select(p => p.AreaNo).Distinct().Count() == 1;
  64. locationInfos.OrderBy(p => p.AreaNo).GroupBy(p => p.AreaNo).ToList().ForEach(
  65. areaData =>
  66. {
  67. var maxColums = 0;
  68. if (ydmBsStorageSettingEntity.ColumnReverse == "0")
  69. {
  70. var list = areaData
  71. .Where(p => StringUtil.IsInt(p.ColNo));
  72. if (list.Any())
  73. maxColums = list.Select(p => int.Parse(p.ColNo.ToString2())).Max();
  74. }
  75. else
  76. {
  77. var list = areaData
  78. .Where(p => StringUtil.IsInt(p.RowNo));
  79. if (list.Any())
  80. maxColums = list.Select(p => int.Parse(p.RowNo.ToString2())).Max();
  81. }
  82. for (var i = 1; i <= maxColums; i++)
  83. {
  84. var name = getColumsName(isSingleArea, areaData.Key, i + "");
  85. dtData.Columns.Add(
  86. new DataColumn(name));
  87. emptyColums.Add(name);
  88. }
  89. }
  90. );
  91. var maxRow = 0;
  92. if (ydmBsStorageSettingEntity.ColumnReverse == "0")
  93. {
  94. var list = locationInfos
  95. .Where(p => StringUtil.IsInt(p.RowNo));
  96. if (list.Any())
  97. maxRow = list.Select(p => int.Parse(p.RowNo.ToString2())).Max();
  98. }
  99. else
  100. {
  101. var list = locationInfos
  102. .Where(p => StringUtil.IsInt(p.ColNo));
  103. if (list.Any())
  104. maxRow = list.Select(p => int.Parse(p.ColNo.ToString2())).Max();
  105. }
  106. for (var i = 0; i < maxRow; i++)
  107. {
  108. dtData.Rows.Add(dtData.NewRow());
  109. emptyRow.Add(i);
  110. }
  111. locationInfos.ForEach(p =>
  112. {
  113. int rowindex;
  114. if (
  115. int.TryParse(ydmBsStorageSettingEntity.ColumnReverse == "0" ? p.RowNo : p.ColNo, out rowindex) &&
  116. (rowindex > 0))
  117. {
  118. int column;
  119. if (
  120. !int.TryParse(ydmBsStorageSettingEntity.ColumnReverse == "0" ? p.ColNo : p.RowNo, out column) &&
  121. (rowindex > 0)) return;
  122. var colum = getColumsName(isSingleArea, p.AreaNo, column + "");
  123. ugStorageInfo.Rows[rowindex - 1].Cells[colum].Tag = p;
  124. if (emptyRow.Contains(rowindex - 1)) emptyRow.Remove(rowindex - 1);
  125. if (emptyColums.Contains(colum)) emptyColums.Remove(colum);
  126. string data = ydmBsStorageSettingEntity.CellShow == "1" ? colum + "_" + rowindex : p.LocationName;
  127. int maxLen = 0;
  128. int.TryParse(ugStorageInfo.DisplayLayout.Bands[0].Columns[colum].Tag.ToString3(), out maxLen);
  129. int dataLen = System.Text.Encoding.Default.GetBytes(data).Length;
  130. if (dataLen > maxLen) ugStorageInfo.DisplayLayout.Bands[0].Columns[colum].Tag = dataLen;
  131. ugStorageInfo.Rows[rowindex - 1].Cells[colum].Value =
  132. ImageText(
  133. p.ActCount.ToString3(),
  134. data);
  135. }
  136. });
  137. if (ydmBsStorageSettingEntity.EmptyRowSort >= 0)
  138. for (var i = emptyRow.Count - 1; i >= 0; i--)
  139. {
  140. var currentlist = new List<int> { emptyRow[i] };
  141. while ((i > 0) && (emptyRow[i] - emptyRow[i - 1] == 1))
  142. currentlist.Add(emptyRow[--i]);
  143. for (var j = currentlist.Count - 1; j >= ydmBsStorageSettingEntity.EmptyRowSort; j--)
  144. ugStorageInfo.Rows[currentlist[j]].Delete(false);
  145. }
  146. if (ydmBsStorageSettingEntity.EmptyColumnSort >= 0)
  147. for (var i = emptyColums.Count - 1; i >= 0; i--)
  148. {
  149. var currentlist = new List<string> { emptyColums[i] };
  150. while ((i > 0) &&
  151. (ugStorageInfo.DisplayLayout.Bands[0].Columns[emptyColums[i]].Index -
  152. ugStorageInfo.DisplayLayout.Bands[0].Columns[emptyColums[i - 1]].Index == 1))
  153. currentlist.Add(emptyColums[--i]);
  154. for (var j = currentlist.Count - 1; j >= ydmBsStorageSettingEntity.EmptyColumnSort; j--)
  155. ugStorageInfo.DisplayLayout.Bands[0].Columns[currentlist[j]].Hidden = true;
  156. for (var j = int.Parse(ydmBsStorageSettingEntity.EmptyColumnSort.ToString2()) - 1; j >= 0; j--)
  157. ugStorageInfo.DisplayLayout.Bands[0].Columns[currentlist[j]].Header.Caption = "...";
  158. }
  159. SetGridFormat();
  160. }
  161. private void OldLogic(DataSourceList<LocationInfo> locationInfos)
  162. {
  163. locationInfos.OrderBy(p => p.AreaNo).GroupBy(p => p.AreaNo).ToList().ForEach(
  164. areaYdmBsLocationEntities =>
  165. {
  166. var maxRow = 0;
  167. foreach (
  168. IGrouping<string, YdmBsLocationEntity> rowYdmBsLocationEntities in
  169. areaYdmBsLocationEntities.OrderBy(p => p.RowNo).GroupBy(p => p.RowNo))
  170. {
  171. var columnName = NunberToChar(areaYdmBsLocationEntities.Key, 1) +
  172. NunberToChar(rowYdmBsLocationEntities.Key);
  173. if (!dtData.Columns.Contains(columnName))
  174. dtData.Columns.Add(
  175. new DataColumn(columnName));
  176. foreach (var ydmBsLocationEntity in rowYdmBsLocationEntities)
  177. {
  178. var rowindex = 0;
  179. if (!int.TryParse(ydmBsLocationEntity.ColNo, out rowindex)) continue;
  180. for (var i = dtData.Rows.Count; i < rowindex; i++)
  181. dtData.Rows.Add(dtData.NewRow());
  182. var locationMatGpMAndStorageEntitys =
  183. locationInfos.Where(p => p.LocationNo == ydmBsLocationEntity.LocationNo).ToList();
  184. if (locationMatGpMAndStorageEntitys.Any())
  185. ugStorageInfo.Rows[rowindex - 1].Cells[columnName].Tag =
  186. locationMatGpMAndStorageEntitys[0];
  187. else
  188. ugStorageInfo.Rows[rowindex - 1].Cells[columnName].Tag =
  189. ydmBsLocationEntity.LocationName.Replace("\n", "").Replace("\r", "");
  190. dtData.Rows[rowindex - 1][columnName] =
  191. ImageText(
  192. locationMatGpMAndStorageEntitys.Where(p => p.ActCount != null)
  193. .Select(p => p.ActCount)
  194. .Sum()
  195. .ToString(),
  196. ydmBsStorageSettingEntity.CellShow == "1" ? ugStorageInfo.DisplayLayout.Bands[0].Columns[columnName].Header.Caption +
  197. rowindex : ydmBsLocationEntity.LocationName);
  198. }
  199. }
  200. }
  201. );
  202. SetGridFormat();
  203. }
  204. private void SetGridFormat()
  205. {
  206. ugStorageInfo.DisplayLayout.Override.AllowRowFiltering = DefaultableBoolean.False;
  207. ugStorageInfo.DisplayLayout.Override.RowSelectorHeaderStyle = RowSelectorHeaderStyle.ExtendFirstColumn;
  208. ugStorageInfo.DisplayLayout.Override.RowSelectorWidth = 20;
  209. foreach (var ugc in ugStorageInfo.DisplayLayout.Bands[0].Columns)
  210. {
  211. int maxLen = 0;
  212. int.TryParse(ugc.Tag.ToString3(), out maxLen);
  213. ugc.SortIndicator = SortIndicator.Disabled;
  214. ugc.CellActivation = Activation.NoEdit;
  215. ugc.Width = maxLen > 8 ? (int)(maxLen * 8.8d) : 72;
  216. ugc.EditorComponent = ut1;
  217. }
  218. //ugStorageInfo.DisplayLayout.Override.RowSizing = RowSizing.AutoFree;
  219. ugStorageInfo.DisplayLayout.Override.DefaultRowHeight = 52 + (ydmBsStorageSettingEntity.CellShow == "3" ? 15 : 0);
  220. }
  221. private void GetStorageSetting()
  222. {
  223. List<YdmBsStorageSettingEntity> lists = EntityHelper.GetData<YdmBsStorageSettingEntity>(
  224. "Core.LgMes.Server.LgDeviceManager.StorageManage.GetStorageSetting",
  225. new object[] {_storageNo},
  226. ob);
  227. if (lists.Any())
  228. ydmBsStorageSettingEntity = lists[0];
  229. else
  230. ydmBsStorageSettingEntity = new YdmBsStorageSettingEntity
  231. {
  232. StorageNo = _storageNo,
  233. GroupArea = "1",
  234. ColumnReverse = "1",
  235. CellShow = "1",
  236. CellHight = 34,
  237. CellWight = 45,
  238. CellFullImage = ut1.EditInfo.EncodeImage(Resources.Full_Shelf),
  239. CellEmptyImage = ut1.EditInfo.EncodeImage(Resources.Empty_Shelf),
  240. EmptyColumnSort = 0,
  241. EmptyRowSort = 0,
  242. ColumnRowNum = "0"
  243. };
  244. }
  245. public string ImageText(string type, string title)
  246. {
  247. var encodedImage = type == "0"
  248. ? ydmBsStorageSettingEntity.CellEmptyImage
  249. : ydmBsStorageSettingEntity.CellFullImage;
  250. /*
  251. string ImageFormat = " <p style=\"text-align:Center;\"><img title=\"{2}\"" +
  252. " style=\"width:45px; height:34px;\" " +
  253. "data=\"{1}\"/><br/><span style=\"font-weight:bold;font-family:宋体; font-size:+0pt;\">{0}</span><br/></p>";*/
  254. var sb = new StringBuilder();
  255. sb.Append(" <p style=\"text-align:Center;\">");
  256. if (ydmBsStorageSettingEntity.CellShow == "3")
  257. {
  258. sb.Append("<span style=\"font-weight:bold;font-family:宋体; font-size:+0pt;\">");
  259. sb.Append("[" + type + "]");
  260. sb.Append("</span>");
  261. sb.Append("<br/>");
  262. }
  263. sb.Append(string.Format(" <img title=\"{0}\" style=\"width:45px; height:34px;\" data=\"{3}\"/> ", title,
  264. ydmBsStorageSettingEntity.CellWight, ydmBsStorageSettingEntity.CellHight,
  265. encodedImage));
  266. if (ydmBsStorageSettingEntity.CellShow != "0")
  267. {
  268. sb.Append("<br/>");
  269. sb.Append("<span style=\"font-weight:bold;font-family:宋体; font-size:+0pt;\">");
  270. sb.Append(title);
  271. sb.Append("</span>");
  272. sb.Append("<br/>");
  273. }
  274. sb.Append("</p>");
  275. return sb.ToString2();
  276. }
  277. private void ugStorageInfo_AfterCellActivate(object sender, EventArgs e)
  278. {
  279. var LocationText = "";
  280. // matGpMAndStorageEntityBindingSource.DataSource = new List<MatGpMAndStorageEntity>();
  281. if (ugStorageInfo.ActiveCell.Tag != null)
  282. {
  283. var locaiton =
  284. ugStorageInfo.ActiveCell.Tag as LocationInfo;
  285. if (locaiton != null)
  286. {
  287. var name = locaiton.LocationName +
  288. (string.IsNullOrWhiteSpace(locaiton.Memo) ? "" : "(" + locaiton.Memo + ")");
  289. if ((locaiton.ActCount == null) || (locaiton.ActCount <= 0))
  290. LocationText = string.Format(@" 当前料位: {0} 空料架", name);
  291. else
  292. LocationText = string.Format(@" 当前料位: {0} 料位炉数: {1} 料位支数: {2} 料位吨数 {3}",
  293. name,
  294. locaiton.JudgeStoveNoCount,
  295. locaiton.ActCount,
  296. locaiton.ActWeight
  297. );
  298. }
  299. }
  300. ugStorageInfo.Text = GridText + LocationText;
  301. // ClsControlPack.RefreshAndAutoSize(ugLocationDetail);
  302. // ugStorageInfo.ActiveCell.Tag
  303. }
  304. private string NunberToChar(string numberstr, int dif = 0)
  305. {
  306. try
  307. {
  308. var number = int.Parse(numberstr) - dif;
  309. if ((1 <= number) && (36 >= number))
  310. {
  311. var num = number + 64;
  312. var asciiEncoding = new ASCIIEncoding();
  313. byte[] btNumber = {(byte) num};
  314. return asciiEncoding.GetString(btNumber);
  315. }
  316. if (number == 0) return "";
  317. return "#";
  318. }
  319. catch (Exception)
  320. {
  321. return "#";
  322. }
  323. }
  324. private void ugStorageInfo_DoubleClick(object sender, EventArgs e)
  325. {
  326. if (ugStorageInfo.ActiveCell == null) return;
  327. var locationInfo = ugStorageInfo.ActiveCell.Tag as LocationInfo;
  328. if (locationInfo != null)
  329. {
  330. SelectLocation = locationInfo;
  331. DialogResult = DialogResult.OK;
  332. }
  333. }
  334. }
  335. }