-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.cs
152 lines (115 loc) · 4.73 KB
/
User.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
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 Oracle.ManagedDataAccess.Client;
namespace Db_project
{
public partial class User : Form
{
OracleConnection con;
// Replace this connection string with your actual Oracle database connection string
private string connectionString = "User Id=TEST;Password=TEST123;Data Source=localhost:1521/xe;";
public User()
{
InitializeComponent();
con = new OracleConnection(connectionString);
}
private void button1_Click(object sender, EventArgs e) // user signup
{
//Create an instance of the homematerial form
usersignup us = new usersignup();
// Set the size and location of homematerial to cover Form1
us.Size = this.ClientSize;
us.Location = new Point(0, 0);
// Set homematerial as a child form of Form1
us.FormBorderStyle = FormBorderStyle.None;
// Show the homematerial form
us.Show();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void User_Load(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)//sign in
{
// Get input values from the form
string username = textBox1.Text;
string password = textBox2.Text;
// Check if the username and password are not empty
if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
{
MessageBox.Show("Please enter both userID and password.");
return;
}
// Construct the SQL query to check user credentials
string query = "SELECT COUNT(*) FROM User_Table WHERE USER_ID = :USER_ID AND Password = :Password";
using (OracleCommand command = new OracleCommand(query, con))
{
// Add parameters to the query to prevent SQL injection
command.Parameters.Add(":UserName", OracleDbType.Varchar2).Value = username;
command.Parameters.Add(":Password", OracleDbType.Varchar2).Value = password;
try
{
// Open the connection
con.Open();
// Execute the query
int userCount = Convert.ToInt32(command.ExecuteScalar());
if (userCount > 0)
{
// Authentication successful
MessageBox.Show("Login successful!");
// Create an instance of the AdminSignup form
Usermanagement umanage = new Usermanagement();
// Set the size and location of AdminSignup to cover Form1
umanage.Size = this.ClientSize;
umanage.Location = new Point(0, 0);
// Set AdminSignup as a child form of Form1
umanage.TopLevel = false;
umanage.FormBorderStyle = FormBorderStyle.None;
this.Controls.Add(umanage);
// Hide the panel on the admin login page
panel1.Visible = false; // Replace "panel1" with the actual name of your panel
// Show the AdminSignup form
umanage.Show();
// Bring the AdminSignup form to the front
umanage.BringToFront();
}
else
{
MessageBox.Show("Invalid userID or password. Please try again.");
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
finally
{
// Close the connection
con.Close();
}
}
}
private void label2_Click(object sender, EventArgs e)
{
}
private void menuButton_Click_1(object sender, EventArgs e)
{
this.Close();
}
}
}