This repository has been archived by the owner on Jan 6, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cs
256 lines (207 loc) · 7.25 KB
/
Main.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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
using Bunifu.UI.WinForms;
using SPAAT.Pages;
using SPAAT.SubPages;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Navigation;
using MySql.Data.MySqlClient;
using static Guna.UI2.Native.WinApi;
using Guna.UI2.WinForms;
namespace SPAAT
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
appbar.MouseDown += new MouseEventHandler(label1_MouseDown);
Admin();
guna2HtmlToolTip1.SetToolTip(ZAPISAXIS, "© 2023 Copyright: Mhar Andrei Macapallag");
guna2HtmlToolTip1.SetToolTip(guna2Button1, "Log out and go to the login page.");
this.Resize += Form_Resize;
}
private const int MinFormWidth = 1000;
private const int MinFormHeight = 800;
private void Form_Resize(object sender, EventArgs e)
{
if (this.Width < MinFormWidth)
{
this.Width = MinFormWidth;
}
if (this.Height < MinFormHeight)
{
this.Height = MinFormHeight;
}
}
private bool IsSuperUser(string username)
{
string connet = "Server=localhost;Database=zapisaxisfms;Username=root;Password=;";
using (MySqlConnection connection = new MySqlConnection(connet))
{
connection.Open();
string getUserIdQuery = "SELECT user_id FROM users WHERE username = @username";
string checkSuperUserQuery = "SELECT COUNT(*) FROM su WHERE user_id = @userId";
using (MySqlCommand getUserIdCommand = new MySqlCommand(getUserIdQuery, connection))
{
getUserIdCommand.Parameters.AddWithValue("@username", username);
int userId = Convert.ToInt32(getUserIdCommand.ExecuteScalar());
using (MySqlCommand checkSuperUserCommand = new MySqlCommand(checkSuperUserQuery, connection))
{
checkSuperUserCommand.Parameters.AddWithValue("@userId", userId);
int count = Convert.ToInt32(checkSuperUserCommand.ExecuteScalar());
return count > 0;
}
}
}
}
public BunifuPages GetPagesControl()
{
return pages;
}
private void label1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
private const int WM_NCLBUTTONDOWN = 0xA1;
private const int HT_CAPTION = 0x2;
[DllImportAttribute("user32.dll")]
private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
private static extern bool ReleaseCapture();
private string loggedInUser;
public string LoggedInUser
{
get { return loggedInUser; }
set
{
loggedInUser = value;
appbar.Text = $"SOCCS Financial Management System | Logged in as: {loggedInUser}";
this.Text = $"ZAPISAXIS - {loggedInUser}";
Admin();
}
}
private void Admin()
{
bool isSuperUser = IsSuperUser(loggedInUser);
adminpage.Enabled = isSuperUser;
adminpage.Visible = isSuperUser;
}
private void Main_Load(object sender, EventArgs e)
{
LoggedInUser = "DefaultUser";
}
private void dashboardbutton_Click(object sender, EventArgs e)
{
pages.SelectTab(dashboardpage);
this.Text = $"ZAPISAXIS - Dashboard - {loggedInUser}";
}
private void budgetmanagement_Click(object sender, EventArgs e)
{
pages.SelectTab(budman);
this.Text = $"ZAPISAXIS - Budget Management - {loggedInUser}";
}
private void logs_Click(object sender, EventArgs e)
{
pages.SelectTab(log);
this.Text = $"ZAPISAXIS - Transaction Logs - {loggedInUser}";
}
private void Settings_Click(object sender, EventArgs e)
{
pages.SelectTab(setting);
this.Text = $"ZAPISAXIS - Settings - {loggedInUser}";
}
private void exportf_Click(object sender, EventArgs e)
{
pages.SelectTab(export);
this.Text = $"ZAPISAXIS - Export - {loggedInUser}";
}
private void adminpage_Click(object sender, EventArgs e)
{
pages.SelectTab(admins);
this.Text = $"ZAPISAXIS - Admin - {loggedInUser}";
}
private void studentfile_Click(object sender, EventArgs e)
{
pages.SelectTab(studfil);
this.Text = $"ZAPISAXIS - Student File - {loggedInUser}";
}
private void guna2CirclePictureBox1_Click(object sender, EventArgs e)
{
}
private void ClosingTimer_Tick(object sender, EventArgs e)
{
if (Opacity > 0)
{
Opacity -= 0.05;
}
else if (Opacity == 0)
{
this.Visible = false;
Environment.Exit(1);
}
}
private Timer closingTimer;
private void exit_Click(object sender, EventArgs e)
{
Main main = new Main();
closingTimer = new Timer();
closingTimer.Interval = 10;
closingTimer.Tick += (s, args) =>
{
ClosingTimer_Tick(s, e);
};
closingTimer.Start();
main.Visible = true;
}
private void appbar_Click(object sender, EventArgs e)
{
}
private void dashboard2_Load(object sender, EventArgs e)
{
}
private void budgetManagement1_Load(object sender, EventArgs e)
{
}
private void settings1_Load(object sender, EventArgs e)
{
}
private void dashboard1_Load(object sender, EventArgs e)
{
}
private void pages_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Left:
case Keys.Right:
e.Handled = true;
break;
}
}
private void guna2Button1_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("Are you sure you want to log out?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
System.Diagnostics.Process.Start(Application.ExecutablePath);
Application.Exit();
}
}
private void pages_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}