Example #1
0
        public void NhaphangList(PhieuNhap kh, int thanhtien, List <ChiTietPN> ds)
        {
            string         ngay  = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
            PhieuNhapModel ddb   = new PhieuNhapModel();
            string         MHMax = ddb.LayDonHangCungNgay(ngay);
            //Xử lý sinh mã hóa đơn theo quy tắc
            string ma = SinhMa(MHMax, ngay);
            //End

            PhieuNhap dh = new PhieuNhap();

            dh.MaPhieuNhap = ma;
            //dh.NgayNhap = DateTime.Now;
            dh.ThanhTien = thanhtien;

            ddb.ThemDonHang(dh);

            ChiTietPNModel cdb = new ChiTietPNModel();

            foreach (ChiTietPN ct in ds)
            {
                ct.MaPhieuNhap = ma;
            }
            cdb.LuuDanhSachPN(ds);
        }
Example #2
0
        public void InsertPhieuNhap(PhieuNhapModel model)
        {
            PhieuNhap        pn        = new PhieuNhap();
            ChiTietPhieuNhap chitietPN = new ChiTietPhieuNhap();
            NhaCungCapDAO    nccDAO    = new NhaCungCapDAO();

            int maxIdPN   = db.PhieuNhaps.Select(x => x.MaPN).Max();
            int maxIdCTPN = db.ChiTietPhieuNhaps.Select(x => x.MaCTPN).Max();

            pn.MaPN     = maxIdPN + 1;
            pn.MaNCC    = model.MaNCC;
            pn.NgayNhap = model.NgayNhap;
            db.PhieuNhaps.Add(pn);

            chitietPN.MaPN        = maxIdPN + 1;
            chitietPN.MaCTPN      = maxIdCTPN + 1;
            chitietPN.DonGiaNhap  = model.DonGiaNhap;
            chitietPN.SoLuongNhap = model.SoLuongNhap;
            chitietPN.MaSP        = model.MaSP;
            db.ChiTietPhieuNhaps.Add(chitietPN);

            //CapNhatSLTon(model.MaSP, model.SoLuongNhap);

            db.SaveChanges();
        }
Example #3
0
        public ActionResult CreatePN(PhieuNhapModel model)
        {
            var spDAO = new SanPhamDAO();

            if (ModelState.IsValid)
            {
                spDAO.InsertPhieuNhap(model);
                return(RedirectToAction("AllPNInMon"));
            }

            return(View(model));
        }
Example #4
0
        public void SuaHang(PhieuNhap kh, int thanhtien, ChiTietPN ds)
        {
            PhieuNhapModel ddb = new PhieuNhapModel();

            //kh.NgayNhap = DateTime.Now;
            kh.ThanhTien = thanhtien;
            ddb.UpdatePN(kh);
            ChiTietPNModel cdb = new ChiTietPNModel();

            cdb.SuaCTPN(ds);
            //int sl = cdb.LaySoluongTheoMaSPN(ma, ds.MaSP);
            //SanPhamModel ssp = new SanPhamModel();
            //SanPham dss = ssp.LaySanPhamTheoMa(ds.MaSP);
            //dss.SoLuongTon += sl;
        }
Example #5
0
        public ActionResult Edit(PhieuNhapModel phieuNhap)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://206.189.90.147/api/");

                //HTTP POST
                var postTask = client.PostAsJsonAsync <PhieuNhapModel>("update_pn", phieuNhap);
                postTask.Wait();
                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index"));
                }
            }
            return(View(phieuNhap));
        }
Example #6
0
        public ActionResult Create(PhieuNhapModel phieuNhap)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://206.189.90.147/");

                //HTTP POST
                var postTask = client.PostAsJsonAsync <PhieuNhapModel>("api/create_pn", phieuNhap);
                postTask.Wait();
                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index"));
                }
            }
            ModelState.AddModelError(string.Empty, "Lỗi khởi tạo.");
            return(View(phieuNhap));
        }
Example #7
0
        public ActionResult Edit(int id)
        {
            IEnumerable <PhieuNhapModel> phieuNhaps = null;
            PhieuNhapModel phieuNhap = new PhieuNhapModel();

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://206.189.90.147/");
                //HTTP GET
                var responseTask = client.GetAsync("api/getallpn");
                responseTask.Wait();

                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <List <PhieuNhapModel> >();
                    readTask.Wait();

                    phieuNhaps = readTask.Result;
                }
                else //web api sent error response
                {
                    //log response status here..

                    phieuNhaps = Enumerable.Empty <PhieuNhapModel>();

                    ModelState.AddModelError(string.Empty, "Lỗi server.");
                }


                foreach (var i in phieuNhaps)
                {
                    if (i.id == id)
                    {
                        phieuNhap = i;
                        break;
                    }
                }
            }
            return(View(phieuNhap));
        }
Example #8
0
        public void NhaphangDon(PhieuNhap kh, int thanhtien, ChiTietPN ds)
        {
            string         ngay  = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
            PhieuNhapModel ddb   = new PhieuNhapModel();
            string         MHMax = ddb.LayDonHangCungNgay(ngay);
            //Xử lý sinh mã hóa đơn theo quy tắc
            string ma = SinhMa(MHMax, ngay);

            //End
            kh.MaPhieuNhap = ma;
            //kh.NgayNhap = DateTime.Now;
            kh.ThanhTien = thanhtien;
            ddb.ThemDonHang(kh);
            ChiTietPNModel cdb = new ChiTietPNModel();

            ds.MaPhieuNhap = ma;
            cdb.LuuCTPN(ds);
            int          sl  = cdb.LaySoluongTheoMaSPN(ma, ds.MaSP);
            SanPhamModel ssp = new SanPhamModel();
            SanPham      dss = ssp.LaySanPhamTheoMa(ds.MaSP);

            dss.SoLuongTon += sl;
        }