public int Add(Rain.Model.channel model) { int siteNavId = new channel_site(this.databaseprefix).GetSiteNavId(model.site_id); if (siteNavId == 0) { return(0); } using (OleDbConnection oleDbConnection = new OleDbConnection(DbHelperOleDb.connectionString)) { oleDbConnection.Open(); using (OleDbTransaction trans = oleDbConnection.BeginTransaction()) { try { StringBuilder stringBuilder1 = new StringBuilder(); stringBuilder1.Append("insert into " + this.databaseprefix + "channel("); stringBuilder1.Append("site_id,[name],title,is_albums,is_attach,is_spec,sort_id)"); stringBuilder1.Append(" values ("); stringBuilder1.Append("@site_id,@name,@title,@is_albums,@is_attach,@is_spec,@sort_id)"); OleDbParameter[] oleDbParameterArray1 = new OleDbParameter[7] { new OleDbParameter("@site_id", OleDbType.Integer, 4), new OleDbParameter("@name", OleDbType.VarChar, 50), new OleDbParameter("@title", OleDbType.VarChar, 100), new OleDbParameter("@is_albums", OleDbType.Integer, 4), new OleDbParameter("@is_attach", OleDbType.Integer, 4), new OleDbParameter("@is_spec", OleDbType.Integer, 4), new OleDbParameter("@sort_id", OleDbType.Integer, 4) }; oleDbParameterArray1[0].Value = (object)model.site_id; oleDbParameterArray1[1].Value = (object)model.name; oleDbParameterArray1[2].Value = (object)model.title; oleDbParameterArray1[3].Value = (object)model.is_albums; oleDbParameterArray1[4].Value = (object)model.is_attach; oleDbParameterArray1[5].Value = (object)model.is_spec; oleDbParameterArray1[6].Value = (object)model.sort_id; DbHelperOleDb.ExecuteSql(oleDbConnection, trans, stringBuilder1.ToString(), oleDbParameterArray1); model.id = this.GetMaxId(oleDbConnection, trans); if (model.channel_fields != null) { foreach (channel_field channelField in model.channel_fields) { StringBuilder stringBuilder2 = new StringBuilder(); stringBuilder2.Append("insert into " + this.databaseprefix + "channel_field("); stringBuilder2.Append("channel_id,field_id)"); stringBuilder2.Append(" values ("); stringBuilder2.Append("@channel_id,@field_id)"); OleDbParameter[] oleDbParameterArray2 = new OleDbParameter[2] { new OleDbParameter("@channel_id", OleDbType.Integer, 4), new OleDbParameter("@field_id", OleDbType.Integer, 4) }; oleDbParameterArray2[0].Value = (object)model.id; oleDbParameterArray2[1].Value = (object)channelField.field_id; DbHelperOleDb.ExecuteSql(oleDbConnection, trans, stringBuilder2.ToString(), oleDbParameterArray2); } } StringBuilder stringBuilder3 = new StringBuilder(); stringBuilder3.Append("CREATE VIEW view_channel_" + model.name + " as"); stringBuilder3.Append(" SELECT " + this.databaseprefix + "article.*"); if (model.channel_fields != null) { foreach (channel_field channelField in model.channel_fields) { Rain.Model.article_attribute_field model1 = new article_attribute_field(this.databaseprefix).GetModel(channelField.field_id); if (model1 != null) { stringBuilder3.Append("," + this.databaseprefix + "article_attribute_value." + model1.name); } } } stringBuilder3.Append(" FROM " + this.databaseprefix + "article_attribute_value INNER JOIN"); stringBuilder3.Append(" " + this.databaseprefix + "article ON " + this.databaseprefix + "article_attribute_value.article_id = " + this.databaseprefix + "article.id"); stringBuilder3.Append(" WHERE " + this.databaseprefix + "article.channel_id=" + (object)model.id); DbHelperOleDb.ExecuteSql(oleDbConnection, trans, stringBuilder3.ToString()); int parent_id = new navigation(this.databaseprefix).Add(oleDbConnection, trans, siteNavId, "channel_" + model.name, model.title, "", model.sort_id, model.id, "Show"); new navigation(this.databaseprefix).Add(oleDbConnection, trans, parent_id, "channel_" + model.name + "_list", "内容管理", "article/article_list.aspx", 99, model.id, "Show,View,Add,Edit,Delete,Audit"); new navigation(this.databaseprefix).Add(oleDbConnection, trans, parent_id, "channel_" + model.name + "_category", "栏目类别", "article/category_list.aspx", 100, model.id, "Show,View,Add,Edit,Delete"); new navigation(this.databaseprefix).Add(oleDbConnection, trans, parent_id, "channel_" + model.name + "_comment", "评论管理", "article/comment_list.aspx", 101, model.id, "Show,View,Delete,Reply"); trans.Commit(); } catch { trans.Rollback(); return(0); } } } return(model.id); }
public bool Update(Rain.Model.channel model) { Rain.Model.channel model1 = this.GetModel(model.id); int siteNavId = new channel_site(this.databaseprefix).GetSiteNavId(model.site_id); if (siteNavId == 0) { return(false); } using (OleDbConnection oleDbConnection = new OleDbConnection(DbHelperOleDb.connectionString)) { oleDbConnection.Open(); using (OleDbTransaction trans = oleDbConnection.BeginTransaction()) { try { StringBuilder stringBuilder1 = new StringBuilder(); stringBuilder1.Append("update " + this.databaseprefix + "channel set "); stringBuilder1.Append("site_id=@site_id,"); stringBuilder1.Append("[name]=@name,"); stringBuilder1.Append("title=@title,"); stringBuilder1.Append("is_albums=@is_albums,"); stringBuilder1.Append("is_attach=@is_attach,"); stringBuilder1.Append("is_spec=@is_spec,"); stringBuilder1.Append("sort_id=@sort_id"); stringBuilder1.Append(" where id=@id "); OleDbParameter[] oleDbParameterArray1 = new OleDbParameter[8] { new OleDbParameter("@site_id", OleDbType.Integer, 4), new OleDbParameter("@name", OleDbType.VarChar, 50), new OleDbParameter("@title", OleDbType.VarChar, 100), new OleDbParameter("@is_albums", OleDbType.Integer, 4), new OleDbParameter("@is_attach", OleDbType.Integer, 4), new OleDbParameter("@is_spec", OleDbType.Integer, 4), new OleDbParameter("@sort_id", OleDbType.Integer, 4), new OleDbParameter("@id", OleDbType.Integer, 4) }; oleDbParameterArray1[0].Value = (object)model.site_id; oleDbParameterArray1[1].Value = (object)model.name; oleDbParameterArray1[2].Value = (object)model.title; oleDbParameterArray1[3].Value = (object)model.is_albums; oleDbParameterArray1[4].Value = (object)model.is_attach; oleDbParameterArray1[5].Value = (object)model.is_spec; oleDbParameterArray1[6].Value = (object)model.sort_id; oleDbParameterArray1[7].Value = (object)model.id; DbHelperOleDb.ExecuteSql(oleDbConnection, trans, stringBuilder1.ToString(), oleDbParameterArray1); this.FieldDelete(oleDbConnection, trans, model.channel_fields, model.id); if (model.channel_fields != null) { using (List <channel_field> .Enumerator enumerator = model.channel_fields.GetEnumerator()) { while (enumerator.MoveNext()) { channel_field modelt = enumerator.Current; StringBuilder stringBuilder2 = new StringBuilder(); channel_field channelField = (channel_field)null; if (model1.channel_fields != null) { channelField = model1.channel_fields.Find((Predicate <channel_field>)(p => p.field_id == modelt.field_id)); } if (channelField == null) { stringBuilder2.Append("insert into " + this.databaseprefix + "channel_field("); stringBuilder2.Append("channel_id,field_id)"); stringBuilder2.Append(" values ("); stringBuilder2.Append("@channel_id,@field_id)"); OleDbParameter[] oleDbParameterArray2 = new OleDbParameter[2] { new OleDbParameter("@channel_id", OleDbType.Integer, 4), new OleDbParameter("@field_id", OleDbType.Integer, 4) }; oleDbParameterArray2[0].Value = (object)modelt.channel_id; oleDbParameterArray2[1].Value = (object)modelt.field_id; DbHelperOleDb.ExecuteSql(oleDbConnection, trans, stringBuilder2.ToString(), oleDbParameterArray2); } } } } this.RehabChannelViews(oleDbConnection, trans, model, model1.name); new navigation(this.databaseprefix).Update(oleDbConnection, trans, "channel_" + model1.name, siteNavId, "channel_" + model.name, model.title, model.sort_id); new navigation(this.databaseprefix).Update(oleDbConnection, trans, "channel_" + model1.name + "_list", "channel_" + model.name + "_list"); new navigation(this.databaseprefix).Update(oleDbConnection, trans, "channel_" + model1.name + "_category", "channel_" + model.name + "_category"); new navigation(this.databaseprefix).Update(oleDbConnection, trans, "channel_" + model1.name + "_comment", "channel_" + model.name + "_comment"); trans.Commit(); } catch { trans.Rollback(); return(false); } } } return(true); }