yangle
2023-03-03 c2a9a460e38c7c196fe98a94e29e6330eac3626f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
 
namespace OAM
{
    public partial class frmChangePWD : Form
    {
        public frmChangePWD()
        {
            InitializeComponent();
        }
 
        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (txtOldPwd.Text.Length > 20 || txtNewPwd.Text.Length > 20 || txtCheckPwd.Text.Length > 20)
            {
                MessageBox.Show("密码长度太长,不能多于20位");
                return;
            }
            if(txtNewPwd.Text!=txtCheckPwd.Text)
            {
                MessageBox.Show("验证码和新密码不匹配");
                return;
            }
            if (CheckPassword(txtOldPwd.Text) == false)
            {
                MessageBox.Show("你的老密码不正确,请重新输入");
                return;
            }
            //if (UpdatePassword(txtOldPwd.Text, txtNewPwd.Text) == true)
            //{
            //    MessageBox.Show("密码已修改");
            //}
            DAL.ClsUser oUser = new DAL.ClsUser();
            oUser.UserCode = DBUtility.ClsPub.CurUserName;
            oUser.Psd = DBUtility.ClsPub.StrToPsd(txtNewPwd.Text.Trim());
            if (oUser.ChangePsd())
            {
                MessageBox.Show("修改完毕!", "提示");
                this.Close();
            }
            else
            {
                MessageBox.Show("修改失败!", "提示");
            }
        }
        public bool UpdatePassword(string OldPwd, string NewPwd)
        {
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); 
            oCn.RunProc("Update Gy_Czygl Set czmm='" + NewPwd + "' where czymc='" + DBUtility.ClsPub.CurUserName + "'");
            return true;
        }
        public bool CheckPassword(string OldPwd)
        {
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            DataSet Ds;
            Ds = oCn.RunProcReturn("Select * from Gy_Czygl where czmm='" +DBUtility.ClsPub.StrToPsd(OldPwd) + "' and czymc='" + DBUtility.ClsPub.CurUserName + "'", "Gy_Czygl");
            if (Ds == null || Ds.Tables[0].Rows.Count == 0)
            {
                return false;
            }
            
            return true;
        }
        private void frmChangePWD_Load(object sender, EventArgs e)
        {
            txtCheckPwd.Text = "";
            txtNewPwd.Text = "";
            txtOldPwd.Text = "";
        }
 
        private void cmdCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}