コード例 #1
0
ファイル: site_channel.cs プロジェクト: ganmkTrue/DTCMS_MVC
        /// <summary>
        /// 删除已移除的扩展字段及频道数据表列
        /// </summary>
        private void FieldDelete(IDbConnection conn, IDbTransaction trans, Model.site_channel newModel, Model.site_channel oldModel)
        {
            if (oldModel.channel_fields == null)
            {
                return;
            }
            string fieldIds = string.Empty;

            foreach (Model.site_channel_field modelt in oldModel.channel_fields)
            {
                //查找对应的字段ID,不在旧实体则删除
                if (newModel.channel_fields.Find(p => p.field_id == modelt.field_id) == null)
                {
                    //记住要删除的字段ID
                    fieldIds += modelt.field_id + ",";
                    //删除该旧字段
                    WriteDataBase.Execute(conn, trans, "delete from " + databaseprefix + "site_channel_field where channel_id=" + newModel.id + " and field_id=" + modelt.field_id);
                }
            }
            //删除频道数据表列
            if (fieldIds.Length > 0)
            {
                List <Model.article_attribute_field> field = new List <Model.article_attribute_field>();
                field = WriteDataBase.Query <Model.article_attribute_field>(conn, trans, Sql.Builder.Select("id,name").From(databaseprefix + "article_attribute_field").Where("id in(" + fieldIds.TrimEnd(',') + ")")).ToList();
                foreach (var dr in field)
                {
                    //删除频道数据表列
                    ReadDataBase.Execute(conn, trans, "alter table " + databaseprefix + DTKeys.TABLE_CHANNEL_ARTICLE + oldModel.name + " drop column " + dr.name);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 根据条件修改
        /// </summary>
        /// <param name="sqlwhere">条件</param>
        /// <param name="files">字段</param>
        /// <returns>bool</returns>
        public bool UpdateFile(string sqlwhere, string files)
        {
            bool isSuccess = true;

            try
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("update " + TableName + " set " + files + " ");
                if (sqlwhere.Trim() != "")
                {
                    strSql.Append(" where " + sqlwhere);
                }
                isSuccess = ReadDataBase.Execute(strSql.ToString()) > 0;
            }
            catch (Exception e)
            {
                isSuccess = false;
            }
            finally
            {
                ReadDataBase.CloseSharedConnection();
            }

            return(isSuccess);
        }
コード例 #3
0
ファイル: site_channel.cs プロジェクト: ganmkTrue/DTCMS_MVC
 /// <summary>
 /// 编辑扩展字段及频道数据表
 /// </summary>
 private void FieldUpdate(IDbConnection conn, IDbTransaction trans, Model.site_channel newModel, Model.site_channel oldModel)
 {
     if (newModel.channel_fields != null)
     {
         string newFieldIds = string.Empty; //用来存储新增的字段ID
         //添加扩展字段
         StringBuilder strSql1;
         foreach (Model.site_channel_field modelt in newModel.channel_fields)
         {
             strSql1 = new StringBuilder();
             Model.site_channel_field fieldModel = null;
             if (oldModel.channel_fields != null)
             {
                 fieldModel = oldModel.channel_fields.Find(p => p.field_id == modelt.field_id); //查找是否已经存在
             }
             if (fieldModel == null)                                                            //如果不存在则添加
             {
                 newFieldIds += modelt.field_id + ",";                                          //以逗号分隔开存储
                 strSql1.Append("insert into " + databaseprefix + "site_channel_field(");
                 strSql1.Append("channel_id,field_id)");
                 strSql1.Append(" values (");
                 strSql1.Append("@0,@1)");
                 WriteDataBase.Execute(conn, trans, strSql1.ToString(), modelt.channel_id, modelt.field_id);
             }
         }
         //添加频道数据表列
         if (newFieldIds.Length > 0)
         {
             List <Model.article_attribute_field> field = new List <Model.article_attribute_field>();
             field = WriteDataBase.Query <Model.article_attribute_field>(conn, trans, Sql.Builder.Select("id,name,data_type").From(databaseprefix + "article_attribute_field").Where("id in(" + newFieldIds.TrimEnd(',') + ")")).ToList();
             foreach (var dr in field)
             {
                 ReadDataBase.Execute(conn, trans, "alter table " + databaseprefix + DTKeys.TABLE_CHANNEL_ARTICLE + oldModel.name + " add " + dr.name + " " + dr.data_type);
                 //(!string.IsNullOrEmpty(dr.default_value) ? "DEFAULT "+ dr.default_value : "")
             }
         }
     }
     //如果频道名称改变则需要更改数据表名
     if (newModel.name != oldModel.name)
     {
         ReadDataBase.Execute(conn, trans, "exec sp_rename '" + databaseprefix + DTKeys.TABLE_CHANNEL_ARTICLE + oldModel.name + "', '" + databaseprefix + DTKeys.TABLE_CHANNEL_ARTICLE + newModel.name + "'");
     }
 }
コード例 #4
0
 /// <summary>
 ///单独执行一条sql语句
 /// </summary>
 /// <param name="sql"></param>
 /// <param name="args"></param>
 /// <returns></returns>
 public int Execute(string sql, params object[] args)
 {
     return(ReadDataBase.Execute(sql, args));
 }