-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdmin_RemoveUsers.cs
More file actions
112 lines (99 loc) · 3.46 KB
/
Copy pathAdmin_RemoveUsers.cs
File metadata and controls
112 lines (99 loc) · 3.46 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
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DormitoryManagment
{
public partial class RemoveUsers : DMForm
{
DataView dataView;
string filterName;
public RemoveUsers()
{
InitializeComponent();
filterName = "Name LIKE '*'";
UpdateTable();
}
private void UpdateTable()
{
dataView = new DataView(DataBase.GetDataSource("SELECT `Username`, `Name`, `Role` FROM Users WHERE NOT Role = 'admin'"));
dataView.RowFilter = filterName;
Table.DataSource = dataView;
}
private void filepath_Leave(object sender, EventArgs e)
{
if (filepath.Text == "")
{
filepath.Text = "Path/to/file.csv";
filepath.ForeColor = SystemColors.GrayText;
}
}
private void filepath_Enter(object sender, EventArgs e)
{
filepath.Text = string.Empty;
filepath.ForeColor = SystemColors.ControlText;
}
private void RemoveUsersButton_Click(object sender, EventArgs e)
{
Program.admin.RemoveUsers(filepath.Text);
this.filepath.Text = string.Empty;
this.filepath_Leave(null, null);
UpdateTable();
}
private void HomePic_Click(object sender, EventArgs e)
{
DMForm nextForm = new ChangePass(Program.admin, "Admin");
Navigate(ref nextForm);
}
private void LogOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
DMForm startScreen = new StartScreen();
Navigate(ref startScreen);
}
private void AddBuilding_Click(object sender, EventArgs e)
{
DMForm nextForm = new AddBuilding();
Navigate(ref nextForm);
}
private void ModifyBuilding_Click(object sender, EventArgs e)
{
DMForm nextForm = new ModifyBuilding();
Navigate(ref nextForm);
}
private void button1_Click(object sender, EventArgs e)
{
DMForm nextForm = new AddUsers();
Navigate(ref nextForm);
}
private void RemoveUserButton_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in Table.SelectedRows)
{
Program.conn.Open();
string sql = "DELETE FROM Users WHERE Username = '" + row.Cells[0].Value + "'";
MySqlCommand cmd = new MySqlCommand(sql, Program.conn);
cmd.ExecuteNonQuery();
Program.conn.Close();
MessageBox.Show("Successfully delete the chosen user!", "Delete successfully", MessageBoxButtons.OK, MessageBoxIcon.Information);
Table.Rows.Remove(row);
}
}
private void applyButton_Click(object sender, EventArgs e)
{
if (NameInput.Text == "") { filterName = "Name LIKE '*'"; }
else { filterName = "Name LIKE '*" + NameInput.Text + "*'"; }
UpdateTable();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
DMForm mainScreen = new AdminMainScreen();
Navigate(ref mainScreen);
}
}
}