protected void Btn_Submit_Click(object sender, EventArgs e) { int updateStatus = 0;//更新是否成功 Arc_Class modelClass = GetClassModel(); #region 数据验证 if (modelClass.ClassName.Trim() == "") { Message.Dialog("操作失败!栏目名称不能为空。", "-1", MessageIcon.Stop, 0); } if (bllClass.ExistsClassName(CID, modelClass.ClassName)) { Message.Dialog("操作失败!该栏目已经存在。", "-1", MessageIcon.Stop, 0); } #endregion 数据验证 if (CID > 0) {//修改栏目 try { updateStatus = bllClass.Update(modelClass); } catch { Message.Dialog("更新栏目失败!更新栏目出现未知错误。", "-1", MessageIcon.Error, 0); } if (updateStatus > 0) { Message.Dialog("更新栏目成功!", "Class_list.aspx", MessageIcon.Success, 0); } else { Message.Dialog("更新栏目失败!请检查数据是否完整。", "-1", MessageIcon.Error, 0); } } else {//添加栏目 try { updateStatus = bllClass.Add(modelClass); } catch { Message.Dialog("添加栏目失败!添加栏目出现未知次错误。", "-1", MessageIcon.Error, 0); } if (updateStatus > 0) { Message.Dialog("添加栏目成功!", "Class_list.aspx", MessageIcon.Success, 0); } else { Message.Dialog("添加栏目失败!请检查数据是否完整。", "-1", MessageIcon.Error, 0); } } }
/// <summary> /// 获取当前类别的父类别集合 /// </summary> /// <param name="CID">栏目编号</param> /// <returns>栏目集合</returns> public List <Arc_Class> GetParentClassList(int CID) { string sql = "SELECT CID,ClassName,Relation,ParentID From DT_Arc_Class WHERE CID=@CID "; SqlParameter[] cmdParms = { AddInParameter("@CID", SqlDbType.Int, CID) }; Arc_Class model = new Arc_Class(); using (SqlDataReader reader = dbHelper.ExecuteReader(CommandType.Text, sql, cmdParms)) { if (reader.HasRows) { model = DataReaderToModel <Arc_Class>(reader); } } if (!string.IsNullOrEmpty(model.Relation)) { List <Arc_Class> list = new List <Arc_Class>(); if (model.ParentID > 0) { model.Relation = model.Relation.Replace(".0.", ""); if (model.Relation.IndexOf(".") != -1) { model.Relation = model.Relation.Trim().Substring(0, model.Relation.Trim().Length - 1); StringBuilder strSql = new StringBuilder(); strSql.Append(" SELECT CID,ClassName,ClassDomain,ClassPath From DT_Arc_Class "); strSql.Append(" WHERE "); strSql.AppendFormat(" CID IN ({0}) ", model.Relation); strSql.Append(" ORDER BY LEN(Relation) ASC "); using (SqlDataReader readerList = dbHelper.ExecuteReader(CommandType.Text, strSql.ToString(), null)) { while (readerList.Read()) { list.Add(DataReaderToModel <Arc_Class>(readerList)); } } } } else { list.Add(model); } return(list); } return(null); }
/// <summary> /// 获取栏目实体,添加,修改 /// </summary> /// <returns>栏目实体</returns> private Arc_Class GetClassModel() { Arc_Class model = new Arc_Class(); model.CID = CID; model.ParentID = Convert.ToInt32(slt_ParentClassName.Value); model.Attribute = GetClassAttribute(); model.ClassName = txt_ClassName.Value; model.ClassEName = txt_ClassEName.Value.Trim(); model.ClassType = Convert.ToByte(slt_ClassType.Value.Trim()); model.ClassDomain = txt_ClassDomain.Value.Trim(); model.ClassPath = txt_ClassPath.Value.Trim(); model.IndexTemplet = txt_IndexTemplet.Value.Trim(); model.ListTemplet = txt_ListTemplet.Value.Trim(); model.ArchiveTemplet = txt_ArchiveTemplet.Value.Trim(); model.IndexRule = txt_IndexRule.Value.Trim(); model.ListRule = txt_ListRule.Value.Trim(); model.ArchiveRule = txt_ArchiveRule.Value.Trim(); model.ClassPage = Convert.ToByte(txt_ClassPage.Value.Trim()); model.Description = txt_Description.Value.Trim(); model.IsHidden = (byte)(chk_ISHiden.Checked ? 1 : 0); model.IsHtml = (byte)(chk_ISHtml.Checked ? 1 : 0); model.CheckLevel = Convert.ToByte(slt_CheckLevel.Value.Trim()); model.IsContribute = (byte)(chk_ISContribute.Checked ? 1 : 0); model.IsComment = (byte)(chk_ISComment.Checked ? 1 : 0); model.Readaccess = Convert.ToInt32(slt_Readaccess.Value.Trim()); model.SiteID = 1;//站点ID,默认1 model.AddDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); if (model.ParentID == 0) { model.Relation = "." + model.ParentID.ToString() + "."; } else { model.Relation = bllClass.GetRelation(model.ParentID) + model.ParentID + "."; } model.OrderID = Convert.ToInt32(txt_OrderID.Value.Trim()); model.ImgUrl = txt_ImgUrl.Value.Trim(); model.Keywords = txt_Keywords.Value.Trim(); model.CrossID = txt_CorssID.Value.Trim(); model.ClassContent = txt_Content.Value.Trim(); return(model); }
/// <summary> /// 添加一条栏目 /// </summary> /// <param name="model">栏目实体对象</param> /// <returns>返回影响行数</returns> public int Add(Arc_Class model) { StringBuilder strSql = new StringBuilder(); strSql.Append("INSERT INTO " + tablePrefix + "Arc_Class("); strSql.Append("ParentID,Attribute,ClassName,ClassEName,ClassType,ClassDomain,ClassPath,IndexTemplet,ListTemplet,ArchiveTemplet,IndexRule,ListRule,ArchiveRule,ClassPage,Description,IsHidden,IsHtml,CheckLevel,IsContribute,IsComment,Readaccess,SiteID,AddDate,Relation,OrderID,ImgUrl,Keywords,CrossID,ClassContent)"); strSql.Append(" VALUES ("); strSql.Append("@ParentID,@Attribute,@ClassName,@ClassEName,@ClassType,@ClassDomain,@ClassPath,@IndexTemplet,@ListTemplet,@ArchiveTemplet,@IndexRule,@ListRule,@ArchiveRule,@ClassPage,@Description,@IsHidden,@IsHtml,@CheckLevel,@IsContribute,@IsComment,@Readaccess,@SiteID,@AddDate,@Relation,@OrderID,@ImgUrl,@Keywords,@CrossID,@ClassContent)"); SqlParameter[] cmdParms = { AddInParameter("@ParentID", SqlDbType.Int, 4, model.ParentID), AddInParameter("@Attribute", SqlDbType.TinyInt, 1, model.Attribute), AddInParameter("@ClassName", SqlDbType.NVarChar, 100, model.ClassName), AddInParameter("@ClassEName", SqlDbType.VarChar, 50, model.ClassEName), AddInParameter("@ClassType", SqlDbType.TinyInt, 1, model.ClassType), AddInParameter("@ClassDomain", SqlDbType.VarChar, 255, model.ClassDomain), AddInParameter("@ClassPath", SqlDbType.VarChar, 255, model.ClassPath), AddInParameter("@IndexTemplet", SqlDbType.VarChar, 255, model.IndexTemplet), AddInParameter("@ListTemplet", SqlDbType.VarChar, 255, model.ListTemplet), AddInParameter("@ArchiveTemplet", SqlDbType.VarChar, 255, model.ArchiveTemplet), AddInParameter("@IndexRule", SqlDbType.VarChar, 255, model.IndexRule), AddInParameter("@ListRule", SqlDbType.VarChar, 255, model.ListRule), AddInParameter("@ArchiveRule", SqlDbType.VarChar, 255, model.ArchiveRule), AddInParameter("@ClassPage", SqlDbType.TinyInt, 1, model.ClassPage), AddInParameter("@Description", SqlDbType.NVarChar, 500, model.Description), AddInParameter("@IsHidden", SqlDbType.TinyInt, 1, model.IsHidden), AddInParameter("@IsHtml", SqlDbType.TinyInt, 1, model.IsHtml), AddInParameter("@CheckLevel", SqlDbType.TinyInt, 1, model.CheckLevel), AddInParameter("@IsContribute", SqlDbType.TinyInt, 1, model.IsContribute), AddInParameter("@IsComment", SqlDbType.TinyInt, 1, model.IsComment), AddInParameter("@Readaccess", SqlDbType.SmallInt, 2, model.Readaccess), AddInParameter("@SiteID", SqlDbType.TinyInt, 1, model.SiteID), AddInParameter("@AddDate", SqlDbType.DateTime, 8, model.AddDate), AddInParameter("@Relation", SqlDbType.VarChar, 100, model.Relation), AddInParameter("@OrderID", SqlDbType.SmallInt, 2, model.OrderID), AddInParameter("@ImgUrl", SqlDbType.VarChar, 255, model.ImgUrl), AddInParameter("@Keywords", SqlDbType.NVarChar, 200, model.Keywords), AddInParameter("@CrossID", SqlDbType.VarChar, 200, model.CrossID), AddInParameter("@ClassContent", SqlDbType.NVarChar, 8, model.ClassContent) }; return(dbHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms)); }
/// <summary> /// 更新,初始化页面数据 /// </summary> /// <param name="CID">栏目ID</param> private void SetPageData() { if (CID <= 0) { return; } Arc_Class model = bllClass.GetModel(CID); if (model != null) { slt_ParentClassName.SelectedIndex = slt_ParentClassName.Items.IndexOf(slt_ParentClassName.Items.FindByValue(model.CID.ToString())); SetClassAttribute(model.Attribute); txt_ClassName.Value = model.ClassName; txt_ClassEName.Value = model.ClassEName; slt_ClassType.Value = model.ClassType.ToString(); txt_ClassDomain.Value = model.ClassDomain; txt_ClassPath.Value = model.ClassPath; txt_IndexTemplet.Value = model.IndexTemplet; txt_ListTemplet.Value = model.ListTemplet; txt_ArchiveTemplet.Value = model.ArchiveTemplet; txt_IndexRule.Value = model.IndexRule; txt_ListRule.Value = model.ListRule; txt_ArchiveRule.Value = model.ArchiveRule; txt_ClassPage.Value = model.ClassPage.ToString(); txt_Description.Value = model.Description; chk_ISHiden.Checked = model.IsHidden == 1; chk_ISHtml.Checked = model.IsHtml == 1; slt_CheckLevel.Value = model.CheckLevel.ToString(); chk_ISContribute.Checked = model.IsContribute == 1; chk_ISComment.Checked = model.IsComment == 1; slt_Readaccess.Value = model.Readaccess.ToString(); txt_OrderID.Value = model.OrderID.ToString(); txt_ImgUrl.Value = model.ImgUrl; txt_Keywords.Value = model.Keywords; txt_CorssID.Value = model.CrossID; txt_Content.Value = model.ClassContent; } }
/// <summary> /// 由一行数据得到一个实体 /// </summary> /// <param name="dr">SqlDataReader对象</param> /// <returns>实体对象</returns> private Arc_Class GetModel(SqlDataReader dr) { Arc_Class model = new Arc_Class(); model.CID = dbHelper.GetInt(dr["CID"]); model.ParentID = dbHelper.GetInt(dr["ParentID"]); model.Attribute = dbHelper.GetByte(dr["Attribute"]); model.ClassName = dbHelper.GetString(dr["ClassName"]); model.ClassEName = dbHelper.GetString(dr["ClassEName"]); model.ClassType = dbHelper.GetByte(dr["ClassType"]); model.ClassDomain = dbHelper.GetString(dr["ClassDomain"]); model.ClassPath = dbHelper.GetString(dr["ClassPath"]); model.IndexTemplet = dbHelper.GetString(dr["IndexTemplet"]); model.ListTemplet = dbHelper.GetString(dr["ListTemplet"]); model.ArchiveTemplet = dbHelper.GetString(dr["ArchiveTemplet"]); model.IndexRule = dbHelper.GetString(dr["IndexRule"]); model.ListRule = dbHelper.GetString(dr["ListRule"]); model.ArchiveRule = dbHelper.GetString(dr["ArchiveRule"]); model.ClassPage = dbHelper.GetByte(dr["ClassPage"]); model.Description = dbHelper.GetString(dr["Description"]); model.IsHidden = dbHelper.GetByte(dr["IsHidden"]); model.IsHtml = dbHelper.GetByte(dr["IsHtml"]); model.CheckLevel = dbHelper.GetByte(dr["CheckLevel"]); model.IsContribute = dbHelper.GetByte(dr["IsContribute"]); model.IsComment = dbHelper.GetByte(dr["IsComment"]); model.Readaccess = dbHelper.GetInt16(dr["Readaccess"]); model.SiteID = dbHelper.GetByte(dr["SiteID"]); model.AddDate = dbHelper.GetDateTime(dr["AddDate"]); model.Relation = dbHelper.GetString(dr["Relation"]); model.OrderID = dbHelper.GetInt16(dr["OrderID"]); model.ImgUrl = dbHelper.GetString(dr["ImgUrl"]); model.Keywords = dbHelper.GetString(dr["Keywords"]); model.CrossID = dbHelper.GetString(dr["CrossID"]); model.ClassContent = dbHelper.GetString(dr["ClassContent"]); return(model); }
/// <summary> /// 初始化当前页面模板数据 /// </summary> protected void InitPageTemplate() { #region 获取文档内容 //获取要生成的栏目ID archiveID = Utils.GetQueryInt("ID"); if (archiveID < 0) { Message.Dialog("生成错误,生成静态页的文档ID为空!", "-1", MessageIcon.Warning); } //获取栏目类型 channelType = Utils.GetQueryInt("type"); if (channelType < 0) { ArcListBLL arclistBll = new ArcListBLL(); Message.Dialog("生成错误,请选择要生成的文档类型!", "-1", MessageIcon.Warning); } //获取生成文档当前页数,默认为第一页 pageIndex = Utils.GetQueryInt("page"); if (pageIndex < 0) { pageIndex = 1; } ArcListBLL arcBll = new ArcListBLL(); List <Archive> archiveInfo = arcBll.GetArchiveInfo(archiveID, channelType); if (archiveInfo.Count > 0) { channelID = archiveInfo[0].ClassID; } else { return; } #endregion #region 获取当前位置 ArchiveField gobal = new ArchiveField(); //获取栏目当前位置 classUrl = this.__CLASSURL.Value; position = this.__POSITION.Value; relation = this.__RELATION.Value; if (classUrl.Length == 0 || relation.Length == 0) { Arc_ClassBLL classBll = new Arc_ClassBLL(); Arc_Class classInfo = classBll.GetModel(channelID); classUrl = this.__CLASSURL.Value = classInfo.ClassPath; relation = this.__RELATION.Value = classInfo.Relation.TrimEnd('.').Replace('.', ','); } if (position.Length == 0) { Arc_ClassBLL classBll = new Arc_ClassBLL(); DataTable dt = classBll.GetThisPlace(relation); position += "<a href=\"/\">首页</a> » "; for (int i = 0; i < dt.Rows.Count; i++) { position += "<a href=\"" + dt.Rows[i]["ClassEName"] + "\">" + dt.Rows[i]["ClassName"] + "</a>"; if (i + 1 < dt.Rows.Count) { position += " » "; } } this.__POSITION.Value = gobal.Position = position; } #endregion #region 获取上一篇、下一篇链接 int count = archiveInfo.Count; for (int i = 1; i < count; i++) { if (archiveInfo[i] != null) { string temp = "<a href=\"" + archiveInfo[i].Url + "\">" + archiveInfo[i].Title + "</a>"; if (archiveInfo[i].ID < archiveID) { gobal.Prior = temp; } else { gobal.Next = temp; } } } #endregion #region 获取配置信息 SiteConfigInfo site = ConfigAccess.LoadConfig <SiteConfigInfo>("CFG_SITE"); #endregion this.Document.Variables.SetValue("field", archiveInfo[0]); this.Document.Variables.SetValue("gobal", gobal); this.Document.Variables.SetValue("site", site); }
/// <summary> /// 更新一个栏目 /// </summary> /// <param name="model">栏目实体对象</param> /// <returns>返回影响行数</returns> public int Update(Arc_Class model) { return(dal.Update(model)); }
/// <summary> /// 添加栏目 /// </summary> /// <param name="model">栏目实体对象</param> /// <returns>返回影响行数</returns> public int Add(Arc_Class model) { return(dal.Add(model)); }
/// <summary> /// 更新一个栏目 /// </summary> /// <param name="model">栏目实体</param> /// <returns>返回影响行数</returns> public int Update(Arc_Class model) { StringBuilder strSql = new StringBuilder(); strSql.Append("UPDATE " + tablePrefix + "Arc_Class SET "); strSql.Append("ParentID=@ParentID,"); strSql.Append("Attribute=@Attribute,"); strSql.Append("ClassName=@ClassName,"); strSql.Append("ClassEName=@ClassEName,"); strSql.Append("ClassType=@ClassType,"); strSql.Append("ClassDomain=@ClassDomain,"); strSql.Append("ClassPath=@ClassPath,"); strSql.Append("IndexTemplet=@IndexTemplet,"); strSql.Append("ListTemplet=@ListTemplet,"); strSql.Append("ArchiveTemplet=@ArchiveTemplet,"); strSql.Append("IndexRule=@IndexRule,"); strSql.Append("ListRule=@ListRule,"); strSql.Append("ArchiveRule=@ArchiveRule,"); strSql.Append("ClassPage=@ClassPage,"); strSql.Append("Description=@Description,"); strSql.Append("IsHidden=@IsHidden,"); strSql.Append("IsHtml=@IsHtml,"); strSql.Append("CheckLevel=@CheckLevel,"); strSql.Append("IsContribute=@IsContribute,"); strSql.Append("IsComment=@IsComment,"); strSql.Append("Readaccess=@Readaccess,"); strSql.Append("SiteID=@SiteID,"); strSql.Append("AddDate=@AddDate,"); strSql.Append("Relation=@Relation,"); strSql.Append("OrderID=@OrderID,"); strSql.Append("ImgUrl=@ImgUrl,"); strSql.Append("Keywords=@Keywords,"); strSql.Append("CrossID=@CrossID,"); strSql.Append("ClassContent=@ClassContent"); strSql.Append(" WHERE CID=@CID"); SqlParameter[] cmdParms = { AddInParameter("@ParentID", SqlDbType.Int, 4, model.ParentID), AddInParameter("@Attribute", SqlDbType.TinyInt, 1, model.Attribute), AddInParameter("@ClassName", SqlDbType.NVarChar, 100, model.ClassName), AddInParameter("@ClassEName", SqlDbType.VarChar, 50, model.ClassEName), AddInParameter("@ClassType", SqlDbType.TinyInt, 1, model.ClassType), AddInParameter("@ClassDomain", SqlDbType.VarChar, 255, model.ClassDomain), AddInParameter("@ClassPath", SqlDbType.VarChar, 255, model.ClassPath), AddInParameter("@IndexTemplet", SqlDbType.VarChar, 255, model.IndexTemplet), AddInParameter("@ListTemplet", SqlDbType.VarChar, 255, model.ListTemplet), AddInParameter("@ArchiveTemplet", SqlDbType.VarChar, 255, model.ArchiveTemplet), AddInParameter("@IndexRule", SqlDbType.VarChar, 255, model.IndexRule), AddInParameter("@ListRule", SqlDbType.VarChar, 255, model.ListRule), AddInParameter("@ArchiveRule", SqlDbType.VarChar, 255, model.ArchiveRule), AddInParameter("@ClassPage", SqlDbType.TinyInt, 1, model.ClassPage), AddInParameter("@Description", SqlDbType.NVarChar, 500, model.Description), AddInParameter("@IsHidden", SqlDbType.TinyInt, 1, model.IsHidden), AddInParameter("@IsHtml", SqlDbType.TinyInt, 1, model.IsHtml), AddInParameter("@CheckLevel", SqlDbType.TinyInt, 1, model.CheckLevel), AddInParameter("@IsContribute", SqlDbType.TinyInt, 1, model.IsContribute), AddInParameter("@IsComment", SqlDbType.TinyInt, 1, model.IsComment), AddInParameter("@Readaccess", SqlDbType.SmallInt, 2, model.Readaccess), AddInParameter("@SiteID", SqlDbType.TinyInt, 1, model.SiteID), AddInParameter("@AddDate", SqlDbType.DateTime, 8, model.AddDate), AddInParameter("@Relation", SqlDbType.VarChar, 100, model.Relation), AddInParameter("@OrderID", SqlDbType.SmallInt, 2, model.OrderID), AddInParameter("@ImgUrl", SqlDbType.VarChar, 255, model.ImgUrl), AddInParameter("@Keywords", SqlDbType.NVarChar, 200, model.Keywords), AddInParameter("@CrossID", SqlDbType.VarChar, 200, model.CrossID), AddInParameter("@ClassContent", SqlDbType.NVarChar, 8, model.ClassContent), AddInParameter("@CID", SqlDbType.Int, 4, model.CID) }; return(dbHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms)); }
/// <summary> /// 初始化当前页面模板数据 /// </summary> protected void InitPageTemplate() { //获取要生成的栏目ID channelID = Utils.GetQueryInt("ID"); if (channelID < 0) { Message.Dialog("生成错误,生成静态页的栏目ID为空!", "-1", MessageIcon.Warning); } //获取栏目类型 channelType = Utils.GetQueryString("type"); if (channelType.Length == 0) { ArcListBLL arclistBll = new ArcListBLL(); channelType = arclistBll.GetChannelType(channelID); } //获取记录总数 totalRecord = Utils.GetQueryInt("total"); if (totalRecord < 0) { ArcListBLL arclistBll = new ArcListBLL(); totalRecord = arclistBll.GetArcCount(channelID, channelType); } //获取生成栏目当前页数 pageIndex = Utils.GetQueryInt("page"); if (pageIndex < 0) { Message.Dialog("生成错误,生成静态页的当前页数为空!", "-1", MessageIcon.Warning); } //获取分页大小 pageSize = Utils.GetQueryInt("size"); //获取分页选项 pageItem = this.__PAGEITEM.Value; if (pageSize < 0 || pageItem.Length == 0) { //分页大小和分页选项从PageList标签中获取 ElementCollection <Tag> tags = this.Document.GetChildTagsByTagName("PageList"); foreach (Tag tag in tags) { pageSize = TypeConvert.ToInt32(tag.Attributes["PageSize"].Value); pageItem = tag.Attributes["Item"].Value.ToString(); } this.__PAGEITEM.Value = pageItem; } //获取栏目当前位置 classUrl = this.__CLASSURL.Value; listTemplet = this.__LISTTEMPLET.Value; indexRule = this.__INDEXRULE.Value; position = this.__POSITION.Value; relation = this.__RELATION.Value; if (classUrl.Length == 0 || listTemplet.Length == 0 || indexRule.Length == 0 || relation.Length == 0) { Arc_ClassBLL classBll = new Arc_ClassBLL(); Arc_Class classInfo = classBll.GetModel(channelID); classUrl = this.__CLASSURL.Value = classInfo.ClassPath; listTemplet = this.__LISTTEMPLET.Value = classInfo.ListTemplet; indexRule = this.__INDEXRULE.Value = classInfo.IndexRule; relation = this.__RELATION.Value = classInfo.Relation.TrimEnd('.').Replace('.', ','); } if (position.Length == 0) { Arc_ClassBLL classBll = new Arc_ClassBLL(); DataTable dt = classBll.GetThisPlace(relation); position += "<a href=\"/\">首页</a> » "; for (int i = 0; i < dt.Rows.Count; i++) { position += "<a href=\"" + dt.Rows[i]["ClassEName"] + "\">" + dt.Rows[i]["ClassName"] + "</a>"; if (i + 1 < dt.Rows.Count) { position += " » "; } } this.__POSITION.Value = position; } //设置自定义属性 PageListField field = new PageListField(); field.CurrentPage = pageIndex; field.TotalPage = PageSeting.GetPageCount(totalRecord, pageSize); field.TotalRecord = totalRecord; field.PageIndex = PageSeting.GetPageNum(pageIndex, field.TotalPage, 10, "createlist.aspx?id=10&page={0}", pageItem); field.Position = position; //gobal.PageIndex = gobal.PageIndex.Replace(string.Format("list/{0}/1/", channelID), "index.html"); this.Document.Variables.SetValue("field", field); }