private void btnThem_Click(object sender, EventArgs e) { if (Kiemtra() == false) { MessageBox.Show("Chưa nhập đủ thông tin"); return; } using (CUAHANGTIENLOI db = new CUAHANGTIENLOI()) { byte[] img = null; FileStream fs = new FileStream(imgSP, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); img = br.ReadBytes((int)fs.Length); HANGHOA hh = new HANGHOA(); PHIEUNHAP pn = new PHIEUNHAP(); CTPHIEUNHAP ctpn = new CTPHIEUNHAP(); hh.TENHANG = txtTenhang.Text; hh.HSD = DateTime.Parse(txtHSD.Text); hh.Hinh = img; hh.MALOAI = int.Parse(cbLoaiSP.SelectedValue.ToString()); hh.DONVITINH = txtDVT.Text; hh.SOLUONG = 0; hh.GIABAN = 0; db.HANGHOAs.Add(hh); pn.MANCC = int.Parse(cbNCC.SelectedValue.ToString()); pn.MANV = int.Parse(cbNV.SelectedValue.ToString()); DateTime ngaynhap = DateTime.Now; pn.NGAYNHAP = DateTime.Parse(ngaynhap.ToString("yyyy-MM-dd")); db.PHIEUNHAPs.Add(pn); db.SaveChanges(); string mapn = db.LAYMAPN().FirstOrDefault().ToString(); string mahang = db.LAYMAHANG().FirstOrDefault().ToString(); ctpn.MAHANG = int.Parse(mahang); ctpn.MAPN = int.Parse(mapn); ctpn.GIANHAP = decimal.Parse(txtGiaNhap.Text); ctpn.SLNHAP = int.Parse(txtSL.Text); db.CTPHIEUNHAPs.Add(ctpn); db.SaveChanges(); } MessageBox.Show("Thêm thành công"); this.Hide(); }
private void btnSua_Click(object sender, EventArgs e) { using (CUAHANGTIENLOI db = new CUAHANGTIENLOI()) { byte[] img = null; FileStream fs = new FileStream(imgSP, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); img = br.ReadBytes((int)fs.Length); HANGHOA hh = db.HANGHOAs.FirstOrDefault(p => p.MAHANG.ToString() == txtMaHang.Text); CTPHIEUNHAP ctpn = db.CTPHIEUNHAPs.FirstOrDefault(p => p.MAHANG.ToString() == txtMaHang.Text); hh.TENHANG = txtTenhang.Text; ctpn.SLNHAP = int.Parse(txtSL.Text); hh.HSD = DateTime.Parse(txtHSD.Text); hh.Hinh = img; hh.MALOAI = int.Parse(cbLoaiSP.SelectedValue.ToString()); hh.DONVITINH = txtDVT.Text; hh.GIABAN = decimal.Parse(txtGiaBan.Text); db.SaveChanges(); } MessageBox.Show("Sửa thành công", "Thông báo"); loadDL(); }