Beispiel #1
0
        public LoginWindow()
        {
            InitializeComponent();

            string versionValue = string.Empty;

            try
            {
                XmlDocument doc      = new XmlDocument();
                String      CurrPath = Directory.GetCurrentDirectory().Trim();
                if (CurrPath.EndsWith("upgrade"))
                {
                    doc.Load(@"config.xml");
                }
                else
                {
                    doc.Load(@"upgrade\config.xml");
                }
                XmlElement root = doc.DocumentElement;

                foreach (XmlElement item in root.ChildNodes)
                {
                    string codeTxt = string.Empty;
                    string nameTxt = string.Empty;
                    if (item.Name == "CurrVersion")
                    {
                        versionValue = item.ChildNodes[0].Value;
                        break;
                    }
                }
            }
            catch (Exception err)
            {
                LogHelper.WriteWarnLog("Get version failed:" + err.Message);
                versionValue = Properties.Settings.Default.app_version;
            }

            competent_organization.Content = Properties.Settings.Default.competent_organization;
            province.Content        = Properties.Settings.Default.province;
            app_type.Content        = Properties.Settings.Default.app_type;
            app_name.Content        = Properties.Settings.Default.app_name + "V" + versionValue;
            support_company.Content = Properties.Settings.Default.support_company;
            support_tel.Content     = Properties.Settings.Default.support_tel;
            RESTClient.REST_HOST    = Properties.Settings.Default.rest_host;

            if (!Directory.Exists(CommDef.ApplicationDataPath))
            {
                Directory.CreateDirectory(CommDef.ApplicationDataPath);
            }

            string computerInfo    = ComputerInfo.GetComputerInfo();
            string encryptComputer = new EncryptionHelper().EncryptString(computerInfo);

            EncryptionHelper help       = new EncryptionHelper(EncryptionKeyEnum.KeyB);
            string           md5String  = help.GetMD5String(encryptComputer);
            string           registInfo = help.EncryptString(md5String);

            //判断是否已经运行
            Process selfProcess = Process.GetCurrentProcess();

            Process[] allProcess = Process.GetProcessesByName("SignInApp");
            foreach (Process item in allProcess)
            {
                if (item.Id != selfProcess.Id)
                {
                    item.Kill();
                }
            }

            if (RegistFileHelper.ExistRegistInfofile() == true)
            {
                string inputRegist = RegistFileHelper.ReadRegistFile();
                if (registInfo == inputRegist)
                {
                    if (File.Exists(CONF_FILE_NAME) == false)
                    {
                        FileStream fs = new FileStream(CONF_FILE_NAME, FileMode.CreateNew);
                        if (fs != null)
                        {
                            fs.Close();
                        }
                        return;
                    }

                    string userName   = "";
                    string password   = "";
                    string isRemember = "";
                    bool   ret        = GetConfInfo(ref userName, ref password, ref isRemember);
                    if (ret)
                    {
                        if (userName != "")
                        {
                            account.Text            = userName;
                            this.account.Foreground = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0x00, 0x00, 0x00));
                        }

                        if (isRemember == "true")
                        {
                            this.password.Password    = password;
                            this.remainFlag.IsChecked = true;
                        }
                    }
                    return;
                }
            }
            RegistWindow RegistWindowPage = new RegistWindow();

            RegistWindowPage.Show();
            this.Close();
        }
Beispiel #2
0
        private void RegistCehckClick(object sender, EventArgs e)
        {
            if (RegistFileHelper.ExistComputerInfofile() == false)
            {
                System.Windows.MessageBox.Show("注册失败,请先生成本地key文件再向厂商申请...");
                return;
            }

            string           computer   = RegistFileHelper.ReadComputerInfoFile();
            EncryptionHelper help       = new EncryptionHelper(EncryptionKeyEnum.KeyB);
            string           md5String  = help.GetMD5String(computer);
            string           registInfo = help.EncryptString(md5String);

            if (RegistFileHelper.ExistRegistInfofile() == true)
            {
                string inputRegist = RegistFileHelper.ReadRegistFile();
                if (registInfo == inputRegist)
                {
                    LoginWindow LoginWindowPage = new LoginWindow();
                    LoginWindowPage.Show();
                    this.Close();
                    return;
                }
            }

            WinForm.OpenFileDialog openFileDialog = new WinForm.OpenFileDialog();
            if (openFileDialog.ShowDialog() == WinForm.DialogResult.OK)
            {
                string fileName = openFileDialog.FileName;
                license_info_file.Text = fileName;
                string localFileName = string.Concat(
                    RegistFileHelper.ApplicationDataPath,
                    RegistFileHelper.RegistInfofile);
                if (fileName != localFileName)
                {
                    if (File.Exists(localFileName) == false)
                    {
                        File.Create(localFileName).Close();
                    }
                    File.Copy(fileName, localFileName, true);
                }

                string inputRegist = RegistFileHelper.ReadRegistFile();
                if (registInfo == inputRegist)
                {
                    LoginWindow LoginWindowPage = new LoginWindow();
                    LoginWindowPage.Show();
                    this.Close();
                    return;
                }
                else
                {
                    System.Windows.MessageBox.Show("注册失败,请验证License...");
                    return;
                }
            }
            else
            {
                return;
            }
        }