protected void bttnGenerate_Click(object sender, EventArgs e) { ModelInfo info = ModelHelper.GetModelInfo(txtModelName.Text.Trim()); if (info != null) { DataBaseHelperFactory.Create().CreateTable(info); } else { Response.Write("当前模型文件不存在"); } }
/// <summary> /// 创建模型数据表 /// </summary> /// <param name="info">内容模型</param> /// <returns></returns> public static Dictionary <string, string> CreateModelTable(ModelInfo info) { Dictionary <string, string> d = new Dictionary <string, string>(); try { DataBaseHelperFactory.Create().CreateTable(info); d.Add("result", "true"); } catch (Exception ex) { d.Add("result", ex.Message); } return(d); }
public string CreateModelTable(string model) { string retVal; try { ModelInfo info = ModelHelper.GetModelInfo(model); DataBaseHelperFactory.Create().CreateTable(info); retVal = "{\"success\":\"true\"}"; } catch (Exception ex) { retVal = "{\"success\":\"false\",\"msg\":\"" + Utils.JsonCharFilter(ex.Message) + "\"}"; } return(retVal); }
/// <summary> /// AddMutiPanel /// </summary> /// <param name="modelInfo"></param> /// <param name="name"></param> public void AddMutiPanel(ModelInfo modelInfo, string name) { Panel panel = new Panel(); panel.Name = "multi"; panel.Label = "会员中心显示面板"; panel.CommandInfo = new CommandInfo(); panel.CommandInfo.Path = "System.SimpleCommandSystem.SimpleCommand"; panel.CommandInfo.Visible = true; panel.ConditionInfo = new ConditionInfo(); panel.ConditionInfo.Path = "System.SimpleCondition"; panel.ConditionInfo.Visible = true; panel.Context = new PanelContext(); panel.EditInfo = new EditInfo(); panel.EditInfo.Path = "System.CascadeEditor"; panel.EditInfo.Visible = true; panel.EditInfo.Groups = new GroupCollection(); panel.EditInfo.Groups.Add(new Group()); panel.EditInfo.Groups[0].Controls = new We7ControlCollection(); panel.ListInfo = new ListInfo(); panel.ListInfo.Path = "System.SimpleList"; panel.ListInfo.Visible = true; panel.ListInfo.Groups[0].Columns = new ColumnInfoCollection(); panel.NavigationInfo = new NavigationInfo(); panel.NavigationInfo.Path = "System.SimplenNavigation"; panel.NavigationInfo.Visible = true; panel.PagerInfo = new PagerInfo(); panel.PagerInfo.Path = "System.SimplePage"; panel.PagerInfo.Visible = true; panel.Context.PageSize = 10; panel.Context.DataKeyString = "ID"; //panel.Context.DataKey =new System.Web.UI.WebControls.DataKey( modelInfo.Layout.Panels.Add(panel); ModelHelper.SaveModelInfo(modelInfo, name); //生成数据表 DataBaseHelperFactory.Create().CreateTable(modelInfo); }
public string SaveList(string model, string panel, string list, string condition, string pagesize, int index, string enable) { string colsJson = HttpContext.Current.Server.UrlDecode(list); string conditionJson = HttpContext.Current.Server.UrlDecode(condition); ModelInfo modelInfo = ModelHelper.GetModelInfo(model); try { if (modelInfo.Layout.Panels[panel] == null && panel == "multi") { AddMutiPanel(modelInfo, model); modelInfo = ModelHelper.GetModelInfo(model); } ColumnInfoCollection cols = JavaScriptConvert.DeserializeObject <ColumnInfoCollection>(colsJson); We7ControlCollection conditionCtr = JavaScriptConvert.DeserializeObject <We7ControlCollection>(conditionJson); ModelUIHandler.DealSystemColumn(cols, modelInfo); GetGroupByIndex(index, modelInfo.Layout.Panels[panel].ListInfo.Groups).Columns = cols; GetGroupByIndex(index, modelInfo.Layout.Panels[panel].ListInfo.Groups).Enable = bool.Parse(enable); modelInfo.Layout.Panels[panel].Context.PageSize = Convert.ToInt32(pagesize); modelInfo.Layout.Panels[panel].ConditionInfo.Controls = conditionCtr; ModelHelper.SaveModelInfo(modelInfo, model); //生成数据表 DataBaseHelperFactory.Create().CreateTable(modelInfo); } catch (Exception ex) { //TODO:: resolve exception return(ex.Message); } return("保存完毕"); }
public string SaveEdit(string model, string panel, string editControls, string copy, int index, string next, string enable) { string editJson = HttpContext.Current.Server.UrlDecode(editControls); ModelInfo modelInfo = ModelHelper.GetModelInfo(model); try { We7ControlCollection editCtrls = JavaScriptConvert.DeserializeObject <We7ControlCollection>(editJson); if (modelInfo.Layout.Panels[panel] == null && panel == "multi") { AddMutiPanel(modelInfo, model); modelInfo = ModelHelper.GetModelInfo(model); } foreach (We7Control editCtrl in editCtrls) { if (editCtrl.Type == "RelationSelect") { //添加统计字段 AddCount(editCtrl, modelInfo); } } Group group = GetGroupByIndex(index, modelInfo.Layout.Panels[panel].EditInfo.Groups); group.Controls = editCtrls; group.Next = int.Parse(next); group.Enable = bool.Parse(enable); if (modelInfo.Type == ModelType.ACCOUNT) { List <We7Control> DeleteCtrs = new List <We7Control>(); foreach (We7Control ctr in modelInfo.Layout.Panels["fedit"].EditInfo.Controls) { if (ctr.Name == "ID") { continue; } DeleteCtrs.Add(ctr); } foreach (We7Control ctr in DeleteCtrs) { modelInfo.Layout.Panels["fedit"].EditInfo.Controls.Remove(ctr); } foreach (We7Control ctr in modelInfo.Layout.Panels["edit"].EditInfo.Controls) { if (ctr.Name == "ID") { continue; } group.Controls.Add(ctr.Clone() as We7Control); } } if (copy == "true") { if (modelInfo.Type == ModelType.ARTICLE) { if (modelInfo.Layout.Panels["multi"] != null) { modelInfo.Layout.Panels["multi"].EditInfo = modelInfo.Layout.Panels["edit"].EditInfo; } } } ModelHelper.SaveModelInfo(modelInfo, model); //生成数据表 DataBaseHelperFactory.Create().CreateTable(modelInfo); } catch (Exception ex) { //TODO:: resolve exception return(ex.Message); } return("保存完毕"); }
/// <summary> /// 检查各项是否已经创建 /// </summary> void Exist(string Action) { IDataBaseHelper helper = DataBaseHelperFactory.Create(); StringBuilder sb = new StringBuilder(); sb.Append("{\"modelName\":\"" + ModelInfo.ModelName + "\",\"Data\":["); if (Action == "widget") { #region 检查部件 //部件 int widgetCount = 0; string viewPath = ModelHelper.GetWidgetDirectory(modelInfo, "View"); string listPath = ModelHelper.GetWidgetDirectory(modelInfo, "List"); string pageListPath = ModelHelper.GetWidgetDirectory(modelInfo, "PagedList"); if (Directory.Exists(viewPath)) { widgetCount++; } if (Directory.Exists(listPath)) { widgetCount++; } if (Directory.Exists(pageListPath)) { widgetCount++; } //存在至少一个部件 if (widgetCount > 0) { sb.Append("{\"name\":\"createWidget\",\"exist\":true},"); } else { sb.Append("{\"name\":\"createWidget\",\"exist\":false},"); } #endregion } if (isArticle) { #region 检查表结构 //int rowCount = 0; //try //{ // rowCount = helper.Count(ModelInfo.Name, ""); // sb.Append("{\"name\":\"createTable\",\"exist\":true},"); //} //catch //{ // sb.Append("{\"name\":\"createTable\",\"exist\":false},"); //} #endregion #region 检查左侧菜单 //MenuHelper MenuHelper = HelperFactory.Instance.GetHelper<MenuHelper>(); //We7.CMS.Common.MenuItem item = MenuHelper.GetMenuItemByTitle(ModelInfo.Label + "管理"); //if (item != null && !string.IsNullOrEmpty(item.ID)) //{ // sb.Append("{\"name\":\"addLeftMenu\",\"exist\":true},"); //} //else //{ // sb.Append("{\"name\":\"addLeftMenu\",\"exist\":false},"); //} #endregion if (Action == "layout") { #region 检查布局 string layoutPath = ModelHelper.GetModelLayoutDirectory(ModelInfo.ModelName) + "GenerateLayout.ascx"; if (File.Exists(layoutPath)) { layoutPath = String.Format("{0}/{1}/{2}/{3}", ModelConfig.ModelsDirectory, ModelInfo.GroupName, ModelInfo.Name, "GenerateLayout.ascx"); EditInfo entity = ModelInfo.Layout.Panels["edit"].EditInfo; sb.Append("{\"name\":\"createLayout\",\"exist\":true,\"path\":\"" + layoutPath + "\"},"); //ModelInfo.Layout.Panels["edit"].EditInfo.Layout; if (!string.IsNullOrEmpty(entity.Layout)) { chkAE.Checked = true; } if (!string.IsNullOrEmpty(entity.ViewerLayout)) { chkView.Checked = true; } if (!string.IsNullOrEmpty(entity.UcLayout)) { chkUC.Checked = true; } } else { sb.Append("{\"name\":\"createLayout\",\"exist\":false},"); } #endregion } } sb.Append("]}"); strScript = sb.ToString(); strScript = strScript.Remove(strScript.LastIndexOf(","), 1); strScript = new JavaScriptSerializer().Serialize(strScript); }
/// <summary> /// 删除模型 /// </summary> /// <returns></returns> public string DeleteModel() { string modelName = We7Request.GetQueryString("model"); string msg = ""; bool success = true; //2011-10-10 取消生成控件 //ModelHelper.CreateControls(modelInf); /* * TODO: * 以下这些代码应该集成到ModelHelper.DeleteContentModel中,但是下列代码中需要一些方法是调用We7.CMS.WebControls.Core.BaseControlHelper中的方法,这个类物理文件存储在We7.CMS.UI里面. */ ModelInfo modelInf = ModelHelper.GetModelInfo(modelName); //反馈模型删除前需要解除类型的绑定 if (modelInf.Type.ToString().ToLower().Equals("advice")) { Criteria c = new Criteria(CriteriaType.Equals, "ModelName", modelInf.ModelName); List <AdviceType> adviceList = Assistant.List <AdviceType>(c, null); if (adviceList != null && adviceList.Count > 0) { success = false; msg = "当前模型尚有绑定的反馈类型,请先解除绑定再进行删除!"; return("{\"success\":" + success.ToString().ToLower() + ",\"msg\":\"" + msg + "\"}"); } } //布局控件 string layoutPath = ModelHelper.GetModelLayoutDirectory(modelInf.ModelName); //部件 int widgetCount = 0; string viewPath = ModelHelper.GetWidgetDirectory(modelInf, "View"); string listPath = ModelHelper.GetWidgetDirectory(modelInf, "List"); string pageListPath = ModelHelper.GetWidgetDirectory(modelInf, "PagedList"); try { if (Directory.Exists(layoutPath)) { Directory.Delete(layoutPath, true); } if (Directory.Exists(viewPath)) { Directory.Delete(viewPath, true); widgetCount++; } if (Directory.Exists(listPath)) { Directory.Delete(listPath, true); widgetCount++; } if (Directory.Exists(pageListPath)) { Directory.Delete(pageListPath, true); widgetCount++; } if (widgetCount > 0) { //重建部件索引 BaseControlHelper ctrHelper = new BaseControlHelper(); ctrHelper.CreateIntegrationIndexConfig(); ctrHelper.CreateWidegetsIndex(); } } catch { msg += "部分文件夹删除失败,请手动删除以下文件夹:\r\n"; msg += "1:" + layoutPath + "\r\n"; msg += "2:" + viewPath + "\r\n"; msg += "3:" + listPath + "\r\n"; msg += "4:" + pageListPath + "\r\n"; success = false; } //删除数据库表 try { DataBaseHelperFactory.Create().DeleteTable(modelInf); } catch { } //检查左侧菜单 MenuHelper MenuHelper = HelperFactory.Instance.GetHelper <MenuHelper>(); MenuItem item = MenuHelper.GetMenuItemByTitle(modelInf.Label + "管理"); if (item != null && !string.IsNullOrEmpty(item.ID)) { try { MenuHelper.DeleteMenuItem(item.ID); } catch { success = false; msg += "左侧菜单删除失败,请在【后台菜单管理里手动删除】"; } } //检查是否关联了Channel List <Channel> channelList = HelperFactory.Instance.GetHelper <ChannelHelper>(). GetChannelByModelName(modelInf.ModelName); if (channelList != null && channelList.Count > 0) { try { foreach (Channel c in channelList) { c.ModelName = ""; HelperFactory.Instance.GetHelper <ChannelHelper>().UpdateChannel(c); } } catch (Exception ex) { success = false; msg += "内容模型已关联栏目,取消关联失败,请手动取消栏目和内容模型的绑定关系!错误消息:" + ex.Message; } } //删除XML节点及文件 success = !ModelHelper.DeleteContentModel(modelName, ref msg) ? false : success; string strResult = "{\"success\":" + success.ToString().ToLower() + ",\"msg\":\"" + Utils.JsonCharFilter(msg) + "\"}"; //return JsonConvert.SerializeObject(strResult).Replace("null", "\"\""); ; return(strResult); }
public string SaveList(string model, string panel, string list, string condition, string pagesize, int index, string enable) { string colsJson = HttpContext.Current.Server.UrlDecode(list); string conditionJson = HttpContext.Current.Server.UrlDecode(condition); ModelInfo modelInfo = ModelHelper.GetModelInfo(model); try { if (modelInfo.Layout.Panels[panel] == null && panel == "multi") { AddMutiPanel(modelInfo, model); modelInfo = ModelHelper.GetModelInfo(model); } ColumnInfoCollection cols = JsonConvert.DeserializeObject <ColumnInfoCollection>(colsJson); We7ControlCollection conditionCtr = JsonConvert.DeserializeObject <We7ControlCollection>(conditionJson); ModelUIHandler.DealSystemColumn(cols, modelInfo); /* begin * ndoe:此段代码的作用是查找编辑配置 * 有param["model"]的项(此param作用于关联控件) * 列表查询读取此段param信息可以得到关联表信息。 * ps:如果您试图维护此代码,或者有更好的办法。请谨慎为之。 * author:丁乐 * date:2011/12/19 */ if (modelInfo.Layout.Panels["edit"] != null && modelInfo.Layout.Panels["edit"].EditInfo != null && modelInfo.Layout.Panels["edit"].EditInfo.Controls != null && modelInfo.Layout.Panels["edit"].EditInfo.Controls.Count > 0) { foreach (var item in modelInfo.Layout.Panels["edit"].EditInfo.Controls) { if (item.Params != null && item.Params.Count > 0 && !string.IsNullOrEmpty(item.Params["model"])) { if (cols[item.Name] != null && cols[item.Name].Params != null) { cols[item.Name].Params.Add(new Param("model", item.Params["model"])); cols[item.Name].Params.Add(new Param("textfield", item.Params["textfield"])); cols[item.Name].Params.Add(new Param("valuefield", item.Params["valuefield"])); } else if (cols[item.Name] != null && cols[item.Name].Params == null) { cols[item.Name].Params = new ParamCollection { new Param("model", item.Params["model"]), new Param("textfield", item.Params["textfield"]), new Param("valuefield", item.Params["valuefield"]) }; } } } } /*end*/ GetGroupByIndex(index, modelInfo.Layout.Panels[panel].ListInfo.Groups).Columns = cols; GetGroupByIndex(index, modelInfo.Layout.Panels[panel].ListInfo.Groups).Enable = bool.Parse(enable); modelInfo.Layout.Panels[panel].Context.PageSize = Convert.ToInt32(pagesize); modelInfo.Layout.Panels[panel].ConditionInfo.Controls = conditionCtr; ModelHelper.SaveModelInfo(modelInfo, model); //生成数据表 DataBaseHelperFactory.Create().CreateTable(modelInfo); } catch (Exception ex) { //TODO:: resolve exception return(ex.Message); } return("保存完毕"); }