using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Threading; using System.Windows.Forms; using DevExpress.XtraEditors; using GCAS.Code; using GCAS.Dto; using GCAS.Localization; using MySql.Data.MySqlClient; namespace GCAS { public partial class LoginForm : XtraForm { private List L; private OperatorRepository operatorRepository; private ActionsRepository actionsRepository; public LoginForm() { InitializeComponent(); DoubleBuffered = true; L = LocalizationHelper.GetSource(Thread.CurrentThread.CurrentUICulture); } private void LoginForm_Load(object sender, EventArgs e) { actionsRepository = new ActionsRepository(); operatorRepository = new OperatorRepository(); panelControl1.ContentImage = Tools.GetLoginBackground(); } private void btn_cancel_Click(object sender, EventArgs e) { Close(); } private async void btn_login_Click(object sender, EventArgs e) { if (text_username.Text.Trim() == string.Empty) { XtraMessageBox.Show(L.GetString("userNameNotNull"), L.GetString("error"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // ValidServer(); if (text_username.Text == "--recover" && text_password.Text == "!23Qwe") { var result = await actionsRepository.Recover(); if (result > 0) { XtraMessageBox.Show("记录清除成功", "重要", MessageBoxButtons.OK, MessageBoxIcon.Information); } } var name = text_username.Text; var pwd = SHAHelper.SHAmd5Encrypt(text_password.Text); var user = await operatorRepository.Get(name, pwd); if (user == null) { XtraMessageBox.Show(L.GetString("userNameOrPasswordError"), L.GetString("error"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } user.Language = Thread.CurrentThread.CurrentUICulture.Name; await actionsRepository.Insert(new Model.ActionsModel { Info = L.GetString("loginSystem"), Operator = user.Name, Time = DateTime.Now, RoleName = user.RoleName }); using (MainForm form = new MainForm()) { Hide(); form.Operator = user; if (form.ShowDialog() == DialogResult.Retry) { Show(); } Close(); } } private void ValidServer() { string connString = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)?.ConnectionStrings?.ConnectionStrings["myconn"]?.ToString(); if (string.IsNullOrEmpty(connString)) { XtraMessageBox.Show(L.GetString("serverError"), L.GetString("exclamation"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Hide(); using (ServerSet form = new ServerSet()) { if (form.ShowDialog() == DialogResult.OK) { Show(); } else { Environment.Exit(0); } } } else { IDbConnection conn = new MySqlConnection(connString); try { conn.Open(); } catch { XtraMessageBox.Show(L.GetString("serverError"), L.GetString("exclamation"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Hide(); using (ServerSet form = new ServerSet()) { if (form.ShowDialog() == DialogResult.OK) { Show(); } else { Environment.Exit(0); } } } finally { conn?.Close(); conn.Dispose(); } } } private void text_username_Click(object sender, EventArgs e) { SoftKeyboard.ActiveSoftKeyboard(sender); } private void text_password_Click(object sender, EventArgs e) { SoftKeyboard.ActiveSoftKeyboard(sender); } } }