private void btnLogin_Click(object sender, RoutedEventArgs e) { lblMessages.Content = null; if (string.IsNullOrWhiteSpace(txtJobNo.Text) || string.IsNullOrWhiteSpace(txtPassword.Password)) { if (string.IsNullOrWhiteSpace(txtJobNo.Text)) { lblMessages.Content = "请输入用户名;"; } if (string.IsNullOrWhiteSpace(txtPassword.Password)) { lblMessages.Content += "请输入密码;"; } } else { OaIni oaIni = new OaIni { JobNo = txtJobNo.Text, Password = txtPassword.Password, IsSavePassword = chkPassword.IsChecked == true, IsAutoLog = chkLogin.IsChecked == true, ServerIp = cbServerIp.SelectedIndex == 0 ? "192.168.1.80" : "113.105.185.82", Port = 8885 }; var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "oa.ini"); bool isExists = System.IO.File.Exists(path); if (isExists) { System.IO.File.Delete(path); } using (StreamWriter sw = System.IO.File.CreateText(path)) { sw.WriteLine(JavaScriptConvert.SerializeObject(oaIni)); } MainWindow mainWindow = new MainWindow(oaIni); mainWindow.Show(); this.Close(); } }
void Login_Loaded(object sender, RoutedEventArgs e) { Keyboard.Focus(txtJobNo); var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "oa.ini"); if (System.IO.File.Exists(path)) { using (StreamReader sr = System.IO.File.OpenText(path)) { string s = sr.ReadLine(); if (!string.IsNullOrWhiteSpace(s)) { OaIni oaIni = JavaScriptConvert.DeserializeObject<OaIni>(s); if (oaIni.IsSavePassword) { txtJobNo.Text = oaIni.JobNo; txtPassword.Password = oaIni.Password; chkPassword.IsChecked = true; Keyboard.Focus(btnLogin); } if(oaIni.IsAutoLog) { chkLogin.IsChecked = true; if(_isAutoLogin) { MainWindow mainWindow = new MainWindow(oaIni); mainWindow.Show(); this.Close(); } } } } } }