|
- using CnasSynchronousCommon;
- using CnasSynchronusClient;
- using CnasSynchrousModel;
- using log4net;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Text;
- using System.Windows.Forms;
- using System.Xml.Serialization;
-
- namespace CNAS_BalanceClient
- {
-
- public partial class frmLoginServer : Form
- {
- public static string strLoginName = "";
- public static string strLoginPwd = "";
- public static string strServerIP = "";
- public static string strServerPort = "";
- //Point mouseOff; //鼠标移动位置
- //bool leftFlag; //标签是否为左键
- public frmLoginServer()
- {
- InitializeComponent();
-
- lblTitle.BackColor = Color.Transparent;
- lblUser.BackColor = Color.Transparent;
- lblPwd.BackColor = Color.Transparent;
- }
-
- private void Btn_Login_Click(object sender, EventArgs e)
- {
- Config();
- }
- private void Config()
- {
- //合法行判断
- if (this.txtUserName.Text.Trim() == "" || this.txtPwd.Text.Trim() == "")
- {
- MessageBox.Show("用户名,密码不能为空。", "提示");
- return;
- }
-
- //1.读取本地数据库配置信息
- DataBaseInfo targetdataBase = new DataBaseInfo(); //cnas目标数据库
- try
- {
- //加载CNAS数据库信息
- targetdataBase = FileOperation.GetLocalPlatFormDB();
-
- if (!CnasDataOperationFact.CnasDataOperation().TestConnect(targetdataBase))
- {
- MessageBox.Show("无法连接数据,请联系管理员。", "提示");
- return;
- }
- }
- catch (Exception ex)
- {
- AppLog.Error(ex.Message.ToString());
- }
- //2.传输输入信息到数据库中,查阅,并返回所需信息
- DataTable dtLogin = CnasDataOperationFact.CnasDataOperation().GetLoginNameByPwd(targetdataBase, this.txtUserName.Text.Trim(), this.txtPwd.Text.Trim());
- if (dtLogin != null && dtLogin.Rows.Count == 1)
- {
- GlobalCommonOperation.strLoginName = dtLogin.Rows[0]["username"].ToString();
- GlobalCommonOperation.strUserName = this.txtUserName.Text.Trim();
- AppLog.Info($"{this.txtUserName.Text.Trim()}登录成功");
- this.DialogResult = DialogResult.OK;
- this.Close();
- }
- else
- {
- MessageBox.Show("用户名,密码登录失败,请重新输入。", "提示");
- AppLog.Error($"{this.txtUserName.Text.Trim()}尝试登录失败");
- return;
- }
- }
- private void Btn_Logout_Click(object sender, EventArgs e)
- {
- this.DialogResult = DialogResult.None;
- this.Close();
- }
-
- [System.Runtime.InteropServices.DllImport("user32.dll")]
- public static extern bool ReleaseCapture();
- [System.Runtime.InteropServices.DllImport("user32.dll")]
- public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
- public const int WM_SYSCOMMAND = 0x0112;
- public const int SC_MOVE = 0xF010;
- public const int HTCAPTION = 0x0002;
- private void frmLoginServer_MouseDown(object sender, MouseEventArgs e)
- {
- try
- {
- ReleaseCapture();
- SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
- }
- catch(Exception ex)
- {
- AppLog.Error(ex.Message.ToString());
- }
- }
-
- private void frmLoginServer_KeyDown(object sender, KeyEventArgs e)
- {
- try
- {
- if (!Btn_Login.Focused && !Btn_Logout.Focused)
- {
- FormKeyEventClass fke = new FormKeyEventClass();
- fke.FormKeyEvent += new FormKeyEventClass.FormKey(Config);
- fke.FormKeyEventRun(e);
- }
- }
- catch(Exception ex)
- {
- AppLog.Error(ex.Message.ToString());
- }
- }
-
- private void frmLoginServer_Shown(object sender, EventArgs e)
- {
- txtUserName.Select(txtUserName.Text.Length, 0);
- }
- }
- }
|