private void matudong() { string masach = "S001"; int dem = 0; while (Sach_BUS.TimSach_TheoMa(masach) != null) { dem += 1; if (dem < 10) { masach = "S00" + dem.ToString(); } else if (dem < 100) { masach = "S0" + dem.ToString(); } else if (dem < 1000) { masach = "S" + dem.ToString(); } else { MessageBox.Show("Không thể thêm nhân viên. Không đủ bộ nhớ!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } txtmasach.Text = masach; }
private void btnXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (Sach_BUS.TimSach_TheoMa(txtmasach.Text.Trim()) == null) { XtraMessageBox.Show("Bạn chưa chọn dòng cần xóa ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { DialogResult thongbao = XtraMessageBox.Show("Bạn có chắc muốn xóa không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (thongbao == DialogResult.No) { XtraMessageBox.Show("Bạn đã hủy tháo tác xóa ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (thongbao == DialogResult.Yes) { //Sach_DTO s = new Sach_DTO(); //s.MaSach = txtmasach.Text; //if (Sach_BUS.XoaSach(txtmasach.Text.Trim())) //{ con = new SqlConnection(conn); con.Open(); SqlCommand cmd = new SqlCommand(); //Thiết lập các thuộc tính cho đối tượng Command cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = con; cmd.CommandText = "DeleteSach"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@MaSach", txtmasach.Text); cmd.ExecuteNonQuery(); Form1_Load(sender, e); XtraMessageBox.Show("Bạn đã xóa thành công sách ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); //} } } }