private void btn_change_Click(object sender, EventArgs e)
        {
            bll_contract = new BLL_Contract();
            _dtocontract = new DTO_Contract();
            setAllcontrolToDTO(ref _dtocontract);
            table = bll_contract.GetDataTableViewContract(ref err);
            string num_no = string.Empty;
            bool   stt    = false;

            foreach (DataRow row in table.Rows)
            {
                num_no = (string)row["Notary_Number"];
                stt    = _dtocontract.No_number.Equals(num_no) ? true : false;
            }
            if (stt)
            {
                dialog = MessageBox.Show("Dữ liệu đã tồn tại");
            }
            if (dialog == DialogResult.OK)
            {
                Update_Contract(_dtocontract, bll_contract);
            }
            else
            {
                Add_Contract(_dtocontract, bll_contract);
            }
            this.Close();
            Frm_detail_contract frm_Detail = new Frm_detail_contract();

            frm_Detail.Show();
        }
        private void Update_Contract(DTO_Contract con, BLL_Contract bll)
        {
            bool bo = bll.UpdateContractExcuNonQue(ref err, con.No_number, con.Dto_person_notary.Name, con.Dto_person_notary.Id_code, con.Dto_person_notary.Address, con.Dto_person_notary.Phone, con.Notary_date, con.Sign_date, con.Dto_notarybook.Number_book, con.Description, con.Dto_name_contract.Name_contract, con.Dto_type_contract.Name_type, (int)con.Price, con.Dto_notary.Name, con.Note, con.Dto_notarybook.Year_book);

            if (bo == true)
            {
                MessageBox.Show("Đã update hợp đồng");
            }
            else
            {
                MessageBox.Show("Không update được hợp đồng");
            }
        }
        private void txt_number_no_Leave(object sender, EventArgs e)
        {
            table        = new DataTable();
            bll_contract = new BLL_Contract();
            DTO_Contract dto_contract = new DTO_Contract();

            table = bll_contract.Load_data_all_control_with_noNum(ref err, txt_number_no.Text);
            bool stt = false;

            stt = table.Rows.Count > 0 ? true : false;

            if (stt)
            {
                setDatabaseToDTO(table, bll_contract, ref dto_contract);
                SetDTOToControl(dto_contract);
            }
        }
        private void tol_find_SelectedIndexChanged(object sender, EventArgs e)
        {
            table_Contract = new DataTable();
            dto_contract   = new DTO_Contract();
            bll_contact    = new BLL_Contract();

            if (tol_find.SelectedItem.Equals("Theo Tên"))
            {
                table_Contract = bll_contact.Load_data_with_name(ref err, tol_txt_find.Text);
                if (stt)
                {
                    if (tol_txt_find.Text == "")
                    {
                        MessageBox.Show("Bạn chưa điền tên");
                        tol_txt_find.Focus();
                    }
                }
                dataGridView1.DataSource = table_Contract;
            }
            if (tol_find.SelectedItem.Equals("Theo CMND"))
            {
                table_Contract = bll_contact.Load_data_with_id_code(ref err, tol_txt_find.Text);
                if (stt)
                {
                    if (tol_txt_find.Text == "")
                    {
                        MessageBox.Show("Bạn chưa điền CMND");
                        tol_txt_find.Focus();
                    }
                }
                dataGridView1.DataSource = table_Contract;
            }
            if (tol_find.SelectedItem.Equals("Theo SCC"))
            {
                table_Contract = bll_contact.Load_data_with_no_num(ref err, tol_txt_find.Text);
                if (stt)
                {
                    if (tol_txt_find.Text == "")
                    {
                        MessageBox.Show("Bạn chưa điền SCC");
                        tol_txt_find.Focus();
                    }
                }
                dataGridView1.DataSource = table_Contract;
            }
        }
 private void setAllcontrolToDTO(ref DTO_Contract dto)
 {
     dto.No_number = (string)txt_number_no.Text;
     dto.Dto_person_notary.Name    = txt_name_p.Text;
     dto.Dto_person_notary.Id_code = txt_id_code.Text;
     dto.Dto_person_notary.Address = txt_address.Text;
     dto.Dto_person_notary.Phone   = "";
     dto.Notary_date = dpk_date_ask.Value;
     dto.Sign_date   = dpk_date_sign.Value;
     dto.Dto_notarybook.Number_book = Convert.ToInt32(cbo_num_bo.SelectedItem.ToString());
     dto.Description = txt_description.Text;
     dto.Dto_name_contract.Name_contract = cbo_name_contract.SelectedItem.ToString();
     dto.Dto_type_contract.Name_type     = cbo_type_contract.SelectedItem.ToString();
     dto.Price                    = Convert.ToDouble(txt_price.Text);
     dto.Note                     = txt_note.Text;
     dto.Dto_notary.Name          = "Lê Thị Ngọc hiêp";
     dto.Dto_notarybook.Year_book = Convert.ToInt32(cbo_year.SelectedItem.ToString());
 }
 public void LoadGridViewToDTO(DTO_Contract dto)
 {
     dto.No_number = dataGridView1.CurrentRow.Cells["col_no_num"].Value.ToString();
     dto.Dto_person_notary.Name    = dataGridView1.CurrentRow.Cells["col_name"].Value.ToString();
     dto.Dto_person_notary.Id_code = dataGridView1.CurrentRow.Cells["col_id_code"].Value.ToString();
     dto.Dto_person_notary.Address = dataGridView1.CurrentRow.Cells["col_address"].Value.ToString();
     dto.Dto_person_notary.Phone   = "";
     dto.Notary_date = (DateTime)dataGridView1.CurrentRow.Cells["col_no_date"].Value;
     dto.Sign_date   = (DateTime)dataGridView1.CurrentRow.Cells["col_sig_date"].Value;
     dto.Dto_notarybook.Number_book = Convert.ToInt32(dataGridView1.CurrentRow.Cells["col_nu_book"].Value.ToString());
     dto.Description = dataGridView1.CurrentRow.Cells["col_des"].Value.ToString();
     dto.Dto_name_contract.Name_contract = dataGridView1.CurrentRow.Cells["col_type_name"].Value.ToString();
     dto.Dto_type_contract.Name_type     = dataGridView1.CurrentRow.Cells["col_type"].Value.ToString();
     dto.Price                    = Convert.ToDouble(dataGridView1.CurrentRow.Cells["col_price"].Value.ToString());
     dto.Note                     = dataGridView1.CurrentRow.Cells["col_not"].Value.ToString();
     dto.Dto_notary.Name          = dataGridView1.CurrentRow.Cells["col_name_no"].Value.ToString();
     dto.Dto_notarybook.Year_book = Convert.ToInt32(((DateTime)dataGridView1.CurrentRow.Cells["col_no_date"].Value).Year);
 }
 // Area set controls and DTO
 private void SetDTOToControl(DTO_Contract _dto)
 {
     if (_dto != null)
     {
         txt_number_no.Text             = _dto.No_number;
         txt_name_p.Text                = _dto.Dto_person_notary.Name;
         txt_id_code.Text               = _dto.Dto_person_notary.Id_code;
         txt_address.Text               = _dto.Dto_person_notary.Address;
         dpk_date_ask.Value             = _dto.Notary_date;
         dpk_date_sign.Value            = _dto.Sign_date;
         cbo_num_bo.SelectedItem        = _dto.Dto_notarybook.Number_book;
         txt_description.Text           = _dto.Description;
         cbo_name_contract.SelectedItem = _dto.Dto_name_contract.Name_contract;
         cbo_type_contract.SelectedItem = _dto.Dto_type_contract.Name_type;
         txt_price.Text        = _dto.Price.ToString();
         txt_note.Text         = _dto.Note;
         cbo_year.SelectedItem = _dto.Dto_notarybook.Year_book;
     }
 }
 private void setDatabaseToDTO(DataTable table, BLL_Contract bll, ref DTO_Contract dto)
 {
     foreach (DataRow row in table.Rows)
     {
         dto.No_number   = (string)row["Notary_Number"];
         dto.Description = (string)row["Description"];
         dto.Notary_date = (DateTime)row["Notary_Date"];
         dto.Sign_date   = (DateTime)row["Sign_Date"];
         dto.Price       = (double)row["Notary_Price"];
         dto.Note        = (string)row["Note"];
         dto.Dto_person_notary.Id_code       = (string)row["ID_Code"];
         dto.Dto_person_notary.Name          = (string)row["LastName"];
         dto.Dto_person_notary.Address       = (string)row["NPerson_Address"];
         dto.Dto_person_notary.Phone         = "";
         dto.Dto_name_contract.Name_contract = (string)row["Type_Name_Contract"];
         dto.Dto_type_contract.Name_type     = (string)row["Name_Type"];
         dto.Dto_notarybook.Number_book      = (int)row["Number_Of_Book"];
         dto.Dto_notarybook.Year_book        = (int)row["Year_Book"];
         dto.Dto_notary.Name = (string)row["Name_Notary"];
     }
 }
 private void dataGridView1_Click(object sender, EventArgs e)
 {
     dto_contract           = new DTO_Contract();
     dto_contract.No_number = dataGridView1.CurrentRow.Cells[""].Value.ToString();
 }
 private void dataGridView1_Click(object sender, EventArgs e)
 {
     dto_contract = new DTO_Contract();
     LoadGridViewToDTO(dto_contract);
 }