using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CB.Framework; using CB.Common; using CB.Entity; using CB.Data; namespace CB.Admin.Plugins.Basic { public partial class TopicClassEdit : AdminPage { protected string Action = string.Empty; private static int id; protected void Page_Load(object sender, EventArgs e) { Action = WRequest.GetQueryString("Action"); if (!Page.IsPostBack) { InitData(); } } protected override void InitData() { BindList(); } protected void BindList() { id = WRequest.GetQueryInt("id"); TopicClassInfo entity = TopicClassService.Get(id); //绑定父类型 int aindex = 0; IList ais = TopicClassService.ToList(); int j = 0; foreach (var item in ais) { ddlParent.Items.Add(new ListItem(item.Name, item.Cid.ToString())); j++; if (entity != null && entity.ParentId == item.Cid) { aindex = j; } } if (entity != null && entity.Cid > 0) { txtcid.Text = entity.Cid.ToString().Trim(); txtName.Text = entity.Name.ToString().Trim(); ddlParent.SelectedIndex = aindex; } } //新增或修改 protected void btnEdit_Click(object sender, EventArgs e) { #region 修改ID为自增 //if (string.IsNullOrEmpty(txtcid.Text.Trim())) //{ // ShowMessageBox("标题ID不能为空"); //} //if (TypeConverter.StrToInt(txtcid.Text.Trim())<=0) //{ // ShowMessageBox("标题ID大于0"); //} #endregion if (string.IsNullOrEmpty(txtName.Text.Trim())) { ShowMessageBox("名称不能为空!"); } TopicClassInfo entity = new TopicClassInfo { Cid = TypeConverter.StrToInt(txtcid.Text.Trim()), Name = txtName.Text.Trim(), ParentId = TypeConverter.StrToInt(ddlParent.SelectedValue), RootId = TypeConverter.StrToInt(ddlParent.SelectedValue), Depth = TypeConverter.StrToInt(ddlParent.SelectedValue) > 0 ? CB.Data.TopicClassService.Get(TypeConverter.StrToInt(ddlParent.SelectedValue)).Depth + 1 : TypeConverter.StrToInt(ddlParent.SelectedValue) }; if (CB.Data.TopicClassService.Get(entity.Cid) != null && Action == "Add") { ShowMessageBox("已存在改CID数据,若要修改,请执行修改操作"); } if (TopicClassService.Save(entity)) { string returnPath = System.Web.HttpContext.Current.Request.Path; //生成当期及后期数据走势图和遗漏数据 if (Action == "Add") { Logs("添加标题类型", string.Format("添加标题类型[Cid={0}]", entity.Cid)); ShowMessageBox("提示:添加成功!", returnPath + "?authPage=TopicList"); } if (Action == "Modify") { Logs("修改区域", string.Format("修改区域[Cid={0}]", entity.Cid)); ShowMessageBox("提示:修改成功!", returnPath + "?authPage=TopicList"); } } else { ShowMessageBox("提示:操作失败!"); } } //重置 protected void btnClear_Click(object sender, EventArgs e) { txtName.Text = string.Empty; txtcid.Text = string.Empty; ddlParent.SelectedIndex = 0; } } }