Example #1
0
        public TResult GetModel <TResult>(BPMSEntities ctx, Expression <Func <T, TResult> > selector, Expression <Func <T, bool> > condition)
        {
            bool newCtx = ctx == null;

            if (newCtx)
            {
                ctx = new BPMSEntities();
            }
            try
            {
                var rlt = ctx.Set <T>().Where(condition).Select(selector).FirstOrDefault();
                return(rlt);
            }
            catch (Exception ex)
            {
                LogHelper.Log.Info(ex.ToString());
                return(default(TResult));
            }
            finally
            {
                if (newCtx)
                {
                    ctx.Dispose();
                }
            }
        }
Example #2
0
 public DataTable GetList(int systemId, int parentId)
 {
     using (var ctx = new BPMSEntities())
     {
         Expression <Func <MenuInfo, bool> > condition = t => t.SystemId == systemId && t.ParentId == parentId;
         var list = from a in ctx.MenuInfo.Where(condition)
                    join b in ctx.SystemInfo on a.SystemId equals b.ID
                    select new
         {
             a.ID,
             a.SystemId,
             SystemName = b.Name,
             a.ParentId,
             a.Name,
             a.Code,
             a.Category,
             a.PurviewId,
             a.Icon,
             a.IconUrl,
             a.NavigateUrl,
             a.FormName,
             a.IsSplit,
             a.Remark,
             a.IsEnable,
             a.SortIndex,
             a.CreateDate,
             a.CreateUserId,
             a.CreateUserName,
             a.ModifyDate,
             a.ModifyUserId,
             a.ModifyUserName
         };
         return(ConvertHelper.ToDataTable(list.ToList().Cast <object>().ToArray()));
     }
 }
Example #3
0
        public int GetCount(BPMSEntities ctx, Expression <Func <T, bool> > condition)
        {
            bool newCtx = ctx == null;

            if (newCtx)
            {
                ctx = new BPMSEntities();
            }
            try
            {
                return(ctx.Set <T>().Count(condition));
            }
            catch (Exception ex)
            {
                LogHelper.Log.Info(ex.ToString());
                return(0);
            }
            finally
            {
                if (newCtx)
                {
                    ctx.Dispose();
                }
            }
        }
Example #4
0
        public bool Delete(BPMSEntities ctx, T model)
        {
            bool newCtx = ctx == null;

            if (newCtx)
            {
                ctx = new BPMSEntities();
            }
            bool blRlt = false;

            try
            {
                ctx.Entry(model).State = EntityState.Deleted;
                ctx.SaveChanges();
                blRlt = true;
            }
            catch (Exception ex)
            {
                LogHelper.Log.Info(ex.ToString());
            }
            finally
            {
                if (newCtx)
                {
                    ctx.Dispose();
                }
            }
            return(blRlt);
        }
Example #5
0
        public bool Delete(BPMSEntities ctx, Expression <Func <T, bool> > condition)
        {
            bool newCtx = ctx == null;

            if (newCtx)
            {
                ctx = new BPMSEntities();
            }
            bool blRlt = false;

            try
            {
                IList <T> list = ctx.Set <T>().Where(condition).ToList();
                foreach (var data in list)
                {
                    ctx.Entry(data).State = EntityState.Deleted;
                }
                ctx.SaveChanges();
                blRlt = true;
            }
            catch (Exception ex)
            {
                LogHelper.Log.Info(ex.ToString());
            }
            finally
            {
                if (newCtx)
                {
                    ctx.Dispose();
                }
            }
            return(blRlt);
        }
Example #6
0
        /// <summary>
        /// 插入数据
        /// </summary>
        public bool Insert(BPMSEntities ctx, IList <T> models)
        {
            bool newCtx = ctx == null;

            if (newCtx)
            {
                ctx = new BPMSEntities();
            }
            bool blRlt = false;

            try
            {
                foreach (var model in models)
                {
                    ctx.Set <T>().Add(model);
                }
                ctx.SaveChanges();
                blRlt = true;
            }
            catch (Exception ex)
            {
                LogHelper.Log.Info(ex.ToString());
            }
            finally
            {
                if (newCtx)
                {
                    ctx.Dispose();
                }
            }
            return(blRlt);
        }
Example #7
0
        public IList GetTop(BPMSEntities ctx, int count, Expression <Func <T, bool> > condition)
        {
            bool newCtx = ctx == null;

            if (newCtx)
            {
                ctx = new BPMSEntities();
            }
            try
            {
                return(ctx.Set <T>().Where(condition).Take(count).ToList());
            }
            catch (Exception ex)
            {
                LogHelper.Log.Info(ex.ToString());
                return(null);
            }
            finally
            {
                if (newCtx)
                {
                    ctx.Dispose();
                }
            }
        }
Example #8
0
 public DataTable GetList(int systemId)
 {
     using (var ctx = new BPMSEntities())
     {
         var list = from a in ctx.RoleInfo.Where(t => t.SystemId == systemId)
                    join b in ctx.SystemInfo on a.SystemId equals b.ID
                    select new
         {
             a.ID,
             a.SystemId,
             SystemName = b.Name,
             a.Name,
             a.Code,
             a.Category,
             a.Remark,
             a.IsEnable,
             a.SortIndex,
             a.CreateDate,
             a.CreateUserId,
             a.CreateUserName,
             a.ModifyDate,
             a.ModifyUserId,
             a.ModifyUserName
         };
         return(ConvertHelper.ToDataTable(list.Cast <object>().ToArray()));
     }
 }
Example #9
0
        public IList GetTop <TKey>(BPMSEntities ctx, int count, Expression <Func <T, bool> > condition, Expression <Func <T, TKey> > orderBy, bool isAsc = true)
        {
            bool newCtx = ctx == null;

            if (newCtx)
            {
                ctx = new BPMSEntities();
            }
            try
            {
                var rlt = ctx.Set <T>().Where(condition);
                if (isAsc)
                {
                    rlt = rlt.OrderBy(orderBy);
                }
                else
                {
                    rlt = rlt.OrderByDescending(orderBy);
                }
                return(rlt.Take(count).ToList());
            }
            catch (Exception ex)
            {
                LogHelper.Log.Info(ex.ToString());
                return(null);
            }
            finally
            {
                if (newCtx)
                {
                    ctx.Dispose();
                }
            }
        }
Example #10
0
        /// <summary>
        /// 设置事务级别
        /// </summary>
        public void SetNoLock(BPMSEntities ctx)
        {
            bool newCtx = ctx == null;

            if (newCtx)
            {
                ctx = new BPMSEntities();
            }
            try
            {
                var sql = "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED";
                ctx.Database.ExecuteSqlCommand(sql);
            }
            catch (Exception ex)
            {
                LogHelper.Log.Info(ex.ToString());
            }
            finally
            {
                if (newCtx)
                {
                    ctx.Dispose();
                }
            }
        }
Example #11
0
        public IList GetList <TResult>(BPMSEntities ctx, Expression <Func <T, TResult> > selector, Expression <Func <T, bool> > condition)
        {
            bool newCtx = ctx == null;

            if (newCtx)
            {
                ctx = new BPMSEntities();
            }
            try
            {
                return(ctx.Set <T>().Where(condition).Select(selector).ToList());
            }
            catch (Exception ex)
            {
                LogHelper.Log.Info(ex.ToString());
                return(null);
            }
            finally
            {
                if (newCtx)
                {
                    ctx.Dispose();
                }
            }
        }
Example #12
0
        public IList GetList <TResult, TKey>(BPMSEntities ctx, int pageIndex, int pageSize, out int count, Expression <Func <T, TResult> > selector, Expression <Func <T, bool> > condition, Expression <Func <T, TKey> > orderBy, bool isAsc = true)
        {
            bool newCtx = ctx == null;

            if (newCtx)
            {
                ctx = new BPMSEntities();
            }
            try
            {
                var models = ctx.Set <T>();
                count = models.Count(condition);
                if (isAsc)
                {
                    return(models.Where(condition).OrderBy(orderBy).Select(selector).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList());
                }
                else
                {
                    return(models.Where(condition).OrderByDescending(orderBy).Select(selector).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList());
                }
            }
            catch (Exception ex)
            {
                count = 0;
                LogHelper.Log.Info(ex.ToString());
                return(null);
            }
            finally
            {
                if (newCtx)
                {
                    ctx.Dispose();
                }
            }
        }
Example #13
0
        /// <summary>
        /// 操作列表
        /// </summary>
        public DataTable GetActionList(int systemId, int moduleId, int functionId, string actionName, string actionCode, int isEnable, int pageIndex, int pageSize, out int count)
        {
            using (var ctx = new BPMSEntities())
            {
                Expression <Func <PurviewInfo, bool> > condition = t => t.SystemId == systemId && t.PurviewType == EPurviewType.操作.GetHashCode();
                if (isEnable != EIsEnable.全部.GetHashCode())
                {
                    bool bIsEnable = isEnable == EIsEnable.启用.GetHashCode() ? true : false;
                    condition.And(t => t.IsEnable == bIsEnable);
                }
                if (functionId > 0)
                {
                    condition.And(t => t.ParentId == functionId);
                }
                if (!string.IsNullOrEmpty(actionName))
                {
                    condition.And(t => t.Name.Contains(actionName));
                }
                if (!string.IsNullOrEmpty(actionCode))
                {
                    condition.And(t => t.Code.Contains(actionCode));
                }

                var list = from a in ctx.PurviewInfo.Where(condition)
                           join b in ctx.SystemInfo on a.SystemId equals b.ID
                           join c in ctx.PurviewInfo on a.ParentId equals c.ID
                           select new
                {
                    a.ID,
                    a.SystemId,
                    SystemName = b.Name,
                    a.Name,
                    a.Code,
                    a.ParentId,
                    MoudleId   = c.ParentId,
                    ParentName = "",
                    a.PurviewType,
                    a.Remark,
                    a.IsEnable,
                    a.SortIndex,
                    a.CreateDate,
                    a.CreateUserId,
                    a.CreateUserName,
                    a.ModifyDate,
                    a.ModifyUserId,
                    a.ModifyUserName
                };
                if (moduleId > 0)
                {
                    list = list.Where(t => t.MoudleId == moduleId);
                }
                count = list.Count();
                list  = list.Skip((pageIndex - 1) * pageSize).Take(pageSize);
                return(ConvertHelper.ToDataTable(list.ToList().Cast <object>().ToArray()));
            }
        }
Example #14
0
 /// <summary>
 /// 角色成员
 /// </summary>
 /// <param name="xmlCredentials"></param>
 /// <param name="roleId"></param>
 /// <returns>用户列表</returns>
 public DataTable RoleMembers(int roleId)
 {
     using (var ctx = new BPMSEntities())
     {
         var list = from a in ctx.UserRole.Where(t => t.RoleId == roleId)
                    join b in ctx.UserInfo.Where(t => t.IsEnable) on a.UserId equals b.ID
                    select b;
         return(ConvertHelper.ToDataTable(list.ToList().Cast <object>().ToList()));
     }
 }
Example #15
0
        public void Delete(BPMSEntities ctx, int systemId, int userId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(" DELETE FROM UserRole ");
            strSql.Append(" WHERE UserId = " + userId + " and RoleId in  ");
            strSql.Append(" ( ");
            strSql.Append(" SELECT ID ");
            strSql.Append(" FROM RoleInfo ");
            strSql.Append(" WHERE SystemId = " + systemId + " ");
            strSql.Append(" ) ");
            ctx.Database.ExecuteSqlCommand(strSql.ToString(), null);
        }
Example #16
0
        public void Delete(BPMSEntities ctx, int systemId, int roleId, int userId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(" DELETE FROM  UserPurview ");
            strSql.Append(" WHERE ID IN ");
            strSql.Append(" ( ");
            strSql.Append(" SELECT a.ID ");
            strSql.Append(" FROM UserPurview a ");
            strSql.Append(" INNER JOIN PurviewInfo b on a.PurviewId = b.ID ");
            strSql.Append(String.Format(" WHERE a.RoleId = {0} and b.SystemId = {1} and a.UserId = {2}", roleId, systemId, userId));
            strSql.Append(" ) ");
            ctx.Database.ExecuteSqlCommand(strSql.ToString(), null);
        }
Example #17
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="model"></param>
        /// <param name="entry"></param>
        /// <returns></returns>
        internal bool Add(BPMSEntities ctx, SysLog model, DbEntityEntry entry)
        {
            /// 资源
            /// http://www.cnblogs.com/oppoic/p/ef_dbpropertyvalues_toobject_clone_setvalues_changetracker_entries.html
            List <SysLogDetails> logDetailList = new List <SysLogDetails>();
            bool rlt = true;

            model.ID = GetNewID();
            var location = IPHelper.GetLocation();

            model.IPAddress      = location.GetIPAddress.ToString();
            model.IPAddressName  = location.ToString();
            model.CreateDate     = DateTime.Now;
            model.CreateUserId   = model.CreateUserId;
            model.CreateUserName = model.CreateUserName;

            if (!Insert(ctx, model))
            {
                rlt = false;
            }
            if (rlt == true && entry != null)
            {
                IEnumerable <string> propertyNames = null;
                if (model.OperationType == EOperationType.新增.GetHashCode() || model.OperationType == EOperationType.除.GetHashCode())
                {
                    propertyNames = entry.CurrentValues.PropertyNames;
                }
                else if (model.OperationType == EOperationType.修改.GetHashCode())
                {
                    propertyNames = entry.CurrentValues.PropertyNames.Where(t => entry.Property(t).IsModified);
                }
                foreach (var propertyName in propertyNames)
                {
                    SysLogDetails logDetail = new SysLogDetails();
                    logDetail.ID        = GetNewID("SysLogDetails");
                    logDetail.SyslogId  = model.ID;
                    logDetail.FieldName = propertyName;
                    logDetail.FieldText = DatabasePDMHelper.GetColumnName(model.TableName, propertyName);
                    logDetail.NewValue  = entry.Property(propertyName).CurrentValue.ToString();
                    logDetail.OldValue  = entry.Property(propertyName).OriginalValue.ToString();
                    logDetailList.Add(logDetail);
                }
                SysLogDetailsDal detailDal = new SysLogDetailsDal();
                if (!detailDal.Insert(ctx, logDetailList))
                {
                    rlt = false;
                }
            }
            return(rlt);
        }
Example #18
0
        /// <summary>
        /// 获取用户有权限的菜单
        /// </summary>
        /// <param name="systemId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public DataTable GetUserMenu(int systemId, int roleId, int userId)
        {
            DataTable rltDt = new DataTable();

            using (var ctx = new BPMSEntities())
            {
                rltDt = ConvertHelper.ToDataTable(ctx.SP_GetUserMenu(systemId, userId).ToList());
                if (roleId != 0)
                {
                    rltDt.DefaultView.RowFilter = "roleId=" + roleId + " ";
                    rltDt = rltDt.DefaultView.ToTable();
                }
            }
            return(rltDt);
        }
Example #19
0
 public DataTable GetList(int systemId, int userId)
 {
     using (var ctx = new BPMSEntities())
     {
         var list = from a in ctx.UserRole
                    join b in ctx.RoleInfo on a.RoleId equals b.ID
                    where a.UserId == userId && b.SystemId == systemId
                    select new
         {
             b.ID,
             b.Name
         };
         return(ConvertHelper.ToDataTable(list.ToList().Cast <object>().ToArray()));
     }
 }
Example #20
0
 /// <summary>
 /// 获取最新表主键ID
 /// </summary>
 /// <param name="tableName">表名</param>
 /// <returns></returns>
 public int GetNewID(string tableName)
 {
     try
     {
         using (var ctx = new BPMSEntities())
         {
             return(ctx.GetNewID(tableName).FirstOrDefault().Value);
         }
     }
     catch (Exception ex)
     {
         LogHelper.Log.Info(ex.ToString());
         return(0);
     }
 }
Example #21
0
 public DataTable GetPurviewList(int systemId, int roleId)
 {
     using (var ctx = new BPMSEntities())
     {
         var list = from a in ctx.RolePurview.Where(t => t.RoleId == roleId)
                    join b in ctx.RoleInfo on a.RoleId equals b.ID
                    join c in ctx.PurviewInfo on a.PurviewId equals c.ID
                    where c.SystemId == systemId
                    select new
         {
             c.ID,
             c.Name,
             c.Code
         };
         return(ConvertHelper.ToDataTable(list.ToList().Cast <object>().ToArray()));
     }
 }
Example #22
0
        /// <summary>
        /// 日志列表
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="account"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public DataTable GetList(DateTime startDate, DateTime endDate, int systemId, string account, int pageIndex, int pageSize, out int count)
        {
            count = 0;
            using (var ctx = new BPMSEntities())
            {
                DateTime tmpStartDate = ConvertHelper.ObjectToDateTime(startDate.ToShortDateString() + " 00:00:00");
                DateTime tmpEndDate   = ConvertHelper.ObjectToDateTime(endDate.AddDays(1).ToShortDateString() + " 00:00:00");
                Expression <Func <SysLoginLog, bool> > condition = t => t.CreateDate >= tmpStartDate && t.CreateDate <= endDate && t.SystemId == systemId;
                if (!string.IsNullOrEmpty(account))
                {
                    condition.And(t => t.Account.Contains(account));
                }

                ///先 匿名查询
                var list = from a in ctx.SysLoginLog.Where(condition)
                           join b in ctx.SystemInfo on a.SystemId equals b.ID
                           join c in ctx.UserInfo on a.Account equals c.Account into logInfo
                           from log in logInfo.DefaultIfEmpty()
                           select new
                {
                    Account     = a.Account,
                    AccountName = log == null ? string.Empty : log.Name,
                    a.CreateDate,
                    a.IPAddress,
                    a.IPAddressName,
                    a.Status,
                    a.SystemId,
                    SystemName = b.Name
                };
                count = list.Count();
                var        data  = list.OrderByDescending(t => t.CreateDate).Skip((pageIndex - 1) * pageSize).Take(pageSize);
                DataTable  tbRlt = ConvertHelper.ToDataTable(data.ToList().Cast <object>().ToArray());
                DataColumn col   = new DataColumn("StatusName");
                tbRlt.Columns.Add(col);
                foreach (DataRow item in tbRlt.Rows)
                {
                    item["StatusName"] = Enum.GetName(typeof(ELoginStatus), item["Status"]);
                }
                return(tbRlt);
            }
        }
Example #23
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        internal bool Add(BPMSEntities ctx, int systemId, string account, ELoginStatus loginStatus, string remark = "")
        {
            int         rlt   = 1;
            SysLoginLog model = new SysLoginLog();

            model.ID         = dal.GetNewID();
            model.Account    = account;
            model.SystemId   = systemId;
            model.CreateDate = DateTime.Now;
            model.Status     = loginStatus.GetHashCode();
            var location = IPHelper.GetLocation();

            model.IPAddress     = location.GetIPAddress.ToString();
            model.IPAddressName = location.ToString();
            model.Remark        = remark;
            if (!dal.Insert(ctx, model))
            {
                rlt = 0;
            }
            return(rlt == 1);
        }
Example #24
0
        public bool Update(BPMSEntities ctx, T model)
        {
            bool newCtx = ctx == null;

            if (newCtx)
            {
                ctx = new BPMSEntities();
            }
            bool      blRlt = false;
            DbSet <T> dbSet = ctx.Set <T>();

            try
            {
                DbEntityEntry <T> entry = ctx.Entry(model);
                if (entry.State == EntityState.Detached)
                {
                    dbSet.Attach(model);
                    entry.State = EntityState.Modified;
                }

                ctx.SaveChanges();
                blRlt = true;
            }
            catch (Exception ex)
            {
                LogHelper.Log.Info(ex.ToString());
            }
            finally
            {
                if (newCtx)
                {
                    ctx.Dispose();
                }
            }
            return(blRlt);
        }
Example #25
0
        public T GetModel(BPMSEntities ctx, Expression <Func <T, bool> > condition)
        {
            var rlt = GetModel(ctx, t => t, condition);

            return(rlt == null ? null : (T)rlt);
        }
Example #26
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="searchType">
        /// 1=编号、2=账号、3=姓名
        /// </param>
        /// <param name="keyWord"></param>
        /// <param name="isEnable"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public DataTable GetList(int searchType, string keyWord, int isEnable, int pageIndex, int pageSize, out int count)
        {
            Expression <Func <UserInfo, bool> > condition = t => true;

            if (isEnable != EIsEnable.全部.GetHashCode())
            {
                bool bIsEnable = isEnable == EIsEnable.启用.GetHashCode() ? true : false;
                condition.And(t => t.IsEnable == bIsEnable);
            }
            if (!string.IsNullOrEmpty(keyWord))
            {
                if (searchType == 1)
                {
                    condition.And(t => t.Code.Contains(keyWord));
                }
                if (searchType == 2)
                {
                    condition.And(t => t.Account.Contains(keyWord));
                }
                if (searchType == 3)
                {
                    condition.And(t => t.Name.Contains(keyWord));
                }
            }
            using (var ctx = new BPMSEntities())
            {
                var list = from a in ctx.UserInfo
                           join b in ctx.Organization on a.CompanyId equals b.ID
                           join c in ctx.Organization on a.DepartmentId equals c.ID
                           join d in ctx.Organization on a.WorkgroupId equals d.ID
                           select new
                {
                    a.ID,
                    a.Code,
                    a.Account,
                    a.Name,
                    a.Spell,
                    a.Alias,
                    a.RoleId,
                    a.Gender,
                    a.Mobile,
                    a.Telephone,
                    a.Birthday,
                    a.Email,
                    a.OICQ,
                    a.DutyId,
                    a.TitleId,
                    a.CompanyId,
                    CompanyName = b.Name,
                    a.DepartmentId,
                    DepartmentName = c.Name,
                    a.WorkgroupId,
                    WorkgroupName = d.Name,
                    a.ChangePasswordDate,
                    a.IPAddress,
                    a.MACAddress,
                    a.LogOnCount,
                    a.FirstVisit,
                    a.PreviousVisit,
                    a.LastVisit,
                    a.Remark,
                    a.IsEnable,
                    a.SortIndex,
                    a.CreateDate,
                    a.CreateUserId,
                    a.CreateUserName,
                    a.ModifyUserId,
                    a.ModifyDate,
                    a.ModifyUserName
                };
                count = list.Count();
                list  = list.Skip((pageIndex - 1) * pageSize).Take(pageSize);
                return(ConvertHelper.ToDataTable(list.ToList().Cast <object>().ToArray()));
            }
        }
Example #27
0
 internal bool Delete(BPMSEntities mc, Expression <Func <TModel, bool> > condition)
 {
     return(dal.Delete(mc, condition));
 }
Example #28
0
 internal TModel GetModel(BPMSEntities mc, Expression <Func <TModel, bool> > condition)
 {
     return(dal.GetModel(mc, condition));
 }
Example #29
0
        public IList GetList(Expression <Func <T, bool> > condition)
        {
            BPMSEntities ctx = null;

            return(GetList(ctx, condition));
        }
Example #30
0
 internal bool Delete(BPMSEntities mc, TModel model)
 {
     return(dal.Delete(mc, model));
 }