public void btnDeleteProductStore_Click(object sender, EventArgs e) { if (txtIDProductCH.Text == "" || txtNameProductCH.Text == "" || txtUnitCH.Text == "" || txtPriceCH.Text == "" || txtAmountOfProductCH.Text == "") { XtraMessageBox.Show("Bạn phải chọn Sản phẩm để xóa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); ClearDisplay(); return; } try { SanPhamCH_DTO sanpham = new SanPhamCH_DTO(); sanpham.MaSPCH = txtIDProductCH.Text; if (SanPhamCH_BUS.XoaSPCH(sanpham)) { LoadSanPhamCH1(); XtraMessageBox.Show("Xóa Sản phẩm trong Cửa hàng thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); lvListImageProduct.Items.Clear(); imageList.Images.Clear(); Display(); ClearDisplay(); return; } } catch (Exception ex) { XtraMessageBox.Show(ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
public void btnDeleteProductStore_Click(object sender, EventArgs e) { if (txtIDProductCH.Text == "") { MessageBox.Show("Bạn phải chọn Sản phẩm để xóa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearDisplay(); return; } try { SanPhamCH_DTO sanpham = new SanPhamCH_DTO(); sanpham.MaSPCH = (string)dtgvProductListOfStore.CurrentRow.Cells["MaSPCH"].Value; if (SanPhamCH_BUS.XoaSPCH(sanpham)) { LoadSanPhamCH(); MessageBox.Show("Xóa Sản phẩm trong Cửa hàng thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearDisplay(); return; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnUpdateProductStore_Click(object sender, EventArgs e) { if (txtIDProductCH.Text == "" || txtNameProductCH.Text == "" || txtUnitCH.Text == "" || txtPriceCH.Text == "" || txtAmountOfProductCH.Text == "") { MessageBox.Show("Bạn phải điền đầy đủ thông tin !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearDisplay(); return; } SanPhamCH_DTO sanpham = new SanPhamCH_DTO(); sanpham.MaSPCH = txtIDProductCH.Text; sanpham.TenSP = txtNameProductCH.Text; sanpham.DonVi = txtUnitCH.Text; sanpham.Gia = Double.Parse(txtPriceCH.Text.ToString()); sanpham.SoLuong = Int32.Parse(txtAmountOfProductCH.Text.ToString()); sanpham.HinhAnh = convertImageToBytes(); if (SanPhamCH_BUS.SuaSPCH(sanpham)) { MessageBox.Show("Sửa thông tin Sản phẩm trong Cửa hàng thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadSanPhamCH(); ClearDisplay(); return; } MessageBox.Show("Sửa thông tin Sản Phẩm trong Cửa hàng thất bại !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); }
public static SanPhamCH_DTO TimKiemTenSP(string t) { SqlConnection con = DataProvider.KetNoi(); string query = string.Format("EXEC dbo.TimKiemTHSP @TenSP = N'" + t + "'"); DataTable dt = DataProvider.LayDataTable(query, con); if (dt.Rows.Count == 0) { return(null); } if (dt.Rows.Count == 0) { return(null); } // 4. Đỏ dữ liệu lên List SanPhamCH_DTO sanpham = new SanPhamCH_DTO(); sanpham.MaSPCH = dt.Rows[0]["MaSPCH"].ToString(); sanpham.TenSP = dt.Rows[0]["TenSP"].ToString(); sanpham.Gia = Double.Parse(dt.Rows[0]["Gia"].ToString()); sanpham.DonVi = dt.Rows[0]["DonVi"].ToString(); sanpham.SoLuong = Int32.Parse(dt.Rows[0]["SoLuong"].ToString()); sanpham.HinhAnh = dt.Rows[0]["HinhAnh"].ToString(); sanpham.ThongSo = dt.Rows[0]["ThongSo"].ToString(); sanpham.BanLe = Convert.ToInt32(dt.Rows[0]["BanLe"].ToString()); sanpham.SoLuongLe = Convert.ToInt32(dt.Rows[0]["SoLuongLe"].ToString()); DataProvider.DongKetNoi(con); return(sanpham); }
//public static List<SanPhamCH_DTO> LoadSanPhamCH() //{ // // 1. Tạo chuối kết nối // SqlConnection con = DataProvider.KetNoi(); // // 2. Tạo chuối truy vấn và thực thi truy vấn // SqlCommand cmd = new SqlCommand("DSSanPhamCH", con); // cmd.CommandType = CommandType.StoredProcedure; // cmd.ExecuteNonQuery(); // SqlDataAdapter da = new SqlDataAdapter(); // da.SelectCommand = cmd; // // 3. Đổ dữ liệu lên DataTable // DataTable dt = new DataTable(); // da.Fill(dt); // if (dt.Rows.Count == 0) // return null; // // 4. Đỏ dữ liệu lên List // List<SanPhamCH_DTO> listSP = new List<SanPhamCH_DTO>(); // for (int i = 0; i < dt.Rows.Count; i++) // { // SanPhamCH_DTO sanpham = new SanPhamCH_DTO(); // sanpham.MaSPCH = dt.Rows[i]["MaSPCH"].ToString(); // sanpham.TenSP = dt.Rows[i]["TenSP"].ToString(); // sanpham.Gia = Double.Parse(dt.Rows[i]["Gia"].ToString()); // sanpham.DonVi = dt.Rows[i]["DonVi"].ToString(); // sanpham.SoLuong = Int32.Parse(dt.Rows[i]["SoLuong"].ToString()); // sanpham.HinhAnh = Encoding.ASCII.GetBytes(dt.Rows[i]["HinhAnh"].ToString()); // listSP.Add(sanpham); // } // DataProvider.DongKetNoi(con); // return listSP; //} public static bool SuaSanPhamCH(SanPhamCH_DTO sanpham) { SqlConnection con = DataProvider.KetNoi(); SqlCommand cmd = new SqlCommand("SuaSPCH", con); try { cmd.CommandType = CommandType.StoredProcedure; SqlParameter p = new SqlParameter("@MaSPCH", sanpham.MaSPCH); cmd.Parameters.Add(p); p = new SqlParameter("@TenSP", sanpham.TenSP); cmd.Parameters.Add(p); p = new SqlParameter("@DonVi", sanpham.DonVi); cmd.Parameters.Add(p); p = new SqlParameter("@Gia", sanpham.Gia); cmd.Parameters.Add(p); p = new SqlParameter("@SoLuong", sanpham.SoLuong); cmd.Parameters.Add(p); p = new SqlParameter("@HinhAnh", sanpham.HinhAnh); cmd.Parameters.Add(p); cmd.ExecuteNonQuery(); DataProvider.DongKetNoi(con); return(true); } catch { DataProvider.DongKetNoi(con); return(false); } }
private void btnUpdateProductStore_Click(object sender, EventArgs e) { if (txtIDProductCH.Text == "" || txtNameProductCH.Text == "" || txtUnitCH.Text == "" || txtPriceCH.Text == "" || txtAmountOfProductCH.Text == "") { XtraMessageBox.Show("Bạn phải điền đầy đủ thông tin !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); ClearDisplay(); return; } try { SanPhamCH_DTO sanpham = new SanPhamCH_DTO(); sanpham.MaSPCH = txtIDProductCH.Text; sanpham.TenSP = txtNameProductCH.Text; sanpham.DonVi = txtUnitCH.Text; sanpham.Gia = Double.Parse(txtPriceCH.Text.ToString()); sanpham.SoLuong = Int32.Parse(txtAmountOfProductCH.Text.ToString()); sanpham.HinhAnh = imageLocation; sanpham.ThongSo = txtParameter.Text; if (cbRetail.Checked == true) { sanpham.BanLe = 1; sanpham.SoLuongLe = Convert.ToInt32(txtAmonutRetail.Text); } else { sanpham.BanLe = 0; sanpham.SoLuongLe = 0; } if (SanPhamCH_BUS.SuaSPCH(sanpham)) { XtraMessageBox.Show("Sửa thông tin Sản phẩm trong Cửa hàng thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadSanPhamCH1(); lvListImageProduct.Items.Clear(); imageList.Images.Clear(); Display(); ClearDisplay(); return; } }catch (Exception ex) { XtraMessageBox.Show(ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
public static List <SanPhamCH_DTO> LoadSanPhamCH() { // 1. Tạo chuối kết nối SqlConnection con = DataProvider.KetNoi(); // 2. Tạo chuối truy vấn và thực thi truy vấn SqlCommand cmd = new SqlCommand("DSSanPhamCH", con); cmd.CommandType = CommandType.StoredProcedure; cmd.ExecuteNonQuery(); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; // 3. Đổ dữ liệu lên DataTable DataTable dt = new DataTable(); da.Fill(dt); if (dt.Rows.Count == 0) { return(null); } // 4. Đỏ dữ liệu lên List List <SanPhamCH_DTO> listSP = new List <SanPhamCH_DTO>(); for (int i = 0; i < dt.Rows.Count; i++) { SanPhamCH_DTO sanpham = new SanPhamCH_DTO(); sanpham.MaSPCH = dt.Rows[i]["MaSPCH"].ToString(); sanpham.TenSP = dt.Rows[i]["TenSP"].ToString(); sanpham.Gia = Double.Parse(dt.Rows[i]["Gia"].ToString()); sanpham.DonVi = dt.Rows[i]["DonVi"].ToString(); sanpham.SoLuong = Int32.Parse(dt.Rows[i]["SoLuong"].ToString()); sanpham.HinhAnh = dt.Rows[i]["HinhAnh"].ToString(); sanpham.ThongSo = dt.Rows[i]["ThongSo"].ToString(); sanpham.BanLe = Convert.ToInt32(dt.Rows[i]["BanLe"].ToString()); sanpham.SoLuongLe = Convert.ToInt32(dt.Rows[i]["SoLuongLe"].ToString()); listSP.Add(sanpham); } DataProvider.DongKetNoi(con); return(listSP); }
private void lvListImageProduct_Click(object sender, EventArgs e) { var firstSelectedItem = lvListImageProduct.SelectedItems[0]; string s = firstSelectedItem.SubItems[0].Text; DataGridView d = new DataGridView(); SanPhamCH_DTO sanpham = SanPhamCH_BUS.TimKiemTenSP(s); try { txtIDProductCH.Text = sanpham.MaSPCH; txtNameProductCH.Text = sanpham.TenSP; txtPriceCH.Text = sanpham.Gia.ToString(); txtUnitCH.Text = sanpham.DonVi; txtAmountOfProductCH.Text = sanpham.SoLuong.ToString(); txtParameter.Text = sanpham.ThongSo.ToString(); if (sanpham.BanLe == 1) { txtAmonutRetail.Text = sanpham.SoLuongLe.ToString(); cbRetail.Checked = true; } else { cbRetail.Checked = false; txtAmonutRetail.Enabled = false; txtAmonutRetail.Text = ""; } string str = sanpham.HinhAnh.ToString(); imageLocation = str; if (str == "" || str == null) { pictureBox.Image = Resources.noimage; } else { pictureBox.Image = Image.FromFile(str); } } catch { return; } }
public static bool XoaSPCH(SanPhamCH_DTO sanpham) { SqlConnection con = DataProvider.KetNoi(); SqlCommand cmd = new SqlCommand("XoaSPCH", con); try { cmd.CommandType = CommandType.StoredProcedure; SqlParameter p = new SqlParameter("@MaSPCH", sanpham.MaSPCH); cmd.Parameters.Add(p); cmd.ExecuteNonQuery(); DataProvider.DongKetNoi(con); return(true); } catch { DataProvider.DongKetNoi(con); return(false); } }
public static bool XoaSPCH(SanPhamCH_DTO sanpham) { return(SanPhamCH_DAL.XoaSPCH(sanpham)); }