private void btnThem_Click(object sender, EventArgs e) { if (KiemTraDuLieu()) { try { BUS_DaiLy dl = new BUS_DaiLy(); var flag = dl.ThemDaiLy(txtTenDaiLy.Text, int.Parse(cbLoaiDL.EditValue.ToString()), txtDiaChi.Text, cbQuan.EditValue.ToString(), txtEmail.Text, DateTime.Parse(dtpNgayTiepNhan.EditValue.ToString())); if (flag == true) { var tb = MessageBox.Show("Bạn đã thêm đại lý thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); if (tb == DialogResult.OK) { txtTenDaiLy.Text = string.Empty; txtDiaChi.Text = string.Empty; txtEmail.Text = string.Empty; cbLoaiDL.EditValue = null; cbQuan.EditValue = null; KhiThemDaiLy(EventArgs.Empty); // https://msdn.microsoft.com/en-us/library/9aackb16(v=vs.110).aspx } } else { MessageBox.Show("Email đã tồn tại trong hệ thống.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception) { //MessageBox.Show(ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(string.Format("Thao tác không thành công. {0} đã đạt đến số đại lý tối đa.", cbQuan.EditValue.ToString()), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }