public ActionResult update(string type, RequestFormInfo formInfo) { switch (type) { case "html": CodeDataBase codeData = new CodeDataBase(); var result = codeData.updateHtml(formInfo); return(Json(new { code = result.ResultStatus, msg = result.Message }, JsonRequestBehavior.AllowGet)); case "": return(View()); } return(View()); }
/// <summary> /// 修改HTML信息 /// </summary> /// <param name="formInfo"></param> /// <returns></returns> public OperateResult updateHtml(RequestFormInfo formInfo) { using (var db = new CGDataBase()) { var htmlInfo = db.control.Where(c => c.id == formInfo.htmlID).FirstOrDefault(); if (htmlInfo != null) { htmlInfo.name = formInfo.htmlName; htmlInfo.desc = formInfo.htmlDesc; htmlInfo.content = StringDispose.AESEncrypt(formInfo.htmlValue); } if (db.SaveChanges() > 0) { return(new OperateResult(ResultStatus.Success, "修改Html信息成功!")); } else { return(new OperateResult(ResultStatus.Error, "修改Html信息失败!")); } } }
public ActionResult CodeAdd(RequestFormInfo formInfo, int bl, int kj, int qj, int mr, int jssx, int ff) { //遍历自定义变量并放入集合 List <definition> bianlianglist = new List <definition>(); for (int i = 1; i <= bl; i++) { string desc = Request.Form["bldesc" + i]; string content = Request.Form["bl" + i]; if (!string.IsNullOrWhiteSpace(desc) && !string.IsNullOrWhiteSpace(content)) { definition definition = new definition() { desc = desc, content = content }; bianlianglist.Add(definition); } } //遍历控件部件并放入集合 List <components> kongjianList = new List <components>(); for (int i = 1; i <= kj; i++) { string desc = Request.Form["kjdesc" + i]; string content = Request.Form["kj" + i]; if (!string.IsNullOrWhiteSpace(desc) && !string.IsNullOrWhiteSpace(content)) { components components = new components() { desc = desc, content = content }; kongjianList.Add(components); } } //遍历全局变量并放入集合 List <data> quanjuList = new List <data>(); for (int i = 1; i <= qj; i++) { string content = Request.Form["qjdesc" + i]; string desc = Request.Form["qj" + i]; if (!string.IsNullOrWhiteSpace(content) && !string.IsNullOrWhiteSpace(desc)) { data data = new data() { content = content, desc = desc }; quanjuList.Add(data); } } //遍历默认数据并放入集合 List <@default> morenList = new List <@default>(); for (int i = 1; i <= mr; i++) { string desc = Request.Form["mrdesc" + i]; string key = Request.Form["mrkey" + i]; string value = Request.Form["mrvalue" + i]; if (!string.IsNullOrWhiteSpace(desc) && !string.IsNullOrWhiteSpace(key) && !string.IsNullOrWhiteSpace(value)) { @default @default = new @default() { desc = desc, key = key, value = value }; morenList.Add(@default); } } //遍历计算属性并放入集合 List <computed> jssxList = new List <computed>(); for (int i = 1; i <= jssx; i++) { string jssxname = Request.Form["jssxname" + i]; string jssxdesc = Request.Form["jssxdesc" + i]; string jssxff = Request.Form["jssxff" + i]; if (!string.IsNullOrWhiteSpace(jssxname) && !string.IsNullOrWhiteSpace(jssxdesc) && !string.IsNullOrWhiteSpace(jssxff)) { computed computed = new computed() { desc = jssxdesc, name = jssxname, content = jssxff }; jssxList.Add(computed); } } //遍历控件方法并放入集合 List <rests> qtfangfaList = new List <rests>(); for (int i = 1; i <= ff; i++) { string qtffname = Request.Form["qtffname" + i]; string qtffdesc = Request.Form["qtffdesc" + i]; string qtffti = Request.Form["qtffti" + i]; if (!string.IsNullOrWhiteSpace(qtffname) && !string.IsNullOrWhiteSpace(qtffdesc) && !string.IsNullOrWhiteSpace(qtffti)) { rests rests = new rests() { name = qtffname, desc = qtffdesc, content = qtffti }; qtfangfaList.Add(rests); } } //遍历控件方法并放入集合 List <methods> fangfaList = new List <methods>(); for (int i = 1; i <= ff; i++) { string ffname = Request.Form["ffname" + i]; string ffdesc = Request.Form["ffdesc" + i]; string ffti = Request.Form["ffti" + i]; if (!string.IsNullOrWhiteSpace(ffname) && !string.IsNullOrWhiteSpace(ffdesc) && !string.IsNullOrWhiteSpace(ffti)) { methods methods = new methods() { name = ffname, desc = ffdesc, content = ffti }; fangfaList.Add(methods); } } //调用方法开始进行数据库存储 //实例化代码入库类 CodeDataBase codeInDataBase = new CodeDataBase(); int result = codeInDataBase.AddCodeInBase(formInfo, bianlianglist, kongjianList, quanjuList, morenList, jssxList, qtfangfaList, fangfaList); switch (result) { case 0: return(Json(new { code = 1, msg = "代码入库失败!" }, JsonRequestBehavior.AllowGet)); case 1: return(Json(new { code = 1, msg = "代码入库成功!" }, JsonRequestBehavior.AllowGet)); case 2: return(Json(new { code = 1, msg = "html代码入库失败!" }, JsonRequestBehavior.AllowGet)); case 3: return(Json(new { code = 1, msg = "Css样式入库失败!" }, JsonRequestBehavior.AllowGet)); case 4: return(Json(new { code = 1, msg = "自定义变量入库失败!" }, JsonRequestBehavior.AllowGet)); case 5: return(Json(new { code = 1, msg = "控件部件入库失败!" }, JsonRequestBehavior.AllowGet)); case 6: return(Json(new { code = 1, msg = "全局变量入库失败!" }, JsonRequestBehavior.AllowGet)); case 7: return(Json(new { code = 1, msg = "默认数据入库失败!" }, JsonRequestBehavior.AllowGet)); case 8: return(Json(new { code = 1, msg = "计算属性入库失败!" }, JsonRequestBehavior.AllowGet)); case 9: return(Json(new { code = 1, msg = "控件方法入库失败!" }, JsonRequestBehavior.AllowGet)); case 10: return(Json(new { code = 1, msg = "添加到PageShow页面失败!" }, JsonRequestBehavior.AllowGet)); } return(View()); }
/// <summary> /// 代码入库将数据添加到各个表中 /// </summary> /// <param name="formInfo"></param> /// <param name="bllist"></param> /// <param name="kjlist"></param> /// <param name="qjlist"></param> /// <param name="mrlist"></param> /// <param name="jssxlist"></param> /// <param name="fflist"></param> /// <returns></returns> public int AddCodeInBase(RequestFormInfo formInfo, List <definition> bllist, List <components> kjlist, List <data> qjlist, List <@default> mrlist, List <computed> jssxlist, List <rests> qtfflist, List <methods> fflist) { //数据库上下文 using (CGDataBase db = new CGDataBase()) { using (DbContextTransaction transaction = db.Database.BeginTransaction()) { try { int c_ID = 0; //添加control表数据 control controlBase = new control() { name = formInfo.htmlName, content = StringDispose.AESEncrypt(formInfo.htmlValue), desc = formInfo.htmlDesc, t_id = formInfo.type }; db.control.Add(controlBase); int res = db.SaveChanges(); if (res > 0) { c_ID = controlBase.id; } //添加样式(style) if (!string.IsNullOrWhiteSpace(formInfo.stylecss)) { style styleBase = new style() { content_css = StringDispose.AESEncrypt(formInfo.stylecss), c_id = c_ID }; db.style.Add(styleBase); db.SaveChanges(); } //添加自定义变量 (definition) if (bllist.Count > 0) { foreach (definition list in bllist) { jb_definition definition = new jb_definition() { content = StringDispose.AESEncrypt(list.content), desc = list.desc, c_id = c_ID }; db.jb_definition.Add(definition); } db.SaveChanges(); } //添加控件部件(components) if (kjlist.Count > 0) { foreach (components list in kjlist) { jb_components components = new jb_components() { content = StringDispose.AESEncrypt(list.content), desc = list.desc, c_id = c_ID }; db.jb_components.Add(components); } db.SaveChanges(); } //添加全局变量(data) if (qjlist.Count > 0) { foreach (data list in qjlist) { jb_data data = new jb_data() { content = StringDispose.AESEncrypt(list.content), desc = list.desc, c_id = c_ID }; db.jb_data.Add(data); } db.SaveChanges(); } //添加默认数据 (default) if (mrlist.Count > 0) { foreach (@default list in mrlist) { jb_default @default = new jb_default() { key = StringDispose.AESEncrypt(list.key), value = StringDispose.AESEncrypt(list.value), desc = list.desc, c_id = c_ID }; db.jb_default.Add(@default); } db.SaveChanges(); } //添加计算属性 (computed) if (jssxlist.Count > 0) { foreach (computed list in jssxlist) { jb_computed computed = new jb_computed() { name = list.name, content = StringDispose.AESEncrypt(list.content), desc = list.desc, c_id = c_ID }; db.jb_computed.Add(computed); } db.SaveChanges(); } //添加其他方法 if (qtfflist.Count > 0) { foreach (rests list in qtfflist) { jb_rests rests = new jb_rests() { name = list.name, content = StringDispose.AESEncrypt(list.content), desc = list.desc, c_id = c_ID }; db.jb_rests.Add(rests); } db.SaveChanges(); } //添加控件方法 (methods) if (fflist.Count > 0) { foreach (methods list in fflist) { jb_methods methods = new jb_methods() { name = list.name, content = StringDispose.AESEncrypt(list.content), desc = list.desc, c_id = c_ID }; db.jb_methods.Add(methods); } db.SaveChanges(); } transaction.Commit(); return(1); ////添加到PageShow页面 //pageshow pageshow = new pageshow() //{ // p_title = formInfo.PageDesc, // c_id = c_ID, // t_id = formInfo.type //}; //db.pageshow.Add(pageshow); //if (db.SaveChanges() > 0) //{ // transaction.Commit(); // return 1; //} //else //{ // return 0; //} } catch (Exception e) { Console.WriteLine(e.Message); transaction.Rollback(); return(0); } } } }