//添加按钮的事件
        private void Btn_Insert(object sender, RoutedEventArgs e)
        {
            int count = authDAO.GetAuthCount();

            if (SetterDAO.ListAll().Count != 0)
            {//判断是否激活
                if (count < 2)
                {
                    AutherAdd addAuther = new AutherAdd
                    {
                        Owner                 = Window.GetWindow(this),
                        ShowActivated         = true,
                        ShowInTaskbar         = false,
                        WindowStartupLocation = WindowStartupLocation.CenterScreen
                    };
                    addAuther.ShowDialog();
                    FlushAuther();
                    authService.UpLoadAuth();
                }
                else
                {
                    MessageBoxX.Info(LanguageUtils.ConvertLanguage("最多只允许存在一个用户", "Only one user is allowed"));
                }
            }
            else
            {
                MessageBoxX.Info(LanguageUtils.ConvertLanguage("您没有添加权限请先激活", "You did not add permission, please activate first"));
            }
        }
 private void Page_Loaded(object sender, RoutedEventArgs e)
 {
     //加载图片
     if (LanguageUtils.IsChainese())
     {
         title_pic.Source = new BitmapImage(new Uri(@"\view\Images\bdl.PNG", UriKind.Relative));
         title_pic.Height = 198.4;
     }
     else
     {
         //TODO 英文图片
         title_pic.Source = new BitmapImage(new Uri(@"\view\Images\design.png", UriKind.Relative));
         title_pic.Height = 257;
     }
     try
     {
         if (SetterDAO.getSetter() != null)
         {
             if (SetterDAO.getSetter().Set_Unique_Id != "" && SetterDAO.getSetter().Set_Unique_Id != null)//判断是否激活
             {
                 Status.Content = LanguageUtils.GetCurrentLanuageStrByKey("SettingsView.Activated");
                 Color color = Color.FromArgb(255, 2, 200, 5);
                 Status.Foreground     = new SolidColorBrush(color);
                 BtnActivite.IsEnabled = false;
             }
         }
     }
     catch (InvalidOperationException ee)
     {
     }
     setterList = setterDao.ListAll();
     try { Pk_Set_Id = setterList[0].Pk_Set_Id; }
     catch (ArgumentOutOfRangeException ee)
     {
     }
     try
     {
         List <Auther> AutherList = new List <Auther>();
         auther = authDAO.GetAuther(auth_level);
         AutherList.Add(auther);
         ((this.FindName("DataGrid1")) as DataGrid).ItemsSource = AutherList;
     }
     catch (Exception ee) { }
     try
     {
         DeviceSetList = deviceSetDAO.ListAll();
         ((this.FindName("ComboBox_Device")) as ComboBox).ItemsSource = DeviceSetList;//系列
         int Dset_Id = (int)ComboBox_Device.SelectedValue;
         DeviceSortList = deviceSortDAO.GetDeviceSortBySet(Dset_Id);
         ((this.FindName("DataGrid2")) as DataGrid).ItemsSource = DeviceSortList;//类型
     }
     catch (Exception ee)
     {
     }
 }
Beispiel #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);
        }
        /// <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);
        }
Beispiel #5
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
        }
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            //加载图片
            if (LanguageUtils.IsChainese())
            {
                title_pic.Source = new BitmapImage(new Uri(@"\view\Images\bdl.PNG", UriKind.Relative));
            }
            else
            {
                title_pic.Source = new BitmapImage(new Uri(@"\view\Images\design.png", UriKind.Relative));
            }
            entity.Setter setter = new entity.Setter();
            //setter.Pk_Set_Id = 5;
            //setterList.Add(setterDao.Load(setter.Pk_Set_Id));
            setterList = setterDao.ListAll();
            //初始化版本号
            if (setterList != null && setterList.Count == 1)
            {
                setterList[0].Set_Version = CommUtil.GetCurrentVersion();
            }
            try
            {
                Pk_Set_Id = setterList[0].Pk_Set_Id;
            }
            catch (ArgumentOutOfRangeException ee)
            {
            }

            try { comboBox2.SelectedIndex = setterList[0].Set_Language; }
            catch (ArgumentOutOfRangeException ee)
            {
                comboBox2.SelectedIndex = 1;
            }
            try
            {
                comboBox1.SelectedIndex = int.Parse(setterList[0].Set_OrganizationSort);
            }
            catch (Exception ee)
            {
                comboBox1.SelectedIndex = 1;
            }
            ObservableCollection <entity.Setter> DataCollection = new ObservableCollection <entity.Setter>(setterList);

            textBox1.DataContext  = DataCollection;                               //设置机构团体名称
            textBox2.DataContext  = DataCollection;                               //设置照片保存文档
            textBox3.DataContext  = DataCollection;                               //设置机构电话
            textBox4.DataContext  = DataCollection;                               //设置当前版本
            textBox5.DataContext  = DataCollection;                               //设置备份地址
            ListDataCode          = DataCodeDAO.ListByTypeId("OrganizationSort"); //绑定组织区分
            comboBox1.ItemsSource = ListDataCode;
            ListDataCode          = DataCodeDAO.ListByTypeId("Language");         //绑定语言
            comboBox2.ItemsSource = ListDataCode;
            //下方三个datagrid的实现
            groupList     = customDataService.GetAllObjectByType(CustomDataEnum.Group);
            diseaseList   = customDataService.GetAllObjectByType(CustomDataEnum.Disease);
            diagnosisList = customDataService.GetAllObjectByType(CustomDataEnum.Diagiosis);

            ((this.FindName("DataGrid2")) as DataGrid).ItemsSource = groupList;
            ((this.FindName("DataGrid3")) as DataGrid).ItemsSource = diseaseList;
            ((this.FindName("DataGrid4")) as DataGrid).ItemsSource = diagnosisList;
        }
Beispiel #7
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);
        }
        /// <summary>
        /// 定时器轮询方法
        /// </summary>
        /// <param name="threadCount"></param>
        ///
        public void Run()
        {
            if (setterDao.ListAll() == null)
            {
                //网路不通 或 未注册 不上传//Console.WriteLine("大数据线程实例化run方法-执行:");

                return;
            }



            //从上传表查询30条数据
            var result = uploadManagementService.ListLimit30();

            if (result == null)
            {
                Console.WriteLine("大数据线程RUN方法-result==null");
            }
            //遍历查询到的数据集合
            foreach (var uploadManagement in result)
            {
                //生成新的SendMsgDTO对象(上传云平台的最终对象)
                SendMsgDTO sendMsgDto = new SendMsgDTO();

                //根据表名,给字段dataType(数据所在实体类)赋值
                switch (uploadManagement.UM_DataTable)
                {
                case "bdl_auth":
                    sendMsgDto.dataType = "Auther";
                    break;

                case "bdl_customdata":
                    sendMsgDto.dataType = "CustomData";
                    break;

                case "bdl_datacode":
                    sendMsgDto.dataType = "DataCode";
                    break;

                case "bdl_deviceprescription":
                    sendMsgDto.dataType = "DevicePrescription";
                    break;

                case "bdl_deviceset":
                    sendMsgDto.dataType = "DeviceSet";
                    break;

                case "bdl_devicesort":
                    sendMsgDto.dataType = "DeviceSort";
                    break;

                case "bdl_onlinedevice":
                    sendMsgDto.dataType = "OnlineDevice";
                    break;

                case "bdl_physicalpower":
                    sendMsgDto.dataType = "PhysicalPower";
                    break;

                case "bdl_prescriptionresult":
                    sendMsgDto.dataType = "PrescriptionResult";
                    break;

                case "bdl_set":
                    sendMsgDto.dataType = "Setter";
                    break;

                case "bdl_symptominfo":
                    sendMsgDto.dataType = "SymptomInfo";
                    break;

                case "bdl_traininfo":
                    sendMsgDto.dataType = "TrainInfo";
                    break;

                case "bdl_user":
                    sendMsgDto.dataType = "User";
                    break;

                case "bdl_error":
                    sendMsgDto.dataType = "Error";
                    break;

                default:
                    Console.WriteLine("没找到对应的表");
                    //Console.WriteLine(uploadManagement.UM_DataTable);
                    break;
                }

                sendMsgDto.dataExec      = uploadManagement.UM_Exec;   //操作方式 0是add(insert) 1是update
                sendMsgDto.dataId        = uploadManagement.UM_DataId; //数据的id
                sendMsgDto.belongProduct = "Recovery";                 //项目名称必须是这个,与云平台相一致
                if (sendMsgDto.dataType == "Error")
                {
                    sendMsgDto.belongProduct = "RecoveryError";
                }


                // Console.WriteLine("大数据线程实例化Upload方法-table:" + uploadManagement.UM_DataTable);
                //1.根据上传表内容查询具体数据(这里的数据是已经转换成json串形式),赋值给字段content
                ServiceResult serviceResult = null;
                try
                {
                    serviceResult = uploadManagementService.GetServiceResult(uploadManagement);
                }
                catch (Exception e)
                {
                    logger.Error("uploadManagement上传云平台失败");
                }

                /*
                 * int i = 1;
                 * Console.WriteLine("这里是上传表的每一条内容" + i + "数字" + uploadManagement.Pk_UM_Id + uploadManagement.UM_DataId + uploadManagement.UM_Exec);
                 * i++;*/
                if (serviceResult == null)
                {
                    //没有查到返回
                    Console.WriteLine("上传表查询失败____________________");
                    logger.Error("上传表查询失败," + DateTime.Now.ToString());
                    continue;
                }
                sendMsgDto.content = serviceResult.Data;
                //用于接受云服务器端返回的字符串
                string strWebResult = "";
                //创建一个新的用来接受服务器端返回结果的对象
                WebResult webResult = new WebResult();

                //这里是url的后缀,每一条数据都是发送到这个地方
                serviceResult.URL = "msg";

                //将发送的实体类SendMsgDTO装成json串
                serviceResult.Data = JsonTools.Obj2JSONStrNew <SendMsgDTO>(sendMsgDto);

                //2.上传和接受云服务器端返回的字符串
                //strWebResult = HttpSender.POSTByJsonStr(serviceResult.URL, serviceResult.Data);
                strWebResult = HTTPClientHelper.HttpPost(serviceResult.Data);

                //将接受到的字符串赋值给webResult对象
                webResult = JsonTools.DeserializeJsonToObject <WebResult>(strWebResult);

                //Console.WriteLine("线程"+ threadCount +"   id: "+webResult.dataId +"type: "+ webResult.dataType + "结果:"+webResult.result);


                //3.根据返回结果删除
                //返回值result为0或1删除上传表所对应的的内容,2则跳出循环,不做处理,隔五分钟再次上传
                if (webResult.result == "0")
                {
                    uploadManagementService.deleteByPrimaryKey(uploadManagement.Pk_UM_Id);
                }
                else
                if (webResult.result == "1")
                {
                    uploadManagementService.deleteByPrimaryKey(uploadManagement.Pk_UM_Id);
                }
                else
                if (webResult.result == "2")
                {
                    Console.WriteLine("线程");
                    break;//不做处理,五分钟后再发,目的是等待云服务器建表
                }
                else
                {
                    logger.Error("失败的内容:" + webResult.result + "," + DateTime.Now.ToString());
                    //Console.WriteLine("失败的内容:" + webResult.result);
                }
                //Console.WriteLine("-----------------------------返回结果 dataid"+webResult.dataId +"type:"+webResult.dataType+"result:"+webResult.result);
            }
        }