Exemple #1
0
        /// <summary>
        /// 增加职务信息
        /// </summary>
        /// <param name="data">提交的表单数据</param>
        /// <param name="errorMsg">错误信息</param>
        /// <returns></returns>
        public bool Add(JObject data, ref string errorMsg)
        {
            using (SqlSugar.SqlSugarClient db = DbInstance)
            {
                try
                {
                    if (IsExits(p => p.Title_Name == data["Dept_Name"].ToString().Trim() && p.Title_State == 1))
                    {
                        errorMsg = "存在相同职务简称";
                    }
                    else if (data["Title_FullName"] != null && IsExits(p => p.Title_FullName == data["Title_FullName"].ToString().Trim() && p.Title_State == 1))
                    {
                        errorMsg = "存在相同职务全称";
                    }
                    else
                    {
                        WJ_T_Title title = new WJ_T_Title();
                        title.Title_Name       = data["Title_Name"].ToString();
                        title.Title_FullName   = data["Title_FullName"] != null ? data["Title_FullName"].ToString() : "";
                        title.Title_Code       = data["Title_Code"].ToString();
                        title.Title_Sort       = data["Title_Sort"].ToObject <int>();
                        title.Title_CreateTime = DateTime.Now;
                        title.Title_State      = 1;

                        return(Add(title));
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.DbServiceLog(ex.Message);
                }
                return(false);
            }
        }
Exemple #2
0
        /// <summary>
        /// 更新角色信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool Update(JObject data, ref string errorMsg)
        {
            using (SqlSugar.SqlSugarClient db = DbInstance)
            {
                try
                {
                    int roleId = data["Id"].ToObject <int>();
                    if (IsExits(p => p.Role_Name == data["Role_Name"].ToString().Trim() && p.Id != roleId && p.Role_State == 1))
                    {
                        errorMsg = "存在相同角色名称";
                    }
                    else
                    {
                        string menuIds = GetMenuId(data["Role_Menu"]);
                        if (string.IsNullOrWhiteSpace(menuIds))
                        {
                            errorMsg = "";
                            return(false);
                        }

                        BeginTran();

                        WJ_T_Role role = GetSingle(p => p.Id == roleId);
                        role.Role_Name = data["Role_Name"].ToString();
                        role.Role_Sort = data["Role_Sort"].ToObject <int>();
                        bool flag = Update(role);

                        if (flag)
                        {
                            //string oldMenuIds = RoleMenuService.Instance.GetRoleMenuId(id);

                            RoleMenuService.Instance.Delete(roleId, db); //删除旧的角色树记录

                            foreach (var menuId in menuIds.TrimEnd(',').Split(','))
                            {
                                WJ_T_RoleMenu roleMneu = new WJ_T_RoleMenu();
                                roleMneu.RoleId = roleId;
                                roleMneu.MenuId = Convert.ToInt32(menuId);

                                if (RoleMenuService.Instance.Add(roleMneu))
                                {
                                    RollbackTran();
                                    return(false);
                                }
                            }

                            CommitTran();
                            return(true);
                        }
                    }
                }
                catch (Exception ex)
                {
                    RollbackTran();
                    LogHelper.DbServiceLog(ex.Message);
                    errorMsg = ex.Message;
                }
                return(false);
            }
        }
Exemple #3
0
        /// <summary>
        /// 保存要发送的营收信息
        /// </summary>
        /// <param name="phone"></param>
        /// <returns></returns>
        public bool SaveRevenueMsg(Business_WeChatPush_Information weChatPush, Business_WeChatPushDetail_Information weChatPushDetail)
        {
            using (SqlSugar.SqlSugarClient _dbMsSql = SugarDao.SugarDao_MsSql.GetInstance())
            {
                bool result = false;
                try
                {
                    _dbMsSql.BeginTran();
                    result = _dbMsSql.Insert <Business_WeChatPush_Information>(weChatPush, false) != DBNull.Value;
                    if (result)
                    {
                        //短信接收者
                        result = _dbMsSql.Insert <Business_WeChatPushDetail_Information>(weChatPushDetail, false) != DBNull.Value;
                    }
                    _dbMsSql.CommitTran();
                }
                catch (Exception ex)
                {
                    Common.LogHelper.LogHelper.WriteLog(ex.Message);
                    _dbMsSql.RollbackTran();
                }
                finally
                {
                }

                return(result);
            }
        }
Exemple #4
0
        /// <summary>
        /// 更新职务信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool Update(JObject data, ref string errorMsg)
        {
            using (SqlSugar.SqlSugarClient db = DbInstance)
            {
                try
                {
                    int id = data["Id"].ToObject <int>();
                    if (IsExits(p => p.Id != id && p.Title_Name == data["Dept_Name"].ToString().Trim() && p.Title_State == 1))
                    {
                        errorMsg = "存在相同职务简称";
                    }
                    else if (data["Title_FullName"] != null && IsExits(p => p.Id != id && p.Title_FullName == data["Title_FullName"].ToString().Trim() && p.Title_State == 1))
                    {
                        errorMsg = "存在相同职务全称";
                    }
                    else
                    {
                        WJ_T_Title title = GetSingle(p => p.Id == id);
                        title.Title_Name     = data["Title_Name"].ToString();
                        title.Title_FullName = data["Title_FullName"] != null ? data["Title_FullName"].ToString() : "";
                        title.Title_Code     = data["Title_Code"].ToString();
                        title.Title_Sort     = data["Title_Sort"].ToObject <int>();

                        return(Update(title));
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.DbServiceLog(ex.Message);
                }
                return(false);
            }
        }
Exemple #5
0
 /// <summary>
 /// 绑定用户角色
 /// </summary>
 /// <returns></returns>
 public List <Sys_Role> GetSysRoleList()
 {
     using (SqlSugar.SqlSugarClient _dbMsSql = SugarDao.SugarDao_MsSql.GetInstance())
     {
         Guid            vguid       = Guid.Parse(Common.Tools.MasterVGUID.SysAdminRole);
         List <Sys_Role> sysRoleList = _dbMsSql.Queryable <Sys_Role>().Where(i => i.Vguid != vguid).ToList();
         return(sysRoleList);
     }
 }
Exemple #6
0
 /// <summary>
 /// 绑定部门信息
 /// </summary>
 /// <returns></returns>
 public List <Master_Organization> GetDepartmentList(string vguid)
 {
     using (SqlSugar.SqlSugarClient _dbMsSql = SugarDao.SugarDao_MsSql.GetInstance())
     {
         Guid VGUID = Guid.Parse(vguid);
         List <Master_Organization> departmentList = _dbMsSql.Queryable <Master_Organization>().Where(i => i.ParentVguid == VGUID).ToList();
         return(departmentList);
     }
 }
Exemple #7
0
 /// <summary>
 /// 绑定公司信息
 /// </summary>
 /// <returns></returns>
 public List <Master_Organization> GetCompanyList()
 {
     using (SqlSugar.SqlSugarClient _dbMsSql = SugarDao.SugarDao_MsSql.GetInstance())
     {
         Guid vguid = Guid.Parse(Common.Tools.MasterVGUID.ParentCompany);
         List <Master_Organization> companyList = _dbMsSql.Queryable <Master_Organization>().Where(i => i.ParentVguid == vguid).ToList();
         return(companyList);
     }
 }
 /// <summary>
 /// 获取推送用户信息列表(获取推送接收者信息列表)短信
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public List <Business_Personnel_Information> GetPushUserSms(Business_WeChatPush_Information pushModel)
 {
     using (SqlSugar.SqlSugarClient _dbMsSql = SugarDao.SugarDao_MsSql.GetInstance())
     {
         var queryable = _dbMsSql.Queryable <Business_Personnel_Information>()
                         .JoinTable <Business_Personnel_Information, Business_WeChatPushDetail_Information>((c1, c2) => c1.UserID == c2.PushObject && c2.Business_WeChatPushVguid == pushModel.VGUID, JoinType.INNER);
         return(queryable.ToList());
     }
 }
Exemple #9
0
 /// <summary>
 /// SqlSugar静态执行方法
 /// </summary>
 public static T StartSqlSugar <T>(Func <SqlSugar.SqlSugarClient, T> func)
 {
     using (SqlSugar.SqlSugarClient db = new SqlSugar.SqlSugarClient(new ConnectionConfig
     {
         ConnectionString = Config.ConnectionString, //必填
         DbType = DbType.SqlServer,                  //必填
         IsAutoCloseConnection = true,               //默认false
         InitKeyType = InitKeyType.SystemTable
     }))
     {
         return(func(db));
     }
 }
 /// <summary>
 /// 保存系统操作日志
 /// </summary>
 /// <param name="operationLogModel"></param>
 /// <returns></returns>
 public void SaveLog(Business_OperationLog operationLogModel)
 {
     using (SqlSugar.SqlSugarClient _dbMsSql = SugarDao.SugarDao_MsSql.GetInstance())
     {
         bool result = false;
         try
         {
             result = _dbMsSql.Insert <Business_OperationLog>(operationLogModel, false) != DBNull.Value;
         }
         catch (Exception ex)
         {
             Common.LogHelper.LogHelper.WriteLog(ex.Message + "/n" + ex.ToString() + "/n" + ex.StackTrace);
         }
     }
 }
        public static void AddSqlsugarSetup(this IServiceCollection services)
        {
            // 默认添加主数据库连接
            MainDb.CurrentDbConnId = Appsettings.app(new string[] { "MainDB" });
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            services.AddScoped <SqlSugar.ISqlSugarClient>(o =>
            {
                //var listConfig = new List<ConnectionConfig>();
                //BaseDBConfig.MutiConnectionString.ForEach(m =>
                //{
                //    listConfig.Add(new ConnectionConfig()
                //    {
                //        ConfigId = m.ConnId.ObjToString().ToLower(),
                //        ConnectionString = m.Conn,
                //        DbType = (DbType)m.DbType,
                //        IsAutoCloseConnection = true,
                //        IsShardSameThread = false,
                //        AopEvents = new AopEvents
                //        {
                //            OnLogExecuting = (sql, p) =>
                //            {
                //                // 多库操作的话,此处暂时无效果,在另一个地方有效,具体请查看BaseRepository.cs
                //            }
                //        },
                //        MoreSettings = new ConnMoreSettings()
                //        {
                //            IsAutoRemoveDataCache = true
                //        }
                //        //InitKeyType = InitKeyType.SystemTable
                //    }
                //   );
                //});
                //return new SqlSugarClient(listConfig);
                var db = new SqlSugar.SqlSugarClient(new SqlSugar.ConnectionConfig()
                {
                    ConnectionString      = _connectionString,               //BaseDBConfig.ConnectionString,//必填, 数据库连接字符串
                    DbType                = SqlSugar.DbType.Sqlite,          //(SqlSugar.DbType)BaseDBConfig.DbType,//必填, 数据库类型
                    IsAutoCloseConnection = true,                            //默认false, 时候知道关闭数据库连接, 设置为true无需使用using或者Close操作
                    InitKeyType           = SqlSugar.InitKeyType.SystemTable //默认SystemTable, 字段信息读取, 如:该属性是不是主键,标识列等等信息
                });
                return(db);
            });
        }
 /// <summary>
 /// 构造函数
 /// </summary>
 public DbContext()
 {
     Db = new SqlSugar.SqlSugarClient(new ConnectionConfig()
     {
         ConnectionString      = Para.EventDBConnectStr,
         DbType                = DbType.SqlServer,
         IsAutoCloseConnection = true
     });
     //Db.Aop.OnLogExecuted = (sql, pars) => //SQL执行完事件
     //{
     //    string x = sql;
     //};
     //Db.Aop.OnLogExecuting = (sql, pars) => //SQL执行前事件
     //{
     //    string x = sql;
     //};
 }
Exemple #13
0
 /// <summary>
 /// SqlSugar静态执行方法
 /// </summary>
 public static void StartSqlSugar(Action <SqlSugar.SqlSugarClient> func)
 {
     using (SqlSugar.SqlSugarClient db = new SqlSugar.SqlSugarClient(new ConnectionConfig
     {
         ConnectionString = Config.ConnectionString, //必填
         DbType = DbType.SqlServer,                  //必填
         IsAutoCloseConnection = true,               //默认false
         InitKeyType = InitKeyType.Attribute
     }))
     {
         try
         {
             func(db);
         }
         catch (Exception ex)
         {
             Common.SystemLog.WriteSystemLog("SqlSugar", ex.Message);
         }
     }
 }
        /// <summary>
        /// 获取推送数据
        /// </summary>
        /// <returns></returns>
        public string GetPushMsg()
        {
            using (SqlSugar.SqlSugarClient _dbMsSql = SugarDao.SugarDao_MsSql.GetInstance())
            {
                string responseMsg = "";
                bool   result      = false;
                List <Business_WeChatPush_Information> pushList = GetPushList();//获取要推送的数据
                foreach (var item in pushList)
                {
                    List <Business_Personnel_Information> pushPersonList = new List <Business_Personnel_Information>();
                    pushPersonList = GetPushUserWeChat(item);       //获取推送信息接收者信息列表
                    result         = PushMsg(item, pushPersonList); //返回推送结果
                    if (!result)
                    {
                        responseMsg = item.Title + "推送失败";
                        return(responseMsg);
                    }
                }

                return(responseMsg);
            }
        }
Exemple #15
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="blnIsAutoCloseConnection">是否自动关闭连接</param>
 private DbContext(bool blnIsAutoCloseConnection)
 {
     if (string.IsNullOrEmpty(_connectionString))
     {
         throw new ArgumentNullException("数据库连接字符串为空");
     }
     _db = new SqlSugarClient(new ConnectionConfig()
     {
         ConnectionString          = _connectionString,
         DbType                    = _dbType,
         IsAutoCloseConnection     = blnIsAutoCloseConnection,
         IsShardSameThread         = true,
         ConfigureExternalServices = new ConfigureExternalServices()
         {
             //DataInfoCacheService = new HttpRuntimeCache()
         },
         MoreSettings = new ConnMoreSettings()
         {
             IsAutoRemoveDataCache = true,
         }
     });
 }
        /// <summary>
        /// 更新是否查看推送状态
        /// </summary>
        /// <param name="contentModel"></param>
        /// <returns></returns>
        public bool UpdateIsReadStatus(U_Content contentModel, string invalidusers = "")
        {
            using (SqlSugar.SqlSugarClient _dbMsSql = SugarDao.SugarDao_MsSql.GetInstance())
            {
                bool result = false;
                try
                {
                    foreach (var item in contentModel.PushObject)
                    {
                        if (!invalidusers.Contains(item.UserID))
                        {
                            result = _dbMsSql.Update <Business_WeChatPushDetail_Information>(new { ISRead = "1" }, i => i.Business_WeChatPushVguid == contentModel.VGUID && i.PushObject == item.UserID);
                        }
                    }
                }
                catch (Exception exp)
                {
                    LogManager.WriteLog(LogFile.Error, "更新推送是否查看:" + exp.ToString());
                }

                return(result);
            }
        }
        public static void AddSqlsugarSetup(this IServiceCollection services)
        {
            if (services == null) throw new ArgumentNullException(nameof(services));

            services.AddScoped<SqlSugar.ISqlSugarClient>(o =>
            {
                var client = new SqlSugar.SqlSugarClient(new SqlSugar.ConnectionConfig()
                {
                    ConnectionString = ConfigurationHelper.GetConnectionString(),//必填, 数据库连接字符串
                    DbType = (SqlSugar.DbType)DbType.MySql,//必填, 数据库类型
                    IsAutoCloseConnection = true,//默认false, 时候知道关闭数据库连接, 设置为true无需使用using或者Close操作
                    InitKeyType = InitKeyType.Attribute //默认SystemTable, 字段信息读取, 如:该属性是不是主键,标识列等等信息
                });
                //用来打印Sql方便你调式    
                client.Aop.OnLogExecuting = (sql, pars) =>
                {
                    Console.WriteLine(sql + "\r\n" +
                    client.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
                    Console.WriteLine();
                };

                return client;
            });
        }
 public SimpleClient(SqlSugarClient context)
 {
     this.Context = context;
 }
Exemple #19
0
 public UtilExceptions(SqlSugarClient context, string message, object pars)
     : base(GetMessage(context, message, pars))
 {
 }
Exemple #20
0
 public UtilExceptions(SqlSugarClient context, string message, string sql)
     : base(GetMessage(context, message, sql))
 {
 }
Exemple #21
0
 public TraceModule()
 {
     _db = Resolve <IBaseQueryRepository>().Context;
 }
Exemple #22
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="sqlSugarClient"></param>

        public SqlSugarUnitOfWorkFilter(ISqlSugarClient sqlSugarClient)
        {
            _sqlSugarClient = (SqlSugarClient)sqlSugarClient;
        }
Exemple #23
0
 /// <summary>
 /// 判段是否包含主键
 /// </summary>
 /// <param name="db"></param>
 /// <param name="tableName"></param>
 /// <returns></returns>
 internal static bool IsPrimaryKey(SqlSugarClient db, string tableName)
 {
     return(GetPrimaryKeyByTableName(db, tableName) != null);
 }
Exemple #24
0
 public UserInfoService(SugarDao sd)
 {
     this.db = sd.db;
 }
Exemple #25
0
 public virtual List <string> GetDataBaseList(SqlSugarClient db)
 {
     return(db.Ado.SqlQuery <string>(this.GetDataBaseSql));
 }
        /// <summary>
        /// 获取表结构信息
        /// </summary>
        /// <param name="db"></param>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public List <PubModel.DataTableMap> GetTableColumns(SqlSugarClient db, string tableName)
        {
            string sql = SqlSugarTool.GetTtableColumnsInfo(tableName);

            return(db.SqlQuery <PubModel.DataTableMap>(sql));
        }
Exemple #27
0
 internal SaveableProvider(SqlSugarClient context, List <T> saveObjects)
 {
     this.saveObjects = saveObjects;
     this.Context     = context;
 }
Exemple #28
0
 public PlatformQuery(IBaseQueryRepository baseRepository)
 {
     _db = baseRepository.Context;
 }
 public static object GetEntity(this IDataReader dr, SqlSugarClient context)
 {
     return(null);
 }
Exemple #30
0
 public TraceModule()
 {
     _db = Infrastructure.DbInstance.Db;
 }
 public UserInfoService(SugarDao sd)
 {
     this.db = sd.db;
 }