using PaintingPC.Model;
using PaintingPC.WebReference;
using System;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;

namespace PaintingPC
{
    public partial class FrmFirstCheck : Form
    {
        public delegate void SideButtonDelegate(object sender);
        private static SideButtonDelegate method;

        //静态变量
        #region 抛光
        /// <summary>
        /// 缺陷部位
        /// </summary>
        public static string damnPosition1 = "";
        /// <summary>
        /// 原因
        /// </summary>
        public static string reason1 = "";
        /// <summary>
        /// 缺陷部位
        /// </summary>
        public static string damnPosition2 = "";
        /// <summary>
        /// 原因
        /// </summary>
        public static string reason2 = ""; 
        #endregion

        #region 报废
        /// <summary>
        /// 报废-缺陷部位
        /// </summary>
        public static string abt_damnPosition1 = "";
        /// <summary>
        /// 报废-原因
        /// </summary>
        public static string abt_reason1 = "";
        /// <summary>
        /// 报废-缺陷部位
        /// </summary>
        public static string abt_damnPosition2 = "";
        /// <summary>
        /// 报废-原因
        /// </summary>
        public static string abt_reason2 = ""; 
        #endregion

        #region 修改颜色

        public static string ColorName = "";

        #endregion

        /// <summary>
        /// 当前滑撬号
        /// </summary>
        public static string skid_No = "";
        static DateTime lighttimerStart = Convert.ToDateTime("2019-01-01 00:00:00");

        public FrmFirstCheck()
        {
            InitializeComponent();
        }

        private void FrmFirstCheck_Load(object sender, EventArgs e)
        {
            Control.CheckForIllegalCrossThreadCalls = false;
            InitPage();
        }

        public void InitPage()
        {
            try
            {
                string title = ConfigurationManager.AppSettings["Position"].ToString();
                string station = ConfigurationManager.AppSettings["Station"].ToString();

                labTitle.Text = title;
                labWorkClass.Text = Function.GetWorkClass();
                labStation.Text = station;
                labelVersion.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

                Program.IP = ConfigurationManager.AppSettings["IP"].ToString();

                ClearStaticString();

                //滑撬号初始值
                txtSideNo.Text = ConfigurationManager.AppSettings["SkidNoStart"].ToString();
                btnSide_Click((object)1, new EventArgs());

                //System.Threading.Timer timer = new System.Threading.Timer(delegate
                //{
                //    labTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                //},
                //null,
                //2000,
                //1000
                //);

                Thread t = new Thread(new ThreadStart(TimeGo));
                t.Start();

                Thread t2 = new Thread(new ThreadStart(LightTimerGo));
                t2.Start();
            }
            catch (Exception ex)
            { }
        }

        private void TimeGo()
        {
            System.Timers.Timer timer = new System.Timers.Timer();
            timer.Interval = 10;
            timer.Enabled = true;
            timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Tick);
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            labTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            Thread.Sleep(500);
        }

        private void LightTimerGo()
        {
            System.Timers.Timer LightTimer = new System.Timers.Timer();
            LightTimer.Interval = 100;
            LightTimer.Enabled = true;
            LightTimer.Elapsed += new System.Timers.ElapsedEventHandler(LightTimer_Tick);
        }

        private void sideBtnMethod(object sender)
        {
            Button btn = sender as Button;
            txtSideNo.Text += btn.Text;
        }

        /// <summary>
        /// 清空页面
        /// </summary>
        public void ClearPage()
        {
            #region 清空页面

            labXingHao1.Text = "";
            labXingHao2.Text = "";
            labColor1.Text = "";
            labColor2.Text = "";
            labBarCode1.Text = "";
            labBarCode2.Text = "";
            labColor1.Tag = "";
            labColor2.Tag = "";
            labDefect1.Text = "";
            labDefect2.Text = "";

            #region 抛光
            damnPosition1 = "";
            reason1 = "";
            damnPosition2 = "";
            reason2 = ""; 
            #endregion

            #region 报废
            /// <summary>
            /// 报废-缺陷部位
            /// </summary>
            abt_damnPosition1 = "";
            /// <summary>
            /// 报废-原因
            /// </summary>
            abt_reason1 = "";
            /// <summary>
            /// 报废-缺陷部位
            /// </summary>
            abt_damnPosition2 = "";
            /// <summary>
            /// 报废-原因
            /// </summary>
            abt_reason2 = "";
            #endregion

            #region 修改颜色

            ColorName = "";

            #endregion

            #region 清空选择按钮

            ClearControlColor(SetControlGroup1());
            ClearControlColor(SetControlGroup2());

            #endregion

            #endregion
        }

        /// <summary>
        /// 清空静态字段值
        /// </summary>
        public void ClearStaticString()
        {
            #region 抛光
            damnPosition1 = "";
            reason1 = "";
            damnPosition2 = "";
            reason2 = "";
            #endregion

            #region 报废
            /// <summary>
            /// 报废-缺陷部位
            /// </summary>
            abt_damnPosition1 = "";
            /// <summary>
            /// 报废-原因
            /// </summary>
            abt_reason1 = "";
            /// <summary>
            /// 报废-缺陷部位
            /// </summary>
            abt_damnPosition2 = "";
            /// <summary>
            /// 报废-原因
            /// </summary>
            abt_reason2 = "";
            #endregion

            #region 修改颜色

            ColorName = "";

            #endregion
        }

        #region 滑撬号数字按钮
        private void btnSide1_Click(object sender, EventArgs e)
        {
            method = new SideButtonDelegate(sideBtnMethod);
            method(sender);
        }

        private void btnSide2_Click(object sender, EventArgs e)
        {
            method = new SideButtonDelegate(sideBtnMethod);
            method(sender);
        }

        private void btnSide3_Click(object sender, EventArgs e)
        {
            method = new SideButtonDelegate(sideBtnMethod);
            method(sender);
        }

        private void btnSide4_Click(object sender, EventArgs e)
        {
            method = new SideButtonDelegate(sideBtnMethod);
            method(sender);
        }

        private void btnSide5_Click(object sender, EventArgs e)
        {
            method = new SideButtonDelegate(sideBtnMethod);
            method(sender);
        }

        private void btnSide6_Click(object sender, EventArgs e)
        {
            method = new SideButtonDelegate(sideBtnMethod);
            method(sender);
        }

        private void btnSide7_Click(object sender, EventArgs e)
        {
            method = new SideButtonDelegate(sideBtnMethod);
            method(sender);
        }

        private void btnSide8_Click(object sender, EventArgs e)
        {
            method = new SideButtonDelegate(sideBtnMethod);
            method(sender);
        }

        private void btnSide9_Click(object sender, EventArgs e)
        {
            method = new SideButtonDelegate(sideBtnMethod);
            method(sender);
        }

        private void btnSide10_Click(object sender, EventArgs e)
        {
            method = new SideButtonDelegate(sideBtnMethod);
            method(sender);
        }

        private void btnSideBack_Click(object sender, EventArgs e)
        {
            string txt = txtSideNo.Text;
            if (!string.IsNullOrWhiteSpace(txt))
            {
                txt = txt.Remove(txt.Length - 1, 1);
                txtSideNo.Text = txt;
            }
        }

        #endregion

        /// <summary>
        /// 根据滑撬号获取条码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSide_Click(object sender, EventArgs e)
        {
            try
            {
                ClearPage();

                string sideNo = txtSideNo.Text.Trim();
                if (!string.IsNullOrWhiteSpace(sideNo))
                {

                    #region 获取AB,上中下

                    string side = "";
                    string title = ConfigurationManager.AppSettings["Position"].Trim();
                    if (title.Contains("A"))
                    {
                        side = "Side_1_BC01";
                    }
                    else
                    {
                        side = "Side_2_BC01";
                    }

                    #endregion

                    #region 根据滑撬号查找颜色,判断产品转几圈,一圈的获取第一个条码(多圈的获取下面有数据的行),看是几层, 获取要取的side_1_BC0X

                    int circle = Function.GetCircle(sideNo);
                    string no = "";
                    no = Function.GetForeignBarCode(sideNo, side, circle);   //获取条码
                     
                    string sideBCstring = Function.GetForeignBCString(no, title);   //获取BC列名

                    #endregion

                    #region 去老外库获取条码,获取页面信息

                    string Side_BC_1 = "";
                    string Side_BC_2 = "";

                    if (!string.IsNullOrWhiteSpace(sideBCstring))
                    {
                        string[] str = sideBCstring.Split(';');
                        if (str.Length > 1)
                        {
                            Side_BC_1 = str[0].Trim();
                            Side_BC_2 = str[1].Trim();
                        }
                        else
                        {
                            Side_BC_1 = str[0].Trim();
                        }
                    }

                    #endregion

                    label7.Text = Side_BC_1;
                    label9.Text = Side_BC_2;
                    labBarCode1.Text = Function.GetForeignBarCode(sideNo, Side_BC_1, circle);
                    labBarCode2.Text = Function.GetForeignBarCode(sideNo, Side_BC_2, circle);
                }
                else
                {
                    labBarCode1.Text = "";
                    labBarCode2.Text = "";
                }

                #region 查询外国数据库获取颜色

                string colorInfo = "";
                string colorName = Function.GetForeignDataColor(sideNo, out colorInfo);
                if (!string.IsNullOrWhiteSpace(colorName))
                {
                    if (!string.IsNullOrWhiteSpace(labBarCode1.Text))
                    {
                        labColor1.Text = colorName;
                    }
                    if (!string.IsNullOrWhiteSpace(labBarCode2.Text))
                    {
                        labColor2.Text = colorName;
                    }
                }
                else
                {
                    labColor1.Text = "";
                    labColor2.Text = "";
                }

                if (!string.IsNullOrWhiteSpace(colorInfo))
                {
                    labColor1.Tag = colorInfo;
                    labColor2.Tag = colorInfo;
                }
                else
                {
                    labColor1.Tag = "";
                    labColor2.Tag = "";
                }


                #endregion

                #region 方案2:如果老外库里取不到条码和颜色,读取扫描的滑撬号和条码号

                //if (string.IsNullOrWhiteSpace(labBarCode1.Text.Trim()) || string.IsNullOrWhiteSpace(labBarCode2.Text.Trim()))
                if (string.IsNullOrWhiteSpace(labBarCode1.Text.Trim()))
                {
                    string bcStrs = "";
                    DataTable dtBarCode = Function.GetMesBarCode(labTitle.Text.Trim(), txtSideNo.Text.Trim(), out bcStrs);
                    if (dtBarCode != null && dtBarCode.Rows.Count > 0)
                    {
                        if (!string.IsNullOrWhiteSpace(bcStrs))
                        {
                            string[] bcStr = bcStrs.Split(';');
                            if (bcStr.Length >= 1)
                            {
                                string colName = bcStr[0];
                                label7.Text = colName;
                                labBarCode1.Text = dtBarCode.Rows[0][colName].ToString().Trim();

                                #region 颜色1
                                if (string.IsNullOrWhiteSpace(labColor1.Text))
                                {
                                    string color = dtBarCode.Rows[0]["ColorInfo"].ToString();
                                    labColor1.Tag = color;
                                    if (!string.IsNullOrWhiteSpace(color))
                                    {
                                        string[] colStr = color.Split(',');
                                        if (colStr.Length > 1)
                                        {
                                            labColor1.Text = colStr[0];
                                        }
                                    } 
                                }
                                
                                #endregion
                            }
                            if (bcStr.Length >= 2)
                            {
                                string colName = bcStr[1];
                                label9.Text = colName;
                                labBarCode2.Text = dtBarCode.Rows[0][colName].ToString().Trim();

                                #region 颜色2

                                if (string.IsNullOrWhiteSpace(labColor2.Text))
                                {
                                    string color = dtBarCode.Rows[0]["ColorInfo"].ToString();
                                    labColor2.Tag = color;
                                    if (!string.IsNullOrWhiteSpace(color))
                                    {
                                        string[] colStr = color.Split(',');
                                        if (colStr.Length > 1)
                                        {
                                            labColor2.Text = colStr[0];
                                        }
                                    } 
                                }
                                
                                #endregion
                            }
                        }
                    } 
                }
                #endregion

                #region 获得第一个型号名称

                string stockNo = "";
                string batchNo = "";
                string partNo = "";
                Function.GetCode(labBarCode1.Text.Trim(), out stockNo, out batchNo, out partNo);

                {
                    string productName = "";
                    Function.GetInfoByStockNo(stockNo, partNo, out productName);
                    labXingHao1.Text = productName;
                }


                #endregion

                #region 获得第二个型号名称

                stockNo = "";
                batchNo = "";
                partNo = "";
                Function.GetCode(labBarCode2.Text.Trim(), out stockNo, out batchNo, out partNo);
                {
                    string productName = "";
                    Function.GetInfoByStockNo(stockNo, partNo, out productName);
                    labXingHao2.Text = productName;

                }

                #endregion

                #region 控制按钮是否可点选

                ButtonDisable();

                #endregion
            }
            catch (Exception ex)
            {
                LogHelper.WriteErrLogBase("喷涂一检滑撬号获取:" + ex.ToString(), MethodBase.GetCurrentMethod().Name);
            }
        }

        #region 设置控件是否选中的颜色

        /// <summary>
        /// 设置控件颜色,是否选中
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="Chose"></param>
        /// <param name="NoChose"></param>
        public void ColorMethod(object sender, Color Chose, Color NoChose)
        {
            Button btn = sender as Button;
            if (btn.BackColor != Chose)
            {
                btn.BackColor = Chose;
                btnSubmit.BackColor = Color.GreenYellow;

                if (lighttimerStart.ToString() == "2019-01-01 00:00:00")
                {
                    lighttimerStart = DateTime.Now;
                }
                //Thread t = new Thread(new ThreadStart(LightTimerStart));
                //t.Start();
            }
            else
            {
                btn.BackColor = NoChose;
                btnSubmit.BackColor = Color.FromArgb(192, 192, 255);
            }
        }

        private void LightTimer_Tick(object sender, EventArgs e)
        {
            if (lighttimerStart.ToString() != "2019-01-01 00:00:00")
            {
                TimeSpan span = DateTime.Now.Subtract(lighttimerStart);
                if (span.Seconds >= 60)
                {
                    if (labTitle.BackColor == Color.LightGray)
                    {
                        labTitle.BackColor = Color.Red;
                    }
                    else
                    {
                        labTitle.BackColor = Color.LightGray;
                    }
                }
            }
        }

        /// <summary>
        /// 清除控件选中
        /// </summary>
        /// <param name="controls"></param>
        public void ClearControlColor(Control[] controls)
        {
            foreach (Control c in controls)
            {
                c.BackColor = Color.LightGray;
            }
        }

        private Control[] SetControlGroup1()
        { 
            Control[] controls = { btnPass1, btnAbt1, btnRepair1 };
            return controls;
        }
        private Control[] SetControlGroup2()
        {
            Control[] controls = { btnPass2, btnAbt2, btnRepair2 };
            return controls;
        }

        private void ButtonDisable()
        {
            if (string.IsNullOrWhiteSpace(labBarCode1.Text.Trim()))
            {
                btnPass1.Enabled = false;
                btnAbt1.Enabled = false;
                btnRepair1.Enabled = false;
            }
            else
            {
                btnPass1.Enabled = true;
                btnAbt1.Enabled = true;
                btnRepair1.Enabled = true;
            }

            if (string.IsNullOrWhiteSpace(labBarCode2.Text.Trim()))
            {
                btnPass2.Enabled = false;
                btnAbt2.Enabled = false;
                btnRepair2.Enabled = false;
            }
            else
            {
                btnPass2.Enabled = true;
                btnAbt2.Enabled = true;
                btnRepair2.Enabled = true;
            }
        }

        private void btnPass1_Click(object sender, EventArgs e)
        {
            ClearControlColor(SetControlGroup1());
            ColorMethod(sender, Color.GreenYellow, Color.LightGray);
        }

        private void btnPass2_Click(object sender, EventArgs e)
        {
            ClearControlColor(SetControlGroup2());
            ColorMethod(sender, Color.GreenYellow, Color.LightGray);
        }

        private void btnAbt1_Click(object sender, EventArgs e)
        {
            ClearControlColor(SetControlGroup1());
            ColorMethod(sender, Color.Red, Color.LightGray);

            abt_damnPosition1 = "";
            abt_reason1 = "";

            string barcode = labBarCode1.Text.Trim();
            FrmChooseDamnPosition frm = new FrmChooseDamnPosition(barcode);
            frm.ShowDialog();
            abt_damnPosition1 = FrmChooseDamnPosition.DamnPosition;
            abt_reason1 = FrmChooseDamnPosition.Reason;

            labDefect1.Text = ConcatDefect("[报废]", abt_damnPosition1, abt_reason1);
        }

        private void btnAbt2_Click(object sender, EventArgs e)
        {
            ClearControlColor(SetControlGroup2());
            ColorMethod(sender, Color.Red, Color.LightGray);

            abt_damnPosition2 = "";
            abt_reason2 = "";

            string barcode = labBarCode1.Text.Trim();
            FrmChooseDamnPosition frm = new FrmChooseDamnPosition(barcode);
            frm.ShowDialog();
            abt_damnPosition2 = FrmChooseDamnPosition.DamnPosition;
            abt_reason2 = FrmChooseDamnPosition.Reason;

            labDefect2.Text = ConcatDefect("[报废]", abt_damnPosition2, abt_reason2);
        }

        private void btnRepair1_Click(object sender, EventArgs e)
        {
            damnPosition1 = "";
            reason1 = "";

            ClearControlColor(SetControlGroup1());
            ColorMethod(sender, Color.Yellow, Color.LightGray);

            string barcode = labBarCode1.Text.Trim();
            FrmChooseDamnPosition frm = new FrmChooseDamnPosition(barcode);
            frm.ShowDialog();
            damnPosition1 = FrmChooseDamnPosition.DamnPosition;
            reason1 = FrmChooseDamnPosition.Reason;

            labDefect1.Text = ConcatDefect("[抛光]", damnPosition1, reason1); 
        }

        private void btnRepair2_Click(object sender, EventArgs e)
        {
            damnPosition2 = "";
            reason2 = "";

            ClearControlColor(SetControlGroup2());
            ColorMethod(sender, Color.Yellow, Color.LightGray);

            string barcode = labBarCode2.Text.Trim();
            FrmChooseDamnPosition frm = new FrmChooseDamnPosition(barcode);
            frm.ShowDialog();
            damnPosition2 = FrmChooseDamnPosition.DamnPosition;
            reason2 = FrmChooseDamnPosition.Reason;

            labDefect2.Text = ConcatDefect("[抛光]", damnPosition2, reason2);
        }

        private string ConcatDefect(string str1, string str2, string str3)
        {
            if (!string.IsNullOrWhiteSpace(str2) && !string.IsNullOrWhiteSpace(str3))
            {
                return str1 + str2 + ":" + str3 + " ";
            }
            else
            {
                return "";
            }
        }

        #endregion

        /// <summary>
        /// 提交
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                InspectModel model1 = new InspectModel();
                InspectModel model2 = new InspectModel();

                #region 有条码的必须进行点选,否则不允许提交

                if (!string.IsNullOrWhiteSpace(labBarCode1.Text))
                {
                    if (btnPass1.BackColor == Color.LightGray && btnRepair1.BackColor == Color.LightGray && btnAbt1.BackColor == Color.LightGray)
                    {
                        MessageBox.Show("条码:" + labBarCode1.Text.Trim() + "没有录入质检结果,不能提交,请补全!");
                        return;
                    }
                }
                if (!string.IsNullOrWhiteSpace(labBarCode2.Text))
                {
                    if (btnPass2.BackColor == Color.LightGray && btnRepair2.BackColor == Color.LightGray && btnAbt2.BackColor == Color.LightGray)
                    {
                        MessageBox.Show("条码:" + labBarCode2.Text.Trim() + "没有录入质检结果,不能提交,请补全!");
                        return;
                    }
                }

                #endregion

                #region 保存Side_1_BC05

                if (!string.IsNullOrWhiteSpace(labBarCode1.Text.Trim()))
                {
                    LogHelper.WriteSysLogBase("条码:" + labBarCode1.Text.Trim() + "准备存入Inspect表", MethodBase.GetCurrentMethod().Name);

                    if (btnPass1.BackColor == Color.LightGray && btnRepair1.BackColor == Color.LightGray && btnAbt1.BackColor == Color.LightGray)
                    {
                        MessageBox.Show("请录入检验结果!");
                        return;
                    }
                    model1.ID = Guid.NewGuid().ToString();
                    model1.barcode = labBarCode1.Text.Trim();

                    string[] strs = labTitle.Text.Trim().Split(' ');
                    if (strs.Length >= 3)
                    {
                        model1.side = strs[1].Trim(); 
                    }

                    model1.position = labTitle.Text.Trim();
                    model1.stationNo = labStation.Text;
                    model1.workClass = labWorkClass.Text;

                    if (btnPass1.BackColor != Color.LightGray && btnAbt1.BackColor == Color.LightGray && btnRepair1.BackColor == Color.LightGray)
                    {
                        model1.inspectResult = "[合格]";
                    }
                    if (btnPass1.BackColor == Color.LightGray && btnAbt1.BackColor != Color.LightGray && btnRepair1.BackColor == Color.LightGray)
                    {
                        model1.inspectResult = "[报废]";
                        model1.damnPosition = abt_damnPosition1;
                        model1.reason = abt_reason1;

                        if (string.IsNullOrWhiteSpace(model1.damnPosition) || string.IsNullOrWhiteSpace(model1.reason))
                        {
                            MessageBox.Show("必须选择报废位置及报废原因!");
                            return;
                        }
                    }
                    if (btnPass1.BackColor == Color.LightGray && btnAbt1.BackColor == Color.LightGray && btnRepair1.BackColor != Color.LightGray)
                    {
                        model1.inspectResult = "[抛光]";
                        model1.damnPosition = damnPosition1;
                        model1.reason = reason1;

                        if (string.IsNullOrWhiteSpace(model1.damnPosition) || string.IsNullOrWhiteSpace(model1.reason))
                        {
                            MessageBox.Show("必须选择抛光位置及抛光原因!");
                            return;
                        }
                    }

                    if (rdo1.Checked)
                    {
                        model1.productOption = "1";
                    }
                    else if (rdo2.Checked)
                    {
                        model1.productOption = "2";
                    }
                    else if (rdo3.Checked)
                    {
                        model1.productOption = "3";
                    }

                    model1.productInfo = labColor1.Tag.ToString().Trim() + "," + labXingHao1.Text.Trim();
                    model1.InspectTimes = "1";

                    if (!string.IsNullOrWhiteSpace(model1.barcode))
                    {
                        Function.InsertInspect(model1);
                    }

                    LogHelper.WriteSysLogBase("条码:" + model1.barcode + "存入Inspect表完毕", MethodBase.GetCurrentMethod().Name);
                }
                

                #endregion

                #region 保存Side_1_BC06

                if (!string.IsNullOrWhiteSpace(labBarCode2.Text.Trim()))
                {
                    LogHelper.WriteSysLogBase("条码:" + labBarCode2.Text.Trim() + "准备存入Inspect表", MethodBase.GetCurrentMethod().Name);

                    if (btnPass2.BackColor == Color.LightGray && btnRepair2.BackColor == Color.LightGray && btnAbt2.BackColor == Color.LightGray)
                    {
                        MessageBox.Show("请录入检验结果!");
                        return;
                    }

                    model2.ID = Guid.NewGuid().ToString();
                    model2.barcode = labBarCode2.Text.Trim();

                    string[] strss = labTitle.Text.Trim().Split(' ');
                    if (strss.Length >= 3)
                    {
                        model2.side = strss[1].Trim();
                    }

                    model2.position = labTitle.Text.Trim();
                    model2.stationNo = labStation.Text;
                    model2.workClass = labWorkClass.Text;

                    if (btnPass2.BackColor != Color.LightGray && btnAbt2.BackColor == Color.LightGray && btnRepair2.BackColor == Color.LightGray)
                    {
                        model2.inspectResult = "[合格]";
                    }
                    if (btnPass2.BackColor == Color.LightGray && btnAbt2.BackColor != Color.LightGray && btnRepair2.BackColor == Color.LightGray)
                    {
                        model2.inspectResult = "[报废]";
                        model2.damnPosition = abt_damnPosition2;
                        model2.reason = abt_reason2;

                        if (string.IsNullOrWhiteSpace(model2.damnPosition) || string.IsNullOrWhiteSpace(model2.reason))
                        {
                            MessageBox.Show("必须选择报废位置及报废原因!");
                            return;
                        }
                    }
                    if (btnPass2.BackColor == Color.LightGray && btnAbt2.BackColor == Color.LightGray && btnRepair2.BackColor != Color.LightGray)
                    {
                        model2.inspectResult = "[抛光]";
                        model2.damnPosition = damnPosition2;
                        model2.reason = reason2;

                        if (string.IsNullOrWhiteSpace(model2.damnPosition) || string.IsNullOrWhiteSpace(model2.reason))
                        {
                            MessageBox.Show("必须选择抛光位置及抛光原因!");
                            return;
                        }
                    }

                    if (rdo1.Checked)
                    {
                        model2.productOption = "1";
                    }
                    else if (rdo2.Checked)
                    {
                        model2.productOption = "2";
                    }
                    else if (rdo3.Checked)
                    {
                        model2.productOption = "3";
                    }

                    model2.productInfo = labColor2.Tag.ToString().Trim() + "," + labXingHao2.Text.Trim();
                    model2.InspectTimes = "1";

                    if (!string.IsNullOrWhiteSpace(model2.barcode))
                    {
                        Function.InsertInspect(model2);
                    }

                    LogHelper.WriteSysLogBase("条码:" + model2.barcode + "存入Inspect表完毕", MethodBase.GetCurrentMethod().Name);
                }
                
                #endregion

                #region 报废则调WMS WebService,入库

                try
                {
                    WMSWebService webService = new WMSWebService();
                    webService.Url = ConfigurationManager.AppSettings["WMSWebServiceURL"].ToString();
                    //webService.Timeout = 120000;

                    string errorReason = "";

                    if (model1.inspectResult == "[报废]" && !string.IsNullOrWhiteSpace(model1.barcode.Trim()))
                    {
                        webService.WMSSprayingForCS(model1.barcode, 0, out errorReason);
                        LogHelper.WriteSysLogBase("条码:" + model1.barcode + "调用WMSSprayingForCS完成", MethodBase.GetCurrentMethod().Name);
                    }
                    if (model2.inspectResult == "[报废]" && !string.IsNullOrWhiteSpace(model2.barcode.Trim()))
                    {
                        webService.WMSSprayingForCS(model2.barcode, 0, out errorReason);
                        LogHelper.WriteSysLogBase("条码:" + model2.barcode + "调用WMSSprayingForCS完成", MethodBase.GetCurrentMethod().Name);
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteErrLogBase("喷涂一检提交调用WMS接口:"+ ex.ToString(), MethodBase.GetCurrentMethod().Name);
                }

                #endregion

                #region 点击提交,滑撬号+1,执行滑撬号获取事件

                #region 清空页面按钮选择

                ClearControlColor(SetControlGroup1());
                ClearControlColor(SetControlGroup2());

                #endregion

                int no = 0;
                Int32.TryParse(txtSideNo.Text.Trim(), out no);
                no = no + 1;
                if (no == 304)
                {
                    no = 1;
                }
                skid_No = no.ToString();
                txtSideNo.Text = skid_No;

                LogHelper.WriteSysLogBase("条码:" + model1.barcode + "," + model2.barcode + "进入滑撬号:" + txtSideNo.Text, MethodBase.GetCurrentMethod().Name);
                btnSide_Click(sender, e); 

                #endregion

                btnSubmit.BackColor = Color.FromArgb(192, 192, 255);
                lighttimerStart = Convert.ToDateTime("2019-01-01 00:00:00");
            }
            catch (Exception ex)
            {
                LogHelper.WriteLogManager(ex);
                LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
            }
        }

        #region 修改颜色
        /// <summary>
        /// 修改颜色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void labChangeColor_Click(object sender, EventArgs e)
        {
            ColorName = "";
            labColor1.Tag = "";
            labColor2.Tag = "";

            FrmChangeColor frm = new FrmChangeColor();
            frm.ShowDialog();

            if (!string.IsNullOrWhiteSpace(ColorName))
            {
                string[] str = ColorName.Split(',');
                if (str.Length >= 3)
                {
                    labColor1.Text = str[0];
                    labColor2.Text = str[0];

                    labColor1.Tag = ColorName;
                    labColor2.Tag = ColorName;
                }
            }
        }

        private void labChangeColor_MouseMove(object sender, MouseEventArgs e)
        {
            Label lab = sender as Label;
            lab.BackColor = Color.Turquoise;
        }

        private void labChangeColor_MouseLeave(object sender, EventArgs e)
        {
            Label lab = sender as Label;
            lab.BackColor = Color.FromArgb(192, 255, 255);
        } 
        #endregion

        /// <summary>
        /// 点击右上角关闭窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void labTime_Click(object sender, EventArgs e)
        {
            Environment.Exit(0); 
        }

        private void labWorkClass_Click(object sender, EventArgs e)
        {
            Function.ChangeWorkClass(labWorkClass);
        }

    }
}