This repository has been archived by the owner on Jul 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
118 lines (107 loc) · 4.15 KB
/
Form1.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
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;
using System.Data.OleDb;
namespace ict_sba_1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public class user
{
public string username;
}
private void title_Click(object sender, EventArgs e)
{
}
private void login_Click(object sender, EventArgs e)
{
if (!teacher1.Checked && !student1.Checked)
{
MessageBox.Show("Please tick the column", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (student1.Checked)
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\sba_account1.mdb;User Id=admin;Password=";
string find = "select count(*) from Table1 where username =" + "? and [password]=?";
OleDbCommand oleDbCommand = new OleDbCommand(find, con);
{
con.Open();
oleDbCommand.Parameters.AddWithValue("@p1", username1.Text);
oleDbCommand.Parameters.AddWithValue("@p2", password1.Text);
int result = (int)oleDbCommand.ExecuteScalar();
if (result > 0)
{
this.Hide();
user u = new user();
u.username = username1.Text;
Form2 f2 = new Form2(u);
f2.ShowDialog();
}
else
MessageBox.Show("Username or password are wrong", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
con.Close();
}
}
else if (teacher1.Checked)
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|account2.mdb;Persist Security Info=False;";
string find = "select count(*) from Table1 where username =" + "? and [password]=?";
OleDbCommand oleDbCommand = new OleDbCommand(find, con);
{
con.Open();
oleDbCommand.Parameters.AddWithValue("@p1", username1.Text);
oleDbCommand.Parameters.AddWithValue("@p2", password1.Text);
int result = (int)oleDbCommand.ExecuteScalar();
if (result > 0)
{
this.Hide();
user u = new user();
u.username = username1.Text;
Form2 f0 = new Form2(u);
f0.ShowDialog();
}
else
MessageBox.Show("Username or password are wrong", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
con.Close();
}
}
}
private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
Application.Exit();
}
private void Form1_Load(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
tableLayoutPanel1.Location = new Point(ClientSize.Width / 2 - tableLayoutPanel1.Size.Width / 2, ClientSize.Height / 2 - tableLayoutPanel1.Size.Height / 2);
}
private void student1_CheckedChanged(object sender, EventArgs e)
{
teacher1.Checked = false;
}
private void teacher1_CheckedChanged(object sender, EventArgs e)
{
student1.Checked = false;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
}
}
}