Esempio n. 1
0
 /// <summary>
 /// 备份图片
 /// </summary>
 /// <param name="saveDirPath"></param>
 public static void CopyDirectory(string saveDirPath)
 {
     try
     {
         entity.Setter setter = new entity.Setter();
         setter = new SetterDAO().getSetter();
         Console.WriteLine("目标路径:" + saveDirPath);
         string sourceDirPath = setter.Set_PhotoLocation;
         Console.WriteLine("原路径:" + sourceDirPath);
         if (!Directory.Exists(saveDirPath))
         {
             Directory.CreateDirectory(saveDirPath);
         }
         string[] files = Directory.GetFiles(sourceDirPath.Substring(0, sourceDirPath.Length - 1));
         //MessageBox.Show(files.Length.ToString());
         foreach (string file in files)
         {
             string pFilePath = saveDirPath + Path.GetFileName(file);
             if (File.Exists(pFilePath))
             {
                 continue;
             }
             File.Copy(file, pFilePath, true);
         }
     }
     catch (Exception ee)
     {
     }
 }
Esempio n. 2
0
        public void updateTest()
        {
            using (TransactionScope ts = new TransactionScope())//使整个代码块成为事务性代码

            {
                SetterDAO setterDAO = new SetterDAO();

                ts.Complete();
            }
        }
Esempio n. 3
0
        //得到当前状态的心跳
        public HttpHeartBeat GetHeartBeatByCurrent()
        {
            HttpHeartBeat sendHeartBeat = null;

            //不属于未注册状态
            SetterDAO setterDAO = new SetterDAO();
            Setter    setter    = setterDAO.getSetter();

            if (setterDAO.ListAll().Count != 1)
            {
                //设置表没有唯一标识,直接返回
                return(null);
            }

            //需要加入解密逻辑
            string mac = "";

            //获得当前主机的mac地址
            mac = SystemInfo.GetMacAddress().Replace(":", "-");
            AuthDAO authDAO = new AuthDAO();
            var     result  = authDAO.GetByAuthLevel(Auther.AUTH_LEVEL_MANAGER);

            //注册用户设置mac与用户名
            //TODO设置mac地址不能从本地拿,必须实时获取


            sendHeartBeat = new HttpHeartBeat(result.Auth_UserName, mac);

            if (result.User_Status == Auther.USER_STATUS_FREEZE)
            {
                //是否为冻结状态的心跳,这里不能从数据库取,否则,云通知本地锁死,本地改状态后,会再次通知云锁死本机,陷入死循环
                sendHeartBeat.heartbeatType = 1;
                sendHeartBeat.authStatus    = 0;
            }
            else if (result.User_Status == Auther.USER_STATUS_FREE)

            {
                //是否完全离线
                sendHeartBeat.heartbeatType = 2;
                sendHeartBeat.authStatus    = 0;
            }
            else
            {
                //默认为正常心跳
                sendHeartBeat.heartbeatType = 0;
                sendHeartBeat.authStatus    = 0;
            }


            return(sendHeartBeat);
        }
Esempio n. 4
0
        /// <summary>
        /// 测试激活
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_16(object sender, RoutedEventArgs e)
        {
            SetterDAO setterDAO = new SetterDAO();

            //获取mac地址
            StringBuilder stringBuilder = new StringBuilder();
            //string strMac = CommUtil.GetMacAddress();
            // List<string> Macs = CommUtil.GetMacByWMI();
            List <string> Macs = CommUtil.GetMacByIPConfig();

            foreach (string mac in Macs)
            {
                string prefix = "物理地址. . . . . . . . . . . . . : ";
                string Mac    = mac.Substring(prefix.Length - 1);
                stringBuilder.Append(Mac);
            }
            //Console.WriteLine("==================="+stringBuilder.ToString());
            //MessageBox.Show("===================" + stringBuilder.ToString());
            entity.Setter setter = new entity.Setter();
            //mac地址先变为byte[]再aes加密
            byte[] byteMac = Encoding.GetEncoding("GBK").GetBytes(stringBuilder.ToString());
            byte[] AesMac  = AesUtil.Encrypt(byteMac, ProtocolConstant.USB_DOG_PASSWORD);
            //存入数据库
            //setter.Set_Unique_Id = Encoding.GetEncoding("GBK").GetString(AesMac);
            setter.Set_Unique_Id = ProtocolUtil.BytesToString(AesMac);

            /*AES解密
             * byte[] a = ProtocolUtil.StringToBcd(setter.Set_Unique_Id);
             * byte[] b = AesUtil.Decrypt(a, ProtocolConstant.USB_DOG_PASSWORD);
             * Console.WriteLine(Encoding.GetEncoding("GBK").GetString(b));*/
            //默认照片路径,激活时获取(路径中不要有汉字)
            string basePath = System.AppDomain.CurrentDomain.BaseDirectory;
            string path     = ConfigurationManager.AppSettings["PicPath"];

            setter.Set_PhotoLocation = basePath + path;
            setter.Set_Language      = 1;
            setter.Pk_Set_Id         = 1;
            //设置版本号
            setter.Set_Version = CommUtil.GetCurrentVersion();
            if (!Directory.Exists(@setter.Set_PhotoLocation))
            {
                Directory.CreateDirectory(@setter.Set_PhotoLocation);//不存在就创建目录
            }

            /*if (Directory.Exists(@setter.Set_PhotoLocation)) {  //存在就删除
             *  Directory.Delete(@setter.Set_PhotoLocation, true);
             *  Directory.CreateDirectory(@setter.Set_PhotoLocation);
             * }*/
            setterDAO.InsertOneMacAdress(setter);
        }
Esempio n. 5
0
        public static bool IsChainese()
        {
            List <Setter> all = new SetterDAO().ListAll();

            if (all != null && all.Count != 0)
            {
                if (all[0].Set_Language == 0)
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 6
0
        private void image_load(object sender, RoutedEventArgs e)
        {
            List <Recovery.entity.Setter> all = new SetterDAO().ListAll();

            if (all != null && all.Count != 0)
            {
                if (all[0].Set_Language == 0)
                {
                    title_pic.Source = new BitmapImage(new Uri("/view/Images/p.jpg", UriKind.RelativeOrAbsolute));
                }
                else
                {
                    title_pic.Source = new BitmapImage(new Uri("/view/Images/p.jpg", UriKind.RelativeOrAbsolute));
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 获取当前心跳
        /// </summary>
        /// <returns></returns>
        public static HeartbeatRequest GetHeartBeatByCurrent()
        {
            HeartbeatRequest sendHeartBeat = new HeartbeatRequest();
            //不属于未注册状态
            SetterDAO setterDAO = new SetterDAO();
            Setter    setter    = setterDAO.getSetter();

            if (setterDAO.ListAll().Count != 1)
            {
                //设置表没有唯一标识,直接返回
                return(null);
            }
            AuthDAO authDAO = new AuthDAO();
            var     result  = authDAO.GetByAuthLevel(Auther.AUTH_LEVEL_MANAGER);

            if (result == null)
            {
                return(null);
            }
            //机器码mac地址从本地拿
            sendHeartBeat.UniqueId = setter.Set_Unique_Id;
            //setting表装换成json,赋值
            sendHeartBeat.SettingJSON = JsonTools.Obj2JSONStrNew <Setter>(setter);
            //项目名 医疗康复赋值
            sendHeartBeat.ProductName = "医疗康复";
            //使用期限
            sendHeartBeat.UseDeadTime = result.Auth_OfflineTime.ToString().Replace("/", "-");
            //地理位置
            //sendHeartBeat.Address = setter.Set_Organizationaddress;
            //冻结
            if (result.User_Status == Auther.USER_STATUS_FREEZE)
            {
                //是否为冻结状态的心跳,这里不能从数据库取,否则,云通知本地锁死,本地改状态后,会再次通知云锁死本机,陷入死循环
                //状态 正常0和锁定1
                sendHeartBeat.Status = 1.ToString();
            }
            //正常
            else if (result.User_Status == Auther.USER_STATUS_GENERAL)
            {
                //状态 正常0和锁定1
                //默认为正常心跳
                sendHeartBeat.Status = 0.ToString();
            }
            return(sendHeartBeat);
        }
Esempio n. 8
0
        /// <summary>
        /// 定时器心跳间隔,load时设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            //加载图片
            if (LanguageUtils.IsChainese())
            {
                title_pic.Source     = new BitmapImage(new Uri(@"\view\Images\12.PNG", UriKind.Relative));
                DesignerHead4.Source = new BitmapImage(new Uri(@"\view\images\6.png", UriKind.Relative));
            }
            else
            {
                //TODO 英文图片
                title_pic.Source     = new BitmapImage(new Uri(@"\view\Images\12.PNG", UriKind.Relative));
                DesignerHead4.Source = new BitmapImage(new Uri(@"\view\images\6.png", UriKind.Relative));
            }
            ///载入时数据装填到list,默认选中第一个
            users = userService.GetAllUsers();
            UsersInfo.ItemsSource   = users;
            UsersInfo.SelectedIndex = 1;
            selectUser = (User)UsersInfo.SelectedItem;
            Refresh_RecordFrame_Action();
            ///心跳部分

            #region 通知公告   未激活不心跳
            SetterDAO setterDao = new SetterDAO();
            if (timerNotice == null)
            {
                while (setterDao.ListAll() != null)
                {
                    break;
                }
                BindNotice();

                timerNotice          = new System.Timers.Timer();
                timerNotice.Elapsed += new System.Timers.ElapsedEventHandler((o, eea) => { BindNotice(); });

                timerNotice.Interval = CommUtil.GetHeartBeatRate();
                timerNotice.Start();
            }

            #endregion
        }
Esempio n. 9
0
        private void image_load(object sender, RoutedEventArgs e)
        {
            List <Recovery.entity.Setter> all = new SetterDAO().ListAll();

            if (all != null && all.Count != 0)
            {
                if (all[0].Set_Language == 0)
                {
                    DesignerHead4.Source = new BitmapImage(new Uri("/view/Images/5_6.png", UriKind.RelativeOrAbsolute));
                    DesignerHead4.Margin = new Thickness(99, 23, 0, 0);
                    DesignerHead4.Height = 25;
                    DesignerHead4.Width  = 125;
                    DesignerHead3.Height = 65;
                }
                else
                {
                    DesignerHead4.Source = new BitmapImage(new Uri("/view/Images/6.png", UriKind.RelativeOrAbsolute));
                    DesignerHead4.Margin = new Thickness(10, 0, 0, 0);
                    DesignerHead4.Height = 65;
                    DesignerHead4.Width  = 225;
                    DesignerHead3.Height = 85;
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="uploadManagement">传入上传管理者实体</param>
        /// <returns>返回可以用来上传的辅助对象</returns>
        public ServiceResult GetServiceResult(UploadManagement uploadManagement)
        {
            //service返回结果对象
            ServiceResult serviceResult = new ServiceResult();
            //提前载入唯一Setter
            SetterDAO setterDAO = new SetterDAO();
            Setter    setter    = setterDAO.getSetter();
            //需要加入解密逻辑 TODO
            string mac = "";

            //try
            //{
            //    byte[] deBytes = AesUtil.Decrypt(Encoding.GetEncoding("GBK").GetBytes(setter.Set_Unique_Id),
            //        ProtocolConstant.USB_DOG_PASSWORD);
            //    mac = Encoding.GetEncoding("GBK").GetString(deBytes);
            //}
            //catch (Exception ex)
            //{
            //    mac = setter.Set_Unique_Id.Replace(":", "");
            //}
            byte[] a = ProtocolUtil.StringToBcd(setter.Set_Unique_Id);
            byte[] b = AesUtil.Decrypt(a, ProtocolConstant.USB_DOG_PASSWORD);
            mac = Encoding.GetEncoding("GBK").GetString(b).Replace(":", "-");

            ///if识别出表,设置发送路径,select出实体,转化至DTO,json打成string,返回
            //识别是否是权限用户添加
            if (uploadManagement.UM_DataTable == "bdl_auth")
            {
                AuthDAO authDAO = new AuthDAO();
                Auther  auther  = authDAO.Load(uploadManagement.UM_DataId);
                if (auther == null)
                {
                    return(null);
                }
                AutherDTO autherDTO = new AutherDTO(setter, auther, mac);


                //serviceResult.URL = "clientController/addClient.action";
                serviceResult.Data = JsonTools.Obj2JSONStrNew <AutherDTO>(autherDTO);
            }
            //bdl_customdata表
            else if (uploadManagement.UM_DataTable == "bdl_customdata")
            {
                CustomDataDAO customDataDAO = new CustomDataDAO();
                CustomData    customData    = customDataDAO.Load(uploadManagement.UM_DataId);
                if (customData == null)
                {
                    return(null);
                }
                CustomDataDTO customDataDTO = new CustomDataDTO(customData, mac);
                serviceResult.Data = JsonTools.Obj2JSONStrNew <CustomDataDTO>(customDataDTO);
            }
            //bdl_datacode表
            else if (uploadManagement.UM_DataTable == "bdl_datacode")
            {
                DataCodeDAO dataCodedao = new DataCodeDAO();
                DataCode    dataCode    = dataCodedao.Load(uploadManagement.UM_DataId);

                if (dataCode == null)
                {
                    return(null);
                }
                DataCodeDTO dataCodeDTO = new DataCodeDTO(dataCode, mac);
                serviceResult.Data = JsonTools.Obj2JSONStrNew <DataCodeDTO>(dataCodeDTO);
            }
            //bdl_deviceset表
            else if (uploadManagement.UM_DataTable == "bdl_deviceset")
            {
                DeviceSetDAO deviceSetDAO = new DeviceSetDAO();
                DeviceSet    deviceSet    = deviceSetDAO.Load(uploadManagement.UM_DataId);
                if (deviceSet == null)
                {
                    return(null);
                }
                DeviceSetDTO deviceSetDTO = new DeviceSetDTO(deviceSet, mac);

                serviceResult.Data = JsonTools.Obj2JSONStrNew <DeviceSetDTO>(deviceSetDTO);
            }
            //bdl_devicesort表
            else if (uploadManagement.UM_DataTable == "bdl_devicesort")
            {
                DeviceSortDAO deviceSortDAO = new DeviceSortDAO();
                DeviceSort    deviceSort    = deviceSortDAO.Load(uploadManagement.UM_DataId);
                if (deviceSort == null)
                {
                    return(null);
                }
                DeviceSortDTO deviceSortDTO = new DeviceSortDTO(deviceSort, mac);


                serviceResult.Data = JsonTools.Obj2JSONStrNew <DeviceSortDTO>(deviceSortDTO);
            }
            //bdl_onlinedevice表
            else if (uploadManagement.UM_DataTable == "bdl_onlinedevice")
            {
                OnlineDeviceDAO onlineDeviceDAO = new OnlineDeviceDAO();
                OnlineDevice    onlineDevice    = onlineDeviceDAO.Load(uploadManagement.UM_DataId);

                if (onlineDevice == null)
                {
                    return(null);
                }
                OnlineDeviceDTO onlineDeviceDTO = new OnlineDeviceDTO(onlineDevice, mac);

                serviceResult.Data = JsonTools.Obj2JSONStrNew <OnlineDeviceDTO>(onlineDeviceDTO);
            }
            //bdl_set表
            else if (uploadManagement.UM_DataTable == "bdl_set")
            {
                SetterDAO setterDAO1 = new SetterDAO();
                Setter    setter1    = setterDAO1.Load(uploadManagement.UM_DataId);

                if (setter1 == null)
                {
                    return(null);
                }

                SetterDTO setterDTO = new SetterDTO(setter1, mac);

                serviceResult.Data = JsonTools.Obj2JSONStrNew <SetterDTO>(setterDTO);
            }
            //病人表
            else if (uploadManagement.UM_DataTable == "bdl_user")
            {
                UserDAO userDAO = new UserDAO();
                User    user    = userDAO.Load(uploadManagement.UM_DataId);
                if (user == null)
                {
                    return(null);
                }


                UserDTO userDTO = new UserDTO(user, mac);
                //serviceResult.URL = "bigData/bodyStrongUser";
                serviceResult.Data = JsonTools.Obj2JSONStrNew <UserDTO>(userDTO);
            }

            //症状表
            else if (uploadManagement.UM_DataTable == "bdl_symptominfo")
            {
                SymptomInfoDao symptomInfoDao = new SymptomInfoDao();
                var            result         = symptomInfoDao.Load(uploadManagement.UM_DataId);
                if (result == null)
                {
                    return(null);
                }


                SymptomInfoDTO symptomInfoDTO = new SymptomInfoDTO(result, mac);
                //serviceResult.URL = "bigData/symptomInfo";
                serviceResult.Data = JsonTools.Obj2JSONStrNew <SymptomInfoDTO>(symptomInfoDTO);
            }

            //训练处方总表
            else if (uploadManagement.UM_DataTable == "bdl_traininfo")
            {
                TrainInfoDAO trainInfoDAO = new TrainInfoDAO();
                var          result       = trainInfoDAO.Load(uploadManagement.UM_DataId);
                if (result == null)
                {
                    return(null);
                }


                TrainInfoDTO trainInfoDTO = new TrainInfoDTO(result, mac);
                //serviceResult.URL = "bigData/trainInfo";
                serviceResult.Data = JsonTools.Obj2JSONStrNew <TrainInfoDTO>(trainInfoDTO);
            }

            //总表中的一条数据对某台设备的具体处方
            else if (uploadManagement.UM_DataTable == "bdl_deviceprescription")
            {
                DevicePrescriptionDAO devicePrescriptionDAO = new DevicePrescriptionDAO();
                var result = devicePrescriptionDAO.Load(uploadManagement.UM_DataId);
                if (result == null)
                {
                    return(null);
                }


                DevicePrescriptionDTO devicePrescriptionDTO = new DevicePrescriptionDTO(result, mac);
                //serviceResult.URL = "bigData/devicePrescription";
                serviceResult.Data = JsonTools.Obj2JSONStrNew <DevicePrescriptionDTO>(devicePrescriptionDTO);
            }
            //具体处方的具体反馈
            else if (uploadManagement.UM_DataTable == "bdl_prescriptionresult")
            {
                PrescriptionResultDAO prescriptionResultDAO = new PrescriptionResultDAO();
                var result = prescriptionResultDAO.Load(uploadManagement.UM_DataId);
                if (result == null)
                {
                    return(null);
                }


                PrescriptionResultDTO prescriptionResultDTO = new PrescriptionResultDTO(result, mac);
                //serviceResult.URL = "bigData/prescriptionResult";
                serviceResult.Data = JsonTools.Obj2JSONStrNew <PrescriptionResultDTO>(prescriptionResultDTO);
            }
            else if (uploadManagement.UM_DataTable == "bdl_physicalpower")
            {
                PhysicalPowerDAO physicalPowerDAO = new PhysicalPowerDAO();
                var result = physicalPowerDAO.Load(uploadManagement.UM_DataId);
                if (result == null)
                {
                    return(null);
                }

                PhysicalPowerDTO physicalPowerDTO = new PhysicalPowerDTO(result, mac);
                //serviceResult.URL = "bigData/physicalPower";
                serviceResult.Data = JsonTools.Obj2JSONStrNew <PhysicalPowerDTO>(physicalPowerDTO);
            }
            else if (uploadManagement.UM_DataTable == "bdl_error")
            {
                ErrorDao errorDao = new ErrorDao();
                var      result   = errorDao.Load(uploadManagement.UM_DataId);
                if (result == null)
                {
                    return(null);
                }

                ErrorDTO errorDTO = new ErrorDTO(result, mac);
                //serviceResult.URL = "bigData/physicalPower";
                serviceResult.Data = JsonTools.Obj2JSONStrNew <ErrorDTO>(errorDTO);
            }

            return(serviceResult);
        }
Esempio n. 11
0
        /// <summary>
        /// 应用启动的时候生命周期
        /// </summary>
        /// <param name="ex"></param>
        protected override void OnStartup(StartupEventArgs ex)
        {
            //全局异常处理机制,UI异常
            Current.DispatcherUnhandledException += App_OnDispatcherUnhandledException;
            //全局异常处理机制,线程异常
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            //加载语言
            LanguageUtils.SetLanguage();

            //启动netty,用于与设备端通信
            Thread th = new Thread(() =>
            {
                try
                {
                    logger.Info("线程启动成功");
                    NettyLuncher.getInstance().Start().Wait();
                }
                catch (AggregateException ee)
                {
                    App.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        MessageBoxX.Info(LanguageUtils.GetCurrentLanuageStrByKey("App.PortOccupy"));
                        System.Environment.Exit(0);
                    }));
                }
            });

            th.Start();


            //启动远程更新
            Thread updateTh = new Thread(() =>
            {
                try
                {
                    Thread.Sleep(1000 * 8);
                    Dictionary <string, string> param = new Dictionary <string, string>();

                    param.Add("version", CommUtil.GetCurrentVersion());
                    var result = HttpSender.GET(HttpSender.URL_UPDATE, param);
                    if (string.IsNullOrEmpty(result))
                    {
                        return;
                    }
                    var info = JsonTools.DeserializeJsonToObject <VersionInfo>(result);
                    if (info == null || info.update == false)
                    {
                        return;
                    }

                    info.language = LanguageUtils.IsChainese() ? 1 : 0;
                    App.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        Boolean dr = MessageBoxX.Question(LanguageUtils.GetCurrentLanuageStrByKey("App.UpdateInfo"));
                        if (dr == true)
                        {
                            Process.Start("AutoUpdater.exe", info.GetProcessString());
                            Environment.Exit(0);
                        }
                    }));
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc.ToString());
                    return;
                }
            });

            updateTh.Start();



            //大数据线程

            Thread bdth = new Thread(() =>
            {
                try
                {
                    SetterDAO setterDao = new SetterDAO();
                    AuthDAO authDAO     = new AuthDAO();
                    while (true)
                    {
                        if (setterDao.ListAll().Count != 1)
                        {
                            //不激活不开启
                            Thread.Sleep(1000 * 15);
                            continue;
                        }
                        if (authDAO.ListAll().Count == 1)
                        {
                            //Console.WriteLine("-----------------boom shakalaka--------------");
                            //只有admin,不创建用户,不开启,睡个15s
                            Thread.Sleep(1000 * 15);
                            continue;
                        }
                        try
                        {
                            BigDataOfficer bigDataOfficer = new BigDataOfficer();
                            bigDataOfficer.Run();
                            //int heartBeatRate = (int)CommUtil.GetBigDataRate();
                            Thread.Sleep(1000 * 60);
                            //Console.WriteLine("-----------------boom");
                        }
                        catch (Exception e)
                        {
                            logger.Error("大数据线程失败:" + e.StackTrace);
                            Console.WriteLine("大数据线程失败:" + e.Message);
                        }
                    }
                }
                catch (Exception exct)
                {
                    Console.WriteLine(exct.ToString());
                }
            });

            bdth.Start();

            //心跳线程
            Thread hbth = new Thread(() =>
            {
                ProtoBufSocket socket = null;
                try
                {
                    socket = new ProtoBufSocket();
                    socket.Connect();
                }
                catch (Exception exception)
                {
                    Console.WriteLine("连接失败:" + exception.StackTrace);
                    TcpHeartBeatUtils.WriteLogFile("连接失败:" + exception.StackTrace);
                }

                while (true)
                {
                    try
                    {
                        BodyStrongMessage bodyStrongMessage = new BodyStrongMessage
                        {
                            MessageType = BodyStrongMessage.Types.MessageType.Heaerbeatreq,
                            //可能为null
                            HeartbeatRequest = TcpHeartBeatUtils.GetHeartBeatByCurrent()
                        };

                        socket.SendMessage(bodyStrongMessage);
                        Console.WriteLine("发送msg!!");
                        //Thread.Sleep(5000);
                    }
                    catch (Exception eee)
                    {
                        Console.WriteLine("发送msg失败" + eee.StackTrace);
                        TcpHeartBeatUtils.WriteLogFile("发送msg失败" + eee.StackTrace);
                    }
                    finally
                    {
                        Thread.Sleep(5000);
                    }
                }
            });

            hbth.Start();

            base.OnStartup(ex);
        }
Esempio n. 12
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <returns></returns>
        public string Login(string username, string password)
        {
            string  loginResult = "success";
            AuthDAO authDAO     = new AuthDAO();

            //先验证admin
            Auther auther = authDAO.Login(username, password);

            //超管监测权限
            if (auther != null && auther.Auth_Level == Auther.AUTH_LEVEL_ADMIN)
            {
                loginResult = "check_U";
                return(loginResult);
            }
            Auther autherCN = authDAO.GetByName(username);

            //密码错误
            if (autherCN == null)
            {
                loginResult = "没有该用户";
                return(loginResult);
            }

            //没有该用户
            if (autherCN != null && auther == null)
            {
                loginResult = "密码错误!";
                return(loginResult);
            }
            //普通用户测试是否超时登录
            if (auther.Auth_OfflineTime < DateTime.Now)
            {
                loginResult = "您的使用时间已经用尽,请联系宝德龙管理员";
                return(loginResult);
            }


            //登录mac与激活mac不对应
            SetterDAO setterDAO = new SetterDAO();
            Setter    setter    = setterDAO.getSetter();

            string mac = "";

            try {
                byte[] debytes = AesUtil.Decrypt(Encoding.GetEncoding("GBK").GetBytes(setter.Set_Unique_Id), ProtocolConstant.USB_DOG_PASSWORD);

                mac = Encoding.GetEncoding("GBK").GetString(debytes);
                //byte[] a = ProtocolUtil.StringToBcd(setter.Set_Unique_Id);
                //byte[] b = AesUtil.Decrypt(a, ProtocolConstant.USB_DOG_PASSWORD);
                //mac = Encoding.GetEncoding("GBK").GetString(b);
            }
            catch (Exception ex)
            {
                //解密出现问题,经常会报错,目前是直接返回的登陆成功的信息。
                logger.Error("解密异常:" + ex.Message);
                //Console.WriteLine("解密异常:" + ex.Message);
                //loginResult = "解密异常.";
                //return loginResult;
            }
            //如果解密后的setter中的mac不包含现在获得的mac
            if (mac.IndexOf(SystemInfo.GetMacAddress().Replace(":", "-")) == -1)
            {
                //Console.WriteLine("DB:"+ mac);
                //Console.WriteLine("current:" + SystemInfo.GetMacAddress().Replace(":","-"));

                //loginResult = "登录异常";
                //return loginResult;
                logger.Error("机器码匹配异常," + DateTime.Now.ToString());
            }
            if (autherCN.User_Status == Auther.USER_STATUS_FREEZE)
            {
                loginResult = "用户已被冻结";
                return(loginResult);
            }
            return(loginResult);
        }