Beispiel #1
0
        /// <summary>
        /// 更新数据不为默认
        /// </summary>
        public void UpDefault(IDbConnection conn, IDbTransaction trans)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + databaseprefix + "sites set is_default=0 where is_default=1");
            WriteDataBase.Execute(conn, trans, strSql.ToString());
        }
Beispiel #2
0
        /// <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);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.user_amount_log model)
        {
            int i = 0;

            using (IDbConnection conn = new DapperView().Context())
            {
                using (IDbTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        #region 主表信息==========================
                        StringBuilder strSql = new StringBuilder();
                        StringBuilder str1   = new StringBuilder(); //数据字段
                        StringBuilder str2   = new StringBuilder(); //数据参数
                        //利用反射获得属性的所有公共属性
                        PropertyInfo[] pros  = model.GetType().GetProperties();
                        List <object>  paras = new List <object>();
                        strSql.Append("insert into " + databaseprefix + "user_amount_log(");
                        foreach (PropertyInfo pi in pros)
                        {
                            //如果不是主键则追加sql字符串
                            if (!pi.Name.Equals("id"))
                            {
                                //判断属性值是否为空
                                if (pi.GetValue(model, null) != null && !pi.GetValue(model, null).ToString().Equals(""))
                                {
                                    str1.Append(pi.Name + ",");          //拼接字段
                                    str2.Append("@" + i + ",");          //声明参数
                                    i++;
                                    paras.Add(pi.GetValue(model, null)); //对参数赋值
                                }
                            }
                        }
                        strSql.Append(str1.ToString().Trim(','));
                        strSql.Append(") values (");
                        strSql.Append(str2.ToString().Trim(','));
                        strSql.Append(") ");
                        strSql.Append(";SELECT @@@IDENTITY;");
                        object obj = WriteDataBase.ExecuteScalar <object>(conn, trans, strSql.ToString(), paras.ToArray());
                        model.id = Convert.ToInt32(obj);
                        #endregion

                        #region 用户表信息========================
                        StringBuilder strSql1 = new StringBuilder();
                        strSql1.Append("update " + databaseprefix + "users set amount=amount+" + model.value);
                        strSql1.Append(" where id=@0");
                        WriteDataBase.Execute(conn, trans, strSql1.ToString(), model.user_id);
                        #endregion

                        trans.Commit();//提交事务
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();//回滚事务
                        return(0);
                    }
                }
            }
            return(model.id);
        }
Beispiel #4
0
        /// <summary>
        /// 查找不存在的图片并删除已移除的图片及数据
        /// </summary>
        public void DeleteList(IDbConnection conn, IDbTransaction trans, List <Model.article_albums> models, int channel_id, int article_id)
        {
            StringBuilder idList = new StringBuilder();

            if (models != null)
            {
                foreach (Model.article_albums modelt in models)
                {
                    if (modelt.id > 0)
                    {
                        idList.Append(modelt.id + ",");
                    }
                }
            }
            string delIds   = idList.ToString().TrimEnd(',');
            string strwhere = "channel_id=" + channel_id + " and article_id=" + article_id;

            if (!string.IsNullOrEmpty(delIds))
            {
                strwhere += " and id not in(" + delIds + ")";
            }
            List <Model.article_albums> albums = new List <Model.article_albums>();

            albums = WriteDataBase.Query <Model.article_albums>(conn, trans, Sql.Builder.Select("channel_id,id,thumb_path,original_path").From(TableName).Where(strwhere)).ToList();
            foreach (var dr in albums)
            {
                int rows = WriteDataBase.Execute(conn, trans, "delete from " + databaseprefix + "article_albums where id=" + dr.id); //删除数据库
                if (rows > 0)
                {
                    FileHelper.DeleteFile(dr.thumb_path);    //删除缩略图
                    FileHelper.DeleteFile(dr.original_path); //删除原图
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// 获取会员组折扣
        /// </summary>
        public int GetDiscount(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select top 1 discount from " + databaseprefix + "user_groups");
            strSql.Append(" where id=" + id);
            return(WriteDataBase.Execute(strSql.ToString()));
        }
Beispiel #6
0
        /// <summary>
        /// 删除文章对应的Tags标签关系
        /// </summary>
        public bool Delete(IDbConnection conn, IDbTransaction trans, int channel_id, int article_id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("delete from " + databaseprefix + "article_tags_relation");
            strSql.Append(" where channel_id=@0 and article_id=@1");
            return(WriteDataBase.Execute(strSql.ToString(), channel_id, article_id) > 0);
        }
Beispiel #7
0
        /// <summary>
        /// 修改一列数据
        /// </summary>
        public bool UpdateField(string channel_name, int id, string strValue)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + databaseprefix + DTKeys.TABLE_CHANNEL_ARTICLE + channel_name + " set " + strValue);
            strSql.Append(" where id=" + id);
            return(WriteDataBase.Execute(strSql.ToString()) > 0);
        }
Beispiel #8
0
        /// <summary>
        /// 修改一列数据
        /// </summary>
        public int UpdateField(int id, string strValue)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + databaseprefix + "users set " + strValue);
            strSql.Append(" where id=" + id);
            return(WriteDataBase.Execute(strSql.ToString()));
        }
Beispiel #9
0
        /// <summary>
        /// 修改一列数据
        /// </summary>
        public bool UpdateField(string order_no, string strValue)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + databaseprefix + "orders set " + strValue);
            strSql.Append(" where order_no='" + order_no + "'");
            return(WriteDataBase.Execute(strSql.ToString()) > 0);
        }
Beispiel #10
0
        /// <summary>
        /// 删除一条数据,带事务
        /// </summary>
        public bool Delete(IDbConnection conn, IDbTransaction trans, string nav_name)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("delete from " + databaseprefix + "navigation");
            strSql.Append(" where name=@0");
            return(WriteDataBase.Execute(conn, trans, strSql.ToString(), nav_name) > 0);
        }
Beispiel #11
0
        /// <summary>
        /// 修改一条记录,带事务
        /// </summary>
        public bool Update(IDbConnection conn, IDbTransaction trans, string old_name, string new_name)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + databaseprefix + "navigation set name=@0");
            strSql.Append(" where name=@1");
            int rows = WriteDataBase.Execute(conn, trans, strSql.ToString(), new_name, old_name);

            return(rows > 0);
        }
Beispiel #12
0
        /// <summary>
        /// 根据用户名删除一条数据
        /// </summary>
        public bool Delete(int id, string user_name)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("delete from " + databaseprefix + "user_point_log ");
            strSql.Append(" where id=@0 and user_name=@1");
            int rows = WriteDataBase.Execute(strSql.ToString(), id, user_name);

            return(rows > 0);
        }
Beispiel #13
0
        /// <summary>
        /// 修改一列数据
        /// </summary>
        public bool UpdateField(int id, string strValue)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + databaseprefix + "sites set " + strValue);
            strSql.Append(" where id=" + id);
            int rows = WriteDataBase.Execute(strSql.ToString());

            return(rows > 0);
        }
Beispiel #14
0
        /// <summary>
        /// 修改一列数据
        /// </summary>
        public bool UpdateField(string build_path, string strValue)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + databaseprefix + "sites set " + strValue);
            strSql.Append(" where build_path=@0");
            int rows = WriteDataBase.Execute(strSql.ToString(), build_path);

            return(rows > 0);
        }
Beispiel #15
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(IDbConnection conn, IDbTransaction trans, List <Model.article_albums> models, int channel_id, int article_id)
        {
            int i = 0;

            if (models != null)
            {
                StringBuilder strSql;
                StringBuilder str1;; //数据字段
                StringBuilder str2;  //数据参数
                foreach (Model.article_albums modelt in models)
                {
                    i      = 0;
                    strSql = new StringBuilder();
                    str1   = new StringBuilder();
                    str2   = new StringBuilder();
                    //利用反射获得属性的所有公共属性
                    PropertyInfo[] pros  = modelt.GetType().GetProperties();
                    List <object>  paras = new List <object>();
                    strSql.Append("insert into " + databaseprefix + "article_albums(");
                    foreach (PropertyInfo pi in pros)
                    {
                        //如果不是主键则追加sql字符串
                        if (!pi.Name.Equals("id"))
                        {
                            //判断属性值是否为空
                            if (pi.GetValue(modelt, null) != null && !pi.GetValue(modelt, null).ToString().Equals(""))
                            {
                                str1.Append(pi.Name + ","); //拼接字段
                                str2.Append("@" + i + ","); //声明参数
                                i++;
                                switch (pi.Name)
                                {
                                case "channel_id":
                                    paras.Add(channel_id);
                                    break;

                                case "article_id":
                                    paras.Add(article_id);    //刚插入的文章ID
                                    break;

                                default:
                                    paras.Add(pi.GetValue(modelt, null));    //对参数赋值
                                    break;
                                }
                            }
                        }
                    }
                    strSql.Append(str1.ToString().Trim(','));
                    strSql.Append(") values (");
                    strSql.Append(str2.ToString().Trim(','));
                    strSql.Append(") ");
                    WriteDataBase.Execute(conn, trans, strSql.ToString(), paras.ToArray());//带事务
                }
            }
        }
Beispiel #16
0
        /// <summary>
        /// 根据用户名删除一条数据
        /// </summary>
        public bool Delete(int id, string user_name)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("delete from " + databaseprefix + "user_message ");
            strSql.Append(" where id=@0 and (post_user_name=@1 or accept_user_name=@2)");

            int rows = WriteDataBase.Execute(strSql.ToString(), id, user_name, user_name);

            return(rows > 0);
        }
Beispiel #17
0
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("delete from " + databaseprefix + "navigation");
            strSql.Append(" where id in(" + GetIds(id) + ")");

            int rows = WriteDataBase.Execute(strSql.ToString());

            return(rows > 0);
        }
Beispiel #18
0
        /// <summary>
        /// 删除已移除的图片扩展字段
        /// </summary>
        private void ThumDelete(IDbConnection conn, IDbTransaction trans, List <Model.site_channel_thum> thums, int channel_id)
        {
            List <Model.site_channel_thum> thum = new List <Model.site_channel_thum>();

            thum = WriteDataBase.Query <Model.site_channel_thum>(conn, trans, Sql.Builder.Select("id").From(databaseprefix + "site_channel_thum").Where("channel_id=" + channel_id)).ToList();
            foreach (var dr in thum)
            {
                Model.site_channel_thum model = thums.Find(p => p.id == dr.id); //查找对应的字段ID
                if (model == null)
                {
                    WriteDataBase.Execute(conn, trans, "delete from " + databaseprefix + "site_channel_thum where channel_id=" + channel_id + " and id=" + dr.id);//删除该行
                }
            }
        }
Beispiel #19
0
        /// <summary>
        /// 修改一条记录,带事务
        /// </summary>
        public bool Update(IDbConnection conn, IDbTransaction trans, string old_name, int parent_id, string nav_name, string title, int sort_id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + databaseprefix + "navigation set");
            strSql.Append(" parent_id=@0,");
            strSql.Append(" name=@1,");
            strSql.Append(" title=@2,");
            strSql.Append(" sort_id=@3");
            strSql.Append(" where name=@4");
            int rows = WriteDataBase.Execute(conn, trans, strSql.ToString(), parent_id, nav_name, title, sort_id, old_name);

            return(rows > 0);
        }
Beispiel #20
0
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {
            //取得频道的名称
            string channel_name = GetChannelName(id);

            if (string.IsNullOrEmpty(channel_name))
            {
                return(false);
            }
            //取得要删除的所有导航ID
            string navIds = new navigation(databaseprefix).GetIds("channel_" + channel_name);

            try
            {
                //删除导航主表
                if (!string.IsNullOrEmpty(navIds))
                {
                    WriteDataBase.Execute("delete from " + databaseprefix + "navigation where id in(" + navIds + ")");
                }

                //删除频道扩展字段表
                StringBuilder strSql2 = new StringBuilder();
                strSql2.Append("delete from " + databaseprefix + "site_channel_field ");
                strSql2.Append(" where channel_id=@0 ");
                WriteDataBase.Execute(strSql2.ToString(), id);

                //删除频道缩略图尺寸表
                StringBuilder strSql5 = new StringBuilder();
                strSql5.Append("delete from " + databaseprefix + "site_channel_thum ");
                strSql5.Append(" where channel_id=@0 ");
                WriteDataBase.Execute(strSql5.ToString(), id);

                //删除频道数据表
                StringBuilder strSql4 = new StringBuilder();
                strSql4.Append("drop table " + databaseprefix + DTKeys.TABLE_CHANNEL_ARTICLE + channel_name);
                WriteDataBase.Execute(strSql4.ToString());

                //删除频道表
                StringBuilder strSql3 = new StringBuilder();
                strSql3.Append("delete from " + databaseprefix + "site_channel ");
                strSql3.Append(" where id=@0 ");
                WriteDataBase.Execute(strSql3.ToString(), id);
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(true);
        }
Beispiel #21
0
        /// <summary>
        /// 设置为默认的收货地址
        /// </summary>
        public void SetDefault(int id, string user_name)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + databaseprefix + "user_addr_book set is_default=0");
            strSql.Append(" where user_name=@0");
            WriteDataBase.Execute(strSql.ToString(), user_name);

            StringBuilder strSql2 = new StringBuilder();

            strSql2.Append("update " + databaseprefix + "user_addr_book set is_default=1");
            strSql2.Append(" where id=@0 and user_name=@1");

            WriteDataBase.Execute(strSql2.ToString(), id, user_name);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {
            Model.article_attribute_field model = GetModel(id);//取得扩展字段实体
            using (IDbConnection conn = new DapperView().Context())
            {
                using (IDbTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        //删除所关联的频道数据表相关列
                        DataTable dt = new DAL.site_channel(databaseprefix).GetFieldList(conn, trans, id).Tables[0];
                        if (dt.Rows.Count > 0)
                        {
                            foreach (DataRow dr in dt.Rows)
                            {
                                //检查有无该频道数据表和列
                                int rowsCount = ReadDataBase.ExecuteScalar <int>(conn, trans, "select count(1) from syscolumns where id=object_id('" + databaseprefix + DTKeys.TABLE_CHANNEL_ARTICLE + dr["name"].ToString() + "') and name='" + model.name + "'");
                                if (rowsCount > 0)
                                {
                                    //删除频道数据表一列
                                    WriteDataBase.Execute(conn, trans, "alter table " + databaseprefix + DTKeys.TABLE_CHANNEL_ARTICLE + dr["name"].ToString() + " drop column " + model.name);
                                }
                            }
                        }

                        //删除频道关联字段表
                        StringBuilder strSql1 = new StringBuilder();
                        strSql1.Append("delete from " + databaseprefix + "site_channel_field");
                        strSql1.Append(" where field_id=@0");
                        WriteDataBase.Execute(conn, trans, strSql1.ToString(), id);

                        //删除扩展字段主表
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("delete from " + databaseprefix + "article_attribute_field");
                        strSql.Append(" where id=@0");
                        WriteDataBase.Execute(conn, trans, strSql.ToString(), id);

                        trans.Commit();//提交事务
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();//回滚事务
                        return(false);
                    }
                }
            }
            return(true);
        }
Beispiel #23
0
        /// <summary>
        /// 删除一条数据,及子表所有相关数据
        /// </summary>
        public bool Delete(int id)
        {
            StringBuilder strSql2 = new StringBuilder();

            strSql2.Append("delete from " + databaseprefix + "order_goods ");
            strSql2.Append(" where order_id=@0 ");
            ReadDataBase.ExecuteScalar <int>(strSql2.ToString(), id);

            StringBuilder strSql = new StringBuilder();

            strSql.Append("delete from " + databaseprefix + "orders ");
            strSql.Append(" where id=@0");

            int rowsAffected = WriteDataBase.Execute(strSql.ToString(), id);

            return(rowsAffected > 0);
        }
Beispiel #24
0
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {
            //删除Tag标签关系表
            StringBuilder strSql1 = new StringBuilder();

            strSql1.Append("delete from " + databaseprefix + "article_tags_relation");
            strSql1.Append(" where tag_id=@0");
            int rowsAffected = WriteDataBase.Execute(strSql1.ToString(), id);

            //删除主表
            StringBuilder strSql = new StringBuilder();

            strSql.Append("delete from " + databaseprefix + "article_tags");
            strSql.Append(" where id=@0");
            rowsAffected += WriteDataBase.Execute(strSql.ToString(), id);

            return(rowsAffected > 1);
        }
Beispiel #25
0
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {
            //删除站点OAtuh应用
            StringBuilder strSql1 = new StringBuilder();

            strSql1.Append("delete from " + databaseprefix + "site_oauth");
            strSql1.Append(" where oauth_id=@0");
            WriteDataBase.Execute(strSql1.ToString(), id);

            //删除主表
            StringBuilder strSql = new StringBuilder();

            strSql.Append("delete from  " + databaseprefix + "oauth_app ");
            strSql.Append(" where id=@0");
            int rows = WriteDataBase.Execute(strSql.ToString(), id);

            return(rows > 0);
        }
Beispiel #26
0
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {
            //删除站点支付方式
            StringBuilder strSql1 = new StringBuilder();

            strSql1.Append("delete from " + databaseprefix + "site_payment");
            strSql1.Append(" where payment_id=@0");
            WriteDataBase.Execute(strSql1.ToString(), id);

            //删除主表
            StringBuilder strSql = new StringBuilder();

            strSql.Append("delete from " + databaseprefix + "payment");
            strSql.Append(" where id=@0");
            int rows = WriteDataBase.Execute(strSql.ToString(), id);

            return(rows > 0);
        }
Beispiel #27
0
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {
            //删除会员组价格
            StringBuilder strSql1 = new StringBuilder();

            strSql1.Append("delete from " + databaseprefix + "user_group_price ");
            strSql1.Append(" where group_id=@0 ");
            WriteDataBase.Execute(strSql1.ToString(), id);

            //删除主表
            StringBuilder strSql = new StringBuilder();

            strSql.Append("delete from " + databaseprefix + "user_groups ");
            strSql.Append(" where id=@0");

            int rowsAffected = WriteDataBase.Execute(strSql.ToString(), id);

            return(rowsAffected > 0);
        }
Beispiel #28
0
 /// <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 + "'");
     }
 }
Beispiel #29
0
        /// <summary>
        /// 确认充值订单
        /// </summary>
        public bool Confirm(string recharge_no)
        {
            Model.user_recharge model = GetModel("recharge_no='" + recharge_no + "'", "", "");//根据充值单号得到实体
            if (model == null)
            {
                return(false);
            }
            using (IDbConnection conn = new DapperView().Context())
            {
                using (IDbTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        #region 增加一条账户余额记录===============
                        Model.user_amount_log amountModel = new Model.user_amount_log();
                        amountModel.user_id   = model.user_id;
                        amountModel.user_name = model.user_name;
                        amountModel.value     = model.amount;
                        amountModel.remark    = "在线充值,单号:" + recharge_no;
                        amountModel.add_time  = DateTime.Now;
                        new DAL.user_amount_log(databaseprefix).Add(conn, trans, amountModel);
                        #endregion

                        #region 更新充值表=========================
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("update " + databaseprefix + "user_recharge set ");
                        strSql.Append("status=@0,");
                        strSql.Append("complete_time=@1");
                        strSql.Append(" where recharge_no=@2");
                        WriteDataBase.Execute(conn, trans, strSql.ToString(), 1, DateTime.Now, recharge_no);
                        #endregion
                        trans.Commit();//提交事务
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();//回滚事务
                        return(false);
                    }
                }
            }
            return(true);
        }
Beispiel #30
0
        /// <summary>
        /// 检查更新Tags标签及关系,带事务
        /// </summary>
        public void Update(IDbConnection conn, IDbTransaction trans, string tags_title, int channel_id, int article_id)
        {
            int tagsId = 0;
            //检查该Tags标签是否已存在
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select top 1 id from " + databaseprefix + "article_tags");
            strSql.Append(" where title=@0");
            object obj1 = ReadDataBase.ExecuteScalar <object>(conn, trans, strSql.ToString(), tags_title);

            if (obj1 != null)
            {
                //存在则将ID赋值
                tagsId = Convert.ToInt32(obj1);
            }
            //如果尚未创建该Tags标签则创建
            if (tagsId == 0)
            {
                StringBuilder strSql2 = new StringBuilder();
                strSql2.Append("insert into " + databaseprefix + "article_tags(");
                strSql2.Append("title,is_red,sort_id,add_time)");
                strSql2.Append(" values (");
                strSql2.Append("@0,@1,@2,@3)");
                strSql2.Append(";SELECT @@@IDENTITY;");
                object obj2 = WriteDataBase.ExecuteScalar <object>(conn, trans, strSql2.ToString(), tags_title, 0, 99, DateTime.Now);
                if (obj2 != null)
                {
                    //插入成功后返回ID
                    tagsId = Convert.ToInt32(obj2);
                }
            }
            //匹配Tags标签与文章之间的关系
            if (tagsId > 0)
            {
                StringBuilder strSql3 = new StringBuilder();
                strSql3.Append("insert into " + databaseprefix + "article_tags_relation(");
                strSql3.Append("channel_id,article_id,tag_id)");
                strSql3.Append(" values (");
                strSql3.Append("@0,@1,@2)");
                WriteDataBase.Execute(conn, trans, strSql3.ToString(), channel_id, article_id, tagsId);
            }
        }