/// <summary> /// 更新一条数据 /// </summary> public void Update(ROYcms.Sys.Model.ROYcms_product model) { // //级联更新 删除以前的分类关联 新建一个分类关联 // ROYcms.Sys.BLL.ROYcms_Class_News ROYcms_Class_product_bll = new ROYcms.Sys.BLL.ROYcms_Class_News(); ROYcms.Sys.Model.ROYcms_Class_News ROYcms_Class_product_model = new ROYcms.Sys.Model.ROYcms_Class_News(); ROYcms.Sys.BLL.ROYcms_class ROYcms_Class_bll = new ROYcms.Sys.BLL.ROYcms_class(); ROYcms.Sys.Model.ROYcms_class ROYcms_Class_model = ROYcms_Class_bll._GetModel(model.classname.ToString()); //删除 ROYcms_Class_product_bll.Delete(" (news_id=" + model.bh + ") AND (Class=" + GetClassName(model.bh) + ") "); //添加 ROYcms_Class_product_model.news_id = model.bh; ROYcms_Class_product_model.Class = Convert.ToInt32(model.classname); ROYcms_Class_product_model.class_id = ROYcms_Class_model.ClassId; ROYcms_Class_product_model.class_list = ROYcms_Class_model.ClassList; ROYcms_Class_product_model.Time = DateTime.Now; ROYcms_Class_product_model.GUID = model.GUID; ROYcms_Class_product_bll.Add(ROYcms_Class_product_model); dal.Update(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(ROYcms.Sys.Model.ROYcms_product model) { int news_id = dal.Add(model); // //级联添加 // if (news_id != 1) { ROYcms.Sys.BLL.ROYcms_Class_News ROYcms_Class_product_bll = new ROYcms.Sys.BLL.ROYcms_Class_News(); ROYcms.Sys.Model.ROYcms_Class_News ROYcms_Class_product_model = new ROYcms.Sys.Model.ROYcms_Class_News(); ROYcms.Sys.BLL.ROYcms_class ROYcms_Class_bll = new ROYcms.Sys.BLL.ROYcms_class(); ROYcms.Sys.Model.ROYcms_class ROYcms_Class_model = ROYcms_Class_bll._GetModel(model.classname.ToString()); ROYcms_Class_product_model.news_id = news_id; ROYcms_Class_product_model.Class = Convert.ToInt32(model.classname); ROYcms_Class_product_model.class_id = ROYcms_Class_model.ClassId; ROYcms_Class_product_model.class_list = ROYcms_Class_model.ClassList; ROYcms_Class_product_model.Time = DateTime.Now; ROYcms_Class_product_model.GUID = model.GUID; ROYcms_Class_product_bll.Add(ROYcms_Class_product_model); } return(news_id); }
/// <summary> /// 得到一个对象实体 根据ID /// </summary> public ROYcms.Sys.Model.ROYcms_class _GetModel(string Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 "); strSql.Append(" Id,ClassId,ClassName,ClassList,ClassPre,ClassTj,ClassOrder,ClassKind,ContentType,FilePath,ListType,GoType,DefaultFile,ColumnsType,WebsiteUrl,TemplateIndex,TemplateList,TemplateShow,ListeRules,ShowRules,keyword,Description,contents "); strSql.Append(" from " + PubConstant.date_prefix + "class "); strSql.Append(" where Id=" + Id + " "); ROYcms.Sys.Model.ROYcms_class model = new ROYcms.Sys.Model.ROYcms_class(); DataSet ds = ROYcms.DB.DbHelpers.GetDataSet(strSql.ToString()); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Id"].ToString() != "") { model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString()); } model.ClassId = ds.Tables[0].Rows[0]["ClassId"].ToString(); model.ClassName = ds.Tables[0].Rows[0]["ClassName"].ToString(); model.ClassList = ds.Tables[0].Rows[0]["ClassList"].ToString(); model.ClassPre = ds.Tables[0].Rows[0]["ClassPre"].ToString(); if (ds.Tables[0].Rows[0]["ClassTj"].ToString() != "") { model.ClassTj = int.Parse(ds.Tables[0].Rows[0]["ClassTj"].ToString()); } if (ds.Tables[0].Rows[0]["ClassOrder"].ToString() != "") { model.ClassOrder = int.Parse(ds.Tables[0].Rows[0]["ClassOrder"].ToString()); } if (ds.Tables[0].Rows[0]["ClassKind"].ToString() != "") { model.ClassKind = int.Parse(ds.Tables[0].Rows[0]["ClassKind"].ToString()); } if (ds.Tables[0].Rows[0]["ContentType"].ToString() != "") { model.ContentType = int.Parse(ds.Tables[0].Rows[0]["ContentType"].ToString()); } model.FilePath = ds.Tables[0].Rows[0]["FilePath"].ToString(); if (ds.Tables[0].Rows[0]["ListType"].ToString() != "") { model.ListType = int.Parse(ds.Tables[0].Rows[0]["ListType"].ToString()); } if (ds.Tables[0].Rows[0]["GoType"].ToString() != "") { model.GoType = int.Parse(ds.Tables[0].Rows[0]["GoType"].ToString()); } model.DefaultFile = ds.Tables[0].Rows[0]["DefaultFile"].ToString(); model.ColumnsType = int.Parse(ds.Tables[0].Rows[0]["ColumnsType"].ToString()); model.WebsiteUrl = ds.Tables[0].Rows[0]["WebsiteUrl"].ToString(); model.TemplateIndex = ds.Tables[0].Rows[0]["TemplateIndex"].ToString(); model.TemplateList = ds.Tables[0].Rows[0]["TemplateList"].ToString(); model.TemplateShow = ds.Tables[0].Rows[0]["TemplateShow"].ToString(); model.ListeRules = ds.Tables[0].Rows[0]["ListeRules"].ToString(); model.ShowRules = ds.Tables[0].Rows[0]["ShowRules"].ToString(); model.keyword = ds.Tables[0].Rows[0]["keyword"].ToString(); model.Description = ds.Tables[0].Rows[0]["Description"].ToString(); model.contents = ds.Tables[0].Rows[0]["contents"].ToString(); return(model); } else { return(null); } }
/// <summary> /// 编辑一个菜单项 /// </summary> /// <param name="ClassId"></param> /// <param name="ClassName"></param> /// <param name="ClassList"></param> /// <param name="ClassPre"></param> /// <param name="ClassTj"></param> /// <returns></returns> public bool ClassUpdate(ROYcms.Sys.Model.ROYcms_class model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update " + PubConstant.date_prefix + "class set "); strSql.Append("ClassId=@ClassId,"); strSql.Append("ClassName=@ClassName,"); strSql.Append("ClassList=@ClassList,"); strSql.Append("ClassPre=@ClassPre,"); strSql.Append("ClassTj=@ClassTj,"); strSql.Append("ClassOrder=@ClassOrder,"); strSql.Append("ContentType=@ContentType,"); strSql.Append("FilePath=@FilePath,"); strSql.Append("ListType=@ListType,"); strSql.Append("GoType=@GoType,"); strSql.Append("DefaultFile=@DefaultFile,"); strSql.Append("ColumnsType=@ColumnsType,"); strSql.Append("WebsiteUrl=@WebsiteUrl,"); strSql.Append("TemplateIndex=@TemplateIndex,"); strSql.Append("TemplateList=@TemplateList,"); strSql.Append("TemplateShow=@TemplateShow,"); strSql.Append("ListeRules=@ListeRules,"); strSql.Append("ShowRules=@ShowRules,"); strSql.Append("keyword=@keyword,"); strSql.Append("Description=@Description,"); strSql.Append("contents=@contents"); strSql.Append(" where Id=@Id "); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4), new SqlParameter("@ClassId", SqlDbType.NVarChar, 30), new SqlParameter("@ClassName", SqlDbType.NVarChar, 50), new SqlParameter("@ClassList", SqlDbType.NVarChar, 300), new SqlParameter("@ClassPre", SqlDbType.NVarChar, 50), new SqlParameter("@ClassTj", SqlDbType.Int, 4), new SqlParameter("@ClassOrder", SqlDbType.Int, 4), new SqlParameter("@ClassKind", SqlDbType.Int, 4), new SqlParameter("@ContentType", SqlDbType.Int, 4), new SqlParameter("@FilePath", SqlDbType.NVarChar, 200), new SqlParameter("@ListType", SqlDbType.Int, 4), new SqlParameter("@GoType", SqlDbType.Int, 4), new SqlParameter("@DefaultFile", SqlDbType.NVarChar, 50), new SqlParameter("@ColumnsType", SqlDbType.NVarChar, 50), new SqlParameter("@WebsiteUrl", SqlDbType.NVarChar, 50), new SqlParameter("@TemplateIndex", SqlDbType.NVarChar, 50), new SqlParameter("@TemplateList", SqlDbType.NVarChar, 50), new SqlParameter("@TemplateShow", SqlDbType.NVarChar, 50), new SqlParameter("@ListeRules", SqlDbType.NVarChar, 50), new SqlParameter("@ShowRules", SqlDbType.NVarChar, 50), new SqlParameter("@keyword", SqlDbType.NVarChar, 100), new SqlParameter("@Description", SqlDbType.NVarChar, 100), new SqlParameter("@contents", SqlDbType.Text) }; parameters[0].Value = model.Id; parameters[1].Value = model.ClassId; parameters[2].Value = model.ClassName; parameters[3].Value = model.ClassList; parameters[4].Value = model.ClassPre; parameters[5].Value = model.ClassTj; parameters[6].Value = model.ClassOrder; parameters[7].Value = model.ClassKind; parameters[8].Value = model.ContentType; parameters[9].Value = model.FilePath; parameters[10].Value = model.ListType; parameters[11].Value = model.GoType; parameters[12].Value = model.DefaultFile; parameters[13].Value = model.ColumnsType; parameters[14].Value = model.WebsiteUrl; parameters[15].Value = model.TemplateIndex; parameters[16].Value = model.TemplateList; parameters[17].Value = model.TemplateShow; parameters[18].Value = model.ListeRules; parameters[19].Value = model.ShowRules; parameters[20].Value = model.keyword; parameters[21].Value = model.Description; parameters[22].Value = model.contents; //同步更新子菜单项 DataSet ds = this.GetSubClassList(model.ClassId); if (ds.Tables[0].Rows.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { string SubClassList = model.ClassList + dr["ClassId"].ToString().Trim() + ","; model.ClassId = dr["ClassId"].ToString().Trim(); model.ClassName = dr["ClassName"].ToString().Trim(); model.ClassList = SubClassList.ToString().Trim(); model.ClassPre = model.ClassId; model.ClassTj = model.ClassTj + 1; model.ClassOrder = Convert.ToInt32(dr["ClassOrder"].ToString()); model.ClassKind = Convert.ToInt32(dr["ClassKind"].ToString()); model.ContentType = Convert.ToInt32(dr["ContentType"].ToString()); model.FilePath = dr["FilePath"].ToString(); model.ListType = Convert.ToInt32(dr["ListType"].ToString()); model.GoType = Convert.ToInt32(dr["GoType"].ToString()); model.DefaultFile = dr["DefaultFile"].ToString(); model.ColumnsType = Convert.ToInt32(dr["ColumnsType"].ToString()); model.WebsiteUrl = dr["WebsiteUrl"].ToString(); model.TemplateIndex = dr["TemplateIndex"].ToString(); model.TemplateList = dr["TemplateList"].ToString(); model.TemplateShow = dr["TemplateShow"].ToString(); model.ListeRules = dr["ListeRules"].ToString(); model.ShowRules = dr["ShowRules"].ToString(); model.keyword = dr["keyword"].ToString(); model.Description = dr["Description"].ToString(); model.contents = dr["contents"].ToString(); ClassUpdate(model); } } return(ROYcms.DB.DbHelpers.NonQuery(strSql.ToString(), parameters) > 0); }
/// <summary> /// 添加一个菜单项 /// </summary> /// <param name="ClassId"></param> /// <param name="ClassName"></param> /// <param name="ClassList"></param> /// <param name="ClassPre"></param> /// <param name="ClassTj"></param> /// <returns></returns> public bool ClassAdd(ROYcms.Sys.Model.ROYcms_class model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into " + PubConstant.date_prefix + "class("); strSql.Append("ClassId,ClassName,ClassList,ClassPre,ClassTj,ClassOrder,ClassKind,ContentType,FilePath,ListType,GoType,DefaultFile,ColumnsType,WebsiteUrl,TemplateIndex,TemplateList,TemplateShow,ListeRules,ShowRules,keyword,Description,contents)"); strSql.Append(" values ("); strSql.Append("@ClassId,@ClassName,@ClassList,@ClassPre,@ClassTj,@ClassOrder,@ClassKind,@ContentType,@FilePath,@ListType,@GoType,@DefaultFile,@ColumnsType,@WebsiteUrl,@TemplateIndex,@TemplateList,@TemplateShow,@ListeRules,@ShowRules,@keyword,@Description,@contents)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@ClassId", SqlDbType.NVarChar, 30), new SqlParameter("@ClassName", SqlDbType.NVarChar, 50), new SqlParameter("@ClassList", SqlDbType.NVarChar, 300), new SqlParameter("@ClassPre", SqlDbType.NVarChar, 50), new SqlParameter("@ClassTj", SqlDbType.Int, 4), new SqlParameter("@ClassOrder", SqlDbType.Int, 4), new SqlParameter("@ClassKind", SqlDbType.Int, 4), new SqlParameter("@ContentType", SqlDbType.Int, 4), new SqlParameter("@FilePath", SqlDbType.NVarChar, 200), new SqlParameter("@ListType", SqlDbType.Int, 4), new SqlParameter("@GoType", SqlDbType.Int, 4), new SqlParameter("@DefaultFile", SqlDbType.NVarChar, 50), new SqlParameter("@ColumnsType", SqlDbType.NVarChar, 50), new SqlParameter("@WebsiteUrl", SqlDbType.NVarChar, 50), new SqlParameter("@TemplateIndex", SqlDbType.NVarChar, 50), new SqlParameter("@TemplateList", SqlDbType.NVarChar, 50), new SqlParameter("@TemplateShow", SqlDbType.NVarChar, 50), new SqlParameter("@ListeRules", SqlDbType.NVarChar, 50), new SqlParameter("@ShowRules", SqlDbType.NVarChar, 50), new SqlParameter("@keyword", SqlDbType.NVarChar, 100), new SqlParameter("@Description", SqlDbType.NVarChar, 100), new SqlParameter("@contents", SqlDbType.Text) }; parameters[0].Value = model.ClassId; parameters[1].Value = model.ClassName; parameters[2].Value = model.ClassList; parameters[3].Value = model.ClassPre; parameters[4].Value = model.ClassTj; parameters[5].Value = model.ClassOrder; parameters[6].Value = model.ClassKind; parameters[7].Value = model.ContentType; parameters[8].Value = model.FilePath; parameters[9].Value = model.ListType; parameters[10].Value = model.GoType; parameters[11].Value = model.DefaultFile; parameters[12].Value = model.ColumnsType; parameters[13].Value = model.WebsiteUrl; parameters[14].Value = model.TemplateIndex; parameters[15].Value = model.TemplateList; parameters[16].Value = model.TemplateShow; parameters[17].Value = model.ListeRules; parameters[18].Value = model.ShowRules; parameters[19].Value = model.keyword; parameters[20].Value = model.Description; parameters[21].Value = model.contents; object obj = ROYcms.DB.DbHelpers.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(false); } else { return(true); } }
/// <summary> /// loop标签的匹配替换 /// </summary> /// <param name="template">模板内容</param> public string LoopTag(string template) { string Attributes = ""; string Text = ""; string AllText = ""; Regex r = new Regex(@"(\[SG:loop\s+(?<attributes>[^\]]*?)\](?<text>[\s\S]*?)\[/SG:loop\])", RegexOptions.Compiled | RegexOptions.IgnoreCase); foreach (Match m in r.Matches(template)) { Attributes = m.Groups["attributes"].ToString(); //循环属性集 Text = m.Groups["text"].ToString(); //循环的内容不包含SG:Loop AllText = m.Groups[0].Value.ToString(); //整个匹配的内容包含SG:Loop #region 取得相关属性 string NewsCount = null; //调用数量 string TitleNum = null; //新闻标题的显示字符数量 string ding = null; string tuijian = null; string NewsType = null; //调用新闻的类型 //string Templet = null; // 模板ID string SQL = null; NewsCount = TagVal(Attributes, "NewsCount"); if (NewsCount == null) { NewsCount = "15"; } TitleNum = TagVal(Attributes, "TitleNum"); if (TitleNum == null) { TitleNum = "100"; } ding = TagVal(Attributes, "ding"); if (ding == null) { ding = "false"; } tuijian = TagVal(Attributes, "tuijian"); if (tuijian == null) { tuijian = "false"; } NewsType = TagVal(Attributes, "NewsType"); if (NewsType == null) { NewsType = "0"; } SQL = TagVal(Attributes, "SQL"); #endregion #region 构造 查询SQL语句 //SQL语句拼接 string strWher = ""; StringBuilder strSql = new StringBuilder(); if (SQL == null) { strWher = "classname='" + NewsType + "'"; strSql.Append("select top "); strSql.Append(NewsCount); strSql.Append(" * from [ROYcms_news] where "); strSql.Append(strWher); strSql.Append(" AND switchs='0'"); if (ding == "true") { strSql.Append(" AND ding='0'"); } if (tuijian == "true") { strSql.Append(" AND tuijian='0'"); } strSql.Append(" order by switchs,bh DESC"); } else { strSql.Append(SQL); } #endregion #region 对循环的内容进行替换 ROYcms_class_Model = ROYcms_class_Bll.GetModel(ROYcms_class_Bll.GetClassId(Convert.ToInt32(NewsType))); string content = ""; DataSet dt = Bll.GetDataSet(strSql.ToString()); if (dt.Tables[0].Rows.Count > 0) { int rowsCount = dt.Tables[0].Rows.Count; for (int n = 0; n < rowsCount; n++) { string str = Text; string T_ShowPath = (ROYcms_class_Model.ShowRules == null ? "" : ROYcms_class_Model.ShowRules); str = Replace(str, @"\[SG:Title\]", ROYcms.Common.input.GetSubString(dt.Tables[0].Rows[n]["title"].ToString(), Convert.ToInt32(TitleNum))); str = Replace(str, @"\[SG:_Title\]", dt.Tables[0].Rows[n]["title"].ToString()); str = Replace(str, @"\[SG:Id\]", dt.Tables[0].Rows[n]["bh"].ToString()); str = Replace(str, @"\[SG:Url\]", dt.Tables[0].Rows[n]["url"].ToString()); T_ShowPath = T_ShowPath.Replace("{yyyy}", Convert.ToDateTime(dt.Tables[0].Rows[n]["time"]).ToString("yyyy")); T_ShowPath = T_ShowPath.Replace("{MM}", Convert.ToDateTime(dt.Tables[0].Rows[n]["time"]).ToString("MM")); T_ShowPath = T_ShowPath.Replace("{dd}", Convert.ToDateTime(dt.Tables[0].Rows[n]["time"]).ToString("dd")); T_ShowPath = T_ShowPath.Replace("{id}", dt.Tables[0].Rows[n]["bh"].ToString()); str = Replace(str, @"\[SG:Link\]", T_ShowPath); str = Replace(str, @"\[SG:Pic\]", dt.Tables[0].Rows[n]["pic"].ToString()); str = Replace(str, @"\[SG:Zhaiyao\]", dt.Tables[0].Rows[n]["zhaiyao"].ToString()); str = Replace(str, @"\[SG:Keyword\]", dt.Tables[0].Rows[n]["keyword"].ToString()); str = Replace(str, @"\[SG:classname\]", new ROYcms.Sys.BLL.ROYcms_class().GetClassTitle(Convert.ToInt32(dt.Tables[0].Rows[n]["classname"].ToString()))); str = Replace(str, @"\[SG:Content\]", dt.Tables[0].Rows[n]["contents"].ToString()); str = Replace(str, @"\[SG:Infor\]", dt.Tables[0].Rows[n]["infor"].ToString()); str = Replace(str, @"\[SG:Author\]", dt.Tables[0].Rows[n]["author"].ToString()); str = Replace(str, @"\[SG:Tag\]", dt.Tables[0].Rows[n]["tag"].ToString()); str = Replace(str, @"\[SG:Dig\]", dt.Tables[0].Rows[n]["dig"].ToString()); str = Replace(str, @"\[SG:Hits\]", dt.Tables[0].Rows[n]["hits"].ToString()); str = Replace(str, @"\[SG:Time\]", dt.Tables[0].Rows[n]["time"].ToString()); str = Replace(str, @"\[SG:Year\]", Convert.ToDateTime(dt.Tables[0].Rows[n]["time"]).Date.Year.ToString()); str = Replace(str, @"\[SG:Month\]", Convert.ToDateTime(dt.Tables[0].Rows[n]["time"]).Date.Month.ToString()); str = Replace(str, @"\[SG:Day\]", Convert.ToDateTime(dt.Tables[0].Rows[n]["time"]).Date.Day.ToString()); content += str; } } else { content = ""; } #endregion template = template.Replace(AllText, content); } return(template); }