using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using 報到系統客戶端.Services; namespace 報到系統客戶端 { public partial class LoginForm : Form { public LoginForm() { InitializeComponent(); lbApiUrlBase.Text = string.Format("主機:{0}", ApiService.Instance.BaseUrl); lbVersion.Text = ClientSession.Version; } private void btnCancel_Click(object sender, EventArgs e) { Application.Exit(); } private async void btnLogin_Click(object sender, EventArgs e) { try { btnLogin.Enabled = false; btnCancel.Enabled = false; btnLogin.Text = "登入中"; Cursor.Current = Cursors.WaitCursor; Application.DoEvents(); if (cbOffline.Checked) { var loginResult = ClientSession.LoginOffline(txtUserID.Text); if (loginResult.Item1) { DialogResult = DialogResult.OK; } else { MessageBox.Show(loginResult.Item2, "登入錯誤"); } } else { var loginResult = await ClientSession.LoginAsync(txtUserID.Text, txtPassword.Text); if (loginResult.Item1) { DialogResult = DialogResult.OK; } else { MessageBox.Show(loginResult.Item2, "登入錯誤"); } } } finally { Cursor.Current = Cursors.Default; btnLogin.Enabled = true; btnCancel.Enabled = true; btnLogin.Text = "登入"; } } private void LoginForm_Activated(object sender, EventArgs e) { txtUserID.Focus(); } private void cbOffline_CheckStateChanged(object sender, EventArgs e) { txtPassword.Enabled = !cbOffline.Checked; } } }