123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- using System;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Collections.Generic;
- using UAS_MES_NEW.DataOperate;
- using UAS_MES_NEW.PublicMethod;
- namespace UAS_MES_NEW.SMT
- {
- public partial class SMT_MaterialsWaring : Form
- {
- AutoSizeFormClass asc = new AutoSizeFormClass();
- DataTable dt;
- DataHelper dh;
- SMT_WaringSetting setting;
- List<int> WaringRowIndex = new List<int>();
- LogStringBuilder sql = new LogStringBuilder();
- public SMT_MaterialsWaring()
- {
- InitializeComponent();
- }
- private void 用料预警_Load(object sender, EventArgs e)
- {
- dh = new DataHelper();
- asc.controllInitializeSize(this);
- }
- private void Setting_Click(object sender, EventArgs e)
- {
- DoSerach.Stop();
- setting = new SMT_WaringSetting();
- setting.Controls["Confirm"].Click += ConfirmClick;
- BaseUtil.SetFormCenter(setting);
- setting.ShowDialog();
- }
- private void ConfirmClick(object sender, EventArgs e)
- {
- string de_code = setting.Controls["de_code"].Text;
- sql.Clear();
- sql.Append("select dsl_devcode,ma_code,ma_qty,ma_madeqty from make left join devsmtlocation on dsl_makecode = ma_code");
- sql.Append(" left join device on dsl_devcode=de_code where dsl_devcode='"+de_code+"' and nvl( de_macode,' ')<>' ' ");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt.Rows.Count > 0)
- {
- BaseUtil.SetFormValue(this.Controls, dt);
- }
- else {
- BaseUtil.ShowError("机台:" + de_code + "未使用!");
- }
- //设置轮询的时间间隔,开启轮询
- DoSerach.Interval = int.Parse(setting.Controls["Cycle"].Text) * 1000;
- DoSerach.Tick += StartMonitor;
- DoSerach.Start();
- LoadData();
- }
- private void StartMonitor(object sender, EventArgs e)
- {
- LoadData();
- WaringRowIndex.Clear();
- for (int i = 0; i < SMTMaterialsDGV.RowCount; i++)
- {
- //单件事件
- int unitTime = int.Parse(setting.Controls["UnitTime"].Text);
- //提前预警
- int earlywaring = int.Parse(setting.Controls["UnitTime"].Text);
- //剩余数量
- int remainQTY = int.Parse(SMTMaterialsDGV.Rows[i].Cells["dsl_remainqty"].Value.ToString());
- if (unitTime * remainQTY < earlywaring * 60)
- {
- WaringRowIndex.Add(i);
- }
- }
- }
- private void LoadData()
- {
- string de_code = setting.Controls["de_code"].Text;
- sql.Clear();
- sql.Append("select dsl_fecode,dsl_barcode,dsl_prodcode,dsl_fespec,dsl_fecode,dsl_getqty,dsl_remainqty,dsl_needqty,dsl_baseqty,");
- sql.Append("dsl_table,dsl_location from makeCraft left join devsmtlocation on dsl_mcid=mc_id left join device on ");
- sql.Append("dsl_devcode=de_code where dsl_devcode='" + de_code + "' and dsl_status=0");
- BaseUtil.FillDgvWithDataTable(SMTMaterialsDGV, (DataTable)dh.ExecuteSql(sql.GetString(), "select"));
- }
- private void SMTMaterialsDGV_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
- {
- //如果用量不足的红色提示
- if (WaringRowIndex.Contains(e.RowIndex))
- {
- e.Graphics.FillRectangle(Brushes.Red, e.CellBounds);
- Rectangle border = e.CellBounds;
- border.Width -= 1;
- e.Graphics.DrawRectangle(Pens.White, border);
- e.PaintContent(e.CellBounds);
- e.Handled = true;
- }
- }
- private void 用料预警_SizeChanged(object sender, EventArgs e)
- {
- asc.controlAutoSize(this);
- }
- }
- }
|