Example #1
0
 public bool LoginAdd(int appId, LOGIN inEnt)
 {
     using (DBEntities db = new DBEntities())
     {
         var login = db.YL_LOGIN.SingleOrDefault(x => x.LOGIN_NAME == inEnt.LOGIN_NAME);
         var oauth = db.YL_OAUTH.SingleOrDefault(x => x.KEY == appId);
         if (oauth == null)
         {
             return(false);
         }
         if (login == null)
         {
             login    = Fun.ClassToCopy <LOGIN, YL_LOGIN>(inEnt);
             login.ID = Fun.GetSeqID <YL_LOGIN>();
             if (string.IsNullOrEmpty(login.REGION))
             {
                 login.REGION = "1";
             }
             login.YL_OAUTH.Add(oauth);
             db.YL_LOGIN.Add(login);
         }
         else
         {
             if (login.YL_OAUTH.SingleOrDefault(x => x.KEY == appId) == null)
             {
                 login.YL_OAUTH.Add(oauth);
             }
         }
         db.SaveChanges();
         return(true);
     }
 }
Example #2
0
        public DISTRICT DistrictAdd(string loginKey, ref ErrorInfo err, DISTRICT inEnt)
        {
            using (DBEntities db = new DBEntities())
            {
                YL_DISTRICT reEnt = Fun.ClassToCopy <ProInterface.Models.DISTRICT, YL_DISTRICT>(inEnt);
                #region 计算ID_PATH和Level_ID
                if (reEnt.PARENT_ID == null)
                {
                    reEnt.LEVEL_ID = 1;
                    reEnt.ID_PATH  = ".";
                }
                else
                {
                    var parent = db.YL_DISTRICT.Single(x => x.ID == reEnt.PARENT_ID);
                    if (parent == null)
                    {
                        reEnt.LEVEL_ID = 1;
                        reEnt.ID_PATH  = ".";
                    }
                    else
                    {
                        reEnt.ID_PATH  = parent.ID_PATH + reEnt.PARENT_ID + ".";
                        reEnt.LEVEL_ID = parent.LEVEL_ID + 1;
                    }
                }
                #endregion
                reEnt.ID = Fun.GetSeqID <YL_DISTRICT>();
                #region 计算REGION

                GlobalUser gu = Global.GetUser(loginKey);
                if (gu == null)
                {
                    reEnt.REGION = reEnt.ID.ToString();
                }
                else
                {
                    reEnt.REGION = gu.Region;
                }
                #endregion
                reEnt.CODE   = (string.IsNullOrEmpty(inEnt.CODE)) ? reEnt.ID.ToString() : inEnt.CODE;
                reEnt.IN_USE = 1;
                reEnt        = db.YL_DISTRICT.Add(reEnt);
                try
                {
                    db.SaveChanges();
                    UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Add);
                    return(Fun.ClassToCopy <YL_DISTRICT, DISTRICT>(reEnt));
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = e.Message;
                    err.Excep   = e;
                    return(null);
                }
            }
        }
Example #3
0
        /// <summary>
        /// 修改模块
        /// </summary>
        /// <param name="loginKey">登录凭证</param>
        /// <param name="err">错误信息</param>
        /// <param name="inEnt">实体类</param>
        /// <param name="allPar">更新的参数</param>
        /// <returns>修改模块</returns>
        public bool ModuleSave(string loginKey, ref ProInterface.ErrorInfo err, ProInterface.Models.TModule inEnt, IList <string> allPar)
        {
            if (!UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(false);
            }
            using (DBEntities db = new DBEntities())
            {
                try
                {
                    var  ent   = db.YL_MODULE.SingleOrDefault(a => a.ID == inEnt.ID);
                    bool isAdd = false;
                    if (ent == null)
                    {
                        isAdd  = true;
                        ent    = Fun.ClassToCopy <ProInterface.Models.MODULE, YL_MODULE>(inEnt);
                        ent.ID = Fun.GetSeqID <YL_MODULE>();
                    }
                    else
                    {
                        ent = Fun.ClassToCopy <ProInterface.Models.MODULE, YL_MODULE>(inEnt, ent, allPar);
                    }
                    var allRoleId = inEnt.AllRoleIdArrStr.Split(',').Select(x => Convert.ToInt32(x)).ToList();
                    ent.YL_ROLE.Clear();
                    ent.YL_ROLE = db.YL_ROLE.Where(x => allRoleId.Contains(x.ID)).ToList();

                    if (isAdd)
                    {
                        db.YL_MODULE.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);
                }
            }
        }
Example #4
0
        public FILES FilesAdd(string loginKey, ref ErrorInfo err, FILES inEnt)
        {
            if (!UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(null);
            }
            GlobalUser gu = Global.GetUser(loginKey);

            if (gu == null)
            {
                err.IsError = true;
                err.Message = "登录超时";
                return(null);
            }
            using (DBEntities db = new DBEntities())
            {
                inEnt.ID      = Fun.GetSeqID <YL_FILES>();
                inEnt.USER_ID = gu.UserId;
                YL_FILES reEnt = Fun.ClassToCopy <ProInterface.Models.FILES, YL_FILES>(inEnt);
                reEnt = db.YL_FILES.Add(reEnt);
                try
                {
                    db.SaveChanges();
                    UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Add);
                    inEnt.ID          = reEnt.ID;
                    inEnt.UPLOAD_TIME = null;
                    return(inEnt);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = e.Message;
                    err.Excep   = e;
                    return(null);
                }
            }
        }
Example #5
0
        public bool TaskFlowSave(string loginKey, ref ProInterface.ErrorInfo err, ProInterface.Models.TTaskFlow inEnt, IList <string> allPar)
        {
            if (!UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(false);
            }
            using (DBEntities db = new DBEntities())
            {
                GlobalUser gu = Global.GetUser(loginKey);
                if (gu == null)
                {
                    err.IsError = true;
                    err.Message = "登录超时";
                    return(false);
                }
                var flow = db.YL_TASK_FLOW.Single(x => x.ID == inEnt.ID);
                if (string.IsNullOrEmpty(inEnt.ROLE_ID_STR)) //无转派
                {
                    flow.DEAL_STATUS = "处理完成";
                    if (flow.PARENT_ID != null) //有上级
                    {
                        //是否全部处理
                        var noDealNum = flow.YL_TASK_FLOW2.YL_TASK_FLOW1.Where(x => x.IS_HANDLE == 0 && x.ID != flow.ID).Count();
                        if (noDealNum == 0)
                        {
                            var taskFlowNext2 = new YL_TASK_FLOW();
                            taskFlowNext2.ID             = Fun.GetSeqID <YL_TASK_FLOW>();
                            taskFlowNext2.HANDLE_USER_ID = flow.YL_TASK_FLOW2.HANDLE_USER_ID;
                            //taskFlowNext2.DEAL_USER_NAME = flow.YL_TASK_FLOW2.DEAL_USER_NAME;
                            taskFlowNext2.LEVEL_ID   = flow.LEVEL_ID + 1;
                            taskFlowNext2.NAME       = flow.YL_TASK_FLOW2.NAME;
                            taskFlowNext2.HANDLE_URL = "~/TaskFlow/Handle";
                            taskFlowNext2.SHOW_URL   = "~/TaskFlow/Single";
                            taskFlowNext2.IS_HANDLE  = 0;
                            taskFlowNext2.PARENT_ID  = flow.YL_TASK_FLOW2.PARENT_ID;
                            taskFlowNext2.TASK_ID    = flow.TASK_ID;
                            db.YL_TASK_FLOW.Add(taskFlowNext2);
                        }
                    }
                    else
                    {
                        flow.YL_TASK.STATUS      = "完成";
                        flow.YL_TASK.STATUS_TIME = DateTime.Now;
                    }
                }
                else //转派
                {
                    flow.DEAL_STATUS = "分派处理";
                    if (!string.IsNullOrEmpty(inEnt.UserIdArrStr))
                    {
                        IList <int> userIdArr = inEnt.UserIdArrStr.Split(',').Where(x => x.IsInt32()).Select(x => Convert.ToInt32(x)).ToList();
                        var         allUser   = db.YL_USER.Where(x => userIdArr.Contains(x.ID)).ToList();
                        var         allRole   = db.YL_ROLE.Where(x => x.YL_USER.Where(y => userIdArr.Contains(y.ID)).Count() > 0).ToList();
                        flow.ROLE_ID_STR = string.Join(",", allRole.Select(x => x.ID).ToList());

                        foreach (var t in flow.YL_TASK_FLOW1.ToList())
                        {
                            if (allUser.SingleOrDefault(x => x.ID == t.HANDLE_USER_ID) == null)
                            {
                                db.YL_TASK_FLOW.Remove(t);
                            }
                        }

                        foreach (var user in allUser)
                        {
                            YL_TASK_FLOW taskFlowNext1 = flow.YL_TASK_FLOW1.SingleOrDefault(x => x.HANDLE_USER_ID == user.ID);
                            if (taskFlowNext1 == null)
                            {
                                taskFlowNext1                = new YL_TASK_FLOW();
                                taskFlowNext1.ID             = Fun.GetSeqID <YL_TASK_FLOW>();
                                taskFlowNext1.HANDLE_USER_ID = user.ID;
                                //taskFlowNext1.DEAL_USER_NAME = user.NAME;
                                taskFlowNext1.LEVEL_ID      = flow.LEVEL_ID + 1;
                                taskFlowNext1.NAME          = "承办人办理";
                                taskFlowNext1.HANDLE_URL    = "~/TaskFlow/Handle";
                                taskFlowNext1.SHOW_URL      = "~/TaskFlow/Single";
                                taskFlowNext1.IS_HANDLE     = 0;
                                taskFlowNext1.YL_TASK_FLOW2 = flow;
                                taskFlowNext1.TASK_ID       = flow.TASK_ID;
                                flow.YL_TASK_FLOW1.Add(taskFlowNext1);
                            }
                        }
                    }
                    else //角色下所有用户
                    {
                    }
                }
                flow.IS_HANDLE = 1;

                //if (!string.IsNullOrEmpty(inEnt.AllFilesStr))
                //{
                //    var fileIdList = ProInterface.JSON.EncodeToEntity<IList<FILES>>(inEnt.AllFilesStr).Select(x => x.ID);
                //    flow.YL_FILES.Clear();
                //    flow.YL_FILES = db.YL_FILES.Where(x => fileIdList.Contains(x.ID)).ToList();
                //}

                //flow.REMARK = inEnt.REMARK;
                db.SaveChanges();

                return(true);
            }
        }
Example #6
0
        public bool DataDownEventStart(string loginKey, ref ErrorInfo err, int downID)
        {
            if (!UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(false);
            }
            GlobalUser gu = Global.GetUser(loginKey);

            using (DBEntities db = new DBEntities())
            {
                var down = db.YL_DATA_DOWN.SingleOrDefault(x => x.ID == downID);


                // string s = GetSelectScript(down.SELECT_SCRIPT);
                //获得相对应的参数
                //GetMonthPath(ref belongMonth, ref path, down.CREATE_TYPE, down.CREATE_TABLE_NAME);

                string tableName = Fun.ReplaceDataTime(down.CREATE_TABLE_NAME, DateTime.Now, loginKey);

                var eventEnt = new YL_DATA_DOWN_EVENT();
                eventEnt.ID             = Fun.GetSeqID <YL_DATA_DOWN_EVENT>();
                eventEnt.TARGET_NAME    = tableName;
                eventEnt.ALL_NUM        = 0;
                eventEnt.LAST_MONTH_NUM = 0;
                eventEnt.PATH           = down.TO_PATH;
                eventEnt.DATA_DOWN_ID   = downID;
                eventEnt.START_TIME     = DateTime.Now;
                eventEnt.USER_ID        = gu.UserId;
                db.YL_DATA_DOWN_EVENT.Add(eventEnt);
                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException dbEx)
                {
                    err.IsError = true;
                    err.Message = Fun.GetDbEntityErrMess(dbEx);
                    return(false);
                }


                string createScript = "";
                if (!string.IsNullOrEmpty(down.CREATE_SCRIPT))
                {
                    createScript = down.CREATE_SCRIPT.Replace("{@TABLE_NAME}", eventEnt.TARGET_NAME);
                }

                foreach (var to in down.YL_DATA_DOWN_TO.ToList())
                {
                    var toServer = to.YL_DB_SERVER;
                    #region 在目标服务器上创建表
                    try
                    {
                        try
                        {
                            DbServerNonQuery(toServer.ID, "drop table " + eventEnt.TARGET_NAME);
                        }
                        catch (Exception e)
                        {
                        }
                        DbServerNonQuery(toServer.ID, createScript);
                    }
                    catch (Exception e)
                    {
                        err.IsError = true;
                        err.Message = "在服务器【" + toServer.NICKNAME + "】上建表失败:\r\nSQL:" + createScript + "\r\n" + e.Message;
                        return(false);
                    }
                    #endregion
                    foreach (var from in down.YL_DB_SERVER.ToList())
                    {
                        YL_DATA_DOWN_TASK task = new YL_DATA_DOWN_TASK();
                        task.ID            = Fun.GetSeqID <YL_DATA_DOWN_TASK>();
                        task.NAME          = eventEnt.TARGET_NAME;
                        task.SELECT_SCRIPT = down.SELECT_SCRIPT;
                        task.EVENT_ID      = eventEnt.ID;
                        #region 替换SELECT_SCRIPT
                        foreach (var replace in JSON.EncodeToEntity <IList <KV> >(to.REPLACE_STR))
                        {
                            task.SELECT_SCRIPT = task.SELECT_SCRIPT.Replace(replace.K, replace.V);
                        }
                        task.SELECT_SCRIPT = Fun.ReplaceDataTime(task.SELECT_SCRIPT, DateTime.Now, loginKey);
                        #endregion

                        #region 生成@[00-99]
                        if (task.SELECT_SCRIPT.IndexOf("@") != -1)
                        {
                            task.SELECT_SCRIPT = Fun.GetSelectScript(task.SELECT_SCRIPT);
                        }
                        #endregion

                        //设置存放路径
                        task.TO_PATH = Fun.ReplaceDataTime(down.TO_PATH, DateTime.Now, loginKey);

                        int thisAllNum = 0;

                        task.ALL_NUM = thisAllNum;
                        int upMonthNum = 0;

                        task.LAST_MONTH_NUM   = upMonthNum;
                        task.SELECT_DB_SERVER = from.ID;
                        task.SELECT_SERVER    = string.Format("(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={0})(PORT={1})))(CONNECT_DATA=(SERVER=DEDICATED)(SID={2})))", from.IP, from.PORT, from.DBNAME);
                        task.SELECT_UID       = from.UID;
                        task.SELECT_PWD       = from.PASSWORD;
                        task.EVENT_TYPE       = 1;
                        if (down.SUCC_SCRIPT != null)
                        {
                            task.SUCC_SCRIPT = down.SUCC_SCRIPT.Replace("{@TABLE_NAME}", eventEnt.TARGET_NAME);
                        }
                        task.TO_DB_SERVER  = toServer.ID;
                        task.TO_SERVER     = toServer.DBNAME;
                        task.TO_UID        = toServer.UID;
                        task.TO_PWD        = toServer.PASSWORD;
                        task.CREATE_SCRIPT = createScript;
                        task.ERROR_NUM     = 0;
                        task.STATUS        = "等待";
                        task.PAGE_SIZE     = down.PAGE_SIZE;
                        task.SPLIT_STR     = down.SPLIT_STR;
                        task.IS_CANCEL     = 0;
                        task.ORDER_NUM     = task.ID;
                        db.YL_DATA_DOWN_TASK.Add(task);
                    }
                }
                db.SaveChanges();
                return(true);
            }
        }
Example #7
0
        public bool FlowSave(string loginKey, ref ErrorInfo err, TFlow ent)
        {
            using (DBEntities db = new DBEntities())
            {
                ent.FlowList = JSON.EncodeToEntity <IList <TFlowFlownodeFlow> >(ent.FlowListStr);
                ent.Idxy     = JSON.EncodeToEntity <IList <IdXY> >(ent.X_Y);

                if (string.IsNullOrEmpty(ent.FLOW_TYPE))
                {
                    ent.FLOW_TYPE = "默认";
                }

                var useId = ent.FlowList.Select(x => x.FROM_FLOWNODE_ID).ToList();
                foreach (var t in ent.FlowList)
                {
                    if (!useId.Contains(t.TO_FLOWNODE_ID))
                    {
                        useId.Add(t.TO_FLOWNODE_ID);
                    }
                }

                ent.Idxy = ent.Idxy.Where(x => useId.Contains(x.Id)).ToList();

                var flow = db.YL_FLOW.SingleOrDefault(x => x.ID == ent.ID);
                if (flow == null)
                {
                    flow    = Fun.ClassToCopy <TFlow, YL_FLOW>(ent);
                    flow.ID = Fun.GetSeqID <YL_FLOW>();
                    db.YL_FLOW.Add(flow);
                }
                else
                {
                    flow = Fun.ClassToCopy <TFlow, YL_FLOW>(ent, flow);
                }

                #region  除节点
                foreach (var t in flow.YL_FLOW_FLOWNODE_FLOW.ToList())
                {
                    if (ent.FlowList.Where(x => x.FROM_FLOWNODE_ID == t.FROM_FLOWNODE_ID && x.TO_FLOWNODE_ID == t.TO_FLOWNODE_ID).Count() == 0)
                    {
                        t.YL_ROLE.Clear();
                        db.YL_FLOW_FLOWNODE_FLOW.Remove(t);
                    }
                }
                #endregion

                foreach (var t in ent.FlowList)
                {
                    if (!string.IsNullOrEmpty(t.AllRoleStr))
                    {
                        string[] tmpRoleArr = t.AllRoleStr.Trim().Split(',');
                        if (tmpRoleArr.Length > 0)
                        {
                            t.AllRoleIDList = tmpRoleArr.Select(x => Convert.ToInt32(x)).ToList();
                        }
                    }
                    var thisFlow = flow.YL_FLOW_FLOWNODE_FLOW.SingleOrDefault(x => x.FROM_FLOWNODE_ID == t.FROM_FLOWNODE_ID && x.TO_FLOWNODE_ID == t.TO_FLOWNODE_ID);
                    if (thisFlow == null)
                    {
                        YL_FLOW_FLOWNODE_FLOW flowF = Fun.ClassToCopy <TFlowFlownodeFlow, YL_FLOW_FLOWNODE_FLOW>(t);

                        flowF.YL_ROLE = db.YL_ROLE.Where(x => t.AllRoleIDList.Contains(x.ID)).ToList();
                        flowF.ID      = Fun.GetSeqID <YL_FLOW_FLOWNODE_FLOW>();
                        flowF.FLOW_ID = flow.ID;
                        db.YL_FLOW_FLOWNODE_FLOW.Add(flowF);
                    }
                    else
                    {
                        thisFlow = Fun.ClassToCopy <TFlowFlownodeFlow, YL_FLOW_FLOWNODE_FLOW>(t, thisFlow);
                        thisFlow.YL_ROLE.Clear();
                        thisFlow.YL_ROLE = db.YL_ROLE.Where(x => t.AllRoleIDList.Contains(x.ID)).ToList();
                        thisFlow         = Fun.ClassToCopy <TFlowFlownodeFlow, YL_FLOW_FLOWNODE_FLOW>(t);
                    }
                }
                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetDbEntityErrMess(e);
                    return(false);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetExceptionMessage(e);
                    return(false);
                }
            }
            return(true);
        }
Example #8
0
        public TUser UserGetAndSave(string loginKey, ref ErrorInfo err, TUser inEnt, IList <string> allPar)
        {
            if (!GlobalFun.UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(null);
            }
            using (DBEntities db = new DBEntities())
            {
                try
                {
                    string nowLoginName = inEnt.LOGIN_NAME;
                    var    userEnt      = db.fa_user.SingleOrDefault(x => x.LOGIN_NAME == inEnt.LOGIN_NAME);
                    var    loginEnt     = db.fa_login.SingleOrDefault(x => x.LOGIN_NAME == nowLoginName);
                    if (userEnt == null)
                    {
                        userEnt             = Fun.ClassToCopy <ProInterface.Models.TUser, fa_user>(inEnt);
                        userEnt.ID          = Fun.GetSeqID <fa_user>();
                        userEnt.CREATE_TIME = DateTime.Now;
                        userEnt.LOGIN_COUNT = 0;
                        userEnt.REGION      = db.fa_district.SingleOrDefault(p => p.ID == inEnt.DISTRICT_ID).REGION;
                        db.fa_user.Add(userEnt);
                    }

                    if (loginEnt == null)
                    {
                        loginEnt          = Fun.ClassToCopy <TUser, fa_login>(inEnt);
                        loginEnt.ID       = Fun.GetSeqID <fa_login>();
                        loginEnt.PASSWORD = (string.IsNullOrEmpty(inEnt.PassWord)) ? AppSet.DefaultPwd.Md5() : inEnt.PassWord.Md5();
                        loginEnt.REGION   = userEnt.REGION;
                        db.fa_login.Add(loginEnt);
                    }

                    IList <int> allRoleId = userEnt.fa_role.Select(x => x.ID).ToList();
                    foreach (var t in inEnt.RoleAllID.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => Convert.ToInt32(x)).ToList())
                    {
                        allRoleId.Add(t);
                    }
                    ;
                    userEnt.fa_role.Clear();
                    userEnt.fa_role = db.fa_role.Where(x => allRoleId.Contains(x.ID)).ToList();

                    db.SaveChanges();
                    inEnt    = Fun.ClassToCopy <fa_user, TUser>(userEnt, inEnt);
                    inEnt.ID = userEnt.ID;
                    GlobalFun.UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Edit);
                    return(inEnt);
                }
                catch (DbEntityValidationException e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetDbEntityErrMess(e);
                    return(null);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetExceptionMessage(e);
                    return(null);
                }
            }
        }
Example #9
0
        public TUser UserSave(string loginKey, ref ErrorInfo err, TUser inEnt, IList <string> allPar)
        {
            if (!GlobalFun.UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(null);
            }
            using (DBEntities db = new DBEntities())
            {
                try
                {
                    var idPar = allPar.SingleOrDefault(x => x == "ID");
                    if (idPar != null)
                    {
                        allPar.Remove(idPar);
                    }

                    var userEnt = db.fa_user.SingleOrDefault(a => a.ID == inEnt.ID);
                    if (userEnt == null)
                    {
                        userEnt = db.fa_user.SingleOrDefault(x => x.LOGIN_NAME == inEnt.LOGIN_NAME);
                    }
                    var  loginEnt = db.fa_login.SingleOrDefault(x => x.LOGIN_NAME == inEnt.LOGIN_NAME);
                    bool isAdd    = false;
                    if (userEnt == null)
                    {
                        isAdd   = true;
                        userEnt = Fun.ClassToCopy <ProInterface.Models.TUser, fa_user>(inEnt);
                        if (userEnt.ID == 0)
                        {
                            userEnt.ID = Fun.GetSeqID <fa_user>();
                        }
                        userEnt.CREATE_TIME = DateTime.Now;
                        userEnt.LOGIN_COUNT = 0;
                        userEnt.REGION      = db.fa_district.SingleOrDefault(p => p.ID == inEnt.DISTRICT_ID).REGION;
                    }
                    else
                    {
                        if (db.fa_user.Where(x => x.LOGIN_NAME == inEnt.LOGIN_NAME && x.ID != userEnt.ID).Count() > 0)
                        {
                            err.IsError = true;
                            err.Message = "登录工号已经存在";
                            return(null);
                        }
                        userEnt = Fun.ClassToCopy <ProInterface.Models.TUser, fa_user>(inEnt, userEnt, allPar);
                    }

                    if (loginEnt == null)
                    {
                        loginEnt          = Fun.ClassToCopy <TUser, fa_login>(inEnt);
                        loginEnt.ID       = Fun.GetSeqID <fa_login>();
                        loginEnt.PASSWORD = AppSet.DefaultPwd.Md5();
                        loginEnt.REGION   = userEnt.REGION;
                        db.fa_login.Add(loginEnt);
                    }
                    else
                    {
                        if (db.fa_login.Where(x => x.LOGIN_NAME == loginEnt.LOGIN_NAME && x.ID != loginEnt.ID).Count() > 0)
                        {
                            err.IsError = true;
                            err.Message = "登录工号已经存在";
                            return(null);
                        }
                        loginEnt          = Fun.ClassToCopy <TUser, fa_login>(inEnt, loginEnt, allPar);
                        loginEnt.PHONE_NO = inEnt.PHONE_NO;
                    }


                    if (allPar.Contains("RoleAllID"))
                    {
                        IList <int> allRoleId = new List <int>();
                        allRoleId = inEnt.RoleAllID.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => Convert.ToInt32(x)).ToList();
                        userEnt.fa_role.Clear();
                        userEnt.fa_role = db.fa_role.Where(x => allRoleId.Contains(x.ID)).ToList();
                    }

                    if (isAdd)
                    {
                        db.fa_user.Add(userEnt);
                    }

                    userEnt.fa_district1.Clear();
                    if (!string.IsNullOrEmpty(inEnt.UserDistrict))
                    {
                        var disArrList = inEnt.UserDistrict.Split(',').Select(x => Convert.ToInt32(x)).ToList();
                        userEnt.fa_district1 = db.fa_district.Where(x => disArrList.Contains(x.ID)).ToList();
                    }

                    db.SaveChanges();
                    inEnt    = Fun.ClassToCopy <fa_user, TUser>(userEnt, inEnt);
                    inEnt.ID = userEnt.ID;
                    GlobalFun.UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Edit);
                    return(inEnt);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    if (e.Message.IndexOf("EntityValidationErrors") > -1)
                    {
                        err.Message = Fun.GetDbEntityErrMess(e as DbEntityValidationException);
                    }
                    else
                    {
                        System.Data.Entity.Infrastructure.DbUpdateException t = e as System.Data.Entity.Infrastructure.DbUpdateException;
                        err.Message = t.Message;
                    }
                    return(null);
                }
            }
        }
Example #10
0
        public object UserAdd(string loginKey, ref ErrorInfo err, TUser inEnt)
        {
            if (!GlobalFun.UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(null);
            }
            GlobalUser gu = Global.GetUser(loginKey);

            using (DBEntities db = new DBEntities())
            {
                fa_user reEnt  = Fun.ClassToCopy <ProInterface.Models.TUser, fa_user>(inEnt);
                var     nowDis = db.fa_district.SingleOrDefault(p => p.ID == inEnt.DISTRICT_ID);
                reEnt.CREATE_TIME = DateTime.Now;
                reEnt.DISTRICT_ID = nowDis.ID;
                reEnt.LOGIN_COUNT = 0;

                IList <int> moduleID = new List <int>();
                foreach (var str in inEnt.RoleAllID.Split(','))
                {
                    if (!string.IsNullOrEmpty(str))
                    {
                        moduleID.Add(Convert.ToInt32(str));
                    }
                }
                reEnt.ID      = Fun.GetSeqID <fa_user>();
                reEnt.REGION  = nowDis.REGION;
                reEnt.fa_role = db.fa_role.Where(x => moduleID.Contains(x.ID)).ToList();
                reEnt.fa_district1.Clear();
                if (!string.IsNullOrEmpty(inEnt.UserDistrict))
                {
                    var disArrList = inEnt.UserDistrict.Split(',').Select(x => Convert.ToInt32(x)).ToList();
                    reEnt.fa_district1 = db.fa_district.Where(x => disArrList.Contains(x.ID)).ToList();
                }
                reEnt = db.fa_user.Add(reEnt);

                fa_login login = new fa_login();
                login.ID         = Fun.GetSeqID <fa_login>();
                login.LOGIN_NAME = inEnt.LOGIN_NAME;
                if (!string.IsNullOrEmpty(inEnt.PassWord))
                {
                    login.PASSWORD = inEnt.PassWord.Md5();
                }
                else
                {
                    login.PASSWORD = AppSet.DefaultPwd.Md5();
                }
                login.PHONE_NO      = inEnt.PHONE_NO;
                login.IS_LOCKED     = inEnt.IS_LOCKED;
                login.LOCKED_REASON = inEnt.LOCKED_REASON;
                login.REGION        = reEnt.REGION;
                login = db.fa_login.Add(login);


                try
                {
                    db.SaveChanges();
                    GlobalFun.UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Add);
                    return(reEnt.ID);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetExceptionMessage(e);
                    err.Excep   = e;
                    return(null);
                }
            }
        }
Example #11
0
        public object BulletinSave(string loginKey, ref ErrorInfo err, ProInterface.Models.TBulletin inEnt, IList <string> allPar)
        {
            if (!UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(null);
            }
            using (DBEntities db = new DBEntities())
            {
                GlobalUser gu = Global.GetUser(loginKey);
                inEnt.AllFiles = JSON.EncodeToEntity <IList <FILES> >(inEnt.AllFilesStr == null ? "[]" : inEnt.AllFilesStr);
                IList <int> fileIdList = inEnt.AllFiles.Select(x => x.ID).ToList();
                if (string.IsNullOrEmpty(inEnt.AllRoleId))
                {
                    err.IsError = true;
                    err.Message = string.Format("保存失败,没有选择可查看的角色", inEnt.AllRoleId);
                    return(null);
                }
                IList <int> AllRoleId = inEnt.AllRoleId.Split(',').Select(x => Convert.ToInt32(x)).ToList();
                YL_BULLETIN reEnt     = new YL_BULLETIN();
                if (inEnt.ID == 0)
                {
                    reEnt             = Fun.ClassToCopy <ProInterface.Models.BULLETIN, YL_BULLETIN>(inEnt);
                    reEnt.ID          = Fun.GetSeqID <YL_BULLETIN>();
                    reEnt.YL_FILES    = db.YL_FILES.Where(x => fileIdList.Contains(x.ID)).ToList();
                    reEnt.YL_ROLE     = db.YL_ROLE.Where(x => AllRoleId.Contains(x.ID)).ToList();
                    reEnt.PUBLISHER   = gu.UserName;
                    reEnt.CREATE_TIME = DateTime.Now;
                    reEnt.UPDATE_TIME = DateTime.Now;
                    reEnt.REGION      = gu.Region;
                    reEnt.USER_ID     = gu.UserId;
                    reEnt             = db.YL_BULLETIN.Add(reEnt);
                    UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Add);
                }
                else
                {
                    reEnt = db.YL_BULLETIN.SingleOrDefault(x => x.ID == inEnt.ID);

                    if (reEnt.USER_ID != gu.UserId)
                    {
                        err.IsError = true;
                        err.Message = string.Format("该公告是【{0}】添加的,不能修改", reEnt.PUBLISHER);
                        return(null);
                    }



                    reEnt = Fun.ClassToCopy <ProInterface.Models.BULLETIN, YL_BULLETIN>(inEnt, reEnt, allPar);
                    var allNowFiles = db.YL_FILES.Where(x => fileIdList.Contains(x.ID)).ToList();
                    foreach (var t in reEnt.YL_FILES.ToList())
                    {
                        if (allNowFiles.SingleOrDefault(x => x.ID == t.ID) == null)
                        {
                            reEnt.YL_FILES.Remove(t);
                            db.YL_FILES.Remove(t);
                        }
                    }

                    reEnt.YL_FILES.Clear();
                    reEnt.YL_ROLE.Clear();
                    reEnt.YL_ROLE     = db.YL_ROLE.Where(x => AllRoleId.Contains(x.ID)).ToList();
                    reEnt.YL_FILES    = allNowFiles;
                    reEnt.PUBLISHER   = gu.UserName;
                    reEnt.UPDATE_TIME = DateTime.Now;
                    UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Edit);
                }
                try
                {
                    //FunTask.StartTask(db, ref err, 1, "阅读公告信息", gu);
                    db.SaveChanges();
                    return(reEnt.ID);
                }
                catch (DbEntityValidationException e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetDbEntityErrMess(e);
                    err.Excep   = e;
                    return(null);
                }
            }
        }
Example #12
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);
                }
            }
        }
Example #13
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);
                }
            }
        }
Example #14
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);
                }
            }
        }
Example #15
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);
        }