Esempio n. 1
0
 private void txtMaLoai_Validated(object sender, EventArgs e)
 {
     if (this.txtMaLoai.Text != string.Empty)
     {
         var kq = LoaiSanPhamBUS.LayDanhSachMaLoai().Where(p => p.MALOAI == this.txtMaLoai.Text).FirstOrDefault();
         if (kq != null)
         {
             MessageBox.Show("Mã loại đã tồn tại !!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
             this.txtMaLoai.Focus();
             return;
         }
         if (this.txtMaLoai.Text == string.Empty)
         {
             return;
         }
         if (this.txtMaLoai.Text.Length > 10)
         {
             MessageBox.Show("Mã loại không được vượt quá 10 kí tự !!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
             this.txtMaLoai.Focus();
             return;
         }
         if (!KiemtraDinhDangMALOAI(this.txtMaLoai.Text))
         {
             MessageBox.Show("Mã loại không đúng định dạng !!!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
             this.txtMaLoai.Focus();
             return;
         }
     }
 }