예제 #1
0
        //
        // GET: /PackShipment/

        public ActionResult Index()
        {
            BestradeContext btContext = new BestradeContext();
            List <Shipment> shipments = btContext.Shipments.Where(s => s.complete == false).ToList();

            ViewData["shipments"] = shipments;
            return(View(PackShipmentView.view()));
        }
예제 #2
0
        public ActionResult AddPackShipment(string purchase, string sku, string shipment, string qty)
        {
            int check_int;

            if (qty.Length == 0 || !int.TryParse(qty, out check_int) || Convert.ToInt32(qty) <= 0)
            {
                return(RedirectToAction("Error", "Shared", new { message = "数量格式不对或者为空或小于等于0" }));
            }
            if (purchase.Length == 0 || sku.Length == 0 || shipment.Length == 0)
            {
                return(RedirectToAction("Error", "Shared", new { message = "请选择Pack和Shipment" }));
            }
            try
            {
                using (var btContext = new BestradeContext())
                {
                    string           sql_cmd = String.Format("SELECT p_qty, s_qty FROM PackShipmentView WHERE purchase = '{0}' AND sku = '{1}'", purchase, sku);
                    PackShipmentView view    = btContext.Database.SqlQuery <PackShipmentView>(sql_cmd).FirstOrDefault();
                    int qty_left             = view.p_qty - view.s_qty - Convert.ToInt32(qty);
                    if (qty_left < 0)
                    {
                        return(RedirectToAction("Error", "Shared", new { message = "该Pack剩余数量低于寄出数量,请确认数量是否正确" }));
                    }
                    btContext.PackShipment.Add(new PackShipment
                    {
                        purchase = purchase,
                        sku      = sku,
                        shipment = shipment,
                        qty      = Convert.ToInt32(qty)
                    });
                    btContext.SaveChanges();
                }
            }
            catch (DbUpdateException e)
            {
                return(RedirectToAction("Error", "Shared", new { message = "同样的Pack在同一个Shipment下面已经存在,请做调整" }));
            }
            catch (FormatException e)
            {
                return(RedirectToAction("Error", "Shared", new { message = "数量格式不对" }));
            }

            return(RedirectToAction("Index", "PackShipment"));
        }
예제 #3
0
        public ActionResult UpdatePackShipment(string purchase, string sku, string shipment, string qty)
        {
            int check_int;

            if (qty.Length == 0 || !int.TryParse(qty, out check_int) || Convert.ToInt32(qty) <= 0)
            {
                return(RedirectToAction("Error", "Shared", new { message = "数量格式不对或者为空或小于等于0" }));
            }
            try
            {
                using (var btContext = new BestradeContext())
                {
                    //Check if the number is right to update
                    string           sql_cmd = String.Format("SELECT p_qty, s_qty FROM PackShipmentView WHERE purchase = '{0}' AND sku = '{1}'", purchase, sku);
                    PackShipmentView view    = btContext.Database.SqlQuery <PackShipmentView>(sql_cmd).FirstOrDefault();
                    int qty_before_update    = btContext.PackShipment.FirstOrDefault(q => q.purchase == purchase && q.sku == sku && q.shipment == shipment).qty;
                    int qty_available        = view.p_qty - view.s_qty + qty_before_update;
                    if (qty_available < Convert.ToInt32(qty))
                    {
                        return(RedirectToAction("Error", "Shared", new { message = "该Pack剩余数量低于寄出数量,请确认数量是否正确" }));
                    }
                    //
                    var result = btContext.PackShipment.SingleOrDefault(p => p.purchase == purchase && p.sku == sku && p.shipment == shipment);
                    result.purchase = purchase;
                    result.sku      = sku;
                    result.shipment = shipment;
                    result.qty      = Convert.ToInt32(qty);
                    btContext.SaveChanges();
                }
            }
            catch (FormatException e)
            {
                return(RedirectToAction("Error", "Shared", new { message = "数量为空或格式不对" }));
            }
            catch (DbUpdateException e)
            {
                return(RedirectToAction("Error", "Shared", new { message = "Pack或Shipment不存在" }));
            }

            return(RedirectToAction("Overview", "PackShipment"));
        }