예제 #1
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);
        }
예제 #2
0
        /// <summary>
        /// 快捷添加系统默认导航
        /// </summary>
        public int Add(string parent_name, string nav_name, string title, string link_url, int sort_id, int channel_id, string action_type)
        {
            //先根据名称查询该父ID
            StringBuilder strSql1 = new StringBuilder();

            strSql1.Append("select top 1 id from " + databaseprefix + "navigation");
            strSql1.Append(" where name=@0");
            object obj1 = ReadDataBase.ExecuteScalar <object>(strSql1.ToString(), parent_name);

            if (obj1 == null)
            {
                return(0);
            }
            int parent_id = Convert.ToInt32(obj1);

            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into " + databaseprefix + "navigation(");
            strSql.Append("parent_id,channel_id,nav_type,name,title,link_url,sort_id,action_type,is_lock,is_sys)");
            strSql.Append(" values (");
            strSql.Append("@0,@1,@2,@3,@4,@5,@6,@7,@8,@9)");
            strSql.Append(";SELECT @@@IDENTITY;");
            object obj2 = WriteDataBase.ExecuteScalar <object>(strSql.ToString(), parent_id, channel_id, DTEnums.NavigationEnum.System.ToString(), nav_name, title, link_url, sort_id, action_type, 0, 1);

            return(Convert.ToInt32(obj2));
        }
예제 #3
0
        /// <summary>
        /// 快捷添加系统默认导航,带事务
        /// </summary>
        public int Add(IDbConnection conn, IDbTransaction trans, int parent_id, string nav_name, string title, string link_url, int sort_id, int channel_id, string action_type, int is_lock)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into " + databaseprefix + "navigation(");
            strSql.Append("parent_id,channel_id,nav_type,name,title,link_url,sort_id,action_type,is_sys,is_lock)");
            strSql.Append(" values (");
            strSql.Append("@0,@1,@2,@3,@4,@5,@6,@7,@8,@9)");
            strSql.Append(";SELECT @@@IDENTITY;");
            object obj = WriteDataBase.ExecuteScalar <object>(conn, trans, strSql.ToString(), parent_id, channel_id, DTEnums.NavigationEnum.System.ToString(), nav_name, title, link_url, sort_id, action_type, 1, is_lock);

            return(Convert.ToInt32(obj));
        }
예제 #4
0
        /// <summary>
        /// 插入一条下载附件记录
        /// </summary>
        public int AddLog(Model.user_attach_log model)
        {
            int           i      = 0;
            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 + "dt_user_attach_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>(strSql.ToString(), paras.ToArray());

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
예제 #5
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);
            }
        }
예제 #6
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.article_comment 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 + "article_comment(");
                        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
                        if (model.parent_id > 0)
                        {
                            Model.article_comment model2 = GetModel(conn, trans, model.parent_id); //带事务
                            model.class_list  = model2.class_list + model.id + ",";
                            model.class_layer = model2.class_layer + 1;
                        }
                        else
                        {
                            model.class_list  = "," + model.id + ",";
                            model.class_layer = 1;
                        }
                        //修改节点列表和深度
                        WriteDataBase.Execute(conn, trans, "update [" + databaseprefix + "article_comment] set class_list='" + model.class_list + "', class_layer=" + model.class_layer + " where id=" + model.id); //带事务
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        return(0);
                    }
                }
            }
            return(model.id);
        }
예제 #7
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.manager_role 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 + "manager_role(");
                        foreach (PropertyInfo pi in pros)
                        {
                            //如果不是主键和LIST<T>则追加sql字符串
                            if (!pi.Name.Equals("id") && !typeof(System.Collections.IList).IsAssignableFrom(pi.PropertyType))
                            {
                                //判断属性值是否为空
                                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 角色权限表信息====================
                        if (model.manager_role_values != null)
                        {
                            StringBuilder strSql2; //SQL字符串
                            StringBuilder str21;   //数据库字段
                            StringBuilder str22;   //声明参数
                            foreach (Model.manager_role_value modelt in model.manager_role_values)
                            {
                                i       = 0;
                                strSql2 = new StringBuilder();
                                str21   = new StringBuilder();
                                str22   = new StringBuilder();
                                PropertyInfo[] pros2  = modelt.GetType().GetProperties();
                                List <object>  paras2 = new List <object>();
                                strSql2.Append("insert into " + databaseprefix + "manager_role_value(");
                                foreach (PropertyInfo pi in pros2)
                                {
                                    if (!pi.Name.Equals("id"))
                                    {
                                        if (pi.GetValue(modelt, null) != null && !pi.GetValue(modelt, null).ToString().Equals(""))
                                        {
                                            str21.Append(pi.Name + ",");
                                            str22.Append("@" + i + ",");
                                            i++;
                                            if (pi.Name.Equals("role_id"))
                                            {
                                                paras2.Add(model.id);//将刚插入的父ID赋值
                                            }
                                            else
                                            {
                                                paras2.Add(pi.GetValue(modelt, null));
                                            }
                                        }
                                    }
                                }
                                strSql2.Append(str21.ToString().Trim(','));
                                strSql2.Append(") values (");
                                strSql2.Append(str22.ToString().Trim(','));
                                strSql2.Append(") ");
                                WriteDataBase.Execute(conn, trans, strSql2.ToString(), paras2.ToArray());
                            }
                        }
                        #endregion

                        trans.Commit(); //提交事务
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback(); //回滚事务
                        return(0);
                    }
                }
            }
            return(model.id);
        }
예제 #8
0
        /// <summary>
        /// 增加一条数据及其子表
        /// </summary>
        public int Add(Model.site_channel model)
        {
            int i = 0;
            //取得站点对应的导航ID
            int parent_id = new DAL.sites(databaseprefix).GetSiteNavId(model.site_id);

            if (parent_id == 0)
            {
                return(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 + "site_channel(");
                        foreach (PropertyInfo pi in pros)
                        {
                            //如果不是主键和List<T>类型则追加sql字符串
                            if (!pi.Name.Equals("id") && !typeof(System.Collections.IList).IsAssignableFrom(pi.PropertyType))
                            {
                                //判断属性值是否为空
                                if (pi.GetValue(model, null) != null)
                                {
                                    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

                        //写入扩展字段及创建频道数据表
                        FieldAdd(conn, trans, model);

                        #region 缩略图字段
                        //添加缩略图字段
                        if (model.channel_thums != null)
                        {
                            StringBuilder strSql2; //SQL字符串
                            StringBuilder str21;   //数据库字段
                            StringBuilder str22;   //声明参数
                            foreach (Model.site_channel_thum modelt in model.channel_thums)
                            {
                                i = 0;
                                //新增
                                strSql2 = new StringBuilder();
                                str21   = new StringBuilder();
                                str22   = new StringBuilder();
                                PropertyInfo[] pros2  = modelt.GetType().GetProperties();
                                List <object>  paras2 = new List <object>();
                                strSql2.Append("insert into " + databaseprefix + "site_channel_thum(");
                                foreach (PropertyInfo pi in pros2)
                                {
                                    if (!pi.Name.Equals("id"))
                                    {
                                        if (pi.GetValue(modelt, null) != null && !pi.GetValue(modelt, null).ToString().Equals(""))
                                        {
                                            str21.Append(pi.Name + ",");
                                            str22.Append("@" + i + ",");
                                            i++;
                                            if (pi.Name.Equals("channel_id"))
                                            {
                                                paras2.Add(model.id); //将规则ID赋值
                                            }
                                            else
                                            {
                                                paras2.Add(pi.GetValue(modelt, null));
                                            }
                                        }
                                    }
                                }
                                strSql2.Append(str21.ToString().Trim(','));
                                strSql2.Append(") values (");
                                strSql2.Append(str22.ToString().Trim(','));
                                strSql2.Append(") ");
                                WriteDataBase.Execute(conn, trans, strSql2.ToString(), paras2.ToArray());
                            }
                        }
                        #endregion

                        #region 写入导航数据===============
                        DAL.navigation dal      = new DAL.navigation(databaseprefix);
                        int            newNavId = dal.Add(conn, trans, parent_id, "channel_" + model.name, model.title, "", model.sort_id, model.id, "Show");
                        dal.Add(conn, trans, newNavId, "channel_" + model.name + "_list", "内容管理", "/admin/article/article_list", 99, model.id, "Show,View,Add,Edit,Delete,Audit");
                        dal.Add(conn, trans, newNavId, "channel_" + model.name + "_category", "栏目类别", "/admin/article/category_list", 100, model.id, "Show,View,Add,Edit,Delete");
                        //开启规格新增菜单
                        if (model.is_spec > 0)
                        {
                            new DAL.navigation(databaseprefix).Add(conn, trans, newNavId, "channel_" + model.name + "_spec", "规格管理", "/admin/article/spec_list", 102, model.id, "Show,View,Add,Edit,Delete");
                        }
                        if (model.is_comment == 1)
                        {
                            dal.Add(conn, trans, newNavId, "channel_" + model.name + "_comment", "评论管理", "/admin/article/comment_list", 101, model.id, "Show,View,Delete,Reply");
                        }
                        if (model.is_recycle == 1)
                        {
                            dal.Add(conn, trans, newNavId, "channel_" + model.name + "_recycle", "回收站", "/admin/article/recycle_list", 102, model.id, "Show,View,Edit,Delete,Audit");
                        }
                        #endregion
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        return(0);
                    }
                }
            }
            return(model.id);
        }
예제 #9
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.article_category model, int role_id)
        {
            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 + "article_category(");
                        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);

                        if (model.parent_id > 0)
                        {
                            Model.article_category model2 = GetModel(conn, trans, model.parent_id); //带事务
                            model.class_list  = model2.class_list + model.id + ",";
                            model.class_layer = model2.class_layer + 1;
                        }
                        else
                        {
                            model.class_list  = "," + model.id + ",";
                            model.class_layer = 1;
                        }

                        //添加权限菜单
                        object name = ReadDataBase.ExecuteScalar <object>(conn, trans, "select top 1 name from [" + databaseprefix + "site_channel]  where id=" + model.channel_id); //带事务
                        if (null != name)
                        {
                            //自动分级
                            string parent_name = "channel_" + name.ToString() + "_category";
                            if (model.parent_id > 0)
                            {
                                parent_name += "_" + model.parent_id;
                            }
                            new DAL.navigation(databaseprefix).Add(conn, trans, parent_name, "channel_" + name.ToString() + "_category_" + model.id, model.title, "", model.sort_id, model.channel_id, "Show", 1);

                            if (role_id > 0)
                            {
                                Model.manager_role_value valModel = new Model.manager_role_value();
                                valModel.role_id     = role_id;
                                valModel.nav_name    = "channel_" + name.ToString() + "_category_" + model.id;
                                valModel.action_type = "Show";
                                new DAL.manager_role_value(databaseprefix).Add(valModel);
                            }
                        }

                        //修改节点列表和深度
                        WriteDataBase.Execute(conn, trans, "update " + databaseprefix + "article_category set class_list='" + model.class_list + "', class_layer=" + model.class_layer + " where id=" + model.id); //带事务
                        #endregion

                        #region 栏目规格===========================
                        if (model.category_specs != null)
                        {
                            StringBuilder strSql3;
                            foreach (Model.article_category_spec modelt in model.category_specs)
                            {
                                strSql3 = new StringBuilder();
                                strSql3.Append("insert into " + databaseprefix + "article_category_spec(");
                                strSql3.Append("category_id,spec_id)");
                                strSql3.Append(" values (");
                                strSql3.Append("@0,@1)");
                                WriteDataBase.Execute(conn, trans, strSql3.ToString(), model.id, modelt.spec_id);
                            }
                        }
                        #endregion
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        return(0);
                    }
                }
            }
            return(model.id);
        }
예제 #10
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.sites model)
        {
            int i = 0;

            using (IDbConnection conn = new DapperView().Context())
            {
                using (IDbTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        //判断当前是否为默认,如果是,取消其它默认数据
                        if (model.is_default > 0)
                        {
                            UpDefault(conn, trans);
                        }
                        #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 + "sites(");
                        foreach (PropertyInfo pi in pros)
                        {
                            //如果不是主键和List<T>类型则追加sql字符串
                            if (!pi.Name.Equals("id") && !typeof(System.Collections.IList).IsAssignableFrom(pi.PropertyType))
                            {
                                //判断属性值是否为空
                                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

                        //如果非继承网站则添加导航菜单
                        if (model.inherit_id == 0)
                        {
                            new DAL.navigation(databaseprefix).Add(conn, trans, "sys_contents", "channel_" + model.build_path, model.title, "", model.sort_id, 0, "Show");
                        }
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        return(0);
                    }
                }
            }
            return(model.id);
        }
예제 #11
0
        /// <summary>
        /// 增加一条数据,及其子表数据
        /// </summary>
        public int Add(Model.orders 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 + "orders(");
                        foreach (PropertyInfo pi in pros)
                        {
                            //如果不是主键则追加sql字符串
                            if (!pi.Name.Equals("id") && !typeof(System.Collections.IList).IsAssignableFrom(pi.PropertyType))
                            {
                                //判断属性值是否为空
                                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 订单商品列表======================
                        if (model.order_goods != null)
                        {
                            StringBuilder strSql2; //SQL字符串
                            StringBuilder strSql3;
                            StringBuilder strSql4;
                            StringBuilder str21; //数据库字段
                            StringBuilder str22; //声明参数
                            foreach (Model.order_goods modelt in model.order_goods)
                            {
                                i       = 0;
                                strSql2 = new StringBuilder();
                                str21   = new StringBuilder();
                                str22   = new StringBuilder();
                                PropertyInfo[] pros2  = modelt.GetType().GetProperties();
                                List <object>  paras2 = new List <object>();
                                strSql2.Append("insert into " + databaseprefix + "order_goods(");
                                foreach (PropertyInfo pi in pros2)
                                {
                                    if (!pi.Name.Equals("id"))
                                    {
                                        if (pi.GetValue(modelt, null) != null && !pi.GetValue(modelt, null).ToString().Equals(""))
                                        {
                                            str21.Append(pi.Name + ",");
                                            str22.Append("@" + i + ",");
                                            i++;
                                            if (pi.Name.Equals("order_id"))
                                            {
                                                paras2.Add(model.id);//将刚插入的父ID赋值
                                            }
                                            else
                                            {
                                                paras2.Add(pi.GetValue(modelt, null));
                                            }
                                        }
                                    }
                                }
                                strSql2.Append(str21.ToString().Trim(','));
                                strSql2.Append(") values (");
                                strSql2.Append(str22.ToString().Trim(','));
                                strSql2.Append(") ");
                                WriteDataBase.Execute(conn, trans, strSql2.ToString(), paras2.ToArray());

                                //扣减商品库存
                                if (modelt.goods_id > 0)
                                {
                                    strSql3 = new StringBuilder();
                                    strSql3.Append("update " + databaseprefix + "article_goods set stock_quantity=stock_quantity-@0");
                                    strSql3.Append(" where id=@1 and channel_id=@2 and article_id=@3");
                                    WriteDataBase.Execute(conn, trans, strSql3.ToString(), modelt.quantity, modelt.goods_id, modelt.channel_id, modelt.article_id);

                                    string channelName = new DAL.site_channel(databaseprefix).GetChannelName(modelt.channel_id);//查询频道的名称
                                    strSql4 = new StringBuilder();
                                    strSql4.Append("update " + databaseprefix + DTKeys.TABLE_CHANNEL_ARTICLE + channelName + " set ");
                                    strSql4.Append("stock_quantity=(select sum(stock_quantity) from " + databaseprefix + "article_goods where channel_id=@0 and article_id=@1)");
                                    strSql4.Append(" where id=@1");
                                    WriteDataBase.Execute(conn, trans, strSql4.ToString(), modelt.channel_id, modelt.article_id);
                                }
                                else
                                {
                                    string channelName = new DAL.site_channel(databaseprefix).GetChannelName(modelt.channel_id);//查询频道的名称
                                    strSql4 = new StringBuilder();
                                    strSql4.Append("update " + databaseprefix + DTKeys.TABLE_CHANNEL_ARTICLE + channelName + " set ");
                                    strSql4.Append("stock_quantity=stock_quantity-@0 where id=@1");
                                    WriteDataBase.Execute(conn, trans, strSql4.ToString(), modelt.quantity, modelt.article_id);
                                }
                            }
                        }
                        #endregion

                        trans.Commit(); //提交事务
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback(); //回滚事务
                        return(0);
                    }
                }
            }
            return(model.id);
        }
예제 #12
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.article model)
        {
            //查询频道名称
            string channelName = new DAL.site_channel(databaseprefix).GetChannelName(model.channel_id);

            if (channelName.Length == 0)
            {
                return(0);
            }
            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 + DTKeys.TABLE_CHANNEL_ARTICLE + channelName + "(");
                        //主表字段信息
                        foreach (PropertyInfo pi in pros)
                        {
                            //如果不是主键或List<T>则追加sql字符串
                            if (!pi.Name.Equals("id") && !pi.Name.Equals("fields") && !typeof(System.Collections.IList).IsAssignableFrom(pi.PropertyType))
                            {
                                //判断属性值是否为空
                                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)); //对参数赋值
                                }
                            }
                        }
                        //扩展字段信息
                        foreach (KeyValuePair <string, string> kvp in model.fields)
                        {
                            str1.Append(kvp.Key + ","); //拼接字段
                            str2.Append("@" + i + ","); //声明参数
                            i++;
                            paras.Add(kvp.Value);       //对参数赋值
                        }
                        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 添加图片相册====================
                        if (model.albums != null)
                        {
                            new DAL.article_albums(databaseprefix).Add(conn, trans, model.albums, model.channel_id, model.id);
                        }
                        #endregion

                        #region 添加内容附件====================
                        if (model.attach != null)
                        {
                            new DAL.article_attach(databaseprefix).Add(conn, trans, model.attach, model.channel_id, model.id);
                        }
                        #endregion

                        #region 添加商品价格====================
                        if (model.goods != null)
                        {
                            foreach (Model.article_goods modelt in model.goods)
                            {
                                new DAL.article_goods(databaseprefix).Add(conn, trans, modelt, model.channel_id, model.id);
                            }
                        }
                        #endregion

                        #region 添加商品规格====================
                        if (model.specs != null)
                        {
                            foreach (Model.article_goods_spec modelt in model.specs)
                            {
                                new DAL.article_goods_spec(databaseprefix).Add(conn, trans, modelt, model.channel_id, model.id);
                            }
                        }
                        #endregion

                        #region 保存自定义参数====================
                        if (model.attribute != null)
                        {
                            new DAL.article_attribute(databaseprefix).Add(conn, trans, model.attribute, model.channel_id, model.id);
                        }
                        #endregion

                        #region 添加Tags标签====================
                        if (model.tags != null && model.tags.Trim().Length > 0)
                        {
                            string[] tagsArr = model.tags.Trim().Split(',');
                            if (tagsArr.Length > 0)
                            {
                                foreach (string tagsStr in tagsArr)
                                {
                                    new DAL.article_tags(databaseprefix).Update(conn, trans, tagsStr, model.channel_id, model.id);
                                }
                            }
                        }
                        #endregion

                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        return(0);
                    }
                }
            }
            return(model.id);
        }
예제 #13
0
        /// <summary>
        /// 直接充值订单
        /// </summary>
        /// <summary>
        /// 直接充值订单
        /// </summary>
        public bool Recharge(Model.user_recharge model)
        {
            int i = 0;

            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    = "在线充值,单号:" + model.recharge_no;
                        amountModel.add_time  = DateTime.Now;
                        new DAL.user_amount_log(databaseprefix).Add(conn, trans, amountModel);
                        #endregion

                        #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_recharge(");
                        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

                        trans.Commit();//提交事务
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();//回滚事务
                        return(false);
                    }
                }
            }
            return(model.id > 0);
        }