public int themctpDNXK(eCTPhieuDNXK ctpDNXK)
        {
            if (kiemtractpDNXK(ctpDNXK.soPDNXK, ctpDNXK.maSP))
            {
                var r = from c in db.Tbl_CTPhieuDNXKs
                        where c.maSP == ctpDNXK.maSP
                        select new { c.soluong };
                int kq = Convert.ToInt32(ctpDNXK.soluong);
                foreach (var k in r)
                {
                    kq += Convert.ToInt32(k.soluong);
                }
                IQueryable <Tbl_CTPhieuDNXK> DNXK1 = db.Tbl_CTPhieuDNXKs.Where(x => x.soPDNXK.Equals(ctpDNXK.soPDNXK) && x.maSP.Equals(ctpDNXK.maSP));
                DNXK1.First().soluong = kq;
                db.SubmitChanges();
                return(0);
            }
            Tbl_CTPhieuDNXK nhap = new Tbl_CTPhieuDNXK();

            nhap.soPDNXK = ctpDNXK.soPDNXK;
            nhap.maSP    = ctpDNXK.maSP;
            nhap.soluong = Convert.ToInt32(ctpDNXK.soluong);
            nhap.Ghichu  = ctpDNXK.Ghichu;
            db.Tbl_CTPhieuDNXKs.InsertOnSubmit(nhap);
            db.SubmitChanges();

            return(1);
        }
        public List <eCTPhieuDNXK> laydanhsachCTPhieuDNXKtheoMaphieu(string map)
        {
            var listCTphieuDNXK    = db.Tbl_CTPhieuDNXKs.Where(x => x.soPDNXK == map).ToList();
            List <eCTPhieuDNXK> ls = new List <eCTPhieuDNXK>();

            foreach (Tbl_CTPhieuDNXK xk in listCTphieuDNXK)
            {
                eCTPhieuDNXK ednxk = new eCTPhieuDNXK();
                ednxk.maSP    = xk.maSP;
                ednxk.soPDNXK = xk.soPDNXK;
                ednxk.soluong = Convert.ToInt32(xk.soluong);
                ednxk.Ghichu  = xk.Ghichu;
                ls.Add(ednxk);
            }
            return(ls);
        }
        private void btnThemChitietXK_Click(object sender, EventArgs e)
        {
            eCTPhieuDNXK n = new eCTPhieuDNXK()
            {
                soPDNXK = txtsophieu.Text,
                maSP    = txtMSP.Text,
                soluong = Convert.ToInt32(txtsoluong.Text),
                Ghichu  = txtghichudnxk.Text
            };
            int kq1 = pdnxkbll.themctpdnxk(n);

            if (kq1 == 1 || kq1 != 1)
            {
                MessageBox.Show("Thêm thành công");
            }
            dgvCTPDNXK.DataSource = pdnxkbll.getallctpdnxk();
        }
 public int themctpdnxk(eCTPhieuDNXK n)
 {
     throw new NotImplementedException();
 }