Ejemplo n.º 1
0
        public static RoleModel CreateRole(string name, string description = "")
        {
            using (var db = SysContext.GetCurrent())
            {
                var oldItem = db.Roles.FirstOrDefault(r => r.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
                if (oldItem != null)
                {
                    throw new Exception("角色已存在");
                }
                var  newID = db.GetNextRoleID();
                Role role  = new Role {
                    RoleID = newID, Name = name, Description = description
                };
                role.ResetCreated();
                db.Roles.Add(role);
                var user = SysService.GetCurrentUser();
                if (user.UserID != "U00001")
                {
                    UserRole ur = new UserRole
                    {
                        UserID = user.UserID,
                        RoleID = role.RoleID
                    };
                    ur.ResetCreated();
                    db.UserRoles.Add(ur);
                }
                db.SaveChanges();

                return(new RoleModel {
                    RoleID = newID, Name = name, Description = description
                });
            }
        }
Ejemplo n.º 2
0
        public static string Messages()//逐条显示当前用户消息
        {
            string id = SysService.GetCurrentUser().UserID;

            //string str="server='10.1.15.235';database='PA_Sys';uid='pguser';pwd='sa123456'";
            //SqlConnection con = new SqlConnection(str);
            //con.Open();
            //string strsql = "select * FROM [dbo].[hr_fl_MessageRemind]('1'," + "'" + id + "'" + ")";
            //SqlCommand cmd = new SqlCommand(strsql, con);
            //SqlDataReader rd = cmd.ExecuteReader();
            using (var db = new SysContext())
            {
                db.Database.Connection.Open();
                var cmd = db.Database.Connection.CreateCommand();

                cmd.CommandText = "select * FROM [dbo].[hr_fl_MessageRemind]('1'," + "'" + id + "'" + ")";
                List <UserMessage> ls = new List <UserMessage>();
                using (var reader = cmd.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                {
                    while (reader.Read())
                    {
                        UserMessage um = new UserMessage();
                        um.MsgTitle = reader["MsgTitle"].ToString();
                        um.Count    = Convert.ToInt32(reader["Count"]);
                        um.MsgUrl   = reader["MsgUrl"].ToString();
                        ls.Add(um);
                    }
                    reader.Close();
                }
                db.Database.Connection.Close();
                return(ls.ToJson());
            }
        }
Ejemplo n.º 3
0
        public virtual void ResetUpdated()
        {
            var user = SysService.GetCurrentUser();

            if (user != null)
            {
                ModifiedUser = user.UserID;
                ModifiedTime = DateTime.Now;
            }
        }
Ejemplo n.º 4
0
        public static List <UserModel> GetUsers(string nameOrEmail, bool isValid, string email, string fullname)
        {
            using (var db = SysContext.GetCurrent())
            {
                Func <User, bool> nameWhere = (u) => true;

                var query = db.Users.Where(u => u.IsValid == isValid && u.UserName != "admin").ToList();
                var user  = SysService.GetCurrentUser();
                if (user != null && user.UserID != "U00001")
                {
                    var companyfilter = ((from u in db.Users
                                          join sr in db.UserRoles on u.UserID equals sr.UserID
                                          join rp in db.RolePages on sr.RoleID equals rp.RoleID
                                          where (u.UserID.Equals(user.UserID) && rp.PageID.Equals("P01001"))
                                          select rp.DataFilter.ToString()).Distinct()).ToList();
                    var deptfilter = ((from u in db.Users
                                       join sr in db.UserRoles on u.UserID equals sr.UserID
                                       join rp in db.RolePages on sr.RoleID equals rp.RoleID
                                       where (u.UserID.Equals(user.UserID) && rp.PageID.Equals("P01002"))
                                       select rp.DataFilter.ToString()).Distinct()).ToList();
                    List <string> eu = new List <string>();

                    eu = (from e in db.hr_Employees where (deptfilter.Contains(e.DeptID) || deptfilter.Contains(e.CompanyID)) select e.UserID).Distinct().ToList();

                    if (eu.Count != 0)
                    {
                        query = query.Where(u => eu.Contains(u.UserID)).ToList();
                    }
                }
                if (!string.IsNullOrEmpty(nameOrEmail) || !string.IsNullOrEmpty(email) || !string.IsNullOrEmpty(fullname))
                {
                    query = string.IsNullOrEmpty(nameOrEmail) ? query : query.Where(u => u.UserName.Contains(nameOrEmail)).ToList();
                    query = string.IsNullOrEmpty(email) ? query : query.Where(u => u.Email.Contains(email)).ToList();
                    query = string.IsNullOrEmpty(fullname) ? query : query.Where(u => u.FullName.Contains(fullname)).ToList();
                }

                // UserDatagrid ud = new UserDatagrid();

                //  var demo = "";
                return(query
                       .Select((u) => new UserModel
                {
                    UserID = u.UserID,
                    UserName = u.UserName,
                    FullName = u.FullName,
                    Email = u.Email,
                    Roles = (from r in db.Roles join s in db.UserRoles on r.RoleID equals s.RoleID where s.UserID.Equals(u.UserID) select r.Name.ToString()).ToArray(),
                    Company = (from em in db.hr_Employees join com in db.hr_Companies on em.CompanyID equals com.CompanyID where em.UserID.Equals(u.UserID) select com.Name).FirstOrDefault(),
                    Dept = (from em in db.hr_Employees join dept in db.hr_Depts on em.DeptID equals dept.DeptID where em.UserID.Equals(u.UserID) select dept.Name.ToString()).FirstOrDefault(),
                    Job = (from em in db.hr_Employees join job in db.hr_Jobs on em.JobID equals job.JobID where em.UserID.Equals(u.UserID) select job.Name.ToString()).FirstOrDefault(),
                    IsValid = u.IsValid
                }).ToList());
            }
        }
Ejemplo n.º 5
0
        public static int MessagesCount()//消息总数
        {
            string id = SysService.GetCurrentUser().UserID;

            using (var db = new SysContext()) {
                db.Database.Connection.Open();
                var cmd = db.Database.Connection.CreateCommand();
                cmd.CommandText = "select isnull(Counts,0) from (select sum(Count)as Counts FROM [dbo].[hr_fl_MessageRemind]('1'," + "'" + id + "'" + "))a";
                var a  = cmd.ExecuteScalar();
                int mc = System.Int32.Parse(a.ToString());
                return(mc);
            }
        }
Ejemplo n.º 6
0
        public static int GetCurrentUserPageActionValue(string pageID)
        {
            var user = SysService.GetCurrentUser();

            if (user == null)
            {
                return(0);
            }
            if (user.UserID.Equals("U00001"))
            {
                return(0x7FFFFFFF);
            }
            var userPage = GetUserPage(user.UserID, pageID);

            return(userPage == null ? 0 : userPage.ActionValue);
        }
Ejemplo n.º 7
0
 public static void AddLog(string actionName, string url, string description = "", string userName = "")
 {
     using (var db = SysContext.GetCurrent())
     {
         var user   = SysService.GetCurrentUser();
         var newLog = new UserLog
         {
             ActionName  = actionName,
             Url         = url,
             Description = description,
             ClientIP    = HttpContext.Current.Request.GetClientIPAddress(),
             UserName    = user == null ? userName : user.FullName
         };
         newLog.ResetCreated();
         db.UserLogs.Add(newLog);
         db.SaveChanges();
     }
 }
Ejemplo n.º 8
0
 public static List <RoleModel> GetRoles(string searchName, string description)
 {
     using (var db = SysContext.GetCurrent())
     {
         var user = SysService.GetCurrentUser();
         if (user.UserID == "U00001")
         {
             return(GetRoles());
         }
         else
         {
             return((from r in db.Roles join ur in db.UserRoles on r.RoleID equals ur.RoleID where ur.UserID.Equals(user.UserID) select r)
                    .Select(r => new RoleModel
             {
                 RoleID = r.RoleID,
                 Name = r.Name,
                 Description = r.Description
             }).ToList());
         }
     }
 }
Ejemplo n.º 9
0
 public static bool ChangePassword(string oldpassword, string password)
 {
     using (var db = SysContext.GetCurrent())
     {
         string id      = SysService.GetCurrentUser().UserID;
         var    oldUser = db.Users.FirstOrDefault(u => u.UserID.Equals(id));
         var    op      = oldpassword.GetMd5_32();
         var    np      = password.GetMd5_32();
         if (oldUser != null && oldUser.Password == op)
         {
             oldUser.Password = np;
             oldUser.ResetUpdated();
             db.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Ejemplo n.º 10
0
        public string Query(Dictionary <string, string> request)
        {
            string name    = request.GetDictionaryValue("name", "");
            var    sqlItem = SqlData.Current.GetShare(name);

            if (sqlItem == null)
            {
                throw LangTexts.Current.GetFormatLangText("9002", "请求查询[{0}] 未定义!", name)
                      .CreateException();
            }
            //权限判断
            if ((!string.IsNullOrEmpty(sqlItem.AuthPage)) && sqlItem.AuthValue > 0)
            {
                var actionValue = SysService.GetCurrentUserPageActionValue(sqlItem.AuthPage);
                if ((sqlItem.AuthValue & actionValue) != actionValue)
                {
                    throw LangTexts.Current.GetFormatLangText("1002", "对不起,您没有使用功能[{0}]的权限,谢谢理解!", sqlItem.SharedName)
                          .CreateException();
                }
            }

            List <string> configParas  = new List <string>();
            string        resultFormat = request.GetDictionaryValue("resultformat", "");

            Func <IEnumerable <Entity>, string> converter = null;

            configParas.Add("name");
            configParas.Add("resultformat");
            if (!string.IsNullOrEmpty(resultFormat))
            {
                configParas.Add("root");
                configParas.Add("pid");
                configParas.Add("id");
                configParas.Add("text");
                configParas.Add("checked");
                switch (resultFormat)
                {
                case "jsontree":
                    string root      = request.GetDictionaryValue("root", "");
                    string pid       = request.GetDictionaryValue("pid", "");
                    string id        = request.GetDictionaryValue("id", "");
                    string text      = request.GetDictionaryValue("text", "");
                    string checkedid = request.GetDictionaryValue("checked", "");
                    converter = (items) =>
                    {
                        return(items.CreateJsonTree(root, pid, id, text, checkedid));
                    };
                    break;
                }
            }

            var           sqlparas = sqlItem.CommandText.GetParameters().Where(p => char.IsUpper(p[0])).ToList();
            List <object> paras    = new List <object>();

            foreach (var item in request.Where(k => !configParas.Contains(k.Key)))
            {
                if (item.Key.Equals("UserID", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                paras.Add(item.Key);
                paras.Add(item.Value);

                sqlparas.Remove(sqlparas.FirstOrDefault(p => p.Equals(item.Key, StringComparison.OrdinalIgnoreCase)));
            }

            if (sqlparas.Count > 0 && sqlparas.FirstOrDefault(p => p.Equals("UserID", StringComparison.OrdinalIgnoreCase)) != null)
            {
                var user = SysService.GetCurrentUser();
                if (user != null)
                {
                    paras.Add("UserID");
                    paras.Add(user.UserID);
                }
            }
            return(converter == null?sqlItem.ExecuteJson(paras.ToArray()) :
                       converter(sqlItem.ExecuteQuery <Entity>(paras.ToArray())));
        }