コード例 #1
0
        public ResultTracking Tracking()
        {
            var log = new MongoHistoryAPI()
            {
                APIUrl     = "/api/product/tracking",
                CreateTime = DateTime.Now,
                Sucess     = 1
            };

            var result = new ResultTracking()
            {
                id  = "1",
                msg = "success"
            };

            var requestContent = Request.Content.ReadAsStringAsync().Result;

            try
            {
                var jsonserializer = new JavaScriptSerializer();
                var paser          = jsonserializer.Deserialize <RequestTracking>(requestContent);
                log.Content = new JavaScriptSerializer().Serialize(paser);

                if (!mongoHelper.checkLoginSession(paser.user, paser.token))
                {
                    throw new Exception("Tài khoản của bạn đã bị đăng nhập trên một thiết bị khác!");
                }

                result.code = paser.code;

                var checkProduct = GetProduct(paser.code);

                if (checkProduct == null)
                {
                    throw new Exception("Mã không hợp lệ");
                }


                result.name = checkProduct.PName;

                var boxCode = paser.code.Substring(0, 15);

                List <PTrackingInfo> productTracking = new List <PTrackingInfo>();

                var pHistoryTracking = db.PTrackings.Where(p => p.CaseCode == boxCode).OrderBy(p => p.ImportTime).ToList();

                foreach (var item in pHistoryTracking)
                {
                    PTrackingInfo pTracking = new PTrackingInfo();

                    if (item.WType == "CI")
                    {
                        pTracking.name = "CẤP 1: " + item.WName;
                    }
                    else if (item.WType == "CII")
                    {
                        pTracking.name = "CẤP 2: " + item.WName;
                    }
                    else if (item.WType == "B")
                    {
                        pTracking.name = "CHI NHÁNH: " + item.WName;
                    }
                    else if (item.WType == "FARMER")
                    {
                        pTracking.name = "NÔNG DÂN: " + item.WName;
                    }
                    else if (item.WType == "W")
                    {
                        pTracking.name = "TỔNG KHO: " + item.WName;
                    }

                    if (item.ImportTime != null)
                    {
                        pTracking.importTime = "Nhập kho lúc " + item.ImportTime.Value.ToString("dd/MM/yyyy HH:mm");
                    }
                    else
                    {
                        pTracking.importTime = "Chưa nhập kho";
                    }

                    if (item.ExportTime != null)
                    {
                        pTracking.exportTime = "Xuất kho lúc " + item.ExportTime.Value.ToString("dd/MM/yyyy HH:mm");
                    }
                    else
                    {
                        pTracking.exportTime = "Chưa xuất kho";
                    }


                    if (item.Quantity == 1 || item.Quantity == 0)
                    {
                        pTracking.status = Convert.ToInt32(item.Quantity) + " thùng";
                    }
                    else
                    {
                        int quantity = Convert.ToInt32(item.Quantity * item.ProductInfo.QuantityBox);
                        pTracking.status = quantity + " hộp";
                    }

                    productTracking.Add(pTracking);
                }

                result.tracking = productTracking;
            }
            catch (Exception e)
            {
                result.id  = "0";
                result.msg = e.Message;
                log.Sucess = 0;
            }

            log.ReturnInfo = new JavaScriptSerializer().Serialize(result);
            mongoHelper.createHistoryAPI(log);

            return(result);
        }
コード例 #2
0
        public ActionResult ProductTracking(string barcode)
        {
            if (!Utitl.CheckUser(db, User.Identity.Name, "Tracking", 0))
            {
                return(RedirectToAction("relogin", "home"));
            }

            var product = GetProduct(barcode);

            ViewBag.Barcode = barcode;
            if (product != null)
            {
                ViewBag.Product = product;
                var boxCode = barcode.Substring(0, 15);

                List <PTrackingInfo> productTracking = new List <PTrackingInfo>();

                var pHistoryTracking = db.PTrackings.Where(p => p.CaseCode == boxCode).OrderBy(p => p.ImportTime).ToList();


                foreach (var item in pHistoryTracking)
                {
                    PTrackingInfo pTracking = new PTrackingInfo();

                    if (item.WType == "CI")
                    {
                        pTracking.name = "CẤP 1: " + item.WName;
                    }
                    else if (item.WType == "CII")
                    {
                        pTracking.name = "CẤP 2: " + item.WName;
                    }
                    else if (item.WType == "B")
                    {
                        pTracking.name = "CHI NHÁNH: " + item.WName;
                    }
                    else if (item.WType == "FARMER")
                    {
                        pTracking.name = "NÔNG DÂN: " + item.WName;
                    }
                    else if (item.WType == "W")
                    {
                        pTracking.name = "TỔNG KHO: " + item.WName;
                    }

                    if (item.ImportTime != null)
                    {
                        pTracking.importTime = "Nhập kho lúc " + item.ImportTime.Value.ToString("dd/MM/yyyy HH:mm");
                    }
                    else
                    {
                        pTracking.importTime = "Chưa nhập kho";
                    }

                    if (item.ExportTime != null)
                    {
                        pTracking.exportTime = "Xuất kho lúc " + item.ExportTime.Value.ToString("dd/MM/yyyy HH:mm");
                    }
                    else
                    {
                        pTracking.exportTime = "Chưa xuất kho";
                    }


                    if (item.Quantity == 1 || item.Quantity == 0)
                    {
                        pTracking.status = Convert.ToInt32(item.Quantity) + " thùng";
                    }
                    else
                    {
                        int quantity = Convert.ToInt32(item.Quantity * item.ProductInfo.QuantityBox);
                        pTracking.status = quantity + " hộp";
                    }

                    productTracking.Add(pTracking);
                }

                ViewBag.Tracking = productTracking;
            }



            return(View());
        }