FrmCodeInPut.cs 4.8 KB
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;
using TSA_V.Common;
using TSA_V.DeviceLibrary;

namespace TSA_V
{
    public partial class FrmCodeInPut : FrmBase
    {
        private int CodeNum = 0;
        public string PCBCode = "";
        public List<string> CodeList = new List<string>();
        public FrmCodeInPut()
        {
            InitializeComponent();
        }
        private List<TextBox> LittleTextList = new List<TextBox>();
        private void FrmCodeInPut_Load(object sender, EventArgs e)
        {
            SetScreen();
            txtPCBCode.Focus();
        }
        public void SetCount(int count)
        {
            CodeNum = count;
            if (CodeNum <= 0)
            {
                this.Size = new Size(630, 360);
            }
            else
            {
                int width = 48;
                for (int i = 1; i <= CodeNum; i++)
                {
                    int addWidth = i * width;
                    Label lblName = new Label();
                    lblName.AutoSize = false;
                    lblName.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                    lblName.Location = new System.Drawing.Point(13, 74 + addWidth);
                    lblName.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
                    lblName.Name = "lblName" + i.ToString();
                    lblName.Size = new System.Drawing.Size(201, 21);
                    lblName.TextAlign = ContentAlignment.MiddleRight;
                    lblName.TabIndex = 10 + i;
                    lblName.Text = "PCB小板_" + i.ToString() + "条码:";
                    this.Controls.Add(lblName);

                    TextBox txtLittlePCB = new TextBox();
                    txtLittlePCB.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                    txtLittlePCB.Location = new System.Drawing.Point(222, 21 + addWidth);
                    txtLittlePCB.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
                    txtLittlePCB.MaxLength = 100;
                    txtLittlePCB.Name = "txtPCBCode" + i.ToString();
                    txtLittlePCB.Size = new System.Drawing.Size(306, 29);
                    txtLittlePCB.TabIndex = 100 + i;
                    LittleTextList.Add(txtLittlePCB);
                    this.Controls.Add(txtLittlePCB);
                }
                this.Size = new Size(630, 360 + width * CodeNum);
                btnContinue.Location = new Point(btnContinue.Location.X, btnContinue.Location.Y + width * CodeNum);
                btnCancel.Location = new Point(btnCancel.Location.X, btnCancel.Location.Y + width * CodeNum);
            }
        }
        private void btnContinue_Click(object sender, EventArgs e)
        {
            PCBCode = FormUtil.getValue(txtPCBCode);
            if (String.IsNullOrEmpty( PCBCode ))
            {
                MessageBox.Show(ResourceCulture.GetString("请输入PCB板条码"));
                txtPCBCode.Focus();
                return;
            }

            if (CodeNum > 0)
            {
                CodeList = new List<string>();
                int i = 1;
                foreach (TextBox text in LittleTextList)
                {
                    string code = FormUtil.getValue(text);
                    if (String.IsNullOrEmpty(PCBCode))
                    {
                        MessageBox.Show("请输入PCB小板_" + i + "条码");
                        txtPCBCode.Focus();
                        return;
                    }
                    CodeList.Add(code);
                    i++;
                }
            }

            MesUtil.SetCode(PCBCode, CodeList);
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            PCBCode = "";
            this.Close();
        }

        private void FrmCodeInPut_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MesUtil.CodeISOk.Equals(false))
            {
                DialogResult result = MessageBox.Show(ResourceCulture.GetString("确定取消条码输入?"), ResourceCulture.GetString("取消条码输入"), MessageBoxButtons.OKCancel);
                if (result.Equals(DialogResult.OK))
                {
                    MesUtil.SetCode("", new List<string>());
                }
                else
                {
                    e.Cancel = true;
                }
            }
        }

        private void FrmCodeInPut_Shown(object sender, EventArgs e)
        {
            this.txtPCBCode.Focus();
        }
    }
}