ucAdditive.cs 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  1. using System;
  2. using System.ComponentModel;
  3. using System.Data;
  4. using System.Drawing;
  5. using System.Windows.Forms;
  6. using Core.StlMes.Client.LgClassModel;
  7. using CoreFS.CA06;
  8. using Infragistics.Win;
  9. using Infragistics.Win.Misc;
  10. using Infragistics.Win.UltraWinGrid;
  11. //using Core.Mes.Client.Comm;
  12. using System.Collections;
  13. using Core.Mes.Client.Comm;
  14. using Core.Mes.Client.Comm.Server;
  15. namespace Core.StlMes.Client.LgCommon
  16. {
  17. public delegate void SetHopperHandler(); //设置料仓后调用控件的SetHopperInfo
  18. /* //##################################################################################################
  19. * 名称:加料公用控件(大部分功能直接在设计器属性字段设置)
  20. *
  21. * 作者:肖桦军
  22. *
  23. * 完成日期:2012-10-09
  24. *
  25. * 关于调用:
  26. *
  27. * 1、在窗体上拖入此控件,设置相关属性(料仓个数、显示参数)
  28. *
  29. * 2、在窗体构造函数或者装载事件设置 ob、DEVICE_POSITION 属性
  30. *
  31. * 3、在设计器或者代码中(构造函数或者FormLoad)设置MtrlCategory、HpprCategory 属性
  32. *
  33. * 4、在构造函数或者窗体装载事件中设置SetHopper代理(处理设置料仓后刷新显示)
  34. *
  35. * 5、在窗体SetData线程中更新 HeatProcessNo 属性(实时的处理信息)
  36. *
  37. * 6、在窗体SetData线程中调用SetAdditiveData()填充数据
  38. */
  39. //#####################################################################################################
  40. public partial class ucAdditive : UserControl
  41. {
  42. private string _Caption = ""; //显示标题
  43. private int _HopperNum = 20; //料斗数目
  44. private int _ItemsPerRow = 2; //每行显示料斗数目
  45. private bool _ExPanded = true; //是否展开
  46. private bool _Expandable = false; //是否可收缩
  47. private int _ExPandedHeight = 0; //展开高度
  48. private bool _Editable = false; //数值可以修改
  49. private bool _ShowCellButton = false; //显示编辑区域按钮
  50. private UIElementBorderStyle _BorderStyle = UIElementBorderStyle.InsetSoft;
  51. private int _ZoneValueWidth = 72; //料斗数值框宽度
  52. private int _ZoneCaptionWidth = 72; //料斗标签框宽度
  53. private int _VerticalSpacing = 1; //料斗垂直间距
  54. private int _HorizontalSpacing = 1; //料斗水平间距
  55. private int _LeftSpacing = 1; //料斗区域左边距
  56. private int _RightSpacing = 1; //料斗区域右边距
  57. private int _TopSpacing = 1; //料斗区域顶距
  58. private int _BottomSpacing = 1; //料斗区域底距
  59. private string _DEVICE_POSITION = ""; //设备位置
  60. private string _HeatProcessNo = ""; //实时加热处理号
  61. private OpeBase _ob;
  62. private MaterialCategory _MtrlCategory = MaterialCategory.FL;
  63. private HopperCategory _HpprCategory = HopperCategory.Automatic;
  64. public SetHopperHandler SetHopper = null; //设置料仓后调用控件的SetHopperInfo
  65. #region 属性
  66. /// <summary>
  67. /// 设备位置
  68. /// </summary>
  69. [Description("设备位置")]
  70. public string DEVICE_POSITION
  71. {
  72. get { return _DEVICE_POSITION; }
  73. set { if (value != _DEVICE_POSITION) _DEVICE_POSITION = value; }
  74. }
  75. [Browsable(false)]
  76. public OpeBase ob
  77. {
  78. get { return _ob; }
  79. set { if (value != _ob) _ob = value; }
  80. }
  81. /// <summary>
  82. /// 实时加热处理号
  83. /// </summary>
  84. [Description("实时加热处理号")]
  85. [Browsable(false)]
  86. public string HeatProcessNo
  87. {
  88. get { return _HeatProcessNo; }
  89. set { if (value != _HeatProcessNo) _HeatProcessNo = value; }
  90. }
  91. /// <summary>
  92. /// 物料类别
  93. /// </summary>
  94. [Description("物料类别")]
  95. public MaterialCategory MtrlCategory
  96. {
  97. get { return _MtrlCategory; }
  98. set { if (value != _MtrlCategory) _MtrlCategory = value; }
  99. }
  100. /// <summary>
  101. /// 投料分类
  102. /// </summary>
  103. [Description("投料分类")]
  104. public HopperCategory HpprCategory
  105. {
  106. get { return _HpprCategory; }
  107. set { if (value != _HpprCategory) _HpprCategory = value; }
  108. }
  109. /// <summary>
  110. /// 显示标题
  111. /// </summary>
  112. [Description("显示标题")]
  113. public string Caption
  114. {
  115. get { return _Caption; }
  116. set
  117. {
  118. if (!value.Equals(_Caption))
  119. {
  120. _Caption = value;
  121. MainContainer.Text = value;
  122. }
  123. }
  124. }
  125. /// <summary>
  126. /// 料斗数目(10 - 100)
  127. /// </summary>
  128. [Description("料斗数目(10 - 100)")]
  129. public int HopperNum
  130. {
  131. get { return _HopperNum; }
  132. set
  133. {
  134. if (value < 10) value = 10;
  135. else if (value > 100) value = 100;
  136. if (value != _HopperNum)
  137. {
  138. _HopperNum = value;
  139. if (_ItemsPerRow > value) _ItemsPerRow = value;
  140. this.ResetLayout();
  141. }
  142. }
  143. }
  144. /// <summary>
  145. /// 每行显示料斗数目(1 - HopperNum)
  146. /// </summary>
  147. [Description("料斗数目(每行显示料斗数目(1 - HopperNum))")]
  148. public int ItemsPerRow
  149. {
  150. get { return _ItemsPerRow; }
  151. set
  152. {
  153. if (value < 1) value = 1;
  154. else if (value > _HopperNum) value = _HopperNum;
  155. if (value != _ItemsPerRow)
  156. {
  157. _ItemsPerRow = value;
  158. this.ResetLayout();
  159. }
  160. }
  161. }
  162. /// <summary>
  163. /// 展开状态
  164. /// </summary>
  165. [Description("展开状态")]
  166. public bool ExPanded
  167. {
  168. get { return _ExPanded; }
  169. set
  170. {
  171. if (!value && !_Expandable) value = true;
  172. if (value != _ExPanded)
  173. {
  174. _ExPanded = value;
  175. MainContainer.Expanded = value;
  176. }
  177. }
  178. }
  179. /// <summary>
  180. /// 是否可收缩
  181. /// </summary>
  182. [Description("是否可收缩")]
  183. public bool Expandable
  184. {
  185. get { return _Expandable; }
  186. set
  187. {
  188. if (value != _Expandable)
  189. {
  190. _Expandable = value;
  191. if (!value)
  192. {
  193. MainContainer.ExpansionIndicator = GroupBoxExpansionIndicator.None;
  194. MainContainer.HeaderClickAction = GroupBoxHeaderClickAction.None;
  195. ExPanded = true;
  196. }
  197. else
  198. {
  199. MainContainer.ExpansionIndicator = GroupBoxExpansionIndicator.Far;
  200. MainContainer.HeaderClickAction = GroupBoxHeaderClickAction.ToggleExpansion;
  201. if (string.IsNullOrEmpty(_Caption)) Caption = "投料类别";
  202. if (value) _ExPanded = MainContainer.Expanded;
  203. }
  204. MainContainer.Invalidate();
  205. }
  206. }
  207. }
  208. [Description("展开高度")]
  209. public int ExPandedHeight
  210. {
  211. get { return _ExPandedHeight; }
  212. }
  213. /// <summary>
  214. /// 数值可以修改
  215. /// </summary>
  216. [Description("数值可以修改")]
  217. public bool Editable
  218. {
  219. get { return _Editable; }
  220. set
  221. {
  222. if (value != _Editable)
  223. {
  224. if (!value)
  225. {
  226. ShowCellButton = false;
  227. }
  228. _Editable = value;
  229. this.SetEditable(value);
  230. }
  231. }
  232. }
  233. /// <summary>
  234. /// 显示编辑区域按钮
  235. /// </summary>
  236. [Description("显示编辑区域按钮")]
  237. public bool ShowCellButton
  238. {
  239. get { return _ShowCellButton; }
  240. set
  241. {
  242. if (!_Editable && value) value = false;
  243. if (value != _ShowCellButton)
  244. {
  245. _ShowCellButton = value;
  246. this.SetEditButton(value);
  247. }
  248. }
  249. }
  250. /// <summary>
  251. /// 料斗数值框宽度(20 - 200)
  252. /// </summary>
  253. [Description("料斗数值框宽度(20 - 200)")]
  254. public int ZoneValueWidth
  255. {
  256. get { return _ZoneValueWidth; }
  257. set
  258. {
  259. if (value < 20) value = 20;
  260. else if (value > 200) value = 200;
  261. if (value != _ZoneValueWidth)
  262. {
  263. _ZoneValueWidth = value;
  264. this.ResetLayout();
  265. }
  266. }
  267. }
  268. /// <summary>
  269. /// 料斗标签框宽度(20 - 200)
  270. /// </summary>
  271. [Description("料斗标签框宽度(20 - 200)")]
  272. public int ZoneCaptionWidth
  273. {
  274. get { return _ZoneCaptionWidth; }
  275. set
  276. {
  277. if (value < 20) value = 20;
  278. else if (value > 200) value = 200;
  279. if (value != _ZoneCaptionWidth)
  280. {
  281. _ZoneCaptionWidth = value;
  282. this.ResetLayout();
  283. }
  284. }
  285. }
  286. /// <summary>
  287. /// 料斗水平间距(0 - 100)
  288. /// </summary>
  289. [Description("料斗水平间距(0 - 100)")]
  290. public int HorizontalSpacing
  291. {
  292. get { return _HorizontalSpacing; }
  293. set
  294. {
  295. if (value < 0) value = 0;
  296. else if (value > 100) value = 100;
  297. if (value != _HorizontalSpacing)
  298. {
  299. _HorizontalSpacing = value;
  300. this.ResetLayout();
  301. }
  302. }
  303. }
  304. /// <summary>
  305. /// 料斗垂直间距(0 - 100)
  306. /// </summary>
  307. [Description("料斗垂直间距(0 - 100)")]
  308. public int VerticalSpacing
  309. {
  310. get { return _VerticalSpacing; }
  311. set
  312. {
  313. if (value < 0) value = 0;
  314. else if (value > 100) value = 100;
  315. if (value != _VerticalSpacing)
  316. {
  317. _VerticalSpacing = value;
  318. this.ResetLayout();
  319. }
  320. }
  321. }
  322. /// <summary>
  323. /// 料斗区域左边距(0 - 100)
  324. /// </summary>
  325. [Description("料斗区域左边距(0 - 100)")]
  326. public int LeftSpacing
  327. {
  328. get { return _LeftSpacing; }
  329. set
  330. {
  331. if (value < 0) value = 0;
  332. else if (value > 100) value = 100;
  333. if (value != _LeftSpacing)
  334. {
  335. _LeftSpacing = value;
  336. this.ResetLayout();
  337. }
  338. }
  339. }
  340. /// <summary>
  341. /// 料斗区域右边距(0 - 100)
  342. /// </summary>
  343. [Description("料斗区域右边距(0 - 100)")]
  344. public int RightSpacing
  345. {
  346. get { return _RightSpacing; }
  347. set
  348. {
  349. if (value < 0) value = 0;
  350. else if (value > 100) value = 100;
  351. if (value != _RightSpacing)
  352. {
  353. _RightSpacing = value;
  354. this.ResetLayout();
  355. }
  356. }
  357. }
  358. /// <summary>
  359. /// 料斗区域顶距(0 - 100)
  360. /// </summary>
  361. [Description("料斗区域顶距(0 - 100)")]
  362. public int TopSpacing
  363. {
  364. get { return _TopSpacing; }
  365. set
  366. {
  367. if (value < 0) value = 0;
  368. else if (value > 100) value = 100;
  369. if (value != _TopSpacing)
  370. {
  371. _TopSpacing = value;
  372. this.ResetLayout();
  373. }
  374. }
  375. }
  376. /// <summary>
  377. /// 料斗区域底距(0 - 100)
  378. /// </summary>
  379. [Description("料斗区域底距(0 - 100)")]
  380. public int BottomSpacing
  381. {
  382. get { return _BottomSpacing; }
  383. set
  384. {
  385. if (value < 0) value = 0;
  386. else if (value > 100) value = 100;
  387. if (value != _BottomSpacing)
  388. {
  389. _BottomSpacing = value;
  390. this.ResetLayout();
  391. }
  392. }
  393. }
  394. [Description("边框样式")]
  395. public new UIElementBorderStyle BorderStyle
  396. {
  397. get { return _BorderStyle; }
  398. set
  399. {
  400. if (value != _BorderStyle)
  401. {
  402. _BorderStyle = value;
  403. MidContainer.BorderStyle = value;
  404. }
  405. }
  406. }
  407. #endregion
  408. #region 构造函数
  409. public ucAdditive()
  410. {
  411. InitializeComponent();
  412. this.Caption = "投料类别";
  413. this.SetDelegate();
  414. this.ResetLayout();
  415. }
  416. #endregion
  417. #region 重新生成框架
  418. private void ResetSource()
  419. {
  420. try
  421. {
  422. ultraDataSource1.Rows.Clear();
  423. ultraDataSource1.Band.Columns.Clear();
  424. }
  425. catch { }
  426. }
  427. private void ResetLayout()
  428. {
  429. try
  430. {
  431. ultraGrid1.BeginUpdate();
  432. this.ResetSource();
  433. for (int i = 0; i < _HopperNum; i++)
  434. {
  435. ultraDataSource1.Band.Columns.Add(Convert.ToString(i + 1), typeof(string));
  436. }
  437. int iOriginX = 0, iOriginY = 0;
  438. for (int i = 0; i < _HopperNum; i++)
  439. {
  440. try
  441. {
  442. ultraGrid1.DisplayLayout.Bands[0].Columns[i].CellActivation = (_Editable ? Activation.AllowEdit : Activation.NoEdit);
  443. if (_ShowCellButton) ultraGrid1.DisplayLayout.Bands[0].Columns[i].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.EditButton;
  444. else ultraGrid1.DisplayLayout.Bands[0].Columns[i].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Default;
  445. }
  446. catch { }
  447. try
  448. {
  449. int iVerCount = (int)Math.Ceiling((float)_HopperNum / (float)_ItemsPerRow);
  450. iOriginX = i % _ItemsPerRow;
  451. iOriginY = i / _ItemsPerRow;
  452. ultraGrid1.DisplayLayout.Bands[0].Columns[i].CellAppearance.TextVAlign = VAlign.Middle;
  453. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Appearance.TextHAlign = HAlign.Left;
  454. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Appearance.TextVAlign = VAlign.Middle;
  455. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Caption = "";
  456. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Tag = "";
  457. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Tag = ultraGrid1.DisplayLayout.Bands[0].Columns[i].Key;
  458. ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.SpanX = 2;
  459. ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.SpanY = 1;
  460. ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.OriginX = iOriginX * 2;
  461. ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.OriginY = iOriginY;
  462. ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.PreferredCellSize = new Size(_ZoneValueWidth, 0);
  463. ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.PreferredLabelSize = new Size(_ZoneCaptionWidth, 0);
  464. ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.LabelInsets.Left = (iOriginX == 0 ? _LeftSpacing : _HorizontalSpacing);
  465. ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.LabelInsets.Top = (iOriginY == 0 ? _TopSpacing : _VerticalSpacing);
  466. ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.CellInsets.Top = (iOriginY == 0 ? _TopSpacing : _VerticalSpacing);
  467. ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.CellInsets.Right = (iOriginX == _ItemsPerRow - 1 ? _RightSpacing : 0);
  468. ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.LabelInsets.Bottom = (iOriginY == iVerCount - 1 ? _BottomSpacing : 0);
  469. ultraGrid1.DisplayLayout.Bands[0].Columns[i].RowLayoutColumnInfo.CellInsets.Bottom = (iOriginY == iVerCount - 1 ? _BottomSpacing : 0);
  470. }
  471. catch { }
  472. }
  473. ClsControlPack.InitUltraDataSource(ultraDataSource1);
  474. }
  475. catch { }
  476. finally
  477. {
  478. ultraGrid1.EndUpdate();
  479. }
  480. }
  481. #endregion
  482. #region 窗体调用(填充加料数据、读取并显示料斗设置)
  483. /// <summary>
  484. /// 加料数据填充
  485. /// </summary>
  486. /// <param name="additiveBuffer">加料数据集</param>
  487. public void SetAdditiveData(CommonAdditive additiveBuffer)
  488. {
  489. try
  490. {
  491. string strKey = ""; //料仓ID
  492. string strCode = ""; //某个料仓配置的物料编码
  493. string strType = ""; //某个料仓配置的物料类别
  494. bool Added = false; //表示某个料仓是否有加料
  495. for (int idx = 0; idx < ultraDataSource1.Band.Columns.Count; idx++)
  496. {
  497. try
  498. {
  499. strKey = ultraDataSource1.Band.Columns[idx].Key;
  500. if (additiveBuffer == null)
  501. {
  502. ultraDataSource1.Rows[0][strKey] = "";
  503. continue;
  504. }
  505. strCode = Convert.ToString(ultraGrid1.DisplayLayout.Bands[0].Columns[strKey].Tag);
  506. strType = Convert.ToString(ultraGrid1.DisplayLayout.Bands[0].Columns[strKey].Header.Tag);
  507. if (strKey.Equals(strCode)) //料斗没有设置物料
  508. {
  509. ultraDataSource1.Rows[0][strKey] = "";
  510. continue;
  511. }
  512. for (int i = 0; i < additiveBuffer.hList.Count; i++)
  513. {
  514. JOB_COMMON_ADDITIVES addt = (JOB_COMMON_ADDITIVES)additiveBuffer.hList[i];
  515. if (_HpprCategory == HopperCategory.Automatic) //自动加料才判断物料类别
  516. {
  517. if (addt == null || addt.HOPPERNUMID != strKey || addt.JMTYPE != "1") continue; //加料类型为1表示自动加料、料仓号匹配
  518. if (addt.MATERIELTYPE != strType || addt.MATERIELCODE != strCode) continue; //物料类别、物料编码匹配
  519. if (_MtrlCategory == MaterialCategory.FL && addt.MATERIELTYPE != "FL") continue;
  520. if (_MtrlCategory == MaterialCategory.HJ && addt.MATERIELTYPE != "HJ") continue;
  521. if (_MtrlCategory == MaterialCategory.WS && addt.MATERIELTYPE != "WS") continue;
  522. if (_MtrlCategory == MaterialCategory.FL_HJ && addt.MATERIELTYPE != "FL" && addt.MATERIELTYPE != "HJ") continue;
  523. if (_MtrlCategory == MaterialCategory.FL_WS && addt.MATERIELTYPE != "FL" && addt.MATERIELTYPE != "WS") continue;
  524. if (_MtrlCategory == MaterialCategory.HJ_WS && addt.MATERIELTYPE != "HJ" && addt.MATERIELTYPE != "WS") continue;
  525. if (_MtrlCategory == MaterialCategory.FL_HJ_WS && addt.MATERIELTYPE != "FL" && addt.MATERIELTYPE != "HJ" && addt.MATERIELTYPE != "WS") continue;
  526. }
  527. else if (_HpprCategory == HopperCategory.Manual)
  528. {
  529. if (addt == null || addt.MATERIELTYPE != strType || addt.MATERIELCODE != strCode || addt.JMTYPE != "2") continue;
  530. }
  531. try
  532. {
  533. ultraDataSource1.Rows[0][strKey] = addt.JMWGT;
  534. Added = true;
  535. break;
  536. }
  537. catch { }
  538. }
  539. }
  540. catch { }
  541. if (!Added) ultraDataSource1.Rows[0][strKey] = "";//没有加料
  542. else if (Added) Added = false; //清除加料标志,跳转到下一料仓
  543. }
  544. }
  545. catch { }
  546. finally
  547. {
  548. ultraGrid1.UpdateData();
  549. }
  550. }
  551. /// <summary>
  552. /// 读取并设置仓对应物料
  553. /// </summary>
  554. /// <param name="tblConfig">设置表</param>
  555. /// <param name="tblMaterial">物料基础表</param>
  556. public void SetHopperInfo(DataTable tblConfig, DataTable tblMaterial)
  557. {
  558. try
  559. {
  560. string HopperID = "";
  561. string Filter = "";
  562. DataRow[] rows = null;
  563. if (_HpprCategory == HopperCategory.Automatic)
  564. {
  565. if (_MtrlCategory == MaterialCategory.FL) Filter = "MATERIELTYPE = 'FL'";
  566. else if (_MtrlCategory == MaterialCategory.HJ) Filter = "MATERIELTYPE = 'HJ'";
  567. else if (_MtrlCategory == MaterialCategory.WS) Filter = "MATERIELTYPE = 'WS'";
  568. else if (_MtrlCategory == MaterialCategory.FL_HJ) Filter = "MATERIELTYPE = 'FL' or MATERIELTYPE = 'HJ'";
  569. else if (_MtrlCategory == MaterialCategory.FL_WS) Filter = "MATERIELTYPE = 'FL' or MATERIELTYPE = 'WS'";
  570. else if (_MtrlCategory == MaterialCategory.HJ_WS) Filter = "MATERIELTYPE = 'HJ' or MATERIELTYPE = 'WS'";
  571. else if (_MtrlCategory == MaterialCategory.FL_HJ_WS) Filter = "MATERIELTYPE = 'FL' or MATERIELTYPE = 'HJ' or MATERIELTYPE = 'WS'";
  572. else Filter = "MATERIELTYPE = '?'";
  573. Filter = "(" + Filter + ") and JMTYPE = '1'";
  574. for (int i = 0; i < ultraGrid1.DisplayLayout.Bands[0].Columns.Count; i++)
  575. {
  576. try
  577. {
  578. if (tblConfig == null || tblConfig.Rows.Count == 0)
  579. {
  580. try
  581. {
  582. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Tag = ultraGrid1.DisplayLayout.Bands[0].Columns[i].Key;
  583. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Caption = "";
  584. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Tag = "";
  585. }
  586. catch { }
  587. break;
  588. }
  589. HopperID = ultraGrid1.DisplayLayout.Bands[0].Columns[i].Key;
  590. rows = tblConfig.Select(Filter + " and MSNUMID = '" + HopperID + "'");
  591. if (rows.Length > 0)
  592. {
  593. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Tag = Convert.ToString(rows[0]["MATERIELCODE"]); //保存物料编码
  594. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Caption = Convert.ToString(rows[0]["MATERIELFORSHORT"]); //保存物料简称
  595. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Tag = Convert.ToString(rows[0]["MATERIELTYPE"]); //保存物料类别
  596. }
  597. else
  598. {
  599. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Tag = ultraGrid1.DisplayLayout.Bands[0].Columns[i].Key;
  600. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Caption = "";
  601. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Tag = "";
  602. }
  603. }
  604. catch { }
  605. }
  606. }
  607. else if (_HpprCategory == HopperCategory.Manual)
  608. {
  609. if (tblConfig == null || tblConfig.Rows.Count == 0 || tblMaterial == null)
  610. {
  611. for (int i = 0; i < ultraGrid1.DisplayLayout.Bands[0].Columns.Count; i++)
  612. {
  613. try
  614. {
  615. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Tag = ultraGrid1.DisplayLayout.Bands[0].Columns[i].Key;
  616. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Caption = "";
  617. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Tag = "";
  618. }
  619. catch { }
  620. }
  621. }
  622. else
  623. {
  624. string strConfig = Convert.ToString(tblConfig.Rows[0]["CONFGCODE"]).Trim();
  625. string[] strCode = strConfig.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
  626. for (int i = 0; i < ultraGrid1.DisplayLayout.Bands[0].Columns.Count; i++)
  627. {
  628. try
  629. {
  630. if (i >= strCode.Length)
  631. {
  632. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Tag = ultraGrid1.DisplayLayout.Bands[0].Columns[i].Key;
  633. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Caption = "";
  634. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Tag = "";
  635. }
  636. else
  637. {
  638. rows = tblMaterial.Select("MATERIELCODE = '" + strCode[i].Trim() + "'");
  639. if (rows.Length > 0)
  640. {
  641. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Tag = Convert.ToString(rows[0]["MATERIELCODE"]); //保存物料编码
  642. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Caption = Convert.ToString(rows[0]["MATERIELFORSHORT"]); //保存物料简称
  643. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Tag = Convert.ToString(rows[0]["MATERIELTYPE"]); //保存物料类别
  644. }
  645. else
  646. {
  647. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Tag = ultraGrid1.DisplayLayout.Bands[0].Columns[i].Key;
  648. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Caption = "";
  649. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Header.Tag = "";
  650. }
  651. }
  652. }
  653. catch { }
  654. }
  655. }
  656. }
  657. }
  658. catch { }
  659. }
  660. public void ResetData()
  661. {
  662. ClsControlPack.ResetUltraDataSource(ultraDataSource1);
  663. }
  664. #endregion
  665. #region 相关属性设置响应
  666. private void SetEditable(bool Editable)
  667. {
  668. try
  669. {
  670. for (int i = 0; i < ultraGrid1.DisplayLayout.Bands[0].Columns.Count; i++)
  671. {
  672. try
  673. {
  674. ultraGrid1.DisplayLayout.Bands[0].Columns[i].CellActivation = (Editable ? Activation.AllowEdit : Activation.NoEdit);
  675. }
  676. catch { }
  677. }
  678. }
  679. catch { }
  680. }
  681. private void SetEditButton(bool ShowEditButton)
  682. {
  683. try
  684. {
  685. for (int i = 0; i < ultraGrid1.DisplayLayout.Bands[0].Columns.Count; i++)
  686. {
  687. try
  688. {
  689. if (ShowEditButton)
  690. {
  691. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.EditButton;
  692. }
  693. else
  694. {
  695. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Default;
  696. }
  697. }
  698. catch { }
  699. }
  700. }
  701. catch { }
  702. }
  703. #endregion
  704. #region 事件
  705. private void SetDelegate()
  706. {
  707. this.Resize += new System.EventHandler(this.ucAdditive_Resize);
  708. this.MainContainer.ExpandedStateChanged += new System.EventHandler(this.ExpandedStateChanged);
  709. this.ultraGrid1.DoubleClickHeader += new Infragistics.Win.UltraWinGrid.DoubleClickHeaderEventHandler(this.ultraGrid1_DoubleClickHeader);
  710. this.ultraGrid1.DoubleClickCell += new Infragistics.Win.UltraWinGrid.DoubleClickCellEventHandler(this.ultraGrid1_DoubleClickCell);
  711. this.ultraGrid1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ultraGrid1_KeyDown);
  712. this.ultraGrid1.ClickCellButton += new Infragistics.Win.UltraWinGrid.CellEventHandler(this.ultraGrid1_ClickCellButton);
  713. }
  714. private void ucAdditive_Resize(object sender, EventArgs e)
  715. {
  716. try
  717. {
  718. if (_Expandable && !_ExPanded)
  719. {
  720. this.Height = MainContainer.Height; //可收缩,处于收缩状态,不允许修改大小
  721. if (_ExPandedHeight == 0 && this.Parent != null) _ExPandedHeight = this.Parent.Height;
  722. }
  723. else if (_Expandable && _ExPanded) _ExPandedHeight = this.Height; //可收缩,处于展开状态,记录高度变化
  724. else if (!Expandable) _ExPandedHeight = this.Height; //不可收缩,记录高度变化
  725. }
  726. catch { }
  727. }
  728. private void ExpandedStateChanged(object sender, EventArgs e)
  729. {
  730. try
  731. {
  732. ExPanded = MainContainer.Expanded;
  733. if (MainContainer.Expanded) this.Height = _ExPandedHeight;
  734. else this.Height = MainContainer.Height;
  735. }
  736. catch { }
  737. }
  738. private void ultraGrid1_DoubleClickHeader(object sender, DoubleClickHeaderEventArgs e)
  739. {
  740. try
  741. {
  742. if (_HpprCategory == HopperCategory.Automatic)
  743. {
  744. frmSetHopper frm = new frmSetHopper(_DEVICE_POSITION, ob);
  745. frm.ShowDialog();
  746. if (this.SetHopper != null)
  747. this.Invoke(this.SetHopper);
  748. }
  749. else if (_HpprCategory == HopperCategory.Manual)
  750. {
  751. string strOriginal = ""; //原始物料编码
  752. if (Convert.ToString(e.Header.Column.Tag) != e.Header.Column.Key)
  753. strOriginal = Convert.ToString(e.Header.Column.Tag);
  754. string strName = Convert.ToString(e.Header.Caption); //物料名称
  755. frmSetMaterialName frm = new frmSetMaterialName(strName, "1", ob);
  756. frm.ShowDialog();
  757. if (frm.bChange)
  758. {
  759. string strMaterielCode = frm.m_szWLBM;
  760. try
  761. {
  762. ServerHelper.SetData("Core.LgMes.Server.LgDeviceManager.StlAdditive.UpdateInterFaceConfig",
  763. new object[]
  764. {
  765. new object[]
  766. {
  767. _DEVICE_POSITION, strOriginal, strMaterielCode
  768. }
  769. }, ob);
  770. if (this.SetHopper != null)
  771. this.Invoke(this.SetHopper);
  772. }
  773. catch (Exception ex)
  774. {
  775. if (ex is MESException)
  776. {
  777. }
  778. else
  779. MessageBox.Show("手投料物料配置失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  780. }
  781. }
  782. }
  783. }
  784. catch { }
  785. }
  786. private void ultraGrid1_KeyDown(object sender, KeyEventArgs e)
  787. {
  788. try
  789. {
  790. if (!_Editable) return;
  791. if (e.KeyCode != Keys.Enter || string.IsNullOrEmpty(_HeatProcessNo)) return; //回车、有生产任务
  792. UltraGridCell cell = ultraGrid1.ActiveCell;
  793. if (ultraGrid1.Rows.Count == 0 || cell == null || cell.Row.Index != 0) return; //行数异常
  794. if (Convert.ToString(cell.Column.Tag) == cell.Column.Key) return; //没有设置物料编码
  795. if (string.IsNullOrEmpty(cell.Column.Header.Caption)) return; //无物料名称
  796. string Value = cell.Text.Trim(); //V6投料量
  797. if (string.IsNullOrEmpty(Value))
  798. {
  799. MessageBox.Show("请输入消耗量!\n如果需要清空数据,请输入原有消耗量的负数。(如加料量为800,要清空此数值,请输入-800然后确认!)", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  800. cell.Activated = true;
  801. return;
  802. }
  803. if (!ClsDataAccessPack.CheckNumValidate(Value))
  804. {
  805. MessageBox.Show("不是有效的数值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  806. ultraGrid1.PerformAction(UltraGridAction.EnterEditMode);
  807. cell.Activated = true;
  808. return;
  809. }
  810. string TableName = ClsBusinessPack.GetTableName(_HeatProcessNo.Substring(0, 1), TableSort.Feeding); //V1表名
  811. string MaterielCode = Convert.ToString(cell.Column.Tag); //V3物料编码
  812. string MaterielType = Convert.ToString(cell.Column.Header.Tag); //V4物料类型
  813. string HopperID = cell.Column.Key; //V8料仓编号
  814. string strMsg = "";
  815. bool bSuccess = ClsBusinessPack.SaveAdditiveData(_HeatProcessNo, HopperID, MaterielType, MaterielCode, Value, _HpprCategory, out strMsg, ob);
  816. if (!bSuccess)
  817. {
  818. MessageBox.Show("数据保存失败!\n" + strMsg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  819. }
  820. else
  821. {
  822. ultraGrid1.PerformAction(UltraGridAction.ExitEditMode);
  823. }
  824. }
  825. catch { }
  826. }
  827. private void ultraGrid1_ClickCellButton(object sender, CellEventArgs e)
  828. {
  829. try
  830. {
  831. if (!_Editable || !_ShowCellButton || string.IsNullOrEmpty(_HeatProcessNo)) return;
  832. UltraGridCell cell = e.Cell;
  833. if (ultraGrid1.Rows.Count == 0 || cell == null || cell.Row.Index != 0) return; //行数异常
  834. if (Convert.ToString(cell.Column.Tag) == cell.Column.Key) return; //没有设置物料编码
  835. if (string.IsNullOrEmpty(cell.Column.Header.Caption)) return; //无物料名称
  836. frmInputDecimal frm = new frmInputDecimal(Convert.ToString(cell.Value));
  837. frm.Location = ClsControlPack.GetChildWindowLocation(frm.Size);
  838. if (frm.ShowDialog() == DialogResult.OK)
  839. {
  840. if (!frm.ValueChanged) return;
  841. string Value = frm.Value; //V6投料量
  842. if (string.IsNullOrEmpty(Value))
  843. {
  844. MessageBox.Show("请输入消耗量!\n如果需要清空数据,请输入原有消耗量的负数。(如加料量为800,要清空此数值,请输入-800然后确认!)", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  845. cell.Activated = true;
  846. return;
  847. }
  848. if (!ClsDataAccessPack.CheckNumValidate(Value))
  849. {
  850. MessageBox.Show("不是有效的数值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  851. ultraGrid1.PerformAction(UltraGridAction.EnterEditMode);
  852. cell.Activated = true;
  853. return;
  854. }
  855. string TableName = ClsBusinessPack.GetTableName(_HeatProcessNo.Substring(0, 1), TableSort.Feeding); //V1表名
  856. string MaterielCode = Convert.ToString(cell.Column.Tag); //V3物料编码
  857. string MaterielType = Convert.ToString(cell.Column.Header.Tag); //V4物料类型
  858. string HopperID = cell.Column.Key; //V8料仓编号
  859. string strMsg = "";
  860. bool bSuccess = ClsBusinessPack.SaveAdditiveData(_HeatProcessNo, HopperID, MaterielType, MaterielCode, Value, _HpprCategory, out strMsg, ob);
  861. if (!bSuccess)
  862. {
  863. MessageBox.Show("数据保存失败!\n" + strMsg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  864. }
  865. else
  866. {
  867. ultraGrid1.PerformAction(UltraGridAction.ExitEditMode);
  868. }
  869. }
  870. }
  871. catch { }
  872. }
  873. #endregion
  874. private void ultraGrid1_DoubleClickCell(object sender, DoubleClickCellEventArgs e)
  875. {
  876. try
  877. {
  878. if (_HeatProcessNo == "") return;
  879. string strOriginal = ""; //原始物料编码
  880. string HopperID = e.Cell.Column.Key.ToString(); //料斗号
  881. if (Convert.ToString(e.Cell.Column.Header.Column.Tag) != e.Cell.Column.Header.Column.Key)
  882. strOriginal = Convert.ToString(e.Cell.Column.Header.Column.Tag);
  883. if (strOriginal == "") return;
  884. string strName = Convert.ToString(e.Cell.Column.Header.Caption); //物料名称
  885. frmSelectWeight frm = new frmSelectWeight(ob);
  886. frm.HeatProcessNo = _HeatProcessNo;
  887. frm.MaterName = strName;
  888. frm.sWeight = e.Cell.Value.ToString();
  889. frm.ShowDialog();
  890. if (frm.flag)
  891. {
  892. string strErr = "";
  893. string strSqlID = "";
  894. //object[] sArgs = null;
  895. if (frm.Weight == "") return;
  896. //if (frm.isCancel)
  897. //{
  898. // strSqlID = "BofHJMater.Delete";
  899. // sArgs = new object[3];
  900. // sArgs[0] = frm.vProcessNo; //加热处理号
  901. // sArgs[1] = strOriginal; //物料编码
  902. // sArgs[2] = HopperID; //料斗号
  903. //}
  904. //else
  905. //{
  906. Hashtable ht = new Hashtable();
  907. strSqlID = "STL_JOB0015";
  908. ht.Add("I1", frm.vProcessNo); //加热处理号
  909. ht.Add("I2", _HeatProcessNo.Substring(5, 8)); //炉号
  910. ht.Add("I3", _HeatProcessNo.Substring(1, 2)); //岗位号
  911. ht.Add("I4", _HeatProcessNo.Substring(3, 2)); //处理次数
  912. ht.Add("I5", strOriginal); //物料编码
  913. ht.Add("I6", strName); //物料名称
  914. ht.Add("I7", frm.Weight); //物料重量
  915. ht.Add("I8", frm.VDate); //加料时间
  916. ht.Add("I9", HopperID); //料斗号
  917. ht.Add("I10", frm.Weightno); //计量单号
  918. ht.Add("I11", frm.isCancel?"2":"1"); //1为保存,2为取消
  919. ht.Add("O1", "");
  920. ht.Add("O2", "");
  921. // }
  922. try
  923. {
  924. //CommonClientToServer ccTs = new CommonClientToServer();
  925. //ccTs.ob = ob;
  926. //string strRCode = ccTs.ExecuteProcedureFunctions("Core.LgMes.Server.Common.ComDBProcedure",
  927. // "ExecProcWithCollParam", strSqlID, sArgs, out strErr);
  928. CommonClientToServer ccTs = new CommonClientToServer();
  929. ccTs.ob = ob;
  930. CoreClientParam ccp = ccTs.ExecuteProcedureFunctionsSqlID("Core.Mes.Server.Common.ComDataAccess",
  931. "executeProcedure", strSqlID, 5, ht, out strErr);
  932. if (strErr != "")
  933. {
  934. MessageBox.Show("操作失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  935. return;
  936. }
  937. else
  938. {
  939. //strErr = "";
  940. //strSqlID = "BofHJMater.StatusChange";
  941. //object[] sArgs1 = new object[6];
  942. //sArgs1[0] = frm.vProcessNo; //加热处理号
  943. //sArgs1[1] = _HeatProcessNo.Substring(5, 8); //炉号
  944. //sArgs1[2] = strOriginal; //物料编码
  945. //sArgs1[3] = strName; //物料名称
  946. //if (frm.isCancel)
  947. //{
  948. // sArgs1[4] = "2";
  949. //}
  950. //else
  951. //{
  952. // sArgs1[4] = "1";
  953. //}
  954. //sArgs1[5] = frm.Weightno; //计量编号
  955. //CommonClientToServer ccts = new CommonClientToServer();
  956. //ccts.ob = ob;
  957. //string Code = ccts.ExecuteProcedureFunctions("Core.LgMes.Server.Common.ComDBMcmsQuery",
  958. // "ExecProcWithCollParam", strSqlID, sArgs1, out strErr);
  959. MessageBox.Show("操作成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  960. }
  961. }
  962. catch { }
  963. }
  964. }
  965. catch { }
  966. }
  967. }
  968. /// <summary>
  969. /// 物料分类
  970. /// </summary>
  971. public enum MaterialCategory
  972. {
  973. /// <summary>
  974. /// 辅料
  975. /// </summary>
  976. FL,
  977. /// <summary>
  978. /// 合金
  979. /// </summary>
  980. HJ,
  981. /// <summary>
  982. /// 喂丝
  983. /// </summary>
  984. WS,
  985. /// <summary>
  986. /// 辅料 + 合金
  987. /// </summary>
  988. FL_HJ,
  989. /// <summary>
  990. /// 辅料 + 喂丝
  991. /// </summary>
  992. FL_WS,
  993. /// <summary>
  994. /// 合金 + 喂丝
  995. /// </summary>
  996. HJ_WS,
  997. /// <summary>
  998. /// 辅料 + 合金 + 合金
  999. /// </summary>
  1000. FL_HJ_WS
  1001. }
  1002. /// <summary>
  1003. /// 投料分类
  1004. /// </summary>
  1005. public enum HopperCategory : int
  1006. {
  1007. /// <summary>
  1008. /// 自动投料(系统采集)
  1009. /// </summary>
  1010. Automatic = 1,
  1011. /// <summary>
  1012. /// 手投料(人工录入)
  1013. /// </summary>
  1014. Manual = 2
  1015. }
  1016. }