You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.9 KiB

using connor_zwcadm.util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Teamcenter.ClientX;
using Teamcenter.Services.Strong.Core;
namespace connor_zwcadm.dialog {
/// <summary>
/// Login.xaml 的交互逻辑
/// </summary>
public partial class Login : Window {
private bool loginResult = false;
private bool closeAfterLogin;
public Login(string userName, bool closeAfterLogin) {
InitializeComponent();
UIUtil.SetOwnerWindow(this);
this.closeAfterLogin = closeAfterLogin;
SetLoginVisible(userName);
tb_UserName.Text = ConfigUtil.GetValue(ConfigUtil.LAST_LOGIN_USER);
}
private void DoLogin(object sender, RoutedEventArgs e) {
string id = tb_UserName.Text;
string password = tb_Password.Password;
string host = ConfigUtil.GetValue(ConfigUtil.TC_HOST);
try {
string userName = TCUtil.Login(host, id, password, "");
SetLoginVisible(userName);
if (closeAfterLogin) {
Close();
}
}
catch (Teamcenter.Schemas.Soa._2006_03.Exceptions.InvalidCredentialsException e1) {
MessageBox.Show(this, "登录失败,用户名或密码错误", "提示");
KUtil.LogErr(e1);
}
catch (System.Exception ex) {
MessageBox.Show(this, "登录失败:\n" + ex.Message, "提示");
KUtil.LogErr(ex);
}
}
public bool getLoginResult() {
return loginResult;
}
private void SetLoginVisible(string userName) {
Visibility v;
if (string.IsNullOrWhiteSpace(userName)) {
v = Visibility.Hidden;
}
else {
v = Visibility.Visible;
}
loginResult = !string.IsNullOrWhiteSpace(userName);
l_UserName.Content = "当前登录用户:" + userName;
rec_Logout.Visibility = v;
b_Logout.Visibility = v;
l_UserName.Visibility = v;
// l_UserNameTitle.Visibility = v;
b_Login.IsEnabled = string.IsNullOrWhiteSpace(userName);
}
private void Window_MouseDown(object sender, MouseButtonEventArgs e) {
if (e.ChangedButton == MouseButton.Left)
this.DragMove();
}
private void Button_Click_1(object sender, RoutedEventArgs e) {
Close();
}
private void DoLogout(object sender, RoutedEventArgs e) {
Session.logout();
KUtil.Log("已注销" + l_UserName.Content);
SetLoginVisible(null);
}
}
}