170 lines
5.7 KiB
C#
170 lines
5.7 KiB
C#
using Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Security.Principal;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
using Tool;
|
|
|
|
namespace View
|
|
{
|
|
/// <summary>
|
|
/// MainWindow.xaml 的交互逻辑
|
|
/// </summary>
|
|
///
|
|
public class LoginModel
|
|
{
|
|
public string name { get; set; }
|
|
public string pro { get; set; }
|
|
/// <summary>
|
|
/// 部门
|
|
/// </summary>
|
|
public string bumen { get; set; }
|
|
}
|
|
public partial class MesLoginView : Window
|
|
{
|
|
private List<string> Users = new List<string>();
|
|
private Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
private LoginModel _model;
|
|
public MesLoginView()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
public MesLoginView(string title, Dictionary<string, string> dic1, List<string> Item, LoginModel model)
|
|
{
|
|
InitializeComponent();
|
|
try
|
|
{
|
|
Users = new List<string>();
|
|
int num = int.Parse(dic1["账号数量"]);
|
|
for (int i = 0; i < num; i++)
|
|
{
|
|
string nam = "账号" + (i + 1).ToString();
|
|
Users.Add(dic1[nam]);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
new MessageBoxView("提示!", ex.ToString() + "账号数量可能不是数值").ShowDialog();
|
|
return;
|
|
}
|
|
dic = dic1;
|
|
lblTitle.Text = title;
|
|
ComboBoxProd.ItemsSource = Item;
|
|
ComboBoxProd.SelectedIndex = 0;
|
|
_model = model;
|
|
}
|
|
public string userName = "";
|
|
private UserModel UserModel = new UserModel();
|
|
private SqlHelper mesHelper = new SqlHelper();
|
|
private SqlHelper sqlHelper = new SqlHelper();
|
|
private void btnCancel_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void btnLogin_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (Account.Text == "")
|
|
{
|
|
new MessageBoxView("提示!", "请输入账号!").ShowDialog();
|
|
return;
|
|
}
|
|
IntPtr p = Marshal.SecureStringToBSTR(this.Password.SecurePassword); // 使用.NET内部算法把IntPtr指向处的字符集合转换成字符串
|
|
string password = Marshal.PtrToStringBSTR(p); // 顺便校验一下
|
|
if (password == "")
|
|
{
|
|
new MessageBoxView("提示!", "请输入密码!").ShowDialog();
|
|
return;
|
|
}
|
|
//try
|
|
//{
|
|
// if (mesHelper.Login(Account.Text.ToLower(), password))
|
|
// {
|
|
// string user = mesHelper.GetName(Account.Text.ToLower());
|
|
// if (user == "")
|
|
// {
|
|
// new MessageBoxView("提示!", "获取姓名失败!").ShowDialog();
|
|
// return;
|
|
// }
|
|
// _model.name = user;
|
|
// _model.pro = ComboBoxProd.Text;
|
|
// this.DialogResult = true;
|
|
// this.Close();
|
|
// }
|
|
// else
|
|
// {
|
|
// new MessageBoxView("提示!", "账号或密码错误!").ShowDialog();
|
|
// }
|
|
//}
|
|
//catch (Exception)
|
|
//{
|
|
//}
|
|
try
|
|
{
|
|
UserModel user = sqlHelper.GetUser(Account.Text.ToLower());
|
|
if (user.nickName == "")
|
|
{
|
|
new MessageBoxView("提示!", "获取姓名失败!").ShowDialog();
|
|
return;
|
|
}
|
|
string nume = user.nickName + ";" + password;
|
|
if (!Users.Contains(nume))
|
|
{
|
|
new MessageBoxView("提示!", "密码错误").ShowDialog();
|
|
return;
|
|
}
|
|
_model.name = user.nickName;
|
|
_model.pro = ComboBoxProd.Text;
|
|
_model.bumen = user.bumen;
|
|
this.DialogResult = true;
|
|
this.Close();
|
|
}
|
|
catch (Exception ee)
|
|
{
|
|
new MessageBoxView("错误!", ee.Message.ToString()).ShowDialog();
|
|
LogHelper.WriteLog(ee.ToString());
|
|
}
|
|
//}
|
|
}
|
|
catch (Exception ee)
|
|
{
|
|
new MessageBoxView("错误!", ee.Message.ToString()).ShowDialog();
|
|
LogHelper.WriteLog(ee.ToString());
|
|
}
|
|
}
|
|
|
|
//private void main_PreviewKeyDown(object sender, KeyEventArgs e)
|
|
//{
|
|
// //if (e.Key == Key.Enter)
|
|
// //{
|
|
// // btnLogin_Click(null, null);
|
|
// //}
|
|
// //else if (e.Key == Key.Escape)
|
|
// //{
|
|
// // this.Close();
|
|
|
|
// //}
|
|
//}
|
|
|
|
private void main_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
Account.Focus();
|
|
Account.SelectAll();
|
|
}
|
|
}
|
|
}
|