private void themSanPham() { if (cbDanhMuc.Text == "Thú Cưng") { string tenthucung = cbTen.Text; using (quanlithucungEntities1 quanli = new quanlithucungEntities1()) { ThuCung tc = quanli.ThuCungs.FirstOrDefault(p => p.TenThuCung.ToLower() == tenthucung.ToLower()); if (tc == null) { //Console.WriteLine("aaa"); quanli.insertCTPN(mapn, int.Parse(txtSoLuong.Text), double.Parse(txtGia.Text), tenthucung, cbLoai.SelectedValue.ToString(), null, txtdonvi.Text); quanli.SaveChanges(); MessageBox.Show("Thêm thành công!"); } else { tc.soluong += int.Parse(txtSoLuong.Text); CTNhapThuCung tcm = new CTNhapThuCung(); tcm.MaPN = mapn; tcm.MaThuCung = tc.MaThuCung; tcm.TenThuCung = tc.TenThuCung; tcm.MaLoai = cbLoai.SelectedValue.ToString(); tcm.SoLuong = int.Parse(txtSoLuong.Text); tcm.GiaNhap = double.Parse(txtGia.Text); tcm.Donvi = txtdonvi.Text; quanli.CTNhapThuCungs.Add(tcm); quanli.SaveChanges(); MessageBox.Show("Thêm thành công!"); } } } if (cbDanhMuc.Text == "Phụ Kiện") { themPhuKien(); } if (cbDanhMuc.Text == "Thực Phẩm") { themThucPham(); } }
private void suaSanPham() { //string matc = cbTen.SelectedValue.ToString(); using (quanlithucungEntities1 quanli = new quanlithucungEntities1()) { CTNhapThuCung nhap = quanli.CTNhapThuCungs.FirstOrDefault(p => p.MaThuCung == matc && p.MaPN == mapn); //nhap.MaPN = "PN01"; Console.WriteLine(nhap.MaThuCung); nhap.MaLoai = cbLoai.SelectedValue.ToString(); nhap.TenThuCung = cbTen.Text; nhap.SoLuong = int.Parse(txtSoLuong.Text); nhap.GiaNhap = double.Parse(txtGia.Text); nhap.Donvi = txtdonvi.Text; quanli.SaveChanges(); ThuCung tc = quanli.ThuCungs.FirstOrDefault(p => p.MaThuCung == matc); tc.TenThuCung = cbTen.Text; tc.MaLoai = cbLoai.SelectedValue.ToString(); tc.soluong += int.Parse(txtSoLuong.Text); tc.DonGia = double.Parse(txtGia.Text) + 0.1 * double.Parse(txtGia.Text); tc.Donvi = txtdonvi.Text; if (dem == 1) { MemoryStream me = new MemoryStream(); byte[] images = null; FileStream stream = new FileStream(img, FileMode.Open, FileAccess.Read); BinaryReader brs = new BinaryReader(stream); images = brs.ReadBytes((int)stream.Length); tc.Anh = images; } quanli.SaveChanges(); } }