Пример #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!");
                }
            }
        }