예제 #1
0
 private void Btn_Confirm(object sender, RoutedEventArgs e)
 {//MessageBox.Show(LanguageUtils.ConvertLanguage("你确认要保存更改吗", "Are you sure you want to save your changes?"), LanguageUtils.ConvertLanguage("提示:", "Tips"), MessageBoxButton.OKCancel) == MessageBoxResult.OK
     if (MessageBoxX.Question(LanguageUtils.ConvertLanguage("你确认要保存更改吗", "Are you sure you want to save your changes?")))
     {
         string textValue1 = textBox1.Text;                         //机构团体名称
         string textValue2 = textBox2.Text;                         //照片保存文档
         string textValue3 = textBox3.Text;                         //机构电话
         //string textValue4 = textBox4.Text;//版本
         string        textValue5        = textBox5.Text;           //备份
         int           comboBox1Selected = comboBox1.SelectedIndex; //机构区分被选择的index
         int           comboBox2Selected = comboBox2.SelectedIndex; //语言被选择的index
         entity.Setter setter            = new entity.Setter();
         setter.Pk_Set_Id             = Pk_Set_Id;
         setter.Set_OrganizationName  = textValue1;
         setter.Set_PhotoLocation     = textValue2;
         setter.Set_OrganizationPhone = textValue3;
         //setter.Set_Version = textValue4;
         if (textValue5.Contains(" "))
         {
             MessageBoxX.Warning(LanguageUtils.ConvertLanguage("备份路径不能含有空格", "Backup path cannot contain spaces"));
         }
         else
         {
             setter.Back_Up              = textValue5;//备份路径
             setter.Set_Version          = CommUtil.GetCurrentVersion();
             setter.Set_Language         = comboBox2Selected;
             setter.Set_OrganizationSort = comboBox1Selected.ToString();
             setterDao.UpdateSetter(setter);
             //切换语言
             LanguageUtils.SetLanguage();
             GoBack(null, null);
         }
     }
 }
예제 #2
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);
        }
예제 #3
0
        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;
        }
        private void Btn_Activate(object sender, RoutedEventArgs e)
        {
            //InputNonPublicInformationPassword
            InputNonPublicInformationPassword passwordInput = new InputNonPublicInformationPassword
            {
                Owner                 = Window.GetWindow(this),
                ShowActivated         = true,
                ShowInTaskbar         = false,
                WindowStartupLocation = WindowStartupLocation.CenterScreen
            };

            passwordInput.ShowDialog();
            if (ProtocolConstant.USB_SUCCESS == 0) //u盘成功读取 破解状态为0
            {                                      //获取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.Back_Up      = basePath + @"BackUp\";
                setter.Set_Language = 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);
                //注释的部分为添加多个mac地址
                // List<entity.Setter> ListMac = CommUtil.GetMacByWMI();
                // SetterDAO.InsertMacAdress(ListMac);



                Status.Content = LanguageUtils.GetCurrentLanuageStrByKey("SettingsView.Activated");
                Color color = Color.FromArgb(255, 2, 200, 5);
                Status.Foreground     = new SolidColorBrush(color);
                BtnActivite.IsEnabled = false;
            }
            else
            {
                MessageBoxX.Error(LanguageUtils.ConvertLanguage("激活失败", "Activation fails"));
            }
        }
예제 #5
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);
        }