SetPwdWindow.xaml.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SQLite;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Shapes;
  16. namespace AIRS
  17. {
  18. /// <summary>
  19. /// SetPwdWindow.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class SetPwdWindow : Window
  22. {
  23. private string path = Directory.GetCurrentDirectory(); //程序工作目录
  24. System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection();
  25. System.Data.SQLite.SQLiteConnectionStringBuilder connstr = new System.Data.SQLite.SQLiteConnectionStringBuilder();
  26. public SetPwdWindow()
  27. {
  28. InitializeComponent();
  29. }
  30. public string username = "";//账号
  31. public string password = "";//密码
  32. /// <summary>
  33. /// 确认按钮
  34. /// </summary>
  35. /// <param name="sender"></param>
  36. /// <param name="e"></param>
  37. private void BtnOK_Click(object sender, RoutedEventArgs e)
  38. {
  39. try
  40. {
  41. if (lodpassword.Password.Trim().Length==0)
  42. {
  43. MessageBox.Show("请填写原密码");
  44. lodpassword.Focus();
  45. return;
  46. }
  47. if (newpassword.Password.Trim().Length == 0)
  48. {
  49. MessageBox.Show("请填写新密码");
  50. newpassword.Focus();
  51. return;
  52. }
  53. if (confirmpassword.Password.Trim().Length == 0)
  54. {
  55. MessageBox.Show("请填写确认密码");
  56. confirmpassword.Focus();
  57. return;
  58. }
  59. if (!lodpassword.Password.Trim().Equals(password))
  60. {
  61. MessageBox.Show("密码错误!");
  62. lodpassword.Focus();
  63. return;
  64. }
  65. if (!newpassword.Password.Trim().Equals(confirmpassword.Password.Trim()))
  66. {
  67. MessageBox.Show("新密码与确认密码不一致!");
  68. //lodpassword.Focus();
  69. return;
  70. }
  71. connstr.DataSource = path + "\\datas.db";
  72. conn.ConnectionString = connstr.ToString();
  73. conn.Open();
  74. SQLiteCommand cmd = conn.CreateCommand();
  75. cmd.CommandText = "update t_username set password=@password where username=@username";
  76. cmd.Parameters.Add(new SQLiteParameter("@password"));
  77. cmd.Parameters.Add(new SQLiteParameter("@username"));
  78. cmd.Parameters["@password"].Value = newpassword.Password.Trim();
  79. cmd.Parameters["@username"].Value = username;
  80. if (cmd.ExecuteNonQuery() > 0)
  81. {
  82. this.DialogResult = true;
  83. }
  84. else
  85. {
  86. MessageBox.Show("修改密码失败!");
  87. }
  88. }
  89. catch (Exception ex)
  90. {
  91. }
  92. }
  93. private void BtnCancle_Click(object sender, RoutedEventArgs e)
  94. {
  95. this.DialogResult = false;
  96. }
  97. }
  98. }