Example #1
0
        /// <summary>
        /// 组合商品保存
        /// </summary>
        /// <param name="model"></param>
        /// <param name="detailList"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public JsonResult ProductCodeGenerateAddSave(T_ProductCodeGenerate model, string detailList)
        {
            using (TransactionScope sc = new TransactionScope())
            {
                try
                {
                    List <T_ProductCodeGenerateDetails> details = Com.Deserialize <T_ProductCodeGenerateDetails>(detailList);
                    string codetype = "";
                    for (int i = 0; i < details.Count; i++)
                    {
                        if (i == 0)
                        {
                            codetype += details[i].CpCode + "|" + details[i].CpNumber;
                        }
                        else
                        {
                            codetype += "|" + details[i].CpCode + "|" + details[i].CpNumber;
                        }
                    }
                    T_ProductCodeGenerate GenerateModel = db.T_ProductCodeGenerate.SingleOrDefault(a => a.CodeType == codetype);
                    if (GenerateModel != null)
                    {
                        return(Json(new { State = "Faile", Message = "该组合已存在" }));
                    }
                    string Nickname = Server.UrlDecode(Request.Cookies["Nickname"].Value);
                    model.CodeType   = codetype;
                    model.CreateDate = DateTime.Now;
                    model.CreateName = Nickname;
                    db.T_ProductCodeGenerate.Add(model);
                    db.SaveChanges();
                    foreach (var item in details)
                    {
                        item.Oid = model.ID;
                        db.T_ProductCodeGenerateDetails.Add(item);
                    }
                    db.SaveChanges();

                    sc.Complete();
                    return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    return(Json(new { State = "Faile", Message = ex.Message }, JsonRequestBehavior.AllowGet));
                }
            }
        }
Example #2
0
        public ContentResult ShowProductCodeGenerateList(Lib.GridPager pager, string queryStr)
        {
            IQueryable <T_ProductCodeGenerate> queryData = db.T_ProductCodeGenerate.AsQueryable();

            if (!string.IsNullOrEmpty(queryStr))
            {
                queryData = queryData.Where(a => (a.Code != null && a.Code.Contains(queryStr) || a.Name != null && a.Name.Contains(queryStr)));
            }

            pager.totalRows = queryData.Count();
            //分页
            queryData = queryData.OrderByDescending(c => c.ID).Skip((pager.page - 1) * pager.rows).Take(pager.rows);
            List <T_ProductCodeGenerate> list = new List <T_ProductCodeGenerate>();

            foreach (var item in queryData)
            {
                T_ProductCodeGenerate i = new T_ProductCodeGenerate();
                i = item;
                list.Add(i);
            }
            string json = "{\"total\":" + pager.totalRows + ",\"rows\":" + JsonConvert.SerializeObject(list, Lib.Comm.setTimeFormat()) + "}";

            return(Content(json));
        }