Beispiel #1
0
 private void btnOk_Click(object sender, RoutedEventArgs e)
 {
     if (string.IsNullOrEmpty(this.txtUserName.Text))
     {
         MessageBox.Show(this, App.Current.FindResource("Message_67").ToString());
         this.txtUserName.Focus();
     }
     else if (string.IsNullOrEmpty(this.txtPwd.Password))
     {
         MessageBox.Show(this, App.Current.FindResource("Message_68").ToString());
         this.txtPwd.Focus();
     }
     else
     {
         NameValueCollection postDict = new NameValueCollection();
         postDict.Add("username", this.txtUserName.Text);
         postDict.Add("password", this.txtPwd.Password);
         postDict.Add("language", App.local);
         string responseStr = null;
         try
         {
             responseStr = HttpWebTools.Post(App.reportSettingModel.CloudPath + "/api/login", postDict);
             if (responseStr != null)
             {
                 var  jsonObj = JObject.Parse(responseStr);
                 bool status  = (bool)jsonObj["status"];
                 if (status)
                 {
                     App.reportSettingModel.CloudUser = this.txtUserName.Text;
                     var dataObj = (JObject)jsonObj["data"];
                     App.reportSettingModel.CloudToken = (string)dataObj["token"];
                     this.DialogResult = (bool?)true;
                     this.Close();
                 }
                 else
                 {
                     var info = (string)jsonObj["info"];
                     MessageBox.Show(this, info);
                     this.txtUserName.Focus();
                 }
             }
         }
         catch (Exception exe)
         {
             MessageBox.Show(this, exe.Message);
             this.txtUserName.Focus();
         }
     }
 }
 private void btnOk_Click(object sender, RoutedEventArgs e)
 {
     if (string.IsNullOrEmpty(this.txtLicense.Text))
     {
         MessageBox.Show(this, App.Current.FindResource("Message_71").ToString());
     }
     else
     {
         try
         {
             NameValueCollection nvlist = new NameValueCollection();
             nvlist.Add("license", this.txtLicense.Text);
             nvlist.Add("cpuid", ComputerInfoTools.GetCPUId());
             var  res     = HttpWebTools.Post(App.reportSettingModel.CloudPath + "/api/active", nvlist);
             var  jsonObj = JObject.Parse(res);
             bool status  = (bool)jsonObj["status"];
             if (status)
             {
                 App.reportSettingModel.License = this.txtLicense.Text;
                 OperateIniFile.WriteIniData("Base", "License", this.txtLicense.Text, System.AppDomain.CurrentDomain.BaseDirectory + "Config.ini");
                 string filePath = System.AppDomain.CurrentDomain.BaseDirectory + "license.dat";
                 SecurityTools.EncryptTextToFile(App.reportSettingModel.License + ComputerInfoTools.GetCPUId(), filePath);
                 MessageBox.Show(this, App.Current.FindResource("Message_73").ToString());
                 this.DialogResult = (bool?)true;
                 this.Close();
             }
             else
             {
                 string info = (string)jsonObj["info"];
                 MessageBox.Show(this, info);
             }
         }
         catch (Exception exe)
         {
             MessageBox.Show(this, App.Current.FindResource("Message_72").ToString() + exe.Message);
         }
     }
     this.txtLicense.Focus();
 }