コード例 #1
0
        public JsonResult save(string c, tb_WMS_ChiTietKhachTraHang ChiTiet)
        {
            if (c != "[]")
            {
                JArray jsonArray   = JArray.Parse(c);
                var    jsonObjects = jsonArray.OfType <JObject>().ToList();

                var idtra       = int.Parse(jsonObjects[0]["idphieutra"].ToString());
                var idxuat      = int.Parse(jsonObjects[0]["idphieuxuat"].ToString());
                var tongtien    = int.Parse(jsonObjects[0]["tongtien"].ToString().Replace(",", ""));
                var tongsoluong = int.Parse(jsonObjects[0]["tongsoluong"].ToString());
                var ghichu      = jsonObjects[0]["ghichu"].ToString();

                var phieutra = (from N in _context.tb_WMS_KhachTraHang
                                where N.ID == idtra
                                select N).FirstOrDefault();
                phieutra.SoLuong = tongsoluong;
                phieutra.Tien    = tongtien;
                phieutra.GhiChu  = ghichu;
                _context.tb_WMS_KhachTraHang.Update(phieutra);
                _context.SaveChanges();

                var chitiet = (from N in _context.tb_WMS_ChiTietKhachTraHang
                               where N.IDTraHang == idtra
                               select N).ToList();
                foreach (var a in chitiet)
                {
                    var imei       = a.Imei;
                    var ctiet_xuat = (from N in _context.tb_WMS_ChiTietPhieuXuat
                                      where N.Imei == imei && N.IDPhieuXuat == idxuat
                                      select N).FirstOrDefault();
                    ctiet_xuat.TraHang = false;
                    _context.tb_WMS_ChiTietPhieuXuat.Update(ctiet_xuat);
                    _context.SaveChanges();
                }

                foreach (var i in chitiet)
                {
                    _context.tb_WMS_ChiTietKhachTraHang.Remove(i);
                    _context.SaveChanges();
                }
                var q = jsonObjects.Count();
                for (var h = 0; h < q; h++)
                {
                    var idchitiet     = int.Parse(jsonObjects[h]["idchitiet"].ToString());
                    var idend_chitiet = (from u in _context.tb_WMS_ChiTietKhachTraHang
                                         orderby u.ID descending
                                         select u.ID).Take(1).FirstOrDefault();
                    if (idchitiet != 0)
                    {
                        var chitiet_xuat = (from N in _context.tb_WMS_ChiTietPhieuXuat
                                            where N.ID == idchitiet
                                            select N).FirstOrDefault();
                        chitiet_xuat.TraHang = true;
                        _context.Update(chitiet_xuat);
                        var imei   = chitiet_xuat.Imei;
                        var gia    = chitiet_xuat.GiaBan;
                        var idpbsp = chitiet_xuat.IDPBSP;

                        ChiTiet.IDPBSP    = idpbsp;
                        ChiTiet.Imei      = imei;
                        ChiTiet.DonGia    = gia;
                        ChiTiet.IDTraHang = idtra;
                        ChiTiet.ID        = idend_chitiet + 1;
                        _context.tb_WMS_ChiTietKhachTraHang.Add(ChiTiet);

                        _context.SaveChanges();
                    }
                }

                return(Json("hello"));
            }
            else
            {
                return(Json(""));
            }
        }
コード例 #2
0
        public JsonResult Save(string c, tb_WMS_KhachTraHang KhachTraHang, tb_WMS_ChiTietKhachTraHang ChiTiet)
        {
            if (c != "[]")
            {
                var idend = (from u in _context.tb_WMS_KhachTraHang
                             orderby u.ID descending
                             select u.ID).Take(1).FirstOrDefault();
                var nhanvien = int.Parse(@User.FindFirst("IdNV").Value);

                JArray jsonArray   = JArray.Parse(c);
                var    jsonObjects = jsonArray.OfType <JObject>().ToList();

                var idxuat      = int.Parse(jsonObjects[0]["idphieu"].ToString());
                var tongtien    = int.Parse(jsonObjects[0]["tongtien"].ToString().Replace(",", ""));
                var tongsoluong = int.Parse(jsonObjects[0]["tongsoluong"].ToString());
                var ghichu      = jsonObjects[0]["ghichu"].ToString();

                KhachTraHang.IDXuat  = idxuat;
                KhachTraHang.SoLuong = tongsoluong;
                KhachTraHang.Tien    = tongtien;
                DateTime date = DateTime.Now;
                KhachTraHang.NgayLap    = date;
                KhachTraHang.MaTraHang  = "CR" + (idend + 1);
                KhachTraHang.ID         = idend + 1;
                KhachTraHang.TrangThai  = 0;
                KhachTraHang.IDNhanVien = nhanvien;
                KhachTraHang.GhiChu     = ghichu;
                _context.tb_WMS_KhachTraHang.Add(KhachTraHang);
                _context.SaveChanges();
                var phieuxuat = (from N in _context.tb_WMS_PhieuXuat
                                 where N.ID == idxuat
                                 select N).FirstOrDefault();
                phieuxuat.TraHang = true;
                _context.Update(phieuxuat);

                var q = jsonObjects.Count();
                for (var h = 0; h < q; h++)
                {
                    var idchitiet     = int.Parse(jsonObjects[h]["idchitiet"].ToString());
                    var idtrahang     = idend + 1;
                    var idend_chitiet = (from u in _context.tb_WMS_ChiTietKhachTraHang
                                         orderby u.ID descending
                                         select u.ID).Take(1).FirstOrDefault();

                    if (idchitiet != 0)
                    {
                        var chitiet_xuat = (from N in _context.tb_WMS_ChiTietPhieuXuat
                                            where N.ID == idchitiet
                                            select N).FirstOrDefault();
                        chitiet_xuat.TraHang = true;
                        _context.Update(chitiet_xuat);
                        var imei   = chitiet_xuat.Imei;
                        var gia    = chitiet_xuat.GiaBan;
                        var idpbsp = chitiet_xuat.IDPBSP;

                        ChiTiet.IDPBSP    = idpbsp;
                        ChiTiet.Imei      = imei;
                        ChiTiet.DonGia    = gia;
                        ChiTiet.IDTraHang = idtrahang;
                        ChiTiet.ID        = idend_chitiet + 1;
                        _context.tb_WMS_ChiTietKhachTraHang.Add(ChiTiet);

                        _context.SaveChanges();
                    }
                }
                //var soluong_phieuxuat = phieuxuat.SoLuong;
                //if () { }

                return(Json(idend + 1));
            }
            else
            {
                return(Json(""));
            }
        }