/// <summary> /// 获得DefaultModelName /// TODO:入口不确定 此方法有待修正 /// </summary> /// <returns></returns> private string GetDefaultModelName() { IList <DefaultModel> list = ModelHelper.GetDefaultModels(); foreach (DefaultModel item in list) { if (item.Name.ToLower().Contains(MyModelType.ToLower())) { return(item.Name); } } return("Template.ArticleModel"); }
/// <summary> /// Form Submit /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void SubmitButton_Click(object sender, EventArgs e) { if (!CheckInput()) { return; } string defaultModelName = RequestHelper.Get <string>("modelname"); if (String.IsNullOrEmpty(defaultModelName)) { defaultModelName = GetDefaultModelName(); } //获取默认的模型 ModelInfo modelInfo = ModelHelper.GetModelInfoByName(defaultModelName); ContentModelEntity model = new ContentModelEntity(); model.Name = string.Format("{0}.{1}", GroupDropDownList.Enabled ? Request[GroupDropDownList.UniqueID] : GroupDropDownList.SelectedValue, ModelNameTextBox.Text.Trim()); model.State = Convert.ToInt32(ModelStateDropDownList.SelectedValue); model.Label = ModelLabelTextBox.Text.Trim(); model.DefaultContentName = defaultModelName; ModelType modelType = ModelType.ARTICLE; if (defaultModelName == "Template.AdviceModel" || MyModelType.ToLower() == "advice") { modelType = ModelType.ADVICE; } else if (defaultModelName == "Template.AccountModel" || MyModelType.ToLower() == "account") { modelType = ModelType.ACCOUNT; if (!string.IsNullOrEmpty(RoleTextBox.Text)) { modelInfo.Parameters = "role:" + RoleTextBox.Text; } ; } model.Description = DescriptionTextBox.Text.Trim(); model.Type = modelType; if (string.IsNullOrEmpty(this.ModelNameTextBox.Text.Trim())) { Messages.ShowError("模型名称不能为空!"); return; } bool success = ModelHelper.SaveContentModel(model); BindModelGroup(); if (success) { modelInfo.Label = model.Label; modelInfo.ModelName = model.Name; modelInfo.Desc = model.Description; modelInfo.DataSet.Tables[0].Name = ModelNameTextBox.Text.Trim(); modelInfo.Type = modelType; modelInfo.AuthorityType = AuthorityTypeCheckBox.Checked; if (defaultModelName == "Template.ArticleModel") { string tempvalue = modelInfo.Layout.Panels["list"].ListInfo.Groups[0].Columns["Manage"].Params["cmd"].Replace("Template.ArticleModel", model.Name); modelInfo.Layout.Panels["list"].ListInfo.Groups[0].Columns["Manage"].Params["cmd"] = tempvalue; } ModelHelper.SaveModelInfo(modelInfo, model.Name); } if (success) { string tempName = RequestHelper.Get <string>("modelname"); string msg = ModelTypeName + " {0} 成功!继续 <a href='EditLayout.aspx?modelname={1}' target='_blank'>编辑模型布局</a> "; if (Action == ActionType.Add) { msg = string.Format(msg, "添加", model.Name); } else if (Action == ActionType.Edit) { msg = string.Format(msg, "修改", tempName); } Messages.ShowMessage(msg); } else { if (Action == ActionType.Add) { Messages.ShowError("添加失败!"); } else if (Action == ActionType.Edit) { Messages.ShowError("修改失败!"); } } }