LoginWindow.xaml.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Shapes;
  14. using System.Data.SQLite;
  15. using System.IO;
  16. using System.Data;
  17. using System.Security;
  18. using System.Security.Cryptography;
  19. namespace AIRS
  20. {
  21. /// <summary>
  22. /// LoginWindow.xaml 的交互逻辑
  23. /// </summary>
  24. public partial class LoginWindow : Window
  25. {
  26. private string path = Directory.GetCurrentDirectory(); //程序工作目录
  27. System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection();
  28. System.Data.SQLite.SQLiteConnectionStringBuilder connstr = new System.Data.SQLite.SQLiteConnectionStringBuilder();
  29. public string loginname = "";//登录名
  30. public string password = "";//密码
  31. public string entryclerk = "";//录入员
  32. public LoginWindow()
  33. {
  34. InitializeComponent();
  35. }
  36. public delegate void DeleTest();
  37. public static event DeleTest TestEvent;
  38. private void BtnExit_Click(object sender, RoutedEventArgs e)
  39. {
  40. this.DialogResult = false;
  41. }
  42. private void Window_Loaded(object sender, RoutedEventArgs e)
  43. {
  44. connstr.DataSource = path + "\\datas.db";
  45. conn.ConnectionString = connstr.ToString();
  46. conn.Open();
  47. cbbLoginname.Focus();
  48. }
  49. /// <summary>
  50. /// 根据账号查询用户信息
  51. /// </summary>
  52. /// <param name="loginname"></param>
  53. private void GetUserByloginname(string strloginname)
  54. {
  55. System.Data.SQLite.SQLiteDataAdapter da = new SQLiteDataAdapter("select * from t_username where username='"+ strloginname + "'", conn);
  56. DataTable ds = new DataTable();
  57. da.Fill(ds);
  58. if (ds.Rows.Count>0)
  59. {
  60. loginname = ds.Rows[0][0].ToString();
  61. password = ds.Rows[0][1].ToString();
  62. }
  63. }
  64. private void BtnLogin_Click(object sender, RoutedEventArgs e)
  65. {
  66. //this.DialogResult = true;
  67. //LoginWindow.TestEvent();
  68. //return;
  69. //if (cbbLoginname.Text.Trim().Length == 0)
  70. //{
  71. // MessageBox.Show("请填写账号!");
  72. // cbbLoginname.Focus();
  73. // return;
  74. //}
  75. //if (cbbpassword.Password.Trim().Length == 0)
  76. //{
  77. // MessageBox.Show("请填写密码!");
  78. // cbbpassword.Focus();
  79. // return;
  80. //}
  81. //if (cbbcompound.Text.Trim().Length == 0)
  82. //{
  83. // MessageBox.Show("请填写录入员!");
  84. // cbbcompound.Focus();
  85. // return;
  86. //}
  87. GetUserByloginname(cbbLoginname.Text.Trim());
  88. //if (!loginname.Equals(cbbLoginname.Text.Trim()))
  89. //{
  90. // MessageBox.Show("账号不存在!");
  91. // cbbLoginname.Focus();
  92. // return;
  93. //}
  94. ////if (!password.Equals(cbbpassword.Password.Trim()))
  95. //{
  96. // MessageBox.Show("密码错误!");
  97. // cbbpassword.Focus();
  98. // return;
  99. //}
  100. entryclerk = cbbcompound.Text.Trim();
  101. this.DialogResult = true;
  102. LoginWindow.TestEvent();
  103. }
  104. }
  105. }