コード例 #1
0
        private void themThucPham()
        {
            string tenthucpham = cbTen.Text;

            using (quanlithucungEntities1 qlthucpham = new quanlithucungEntities1())
            {
                THUCPHAM tp = qlthucpham.THUCPHAMs.FirstOrDefault(p => p.Tenthucpham.ToLower() == tenthucpham.ToLower());
                if (tp == null)
                {
                    qlthucpham.insertCTTP(mapn, int.Parse(txtSoLuong.Text), double.Parse(txtGia.Text), tenthucpham, cbLoai.SelectedValue.ToString(), null, txtdonvi.Text);
                    qlthucpham.SaveChanges();
                    MessageBox.Show("Thêm thành công!");
                }
                else
                {
                    tp.SOLUONG += int.Parse(txtSoLuong.Text);
                    CTNhapThucPham tpm = new CTNhapThucPham();
                    tpm.MaPN        = mapn;
                    tpm.MaThucPham  = tp.Mathucpham;
                    tpm.TenThucPham = tp.Tenthucpham;
                    tpm.MaLoai      = cbLoai.SelectedValue.ToString();
                    tpm.Soluong     = int.Parse(txtSoLuong.Text);
                    tpm.GiaNhap     = double.Parse(txtGia.Text);
                    tpm.DonVi       = txtdonvi.Text;
                    qlthucpham.CTNhapThucPhams.Add(tpm);
                    qlthucpham.SaveChanges();
                    MessageBox.Show("Thêm thành công!");
                }
            }
        }
コード例 #2
0
ファイル: Frmthucpham.cs プロジェクト: babychoi1999/ThucTapCM
        private void chonhinhanh(object sender, EventArgs e)
        {
            BunifuImageButton img = sender as BunifuImageButton;

            matp = img.Name.ToString();
            using (quanlithucungEntities1 quanli = new quanlithucungEntities1())
            {
                THUCPHAM thucpham = quanli.THUCPHAMs.FirstOrDefault(p => p.Mathucpham == matp);
                cbLoaiThucPham.SelectedValue = thucpham.MaLoai;
                txttenthucpham.Text          = thucpham.Tenthucpham;
                txtdongia.Text = thucpham.dongia.ToString();
            }
        }
コード例 #3
0
 private void updateThucPham(string mathucpham)
 {
     using (quanlithucungEntities1 quanli = new quanlithucungEntities1())
     {
         THUCPHAM     tc     = quanli.THUCPHAMs.FirstOrDefault(p => p.Mathucpham == mathucpham);
         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");
     }
 }
コード例 #4
0
 private void loadThongTinTP(string mathucpham)
 {
     using (quanlithucungEntities1 quanli = new quanlithucungEntities1())
     {
         THUCPHAM thucpham = quanli.THUCPHAMs.FirstOrDefault(p => p.Mathucpham == mathucpham);
         cbDanhMuc.SelectedIndex = 2;
         cbLoai.SelectedValue    = thucpham.MaLoai;
         cbTen.SelectedValue     = thucpham.Mathucpham;
         Byte[] img = thucpham.hinhanh;
         if (img != null)
         {
             using (MemoryStream stream = new MemoryStream(img))
             {
                 Image returnImage = Image.FromStream(stream);
                 hinhanh.Image = returnImage;
             }
         }
     }
 }