예제 #1
0
        public void Insert(int sophieu, int masp,
                           int sl, decimal dongia, decimal thanhtien)
        {
            var r = datacontext.CTPHIEUBANs.Where(p => p.MaSP == masp && p.SoPhieuBan == sophieu).FirstOrDefault();

            if (r != null) // da ton tai thi cap nhat so luong // update
            {
                r.SoLuong   += sl;
                r.ThanhTien += thanhtien;

                SanPham.Update(masp, sl);                         // cap nhat so luongton
                PhieuBan.UpdateTongTien(r.SoPhieuBan, thanhtien); // cap nhat tongtien

                datacontext.SubmitChanges();
            }
            else // them moi
            {
                CTPHIEUBAN ct = new CTPHIEUBAN();
                ct.SoPhieuBan = sophieu;
                ct.MaSP       = masp;
                ct.SoLuong    = sl;
                ct.DonGia     = dongia;
                ct.ThanhTien  = thanhtien;
                datacontext.CTPHIEUBANs.InsertOnSubmit(ct);

                datacontext.SubmitChanges();

                PhieuBan.UpdateTongTien(ct.SoPhieuBan, ct.ThanhTien.Value); //cap nhat tong tien
                SanPham.Update(ct.MaSP, sl);                                // cap nhat so luong ton
            }
        }
예제 #2
0
        public void Delete(int sophieu, int masp)
        {
            CTPHIEUBAN ct = datacontext.CTPHIEUBANs.Where(p => (p.SoPhieuBan == sophieu && p.MaSP == masp)).FirstOrDefault();

            if (ct != null)
            {
                PhieuBan.UpdateTongTien(ct.SoPhieuBan, -ct.ThanhTien.Value); //cap nhat tong tien
                SanPham.Update(ct.MaSP, -ct.SoLuong.Value);                  // cap nhat so luong ton

                datacontext.CTPHIEUBANs.DeleteOnSubmit(ct);
                datacontext.SubmitChanges();
            }
        }
예제 #3
0
        public void Update(int sophieu, int masp,
                           int sl, decimal dongia, decimal thanhtien)
        {
            CTPHIEUBAN ct = datacontext.CTPHIEUBANs.Where(p => (p.SoPhieuBan == sophieu && p.MaSP == masp)).FirstOrDefault();

            if (ct != null)
            {
                PhieuBan.UpdateTongTien(ct.SoPhieuBan, -ct.ThanhTien.Value); //cap nhat tong tien
                SanPham.Update(ct.MaSP, -ct.SoLuong.Value);                  // cap nhat so luong ton

                ct.SoLuong   = sl;
                ct.DonGia    = dongia;
                ct.ThanhTien = thanhtien;

                PhieuBan.UpdateTongTien(ct.SoPhieuBan, thanhtien); //cap nhat tong tien
                SanPham.Update(ct.MaSP, sl);                       // cap nhat so luong ton

                datacontext.SubmitChanges();
            }
        }