예제 #1
0
        public override bool Login()
        {
            string passwd      = this.tePassword.Text;
            string system_code = this.lueSystem.EditValue.ToString();
            string ret         = "";

            if (string.IsNullOrEmpty(passwd))
            {
                ret = "请输入密码";
            }
            else
            {
                ret = EmpInfo.Login(EnvInfo.BranchId, system_code, passwd);
            }

            if (ret.IsNullOrEmpty())
            {
                var parmList = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>("empId", EmpInfo.Id.ToString())
                };
                CustomException    ce         = null;
                BDictEmp           empInfo    = HttpDataHelper.GetWithInfo <BDictEmp>("BASE", "/sys/empinfo", out ce, parmList);
                List <string>      roleList   = HttpDataHelper.GetWithInfo <List <string> >("BASE", "/sys/role", out ce, parmList);
                List <CDictAction> actionList = HttpDataHelper.GetWithInfo <List <CDictAction> >("BASE", "/sys/action", out ce, parmList);

                EmpInfo.SetEmpInfo(empInfo, roleList, actionList);
                return(true);
            }
            else
            {
                MessageHelper.ShowError(ret);
                return(false);
            }
        }
예제 #2
0
        /// <summary>
        ///  获取JSON格式缓存
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="cacheName">缓存名</param>
        /// <param name="url">服务地址</param>
        /// <param name="parms">服务参数</param>
        /// <returns></returns>
        public static List <T> Get <T>(String cacheName, String url, List <KeyValuePair <String, String> > parms = null)
        {
            //  1. 获取服务器缓存的版本
            //  2. 查询本地是否存在对应版本的磁盘缓存文件
            //  3.
            //     a) 如果存在从本地磁盘获取数据后反序列化,返回结果,失败转入b)
            //     b) 如果不存在或本地获取失败 1、从服务端获取数据,2、清除本地磁盘数据,3、序列化后写入本地文件, 返回结果

            List <T> list       = null;
            string   remote_ver = GetRemoteVer(cacheName);  //  1. 获取服务器缓存的版本
            string   file       = EnvInfo.RunPath + "Cache\\" + cacheName + "(" + remote_ver + ").cache";
            bool     ok         = false;

            if (File.Exists(file))
            {
                try
                {
                    LogHelper.Info(typeof(CacheHelper).FullName, "开始获取" + cacheName + "本地磁盘缓存");
                    string result = File.ReadAllText(file);
                    list = JsonConvert.DeserializeObject <List <T> >(result);
                    LogHelper.Info(typeof(CacheHelper).FullName, "成功获取" + cacheName + "本地磁盘缓存");
                    ok = true;
                }
                catch (Exception ex)
                {
                    LogHelper.Warn(typeof(CacheHelper).FullName, "获取" + cacheName + "本地磁盘缓存失败\r\n" + ex.Message + "\r\n" + ex.StackTrace);
                }
            }

            if (!ok)
            {
                try
                {
                    LogHelper.Info(typeof(CacheHelper).FullName, "开始获取" + cacheName + "服务端数据");
                    CustomException ce     = null;
                    string          result = HttpDataHelper.GetStringWithInfo("BASE", url, out ce, parms);
                    if (ce != null)
                    {
                        throw ce;
                    }

                    LogHelper.Info(typeof(CacheHelper).FullName, "开始序列化" + cacheName);
                    list = JsonConvert.DeserializeObject <List <T> >(result);

                    LogHelper.Info(typeof(CacheHelper).FullName, "删除" + cacheName + "旧的缓存文件");
                    RemoveFile(cacheName);

                    LogHelper.Info(typeof(CacheHelper).FullName, "写入" + cacheName + "新的磁盘缓存文件");
                    File.WriteAllText(file, result);
                }
                catch (Exception ex)
                {
                    LogHelper.Error(typeof(CacheHelper).FullName, "获取" + cacheName + "服务端数据失败\r\n" + ex.Message + "\r\n" + ex.StackTrace);
                }
            }
            return(list);
        }
예제 #3
0
        /// <summary>
        /// 刷新对应模块的Url
        /// </summary>
        /// <param name="app"></param>
        /// <returns></returns>
        public static bool RefreshEurekaUrls(String app)
        {
            try
            {
                List <EurekaUrlAction> urlsOfApp = new List <EurekaUrlAction>();
                foreach (String serverUrl in _EurekaServers) //遍历EUREKA服务的APP内容
                {
                    String eurekaServerInfo = HttpDataHelper.GetString(serverUrl);

                    XmlDocument d = new XmlDocument();
                    d.LoadXml(eurekaServerInfo);

                    XmlNode     top          = d.SelectNodes("//applications")[0];
                    XmlNodeList applications = top.SelectNodes("//application");
                    foreach (XmlElement element in applications)
                    {
                        string name = element.GetElementsByTagName("name")[0].InnerText;
                        if (name.Equals(app))   //找到对应的application
                        {
                            XmlNodeList instances = element.GetElementsByTagName("instance");

                            foreach (XmlElement ele in instances)
                            {
                                string ipAddress = ele.GetElementsByTagName("ipAddr")[0].InnerText;
                                string port      = ele.GetElementsByTagName("port")[0].InnerText;
                                string newUrl    = "http://" + ipAddress + ":" + port;

                                EurekaUrlAction ua = new EurekaUrlAction();
                                ua.Url = newUrl;

                                if (!Contains(urlsOfApp, newUrl))
                                {
                                    EurekaUrlAction eua = new EurekaUrlAction();
                                    eua.Url      = newUrl;
                                    eua.IsActive = true;
                                    eua.Count    = 0;
                                    urlsOfApp.Add(eua);
                                }
                            }
                        }
                    }
                }
                lock (_EurekaUrls)
                {
                    _EurekaUrls.Remove(app);
                    _EurekaUrls.Add(app, urlsOfApp);
                }
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
        }
예제 #4
0
        /// <summary>
        ///  获取自定义格式缓存
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="cacheName">缓存名</param>
        /// <param name="url">服务地址</param>
        /// <param name="parms">服务参数</param>
        /// <returns></returns>
        public static List <T> GetFast <T>(String cacheName, String url, List <KeyValuePair <String, String> > parms = null) where T : IFastSerialize, new()
        {
            List <T> list       = null;
            string   remote_ver = GetRemoteVer(cacheName);  //  1. 获取服务器缓存的版本
            string   file       = EnvInfo.RunPath + "Cache\\" + cacheName + "(" + remote_ver + ").cache";
            bool     ok         = false;

            if (File.Exists(file))
            {
                try
                {
                    LogHelper.Info(typeof(CacheHelper).FullName, "开始获取" + cacheName + "本地磁盘缓存");
                    byte[] cache_bytes = System.IO.File.ReadAllBytes(file);
                    list = FastSerializeHelper.DeSerialize <T>(cache_bytes);
                    LogHelper.Info(typeof(CacheHelper).FullName, "成功获取" + cacheName + "本地磁盘缓存");
                    ok = true;
                }
                catch (Exception ex)
                {
                    LogHelper.Warn(typeof(CacheHelper).FullName, "获取" + cacheName + "本地磁盘缓存失败\r\n" + ex.Message + "\r\n" + ex.StackTrace);
                }
            }

            if (!ok)
            {
                try
                {
                    LogHelper.Info(typeof(CacheHelper).FullName, "开始获取" + cacheName + "服务端数据");
                    CustomException ce     = null;
                    string          result = HttpDataHelper.GetStringWithInfo("BASE", url, out ce, parms);
                    if (ce != null)
                    {
                        throw ce;
                    }
                    list = JsonConvert.DeserializeObject <List <T> >(result);

                    LogHelper.Info(typeof(CacheHelper).FullName, "开始序列化" + cacheName);
                    List <byte> list_bytes = FastSerializeHelper.Serialize(list);

                    LogHelper.Info(typeof(CacheHelper).FullName, "删除" + cacheName + "旧的缓存文件");
                    RemoveFile(cacheName);

                    LogHelper.Info(typeof(CacheHelper).FullName, "写入" + cacheName + "新的磁盘缓存文件");
                    File.WriteAllBytes(file, list_bytes.ToArray());
                }
                catch (Exception ex)
                {
                    LogHelper.Error(typeof(CacheHelper).FullName, "获取" + cacheName + "服务端数据失败\r\n" + ex.Message + "\r\n" + ex.StackTrace);
                }
            }
            return(list);
        }
예제 #5
0
        public static bool Login(int branchId, String operCode, String passwd, String workplace, String subSystem)
        {
            String loginUrl = HttpDataHelper.getUrl("SYS");

            if (loginUrl != null)
            {
                Dictionary <String, String> dic = HttpDataHelper.PathGet <Dictionary <String, String> >(loginUrl + "login",
                                                                                                        new String[] { branchId.ToString(), operCode, passwd });

                //workplace subSystem判断
            }
            return(true);
        }
예제 #6
0
        /// <summary>
        ///  系统登录
        /// </summary>
        /// <param name="branch_id">机构ID</param>
        /// <param name="system_code">子系统代码</param>
        /// <param name="password">口令</param>
        /// <returns>返回错误信息,空为成功</returns>
        public static string Login(int branch_id, string system_code, string password)
        {
            //  完成登录,获取员工相关信息
            //        1. 验证用户口令并获取员工信息记录中的基本内容。
            //        2. 判断子系统使用权限
            //        3. 获取普通角色、行为角色

            List <KeyValuePair <string, string> > parms = new List <KeyValuePair <string, string> >();

            parms.Add(new KeyValuePair <string, string>("branchCode", EnvInfo.BranchCode));
            parms.Add(new KeyValuePair <string, string>("empCode", EmpInfo.Code));
            parms.Add(new KeyValuePair <string, string>("password", DataCryptoHelper.MD5EncryptString(password)));
            parms.Add(new KeyValuePair <string, string>("ip", EnvInfo.ComputerIp));
            CustomException ce       = null;
            int             loginRst = int.Parse(HttpDataHelper.HttpPostFormUrlWithInfo("BASE", "/sys/login", out ce, parms));

            switch (loginRst)
            {
            case -1:
                return("人员不存在!");

            case -2:
                return("密码错误!");

            case 1:
                // 4. 设置环境信息对应的子系统代码、名称
                SelectSystem(system_code, true);
                return(string.Empty);

            default:
                return("服务异常");
            }

            /* TODO 参考
             * EmpInfo.Name = EmpInfo.Id.ToString();
             * EmpInfo.BizEmpName = " 业务" + EmpInfo.Id.ToString();
             * EmpInfo.InputCode = "1";
             *
             * String loginUrl = HttpDataHelper.getUrl("SYSTEM");
             * if (loginUrl != null)
             * {
             *
             *  Dictionary<String, String> dic = HttpDataHelper.PathGet<Dictionary<String, String>>(loginUrl + "login",
             *      new String[] { branch_id.ToString(), system_code, EmpInfo.Id.ToString(), password });
             *
             *  //workplace subSystem判断
             *
             * }
             */
        }
예제 #7
0
        /// <summary>
        ///  判别是否有功能点权限
        /// </summary>
        /// <param name="container_code">容器代码</param>
        /// <param name="code">代码</param>
        /// <param name="name">名称</param>
        /// <param name="describe">描述信息</param>
        /// <returns>是否有权限</returns>
        public static bool GetFunctionPointAuthority(string container_code,
                                                     string code, string name, string describe)
        {
            if (String.IsNullOrEmpty(code))
            {
                return(false);
            }

            //  判别是否有功能点记录,返回记录数(>0有权)
            var parmList = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("fpCode", container_code + "-" + code),
                new KeyValuePair <string, string>("empId", EmpInfo.Id.ToString()),
                new KeyValuePair <string, string>("roles", EmpInfo.Roles)
            };
            CustomException    ce = null;
            CDictFunctionPoint fp = HttpDataHelper.GetWithInfo <CDictFunctionPoint>("BASE", "/setup/funcpoint", out ce, parmList);

            return(fp != null && fp.Code.Length > 0);
        }
예제 #8
0
        /// <summary>
        ///  切换子系统
        /// </summary>
        /// <param name="system_code">系统代码</param>
        public static void SelectSystem(string system_code, bool isLogin = false)
        {
            EnvInfo.SystemCode = system_code;
            EnvInfo.SystemId   = CanUseSystemList.Find(o => o.Code == system_code).Id;
            EnvInfo.SystemName = CanUseSystemList.Find(o => o.Code == system_code).Name;

            // 将最新使用子系统更新至个人参数
            if (!GetLastSystemCode().Equals(system_code))
            {
                List <KeyValuePair <string, string> > parms = new List <KeyValuePair <string, string> >();
                parms.Add(new KeyValuePair <string, string>("empId", EmpInfo.Id.ToString()));
                parms.Add(new KeyValuePair <string, string>("parmName", "DEF_SYSTEM"));
                parms.Add(new KeyValuePair <string, string>("value", EnvInfo.SystemCode));
                CustomException ce;
                HttpDataHelper.HttpPostFormUrlParamWithInfo("BASE", "/sys/parameteremp", out ce, parms);
                if (ce != null)
                {
                    throw ce;
                }
            }
        }
예제 #9
0
        /// <summary>
        ///  判别人员是否有职责性质
        /// </summary>
        /// <param name="kind">职责性质</param>
        /// <returns></returns>
        //public static bool HasKind(int kind)
        //{
        //    if (KindList != null)
        //    {
        //        return KindList.Contains(kind);
        //    }
        //    return false;
        //}

        #endregion

        #region 功能方法

        /// <summary>
        ///  通过代码获取员工ID及可用系统信息
        /// </summary>
        /// <param name="code">员工代码</param>
        /// <returns>返回错误信息,空为成功</returns>
        public static string QueryEmpByCode(string code)
        {
            //EmpInfo.CanUseSystemList = new List<BDicSystem>();
            if (code.IsNullOrEmpty())
            {
                EmpInfo.Id   = 0;
                EmpInfo.Code = string.Empty;
                return("工号不可为空!");
            }

            //  依据员工代码获取员工ID,再获取可使用的子系统
            var parmList = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("empCode", code)
            };
            CustomException ce     = null;
            int             emp_id = HttpDataHelper.GetWithInfo <int>("BASE", "/sys/empid", out ce, parmList);

            if (emp_id < 0)
            {
                return("不存在工号为" + code + "的人员!");
            }

            parmList = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("empId", emp_id.ToString())
            };
            List <BDictSystem> ls = HttpDataHelper.GetWithInfo <List <BDictSystem> >("BASE", "/sys/system", out ce, parmList);

            if (ls == null || ls.Count == 0)
            {
                return("工号" + code + "的人员没有可用的子系统!");
            }
            EmpInfo.CanUseSystemList = ls;

            EmpInfo.Code = code;
            EmpInfo.Id   = emp_id;

            return(string.Empty);
        }
예제 #10
0
        /// <summary>
        ///  获取上一次登录的系统代码
        /// </summary>
        /// <returns></returns>
        public static string GetLastSystemCode()
        {
            string code = string.Empty;

            if (EmpInfo.Id > 0)
            {
                var parmList = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>("empId", EmpInfo.Id.ToString())
                };
                CustomException ce = null;
                // 获取上一次登录的系统代码
                code = HttpDataHelper.GetStringWithInfo("BASE", "/sys/systemdefault", out ce, parmList);
                if (ce != null)
                {
                    MessageHelper.ShowError("获取默认子系统失败!\r\n" + ce.Info + " " + ce.InnerMessage);
                    return(null);
                }
            }

            return(code);
        }
예제 #11
0
        public static void SetEmpInfo(BDictEmp emp, List <string> roleList, List <CDictAction> actionList)
        {
            EmpInfo.Name        = emp.Name;
            EmpInfo.Ceid        = emp.Ceid;
            EmpInfo.DeptId      = emp.DeptId;
            EmpInfo.DeptName    = emp.DeptName;
            EmpInfo.BizDeptId   = emp.BizDeptId;
            EmpInfo.BizDeptName = emp.BizDeptName;
            EmpInfo.GroupId     = emp.GroupId;
            EmpInfo.GroupName   = emp.GroupName;
            EmpInfo.TitlesId    = emp.TitlesId;
            EmpInfo.TitlesName  = emp.TitlesName;

            EmpInfo.RoleList       = roleList;
            EmpInfo.ActionRoleList = actionList;

            var parmList = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("empId", EmpInfo.Id.ToString()),
                new KeyValuePair <string, string>("parmName", "DEF_INPUT")
            };
            CustomException ce       = null;
            String          defInput = HttpDataHelper.GetStringWithInfo("BASE", "/sys/parameteremp", out ce, parmList);

            if (ce != null)
            {
                MessageHelper.ShowError("获取默认输入法失败!\r\n" + ce.Info + " " + ce.InnerMessage);
            }
            if (String.IsNullOrEmpty(defInput))
            {
                EmpInfo.InputChoice = "1";
            }
            else
            {
                EmpInfo.InputChoice = defInput;
            }
        }
예제 #12
0
        /// <summary>
        /// 通过配置文件设置机构信息
        /// </summary>
        private static void SetBranchInfo()
        {
            //  获取机构ID,默认为1.
            string sid = ConfigurationManager.AppSettings.Get("BranchId");

            if (!sid.IsNullOrEmpty() && sid.IsInt())
            {
                EnvInfo.BranchId = int.Parse(sid);
            }
            else
            {
                EnvInfo.BranchId = 1;
            }

            string key = ConfigurationManager.AppSettings.Get("UserSerial").Reversal();
            // 获取用户名称
            string rets = ConfigurationManager.AppSettings.Get("UserName");

            if (!string.IsNullOrEmpty(rets))
            {
                rets             = DataCryptoHelper.Decrypting(rets, "Wonder.His" + key);
                EnvInfo.UserName = rets;
            }
            else
            {
                throw new Exception("配置文件中用户名称有误!");
            }

            //try
            //{
            // 系统时间与数据库时间同步
            DateTime d = DateTime.Now;
            //int timezone = int.Parse(DateTime.Now.ToString("%z").Substring(1));

            CustomException ex      = null;
            String          systime = HttpDataHelper.GetStringWithInfo("BASE", "/sys/date", out ex);

            if (ex != null)
            {
                throw ex;
            }
            char[]   spp = new char[] { '-', ':', ' ', '+' };
            string[] tp  = systime.Split(spp, StringSplitOptions.RemoveEmptyEntries);
            int[]    itp = new int[7];
            for (int i = 0; i < 7; i++)
            {
                itp[i] = int.Parse(tp[i]);
            }
            DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(itp[0], itp[1], itp[2], itp[3], itp[4], itp[5]));

            long delta = GetTimeStamp(startTime) - GetTimeStamp(d) - itp[6] * 36000; //时区处理

            if (Math.Abs(delta) < 60000)
            {
                SYSTEMTIME st = new SYSTEMTIME();
                st.FromDateTime(DateTime.Now.AddMilliseconds(delta));
                bool syn = Win32API.SetLocalTime(ref st);
                if (!syn)
                {
                    EnvInfo.ServerTimeDelta = delta;
                }
            }

            //  通过BranchId 查询 名称及代码
            List <KeyValuePair <string, string> > parms = new List <KeyValuePair <string, string> >();

            parms.Add(new KeyValuePair <string, string>("branchId", EnvInfo.BranchId.ToString()));
            CustomException ce     = null;
            CDictBranch     branch = HttpDataHelper.GetWithInfo <CDictBranch>("BASE", "/sys/branch", out ce, parms);

            EnvInfo.BranchCode = branch.Code; // "101";
            EnvInfo.BranchName = branch.Name; // EnvInfo.UserName;

            #region MONGODB 测试
            //ErrorLogInfo eli = new ErrorLogInfo();
            //eli.BranchId = EnvInfo.BranchId;
            //eli.EmpId = EmpInfo.Id;
            //eli.ComputerIp = EnvInfo.ComputerIp;
            //eli.Info = "Try";
            //eli.Message = "Demo message";

            //String json = StringHelper.SerializeObject<ErrorLogInfo>(eli);
            //HttpDataHelper.HttpPostWithInfo"BASE", "/mongo/errorlog/save", json);

            #endregion

            //}
            //catch (Exception ex)
            //{
            //    MessageHelper.ShowError(ex.Message);
            //}
        }