FrmDisableTray.cs 5.8 KB
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OnlineStore.AssemblyLine
{
     partial class FrmDisableTray : FrmBase
    {
        public FrmDisableTray()
        {
            InitializeComponent();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            timer1.Stop();
            this.Close();
        }

        private void FrmDisableTray_Load(object sender, EventArgs e)
        {
            LoadList();
            timer1.Start();
            lblMsg.Text = "勾选开始处理托盘,禁用的托盘到达出料4后,会等待托盘启用后再放行\r\n关闭当前界面后,自动退出托盘处理";
        }

        private void LoadList()
        {
            dataGridView1.Rows.Clear();
            List<TrayDisableInfo> list = TrayDisableManager.GetDisableList();
            foreach (TrayDisableInfo t in list)
            {
                DataGridViewRow view = new DataGridViewRow();
                view.CreateCells(dataGridView1);
                view.Cells[Column_trayNum.Index].Value = t.TrayCode;
                view.Cells[Column_DeviceName.Index].Value = t.DDeviceName;
                view.Cells[Column_describle.Index].Value = t.DDescribe;
                view.Cells[Column_datetime.Index].Value =t.DisableTime.ToString("yyyy-MM-dd HH:mm:ss");
                TrayInfo tray = TrayManager.GetTrayInfo(t.TrayCode);
                string trayInfo = "";
                if (tray.InOrOutStore.Equals(0))
                {
                    trayInfo = "空托盘";
                }
                else if (tray.InOrOutStore.Equals(1))
                {
                    if (tray.InoutPar.InStoreNg)
                    { 
                        trayInfo = $"入库NG[{tray.InoutPar.NgMsg}][{tray.InoutPar.WareCode}][{tray.InoutPar.PosId}]";
                    }
                    else
                    {
                        trayInfo = $"入库[{tray.InoutPar.WareCode}][{tray.InoutPar.PosId}]";
                    }
                }
                else if (tray.InOrOutStore.Equals(2))
                {
                    trayInfo = $"出库[{tray.InoutPar.WareCode}][{tray.InoutPar.PosId}]";
                }
                view.Cells[Column_TrayInfo.Index].Value = trayInfo; 
                dataGridView1.Rows.Add(view);
            }
            lblTrayInfo.Text = "";
        }

        private void btnrefresh_Click(object sender, EventArgs e)
        { 
            LoadList();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex != -1 && e.ColumnIndex >= 0)
            {
                string name = this.dataGridView1.Columns[e.ColumnIndex].Name;
                int num = Convert.ToInt32(this.dataGridView1.Rows[e.RowIndex].Cells[Column_trayNum.Index].Value);
                int rowIndex = e.RowIndex;
                if (name.Equals(this.Column_Del.Name))
                {
                    TrayInfo tray = TrayManager.GetTrayInfo(num);
                    string msg =  "启用托盘将清空托盘信息,确定启用托盘【" + num + "】?";

                    DialogResult dialogResult = MessageBox.Show(msg, "提示?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (dialogResult.Equals(DialogResult.OK))
                    {
                        LogUtil.info("用户手动启用托盘【" + num + "】" + tray.ToStr());
                        if (tray.IsFull && tray.InOrOutStore.Equals(1))
                        {
                            TrayManager.ClearInstore(tray,"清理禁用托盘");
                        }
                        TrayDisableManager.RemoveDisable(num);
                        this.dataGridView1.Rows.RemoveAt(rowIndex);

                        lblTrayInfo.Text = "";
                    }
                }
            }
        }

        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                DataGridViewRow row = dataGridView1.SelectedRows[0];
                int num = Convert.ToInt32(row.Cells[Column_trayNum.Index].Value);
                TrayInfo tray = TrayManager.GetTrayInfo(num);
               
                lblTrayInfo.Text = tray.ToStr();
            }
        }

        private void chbProTray_CheckedChanged(object sender, EventArgs e)
        {
            TrayDisableManager.ProcessTray = chbProTray.Checked;
            LogUtil.info("用户更改" + chbProTray.Text + "=" + chbProTray.Checked);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (this.Visible)
            {
                try
                {
                    ProvidingEquip pro4 = LineManager.Line.ProvidingEquipMap[204];
                    if(pro4.WarnMsg.Contains(  TrayDisableManager.ProWarnMsg))
                    {
                        lblPro4Warnmsg.Text = pro4.WarnMsg;
                    }else
                    {
                        lblPro4Warnmsg.Text = "";
                    }
                }catch (Exception ex)
                {
                    LogUtil.error("FrmDisableTray timer1_Tick error:" + ex.ToString());
                }
            }
        }

        private void group3_Enter(object sender, EventArgs e)
        {

        }

        private void FrmDisableTray_FormClosed(object sender, FormClosedEventArgs e)
        {
            TrayDisableManager.ProcessTray = false;

            LogUtil.info("退出禁用托盘处理界面," + chbProTray.Text + "=false" );
        }
    }
}