FrmDisableTray.cs 3.9 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)
        {
            this.Close();
        }

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

        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))
                {
                    DialogResult dialogResult = MessageBox.Show("确定启用托盘【"+num+"】?", "提示?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (dialogResult.Equals(DialogResult.OK))
                    { 
                        LogUtil.info("用户手动启用托盘【" + num + "】");
                        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();
            }
        }
    }
}