添加登录页面
This commit is contained in:
commit
65fc78f092
14 files changed
+179
-13
No files matched your search
+108
@@ -0,0 +1,108 @@
|
||||
using SunlightCentralizedControlManagement_SCCM_.ViewModel;
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper;
|
||||
|
||||
namespace SunlightCentralizedControlManagement_SCCM_
|
||||
{
|
||||
/// <summary>
|
||||
/// Login.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class Login : Window
|
||||
{
|
||||
public string INIPath = Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "SCCM.ini"; //配置文件路径
|
||||
|
||||
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\SCCM.db"; //数据库路径
|
||||
DataTable logindataTable = new DataTable(); //建立login缓存
|
||||
|
||||
public Login()
|
||||
{
|
||||
WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||
InitializeComponent();
|
||||
|
||||
UserClass.LogGing.LogGingDATA("SCCM_start");
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e) //退出按钮事件
|
||||
{
|
||||
UserClass.LogGing.LogGingDATA("SCCM_LogStop");
|
||||
Window window = Window.GetWindow(this);
|
||||
window.Close();
|
||||
}
|
||||
|
||||
private void Button_Click_1(object sender, RoutedEventArgs e) //登录按钮事件
|
||||
{
|
||||
string user = User.Text;
|
||||
string pasword = Pasword.Password; ;
|
||||
|
||||
if (User.Text == "") //检查用户名输入
|
||||
{
|
||||
System.Windows.MessageBox.Show(Properties.Resources.NPERR, "SCCM", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((user == "engineer" || user == "ENGINEER") && (pasword == "engineer" || pasword == "ENGINEER")) //确认账号是否是工程师
|
||||
{
|
||||
App.USER_Purview = "ENGINEER";//传入用户名
|
||||
|
||||
Window window = Window.GetWindow(this);
|
||||
MainWindow Main = new MainWindow();
|
||||
window.Close();
|
||||
UserClass.LogGing.LogGingDATA("LOGon = ENGINEER");
|
||||
|
||||
Main.ShowDialog();//实例化并置顶打开窗口
|
||||
}
|
||||
else
|
||||
{
|
||||
var paw = logindataTable.Select("Name='" + user + "'").First().Field<string>("Password");
|
||||
if (paw == null) paw = "";
|
||||
|
||||
if (paw == pasword)
|
||||
{
|
||||
App.USER_Purview = User.Text;//传入用户名
|
||||
|
||||
Window window = Window.GetWindow(this);
|
||||
MainWindow Main = new MainWindow();
|
||||
window.Close();
|
||||
|
||||
UserClass.LogGing.LogGingDATA("LOGon = " + user);
|
||||
Main.ShowDialog();//实例化并置顶打开窗口
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Windows.MessageBox.Show(Properties.Resources.NPERR, "SCCM", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SearchBox_OnKeyDownd(object sender, System.Windows.Input.KeyEventArgs e) //回车跳转功能
|
||||
{
|
||||
if (e.Key == Key.Enter)
|
||||
{
|
||||
//SendKeys.SendWait("{Tab}");
|
||||
UserClass.PressKey.PressKeys(Keys.Tab, false);
|
||||
UserClass.PressKey.PressKeys(Keys.Tab, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
logon.IsEnabled = false;
|
||||
SQLiteHelper db = new SQLiteHelper(DBAddress); //数据库连接路径
|
||||
db.Open(); //打开数据库
|
||||
logindataTable = db.ExecuteDataSet("select * from USER", null).Tables[0]; //读取表写入缓存
|
||||
db.Close();
|
||||
User.ItemsSource = logindataTable.AsEnumerable().Select(rowdata => rowdata.Field<string>("Name"));//转换
|
||||
logon.IsEnabled = true; //允许登录按钮
|
||||
UserClass.PressKey.PressKeys(Keys.Tab, false);
|
||||
UserClass.PressKey.PressKeys(Keys.Tab, true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user