private void btnLuu_Click(object sender, EventArgs e) { float gia = float.Parse(txtGia.Text); float SL = float.Parse(txtSoLuong.Text); if (Them) { try { BLSanPham blsp = new BLSanPham(); //blsp.ThemSanPham(this.txtMasp.Text, this.txtTen.Text, gia,SL, ref err); blsp.ThemSanPham(this.txtMasp.Text, this.txtTen.Text, SL, gia, this.txtLoaiSP.Text, ref err); LoadData(); MessageBox.Show("Đã thêm xong!"); } catch (SqlException) { MessageBox.Show("Không thêm được. Lỗi rồi!"); } } else { BLSanPham blsp = new BLSanPham(); blsp.CapNhatSanPham(this.txtMasp.Text, this.txtTen.Text, SL, gia, this.txtLoaiSP.Text, ref err); LoadData(); MessageBox.Show("Đã sửa xong!"); } }
private void LoadData() { blSP = new BLSanPham(); dsVSP = blSP.dsVSanPham(); dgvSanPham.Rows.Clear(); for (int i = 0; i < dsVSP.Count; i++) { dgvSanPham.Rows.Add(dsVSP[i].MaSP, dsVSP[i].TenSP, dsVSP[i].GiaGoc, dsVSP[i].GiaBan); } }
//load vào combobox sản phẩm void showCbbMaSp() { dtK = new DataTable(); dtK.Clear(); BLSanPham bl = new BLSanPham(); DataSet ds = bl.LaySanPham(); dtK = ds.Tables[0]; cbbMaSP.DataSource = dtK; cbbMaSP.DisplayMember = BLSanPham.masp; cbbMaSP.ValueMember = BLSanPham.masp; }
public DetailProduct(int Ma) { InitializeComponent(); blSP = new BLSanPham(); dsSP = blSP.dsSanPham(); for (int i = 0; i < dsSP.Count; i++) { if (dsSP[i].MaSP == Ma) { sp = dsSP[i]; } } }
private void cbbMaSP_SelectedIndexChanged(object sender, EventArgs e) { BLSanPham blsp = new BLSanPham(); dtK = new DataTable(); dtK.Clear(); DataSet ds = blsp.ktra(cbbMaLoai.Text);; dtK = ds.Tables[0]; foreach (DataRow a in dtK.Rows) { txtTenLoai.Text = a[BLSanPham.ten].ToString(); } }
//private void cbbMaDH_SelectedIndexChanged(object sender, EventArgs e) //{ // dtK = new DataTable(); // dtK.Clear(); // DataSet ds = blDH.ktra(cbbMaDH.Text); ; // dtK = ds.Tables[0]; // foreach (DataRow a in dtK.Rows) // { // txtMaKH.Text = a[BLKhachHang.makh].ToString(); // } //} private void cbbMaSP_SelectedIndexChanged(object sender, EventArgs e) { BLSanPham blsp = new BLSanPham(); dtK = new DataTable(); dtK.Clear(); DataSet ds = blsp.ktra(cbbMaSP.Text);; dtK = ds.Tables[0]; float g; foreach (DataRow a in dtK.Rows) { txtGia.Text = a[BLSanPham.gia].ToString(); g = float.Parse(txtGia.Text); } }
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { if (isThem == true) { try { if (FormMain.IsNumber(txtGiaBan.Text) == true) { BLSanPham blSP = new BLSanPham(); blSP.ThemSanPham(txtMaSP.Text, txtTenSP.Text, txtDonViTinh.Text, txtGiaBan.Text, pcbHinhAnh.Image, ref err); LoadData(); MessageBox.Show("Đã thêm xong!"); } else { MessageBox.Show("Giá bán phải là một số!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch { MessageBox.Show("Đã xảy ra lỗi! Không thêm được mẫu tin!"); } } else { try { BLSanPham blSP = new BLSanPham(); blSP.CapNhatSanPham(txtMaSP.Text, txtTenSP.Text, txtDonViTinh.Text, txtGiaBan.Text, pcbHinhAnh.Image, ref err); LoadData(); MessageBox.Show("Đã sửa xong!"); } catch { MessageBox.Show("Đã xảy ra lỗi! Không sửa được mẫu tin!"); } } }
private void LoadData() { string message; blSP = new BLSanPham(); dsSP = new List <SanPham>(); bool result = blSP.Reader(out message); if (result == false) { MessageBox.Show(message); } dsSP = blSP.dsSP; dgvSanPham.Rows.Clear(); for (int i = 0; i < dsSP.Count; i++) { if (dsSP[i].TT_Ban == true) { dgvSanPham.Rows.Add(dsSP[i].MaSP.ToString(), dsSP[i].TenSP, dsSP[i].GiaSP.ToString(), dsSP[i].GiaBan.ToString()); } } }
private void DetailProduct_Load(object sender, EventArgs e) { try { blSP = new BLSanPham(); blNL = new BLNguyenLieu(); dsNL = blNL.dsNguyenLieu(); dsSP = blSP.dsSanPham(); cbNguyenLieu.BeginUpdate(); dsNL.ForEach(x => cbNguyenLieu.Items.Add(x.TenNL)); cbNguyenLieu.EndUpdate(); if (Them == true) { lblName.Text = "ADD"; } else { v_SanPham vsp = blSP.dsVSanPham().Find(x => x.MaSP == sp.MaSP); lblName.Text = "EDIT"; txtTenSP.Text = sp.TenSP; txtGiaBan.Text = vsp.GiaBan.ToString(); txtGiaGoc.Text = vsp.GiaGoc.ToString(); txtLoiNhuan.Text = sp.LoiNhuan.ToString(); txtGiamGia.Text = sp.GiamGia.ToString(); picSP.BackgroundImage = ConvertImage((byte[])sp.HinhSP.ToArray()); pnKind.Visible = false; pnPhanTram.Location = new Point(pnKind.Location.X, pnKind.Location.Y + 10); dsDGV = blNL.dsNguyenLieuDGV(sp); LoadData(); } } catch { MessageBox.Show("Bạn không có quyền truy cập"); } }