| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- 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<NameValue> 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);
-
- }
- }
- }
|