예제 #1
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            string         maNhaXuatBan  = txtMaNhaXuatBan.Text;
            string         tenNhaXuatBan = txtTenNhaXuatBan.Text;
            string         email         = txtEmail.Text;
            string         trangThai     = "Tồn tại";
            BEL_NhaXuatBan nhaXuatBan    = new BEL_NhaXuatBan(maNhaXuatBan, tenNhaXuatBan, email, trangThai);

            //
            try
            {
                if (BAL_NhaXuatBan.Add(nhaXuatBan))
                {
                    MessageBox.Show("Thêm thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //
                    txtMaNhaXuatBan.Text = "NXB" + (BAL_NhaXuatBan.Count() + 1);
                    txtTenNhaXuatBan.Focus();
                }
                else
                {
                    MessageBox.Show("Thêm thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #2
0
 public static bool Update(BEL_NhaXuatBan NhaXuatBan)
 {
     if (NhaXuatBan.Ma == "")
     {
         throw new Exception("Mã nhà xuất bản không được rỗng!");
     }
     if (NhaXuatBan.Ten == "")
     {
         throw new Exception("Tên nhà xuất bản không được rỗng!");
     }
     if (NhaXuatBan.Email == "")
     {
         throw new Exception("Email không được rỗng!");
     }
     if (NhaXuatBan.TrangThai == "")
     {
         throw new Exception("Trạng thái không được rỗng!");
     }
     try
     {
         return(DAL_NhaXuatBan.Update(NhaXuatBan));
     }
     catch (Exception Err)
     {
         throw;
     }
 }
예제 #3
0
 public BEL_NhaXuatBan(BEL_NhaXuatBan NhaXuatBan)
 {
     _Ma        = NhaXuatBan._Ma;
     _Ten       = NhaXuatBan._Ten;
     _Email     = NhaXuatBan._Email;
     _TrangThai = NhaXuatBan._TrangThai;
 }
예제 #4
0
 public static BEL_NhaXuatBan GetObjectById(string Id)
 {
     try
     {
         GetConnection();
         string        Query      = string.Format("select* from NHAXUATBAN where MaNhaXuatBan = '{0}'", Id);
         SqlCommand    Command    = new SqlCommand(Query, Connection);
         SqlDataReader DataReader = Command.ExecuteReader();
         DataReader.Read();
         string         MaNhaXuatBan  = (string)DataReader["MaNhaXuatBan"];
         string         TenNhaXuatBan = (string)DataReader["TenNhaXuatBan"];
         string         Email         = (string)DataReader["Email"];
         string         TrangThai     = (string)DataReader["TrangThai"];
         BEL_NhaXuatBan NhaXuatBan    = new BEL_NhaXuatBan(MaNhaXuatBan, TenNhaXuatBan, Email, TrangThai);
         return(NhaXuatBan);
     }
     catch (Exception Err)
     {
         throw;
     }
     finally
     {
         Connection.Close();
     }
 }
예제 #5
0
        private void btnSuaNhaXuatBan_Click(object sender, EventArgs e)
        {
            string         maNhaXuatBan  = txtMaNhaXuatBan.Text;
            string         tenNhaXuatBan = txtTenNhaXuatBan.Text;
            string         email         = txtEmailNhaXuatBan.Text;
            string         trangThai     = "Tồn tại";
            BEL_NhaXuatBan nhaXuatBan    = new BEL_NhaXuatBan(maNhaXuatBan, tenNhaXuatBan, email, trangThai);

            try
            {
                if (BAL_NhaXuatBan.Update(nhaXuatBan))
                {
                    MessageBox.Show("Cập nhật thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    loadDanhSachNhaXuatBan(dgvDanhSachNhaXuatBan, BAL_NhaXuatBan.Load());
                    //
                    for (int i = 0; i < dgvDanhSachNhaXuatBan.RowCount; i++)
                    {
                        if (dgvDanhSachNhaXuatBan["MaNhaXuatBan", i].Value.ToString() == maNhaXuatBan)
                        {
                            dgvDanhSachNhaXuatBan["MaNhaXuatBan", i].Selected = true;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Cập nhật thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #6
0
        private void dgvDanhSachNhaXuatBan_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            string         maNhaXuatBan = dgvDanhSachNhaXuatBan.CurrentRow.Cells["MaNhaXuatBan"].Value.ToString().Trim();
            BEL_NhaXuatBan nhaXuatBan   = BAL_NhaXuatBan.GetObjectById(maNhaXuatBan);

            txtMaNhaXuatBan.Text    = nhaXuatBan.Ma;
            txtTenNhaXuatBan.Text   = nhaXuatBan.Ten;
            txtEmailNhaXuatBan.Text = nhaXuatBan.Email;
        }
예제 #7
0
 public static bool Update(BEL_NhaXuatBan NhaXuatBan)
 {
     try
     {
         GetConnection();
         string     Query   = string.Format("update NHAXUATBAN set TenNhaXuatBan = N'{0}', Email = '{1}' where MaNhaXuatBan = '{2}'", NhaXuatBan.Ten, NhaXuatBan.Email, NhaXuatBan.Ma);
         SqlCommand Command = new SqlCommand(Query, Connection);
         int        Result  = Command.ExecuteNonQuery();
         return(Result == 1);
     }
     catch (Exception Err)
     {
         throw;
     }
     finally
     {
         Connection.Close();
     }
 }
예제 #8
0
 public static bool Add(BEL_NhaXuatBan NhaXuatBan)
 {
     try
     {
         GetConnection();
         string     Query   = string.Format("insert into NHAXUATBAN(MaNhaXuatBan, TenNhaXuatBan, Email, TrangThai) values('{0}', N'{1}', '{2}', N'{3}')", NhaXuatBan.Ma, NhaXuatBan.Ten, NhaXuatBan.Email, NhaXuatBan.TrangThai);
         SqlCommand Command = new SqlCommand(Query, Connection);
         int        Result  = Command.ExecuteNonQuery();
         return(Result == 1);
     }
     catch (Exception Err)
     {
         throw;
     }
     finally
     {
         Connection.Close();
     }
 }