Exemplo n.º 1
0
        public ContentResult GetStockDetail(Lib.GridPager pager, string queryStr, string WarehouseCode)
        {
            IQueryable <T_StockStorage> queryData = db.T_StockStorage.Where(a => a.Type == "入库").AsQueryable();

            if (!string.IsNullOrEmpty(queryStr))
            {
                queryData = queryData.Where(a => a.SupplierName != null && a.SupplierName.Contains(queryStr));
            }
            if (!string.IsNullOrEmpty(WarehouseCode))
            {
                queryData = queryData.Where(a => a.WarehouseCode.Contains(WarehouseCode));
            }
            pager.totalRows = queryData.Count();
            //分页
            queryData = queryData.OrderByDescending(c => c.ID).Skip((pager.page - 1) * pager.rows).Take(pager.rows);
            List <T_StockStorage> list = new List <T_StockStorage>();

            foreach (var item in queryData)
            {
                T_StockStorage i = new T_StockStorage();
                item.WarehouseCode = WarehouseByName(item.WarehouseCode);
                item.SupplierName  = SupplierGY(item.SupplierName);
                i = item;
                list.Add(i);
            }
            // List<T_ManualBilling> list = queryData.OrderByDescending(c => c.ID).Skip((pager.page - 1) * pager.rows).Take(pager.rows).ToList();
            string json = "{\"total\":" + pager.totalRows + ",\"rows\":" + JsonConvert.SerializeObject(list, Lib.Comm.setTimeFormat()) + "}";

            return(Content(json));
        }
Exemplo n.º 2
0
        public JsonResult StockDetailAdd(T_StockStorage Model, string jsonStr)
        {
            using (TransactionScope sc = new TransactionScope())
            {
                try
                {
                    string 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();
                    }
                    sc.Complete();
                    return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    return(Json(new { State = "Faile", Message = ex.Message }, JsonRequestBehavior.AllowGet));
                }
            }
        }
Exemplo n.º 3
0
        public ActionResult ViewStockStorageStockDetail(int ID)
        {
            T_StockStorage Model = db.T_StockStorage.SingleOrDefault(a => a.ID == ID);

            Model.WarehouseCode = WarehouseByName(Model.WarehouseCode);
            Model.SupplierName  = SupplierGY(Model.SupplierName);
            ViewData["ID"]      = Model.ID;
            return(View(Model));
        }
Exemplo n.º 4
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));
                }
            }
        }