8,734
社区成员
发帖
与我相关
我的任务
分享
private void InitCommand()
{
LoginCommand = new DelegateCommand() { ExecuteAction = Login };
}
private void Login(object param)
{
if (!string.IsNullOrEmpty(CustomerId) && !string.IsNullOrEmpty(CustomerName) && !string.IsNullOrEmpty(Password))
{
thread = new Thread(new ThreadStart(UserLogin));
thread.Start();
}
else
{
IsShow_Login = Visibility.Visible;
Error_Login = Enums.Error_Null;
}
}
private void UserLogin()
{
string url = string.Format("{0}DataHandler.ashx?PageType={1}&CustomerId={2}&CustomerName={3}&Password={4}", ApplicationHelper.WebServicePath, (int)Enums.PageType.登录, CustomerId, CustomerName, Password);
Button_Content = "登录中...";
string jsonStr = Tools.GetHttpData(url, (msg) =>
{
Error_Login = msg;
IsShow_Login = Visibility.Visible;
Button_Content = "登录";
});
if (jsonStr != Enums.Error_Http)
{
if (jsonStr != Enums.Error_Login)
{
ApplicationHelper.c = JsonConvert.DeserializeObject<Model_Customer>(jsonStr);
/***判断密码保存***/
ApplicationHelper.UserXml.Element("root").Element("UserAccount").Element("IsChecked").Value = IsChecked.ToString();
if (IsChecked)
{
ApplicationHelper.UserXml.Element("root").Element("UserAccount").Element("CustomerId").Value = ApplicationHelper.eh.Encrypto(CustomerId);
ApplicationHelper.UserXml.Element("root").Element("UserAccount").Element("CustomerName").Value = ApplicationHelper.eh.Encrypto(CustomerName);
ApplicationHelper.UserXml.Element("root").Element("UserAccount").Element("Password").Value = ApplicationHelper.eh.Encrypto(Password);
}
else
{
ApplicationHelper.UserXml.Element("root").Element("UserAccount").Element("CustomerId").Value = string.Empty;
ApplicationHelper.UserXml.Element("root").Element("UserAccount").Element("CustomerName").Value = string.Empty;
ApplicationHelper.UserXml.Element("root").Element("UserAccount").Element("Password").Value = string.Empty;
}
ApplicationHelper.UserXml.Save(string.Format("{0}\\{1}", AppDomain.CurrentDomain.BaseDirectory, "Xml\\UserConfig.xml"));
/******大神看这里,调用委托打开窗体,我做的对吗?******/
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, LoginWindow.Callback_OpenMainWindow);
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, LoginWindow.Callback_Close);
}
else
{
Button_Content = "登录";
Error_Login = Enums.Error_Login;
IsShow_Login = Visibility.Visible;
}
}
thread.Abort();
}
public static Action Callback_Close { get; set; }
public static Action Callback_OpenMainWindow { get; set; }
public LoginWindow()
{
InitializeComponent();
this.DataContext = new LoginWindowViewModel();
btn_Close.Callback_Close = () =>
{
this.Close();
};
btn_Close.Callback_Min = () =>
{
this.WindowState = WindowState.Minimized;
};
Callback_Close = () => { this.Close(); };
Callback_OpenMainWindow = () =>
{
MainWindow mw = new MainWindow();
mw.Show();
};
}