/// <summary> /// 保存更新数据 /// </summary> /// <param name="formdata"></param> public void save(string formdata) { parentid = Request["parentid"]; string response = ""; string repeat = ""; JObject json = (JObject)JsonConvert.DeserializeObject(formdata); WEB_PAGECONFIG_DETAIL en = JsonToEntity(json); if (!string.IsNullOrEmpty(parentid)) { en.PARENTID = Convert.ToInt32(parentid); } if (en != null) { if (en.ID < 0) { //新增 string sqlStr = @"insert into web_pageconfig_detail (id,parentid,orderno,name,controltype,isselect,selectcontent,configtype,tablecode,fieldcode,tablename,fieldname,createtime,userid,username,enabled) values (web_pageconfig_detail_id.nextval,'{0}','{1}','{2}','{3}','0','{4}','{5}','{6}','{7}','{8}','{9}', sysdate,'{10}','{11}','{12}')"; sqlStr = string.Format(sqlStr, en.PARENTID, en.ORDERNO, en.NAME, en.CONTROLTYPE, en.SELECTCONTENT, en.CONFIGTYPE, en.TABLECODE, en.FIELDCODE, en.TABLENAME, en.FIELDNAME, en.USERID, en.USERNAME, en.ENABLED); int i = DBMgr.ExecuteNonQuery(sqlStr); if (i > 0) { repeat = "5"; } else { repeat = "新增配置失败"; } } else { //更新 string sqlStr = @"update web_pageconfig_detail set name='{0}',controltype='{1}',selectcontent='{2}',configtype='{3}',tablecode='{4}',fieldcode='{5}',tablename='{6}',fieldname='{7}', userid='{8}',username='******',enabled='{10}' where id='{11}'"; sqlStr = string.Format(sqlStr, en.NAME, en.CONTROLTYPE, en.SELECTCONTENT, en.CONFIGTYPE, en.TABLECODE, en.FIELDCODE, en.TABLENAME, en.FIELDNAME, en.USERID, en.USERNAME, en.ENABLED, en.ID); int i = DBMgr.ExecuteNonQuery(sqlStr); if (i > 0) { repeat = "5"; } else { repeat = "更新配置失败"; } } } else { repeat = "json转换出错"; } response = "{\"success\":\"" + repeat + "\"}"; Response.Write(response); Response.End(); }
public WEB_PAGECONFIG_DETAIL JsonToEntity(JObject json) { WEB_PAGECONFIG_DETAIL en = new WEB_PAGECONFIG_DETAIL(); try { if (!string.IsNullOrEmpty(json.Value <string>("ID"))) { en.ID = Convert.ToInt32(json.Value <string>("ID")); } else { en.ID = -1; } if (!string.IsNullOrEmpty(json.Value <string>("ENABLED"))) { en.ENABLED = Convert.ToInt32(json.Value <string>("ENABLED")); } else { en.ENABLED = 1; } FormsIdentity identity = HttpContext.Current.User.Identity as FormsIdentity; string userName = identity.Name; JObject json_user = Extension.Get_UserInfo(userName); en.USERID = (Int32)json_user.GetValue("ID"); en.USERNAME = (string)json_user.GetValue("REALNAME"); en.REASON = json.Value <string>("REASON"); en.NAME = json.Value <string>("NAME"); en.FIELDCODE = json.Value <string>("FIELDCODE"); en.TABLECODE = json.Value <string>("TABLECODE"); en.SELECTCONTENT = json.Value <string>("SELECTCONTENT"); if (!string.IsNullOrEmpty(json.Value <string>("ORDERNO"))) { en.ORDERNO = Convert.ToInt32(json.Value <string>("ORDERNO")); } en.CONTROLTYPE = json.Value <string>("CONTROLTYPE"); en.CONFIGTYPE = json.Value <string>("CONFIGTYPE"); if (en.CONTROLTYPE == "下拉框") { en.SELECTCONTENT = en.SELECTCONTENT.Replace(";", ";"); } else { en.SELECTCONTENT = ""; } en.TABLENAME = GetTableNameWithCode(en.TABLECODE); en.FIELDNAME = GetFieldNameWithCode(en.FIELDCODE, en.TABLECODE); } catch { return(null); } return(en); }