/
paroles_maina.cs
117 lines (99 loc) · 4.29 KB
/
paroles_maina.cs
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System;
using System.Drawing;
using System.Windows.Forms;
using Npgsql;
namespace naus
{
public partial class paroles_maina : Form
{
NpgsqlCommand mainas_kom;
public paroles_maina()
{
InitializeComponent();
this.ActiveControl = tb_pasreizeja;
}
void mainit_paroli()
{
switch (db.liet_grupa) {
case "Mācībspēks":
mainas_kom = new NpgsqlCommand("UPDATE macibspeki SET parole = @parole WHERE id_macsp = @lietotajs;", db.sav);
break;
case "Vadība":
mainas_kom = new NpgsqlCommand("UPDATE vadiba SET parole = @parole WHERE id_vadiba = @lietotajs;", db.sav);
break;
case "Students":
mainas_kom = new NpgsqlCommand("UPDATE studenti SET parole = @parole WHERE id_matr = @lietotajs;", db.sav);
break;
}
mainas_kom.Parameters.AddWithValue("@lietotajs", db.lietotajs);
mainas_kom.Parameters.AddWithValue("@parole", db.SHA1Parole(db.lietotajs, tb_jauna.Text));
db.sav.Open();
int ieraksti = mainas_kom.ExecuteNonQuery();
db.sav.Close();
if (ieraksti != -1) {
MessageBox.Show("Lietotāja parole veiksmīgi nomainīta!", "Parole nomainīta", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
} else {
MessageBox.Show("Paroles maiņas procesā radās neparedzēta kļūda!\nMēģiniet atkārtot paroles maiņu vēlāk.", "Kļūda paroles maiņas procesā", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
bool parbaudit_ievadlaukus()
{
bool nav_kludu = true;
if (tb_pasreizeja.Text == "") {
ep_kluda.SetError(tb_pasreizeja, db.obligats);
} else if (db.SHA1Parole(db.lietotajs, tb_pasreizeja.Text) != db.parole) {
ep_kluda.SetError(tb_pasreizeja, "Ievadītā parole nesakrīt ar pašreizējo paroli");
} else {
ep_kluda.SetError(tb_pasreizeja, "");
}
if (tb_jauna.Text == "") {
ep_kluda.SetError(tb_jauna, db.obligats);
} else if (tb_jauna.Text == tb_pasreizeja.Text) {
ep_kluda.SetError(tb_jauna, "Jaunā parole sakrīt ar pašreizējo paroli");
} else if (tb_jauna.Text != tb_atkartoti.Text) {
ep_kluda.SetError(tb_jauna, "Jaunā un atkārtoti ievadītā parole nesakrīt");
} else if (tb_jauna.Text.Length < 5) {
ep_kluda.SetError(tb_jauna, "Parolei jābūt vismaz 5 simbolus garai");
} else {
ep_kluda.SetError(tb_jauna, "");
}
if (tb_atkartoti.Text == "") {
ep_kluda.SetError(tb_atkartoti, db.obligats);
} else if (tb_jauna.Text != tb_atkartoti.Text) {
ep_kluda.SetError(tb_atkartoti, "Jaunā un atkārtoti ievadītā parole nesakrīt");
} else if (tb_atkartoti.Text.Length < 5) {
ep_kluda.SetError(tb_atkartoti, "Parolei jābūt vismaz 5 simbolus garai");
} else {
ep_kluda.SetError(tb_atkartoti, "");
}
foreach (Control el in Controls) {
if (ep_kluda.GetError(el) != "") {
nav_kludu = false;
break;
}
}
return nav_kludu;
}
void Tb_atkartotiKeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter) {
if (parbaudit_ievadlaukus()) {
mainit_paroli();
}
}
}
void B_atceltClick(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
void B_mainitClick(object sender, EventArgs e)
{
if (parbaudit_ievadlaukus()) {
mainit_paroli();
}
}
}
}