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()); } } }
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); } }