Esempio n. 1
0
        public JsonResult Get(int draw, int start)
        {
            //var filteredData = (from v in _db.VendorProducts
            //					join c in _Ldb.CMSMB on v.VendorNo equals c.MB001
            //					select new Vendor {
            //						VendorNo = v.VendorNo,
            //						VendorName = c.MB001
            //					}).AsQueryable();  //get three results



            var filteredData = (from v in _db.VendorProducts
                                select new Vendor {
                VendorNo = v.VendorNo
            }).Distinct().AsQueryable();

            string parameter = Request.Query["search[value]"].FirstOrDefault();

            VendorCondition condition = null;

            if (parameter != "")
            {
                condition = (VendorCondition)JsonConvert.DeserializeObject(parameter, typeof(VendorCondition));
            }

            List <Vendor> rows = null;

            if (condition != null)
            {
                if (condition.VendorNo != "")
                {
                    filteredData = filteredData.Where(e => e.VendorNo.Contains(condition.VendorNo));
                }
            }

            //var filteredData2 = filteredData.GroupBy(x => x.v.VendorNo)
            //				   .Select(grp => grp.First())
            //				   .ToList();  //get one result


            int recordsTotal = filteredData.Count();

            //rows = filteredData.GroupBy(x => x.VendorNo)
            //				   .Select(grp => grp.First()).OrderBy(e => e.VendorNo).Skip(start).Take(15).ToList();

            rows = filteredData.OrderBy(e => e.VendorNo).Skip(start).Take(15).ToList();

            var renderModel = new DataTablesRenderModel
            {
                draw            = draw,
                data            = rows,
                length          = rows.Count(),
                recordsFiltered = recordsTotal,
                recordsTotal    = recordsTotal
            };

            return(Json(renderModel));
        }
Esempio n. 2
0
        public JsonResult Get(int draw, int start)
        {
            List <ProductVendor>  rows     = null;
            List <VendorProducts> vrows    = null;
            var VendorProductsfilteredData = _db.VendorProducts.AsQueryable();
            var filteredData = (from p in _db.ProductInfoes
                                select new ProductVendor
            {
                ProductNo = p.ProductNo,
                ProductName = p.ProductName,
                Spec = p.Spec,
                Unit = p.Unit,
                Capcity = p.Capcity,
                EffectiveMonth = p.EffectiveMonth,
                EffectiveDay = p.EffectiveDay,
                Barcode = p.Barcode,
                Manufacture = false
            }
                                ).AsQueryable();

            string parameter = Request.Query["search[value]"].FirstOrDefault();

            VendorCondition condition = null;

            if (parameter != "")
            {
                condition = (VendorCondition)JsonConvert.DeserializeObject(parameter, typeof(VendorCondition));
            }

            int recordsTotal = filteredData.Count();

            rows = filteredData.OrderBy(e => e.ProductNo).ToList();


            if (condition != null)
            {
                //根據代工廠Table(VendorProducts),給予ProductVendor.Manufacture是否為true,true代表該代工廠有製造此商品
                VendorProductsfilteredData = VendorProductsfilteredData.Where(e => e.VendorNo == condition.VendorNo);
                vrows = VendorProductsfilteredData.OrderBy(e => e.ProductNo).ToList();

                foreach (VendorProducts vendorProducts in vrows)
                {
                    foreach (ProductVendor productVendor in rows)
                    {
                        if (productVendor.ProductNo.Equals(vendorProducts.ProductNo))
                        {
                            productVendor.Manufacture = true;
                        }
                    }
                }
            }

            rows = rows.AsQueryable().OrderByDescending(x => x.Manufacture).ToList();


            var renderModel = new DataTablesRenderModel
            {
                draw            = draw,
                data            = rows,
                length          = rows.Count(),
                recordsFiltered = recordsTotal,
                recordsTotal    = recordsTotal
            };

            return(Json(renderModel));
        }