private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (txt_materialRequest.Text.Length == 12)
            {
                dtgv_data.Columns.Clear();
                dtgv_data.DataSource = null;
                Database.MOC.MOCTCTE mOCTCTE = new Database.MOC.MOCTCTE();
                var txtSpilit = txt_materialRequest.Text.Split('-');
                dtGet = mOCTCTE.GetdtMOCTCTE(txtSpilit[0], txtSpilit[1]);
                dtgv_data.DataSource = dtGet;
                DataGridViewCheckBoxColumn checkBoxCell = new DataGridViewCheckBoxColumn();
                checkBoxCell.Name         = "checkbox";
                checkBoxCell.HeaderText   = "Scan QR Material";
                checkBoxCell.DisplayIndex = 0;

                dtgv_data.Columns.Insert(0, checkBoxCell);
                DataGridViewCheckBoxColumn checkBoxCell2 = new DataGridViewCheckBoxColumn();
                checkBoxCell2.Name         = "checkbox2";
                checkBoxCell2.HeaderText   = "Scan QR Location";
                checkBoxCell2.DisplayIndex = 1;

                dtgv_data.Columns.Insert(1, checkBoxCell2);
                DataGridViewTextBoxColumn textBoxColumn = new DataGridViewTextBoxColumn();
                textBoxColumn.Name         = "FEFO";
                textBoxColumn.HeaderText   = "FEFO";
                textBoxColumn.DisplayIndex = 2;
                dtgv_data.Columns.Insert(1, textBoxColumn);

                for (int i = 0; i < dtgv_data.Rows.Count; i++)
                {
                    string material  = dtgv_data.Rows[i].Cells["TE004"].Value.ToString().Trim();
                    string lot       = dtgv_data.Rows[i].Cells["TE010"].Value.ToString().Trim();
                    string warehouse = "B05";
                    string IsConfirm = dtgv_data.Rows[i].Cells["TC009"].Value.ToString().Trim();
                    if (IsConfirm == "N")
                    {
                        lb_confirm.Text      = "Not yet confirm";
                        lb_confirm.BackColor = Color.LightYellow;
                    }
                    var isFIFO = IscheckFIFO(material, lot, warehouse);
                    if (isFIFO)
                    {
                        dtgv_data.Rows[i].Cells["FEFO"].Value           = "FEFO OK";
                        dtgv_data.Rows[i].Cells["FEFO"].Style.BackColor = Color.Green;
                        dtgv_data.Rows[i].ReadOnly = false;
                    }
                    else
                    {
                        dtgv_data.Rows[i].Cells["FEFO"].Value           = "FEFO NG";
                        dtgv_data.Rows[i].Cells["FEFO"].Style.BackColor = Color.Red;
                        dtgv_data.Rows[i].ReadOnly = true;
                    }
                }
                txt_QrScanMaterial.Focus();
            }
        }
        private void UpdateERP()
        {
            //DataTable dt = new DataTable();
            //foreach (DataGridViewColumn column in dtgv_data.Columns)
            //    dt.Columns.Add(column.Name, column.CellType); //better to have cell type
            //for (int i = 0; i < dtgv_data.Rows.Count; i++)
            //{
            //    if ((bool)dtgv_data.Rows[i].Cells["checkbox"].Value == true && (bool)dtgv_data.Rows[i].Cells["checkbox2"].Value == true)
            //    {
            //        dt.Rows.Add();
            //        dt.Rows[i]["TE001"] = dtgv_data.Rows[i].Cells["TE001"].Value;
            //        dt.Rows[i]["TE002"] = dtgv_data.Rows[i].Cells["TE002"].Value;
            //        dt.Rows[i]["TE003"] = dtgv_data.Rows[i].Cells["TE003"].Value;


            //    }
            //}

            DataTable dt     = new DataTable();                   // create a table for storing selected rows
            var       dtTemp = dtgv_data.DataSource as DataTable; // get the source table object

            dt = dtTemp.Clone();                                  // clone the schema of the source table to new table
            DataTable table = new DataTable();

            for (int i = 0; i < dtgv_data.Rows.Count; i++)
            {
                if ((bool)dtgv_data.Rows[i].Cells["checkbox"].Value == true && (bool)dtgv_data.Rows[i].Cells["checkbox2"].Value == true)
                {
                    var row = dt.NewRow();  // create a new row with the schema
                    for (int j = 0; j < dtgv_data.Columns.Count; j++)
                    {
                        row["TE001"] = dtgv_data.Rows[i].Cells["TE001"].Value.ToString().Trim();
                        row["TE002"] = dtgv_data.Rows[i].Cells["TE002"].Value.ToString();
                        row["TE003"] = dtgv_data.Rows[i].Cells["TE003"].Value.ToString();
                    }
                    dt.Rows.Add(row);  // add rows to the new table
                }
            }


            Database.MOC.MOCTCTE mOCTCTE = new Database.MOC.MOCTCTE();
            mOCTCTE.UpdateMOCTC(dt);
            lb_confirm.Text      = "Confirmed";
            lb_confirm.BackColor = Color.OrangeRed;
        }