private void themPhuKien() { string tenphukien = cbTen.Text; using (quanlithucungEntities1 quanli = new quanlithucungEntities1()) { PHUKIEN pk = quanli.PHUKIENs.FirstOrDefault(p => p.Tenphukien.ToLower() == tenphukien.ToLower()); if (pk == null) { Console.WriteLine("aa"); quanli.insertCTPK(mapn, int.Parse(txtSoLuong.Text), double.Parse(txtGia.Text), tenphukien, cbLoai.SelectedValue.ToString(), null, txtdonvi.Text); quanli.SaveChanges(); MessageBox.Show("Thêm thành công"); } else { pk.Soluong += int.Parse(txtSoLuong.Text); CTNhapPhuKien pkm = new CTNhapPhuKien(); pkm.MaPN = mapn; pkm.MaPhuKien = pk.Maphukien; pkm.TenPhuKien = pk.Tenphukien; pkm.MaLoai = cbLoai.SelectedValue.ToString(); pkm.GiaNhap = double.Parse(txtGia.Text); pkm.Soluong = int.Parse(txtSoLuong.Text); pkm.Donvi = txtdonvi.Text; pkm.Anh = pk.HinhAnh; quanli.CTNhapPhuKiens.Add(pkm); quanli.SaveChanges(); MessageBox.Show("Thêm thành công"); } } }
private void chonhinhanh(object sender, EventArgs e) { BunifuImageButton img = sender as BunifuImageButton; mapk = img.Name.ToString(); using (quanlithucungEntities1 quanli = new quanlithucungEntities1()) { PHUKIEN phukien = quanli.PHUKIENs.FirstOrDefault(p => p.Maphukien == mapk); cbLoaiPhuKien.SelectedValue = phukien.MaLoai; txttenphukien.Text = phukien.Tenphukien; txtdongia.Text = phukien.dongia.ToString(); } }
private void updatePhuKien(string maphukien) { using (quanlithucungEntities1 quanli = new quanlithucungEntities1()) { PHUKIEN tc = quanli.PHUKIENs.FirstOrDefault(p => p.Maphukien == maphukien); 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.HinhAnh = images; quanli.SaveChanges(); MessageBox.Show("Update thanh cong"); } }
private void loadThongTinPK(string maphukien) { using (quanlithucungEntities1 quanli = new quanlithucungEntities1()) { PHUKIEN phukien = quanli.PHUKIENs.FirstOrDefault(p => p.Maphukien == maphukien); cbDanhMuc.SelectedIndex = 1; cbLoai.SelectedValue = phukien.MaLoai; cbTen.SelectedValue = phukien.Maphukien; Byte[] img = phukien.HinhAnh; if (img != null) { using (MemoryStream stream = new MemoryStream(img)) { Image returnImage = Image.FromStream(stream); hinhanh.Image = returnImage; } } } }