Exemple #1
0
        public bool RoleSave(string loginKey, ref ErrorInfo err, TRole inEnt, IList <string> allPar)
        {
            if (!GlobalFun.UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(false);
            }
            using (DBEntities db = new DBEntities())
            {
                try
                {
                    var ent = db.fa_role.SingleOrDefault(a => a.ID == inEnt.ID);

                    bool isAdd = false;
                    if (ent == null)
                    {
                        isAdd  = true;
                        ent    = Fun.ClassToCopy <ProInterface.Models.ROLE, fa_role>(inEnt);
                        ent.ID = Fun.GetSeqID <fa_role>();
                    }
                    else
                    {
                        ent = Fun.ClassToCopy <ProInterface.Models.ROLE, fa_role>(inEnt, ent, allPar);
                    }

                    ent.fa_module.Clear();
                    IList <int> moduleID = inEnt.ModuleAllStr.Split(',').Select(x => Convert.ToInt32(x)).ToList();
                    ent.fa_module     = db.fa_module.Where(x => moduleID.Contains(x.ID)).ToList();
                    inEnt.RoleConfigs = JSON.EncodeToEntity <IList <ROLE_CONFIG> >(inEnt.RoleConfigsStr);
                    foreach (var t in inEnt.RoleConfigs)
                    {
                        var cfg = ent.fa_role_config.SingleOrDefault(x => x.NAME == t.NAME);
                        if (cfg == null)
                        {
                            ent.fa_role_config.Add(new fa_role_config
                            {
                                NAME    = t.NAME,
                                ROLE_ID = ent.ID,
                                VALUE   = t.VALUE
                            });
                        }
                        else
                        {
                            cfg.VALUE = t.VALUE;
                        }
                    }
                    foreach (var t in ent.fa_role_config.ToList())
                    {
                        if (inEnt.RoleConfigs.SingleOrDefault(x => x.NAME == t.NAME) == null)
                        {
                            db.fa_role_config.Remove(t);
                        }
                    }

                    if (isAdd)
                    {
                        db.fa_role.Add(ent);
                    }
                    db.SaveChanges();
                    GlobalFun.UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Edit);
                    return(true);
                }
                catch (DbEntityValidationException e)
                {
                    err.IsError = true;
                    err.Message = e.Message;
                    err.Excep   = e;
                    return(false);
                }
            }
        }
Exemple #2
0
        public static GlobalUser Add(int userId, string loginIP)
        {
            GlobalUser reEnt  = new GlobalUser();
            var        entArr = OnLines.Where(a => a.UserId == userId && a.LoginIP == loginIP).ToList();

            if (entArr.Count() > 0)
            {
                reEnt            = entArr[0];
                reEnt.LastOpTime = DateTime.Now;
                return(reEnt);
            }

            lock (symObj)
            {
                using (DBEntities db = new DBEntities())
                {
                    var user = db.fa_user.SingleOrDefault(x => x.ID == userId);

                    string loginKey = Guid.NewGuid().ToString().Replace("-", "");
                    ClearTimeOutUser();


                    IList <string> idArr = new List <string>();
                    var            dis   = user.fa_district;
                    var            tmp   = dis;
                    while (tmp != null)
                    {
                        idArr.Add(tmp.ID.ToString());
                        tmp = tmp.fa_district2;
                    }
                    string tmpRuleRegionList = "";
                    if (user.fa_district1.Count() > 0)
                    {
                        tmpRuleRegionList = string.Format("'{0}'", string.Join("','", user.fa_district1.Select(x => x.CODE).ToList()));
                    }
                    else
                    {
                        tmpRuleRegionList = string.Format("'{0}'", user.DISTRICT_ID);
                    }


                    reEnt = new GlobalUser
                    {
                        Guid          = loginKey,
                        UserId        = userId,
                        DistrictId    = user.DISTRICT_ID,
                        LastOpTime    = DateTime.Now,
                        RoleID        = user.fa_role.Select(y => y.ID).ToList(),
                        UserName      = user.NAME,
                        LoginIP       = loginIP,
                        Region        = user.DISTRICT_ID.ToString(),
                        RegionList    = idArr,
                        RuleRegionStr = tmpRuleRegionList,
                        LevelId       = user.fa_district.LEVEL_ID,
                        LoginName     = user.LOGIN_NAME,
                        DistrictCode  = user.fa_district.CODE
                    };
                    OnLines.Add(reEnt);

                    Save();

                    #region 记录登录历史
                    var tmp_user = db.fa_user.SingleOrDefault(x => x.ID == userId);
                    if (tmp_user.LOGIN_COUNT == null)
                    {
                        tmp_user.LOGIN_COUNT = 0;
                    }
                    tmp_user.LOGIN_COUNT++;
                    tmp_user.LAST_LOGIN_TIME = DateTime.Now;
                    if (ProInterface.AppSet.WiteLoginLog)
                    {
                        fa_login_history hist = new fa_login_history();
                        hist.ID         = Fun.GetSeqID <fa_login_history>();
                        hist.USER_ID    = userId;
                        hist.LOGIN_TIME = DateTime.Now;
                        hist.LOGIN_HOST = loginIP;
                        db.fa_login_history.Add(hist);
                        GetUser(loginKey).loginHistoryId = hist.ID;
                    }
                    ErrorInfo err = new ErrorInfo();
                    Fun.DBEntitiesCommit(db, ref err);

                    #endregion

                    //var Watermark = PicFun.CreateWatermark(ProInterface.AppSet.SysName, reEnt.UserName);
                    //try
                    //{
                    //    File.WriteAllBytes(string.Format("{0}/UpFiles/{1}.jpg", AppDomain.CurrentDomain.BaseDirectory, reEnt.Guid), Watermark);
                    //}
                    //catch { }
                    return(reEnt);
                }
            }
        }
Exemple #3
0
        public bool ScriptSave(string loginKey, ref ErrorInfo err, TScript inEnt, IList <string> allPar)
        {
            GlobalUser gu = Global.GetUser(loginKey);

            if (gu == null)
            {
                err.IsError = true;
                err.Message = "登录超时";
                return(false);
            }

            if (!UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(false);
            }
            using (DBEntities db = new DBEntities())
            {
                try
                {
                    var  ent   = db.YL_SCRIPT.SingleOrDefault(a => a.ID == inEnt.ID);
                    bool isAdd = false;
                    if (ent == null)
                    {
                        isAdd  = true;
                        ent    = Fun.ClassToCopy <ProInterface.Models.TScript, YL_SCRIPT>(inEnt);
                        ent.ID = Fun.GetSeqID <YL_SCRIPT>();
                    }
                    else
                    {
                        if (!ent.BODY_TEXT.Equals(inEnt.BODY_TEXT))
                        {
                            inEnt.BODY_TEXT = string.Format("//{0}于{1}修改\r\n{2}", gu.UserName, DateTime.Now.ToString(), inEnt.BODY_TEXT);
                        }

                        ent = Fun.ClassToCopy <ProInterface.Models.TScript, YL_SCRIPT>(inEnt, ent, allPar);
                    }
                    if (!string.IsNullOrEmpty(inEnt.ScriptGroupListJosn))
                    {
                        inEnt.ScriptGroupList = JSON.EncodeToEntity <IList <SCRIPT_GROUP_LIST> >(inEnt.ScriptGroupListJosn);
                    }
                    foreach (var t in inEnt.ScriptGroupList)
                    {
                        var single = ent.YL_SCRIPT_GROUP_LIST.SingleOrDefault(x => x.SCRIPT_ID == t.SCRIPT_ID);
                        if (single == null)
                        {
                            single          = Fun.ClassToCopy <ProInterface.Models.SCRIPT_GROUP_LIST, YL_SCRIPT_GROUP_LIST>(t);
                            single.GROUP_ID = ent.ID;
                            ent.YL_SCRIPT_GROUP_LIST.Add(single);
                        }
                        else
                        {
                            single.ORDER_INDEX = t.ORDER_INDEX;
                        }
                    }

                    foreach (var t in ent.YL_SCRIPT_GROUP_LIST.ToList())
                    {
                        var single = inEnt.ScriptGroupList.SingleOrDefault(x => x.SCRIPT_ID == t.SCRIPT_ID);
                        if (single == null)
                        {
                            db.YL_SCRIPT_GROUP_LIST.Remove(t);
                        }
                    }

                    if (isAdd)
                    {
                        db.YL_SCRIPT.Add(ent);
                    }
                    db.SaveChanges();
                    UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Edit);
                    return(true);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = e.Message;
                    return(false);
                }
            }
        }
Exemple #4
0
        public bool UserMessageSaveByGlobalUser(GlobalUser gu, ref ErrorInfo err, ProInterface.Models.MESSAGE inEnt, IList <string> allPar, string allUserIdStr = null)
        {
            using (DBEntities db = new DBEntities())
            {
                var         disId     = string.Format(".{0}.", inEnt.DISTRICT_ID);
                IList <int> allUserId = new List <int>();
                IList <int> allRole   = new List <int>();
                IList <int> allUser   = new List <int>();
                if (!string.IsNullOrEmpty(inEnt.ALL_ROLE_ID))
                {
                    allRole = inEnt.ALL_ROLE_ID.Split(',').Select(x => Convert.ToInt32(x)).ToList();
                }
                if (!string.IsNullOrEmpty(allUserIdStr))
                {
                    allUser = allUserIdStr.Split(',').Select(x => Convert.ToInt32(x)).ToList();
                }
                if (allUser.Count() > 0)
                {
                    allUserId = db.YL_USER.Where(x => allUser.Contains(x.ID) && (x.YL_DISTRICT.ID_PATH.IndexOf(disId) > -1 || x.DISTRICT_ID == inEnt.DISTRICT_ID)).Select(x => x.ID).ToList();
                }
                else if (allRole.Count() == 0)
                {
                    allUserId = db.YL_USER.Where(x => x.YL_DISTRICT.ID_PATH.IndexOf(disId) > -1).Select(x => x.ID).ToList();
                }
                else
                {
                    allUserId = db.YL_USER.Where(x => x.YL_ROLE.Where(y => allRole.Contains(y.ID)).Count() > 0 && (x.DISTRICT_ID == inEnt.DISTRICT_ID || x.YL_DISTRICT.ID_PATH.IndexOf(disId) > -1)).Select(x => x.ID).ToList();
                }

                YL_MESSAGE message = new YL_MESSAGE();
                bool       isAdd   = false;
                if (inEnt.ID == 0)
                {
                    isAdd   = true;
                    message = Fun.ClassToCopy <ProInterface.Models.MESSAGE, YL_MESSAGE>(inEnt);
                    if (message.MESSAGE_TYPE_ID == null)
                    {
                        message.MESSAGE_TYPE_ID = 1;
                    }
                    message.ID              = Fun.GetSeqID <YL_MESSAGE>();
                    message.CREATE_TIME     = DateTime.Now;
                    message.CREATE_USERNAME = gu.UserName;
                    message.CREATE_USERID   = gu.UserId;
                    var allUserList  = db.YL_USER.Where(x => allUserId.Contains(x.ID)).ToList();
                    var tmpLoginName = allUserList.Select(x => x.LOGIN_NAME).ToList();
                    var allLogin     = db.YL_LOGIN.Where(x => tmpLoginName.Contains(x.LOGIN_NAME)).ToList();
                    foreach (var t in allUserList)
                    {
                        var login = allLogin.SingleOrDefault(x => x.LOGIN_NAME == t.LOGIN_NAME);
                        if (login != null && login.PHONE_NO != null)
                        {
                            YL_USER_MESSAGE tmp = new YL_USER_MESSAGE();
                            tmp.MESSAGE_ID  = message.ID;
                            tmp.USER_ID     = t.ID;
                            tmp.PHONE_NO    = login.PHONE_NO;
                            tmp.STATUS      = "等待";
                            tmp.STATUS_TIME = DateTime.Now;


                            if (message.PUSH_TYPE == "短信推送")
                            {
                                SmsSendAdd(db, login.PHONE_NO, message.CONTENT, message.ID);
                                tmp.STATUS = "已推送";
                            }
                            tmp.PUSH_TYPE = message.PUSH_TYPE;
                            message.YL_USER_MESSAGE.Add(tmp);
                        }
                    }
                }
                else
                {
                    message = db.YL_MESSAGE.Single(x => x.ID == inEnt.ID);
                    message = Fun.ClassToCopy <ProInterface.Models.MESSAGE, YL_MESSAGE>(inEnt, message, allPar);
                }

                if (isAdd)
                {
                    db.YL_MESSAGE.Add(message);
                }
                db.SaveChanges();
            }
            return(true);
        }
Exemple #5
0
        public IList <QueryCfg> QueryGetCfg(string loginKey, ref ErrorInfo err, string sql, string queryCode)
        {
            using (DBEntities db = new DBEntities())
            {
                var query = db.YL_QUERY.SingleOrDefault(x => x.CODE == queryCode);

                IList <QueryCfg> nowCfgList = new List <QueryCfg>();
                GlobalUser       gu         = Global.GetUser(loginKey);
                if (gu == null)
                {
                    err.IsError = true;
                    err.Message = "用户登录超时,请重新登录";
                    return(nowCfgList);
                }

                if (sql.IndexOf("<sql>") > -1)
                {
                    var xml = XmlHelper.Document.Load(sql);
                }



                sql = ReplacePer(sql, gu, null);


                DataTable dt = new DataTable();
                try
                {
                    dt = ExecuteGetNullTable(query.DB_SERVER_ID.Value, sql);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetExceptionMessage(e);
                    return(nowCfgList);
                }
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    var            t          = dt.Columns[i];
                    var            tmp        = t.DataType.FullName.ToLower().Substring(t.DataType.FullName.IndexOf(".") + 1);
                    IList <string> numberList = new[] { "int", "decimal", "double", "int64", "int16" };
                    if (numberList.Contains(tmp))
                    {
                        tmp = "int";
                    }
                    string searchType   = "";
                    string searchScript = null;
                    switch (tmp)
                    {
                    case "int":
                        searchScript = "$('{@this}').numberbox({min:0,precision:0});";
                        searchType   = "numberbox";
                        break;

                    case "datetime":
                        searchScript = "$('{@this}').datetimebox({showSeconds: false,required: false});";
                        searchType   = "datetimebox";
                        break;

                    default:
                        searchType = "text";
                        break;
                    }

                    nowCfgList.Add(new QueryCfg()
                    {
                        FieldName    = t.ColumnName,
                        Show         = true,
                        FieldType    = t.DataType.FullName,
                        Width        = 0,
                        CanSearch    = true,
                        SearchType   = searchType,
                        SearchScript = searchScript,
                        Sortable     = true,
                        Alias        = t.Caption
                    });
                }
                #region 获取当前状态
                {
                    var queryEnt = db.YL_QUERY.SingleOrDefault(x => x.CODE == queryCode);
                    if (queryEnt != null)
                    {
                        IList <QueryCfg> old = JSON.EncodeToEntity <IList <QueryCfg> >(queryEnt.QUERY_CFG_JSON);
                        if (old != null)
                        {
                            for (int i = 0; i < nowCfgList.Count; i++)
                            {
                                var t0 = old.SingleOrDefault(x => x.FieldName == nowCfgList[i].FieldName);
                                if (t0 != null)
                                {
                                    nowCfgList[i] = t0;
                                }
                            }
                        }
                    }
                }
                #endregion
                return(nowCfgList);
            }
        }
Exemple #6
0
        /// <summary>
        /// 查询一条
        /// </summary>
        /// <param name="loginKey">登录凭证</param>
        /// <param name="err">错误信息</param>
        /// <param name="code">代码</param>
        /// <returns>查询一条</returns>
        public ProInterface.Models.TQuery QuerySingleByCode(string loginKey, ref ProInterface.ErrorInfo err, string code)
        {
            if (!UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(null);
            }
            using (DBEntities db = new DBEntities())
            {
                var queryEnt = db.YL_QUERY.Where(x => x.CODE == code).ToList();

                if (queryEnt.Count > 0)
                {
                    var        reEnt = Fun.ClassToCopy <YL_QUERY, ProInterface.Models.TQuery>(queryEnt[0]);
                    GlobalUser gu    = Global.GetUser(loginKey);
                    if (gu == null)
                    {
                        err.IsError = true;
                        err.Message = "登录超时";
                        return(null);
                    }



                    var allAuth = queryEnt[0].YL_ROLE_QUERY_AUTHORITY.Where(x => gu.RoleID.Contains(x.ROLE_ID)).ToList();
                    foreach (var t in allAuth)
                    {
                        if (reEnt.NoAuthority == null)
                        {
                            if (t.NO_AUTHORITY == null)
                            {
                                reEnt.NoAuthority = "";
                            }
                            else
                            {
                                reEnt.NoAuthority = t.NO_AUTHORITY;
                            }
                        }
                        else
                        {
                            if (reEnt.NoAuthority == null)
                            {
                                reEnt.NoAuthority = "";
                            }
                            if (t.NO_AUTHORITY == null)
                            {
                                t.NO_AUTHORITY = "";
                            }
                            var allNowAuth = reEnt.NoAuthority.Split(',').ToList();
                            var thisAuth   = t.NO_AUTHORITY.Split(',');
                            foreach (var t0 in reEnt.NoAuthority.Split(',').ToList())
                            {
                                if (!thisAuth.Contains(t0))
                                {
                                    allNowAuth.Remove(t0);
                                }
                            }
                            reEnt.NoAuthority = string.Join(",", allNowAuth);
                        }
                    }
                    return(reEnt);
                }
                return(null);
            }
        }
Exemple #7
0
        /// <summary>
        /// 查询权限检查
        /// </summary>
        /// <param name="loginKey"></param>
        /// <param name="err"></param>
        /// <param name="code"></param>
        /// <param name="methodBase"></param>
        /// <returns></returns>
        public bool QueryCheckFunctioAuthority(string loginKey, ref ErrorInfo err, string code, MethodBase methodBase = null)
        {
            GlobalUser gu = Global.GetUser(loginKey);

            if (gu == null)
            {
                err.IsError = true;
                err.Message = "登录超时,请重新登录";
                return(false);
            }
            using (DBEntities db = new DBEntities())
            {
                #region 角色模板权限控制
                var    user        = db.YL_USER.SingleOrDefault(x => x.ID == gu.UserId);
                var    roles       = db.YL_ROLE.Where(x => gu.RoleID.Contains <int>(x.ID)).ToList();
                string str         = string.Format("~/Query/Query?code={0}", code);
                var    moduleCount = user.YL_MODULE.Where(x => x.LOCATION == str).Count();
                if (moduleCount == 0)
                {
                    foreach (var i in roles)
                    {
                        moduleCount = i.YL_MODULE.Where(x => x.LOCATION == str).Count();
                        if (moduleCount != 0)
                        {
                            break;
                        }
                    }
                    if (moduleCount == 0)
                    {
                        err.IsError = true;
                        err.Message = "您没有此模块的权限";
                        return(false);
                    }
                }
                #endregion

                #region  键权限控制
                var            queryEnt   = db.YL_QUERY.Where(x => x.CODE == code).ToList();
                IList <string> allNowAuth = null;
                if (queryEnt.Count > 0)
                {
                    var allAuth     = queryEnt[0].YL_ROLE_QUERY_AUTHORITY.Where(x => gu.RoleID.Contains(x.ROLE_ID)).ToList();
                    var noAuthority = string.Empty;
                    foreach (var t in allAuth)
                    {
                        if (t.NO_AUTHORITY == null)
                        {
                            return(true);
                        }
                        else
                        {
                            noAuthority = t.NO_AUTHORITY;
                        }

                        allNowAuth = noAuthority.Split(',').ToList();
                        var thisAuth = t.NO_AUTHORITY.Split(',');
                        foreach (var t0 in noAuthority.Split(',').ToList())
                        {
                            if (!thisAuth.Contains(t0))
                            {
                                allNowAuth.Remove(t0);
                            }
                        }
                    }
                    if (noAuthority.IsNullOrEmpty())
                    {
                        return(true);
                    }
                    if (methodBase != null)
                    {
                        if (methodBase.Name == "DownFile")
                        {
                            if (allNowAuth.Contains <string>("导出"))
                            {
                                err.IsError = true;
                                err.Message = "您没有此查询的导出权限";
                                return(false);
                            }
                        }
                    }
                }
                #endregion
            }
            return(true);
        }