Example #1
0
        private void btLuu_Click(object sender, EventArgs e)
        {
            int gioitinh = 1;

            if (rdNu.Checked == true)
            {
                gioitinh = 0;
            }

            if (txtTen.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập tên khách hàng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtTen.Focus();
                return;
            }

            if (!isvailphone(txtSDT.Text))
            {
                MessageBox.Show("Định dạng số điện thoại không hợp lệ, vui lòng nhập lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtSDT.Focus();
                return;
            }
            else if (checksdt(txtSDT.Text, busKhach))
            {
                MessageBox.Show("Số điện thoại đã tồn tại, vui lòng nhập lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtSDT.Focus();
                return;
            }

            if (!Isvaild(txtEmail.Text.Trim()))
            {
                MessageBox.Show("Định dạng email không hợp lệ, vui lòng nhập lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtEmail.Focus();
                return;
            }



            DTO_Khach khach = new DTO_Khach(txtTen.Text, txtSDT.Text, dtpNgaySinh.Value, txtEmail.Text, gioitinh);

            if (busKhach.insertKhach(khach))
            {
                MessageBox.Show("Thêm thành công");
                LoadGridview_Khach();
                btLuu.Enabled = false;
            }
            else
            {
                MessageBox.Show("Thêm không thành công");
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (isOld == 1)
            {
                FormKhuVucBan.hd.SDT_KH = txtSDT.Text;
                busBan.UpdateKHvaoHDTam(FormKhuVucBan.hd.MaHD, txtSDT.Text);
                this.Close();
            }
            else
            {
                int gioitinh = 1;
                if (rdbNu.Checked == true)
                {
                    gioitinh = 0;
                }

                if (!isvailphone(txtSDT.Text))
                {
                    MessageBox.Show("Định dạng số điện thoại không hợp lệ, vui lòng nhập lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtSDT.Focus();
                    return;
                }

                DTO_Khach KhachHang = new DTO_Khach(txtTenKH.Text, txtSDT.Text, dtpNgS.Value.Date, txtEmail.Text, gioitinh);
                if (!Isvaild(txtEmail.Text))
                {
                    MessageBox.Show("Email không hợp lệ");
                }
                else if (busKH.insertKhach(KhachHang))
                {
                    MessageBox.Show(txtSDT.Text);
                    FormKhuVucBan.hd.SDT_KH = txtSDT.Text;
                    busBan.UpdateKHvaoHDTam(FormKhuVucBan.hd.MaHD, txtSDT.Text);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Đã xảy ra lỗi vui lòng kiểm tra lại");
                }
            }
        }