private void btnModeThem_Click(object sender, EventArgs e) { if (this.txtMaSp.Text == string.Empty || this.txtTenSP.Text == string.Empty || this.txtGiaBanSp.Text == string.Empty || this.txtSLTonSp.Text == string.Empty || this.txtDVT.Text == string.Empty || this.txtLoaiSanPham.Text == string.Empty || this.txtNhaPhanPhoi.Text == string.Empty || this.imgSanPham.Image == null) { MessageBox.Show("Bạn chưa điền đủ thông tin !!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } SANPHAM sanpham = new SANPHAM(); sanpham.MASP = this.txtMaSp.Text; sanpham.TENSP = this.txtTenSP.Text; sanpham.GIABAN = Convert.ToInt32(this.txtGiaBanSp.Text); sanpham.SL_TON = Convert.ToInt32(this.txtSLTonSp.Text); sanpham.DVT = this.txtDVT.Text; sanpham.MALOAI = this.txtLoaiSanPham.Text; sanpham.MANPP = this.txtNhaPhanPhoi.Text; sanpham.TRANGTHAI = true; string maAnh = this.txtMaSp.Text + "_" + DateTime.Now.ToString("dd-MM-yy-h-m-s"); string[] chuoiXuLiTenAnh = this.tenAnhMinhHoa.Split('.'); this.tenAnhMinhHoa = this.txtMaSp.Text + "_" + DateTime.Now.ToString("dd-MM-yy-h-m-s") + "." + chuoiXuLiTenAnh[1]; ANHMINHHOASP anhMH = new ANHMINHHOASP { MAANH = maAnh, TENANHMINHHOA = this.tenAnhMinhHoa, MASP = sanpham.MASP, TRANGTHAI = true }; if (!SanPhamBUS.KiemTraMaSPTonTai(sanpham.MASP)) { try { SanPhamBUS.ThemSanPham(sanpham); AnhMinhHoaSPBUS.ThemAnhMinhHoa(anhMH); this.imgSanPham.Image.Save(patch + anhMH.TENANHMINHHOA); MessageBox.Show("Thêm sản phẩm thành công !!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); Reset(); LoadDataTabQLSP(); LoadDataTabDSSP(); string lsth = "[" + DateTime.Now.ToString("dd/MM/yyyy-h:m:s") + "] " + this.manv + " đã thêm một sản phẩm (" + sanpham.MASP + ")"; LichSuHeThongBUS.ThemLSHT(new LICHSUHETHONG { NGAYTAO = DateTime.Now.Date, NV_THAOTAC = this.manv, VITRI_THAOTAC = this.vitrithaotac, GHICHU = lsth }); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
public static bool ThemAnhMinhHoaSanPham(ANHMINHHOASP anhMH) { try { db.ANHMINHHOASP.Add(anhMH); db.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
private void dgvQLSanPham_CellClick(object sender, DataGridViewCellEventArgs e) { this.btnSuaSP.Enabled = true; this.btnXoaSP.Enabled = true; this.btnThemSP.Enabled = false; this.txtMaSp.Enabled = false; this.dangThayDoiDL = true; this.txtMaSp.Text = this.dgvQLSanPham.CurrentRow.Cells["MASPQL"].Value.ToString(); this.txtTenSP.Text = this.dgvQLSanPham.CurrentRow.Cells["TENSPQL"].Value.ToString(); this.txtGiaBanSp.Text = Convert.ToDecimal(this.dgvQLSanPham.CurrentRow.Cells["GIABANQL"].Value).ToString("#,##"); this.txtSLTonSp.Text = this.dgvQLSanPham.CurrentRow.Cells["SLTONQL"].Value.ToString(); this.txtDVT.Text = this.dgvQLSanPham.CurrentRow.Cells["DVTQL"].Value.ToString(); string tenLoai = this.dgvQLSanPham.CurrentRow.Cells["TENLOAIQL"].Value.ToString(); string tenNPP = this.dgvQLSanPham.CurrentRow.Cells["TENNPPQL"].Value.ToString(); this.txtLoaiSanPham.Text = lstLoaiSp.Where(p => p.TENLOAI == tenLoai).Select(p => p.MALOAI).FirstOrDefault(); this.txtNhaPhanPhoi.Text = lstNhaPP.Where(p => p.TENNPP == tenNPP).Select(p => p.MANPP).FirstOrDefault(); AMH = lstAnhMinhHoa.Where(p => p.MASP == this.txtMaSp.Text && p.TRANGTHAI == true).FirstOrDefault(); try { if (AMH != null) { this.imgSanPham.ImageLocation = patch + AMH.TENANHMINHHOA; } else { this.imgSanPham.ImageLocation = null; } } catch { this.imgSanPham.ImageLocation = null; } }
private void btnModeSua_Click(object sender, EventArgs e) { if (this.txtMaSp.Text == string.Empty || this.txtTenSP.Text == string.Empty || this.txtGiaBanSp.Text == string.Empty || this.txtSLTonSp.Text == string.Empty || this.txtDVT.Text == string.Empty || this.txtLoaiSanPham.Text == string.Empty || this.txtNhaPhanPhoi.Text == string.Empty || this.imgSanPham.Image == null) { MessageBox.Show("Bạn chưa điền đủ thông tin !!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (AMH != null) { if (this.tenAnhMinhHoa != AMH.TENANHMINHHOA && this.tenAnhMinhHoa != null) { string[] chuoiXuLiTenAnh = this.tenAnhMinhHoa.Split('.'); tenAnhMinhHoa = this.txtMaSp.Text + "_" + DateTime.Now.ToString("dd-MM-yy-h-m-s") + "." + chuoiXuLiTenAnh[1]; } } SANPHAM sanpham = new SANPHAM(); sanpham.MASP = this.txtMaSp.Text; sanpham.TENSP = this.txtTenSP.Text; sanpham.GIABAN = Convert.ToDecimal(this.txtGiaBanSp.Text); sanpham.SL_TON = Convert.ToInt32(this.txtSLTonSp.Text); sanpham.DVT = this.txtDVT.Text; sanpham.MALOAI = this.txtLoaiSanPham.Text; sanpham.MANPP = this.txtNhaPhanPhoi.Text; if (SanPhamBUS.SuaSanPham(sanpham)) { if (AMH != null) { if (this.imgSanPham.ImageLocation == System.IO.Path.Combine(patch, AMH.TENANHMINHHOA) && this.tenAnhMinhHoa != null) { ANHMINHHOASP anhMinhHoa = AnhMinhHoaSPBUS.LayDanhSachAnhMinhHoa().Where(p => p.TENANHMINHHOA == AMH.TENANHMINHHOA).FirstOrDefault(); this.imgSanPham.Image.Save(System.IO.Path.Combine(patch + this.tenAnhMinhHoa)); AnhMinhHoaSPBUS.XoaAnhMinhHoa(anhMinhHoa.MAANH); string maAnh = this.txtMaSp.Text + "_" + DateTime.Now.ToString("dd-MM-yy-h-m-s"); ANHMINHHOASP anhMH = new ANHMINHHOASP { MAANH = maAnh, TENANHMINHHOA = this.tenAnhMinhHoa, MASP = sanpham.MASP, TRANGTHAI = true }; AnhMinhHoaSPBUS.ThemAnhMinhHoa(anhMH); } } else { string maAnh = this.txtMaSp.Text + "_" + DateTime.Now.ToString("dd-MM-yy-h-m-s"); string[] chuoiXuLiTenAnh = this.tenAnhMinhHoa.Split('.'); this.tenAnhMinhHoa = this.txtMaSp.Text + "_" + DateTime.Now.ToString("dd-MM-yy-h-m-s") + "." + chuoiXuLiTenAnh[1]; ANHMINHHOASP anhMH = new ANHMINHHOASP { MAANH = maAnh, TENANHMINHHOA = this.tenAnhMinhHoa, MASP = sanpham.MASP, TRANGTHAI = true }; AnhMinhHoaSPBUS.ThemAnhMinhHoa(anhMH); this.imgSanPham.Image.Save(patch + anhMH.TENANHMINHHOA); } Reset(); LoadDataTabQLSP(); LoadDataTabDSSP(); MessageBox.Show("Cập nhật thông tin sản phẩm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); string lsth = "[" + DateTime.Now.ToString("dd/MM/yyyy-h:m:s") + "] " + this.manv + " đã cập nhật thông tin của sản phẩm " + sanpham.MASP; LichSuHeThongBUS.ThemLSHT(new LICHSUHETHONG { NGAYTAO = DateTime.Now.Date, NV_THAOTAC = this.manv, VITRI_THAOTAC = this.vitrithaotac, GHICHU = lsth }); } else { MessageBox.Show("Cập nhật thông tin sản phẩm thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static bool ThemAnhMinhHoa(ANHMINHHOASP anhMH) { return(AnhMinhHoaSPDAO.ThemAnhMinhHoaSanPham(anhMH)); }