public static void Sua(LoaiPhimDTO loaiphim) { // mở kết nối SqlConnection connection = SQLConnectionData.HamKetNoi(); connection.Open(); // tạo câu lệnh Thêm SqlCommand command = connection.CreateCommand(); command.CommandType = CommandType.Text; //command.CommandText = "INSERT INTO NHANVIEN VALUES(@MANV,@HOTEN,@CHUCVU,@SDT,@GIOITINH,@NGAYSINH,@DIACHI,@LUONG,@NGAYVL)"; command.CommandText = "EXEC Sualoaiphim @MALP,@TENLP,@MOTA"; command.Parameters.Add("@MALP", SqlDbType.VarChar, 10); command.Parameters.Add("@TENLP", SqlDbType.NVarChar, 40); command.Parameters.Add("@MOTA", SqlDbType.NVarChar, 1000); // gán giá trị command.Parameters["@MALP"].Value = loaiphim.MaLP; command.Parameters["@TENLP"].Value = loaiphim.TenLP; command.Parameters["@MOTA"].Value = loaiphim.MoTa; command.ExecuteNonQuery(); // đóng kết nối connection.Close(); }
private void dtgDSLP_MouseUp(object sender, MouseButtonEventArgs e) { int index = dtgDSLP.SelectedIndex; if (index >= 0) // tránh lỗi click vẫn trong datagrid nhưng mà click chỗ k có dòng nào { Selected = true; LoaiPhimDTO nv = dtgDSLP.SelectedItem as LoaiPhimDTO; txtMalp.Text = nv.MaLP; txtTenloaiphim.Text = nv.TenLP; txtMota.Text = nv.MoTa; } }
private void BtnLuu_Click(object sender, RoutedEventArgs e) { bool TrungMaLP = false; Nhaplai: string malp = null; if (txtMaLP.Text.Length != 0) { malp = txtMaLP.Text; } string tenlp = null; if (txtTenlp.Text.Length != 0) { tenlp = txtTenlp.Text; } string mota = null; if (txtMota.Text.Length != 0) { mota = txtMota.Text; } LoaiPhimDTO lp = new LoaiPhimDTO(malp, tenlp, mota); // báo lỗi nếu chưa nhập theo thứ tự trừ trên xuống , trái sang phải if (malp == null) { if (TrungMaLP == false) { MessageBox.Show("Chưa nhập mã loại phim"); txtMaLP.Focus(); } else { MessageBox.Show("Mã loại phim trùng"); txtMaLP.Focus(); } } else if (tenlp == null) { MessageBox.Show("Chưa nhập họ tên"); txtTenlp.Focus(); } else if (mota == null) { MessageBox.Show("Chưa nhập địa chỉ"); txtMota.Focus(); } else { try { LoaiPhimBUS.Them(lp); } catch { txtMaLP.Clear(); TrungMaLP = true; goto Nhaplai; } MessageBox.Show("Thêm loại phim mới thành công", "Thông báo"); this.Close(); } }
private void BtnLuu_Sua_Click(object sender, RoutedEventArgs e) { bool TrungMaLP = false; SuaLai: string malp = null; if (txtMalp.Text.Length != 0) { malp = txtMalp.Text; } string tenlp = null; if (txtTenloaiphim.Text.Length != 0) { tenlp = txtTenloaiphim.Text; } string mota = null; if (txtMota.Text.Length != 0) { mota = txtMota.Text; } LoaiPhimDTO lp = new LoaiPhimDTO(malp, tenlp, mota); if (malp == null) { if (TrungMaLP == false) { MessageBox.Show("Mã số loại phim không được để trống"); } else { MessageBox.Show("Mã số loại phim bị trùng"); } txtMalp.Focus(); } else if (tenlp == null) { MessageBox.Show("Tên loại phim không được để trống"); txtTenloaiphim.Focus(); } else if (mota == null) { MessageBox.Show("Mô tả không được để trống"); txtMota.Focus(); } else { try { LoaiPhimBUS.Sua(lp); } catch { txtMalp.Clear(); TrungMaLP = true; goto SuaLai; } MessageBox.Show("Sửa thông tin loại phim thành công", "Thông báo"); DataTable dataTable = new DataTable(); dataTable = LoaiPhimBUS.LoadDSLP(); Load_Data(dataTable); KhongChoNhap(); btnHuy_Sua.Visibility = btnLuu_Sua.Visibility = Visibility.Hidden; btnSua.Visibility = Visibility.Visible; btnThem.IsEnabled = btnXoa.IsEnabled = true; dtgDSLP.IsEnabled = true; Selected = false; } }
public static void Sua(LoaiPhimDTO lp) { LoaiPhimDAO.Sua(lp); }
public static void Them(LoaiPhimDTO lp) { LoaiPhimDAO.Them(lp); }