public bool Add(DTO_LoaiThuoc pLoaiThuoc) { try { SqlDataAdapter da = new SqlDataAdapter("select * from LOAITHUOC", _cn); DataRow r = dt.NewRow(); r["MaLoaiThuoc"] = pLoaiThuoc.MaLoaiThuoc; r["TenLoaiThuoc"] = pLoaiThuoc.TenLoaiThuoc; r["MaLoaiDonVi"] = pLoaiThuoc.MaLoaiDonVi; r["MaLoaiCachDung"] = pLoaiThuoc.MaLoaiCachDung; r["DonGia"] = pLoaiThuoc.DonGia; dt.Rows.Add(r); SqlCommandBuilder cm = new SqlCommandBuilder(da); da.Update(dt); return(true); } catch { return(false); } }
public bool Update(DTO_LoaiThuoc pLoaiThuoc) { return(dal_loaiThuoc.Update(pLoaiThuoc)); }
private void btnSua_Click(object sender, EventArgs e) { if (tbxMaThuoc.Text == "") { MessageBox.Show("Không tìm thấy mã loại thuốc!"); return; } if (isSua)// neu sua xong thi luu va disable { if (tbxMaThuoc.Text == "") { MessageBox.Show("Mã loại thuốc không hợp lệ!"); return; } else if (tbxTenThuoc.Text.Length < 2) { MessageBox.Show("Tên thuốc không hợp lệ!"); return; } else if (cbxDonVi.SelectedValue == null) { MessageBox.Show("Đơn vị không hợp lệ!"); return; } else if (cbxCachDung.SelectedValue == null) { MessageBox.Show("Cách dùng không hợp lệ!"); return; } if (tbxDonGia.Text == "") { tbxDonGia.Text = "0"; } if (!CheckThongTinThuocPhuHop()) { return; } DisableControl(); btnSua.Text = "Sửa"; btnThem.Enabled = true; btnXoa.Enabled = true; btnTimKiem.Enabled = true; DTO_LoaiThuoc loaiThuoc = new DTO_LoaiThuoc(tbxMaThuoc.Text, tbxTenThuoc.Text, cbxDonVi.SelectedValue.ToString(), cbxCachDung.SelectedValue.ToString(), Int32.Parse(tbxDonGia.Text)); if (bus_loaiThuoc.Update(loaiThuoc)) { ReloadGridViewLoaiThuoc(); MessageBox.Show("Sửa loại thuốc thành công!"); } else { MessageBox.Show("Sửa loại thuốc thất bại!"); } } else //Neu chua sua thi enable { EnableControl(); btnThem.Enabled = false; btnXoa.Enabled = false; btnTimKiem.Enabled = false; btnSua.Text = "Hoàn tất"; } isSua = !isSua; }
public bool Add(DTO_LoaiThuoc pLoaiThuoc) { return(dal_loaiThuoc.Add(pLoaiThuoc)); }
private void btnThem_Click(object sender, EventArgs e) { if (!isThem)//neu chua them thi gio them { EnableControl(); tbxDonGia.Text = ""; tbxTenThuoc.Text = ""; tbxMaThuoc.Text = bus_loaiThuoc.GetMaLoaiThuocNext(); if (tbxMaThuoc.Text == "") { MessageBox.Show("Không lấy được mã loại thuốc!"); return; } btnThem.Text = " Hoàn tất"; btnSua.Enabled = false; btnXoa.Enabled = false; btnTimKiem.Enabled = false; } else //Neu nhap xong thi them vo { if (tbxMaThuoc.Text == "") { MessageBox.Show("Mã loại thuốc không hợp lệ!"); return; } else if (tbxTenThuoc.Text.Length < 2) { MessageBox.Show("Tên thuốc không hợp lệ!"); return; } else if (cbxDonVi.SelectedValue == null) { MessageBox.Show("Đơn vị không hợp lệ!"); return; } else if (cbxCachDung.SelectedValue == null) { MessageBox.Show("Cách dùng không hợp lệ!"); return; } if (tbxDonGia.Text == "") { tbxDonGia.Text = "0"; MessageBox.Show("Đơn giá không được để trống!"); return; } if (!CheckThongTinThuocPhuHop()) { return; } DTO_LoaiThuoc loaiThuoc = new DTO_LoaiThuoc(tbxMaThuoc.Text, tbxTenThuoc.Text, cbxDonVi.SelectedValue.ToString(), cbxCachDung.SelectedValue.ToString(), Int32.Parse(tbxDonGia.Text)); if (bus_loaiThuoc.Add(loaiThuoc)) { ReloadGridViewLoaiThuoc(); MessageBox.Show("Thêm loại thuốc thành công!"); } else { MessageBox.Show("Thêm loại thuốc thất bại!"); } //Done DisableControl(); btnThem.Text = "Thêm"; btnSua.Enabled = true; btnXoa.Enabled = true; btnTimKiem.Enabled = true; } isThem = !isThem; }