Example #1
0
 public JsonResult RespiratorEditSave(T_RespiratorOrder model, string jsonStr)
 {
     using (TransactionScope sc = new TransactionScope())
     {
         try
         {
             T_RespiratorOrder order = db.T_RespiratorOrder.Find(model.ID);
             if (order != null)
             {
                 List <T_RespiratorOrderDetails> detail = Com.Deserialize <T_RespiratorOrderDetails>(jsonStr);
                 if (detail.Count == 0)
                 {
                     return(Json(new { State = "Faile", Message = "请添加详情" }, JsonRequestBehavior.AllowGet));
                 }
                 else
                 {
                     foreach (var item in detail)
                     {
                         T_RespiratorOrderDetails editDetail = db.T_RespiratorOrderDetails.Find(item.ID);
                         editDetail.Company     = item.Company;
                         editDetail.Number      = item.Number;
                         editDetail.Price       = item.Price;
                         editDetail.ProductCode = item.ProductCode;
                         editDetail.ProductName = item.ProductName;
                         editDetail.Subtotal    = item.Subtotal;
                         db.Entry <T_RespiratorOrderDetails>(editDetail).State = System.Data.Entity.EntityState.Modified;
                     }
                     db.SaveChanges();
                     sc.Complete();
                     return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet));
                 }
             }
             else
             {
                 return(Json(new { State = "Faile", Message = "保存失败" }, JsonRequestBehavior.AllowGet));
             }
         }
         catch (Exception ex)
         {
             return(Json(new { State = "Faile", Message = ex.Message }, JsonRequestBehavior.AllowGet));
         }
     }
 }
Example #2
0
        //根据订单号查询查询数据
        public JsonResult QueryDataByCode(string Ordercode)
        {
            if (!string.IsNullOrWhiteSpace(Ordercode))
            {
                List <T_RespiratorOrder> orders = db.T_RespiratorOrder.Where(a => a.OrderCode == Ordercode.Trim()).ToList();
                if (orders.Count > 0)
                {
                    return(Json(-1));
                }
            }
            if (Ordercode != "" && Ordercode != null)
            {
                App_Code.GY gy  = new App_Code.GY();
                string      cmd = "";
                cmd = "{" +
                      "\"appkey\":\"171736\"," +
                      "\"method\":\"gy.erp.trade.get\"," +
                      "\"page_no\":1," +
                      "\"page_size\":10," +
                      "\"platform_code\":\"" + Ordercode + "\"," +
                      "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"" +
                      "}";
                string sign = gy.Sign(cmd);
                cmd = cmd.Replace("}", ",\"sign\":\"" + sign + "\"}");
                string   retnum      = gy.DoPost("http://api.guanyierp.com/rest/erp_open", cmd);
                JsonData jsonDatanum = null;
                jsonDatanum = JsonMapper.ToObject(retnum);
                int successnum = int.Parse(jsonDatanum[7].ToString());
                if (successnum > 0)
                {
                    //赋值

                    JsonData orders = jsonDatanum["orders"][0];
                    //收货人
                    string receiver_name = isNULL(orders["receiver_name"]).ToString();
                    //收货人电话
                    string receiver_phone = isNULL(orders["receiver_phone"]).ToString();
                    //收货人手机
                    string receiver_mobile = isNULL(orders["receiver_mobile"]).ToString();
                    //收货人地址
                    string            receiver_address = isNULL(orders["receiver_address"]).ToString();
                    T_RespiratorOrder model            = new T_RespiratorOrder();
                    model.CustomerName = receiver_name;
                    if (receiver_phone != "")
                    {
                        model.Customerphone = receiver_phone;
                    }
                    else
                    {
                        model.Customerphone = receiver_mobile;
                    }

                    model.Customeraddress = receiver_address;

                    JsonData details = orders["details"];
                    List <T_RespiratorOrderDetails> detalislist = new List <T_RespiratorOrderDetails>();
                    for (int s = 0; s < details.Count; s++)
                    {
                        T_RespiratorOrderDetails detalis = new T_RespiratorOrderDetails();
                        JsonData detailsxiangqing        = details[s];
                        detalis.ProductName = isNULL(detailsxiangqing["item_name"]).ToString();
                        detalis.Company     = isNULL(detailsxiangqing["item_simple_name"]).ToString();
                        detalislist.Add(detalis);
                    }
                    return(Json(new { i = model, d = detalislist }, JsonRequestBehavior.AllowGet));
                    //return View(model);
                }
                else
                {
                    App_Code.GY gynum = new App_Code.GY();

                    string cmdnum = "";
                    cmdnum = "{" +
                             "\"appkey\":\"171736\"," +
                             "\"method\":\"gy.erp.trade.history.get\"," +
                             "\"page_no\":1," +
                             "\"page_size\":10," +
                             "\"platform_code\":\"" + Ordercode + "\"," +
                             "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"" +
                             "}";
                    string signnum = gynum.Sign(cmdnum);
                    cmdnum      = cmdnum.Replace("}", ",\"sign\":\"" + signnum + "\"}");
                    retnum      = gy.DoPost("http://api.guanyierp.com/rest/erp_open", cmdnum);
                    jsonDatanum = null;
                    jsonDatanum = JsonMapper.ToObject(retnum);
                    successnum  = int.Parse(jsonDatanum[7].ToString());
                    if (successnum > 0)
                    {
                        //赋值

                        JsonData orders = jsonDatanum["orders"][0];
                        //收货人
                        string receiver_name = isNULL(orders["receiver_name"]).ToString();
                        //收货人电话
                        string receiver_phone = isNULL(orders["receiver_phone"]).ToString();
                        //收货人手机
                        string receiver_mobile = isNULL(orders["receiver_mobile"]).ToString();
                        //收货人地址
                        string            receiver_address = isNULL(orders["receiver_address"]).ToString();
                        T_RespiratorOrder model            = new T_RespiratorOrder();
                        model.CustomerName = receiver_name;
                        if (receiver_phone != "")
                        {
                            model.Customerphone = receiver_phone;
                        }
                        else
                        {
                            model.Customerphone = receiver_mobile;
                        }

                        model.Customeraddress = receiver_address;

                        JsonData details = orders["details"];
                        List <T_RespiratorOrderDetails> detalislist = new List <T_RespiratorOrderDetails>();
                        for (int s = 0; s < details.Count; s++)
                        {
                            T_RespiratorOrderDetails detalis = new T_RespiratorOrderDetails();
                            JsonData detailsxiangqing        = details[s];
                            detalis.ProductName = detailsxiangqing["item_name"].ToString();
                            detalis.Company     = detailsxiangqing["item_simple_name"].ToString();
                            detalis.ProductCode = detailsxiangqing["item_code"].ToString();
                            detalis.Number      = Convert.ToInt32(detailsxiangqing["qty"].ToString());
                            detalislist.Add(detalis);
                        }
                        return(Json(new { i = model, d = detalislist }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            int i = 0;

            return(Json(i, JsonRequestBehavior.AllowGet));
            //if (!string.IsNullOrWhiteSpace(Ordercode))
            //{
            //    List<T_RespiratorOrder> RespiratorOrder = db.T_RespiratorOrder.Where(a => a.OrderCode == Ordercode.Trim()).ToList();



            //    if (RespiratorOrder.Count > 0)
            //    {
            //        return Json(-1);//已添加该订单
            //    }
            //    else
            //    {
            //        T_OrderList Order = db.T_OrderList.SingleOrDefault(a => a.platform_code == Ordercode);
            //        if (Order != null)
            //        {
            //            string oid=Order.code;
            //            List<T_OrderDetail> detail = db.T_OrderDetail.Where(a => a.oid == oid).ToList();
            //            return Json(new { i = Order,d=detail }, JsonRequestBehavior.AllowGet);
            //        }
            //        else
            //        {
            //            return Json(0, JsonRequestBehavior.AllowGet);
            //        }
            //    }
            //}
            //else
            //{
            //    return Json(0, JsonRequestBehavior.AllowGet);
            //}
        }