SMT_MaterialsWaring.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using System.Collections.Generic;
  7. using UAS_MES_NEW.DataOperate;
  8. using UAS_MES_NEW.PublicMethod;
  9. namespace UAS_MES_NEW.SMT
  10. {
  11. public partial class SMT_MaterialsWaring : Form
  12. {
  13. AutoSizeFormClass asc = new AutoSizeFormClass();
  14. DataTable dt;
  15. DataHelper dh;
  16. SMT_WaringSetting setting;
  17. List<int> WaringRowIndex = new List<int>();
  18. LogStringBuilder sql = new LogStringBuilder();
  19. public SMT_MaterialsWaring()
  20. {
  21. InitializeComponent();
  22. }
  23. private void 用料预警_Load(object sender, EventArgs e)
  24. {
  25. dh = new DataHelper();
  26. asc.controllInitializeSize(this);
  27. }
  28. private void Setting_Click(object sender, EventArgs e)
  29. {
  30. DoSerach.Stop();
  31. setting = new SMT_WaringSetting();
  32. setting.Controls["Confirm"].Click += ConfirmClick;
  33. BaseUtil.SetFormCenter(setting);
  34. setting.ShowDialog();
  35. }
  36. private void ConfirmClick(object sender, EventArgs e)
  37. {
  38. string de_code = setting.Controls["de_code"].Text;
  39. sql.Clear();
  40. sql.Append("select dsl_devcode,ma_code,ma_qty,ma_madeqty from make left join devsmtlocation on dsl_makecode = ma_code");
  41. sql.Append(" left join device on dsl_devcode=de_code where dsl_devcode='"+de_code+"' and nvl( de_macode,' ')<>' ' ");
  42. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  43. if (dt.Rows.Count > 0)
  44. {
  45. BaseUtil.SetFormValue(this.Controls, dt);
  46. }
  47. else {
  48. BaseUtil.ShowError("机台:" + de_code + "未使用!");
  49. }
  50. //设置轮询的时间间隔,开启轮询
  51. DoSerach.Interval = int.Parse(setting.Controls["Cycle"].Text) * 1000;
  52. DoSerach.Tick += StartMonitor;
  53. DoSerach.Start();
  54. LoadData();
  55. }
  56. private void StartMonitor(object sender, EventArgs e)
  57. {
  58. LoadData();
  59. WaringRowIndex.Clear();
  60. for (int i = 0; i < SMTMaterialsDGV.RowCount; i++)
  61. {
  62. //单件事件
  63. int unitTime = int.Parse(setting.Controls["UnitTime"].Text);
  64. //提前预警
  65. int earlywaring = int.Parse(setting.Controls["UnitTime"].Text);
  66. //剩余数量
  67. int remainQTY = int.Parse(SMTMaterialsDGV.Rows[i].Cells["dsl_remainqty"].Value.ToString());
  68. if (unitTime * remainQTY < earlywaring * 60)
  69. {
  70. WaringRowIndex.Add(i);
  71. }
  72. }
  73. }
  74. private void LoadData()
  75. {
  76. string de_code = setting.Controls["de_code"].Text;
  77. sql.Clear();
  78. sql.Append("select dsl_fecode,dsl_barcode,dsl_prodcode,dsl_fespec,dsl_fecode,dsl_getqty,dsl_remainqty,dsl_needqty,dsl_baseqty,");
  79. sql.Append("dsl_table,dsl_location from makeCraft left join devsmtlocation on dsl_mcid=mc_id left join device on ");
  80. sql.Append("dsl_devcode=de_code where dsl_devcode='" + de_code + "' and dsl_status=0");
  81. BaseUtil.FillDgvWithDataTable(SMTMaterialsDGV, (DataTable)dh.ExecuteSql(sql.GetString(), "select"));
  82. }
  83. private void SMTMaterialsDGV_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  84. {
  85. //如果用量不足的红色提示
  86. if (WaringRowIndex.Contains(e.RowIndex))
  87. {
  88. e.Graphics.FillRectangle(Brushes.Red, e.CellBounds);
  89. Rectangle border = e.CellBounds;
  90. border.Width -= 1;
  91. e.Graphics.DrawRectangle(Pens.White, border);
  92. e.PaintContent(e.CellBounds);
  93. e.Handled = true;
  94. }
  95. }
  96. private void 用料预警_SizeChanged(object sender, EventArgs e)
  97. {
  98. asc.controlAutoSize(this);
  99. }
  100. }
  101. }