private void SaveToDB()
 {
     try
     {
         ImportExportDAL importExportDAL = new ImportExportDAL();
         if (ValidateData())
         {
             importExport.CheckNo = int.Parse(txtCheckNo.Text);
             importExport.Date = DateTime.ParseExact(txtDay.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
             if (radioButtonImport.Checked)
             {
                 importExport.ImEx = "Nhập";
             }
             else if (radioButtonExport.Checked)
             {
                 importExport.ImEx = "Xuất";
             }
             importExport.Type = cbType.SelectedItem.ToString();
             CustomerDAL customerDAL = new CustomerDAL();
             importExport.CustomerID = customerDAL.GetCustomerbyName(txtCustomerName.Text).CustomerID;
         }
         bool rs;
         if (isAdd)
         {
             rs = importExportDAL.CreateIE(importExport);
         }
         else
         {
             rs = importExportDAL.UpdateIE(importExport);
         }
         if (rs)
         {
             MessageBox.Show("Đã lưu !");
             groupBoxDetail.Enabled = false;
             txtCheckNo.ReadOnly = true;
             LoadAllData();
         }
         else
         {
             MessageBox.Show("Không thể lưu !");
         }
     }
     catch (Exception ex)
     {
         logger.MyLogFile(DateTime.Now.ToString(), "' Error '" + ex.Message + "'");
     }
 }
        private void dataGridView1_Click(object sender, EventArgs e)
        {
            try
            {
                isAdd = false;

                radioButtonExport.Enabled = false;
                radioButtonImport.Enabled = false;
                importExport.CheckNo = (int)dataGridView1.SelectedRows[0].Cells[0].Value;
                importExport.Date = (DateTime)dataGridView1.SelectedRows[0].Cells[1].Value;
                importExport.ImEx = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
                importExport.Type = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();

                groupBoxDetail.Enabled = true;
                CustomerDAL cusDAL = new CustomerDAL();
                string CusName = dataGridView1.SelectedRows[0].Cells[4].Value.ToString();
                importExport.CustomerID = cusDAL.GetCustomerbyName(CusName).CustomerID;

                txtCheckNo.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                txtCheckNo.ReadOnly = true;
                txtDay.Text = String.Format("{0:dd/MM/yyyy}", dataGridView1.SelectedRows[0].Cells[1].Value);
                string ImEx = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
                if (String.Compare(ImEx, "Nhập", true) == 0)
                {
                    radioButtonImport.Checked = true;
                }
                else
                {
                    radioButtonExport.Checked = true;
                }
                string type = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                if (String.Compare(type, "Ký gửi", true) == 0)
                {
                    cbType.SelectedIndex = 0;
                }
                if (String.Compare(type, "Bán lẻ", true) == 0)
                {
                    cbType.SelectedIndex = 1;
                }
                if (String.Compare(type, "Nhập trả", true) == 0 && String.Compare(importExport.ImEx, "Nhập", true) == 0)
                {
                    cbType.SelectedIndex = 2;
                }
                if (String.Compare(type, "Lưu kho", true) == 0 && String.Compare(importExport.ImEx, "Xuất", true) == 0)
                {
                    cbType.SelectedIndex = 2;
                }
                if (String.Compare(type, "Trả hàng", true) == 0 && String.Compare(importExport.ImEx, "Xuất", true) == 0)
                {
                    cbType.SelectedIndex = 3;
                }
                txtCustomerName.Text = dataGridView1.SelectedRows[0].Cells[4].Value.ToString();
            }
            catch (Exception ex)
            {

                logger.MyLogFile(DateTime.Now.ToString(), "' Error '" + ex.Message + "'");
            }
        }