示例#1
0
        public JsonResult SingleProductAddSave(T_goodsGY model)
        {
            string name = Server.UrlDecode(Request.Cookies["Nickname"].Value);

            using (TransactionScope sc = new TransactionScope())
            {
                model.create_date = DateTime.Now;
                model.create_Name = name;
                db.T_goodsGY.Add(model);
                try
                {
                    int i = db.SaveChanges();
                    if (i > 0)
                    {
                        App_Code.GY gy  = new App_Code.GY();
                        string      cmd = "";
                        cmd = "{" +
                              "\"appkey\":\"171736\"," +
                              "\"method\":\"gy.erp.item.add\"," +
                              "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"," +
                              "\"code\":\"" + model.code + "\"," +
                              "\"name\":\"" + model.name + "\"," +
                              "\"simple_name\":\"" + model.simple_name + "\"," +
                              "\"skus\":[]" +
                              "}";
                        string sign    = gy.Sign(cmd);
                        string comcode = "{" +
                                         "\"appkey\":\"171736\"," +
                                         "\"method\":\"gy.erp.item.add\"," +
                                         "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"," +
                                         "\"code\":\"" + model.code + "\"," +
                                         "\"name\":\"" + model.name + "\"," +
                                         "\"simple_name\":\"" + model.simple_name + "\"," +
                                         "\"sign\":\"" + sign + "\"," +
                                         "\"skus\":[]" +
                                         "}";
                        string   ret      = gy.DoPost("http://api.guanyierp.com/rest/erp_open", comcode);
                        JsonData jsonData = null;
                        jsonData = JsonMapper.ToObject(ret);
                        string sd = jsonData[0].ToString();
                        if (sd == "True")
                        {
                            sc.Complete();
                            return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet));
                        }
                        else
                        {
                            return(Json(new { State = "Faile" }, JsonRequestBehavior.AllowGet));
                        }
                    }
                }
                catch (DbEntityValidationException ex)
                {
                    return(Json(new { State = "Faile", Message = ex.EntityValidationErrors.First().ValidationErrors.First().ErrorMessage }, JsonRequestBehavior.AllowGet));
                }
                return(Json(new { State = "Faile" }, JsonRequestBehavior.AllowGet));
            }
        }
示例#2
0
 public JsonResult ViewSingleProductsplitCheckSave(string code)
 {
     using (TransactionScope sc = new TransactionScope())
     {
         T_goodsGY model = db.T_goodsGY.SingleOrDefault(a => a.code == code);
         model.isexamine = "1";
         db.Entry <T_goodsGY>(model).State = System.Data.Entity.EntityState.Modified;
         try
         {
             int i = db.SaveChanges();
             if (i > 0)
             {
                 App_Code.GY gy  = new App_Code.GY();
                 string      cmd = "";
                 cmd = "{" +
                       "\"appkey\":\"171736\"," +
                       "\"method\":\"gy.erp.item.add\"," +
                       "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"," +
                       "\"code\":\"" + model.code + "\"," +
                       "\"name\":\"" + model.name + "\"," +
                       "\"simple_name\":\"" + model.simple_name + "\"," +
                       "\"skus\":[]" +
                       "}";
                 string sign    = gy.Sign(cmd);
                 string comcode = "{" +
                                  "\"appkey\":\"171736\"," +
                                  "\"method\":\"gy.erp.item.add\"," +
                                  "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"," +
                                  "\"code\":\"" + model.code + "\"," +
                                  "\"name\":\"" + model.name + "\"," +
                                  "\"simple_name\":\"" + model.simple_name + "\"," +
                                  "\"sign\":\"" + sign + "\"," +
                                  "\"skus\":[]" +
                                  "}";
                 string   ret      = gy.DoPost("http://api.guanyierp.com/rest/erp_open", comcode);
                 JsonData jsonData = null;
                 jsonData = JsonMapper.ToObject(ret);
                 string sd = jsonData[0].ToString();
                 if (sd == "True")
                 {
                     sc.Complete();
                     return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet));
                 }
                 else
                 {
                     return(Json(new { State = "Faile", Message = "审核失败" }, JsonRequestBehavior.AllowGet));
                 }
             }
         }
         catch (DbEntityValidationException ex)
         {
             return(Json(new { State = "Faile", Message = "审核失败" }, JsonRequestBehavior.AllowGet));
         }
         return(Json(new { State = "Faile", Message = "审核失败" }, JsonRequestBehavior.AllowGet));
     }
 }
示例#3
0
        public JsonResult ViewSingleProductPartsAddSave(T_goodsGY model)
        {
            string name = Server.UrlDecode(Request.Cookies["Nickname"].Value);

            using (TransactionScope sc = new TransactionScope())
            {
                T_ProductClass      ProductClassmodel      = db.T_ProductClass.SingleOrDefault(a => a.ClassName == model.classify);
                string              ClassCode              = ProductClassmodel.ClassCode;
                T_ProductManufactor ProductManufactormodel = db.T_ProductManufactor.SingleOrDefault(a => a.ManufactorName == model.Manufactor);
                string              ManufactorCode         = ProductManufactormodel.ManufactorCode;
                string              Specifications         = model.Specifications;

                string code = "S" + ClassCode + ManufactorCode + Specifications;

                List <T_goodsGY> goodsList = db.T_goodsGY.Where(a => a.code == code).ToList();
                if (goodsList.Count > 0)
                {
                    return(Json(new { State = "Faile", Message = "该组合方式的配件已存在" }, JsonRequestBehavior.AllowGet));
                }

                model.code = code;

                model.create_date = DateTime.Now;
                model.create_Name = name;
                db.T_goodsGY.Add(model);
                try
                {
                    int i = db.SaveChanges();
                    if (i > 0)
                    {
                        App_Code.GY gy  = new App_Code.GY();
                        string      cmd = "";
                        cmd = "{" +
                              "\"appkey\":\"171736\"," +
                              "\"method\":\"gy.erp.item.add\"," +
                              "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"," +
                              "\"code\":\"" + model.code + "\"," +
                              "\"name\":\"" + model.name + "\"," +
                              "\"simple_name\":\"" + model.simple_name + "\"," +
                              "\"skus\":[]" +
                              "}";
                        string sign    = gy.Sign(cmd);
                        string comcode = "{" +
                                         "\"appkey\":\"171736\"," +
                                         "\"method\":\"gy.erp.item.add\"," +
                                         "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"," +
                                         "\"code\":\"" + model.code + "\"," +
                                         "\"name\":\"" + model.name + "\"," +
                                         "\"simple_name\":\"" + model.simple_name + "\"," +
                                         "\"sign\":\"" + sign + "\"," +
                                         "\"skus\":[]" +
                                         "}";
                        string   ret      = gy.DoPost("http://api.guanyierp.com/rest/erp_open", comcode);
                        JsonData jsonData = null;
                        jsonData = JsonMapper.ToObject(ret);
                        string sd = jsonData[0].ToString();
                        if (sd == "True")
                        {
                            sc.Complete();
                            return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet));
                        }
                        else
                        {
                            return(Json(new { State = "Faile", Message = "保存失败" }, JsonRequestBehavior.AllowGet));
                        }
                    }
                }
                catch (DbEntityValidationException ex)
                {
                    return(Json(new { State = "Faile", Message = "保存失败" }, JsonRequestBehavior.AllowGet));
                }
                return(Json(new { State = "Faile", Message = "保存失败" }, JsonRequestBehavior.AllowGet));
            }
        }
示例#4
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);
            //}
        }
示例#5
0
        //[Description("新增保存")]
        public JsonResult StockDetailAdd(T_StockStorage Model, string jsonStr, string CurUser)
        {
            using (TransactionScope sc = new TransactionScope())
            {
                try
                {
                    string Nickname = "";
                    if (!string.IsNullOrWhiteSpace(CurUser))
                    {
                        Nickname = CurUser;
                    }
                    else
                    {
                        Nickname = Server.UrlDecode(Request.Cookies["Nickname"].Value);
                    }
                    Model.Type      = "入库";
                    Model.ApplyName = Nickname;
                    Model.ApplyDate = DateTime.Now;
                    db.T_StockStorage.Add(Model);
                    db.SaveChanges();
                    List <T_StockDetail> details = App_Code.Com.Deserialize <T_StockDetail>(jsonStr);


                    foreach (var item in details)
                    {
                        item.Oid = Model.ID;
                        db.T_StockDetail.Add(item);
                        db.SaveChanges();
                        string  code          = item.Code;
                        string  WarehouseCode = Model.WarehouseCode;
                        T_Stock Smodel        = db.T_Stock.SingleOrDefault(a => a.Code == code && a.WarehouseName == WarehouseCode);
                        if (Smodel != null)
                        {
                            Smodel.Qty += item.Qty;
                            db.Entry <T_Stock>(Smodel).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                        }
                        else
                        {
                            T_Stock StModel = new T_Stock();
                            StModel.Qty           = item.Qty;
                            StModel.Name          = item.Name;
                            StModel.Code          = item.Code;
                            StModel.WarehouseName = WarehouseCode;
                            db.T_Stock.Add(StModel);
                            db.SaveChanges();
                        }

                        T_StockOutstorage StorageModel = new T_StockOutstorage();
                        StorageModel.Code          = item.Code;
                        StorageModel.Name          = item.Name;
                        StorageModel.WarehouseCode = WarehouseCode;
                        StorageModel.number        = Model.ID.ToString();
                        StorageModel.Qty           = item.Qty;
                        StorageModel.Type          = "入库";
                        db.T_StockOutstorage.Add(StorageModel);
                        db.SaveChanges();
                    }
                    string cpcode = "";
                    for (int z = 0; z < details.Count; z++)
                    {
                        if (z == details.Count - 1)
                        {
                            cpcode += "{\"barcode\":\"" + details[z].Code + "\",\"qty\":" + details[z].Qty + "}";
                        }
                        else
                        {
                            cpcode += "{\"barcode\":\"" + details[z].Code + "\",\"qty\":" + details[z].Qty + "},";
                        }
                    }
                    EBMS.App_Code.GY gy  = new App_Code.GY();
                    string           cmd = "";
                    cmd = "{" +
                          "\"appkey\":\"171736\"," +
                          "\"method\":\"gy.erp.new.purchase.arrive.add\"," +
                          "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"," +
                          "\"warehouse_code\":\"" + Model.WarehouseCode + "\"," +
                          "\"supplier_code\":\"" + Model.SupplierName + "\"," +
                          "\"order_type\":\"001\"," +
                          "\"detail_list\":[" + cpcode + "]" +
                          "}";
                    string sign    = gy.Sign(cmd);
                    string comcode = "";
                    comcode = "{" +
                              "\"appkey\":\"171736\"," +
                              "\"method\":\"gy.erp.new.purchase.arrive.add\"," +
                              "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"," +
                              "\"sign\":\"" + sign + "\"," +
                              "\"warehouse_code\":\"" + Model.WarehouseCode + "\"," +
                              "\"supplier_code\":\"" + Model.SupplierName + "\"," +
                              "\"order_type\":\"001\"," +
                              "\"detail_list\":[" + cpcode + "]" +
                              "}";
                    string   ret      = gy.DoPost("http://api.guanyierp.com/rest/erp_open", comcode);
                    JsonData jsonData = null;
                    jsonData = JsonMapper.ToObject(ret);

                    if (jsonData.Count == 6)
                    {
                        return(Json(new { State = "Faile", Message = "写入管易失败,请联系管理员" }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        sc.Complete();
                        return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet));
                    }
                }
                catch (Exception ex)
                {
                    return(Json(new { State = "Faile", Message = ex.Message }, JsonRequestBehavior.AllowGet));
                }
            }
        }
示例#6
0
        //查询单据编号返回详情 数据来自管易
        public JsonResult getOrderDetail(string num)
        {
            try {
                string result = "";
                if (num != null)
                {
                    App_Code.GY gy  = new App_Code.GY();
                    string      cmd = "";

                    cmd = "{" +
                          "\"appkey\":\"171736\"," +
                          "\"method\":\"gy.erp.trade.deliverys.get\"," +
                          "\"page\":1," +
                          "\"page_size\":3," +
                          "\"code\":\"" + num + "\"," +
                          "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"" +
                          "}";

                    string sign = gy.Sign(cmd);
                    cmd = cmd.Replace("}", ",\"sign\":\"" + sign + "\"}");
                    string   ret      = gy.DoPost("http://api.guanyierp.com/rest/erp_open", cmd);
                    JsonData jsonData = null;
                    jsonData = JsonMapper.ToObject(ret);
                    DateTime dateStar = DateTime.Parse("2017-02-10 16:07:50.473");
                    DateTime dateEnd  = DateTime.Parse("2017-02-11 16:07:50.473");
                    if (jsonData["deliverys"].Count == 0)
                    {
                        cmd = "{" +
                              "\"appkey\":\"171736\"," +
                              "\"method\":\"gy.erp.trade.deliverys.history.get\"," +
                              "\"page\":1," +
                              "\"page_size\":3," +
                              "\"code\":\"" + num + "\"," +
                              "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"" +
                              "}";
                        sign     = gy.Sign(cmd);
                        cmd      = cmd.Replace("}", ",\"sign\":\"" + sign + "\"}");
                        ret      = gy.DoPost("http://api.guanyierp.com/rest/erp_open", cmd);
                        jsonData = null;
                        jsonData = JsonMapper.ToObject(ret);
                        if (jsonData.Count == 6 || jsonData["deliverys"].Count == 0)
                        {
                            result = "单据编号不存在";
                            return(Json(new { State = "Faile", Message = result }, JsonRequestBehavior.AllowGet));
                        }
                    }
                    JsonData jsonOrders = jsonData["deliverys"][0];
                    //查询管易发货字段 可是不能修改
                    //int state = int.Parse((jsonOrders["delivery_state"]).ToString());

                    //if (state != 0) {
                    //    result = "该订单已经发货";
                    //    return Json(new { State = "Faile", Message = result }, JsonRequestBehavior.AllowGet);
                    //}
                    // 查询发货表 订单是否发货
                    T_Deliver deliverFlag = db.T_Deliver.FirstOrDefault(a => a.MailNo == num);
                    if (deliverFlag != null)
                    {
                        return(Json(new { State = "Faile", Message = "该单据编号已经发货" }, JsonRequestBehavior.AllowGet));
                    }
                    JsonData      details     = jsonOrders["details"];
                    List <AddMod> detalislist = new List <AddMod>();
                    for (int s = 0; s < details.Count; s++)
                    {
                        //返回的数据构造
                        AddMod   detalis    = new AddMod();
                        JsonData detailItem = details[s];
                        string   Code       = isNULL(detailItem["item_code"]).ToString();
                        detalis.item_code = isNULL(detailItem["item_code"]).ToString();
                        detalis.item_name = isNULL(detailItem["item_name"]).ToString();
                        detalis.qty       = int.Parse(detailItem["qty"].ToString());
                        detalis.sku_name  = isNULL(detailItem["sku_name"]).ToString();
                        string Tiaoma = db.T_goodsGY.SingleOrDefault(a => a.code == Code).barcode;
                        detalis.tiaoma = Tiaoma;
                        detalislist.Add(detalis);
                    }
                    string Warehouse = isNULL(jsonOrders["warehouse_name"]).ToString();
                    string OrderNum  = isNULL(jsonOrders["platform_code"]).ToString();

                    result = "{\"rows\":" + JsonConvert.SerializeObject(detalislist) + ",\"Warehouse\":\"" + Warehouse + "\",\"OrderNum\":\"" + OrderNum + "\"}";
                }
                else
                {
                    result = "请输入正确的单据编号";
                    return(Json(new { State = "Faile", Message = result }, JsonRequestBehavior.AllowGet));
                }
                return(Json(new { State = "Success", result = result }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json(new { State = "Faile", Message = e.Message }, JsonRequestBehavior.AllowGet));
            }
        }
        //审核
        public JsonResult ManualBillingCheckCheck(T_ManualBilling model, string status, string Memo)
        {
            using (TransactionScope sc = new TransactionScope())
            {
                int             ID           = model.ID;
                T_ManualBilling Invoicemodel = db.T_ManualBilling.SingleOrDefault(a => a.ID == ID && a.Isdelete == 0);
                if (Invoicemodel == null)
                {
                    return(Json("数据可能被删除", JsonRequestBehavior.AllowGet));
                }

                T_ManualBillingAppRove modelApprove = db.T_ManualBillingAppRove.FirstOrDefault(a => a.Oid == ID && a.ApproveTime == null);
                string Nickname = Server.UrlDecode(Request.Cookies["Nickname"].Value);

                string result = "";
                modelApprove.ApproveName = Nickname;
                modelApprove.Memo        = Memo;
                modelApprove.ApproveTime = DateTime.Now;
                modelApprove.Status      = int.Parse(status);
                db.Entry <T_ManualBillingAppRove>(modelApprove).State = System.Data.Entity.EntityState.Modified;
                int i = db.SaveChanges();
                if (i > 0)
                {
                    if (status == "1")
                    {
                        T_ManualBillingAppRove newApprove = new T_ManualBillingAppRove();
                        int step = int.Parse(Invoicemodel.Step.ToString());
                        step++;
                        IQueryable <T_ManualBillingConfig> config = db.T_ManualBillingConfig.AsQueryable();
                        int stepLength = config.Count();//总共步骤
                        if (step < stepLength)
                        {
                            Invoicemodel.Status = 0;
                            T_ManualBillingConfig stepMod = db.T_ManualBillingConfig.SingleOrDefault(a => a.Step == step);
                            string nextName = stepMod.Name;
                            newApprove.Memo   = "";
                            newApprove.Oid    = ID;
                            newApprove.Status = -1;
                            newApprove.Step   = step.ToString();
                            if (nextName != null)
                            {
                                newApprove.ApproveName  = nextName;
                                newApprove.ApproveDName = stepMod.Type;
                            }
                            else
                            {
                                newApprove.ApproveName  = stepMod.Type;
                                newApprove.ApproveDName = stepMod.Type;
                            }
                            db.T_ManualBillingAppRove.Add(newApprove);
                            db.SaveChanges();
                        }
                        else
                        {
                            List <T_ManualBillingDetails> DetailsList = db.T_ManualBillingDetails.Where(a => a.Oid == ID).ToList();
                            string shangp = "";
                            for (int e = 0; e < DetailsList.Count; e++)
                            {
                                if (e == DetailsList.Count - 1)
                                {
                                    shangp += "{\"qty\":" + DetailsList[e].qty + ",\"note\":\"\",\"refund\":0,\"item_code\":\"" + System.Web.HttpContext.Current.Server.UrlEncode(DetailsList[e].Code) + "\"}";
                                }
                                else
                                {
                                    shangp += "{\"qty\":" + DetailsList[e].qty + ",\"note\":\"\",\"refund\":0,\"item_code\":\"" + System.Web.HttpContext.Current.Server.UrlEncode(DetailsList[e].Code) + "\"},";
                                }
                            }
                            decimal PaymentAmount = 0;
                            if (Invoicemodel.PaymentAmount != null)
                            {
                                PaymentAmount = decimal.Parse(Invoicemodel.PaymentAmount.ToString());
                            }

                            //   string payments = "{\"pay_type_code\":wangyin,\"payment\":" + PaymentAmount + "},";
                            string   payments          = "{\"pay_type_code\":\"wangyin\",\"payment\":\"" + PaymentAmount + "\"}";
                            string[] address           = Invoicemodel.GoodsAddress.Split('-');
                            string   receiver_province = "";
                            string   receiver_city     = "";
                            string   receiver_district = "";
                            if (address.Length >= 1)
                            {
                                receiver_province = address[0];
                            }
                            if (address.Length >= 2)
                            {
                                receiver_city = address[1];
                            }
                            if (address.Length >= 3)
                            {
                                receiver_district = address[2];
                            }


                            EBMS.App_Code.GY gy       = new App_Code.GY();
                            string           ShopCode = GetShopFromString(Invoicemodel.ShopName);
                            string           datetime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                            string           cmd      = "";
                            cmd = "{" +
                                  "\"appkey\":\"171736\"," +
                                  "\"method\":\"gy.erp.trade.add\"," +
                                  "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"," +
                                  "\"platform_code\":\"" + Invoicemodel.OrderNumber + "\"," +
                                  "\"order_type_code\":\"Sales\"," +
                                  "\"shop_code\":\"" + ShopCode + "\"," +
                                  "\"post_fee\":\"" + Invoicemodel.ExpressFee + "\"," +

                                  "\"receiver_province\":\"" + receiver_province + "\"," +
                                  "\"receiver_city\":\"" + receiver_city + "\"," +
                                  "\"receiver_district\":\"" + receiver_district + "\"," +
                                  "\"express_code\":\"" + Invoicemodel.ExpressCode + "\"," +
                                  "\"warehouse_code\":\"" + Invoicemodel.DeliverGoodsWarehouse + "\"," +
                                  "\"vip_code\":\"" + Invoicemodel.GoodsReceiptName + "\"," +
                                  "\"vip_name\":\"" + Invoicemodel.GoodsReceiptName + "\"," +
                                  "\"receiver_name\":\"" + Invoicemodel.GoodsReceiptName + "\"," +
                                  "\"receiver_address\":\"" + Invoicemodel.GoodsReceiptAddress + "\"," +
                                  "\"receiver_mobile\":\"" + Invoicemodel.GoodsReceiptPhone + "\"," +
                                  "\"receiver_phone\":\"" + Invoicemodel.GoodsReceiptPhone + "\"," +
                                  "\"deal_datetime\":\"" + datetime + "\"," +
                                  "\"seller_memo\":\"" + Invoicemodel.DeliverGoodsReason + "\"," +
                                  "\"payments\":[" + payments + "]," +
                                  "\"details\":[" + shangp + "]" +
                                  "}";
                            string sign    = gy.Sign(cmd);
                            string comcode = "{" +
                                             "\"appkey\":\"171736\"," +
                                             "\"method\":\"gy.erp.trade.add\"," +
                                             "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"," +
                                             "\"platform_code\":\"" + Invoicemodel.OrderNumber + "\"," +
                                             "\"order_type_code\":\"Sales\"," +
                                             "\"shop_code\":\"" + ShopCode + "\"," +
                                             "\"post_fee\":\"" + Invoicemodel.ExpressFee + "\"," +

                                             "\"receiver_province\":\"" + receiver_province + "\"," +
                                             "\"receiver_city\":\"" + receiver_city + "\"," +
                                             "\"receiver_district\":\"" + receiver_district + "\"," +
                                             "\"express_code\":\"" + Invoicemodel.ExpressCode + "\"," +
                                             "\"warehouse_code\":\"" + Invoicemodel.DeliverGoodsWarehouse + "\"," +
                                             "\"vip_code\":\"" + Invoicemodel.GoodsReceiptName + "\"," +
                                             "\"vip_name\":\"" + Invoicemodel.GoodsReceiptName + "\"," +
                                             "\"receiver_name\":\"" + Invoicemodel.GoodsReceiptName + "\"," +
                                             "\"receiver_address\":\"" + Invoicemodel.GoodsReceiptAddress + "\"," +
                                             "\"receiver_mobile\":\"" + Invoicemodel.GoodsReceiptPhone + "\"," +
                                             "\"receiver_phone\":\"" + Invoicemodel.GoodsReceiptPhone + "\"," +
                                             "\"deal_datetime\":\"" + datetime + "\"," +
                                             "\"seller_memo\":\"" + Invoicemodel.DeliverGoodsReason + "\"," +
                                             "\"sign\":\"" + sign + "\"," +
                                             "\"payments\":[" + payments + "]," +
                                             "\"details\":[" + shangp + "]" +
                                             "}";
                            string   ret      = gy.DoPost("http://api.guanyierp.com/rest/erp_open", comcode);
                            JsonData jsonData = null;
                            jsonData = JsonMapper.ToObject(ret);
                            string sd = jsonData[0].ToString();
                            if (jsonData.Count == 6)
                            {
                                // return Json(new { State = "Faile" }, JsonRequestBehavior.AllowGet);
                                result = "管理调整单失败,请核对信息";
                                return(Json(result, JsonRequestBehavior.AllowGet));
                            }
                            Invoicemodel.Status = int.Parse(status);
                        }
                        Invoicemodel.Step = step;
                        db.Entry <T_ManualBilling>(Invoicemodel).State = System.Data.Entity.EntityState.Modified;
                        int j = db.SaveChanges();
                        sc.Complete();
                        if (j > 0)
                        {
                            result = "保存成功";
                        }
                        else
                        {
                            result = "保存失败";
                        }
                    }
                    else
                    {
                        //不同意
                        Invoicemodel.Step   = 0;
                        Invoicemodel.Status = 2;
                        db.Entry <T_ManualBilling>(Invoicemodel).State = System.Data.Entity.EntityState.Modified;
                        int j = db.SaveChanges();
                        //审核流程结束 申请人编辑后插入下一条记录
                        sc.Complete();
                        if (j > 0)
                        {
                            result = "保存成功";
                        }
                        else
                        {
                            result = "保存失败";
                        }
                    }
                }
                else
                {
                    result = "保存失败";
                }


                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }