using ManualSoftwareSystem.lib;
using ManualSoftwareSystem.Operation_Manual;
using System;
using System.Collections;
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 System.Xml;

namespace ManualSoftwareSystem
{

    public partial class FrmComment : Form
    {
        private List<List<string>> Data = new List<List<string>>();
        private string csvPartFileComment = System.IO.Directory.GetCurrentDirectory() + "\\Comment.sys";
        private string commentType = string.Empty;
        private string condition = string.Empty;
        private string[] arrayCondition;
        private string strJudgment = string.Empty;
        private Int32 intWordCount = 0;
        private bool blCheck = false;
        private bool blInput = false;
        private Int32 intMin = 0;
        private Int32 intMax = 0;
        private Double dblMin = 0;
        private Double dblMax = 0;
        private string strLess = string.Empty;
        private string strMore = string.Empty;
        private string strUnit = string.Empty;
        private string csvPartFile = string.Empty;
        private Int32 intPage = 0;
        public dynamic objLanguage;
        public Point downPoint = Point.Empty;



        public FrmComment(string condition, string pathFile, Int32 intPage)
        {
            InitializeComponent();
            this.condition = condition;
            this.csvPartFile = pathFile;
            this.intPage = intPage;
            this.objLanguage = FrmOperationManualOperator.objLanguage;
            this.StartPosition = FormStartPosition.Manual;
            this.Location = new Point(600, 230);
        }

        private void FrmComment_Load(object sender, EventArgs e)
        {
            string strComment = "Comment";
            string strOK = "OK";
            string strCancel = "Cancel";
            string strStop = "STOP";
            string strAdd = "Add";
            string strDel = "Del";
            string strReset = "Reset";

            lblComment.Text = objLanguage.Translate(strComment);
            btnOK.Text = objLanguage.Translate(strOK);
            btnCancel.Text = objLanguage.Translate(strCancel);
            btnStop.Text = objLanguage.Translate(strStop);
            btnAdd.Text = objLanguage.Translate(strAdd);
            btnDel.Text = objLanguage.Translate(strDel);
            btnReset.Text = objLanguage.Translate(strReset);


            FrmOperationManual.startClick = false;
            FrmOperationManual.stopClick = false;
            FrmOperationManualOperator.commentTypeShare = string.Empty;
            FrmOperationManualOperator.TextTypeShare = string.Empty;
            FrmOperationManualOperator.WordCountShare = "0";
            FrmOperationManualOperator.MinShare = "0";
            FrmOperationManualOperator.MaxShare = "0";
            FrmOperationManualOperator.UnitShare = string.Empty;
            FrmOperationManualOperator.startClickShare = false;
            FrmOperationManualOperator.ErrorClickShare = false;
            FrmOperationManualOperator.CancelClickShare = false;

            if (!File.Exists(csvPartFileComment))
            {
                using (StreamWriter sw = File.CreateText(csvPartFileComment))
                {
                    sw.WriteLine("");
                    sw.WriteLine("");
                    sw.WriteLine("");
                }
            }

            if (condition != string.Empty)
            {
                if (condition.Split("|").Length == 8)
                {
                    arrayCondition = condition.Split("|");
                    commentType = arrayCondition[0];
                    FrmOperationManualOperator.commentTypeShare = commentType;
                    if (commentType == "Character input")
                    {
                        lblShowTextType.Text = arrayCondition[1];
                        FrmOperationManualOperator.TextTypeShare = arrayCondition[1];
                        strJudgment = arrayCondition[2];
                        if (arrayCondition[3].Trim().Length == 0)
                        {
                            intWordCount = 0;
                            FrmOperationManualOperator.WordCountShare = "0";
                        }
                        else
                        {
                            intWordCount = Convert.ToInt32(arrayCondition[3]);
                            FrmOperationManualOperator.WordCountShare = arrayCondition[3];
                        }
                        if (arrayCondition[4] == "1")
                        {
                            blCheck = true;
                        }
                        else if (arrayCondition[4] == "0")
                        {
                            blCheck = false;
                        }
                        if (arrayCondition[5] == "1")
                        {
                            blInput = true;
                        }
                        else if (arrayCondition[5] == "0")
                        {
                            blInput = false;
                        }
                    }
                    else if (commentType == "Integer input")
                    {
                        lblShowTextType.Text = arrayCondition[1];
                        FrmOperationManualOperator.TextTypeShare = arrayCondition[1];
                        if (arrayCondition[2].Trim().Length == 0)
                        {
                            intMin = 0;
                            FrmOperationManualOperator.MinShare = "0";
                        }
                        else
                        {
                            intMin = Convert.ToInt32(arrayCondition[2]);
                            FrmOperationManualOperator.MinShare = arrayCondition[2];
                        }
                        strLess = arrayCondition[3];
                        strMore = arrayCondition[4];
                        if (arrayCondition[5].Trim().Length == 0)
                        {
                            intMax = 0;
                            FrmOperationManualOperator.MaxShare = "0";
                        }
                        else
                        {
                            intMax = Convert.ToInt32(arrayCondition[5]);
                            FrmOperationManualOperator.MaxShare = arrayCondition[5];
                        }
                        strUnit = arrayCondition[6];
                        FrmOperationManualOperator.UnitShare = arrayCondition[6];
                        if (arrayCondition[7] == "1")
                        {
                            blInput = true;
                        }
                        else if (arrayCondition[7] == "0")
                        {
                            blInput = false;
                        }
                    }
                    else if (commentType == "Decimal input")
                    {
                        lblShowTextType.Text = arrayCondition[1];
                        FrmOperationManualOperator.TextTypeShare = arrayCondition[1];
                        if (arrayCondition[2].Trim().Length == 0)
                        {
                            dblMin = 0.0;
                            FrmOperationManualOperator.MinShare = "0";
                        }
                        else
                        {
                            dblMin = Convert.ToDouble(arrayCondition[2]);
                            FrmOperationManualOperator.MinShare = arrayCondition[2];
                        }
                        strLess = arrayCondition[3];
                        strMore = arrayCondition[4];
                        if (arrayCondition[5].Trim().Length == 0)
                        {
                            dblMax = 0.0;
                            FrmOperationManualOperator.MaxShare = "0";
                        }
                        else
                        {
                            dblMax = Convert.ToDouble(arrayCondition[5]);
                            FrmOperationManualOperator.MaxShare = arrayCondition[5];
                        }
                        //txtUnit.Text = arrayCondition[6];
                        strUnit = arrayCondition[6];
                        FrmOperationManualOperator.UnitShare = arrayCondition[6];
                        if (arrayCondition[7] == "1")
                        {
                            blInput = true;
                        }
                        else if (arrayCondition[7] == "0")
                        {
                            blInput = false;
                        }
                    }
                }
            }


            cmbSerialNumber.Items.Clear();


            List<string> tmp = null;
            Data = new List<List<string>>();
            tmp = null;
            Int32 i = 0;
            using (var csv = new CsvReader(csvPartFileComment))
            {
                while ((tmp = csv.ReadRow()) != null)
                {
                    Data.Add(tmp);

                    if ((i == 0) && (commentType == "Character input"))
                    {
                        //lblShowTextType.Text = objLanguage.Translate("Enter serial number");

                        for (int j = 0; j < tmp.Count; j++)
                        {
                            if (this.Data[i][j] != string.Empty)
                            {
                                cmbSerialNumber.Items.Add(this.Data[i][j]);
                            }

                        }
                    }

                    if ((i == 1) && (commentType == "Integer input"))
                    {
                        for (int j = 0; j < tmp.Count; j++)
                        {
                            if (this.Data[i][j] != string.Empty)
                            {
                                cmbSerialNumber.Items.Add(this.Data[i][j]);
                            }

                        }
                    }

                    if ((i == 2) && (commentType == "Decimal input"))
                    {
                        for (int j = 0; j < tmp.Count; j++)
                        {
                            if (this.Data[i][j] != string.Empty)
                            {
                                cmbSerialNumber.Items.Add(this.Data[i][j]);
                            }

                        }
                    }




                    i = i + 1;
                }

            }//using end

            cmbSerialNumber.Focus();

        }

        protected override void OnLoad(EventArgs e)
        {
            if (FormBorderStyle == System.Windows.Forms.FormBorderStyle.None)
            {
                MouseDown += new MouseEventHandler(FrmComment_MouseDown);
                MouseMove += new MouseEventHandler(FrmComment_MouseMove);
                MouseUp += new MouseEventHandler(FrmComment_MouseUp);
            }

            base.OnLoad(e);
        }


        private void FrmComment_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
                downPoint = new Point(e.X, e.Y);
        }
        private void FrmComment_MouseMove(object sender, MouseEventArgs e)
        {
            if (downPoint != Point.Empty)
                Location = new Point(Left + e.X - downPoint.X, Top + e.Y - downPoint.Y);
        }
        private void FrmComment_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
                downPoint = Point.Empty;
        }



        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (cmbSerialNumber.Text.Trim().Replace(",", "") == string.Empty)
            {
                MessageBox.Show(this, objLanguage.Translate("Data is Blanks"),
                                       objLanguage.Translate("Warning"), MessageBoxButtons.OK,
                                       MessageBoxIcon.Exclamation,
                                       MessageBoxDefaultButton.Button1, 0);
                return;
            }


            int index = cmbSerialNumber.FindStringExact(cmbSerialNumber.Text.Trim().Replace(",", ""));

            if (index == -1)
            {
                cmbSerialNumber.Items.Add(cmbSerialNumber.Text.Trim().Replace(",", ""));

                string strTemp = string.Empty;

                for (int i = 0; i < cmbSerialNumber.Items.Count; i++)
                {
                    if (i == 0)
                    {
                        strTemp = cmbSerialNumber.Items[i].ToString();
                    }
                    else
                    {
                        strTemp = strTemp + "," + cmbSerialNumber.Items[i].ToString();
                    }

                }

                if (commentType == "Character input")
                {
                    lineChanger(strTemp, csvPartFileComment, 1);
                }
                else if (commentType == "Integer input")
                {
                    lineChanger(strTemp, csvPartFileComment, 2);
                }
                else if (commentType == "Decimal input")
                {
                    lineChanger(strTemp, csvPartFileComment, 3);
                }


            }
        }

        static void lineChanger(string newText, string fileName, int line_to_edit)
        {
            string[] arrLine = File.ReadAllLines(fileName);
            arrLine[line_to_edit - 1] = newText;
            File.WriteAllLines(fileName, arrLine);
        }

        private void btnDel_Click(object sender, EventArgs e)
        {
            if (cmbSerialNumber.Text.Trim() == string.Empty)
            {
                MessageBox.Show(this, objLanguage.Translate("Data is Blanks"),
                                       objLanguage.Translate("Warning"), MessageBoxButtons.OK,
                                       MessageBoxIcon.Exclamation,
                                       MessageBoxDefaultButton.Button1, 0);
                return;
            }

            int index = cmbSerialNumber.FindStringExact(cmbSerialNumber.Text.Trim());

            if (index > -1)
            {
                cmbSerialNumber.Items.RemoveAt(index);

                if (cmbSerialNumber.Items.Count == 0)
                {
                    cmbSerialNumber.Items.Clear();
                    cmbSerialNumber.Text = string.Empty;
                }

                string strTemp = string.Empty;

                for (int i = 0; i < cmbSerialNumber.Items.Count; i++)
                {
                    if (i == 0)
                    {
                        strTemp = cmbSerialNumber.Items[i].ToString();
                    }
                    else
                    {
                        strTemp = strTemp + "," + cmbSerialNumber.Items[i].ToString();
                    }

                }


                if (commentType == "Character input")
                {
                    lineChanger(strTemp, csvPartFileComment, 1);
                }
                else if (commentType == "Integer input")
                {
                    lineChanger(strTemp, csvPartFileComment, 2);
                }
                else if (commentType == "Decimal input")
                {
                    lineChanger(strTemp, csvPartFileComment, 3);
                }

            }
        }

        private void btnOrderAtoZ_Click(object sender, EventArgs e)
        {
            cmbSerialNumber.Sorted = true;
        }

        private void btnOrderZtoA_Click(object sender, EventArgs e)
        {
            cmbSerialNumber.Sorted = false;

            List<string> TempList = new List<string>();
            for (int i = 0; i < cmbSerialNumber.Items.Count; i++)
            {

                TempList.Add(cmbSerialNumber.Items[i].ToString());

            }

            List<string> sortedDetailedComment = TempList.OrderByDescending(DetailedComment => DetailedComment).ToList();
            cmbSerialNumber.Items.Clear();
            foreach (string DetailedCommentName in sortedDetailedComment)
                cmbSerialNumber.Items.Add(DetailedCommentName);
        }

        private void btnReset_Click(object sender, EventArgs e)
        {

            cmbSerialNumber.Text = string.Empty;

            //cmbSerialNumber.Items.Clear();
            //cmbSerialNumber.Text = string.Empty;

            //string strTemp = string.Empty;

            //if (commentType == "Character input")
            //{
            //    lineChanger(strTemp, csvPartFileComment, 1);
            //}
            //else if (commentType == "Integer input")
            //{
            //    lineChanger(strTemp, csvPartFileComment, 2);
            //}
            //else if (commentType == "Decimal input")
            //{
            //    lineChanger(strTemp, csvPartFileComment, 3);
            //}

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            FrmOperationManualOperator.SerialNumberShare = string.Empty;
            FrmOperationManualOperator.CancelClickShare = true;

            this.Close();

        }

        private void Error_judment()
        {
            //DialogResult dialogResult = MessageBox.Show(objLanguage.Translate("Error judgment. Would you like to reconfirm?")
            DialogResult dialogResult = MessageBox.Show(objLanguage.Translate("Error. Would you like to reconfirm?")
            , objLanguage.Translate("Confirmation"),
            MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 0);
            if (dialogResult == DialogResult.Yes)
            {
                //FrmOperationManual.startClick = true;

                //this.Close();

                return;

            }
            else if (dialogResult == DialogResult.No)
            {

                FrmOperationInputInformation frmOperationInputInformation = new FrmOperationInputInformation(csvPartFile);

                //this.Dispose();

                frmOperationInputInformation.ShowDialog();

                FrmOperationManual.startClick = true;
                FrmOperationManual.strType = commentType;
                FrmOperationManualOperator.startClickShare = true;


                //FrmOperationManual.listS.Insert(intPage, cmbSerialNumber.Text);
                //FrmOperationManual.listSBNEF.Insert(intPage, "N");


                this.Dispose();

            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            FrmOperationManualOperator.SerialNumberShare = string.Empty;
            FrmOperationManualOperator.startClickShare = false;
            FrmOperationManualOperator.ErrorCloseShare = false;

            if (commentType == "Character input")
            {
                if ((blInput == false) && (cmbSerialNumber.Text.Trim().Length == 0))
                {

                    //Error_judment();
                    FrmOperationManualOperator.SerialNumberShare = cmbSerialNumber.Text.Trim();
                    FrmOperationManualOperator.startClickShare = true;
                    this.Close();
                    return;
                }
                if (cmbSerialNumber.Text.Trim().Length == 0)
                {
                    //MessageBox.Show(objLanguage.Translate("Please key data again."), objLanguage.Translate("Warning"),
                    //MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    Error_judment();
                    return;
                }
                if (cmbSerialNumber.Text.Trim().Length != intWordCount)
                {
                    //MessageBox.Show(objLanguage.Translate("Please key data again."), objLanguage.Translate("Warning"),
                    //MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    Error_judment();
                    return;
                }
                for (int i = 0; i < cmbSerialNumber.Text.Trim().Length; i++)
                {
                    if (strJudgment.Substring(i, 1) != "*")
                    {
                        if (blCheck == false)
                        {
                            if (cmbSerialNumber.Text.Trim().Substring(i, 1).ToUpper() != strJudgment.Substring(i, 1).ToUpper())
                            {

                                //MessageBox.Show(objLanguage.Translate("Please key data again."), objLanguage.Translate("Warning"),
                                //    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                Error_judment();
                                return;
                            }
                        }
                        else if (blCheck == true)
                        {
                            if (cmbSerialNumber.Text.Trim().Substring(i, 1) != strJudgment.Substring(i, 1))
                            {

                                //MessageBox.Show(objLanguage.Translate("Please key data again."), objLanguage.Translate("Warning"),
                                //    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                Error_judment();
                                return;
                            }
                        }


                    }
                }

                FrmOperationManualOperator.SerialNumberShare = cmbSerialNumber.Text.Trim();
                FrmOperationManualOperator.startClickShare = true;
                this.Close();
                //Error_judment();

            }
            else if (commentType == "Integer input")
            {
                if ((blInput == false) && (cmbSerialNumber.Text.Trim().Length == 0))
                {

                    //Error_judment();
                    FrmOperationManualOperator.SerialNumberShare = cmbSerialNumber.Text.Trim();
                    FrmOperationManualOperator.startClickShare = true;
                    this.Close();
                    return;
                }
                if (cmbSerialNumber.Text.Trim().Length == 0)
                {
                    //MessageBox.Show(objLanguage.Translate("Please key data again."), objLanguage.Translate("Warning"),
                    //MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    Error_judment();
                    return;
                }

                if (strLess == "None")
                {
                    if (strMore == "<")
                    {
                        if (Convert.ToInt32(cmbSerialNumber.Text.Trim()) >= intMax)
                        {
                            //MessageBox.Show(objLanguage.Translate("Please key data again."), objLanguage.Translate("Warning"),
                            //MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            Error_judment();
                            return;
                        }
                        else
                        {

                            //Error_judment();
                            FrmOperationManualOperator.SerialNumberShare = cmbSerialNumber.Text.Trim();
                            FrmOperationManualOperator.startClickShare = true;
                            this.Close();
                            return;
                        }
                    }
                    else if (strMore == "<=")
                    {
                        if (Convert.ToInt32(cmbSerialNumber.Text.Trim()) > intMax)
                        {
                            //MessageBox.Show(objLanguage.Translate("Please key data again."), objLanguage.Translate("Warning"),
                            //MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            Error_judment();
                            return;
                        }
                        else
                        {

                            //Error_judment();
                            FrmOperationManualOperator.SerialNumberShare = cmbSerialNumber.Text.Trim();
                            FrmOperationManualOperator.startClickShare = true;
                            this.Close();
                            return;
                        }
                    }
                    else if (strMore == "None")
                    {

                        //Error_judment();
                        FrmOperationManualOperator.SerialNumberShare = cmbSerialNumber.Text.Trim();
                        FrmOperationManualOperator.startClickShare = true;
                        this.Close();
                        return;
                    }
                }
                else if (strLess == "<")
                {
                    if (strMore == "<")
                    {
                        if ((Convert.ToInt32(cmbSerialNumber.Text.Trim()) >= intMax) || (Convert.ToInt32(cmbSerialNumber.Text.Trim()) <= intMin))
                        {
                            //MessageBox.Show(objLanguage.Translate("Please key data again."), objLanguage.Translate("Warning"),
                            //MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            Error_judment();
                            return;
                        }
                        else
                        {

                            //Error_judment();
                            FrmOperationManualOperator.SerialNumberShare = cmbSerialNumber.Text.Trim();
                            FrmOperationManualOperator.startClickShare = true;
                            this.Close();
                            return;
                        }
                    }
                    else if (strMore == "<=")
                    {
                        if ((Convert.ToInt32(cmbSerialNumber.Text.Trim()) > intMax) || (Convert.ToInt32(cmbSerialNumber.Text.Trim()) <= intMin))
                        {
                            //MessageBox.Show(objLanguage.Translate("Please key data again."), objLanguage.Translate("Warning"),
                            //MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            Error_judment();
                            return;
                        }
                        else
                        {

                            //Error_judment();
                            FrmOperationManualOperator.SerialNumberShare = cmbSerialNumber.Text.Trim();
                            FrmOperationManualOperator.startClickShare = true;
                            this.Close();
                            return;
                        }
                    }
                    else if (strMore == "None")
                    {
                        if (Convert.ToInt32(cmbSerialNumber.Text.Trim()) <= intMin)
                        {
                            // MessageBox.Show(objLanguage.Translate("Please key data again."), objLanguage.Translate("Warning"),
                            //MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            Error_judment();
                            return;
                        }
                        else
                        {
                            //Error_judment();
                            FrmOperationManualOperator.SerialNumberShare = cmbSerialNumber.Text.Trim();
                            FrmOperationManualOperator.startClickShare = true;
                            this.Close();
                            return;
                        }


                    }
                }

                else if (strLess == "<=")
                {
                    if (strMore == "<")
                    {
                        if ((Convert.ToInt32(cmbSerialNumber.Text.Trim()) >= intMax) || (Convert.ToInt32(cmbSerialNumber.Text.Trim()) < intMin))
                        {
                            //MessageBox.Show(objLanguage.Translate("Please key data again."), objLanguage.Translate("Warning"),
                            //MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            Error_judment();
                            return;
                        }
                        else
                        {

                            //Error_judment();
                            FrmOperationManualOperator.SerialNumberShare = cmbSerialNumber.Text.Trim();
                            FrmOperationManualOperator.startClickShare = true;
                            this.Close();
                            return;
                        }
                    }
                    else if (strMore == "<=")
                    {
                        if ((Convert.ToInt32(cmbSerialNumber.Text.Trim()) > intMax) || (Convert.ToInt32(cmbSerialNumber.Text.Trim()) < intMin))
                        {
                            //MessageBox.Show(objLanguage.Translate("Please key data again."), objLanguage.Translate("Warning"),
                            //MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            Error_judment();
                            return;
                        }
                        else
                        {

                            //Error_judment();
                            FrmOperationManualOperator.SerialNumberShare = cmbSerialNumber.Text.Trim();
                            FrmOperationManualOperator.startClickShare = true;
                            this.Close();
                            return;
                        }
                    }
                    else if (strMore == "None")
                    {
                        if (Convert.ToInt32(cmbSerialNumber.Text.Trim()) < intMin)
                        {
                            // MessageBox.Show(objLanguage.Translate("Please key data again."), objLanguage.Translate("Warning"),
                            //MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            Error_judment();
                            return;
                        }
                        else
                        {
                            //Error_judment();
                            FrmOperationManualOperator.SerialNumberShare = cmbSerialNumber.Text.Trim();
                            FrmOperationManualOperator.startClickShare = true;
                            this.Close();
                            return;
                        }


                    }
                }

            }
            else if (commentType == "Decimal input")
            {

                if ((blInput == false) && (cmbSerialNumber.Text.Trim().Length == 0))
                {

                    //Error_judment();
                    FrmOperationManualOperator.SerialNumberShare = cmbSerialNumber.Text.Trim();
                    FrmOperationManualOperator.startClickShare = true;
                    this.Close();
                    return;
                }
                if (cmbSerialNumber.Text.Trim().Length == 0)
                {
                    //MessageBox.Show(objLanguage.Translate("Please key data again."), objLanguage.Translate("Warning"),
                    //MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    Error_judment();
                    return;
                }

                if (strLess == "None")
                {
                    if (strMore == "<")
                    {
                        if (Convert.ToDouble(cmbSerialNumber.Text.Trim()) >= dblMax)
                        {
                            //MessageBox.Show(objLanguage.Translate("Please key data again."), objLanguage.Translate("Warning"),
                            //MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            Error_judment();
                            return;
                        }
                        else
                        {

                            //Error_judment();
                            FrmOperationManualOperator.SerialNumberShare = cmbSerialNumber.Text.Trim();
                            FrmOperationManualOperator.startClickShare = true;
                            this.Close();
                            return;
                        }
                    }
                    else if (strMore == "<=")
                    {
                        if (Convert.ToDouble(cmbSerialNumber.Text.Trim()) > dblMax)
                        {
                            //MessageBox.Show(objLanguage.Translate("Please key data again."), objLanguage.Translate("Warning"),
                            //MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            Error_judment();
                            return;
                        }
                        else
                        {

                            //Error_judment();
                            FrmOperationManualOperator.SerialNumberShare = cmbSerialNumber.Text.Trim();
                            FrmOperationManualOperator.startClickShare = true;
                            this.Close();
                            return;
                        }
                    }
                    else if (strMore == "None")
                    {

                        //Error_judment();
                        FrmOperationManualOperator.SerialNumberShare = cmbSerialNumber.Text.Trim();
                        FrmOperationManualOperator.startClickShare = true;
                        this.Close();
                        return;
                    }
                }
                else if (strLess == "<")
                {
                    if (strMore == "<")
                    {
                        if ((Convert.ToDouble(cmbSerialNumber.Text.Trim()) >= dblMax) || (Convert.ToDouble(cmbSerialNumber.Text.Trim()) <= dblMin))
                        {
                            //MessageBox.Show(objLanguage.Translate("Please key data again."), objLanguage.Translate("Warning"),
                            //MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            Error_judment();
                            return;
                        }
                        else
                        {

                            //Error_judment();
                            FrmOperationManualOperator.SerialNumberShare = cmbSerialNumber.Text.Trim();
                            FrmOperationManualOperator.startClickShare = true;
                            this.Close();
                            return;
                        }
                    }
                    else if (strMore == "<=")
                    {
                        if ((Convert.ToDouble(cmbSerialNumber.Text.Trim()) > dblMax) || (Convert.ToDouble(cmbSerialNumber.Text.Trim()) <= dblMin))
                        {
                            //MessageBox.Show(objLanguage.Translate("Please key data again."), objLanguage.Translate("Warning"),
                            //MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            Error_judment();
                            return;
                        }
                        else
                        {

                            //Error_judment();
                            FrmOperationManualOperator.SerialNumberShare = cmbSerialNumber.Text.Trim();
                            FrmOperationManualOperator.startClickShare = true;
                            this.Close();
                            return;
                        }
                    }
                    else if (strMore == "None")
                    {
                        if (Convert.ToDouble(cmbSerialNumber.Text.Trim()) <= dblMin)
                        {
                            // MessageBox.Show(objLanguage.Translate("Please key data again."), objLanguage.Translate("Warning"),
                            //MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            Error_judment();
                            return;
                        }
                        else
                        {
                            //Error_judment();
                            FrmOperationManualOperator.SerialNumberShare = cmbSerialNumber.Text.Trim();
                            FrmOperationManualOperator.startClickShare = true;
                            this.Close();
                            return;
                        }


                    }
                }

                else if (strLess == "<=")
                {
                    if (strMore == "<")
                    {
                        if ((Convert.ToDouble(cmbSerialNumber.Text.Trim()) >= dblMax) || (Convert.ToDouble(cmbSerialNumber.Text.Trim()) < dblMin))
                        {
                            //MessageBox.Show(objLanguage.Translate("Please key data again."), objLanguage.Translate("Warning"),
                            //MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            Error_judment();
                            return;
                        }
                        else
                        {

                            //Error_judment();
                            FrmOperationManualOperator.SerialNumberShare = cmbSerialNumber.Text.Trim();
                            FrmOperationManualOperator.startClickShare = true;
                            this.Close();
                            return;
                        }
                    }
                    else if (strMore == "<=")
                    {
                        if ((Convert.ToDouble(cmbSerialNumber.Text.Trim()) > dblMax) || (Convert.ToDouble(cmbSerialNumber.Text.Trim()) < dblMin))
                        {
                            //MessageBox.Show(objLanguage.Translate("Please key data again."), objLanguage.Translate("Warning"),
                            //MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            Error_judment();
                            return;
                        }
                        else
                        {

                            //Error_judment();
                            FrmOperationManualOperator.SerialNumberShare = cmbSerialNumber.Text.Trim();
                            FrmOperationManualOperator.startClickShare = true;
                            this.Close();
                            return;
                        }
                    }
                    else if (strMore == "None")
                    {
                        if (Convert.ToDouble(cmbSerialNumber.Text.Trim()) < dblMin)
                        {
                            // MessageBox.Show(objLanguage.Translate("Please key data again."), objLanguage.Translate("Warning"),
                            //MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            Error_judment();
                            return;
                        }
                        else
                        {
                            //Error_judment();
                            FrmOperationManualOperator.SerialNumberShare = cmbSerialNumber.Text.Trim();
                            FrmOperationManualOperator.startClickShare = true;
                            this.Close();
                            return;
                        }


                    }
                }


            }
        }

        private void cmbSerialNumber_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (commentType == "Decimal input")
            {
                if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.')
                {
                    e.Handled = true;
                }

                // only allow one decimal point
                if (e.KeyChar == '.' && (sender as ComboBox).Text.IndexOf('.') > -1)
                {
                    e.Handled = true;
                }

                if (!char.IsControl(e.KeyChar))
                {

                    //TextBox textBox = (TextBox)sender;
                    ComboBox comboBox = (ComboBox)sender;

                    if (comboBox.Text.IndexOf('.') > -1 &&
                             comboBox.Text.Substring(comboBox.Text.IndexOf('.')).Length >= 3)
                    {
                        e.Handled = true;
                    }
                }
            }
            else if (commentType == "Integer input")
            {
                if (e.KeyChar == ((char)Keys.Back))
                {
                    e.Handled = false;
                }
                else
                {
                    e.Handled = !Char.IsDigit(e.KeyChar);
                }
            }

        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            this.Dispose();

            FrmOperationManual.stopClick = true;
        }
    }
}
