forked from allanakshay12/UniversityTranscriptCreator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm7.cs
More file actions
183 lines (158 loc) · 7.28 KB
/
Copy pathForm7.cs
File metadata and controls
183 lines (158 loc) · 7.28 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace UniversityTranscriptCreator
{
public partial class UserForm : Form
{
private string connectionString;
public UserForm()
{
InitializeComponent();
connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Jerry Allan Akshay\Documents\GitHub\University Transcript Creator\UniversityTranscriptCreator\Database2.mdf;Integrated Security=True";
/*FormCollection fc = Application.OpenForms;
foreach (Form frm in fc)
{
//iterate through
if (frm.Name == "UserForm")
{
YourProfileUsername.Text = ((LoginForm)frm).getUsername();
YourProfilePassword.Text = ((LoginForm)frm).getPassword();
YourProfileName.Text = ((LoginForm)frm).getName();
}
}*/
YourProfileUsername.Text = LoginForm.username_data;
YourProfilePassword.Text = LoginForm.password_data;
YourProfileName.Text = LoginForm.name_data;
YourProfileUsername.Enabled = false;
}
private void label1_Click(object sender, EventArgs e)
{
}
private void UpdateProfileButton_Click(object sender, EventArgs e)
{
if (!YourProfileUsername.Text.Equals("") && !YourProfilePassword.Text.Equals("") && !YourProfileName.Text.Trim().Equals(""))
{
SqlConnection sqlConnection1 = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
//cmd.CommandText = "delete from dbo.BranchSubject where Branch=\'" + BranchModify.Text.Trim() + "\' and Code=\'" + SubjectModify.SelectedItem.ToString() + "\';";
cmd.CommandText = "Update dbo.Users set Name=\'" + YourProfileName.Text.Trim() + "\', Password=\'" + YourProfilePassword.Text + "\' where UserName=\'" + YourProfileUsername.Text + "\';";
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("Profile Successfully Updated.");
LoginForm.username_data = YourProfileUsername.Text;
LoginForm.password_data = YourProfilePassword.Text;
LoginForm.name_data = YourProfileName.Text.Trim();
}
catch (Exception ex)
{
MessageBox.Show("Unable to update your profile.");
}
sqlConnection1.Close();
}
else
{
MessageBox.Show("Please fill in all the fields.");
}
}
private void CreateUserButton_Click(object sender, EventArgs e)
{
string digsign = Guid.NewGuid().ToString();
if (!NewName.Text.Trim().Equals("") && !NewPassword.Equals("") && !NewUsername.Text.Trim().Equals(""))
{
SqlConnection sqlConnection1 = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
//cmd.CommandText = "delete from dbo.BranchSubject where Branch=\'" + BranchModify.Text.Trim() + "\' and Code=\'" + SubjectModify.SelectedItem.ToString() + "\';";
cmd.CommandText = "insert dbo.Users (Name, UserName, Password, DigitalSignature) values (\'" + NewName.Text.Trim() + "\', \'" + NewUsername.Text.Trim() + "\', \'" + NewPassword.Text + "\', \'" + digsign + "\');";
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("User Successfully Created.");
NewName.Text = "";
NewPassword.Text = "";
NewUsername.Text = "";
}
catch (Exception ex)
{
MessageBox.Show("Unable to create user.");
}
sqlConnection1.Close();
} else
{
MessageBox.Show("Please fill in all the fields.");
}
}
private void DeleteUserButton_Click(object sender, EventArgs e)
{
SqlDataReader dataReaderbr;
SqlConnection sqlConnection1 = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from Users where UserName = \'" + DeleteUsername.Text.Trim() + "\' and Name = \'" + DeleteName.Text.Trim() + "\' and Password = \'" + DeletePassword.Text + "\';";
cmd.Connection = sqlConnection1;
if (!DeleteName.Text.Trim().Equals("") && !DeletePassword.Equals("") && !DeleteUsername.Text.Trim().Equals(""))
{
sqlConnection1.Open();
try
{
dataReaderbr = cmd.ExecuteReader();
if(dataReaderbr.HasRows)
{
if (!DeleteUsername.Text.Trim().Equals(LoginForm.username_data))
{
SqlConnection sqlConnection2 = new SqlConnection(connectionString);
SqlCommand cmd1 = new SqlCommand();
cmd1.CommandType = CommandType.Text;
cmd1.CommandText = "delete from dbo.Users where UserName=\'" + DeleteUsername.Text.Trim() + "\';";
cmd1.Connection = sqlConnection2;
try
{
sqlConnection2.Open();
cmd1.ExecuteNonQuery();
DeleteUsername.Text = "";
DeletePassword.Text = "";
DeleteName.Text = "";
MessageBox.Show("User Successfully Deleted.");
sqlConnection2.Close();
}
catch (Exception ex)
{
sqlConnection2.Close();
MessageBox.Show("Unable to delete user.");
}
} else
{
MessageBox.Show("You cannot delete your own account.");
}
}
else
{
MessageBox.Show("The Credentials don't match any user\'s credentials.");
}
}
catch (Exception ex)
{
MessageBox.Show("The Credentials don't match any user\'s credentials.");
}
sqlConnection1.Close();
} else
{
MessageBox.Show("Please fill in all the fields.");
}
}
}
}