private void simpleButton1_Click_1(object sender, EventArgs e) { int idDaiLy = dsIdDL[cbDaiLy.SelectedIndex]; DateTime ngayXuat = dtNgayLap.Value; //Console.WriteLine(ngayXuat.ToString("yyyy-MM-dd")); float tienCon = (float)Convert.ToDouble(txtTienCon.Text); float tienNo = BUS_DaiLy.GetTienNo(idDaiLy); float tienNoMoi = tienCon + tienNo; int kqUpdate = BUS_DaiLy.UpdateTienNo(idDaiLy, tienNoMoi); if (kqUpdate == 1) { string cmnd = taiKhoan.Cmnd; DTO_PhieuXuatHang phieuXuatHang = new DTO_PhieuXuatHang(0, ngayXuat, idDaiLy, cmnd); int idPhieuXuat = BUS_PhieuXuat.ThemPhieuXuatGetId(phieuXuatHang); foreach (DataRow r in tb.Rows) { DTO_ChiTietXuat ctx = new DTO_ChiTietXuat(idPhieuXuat, (int)r[0], (int)r[2], (float)r[4], r[3].ToString(), (float)r[5]); BUS_ChiTietXuat.ThemChiTietXuat(ctx); } } else { } }
/// <summary> /// Xuất danh sách đại lý dưới định dạng Excel /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void navBarXuatDSExcel_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e) { var dl = new BUS_DaiLy(); var flag = MessageBox.Show("Bạn muốn xuất danh sách đại lý dưới định dạng Excel ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (flag == DialogResult.Yes) { progressBar1.Visible = true; label1.Visible = true; if (backgroundWorker1.IsBusy) { return; } using (SaveFileDialog sf = new SaveFileDialog() { Filter = "Excel workbook|*.xls" }) { if (sf.ShowDialog() == DialogResult.OK) { DSDaiLi.FileName = sf.FileName; DSDaiLi.DaiLi = dl.DanhSachDaiLy(); progressBar1.Minimum = 0; progressBar1.Value = 0; backgroundWorker1.RunWorkerAsync(DSDaiLi); } }; } else { return; } }
private void btnAdd_Click(object sender, EventArgs e) { if (idDL != -1 && arrIdLDL[cbLoaiDL.SelectedIndex] >= 0 && arrIdQuan[cbQuan.SelectedIndex] >= 0 && txtTienNo.Text.Equals("") == false && txtTenDaiLy.Text.Equals("") == false && txtSdt.Text.Equals("") == false && txtDiaChi.Text.Equals("") == false) { DTO_DaiLy dl = new DTO_DaiLy(); dl.IdDL = 1; dl.IdLoaiDL = arrIdLDL[cbLoaiDL.SelectedIndex]; dl.IdQuan = arrIdQuan[cbQuan.SelectedIndex]; dl.TenDaiLy = txtTenDaiLy.Text; dl.Sdt = txtSdt.Text; dl.Cmnd = nhanVien.Cmnd; dl.DiaChi = txtDiaChi.Text; dl.NgayNhan = DateTime.Now; dl.TienNo = 0; if (BUS_DaiLy.Themdaily(dl) == 0) { } else { dsDaiLy = BUS_DaiLy.DsDaiLy(); UpdateGvDaiLy(); } } }
private void btnModify_Click(object sender, EventArgs e) { if (idDL != -1 && arrIdLDL[cbLoaiDL.SelectedIndex] >= 0 && arrIdQuan[cbQuan.SelectedIndex] >= 0 && txtTienNo.Text.Equals("") == false && txtTenDaiLy.Text.Equals("") == false && txtSdt.Text.Equals("") == false && txtDiaChi.Text.Equals("") == false) { DTO_DaiLy dl = new DTO_DaiLy(); dl.IdDL = idDL; dl.IdLoaiDL = arrIdLDL[cbLoaiDL.SelectedIndex]; dl.IdQuan = arrIdQuan[cbQuan.SelectedIndex]; dl.TienNo = (float)Convert.ToDouble(txtTienNo.Text); dl.TenDaiLy = txtTenDaiLy.Text; dl.Sdt = txtSdt.Text; dl.DiaChi = txtDiaChi.Text; dl.Cmnd = nhanVien.Cmnd; dl.NgayNhan = DateTime.Now; int kq = BUS_DaiLy.SuaDaiLy(dl); if (kq == 1) { dsDaiLy = BUS_DaiLy.DsDaiLy(); UpdateGvDaiLy(); MessageBox.Show("Cập nhật thành công"); } else if (kq == 3) { MessageBox.Show("Loại đại lý đã đủ số lượng"); } else { MessageBox.Show("Cập nhật thất bại"); } } }
private void btnSua_Click(object sender, EventArgs e) { if (KiemTraDuLieu()) { try { var tb = MessageBox.Show("Bạn có chắc chắn muốn chỉnh sửa thông tin của đại lý ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (tb == DialogResult.Yes) { BUS_DaiLy dl = new BUS_DaiLy(); var flag = dl.SuaDaiLy(int.Parse(txtMaDaiLy.Text), txtTenDaiLy.Text, int.Parse(cbLoaiDL.EditValue.ToString()), txtDiaChi.Text, cbQuan.EditValue.ToString(), txtEmail.Text, DateTime.Parse(dtpNgayTiepNhan.EditValue.ToString())); if (flag == true) { MessageBox.Show("Bạn đã chỉnh sửa thông tin đại lý thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); KhiSuaDaiLy(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); } } else { return; } } catch (Exception) { 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); } } }
private void btnKinhDoanh_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { int madl = int.Parse(gridViewDLNgungKD.GetFocusedRowCellValue("MaDaiLy").ToString()); string tendl = gridViewDLNgungKD.GetFocusedRowCellValue("TenDaiLy").ToString(); string quan = gridViewDLNgungKD.GetFocusedRowCellValue("Quan").ToString(); var tb = MessageBox.Show(string.Format("Bạn có chắc chắn muốn tiếp tục kinh doanh đại lý <{0}> ?", tendl), "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (tb == DialogResult.Yes) { BUS_DaiLy daily = new BUS_DaiLy(); var flag = daily.TiepTucKinhDoanh(madl, quan); if (flag == true) { MessageBox.Show(string.Format("Bạn đã tiếp tục kinh doanh đại lý <{0}> thành công.", tendl), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); KhiKinhDoanhLaiDaiLy(EventArgs.Empty); // https://msdn.microsoft.com/en-us/library/9aackb16(v=vs.110).aspx this.FormLoad(); } else { MessageBox.Show(string.Format("Thao tác không thành công. {0} đã đạt đến số đại lý tối đa.", quan), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { return; } }
private void frmLapPhieuXuatHang_Load(object sender, EventArgs e) { this.FormLoad(); // https://www.devexpress.com/Support/Center/Question/Details/Q20064/comboboxedit-how-do-you-set-the-datasource // Lookup-edit Đại lý BUS_DaiLy dl = new BUS_DaiLy(); cbDaiLy.Properties.DataSource = dl.DanhSachDaiLy(); cbDaiLy.Properties.DisplayMember = "TenDaiLy"; cbDaiLy.Properties.ValueMember = "MaDaiLy"; cbDaiLy.Properties.Columns.Add(new LookUpColumnInfo("TenDaiLy", "Tên Đại Lý")); cbDaiLy.Properties.Columns.Add(new LookUpColumnInfo("Quan", "Quận")); cbDaiLy.Properties.Columns.Add(new LookUpColumnInfo("DiaChi", "Địa Chỉ")); // Date edit dtpNgayLap.EditValue = DateTime.Now; // Thêm hàng hóa vào giỏ hàng dt = new DataTable(); dt.Columns.Add("Mã Hàng Hóa"); dt.Columns.Add("Tên Hàng Hóa"); dt.Columns.Add("Đơn Vị Tính"); dt.Columns.Add("Đơn Giá"); dt.Columns.Add("Số Lượng Mua"); dt.Columns.Add("Thành Tiền"); dgvGioHang.DataSource = dt; }
private void cbSoLuongSP_SelectedIndexChanged(object sender, EventArgs e) { BUS_DaiLy dl = new BUS_DaiLy(); if (cbSoLuongSP.Text == "Tất Cả") { dgvDaiLy.DataSource = dl.DanhSachDaiLy(); lbtrang.Text = ""; btnlui.Enabled = false; btntien.Enabled = false; cbTrang.Enabled = false; } else { int t = dl.SoLuongTrang(int.Parse(cbSoLuongSP.Text)); cbTrang.DataSource = dl.DStrang(t); if (int.Parse(cbTrang.Text) == 1) { btnlui.Enabled = false; } else { btnlui.Enabled = true; } if (int.Parse(cbTrang.Text) == t) { btntien.Enabled = false; } else { btntien.Enabled = true; } dgvDaiLy.DataSource = dl.DSdaili(int.Parse(cbTrang.Text), int.Parse(cbSoLuongSP.Text)); } }
private void btntien_Click(object sender, EventArgs e) { BUS_DaiLy dl = new BUS_DaiLy(); cbTrang.Text = (int.Parse(cbTrang.Text) + 1).ToString(); dgvDaiLy.DataSource = dl.DSdaili(int.Parse(cbTrang.Text), int.Parse(cbSoLuongSP.Text)); }
private void Load() { tb = new DataTable(); dsDaiLy = BUS_DaiLy.DsDaiLy(); txtDiaChi.Modified = false; txtNguoiThu.Modified = false; txtSdt.Modified = false; txtTienNo.Modified = false; dsIdDL = new int[dsDaiLy.Count]; int i = 0; tb = new DataTable(); tb.Columns.Add("idDL", typeof(int)); tb.Columns.Add("diachi", typeof(string)); tb.Columns.Add("sdt", typeof(string)); tb.Columns.Add("tienno", typeof(float)); foreach (DTO_DaiLy dl in dsDaiLy) { dsIdDL[i] = dl.IdDL; string tendaily = BUS_DaiLy.GetTenById(dl.IdDL); cbDaiLy.Items.Add(tendaily); tb.Rows.Add(dl.IdDL, dl.DiaChi, dl.Sdt, dl.TienNo); i++; } cbDaiLy.SelectedIndex = 0; }
private void btnThu_Click(object sender, EventArgs e) { if (txtTienThu.Text.Equals("") == false) { float tienNo = (float)Convert.ToDouble(txtTienNo.Text); float tienThu = (float)Convert.ToDouble(txtTienThu.Text); if (tienThu <= tienNo) { int id = dsIdDL[cbDaiLy.SelectedIndex]; DateTime ngayThu = dtNgayThu.Value; float soTienThu = (float)Convert.ToDouble(txtTienThu.Text); string cmnd = nhanVien.Cmnd; DTO_PhieuThuTien pt = new DTO_PhieuThuTien(0, ngayThu, soTienThu, id, cmnd); BUS_PhieuThuTien.ThemPhieuThu(pt); float tienNoMoi = tienNo - tienThu; int kq = BUS_DaiLy.UpdateTienNo(id, tienNoMoi); if (kq == 1) { MessageBox.Show("Thu thành công"); txtTienNo.Text = BUS_DaiLy.GetTienNo(id).ToString(); txtTienThu.Text = ""; } else if (kq == 2) { MessageBox.Show("tiền nợ vượt quá quy định"); } else { MessageBox.Show("Thu thất bại"); } } } }
private void btnDelete_Click(object sender, EventArgs e) { if (BUS_DaiLy.XoaDaiLy(idDL) == 0) { } else { dsDaiLy = BUS_DaiLy.DsDaiLy(); UpdateGvDaiLy(); } }
private void txtsearch_EditValueChanged_1(object sender, EventArgs e) { if (txtsearch.Text.Equals("") == false) { dsDaiLy = BUS_DaiLy.Search(txtsearch.Text); UpdateGvDaiLy(); } else { dsDaiLy = BUS_DaiLy.DsDaiLy(); UpdateGvDaiLy(); } }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { tb.Clear(); if (cbThang.SelectedIndex != -1) { int thang = int.Parse(cbThang.SelectedItem.ToString()); doanhSo = BUS_BaoCaoDoanhSo.GetDoanhSo(thang); foreach (DTO_DoanhSo dso in doanhSo) { string tendl = BUS_DaiLy.GetTenById(dso.IdDaiLy); tb.Rows.Add(dso.IdDaiLy, tendl, dso.SoPhieuXuat, dso.TongDoanhSo, dso.TiLe + "%"); } gvDoanhSo.DataSource = tb; } }
private void cbCN_SelectedIndexChanged(object sender, EventArgs e) { tb.Clear(); if (cbCN.SelectedIndex != -1) { int thang = int.Parse(cbCN.SelectedItem.ToString()); congNo = BUS_BaoCaoCongNo.GetCongNo(thang); foreach (DTO_CongNo dso in congNo) { string tendl = BUS_DaiLy.GetTenById(dso.IdDaiLy); tb.Rows.Add(dso.IdDaiLy, tendl, dso.NoDau, dso.NoCuoi); } gvCN.DataSource = tb; } }
private void btnThem_Click(object sender, EventArgs e) { if (txtTienCon.Text.Equals("") == false) { int idDaiLy = dsIdDL[cbDaiLy.SelectedIndex]; DateTime ngayXuat = dtNgayLap.Value; //Console.WriteLine(ngayXuat.ToString("yyyy-MM-dd")); float tienCon = (float)Convert.ToDouble(txtTienCon.Text); float tienNo = BUS_DaiLy.GetTienNo(idDaiLy); Console.WriteLine(tienNo); float tienNoMoi = tienCon + tienNo; int kqUpdate = BUS_DaiLy.UpdateTienNo(idDaiLy, tienNoMoi); if (kqUpdate == 1) { string cmnd = taiKhoan.Cmnd; DTO_PhieuXuatHang phieuXuatHang = new DTO_PhieuXuatHang(0, ngayXuat, idDaiLy, cmnd); int idPhieuXuat = BUS_PhieuXuat.ThemPhieuXuatGetId(phieuXuatHang); foreach (DataRow r in tb.Rows) { int idMatHang = (int)r[0]; int soLuong = int.Parse(r[2].ToString()); float donGia = (float)Convert.ToDouble(r[4]); string donViTinh = r[3].ToString(); float thanhTien = (float)Convert.ToDouble(r[5]); // DTO_ChiTietXuat ctx = new DTO_ChiTietXuat(idPhieuXuat, (int)r[0], (int)r[2], (float)Convert.ToDouble(r[4]), r[3].ToString(), (float)Convert.ToDouble(r[5])); DTO_ChiTietXuat ctx = new DTO_ChiTietXuat(idPhieuXuat, idMatHang, soLuong, donGia, donViTinh, thanhTien); BUS_ChiTietXuat.ThemChiTietXuat(ctx); } MessageBox.Show("Xuất thành công"); } else if (kqUpdate == 2) { MessageBox.Show("Số tiền còn lại cộng với nợ cũ vượt quy định"); } else { MessageBox.Show("Xuất thất bại"); } //tb.Columns.Add("Id", typeof(int)); //tb.Columns.Add("Mặt hàng", typeof(string)); //tb.Columns.Add("Số lượng", typeof(string)); //tb.Columns.Add("đơn vị tính", typeof(string)); //tb.Columns.Add("Đơn giá", typeof(string)); //tb.Columns.Add("Thành tiền", typeof(string)); } }
private void UpdateGvDaiLy() { ResetTable(); int t = 0; foreach (DTO_DaiLy dl in dsDaiLy) { arrIdDL[t] = dl.IdDL; t++; string tenDL = BUS_DaiLy.GetTenById(dl.IdDL); string tenQuan = BUS_Quan.GetTen(dl.IdQuan); string tenLoaiDL = BUS_LoaiDL.GetTenById(dl.IdLoaiDL); string tenNV = BUS_NhanVien.GetTenNV(dl.Cmnd); string ngay = dl.NgayNhan.ToString("dd/MM/yyyy"); tb.Rows.Add(dl.IdDL, dl.IdLoaiDL, dl.IdQuan, tenDL, tenLoaiDL, dl.Sdt, tenQuan, ngay, tenNV, dl.TienNo, dl.DiaChi); } }
private void FormLoad() { // https://www.devexpress.com/Support/Center/Question/Details/Q20064/comboboxedit-how-do-you-set-the-datasource // Lookup-edit Đại lý BUS_DaiLy dl = new BUS_DaiLy(); cbDaiLy.Properties.DataSource = dl.DanhSachDaiLy(); cbDaiLy.Properties.DisplayMember = "TenDaiLy"; cbDaiLy.Properties.ValueMember = "MaDaiLy"; cbDaiLy.Properties.Columns.Add(new LookUpColumnInfo("TenDaiLy", "Tên Đại Lý")); cbDaiLy.Properties.Columns.Add(new LookUpColumnInfo("Quan", "Quận")); cbDaiLy.Properties.Columns.Add(new LookUpColumnInfo("DiaChi", "Địa Chỉ")); // Date edit dtpNgayLap.EditValue = DateTime.Now; }
private void Load() { idDL = -1; idLoaiDL = -1; idQuan = -1; txtTenDaiLy.Text = ""; cbLoaiDL.SelectedItem = ""; txtSdt.Text = ""; cbQuan.SelectedItem = ""; dtNgayNhan.Value = DateTime.Now; txtNguoiNhan.Text = ""; txtTienNo.Text = ""; txtDiaChi.Text = ""; //txtNguoiNhan.Enabled = false; dsDaiLy = BUS_DaiLy.DsDaiLy(); dsQuan = BUS_Quan.DSquan(); dsLoaiDL = BUS_LoaiDL.DsLoaiDL(); arrIdDL = new int[dsDaiLy.Count]; arrIdLDL = new int[dsLoaiDL.Count]; arrIdQuan = new int[dsQuan.Count]; int i = 0; foreach (DTO_LoaiDL ldl in dsLoaiDL) { cbLoaiDL.Items.Add(ldl.TenLoaiDL); arrIdLDL[i] = ldl.IdLoaiDL; i++; } int j = 0; foreach (DTO_Quan ldl in dsQuan) { cbQuan.Items.Add(ldl.TenQuan); arrIdQuan[j] = ldl.IdQuan; j++; } gvDaiLy.DataSource = tb; gvDaiLy.Columns["IdDL"].Visible = false; gvDaiLy.Columns["IdLoaiDL"].Visible = false; gvDaiLy.Columns["IdQuan"].Visible = false; UpdateGvDaiLy(); }
private void btnAdd_Click(object sender, EventArgs e) { if (txtTienThu.Text.Equals("") == false) { float tienNo = (float)Convert.ToDouble(txtTienNo.Text); float tienThu = (float)Convert.ToDouble(txtTienThu.Text); if (tienThu <= tienNo) { int id = dsIdDL[cbDaiLy.SelectedIndex]; DateTime ngayThu = dtNgayThu.Value; float soTienThu = (float)Convert.ToDouble(txtTienThu.Text); string cmnd = nhanVien.Cmnd; DTO_PhieuThuTien pt = new DTO_PhieuThuTien(0, ngayThu, soTienThu, id, cmnd); BUS_PhieuThuTien.ThemPhieuThu(pt); float tienNoMoi = tienNo - tienThu; BUS_DaiLy.UpdateTienNo(id, tienNoMoi); } } }
private void frmDaiLy_Load(object sender, EventArgs e) { BUS_DaiLy dl = new BUS_DaiLy(); this.FormLoad(); cbSoLuongSP.SelectedIndex = 4; if (cbSoLuongSP.Text == "Tất Cả") { dgvDaiLy.DataSource = dl.DanhSachDaiLy(); lbtrang.Text = ""; btnlui.Enabled = false; btntien.Enabled = false; cbTrang.Enabled = false; } else { int t = dl.SoLuongTrang(int.Parse(cbSoLuongSP.Text)); cbTrang.DataSource = dl.DStrang(t); lbtrang.Text = "Trang " + cbTrang.Text + "/" + t.ToString(); dgvDaiLy.DataSource = dl.DSdaili(int.Parse(cbTrang.Text), int.Parse(cbSoLuongSP.Text)); if (int.Parse(cbTrang.Text) == 1) { btnlui.Enabled = false; } else { btnlui.Enabled = true; } if (int.Parse(cbTrang.Text) == t) { btntien.Enabled = false; } else { btntien.Enabled = true; } } }
private void navbarXoa_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e) { var flag = MessageBox.Show(string.Format("Bạn có chắc chắn muốn ngừng kinh doanh đại lý {0} ?", gridViewDaiLy.GetFocusedRowCellValue("TenDaiLy").ToString()), "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (flag == DialogResult.Yes) { BUS_DaiLy dl = new BUS_DaiLy(); int madl = int.Parse(gridViewDaiLy.GetFocusedRowCellValue("MaDaiLy").ToString()); string tendl = gridViewDaiLy.GetFocusedRowCellValue("TenDaiLy").ToString(); string tenquan = gridViewDaiLy.GetFocusedRowCellValue("Quan").ToString(); var tb = dl.XoaDaiLy(madl, tenquan); if (tb == true) { MessageBox.Show(string.Format("Bạn đã ngừng kinh doanh đại lý <{0}> thành công.", tendl), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); this.FormLoad(); } } else { return; } }
private void Load() { tongTien = 0; //tb = new DataTable(); dsDaiLy = BUS_DaiLy.DsDaiLy(); dsIdDL = new int[dsDaiLy.Count]; foreach (DataRow r in tb.Rows) { tongTien = tongTien + (float)Convert.ToDouble(r[5].ToString()); } int i = 0; foreach (DTO_DaiLy dl in dsDaiLy) { cbDaiLy.Items.Add(dl.TenDaiLy); dsIdDL[i] = dl.IdDL; i++; } cbDaiLy.SelectedIndex = 0; gvhang.DataSource = tb; txtTongTien.Text = tongTien.ToString(); }
private void cbTrang_SelectedIndexChanged(object sender, EventArgs e) { BUS_DaiLy dl = new BUS_DaiLy(); int t = dl.SoLuongTrang(int.Parse(cbSoLuongSP.Text)); if (int.Parse(cbTrang.Text) == 1) { btnlui.Enabled = false; } else { btnlui.Enabled = true; } if (int.Parse(cbTrang.Text) == t) { btntien.Enabled = false; } else { btntien.Enabled = true; } lbtrang.Text = "Trang " + cbTrang.Text + "/" + t.ToString(); dgvDaiLy.DataSource = dl.DSdaili(int.Parse(cbTrang.Text), int.Parse(cbSoLuongSP.Text)); }
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); } } }
private bool KiemTraDuLieu() { ErrorChecker.Clear(); // giả sử ban đầu mọi dữ liệu là đúng BUS_DaiLy dl = new BUS_DaiLy(); if (string.IsNullOrWhiteSpace(txtTenDaiLy.Text) || string.IsNullOrEmpty(txtTenDaiLy.Text)) { ErrorChecker.BlinkRate = 500; ErrorChecker.SetError(txtTenDaiLy, "Không được để trống."); return(false); } int madl = int.Parse(txtMaDaiLy.Text); if (dl.KiemTraTenDaiLy(madl, txtTenDaiLy.Text) == false) { ErrorChecker.BlinkRate = 500; ErrorChecker.SetError(txtTenDaiLy, "Tên đại lý đã tồn tại.\nGợi ý: Bạn hãy kiểm tra danh sách đại lý ngừng kinh doanh."); return(false); } if (string.IsNullOrWhiteSpace(txtDiaChi.Text) || string.IsNullOrEmpty(txtDiaChi.Text)) { ErrorChecker.BlinkRate = 500; ErrorChecker.SetError(txtDiaChi, "Không được để trống."); return(false); } if (cbLoaiDL.EditValue == null) { ErrorChecker.BlinkRate = 500; ErrorChecker.SetError(cbLoaiDL, "Không được để trống."); return(false); } if (cbQuan.EditValue == null) { ErrorChecker.BlinkRate = 500; ErrorChecker.SetError(cbQuan, "Không được để trống."); return(false); } // Kiểm tra Email hợp lệ // https://stackoverflow.com/a/19475049/7385686 // https://docs.microsoft.com/en-us/dotnet/standard/base-types/how-to-verify-that-strings-are-in-valid-email-format // https://docs.microsoft.com/en-us/dotnet/standard/base-types/anchors-in-regular-expressions string pattern = @"\A[a-z0-9]+([-._][a-z0-9]+)*@([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,4}\z"; if (txtEmail.Text.Length == 0) { ErrorChecker.Clear(); return(true); } if (Regex.IsMatch(txtEmail.Text, pattern)) { if (dl.KTEmailTonTai(int.Parse(txtMaDaiLy.Text), txtEmail.Text) == false) { ErrorChecker.BlinkRate = 500; ErrorChecker.SetError(txtEmail, "Email đã tồn tại trong hệ thống."); return(false); } } if (Regex.IsMatch(txtEmail.Text, pattern) == false) { ErrorChecker.BlinkRate = 500; ErrorChecker.SetError(txtEmail, "Email không hợp lệ."); return(false); } else { ErrorChecker.Clear(); } return(true); }