Ejemplo n.º 1
0
 public static BEL_DocGia GetObjectById(string Id)
 {
     try
     {
         GetConnection();
         string        Query      = string.Format("select* from DOCGIA where MaDocGia = '{0}'", Id);
         SqlCommand    Command    = new SqlCommand(Query, Connection);
         SqlDataReader DataReader = Command.ExecuteReader();
         DataReader.Read();
         string     MaDocGia  = (string)DataReader["MaDocGia"];
         string     TenDocGia = (string)DataReader["TenDocGia"];
         string     GioiTinh  = (string)DataReader["GioiTinh"];
         DateTime   NgaySinh  = (DateTime)DataReader["NgaySinh"];
         string     DiaChi    = (string)DataReader["DiaChi"];
         string     DienThoai = (string)DataReader["DienThoai"];
         string     MaLoai    = (string)DataReader["MaLoai"];
         string     HinhAnh   = (string)DataReader["HinhAnh"];
         string     TrangThai = (string)DataReader["TrangThai"];
         BEL_DocGia DocGia    = new BEL_DocGia(MaDocGia, TenDocGia, GioiTinh, NgaySinh, DiaChi, DienThoai, MaLoai, HinhAnh, TrangThai);
         return(DocGia);
     }
     catch (Exception Err)
     {
         throw;
     }
     finally
     {
         Connection.Close();
     }
 }
Ejemplo n.º 2
0
 public static bool Add(BEL_DocGia DocGia)
 {
     if (DocGia.Ma == "")
     {
         throw new Exception("Mã độc giả không được rỗng!");
     }
     if (DocGia.Ten == "")
     {
         throw new Exception("Tên độc giả không được rỗng!");
     }
     if (DocGia.GioiTinh == "")
     {
         throw new Exception("Giới tính không được rỗng!");
     }
     if (DocGia.NgaySinh == null)
     {
         throw new Exception("Ngày sinh không được rỗng!");
     }
     if (DocGia.DiaChi == "")
     {
         throw new Exception("Địa chỉ không được rỗng!");
     }
     if (DocGia.DienThoai == "")
     {
         throw new Exception("Điện thoại không được rỗng!");
     }
     if (DocGia.MatKhau == "")
     {
         throw new Exception("Mật khẩu không được rỗng!");
     }
     if (DocGia.MaLoai == "")
     {
         throw new Exception("Mã loại không được rỗng!");
     }
     if (DocGia.HinhAnh == "")
     {
         throw new Exception("Hình ảnh không được rỗng!");
     }
     if (DocGia.TrangThai == "")
     {
         throw new Exception("Trạng thái không được rỗng!");
     }
     try
     {
         return(DAL_DocGia.Add(DocGia));
     }
     catch (Exception Err)
     {
         throw;
     }
 }
Ejemplo n.º 3
0
 public static bool Update(BEL_DocGia DocGia)
 {
     try
     {
         GetConnection();
         string     Query   = string.Format("update DOCGIA set TenDocGia = N'{0}', GioiTinh = N'{1}', NgaySinh = '{2}', DiaChi = N'{3}', DienThoai = '{4}', MaLoai = '{5}', HinhAnh = N'{6}' where MaDocGia  = '{7}'", DocGia.Ten, DocGia.GioiTinh, DocGia.NgaySinh.ToString("MM-dd-yyyy"), DocGia.DiaChi, DocGia.DienThoai, DocGia.MaLoai, DocGia.HinhAnh, DocGia.Ma);
         SqlCommand Command = new SqlCommand(Query, Connection);
         int        Result  = Command.ExecuteNonQuery();
         return(Result == 1);
     }
     catch (Exception Err)
     {
         throw;
     }
     finally
     {
         Connection.Close();
     }
 }
Ejemplo n.º 4
0
 public static bool Add(BEL_DocGia DocGia)
 {
     try
     {
         GetConnection();
         DocGia.MatKhau = MD5Encode(DocGia.MatKhau);
         string     Query   = string.Format("insert into DOCGIA(MaDocGia, TenDocGia, GioiTinh, NgaySinh, DiaChi, DienThoai, MatKhau, MaLoai, HinhAnh, TrangThai) values('{0}', N'{1}', N'{2}', '{3}', N'{4}', '{5}', '{6}', '{7}', N'{8}', N'{9}')", DocGia.Ma, DocGia.Ten, DocGia.GioiTinh, DocGia.NgaySinh.ToString("MM-dd-yyyy"), DocGia.DiaChi, DocGia.DienThoai, DocGia.MatKhau, DocGia.MaLoai, DocGia.HinhAnh, DocGia.TrangThai);
         SqlCommand Command = new SqlCommand(Query, Connection);
         int        Result  = Command.ExecuteNonQuery();
         return(Result == 1);
     }
     catch (Exception Err)
     {
         throw;
     }
     finally
     {
         Connection.Close();
     }
 }
Ejemplo n.º 5
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            string maDocGia  = txtMaDocGia.Text;
            string tenDocGia = txtTenDocGia.Text;
            string gioiTinh;

            if (radNam.Checked == true)
            {
                gioiTinh = "Nam";
            }
            else
            {
                gioiTinh = "Nữ";
            }
            DateTime ngaySinh     = dtpNgaySinhDocGia.Value;
            string   diaChi       = txtDiaChiDocGia.Text;
            string   dienThoai    = txtDienThoaiDocGia.Text;
            string   matKhau      = txtMatKhauDocGia.Text;
            string   maLoaiDocGia = cboMaLoaiDocGia.Text;

            if (maLoaiDocGia == "Trẻ em")
            {
                maLoaiDocGia = "LDG001";
            }
            else if (maLoaiDocGia == "Người lớn")
            {
                maLoaiDocGia = "LDG002";
            }
            string     trangThai = txtTrangThaiDocGia.Text;
            BEL_DocGia docGia    = new BEL_DocGia(maDocGia, tenDocGia, gioiTinh, ngaySinh, diaChi, dienThoai, matKhau, maLoaiDocGia, trangThai);

            try
            {
                if (!BAL_DocGia.IsExist(maDocGia))
                {
                    if (tenDocGia == "")
                    {
                        txtTenDocGia.Focus();
                    }
                    else if (gioiTinh == "")
                    {
                        radNam.Focus();
                    }
                    else if (ngaySinh == null)
                    {
                        dtpNgaySinhDocGia.Focus();
                    }
                    else if (diaChi == "")
                    {
                        txtDiaChiDocGia.Focus();
                    }
                    else if (dienThoai == "")
                    {
                        txtDienThoaiDocGia.Focus();
                    }
                    else if (matKhau == "")
                    {
                        txtMatKhauDocGia.Focus();
                    }
                    else if (maLoaiDocGia == "")
                    {
                        cboMaLoaiDocGia.Focus();
                    }
                    else if (trangThai == "")
                    {
                        txtTrangThaiDocGia.Focus();
                    }
                    if (BAL_DocGia.Add(docGia))
                    {
                        MessageBox.Show("Thêm thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Thêm không thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Mã độc giả đã tồn tại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtMaDocGia.Focus();
                }
            }
            catch (Exception Err)
            {
                MessageBox.Show(Err.Message, "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
            }
        }