public bool DAL_SuaDP(DTO_DP DP, int id) { try { cnn.Open(); SqlCommand cmd = new SqlCommand("UPDATE DanhMucDP Set TenDP = N'" + DP.txtTenDP + "', NhaSanXuat = N'" + DP.txtNhaSanXuat + "', DVT = N'" + DP.cbDVT + "', GiaNhap = N'" + DP.txtGiaNhap + "', GiaBan = N'" + DP.txtGiaBan + "'WHERE MaDP = " + id, cnn); if (cmd.ExecuteNonQuery() > 0) { return(true); } else { return(false); } } catch { return(false); } finally { cnn.Close(); } }
public bool DAL_ThemDP(DTO_DP DP) { try { cnn.Open(); string commandText2 = "insert into DanhMucDP (TenDP, NhaSanXuat, DVT, SoLuong, GiaNhap, GiaBan) values (@TenDP, @NhaSanXuat, @DVT, @SoLuong, @GiaNhap, @GiaBan)"; SqlCommand sqlCommand2 = new SqlCommand(commandText2, cnn); sqlCommand2.Parameters.AddWithValue("@TenDP", DP.txtTenDP); sqlCommand2.Parameters.AddWithValue("@NhaSanXuat", DP.txtNhaSanXuat); sqlCommand2.Parameters.AddWithValue("@DVT", DP.cbDVT); sqlCommand2.Parameters.AddWithValue("@SoLuong", "0"); sqlCommand2.Parameters.AddWithValue("@GiaNhap", DP.txtGiaNhap); sqlCommand2.Parameters.AddWithValue("@GiaBan", DP.txtGiaBan); if (sqlCommand2.ExecuteNonQuery() > 0) { return(true); } else { return(false); } } catch { return(false); } finally { cnn.Close(); } }
private void btnThem_Click(object sender, EventArgs e) { if (cbDVT.Text == "" || cbDVT.Text == "" || txtTenDP.Text == "" || txtNhaSanXuat.Text == "" || txtGiaBan.Text == "" || txtGiaNhap.Text == "") { MessageBox.Show("Không được đê trống", "Lưu ý", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (Quyen_ThemDP == "1") { try { if (BUS.BUS_GetTenDP(txtTenDP.Text).Read()) { MessageBox.Show("Tên Dược phẩm này đã tồn tại!\nVui lòng nhập lại tên khác.", "Thông báo"); btnThem.Enabled = false; } else { DTO_DP DP = new DTO_DP(txtTenDP.Text, txtNhaSanXuat.Text, cbDVT.Text, txtGiaNhap.Text, txtGiaBan.Text); if (BUS.BUS_ThemDP(DP) == true) { MessageBox.Show("Đã cập nhật dữ liệu này thành công", "Thông báo"); cbDVT.Text = ""; txtGiaBan.Text = ""; txtGiaNhap.Text = ""; txtNhaSanXuat.Text = ""; txtTenDP.Text = ""; } else { MessageBox.Show("Lỗi!\nKhông thể cập nhật dữ liệu!", "Thông báo"); } } } catch { MessageBox.Show("Lỗi kết nối đến CSDL!"); kn.ShowDialog(); } } else { MessageBox.Show("Bạn không có quyền truy cập vào chức năng này!\nLiên hệ với Admin để biết thêm chi tiết.", "Thông báo"); } } }
private void btnThem_Sua_Click(object sender, EventArgs e) { if (cbDVT.Text == "" || cbDVT.Text == "" || txtTenDP.Text == "" || txtNhaSanXuat.Text == "" || txtGiaBan.Text == "" || txtGiaNhap.Text == "") { MessageBox.Show("Không được đê trống", "Lưu ý", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (btnThem_Sua.Text == "Thêm") { if (Quyen_ThemDP == "1") { try { if (BUS.BUS_GetTenDP(txtTenDP.Text).Read()) { MessageBox.Show("Tên dược phẩm này đã tồn tại!"); btnThem_Sua.Enabled = false; } else { DTO_DP DTO_Them_DP = new DTO_DP(txtTenDP.Text, txtNhaSanXuat.Text, cbDVT.Text, txtGiaNhap.Text, txtGiaBan.Text); if (BUS.BUS_ThemDP(DTO_Them_DP)) { DataTable dt = (DataTable)bs.DataSource; DataRow row = dt.NewRow(); row["TenDP"] = txtTenDP.Text; row["NhaSanXuat"] = txtNhaSanXuat.Text; row["DVT"] = cbDVT.Text; row["SoLuong"] = "0"; row["GiaNhap"] = txtGiaNhap.Text; row["GiaBan"] = txtGiaBan.Text; dt.Rows.Add(row); cbDVT.Text = ""; txtGiaBan.Text = ""; txtGiaNhap.Text = ""; txtNhaSanXuat.Text = ""; txtTenDP.Text = ""; MessageBox.Show("Đã cập nhật dữ liệu này thành công", "Thông báo"); } else { MessageBox.Show("Lỗi kết nối CSDL!"); kn.ShowDialog(); } } BUS.BUS_CloseConnect_DanhMuc(); } catch { MessageBox.Show("Lỗi kết nối CSDL!"); kn.ShowDialog(); } } else { MessageBox.Show("Bạn không có quyền truy cập vào chức năng này!\nLiên hệ với Admin để biết thêm chi tiết.", "Thông báo"); } } else { if (Quyen_SuaDP == "1") { try { int id = (int)dataGridView1.CurrentRow.Cells["MaDP"].Value; DTO_DP DTO_Sua_DP = new DTO_DP(txtTenDP.Text, txtNhaSanXuat.Text, cbDVT.Text, txtGiaNhap.Text, txtGiaBan.Text); if (BUS.BUS_SuaDP(DTO_Sua_DP, id)) { DataRowView row = (DataRowView)bs.Current; // Hàng chọn hiện thời row["TenDP"] = txtTenDP.Text; row["NhaSanXuat"] = txtNhaSanXuat.Text; row["DVT"] = cbDVT.Text; row["GiaNhap"] = txtGiaNhap.Text; row["GiaBan"] = txtGiaBan.Text; bs.ResetCurrentItem(); cbDVT.Text = ""; txtGiaBan.Text = ""; txtGiaNhap.Text = ""; txtNhaSanXuat.Text = ""; txtTenDP.Text = ""; MessageBox.Show("Sửa thành công!"); } else { MessageBox.Show("Lỗi kết nối CSDL!"); kn.ShowDialog(); } } catch { MessageBox.Show("Lỗi kết nối CSDL!"); kn.ShowDialog(); } } else { MessageBox.Show("Bạn không có quyền truy cập vào chức năng này!\nLiên hệ với Admin để biết thêm chi tiết.", "Thông báo"); } } } }
public bool BUS_SuaDP(DTO_DP DP, int id) { return(d.DAL_SuaDP(DP, id)); }
public bool BUS_ThemDP(DTO_DP DP) { return(d.DAL_ThemDP(DP)); }