FrmPosResult.cs 6.4 KB
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.XLRStore
{
    public partial class FrmPosResult : Form
    {
        public FrmPosResult()
        {
            CheckForIllegalCrossThreadCalls = false;
            boxEquip = StoreManager.XLRStore.boxEquip;
            DrawerResults = PosDebugResultManager.DrawerResults;
            InitializeComponent();
            LoadDrawerList();
            timer1.Enabled = true;
        }
        List<DrawerResult> DrawerResults;
        BoxEquip boxEquip;
        protected Dictionary<string, UCStatusPanel> PosControlList = new Dictionary<string, UCStatusPanel>();
        protected Dictionary<string, UCStatusPanel> DrawerControlList = new Dictionary<string, UCStatusPanel>();
        private void LoadDrawerList()
        {
            this.tlpDrawerA.RowStyles.Clear();
            this.tlpDrawerA.ColumnStyles.Clear();
            this.tlpDrawerA.CellBorderStyle = TableLayoutPanelCellBorderStyle.OutsetPartial;
            this.tlpDrawerA.RowCount = boxEquip.Config.Drawer_Rows;
            this.tlpDrawerA.ColumnCount = boxEquip.Config.Drawer_Columns;
            this.tlpDrawerA.Height = 40 * this.tlpDrawerA.RowCount;
            this.tlpDrawerA.Width = 90 * this.tlpDrawerA.ColumnCount;
            string cid = boxEquip.Config.CID;
            selectedDrawer = $"{cid}AA{"01"}{"01"}";
            for (int rowindex = 0; rowindex < boxEquip.Config.Drawer_Rows; rowindex++)
            {
                tlpDrawerA.RowStyles.Add(new RowStyle(SizeType.Absolute, 38));
                for (int colindex = 0; colindex < boxEquip.Config.Drawer_Columns; colindex++)
                {
                    tlpDrawerA.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 87));
                    UCStatusPanel control = new UCStatusPanel();
                    control.ControlName = $"{cid}AA{(rowindex + 1).ToString("00")}{(colindex + 1).ToString("00")}";
                    control.Click += Control_Click;
                    control.Dock = DockStyle.Fill;
                    this.tlpDrawerA.Controls.Add(control, colindex, rowindex);
                    DrawerControlList.Add(control.ControlName, control);
                }
            }

            this.tlpDrawerB.RowStyles.Clear();
            this.tlpDrawerB.ColumnStyles.Clear();
            this.tlpDrawerB.CellBorderStyle = TableLayoutPanelCellBorderStyle.OutsetPartial;
            this.tlpDrawerB.RowCount = boxEquip.Config.Drawer_Rows;
            this.tlpDrawerB.ColumnCount = boxEquip.Config.Drawer_Columns;
            this.tlpDrawerB.Height = 40 * this.tlpDrawerB.RowCount;
            this.tlpDrawerB.Width = 90 * this.tlpDrawerB.ColumnCount;
            for (int rowindex = 0; rowindex < boxEquip.Config.Drawer_Rows; rowindex++)
            {
                tlpDrawerB.RowStyles.Add(new RowStyle(SizeType.Absolute, 38));
                for (int colindex = 0; colindex < boxEquip.Config.Drawer_Columns; colindex++)
                {
                    tlpDrawerB.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 87));
                    UCStatusPanel control = new UCStatusPanel();
                    control.ControlName = $"{cid}BB{(rowindex + 1).ToString("00")}{(colindex + 1).ToString("00")}";
                    control.Click += Control_Click;
                    control.Dock = DockStyle.Fill;
                    this.tlpDrawerB.Controls.Add(control, colindex, rowindex);
                    DrawerControlList.Add(control.ControlName, control);
                }
            }

            this.tlpPos.RowStyles.Clear();
            this.tlpPos.ColumnStyles.Clear();
            this.tlpPos.CellBorderStyle = TableLayoutPanelCellBorderStyle.OutsetPartial;
            this.tlpPos.AutoScroll = true;
            this.tlpPos.RowCount = boxEquip.Config.Cols_In_Drawer;
            this.tlpPos.ColumnCount = boxEquip.Config.Rows_In_Drawer;
            this.tlpPos.Height = 40 * this.tlpPos.RowCount;
            this.tlpPos.Width = 90 * this.tlpPos.ColumnCount;
            for (int rowindex = 0; rowindex < boxEquip.Config.Cols_In_Drawer; rowindex++)
            {
                tlpPos.RowStyles.Add(new RowStyle(SizeType.Absolute, 38));
                for (int colindex = 0; colindex < boxEquip.Config.Rows_In_Drawer; colindex++)
                {
                    tlpPos.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 87));
                    UCStatusPanel control = new UCStatusPanel();
                    control.ControlName = $"{(colindex + 1).ToString("00")}{(rowindex + 1).ToString("00")}";
                    control.Dock = DockStyle.Fill;
                    this.tlpPos.Controls.Add(control, colindex, rowindex);
                    PosControlList.Add(control.ControlName, control);
                }
            }
            this.SuspendLayout();
        }

        private void Control_Click(object sender, EventArgs e)
        {
            UCStatusPanel statusPanel = sender as UCStatusPanel;
            if (statusPanel != null)
            {
                selectedDrawer = statusPanel.ControlName;
                UpdateInfosInDrawer(statusPanel.ControlName);
            }
        }
        public string selectedDrawer = "";
        private void UpdateInfosInDrawer(string drawername)
        {
            groupBox2.Text = $"{drawername}库位结果";
            foreach (var item in PosControlList.Values)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(drawername);
                sb.Append(item.ControlName);
                item.ResultCode = PosDebugResultManager.GetGridResult(sb.ToString());
                item.ShowResult();
            }
        }
        private void UpdateDrawerInfos()
        {
            foreach (var item in DrawerControlList.Values)
            {
                item.ResultCode = PosDebugResultManager.GetDrawerResult(item.ControlName);
                item.ShowResult();
            }
        }
        bool inUpdate = false;
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (inUpdate)
                return;
            inUpdate = true;
            UpdateDrawerInfos();
            if (!selectedDrawer.Equals(""))
                UpdateInfosInDrawer(selectedDrawer);
            inUpdate = false;
        }
    }
}