Ejemplo n.º 1
0
 public IEnumerable <dynamic> GetAllButtons()
 {
     using (var db = new SysContext())
     {
         return(db.sys_button.SqlQuery("select * from sys_button order by ButtonSeq").ToList());
     }
 }
Ejemplo n.º 2
0
        public sys_user Login(string user, string pass)
        {
            sys_user u = null;

            using (var db = new SysContext())
            {
                u = db.sys_user.Find(user);
                if (u != null)
                {
                    if (!u.Password.Equals(pass))
                    {
                        // 密码错误
                        u = null;
                    }
                    //else if (u.IsEnable.HasValue && !u.IsEnable.Value)
                    else if (!u.IsEnable)
                    {
                        // 帐户未启用
                        u = null;
                    }
                }

                if (u != null)
                {
                    u.LoginCount++;
                    u.LastLoginDate = DateTime.Now;
                    db.SaveChanges();
                }
            }
            return(u);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 为指定表请求新的序列号
 /// </summary>
 /// <param name="table">应用表名</param>
 /// <param name="cycle">周期值,当此值不为空同时与当前最后周期值不同时序列号重新从1开始</param>
 /// <param name="updateSerial">是否保存序列号的更新</param>
 /// <returns>新的序列号</returns>
 public int GetNewSerial(string table, int?cycle = null, bool updateSerial = true)
 {
     using (var db = new SysContext())
     {
         return(GetNewSerial(db, table, cycle, updateSerial));
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 为指定表请求新的序列号
        /// </summary>
        /// <param name="db">数据上下文</param>
        /// <param name="table">应用表名</param>
        /// <param name="cycle">周期值,当此值不为空同时与当前最后周期值不同时序列号重新从1开始</param>
        /// <param name="updateSerial">是否保存序列号的更新</param>
        /// <returns>新的序列号</returns>
        public int GetNewSerial(SysContext db, string table, int?cycle = null, bool updateSerial = true)
        {
            var serial = db.sys_serial.Find(table);

            if (serial == null)
            {
                if (updateSerial)
                {
                    serial = new sys_serial {
                        Table = table, Cycle = cycle, Serial = 1
                    };
                    db.sys_serial.Add(serial);
                    db.SaveChanges();
                }
                return(1);
            }
            if (serial.Cycle != cycle)
            {
                if (updateSerial)
                {
                    serial.Cycle  = cycle;
                    serial.Serial = 1;
                    db.SaveChanges();
                }
                return(1);
            }
            serial.Serial++;
            if (updateSerial)
            {
                db.SaveChanges();
            }
            return(serial.Serial);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 获取指定用户的菜单列表
 /// </summary>
 /// <param name="userCode">用户代码</param>
 /// <param name="includeHidden">是否包括不显示(但启用)的菜单项</param>
 /// <returns></returns>
 public IEnumerable <sys_menu> GetUserMenuList(string userCode, bool includeHidden = false)
 {
     using (var db = new SysContext())
     {
         var sql = @"select * from sys_menu where IsVisible=1 and IsEnable=1 and MenuCode in (select MenuCode from sys_roleMenuMap where RoleCode in (select RoleCode from sys_userRoleMap where UserCode=@userCode)) order by MenuSeq";
         if (includeHidden)
         {
             sql = @"select * from sys_menu where IsEnable=1 and MenuCode in (select MenuCode from sys_roleMenuMap where RoleCode in (select RoleCode from sys_userRoleMap where UserCode=@userCode)) order by MenuSeq";
         }
         return(db.sys_menu.SqlQuery(sql, new SqlParameter("@userCode", userCode)).AsNoTracking().ToList());
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 获取所有的系统菜单列表
 /// </summary>
 /// <param name="userCode">用户代码</param>
 /// <returns></returns>
 public IEnumerable <dynamic> GetMenuList()
 {
     using (var db = new SysContext())
     {
         return(db.sys_menu.AsNoTracking().LeftJoin(db.sys_menu, a => a.ParentCode, b => b.MenuCode, (a, b) => new {
             a.MenuCode,
             a.MenuName,
             a.MenuSeq,
             a.ParentCode,
             a.CreateDate,
             a.CreatePerson,
             a.Description,
             a.IconClass,
             a.IconURL,
             a.IsEnable,
             a.IsVisible,
             a.UpdateDate,
             a.UpdatePerson,
             a.URL,
             ParentName = b.MenuName
         }).OrderBy(a => a.MenuSeq).ToList());
     }
 }
Ejemplo n.º 7
0
        public void OnLogined(sys_user user)
        {
            // 记录登录日志
            using (var db = new SysContext())
            {
                var    hostIp     = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                string clientName = null;
                try
                {
                    System.Net.IPAddress   address = System.Net.IPAddress.Parse(hostIp);
                    System.Net.IPHostEntry ipInfor = System.Net.Dns.GetHostEntry(address);
                    clientName = ipInfor.HostName;
                }
                catch { }
                db.sys_loginHistory.Add(new sys_loginHistory
                {
                    UserCode  = user.UserCode,
                    UserName  = user.UserName,
                    HostIP    = hostIp,
                    HostName  = clientName,
                    LoginDate = DateTime.Now
                });
                db.SaveChanges();
            }

            // 执行 Session 初始化
            Dictionary <string, OneConnection> openConnections = new Dictionary <string, OneConnection>();

            foreach (var s in SysSessions)
            {
                try
                {
                    // 准备连接
                    var           connName = string.IsNullOrEmpty(s.Connection) ? DefaultConnection.Name : s.Connection;
                    OneConnection conn     = null;
                    if (openConnections.ContainsKey(connName))
                    {
                        conn = openConnections[connName];
                    }
                    else
                    {
                        conn = openConnections[connName] = CreateOneConnection(connName);
                    }

                    if (!string.IsNullOrEmpty(s.Condition))
                    {
                        // 进行条件测试
                        object val = conn.ExecuteScalar(FruitExpression.Replace(s.Condition));
                        if (val is bool && (bool)val == false)
                        {
                            continue;
                        }
                    }

                    if (!string.IsNullOrEmpty(s.T_SQL))
                    {
                        // 运行查询
                        object val = conn.ExecuteScalar(FruitExpression.Replace(s.T_SQL));
                        if (val != DBNull.Value && val != null)
                        {
                            HttpContext.Current.Session[s.SessionName] = val.ToString();
                            continue;
                        }
                    }

                    if (!string.IsNullOrEmpty(s.DefaultValue))
                    {
                        // 默认值
                        HttpContext.Current.Session[s.SessionName] = FruitExpression.Replace(s.DefaultValue);
                    }
                }
                catch (Exception e) {
                    System.Diagnostics.Debug.WriteLine(e);
                }
            }
            // 关闭所有打开过的连接
            foreach (var conn in openConnections.Values)
            {
                conn.Dispose();
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 测试指定用户是否有特定的菜单权限
        /// </summary>
        /// <param name="userCode"></param>
        /// <param name="menuCode"></param>
        /// <returns></returns>
        public bool MenuVisible(string userCode, string menuCode)
        {
            var db = new SysContext();

            return(db.sys_roleMenuMap.Any(rm => rm.MenuCode == menuCode && rm.sys_role.sys_userRoleMap.Any(ur => ur.UserCode == userCode)));
        }