-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrary Management Source Code.txt
More file actions
211 lines (162 loc) · 5.91 KB
/
Library Management Source Code.txt
File metadata and controls
211 lines (162 loc) · 5.91 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
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
Create Database and Tables in Sql Server
CREATE DATABASE LibraryDB;
USE LibraryDB;
CREATE TABLE logintab(
Id INT PRIMARY KEY IDENTITY(1,1),
Username NVARCHAR(50),
Password NVARCHAR(50)
);
CREATE TABLE students (
StudentID INT IDENTITY(1,1) PRIMARY KEY,
Student_Name NVARCHAR(100) NOT NULL,
Gender NVARCHAR(20),
Email NVARCHAR(100) UNIQUE,
Phone_Number NVARCHAR(20),
Address NVARCHAR(50)
);
CREATE TABLE books (
BookID INT IDENTITY(1,1) PRIMARY KEY,
Book_Name NVARCHAR(100) NOT NULL,
Author NVARCHAR(100),
Publisher NVARCHAR(100)
);
CREATE TABLE issue (
IssueID INT IDENTITY(1,1) PRIMARY KEY,
StudentID INT,
BookID INT,
Issue_Date DATETIME,
Due_Date DATETIME,
Return_Date DATETIME,
CONSTRAINT FK_issue_students FOREIGN KEY (StudentID) REFERENCES students(StudentID),
CONSTRAINT FK_issue_books FOREIGN KEY (BookID) REFERENCES books(BookID)
);
CREATE TABLE librarians (
LibrarianID INT IDENTITY(1,1) PRIMARY KEY,
Name NVARCHAR(100) NOT NULL,
Email NVARCHAR(100) UNIQUE,
Phone_Number NVARCHAR(20)
);
CREATE TABLE fine (
FineID INT IDENTITY(1,1) PRIMARY KEY,
IssueID INT,
Amount DECIMAL(10,2),
CONSTRAINT FK_fine_issue FOREIGN KEY (IssueID) REFERENCES issue(IssueID)
);
INSERT INTO logintab VALUES('admin','12345');
INSERT INTO logintab VALUES('mycodingproject','5656');
Login Button Code
if (string.IsNullOrWhiteSpace(txtUsername.Text) || string.IsNullOrWhiteSpace(txtPassword.Text))
{
MessageBox.Show("Please enter username and password");
return;
}
SqlConnection con = new SqlConnection(@"Data Source=localhost;Initial Catalog=LibraryDB;Integrated Security=True;TrustServerCertificate=True");
con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM logintab WHERE Username=@username AND Password=@password", con);
cmd.Parameters.AddWithValue("@username", txtUsername.Text.Trim());
cmd.Parameters.AddWithValue("@password", txtPassword.Text.Trim());
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
Main mn = new Main();
mn.Show();
}
else
{
MessageBox.Show("Invalid Login");
}
con.Close();
Student.cs
Insert Button Code
SqlConnection con = new SqlConnection(@"Data Source=localhost;Initial Catalog=LibraryDB;Integrated Security=True;TrustServerCertificate=True");
con.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO students (Student_Name, Gender, Email, Phone_Number, Address) " +
"VALUES (@Student_Name, @Gender, @Email, @Phone_Number, @Address)", con);
cmd.Parameters.AddWithValue("@Student_Name", textBox2.Text);
cmd.Parameters.AddWithValue("@Gender", textBox3.Text);
cmd.Parameters.AddWithValue("@Email", textBox4.Text);
cmd.Parameters.AddWithValue("@Phone_Number", textBox5.Text);
cmd.Parameters.AddWithValue("@Address", textBox6.Text);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Record Inserted");
LoadStudents();
Update Button Code
SqlConnection con = new SqlConnection(@"Data Source=localhost;Initial Catalog=LibraryDB;Integrated Security=True;TrustServerCertificate=True");
con.Open();
SqlCommand cmd = new SqlCommand("UPDATE students SET Student_Name=@Student_Name, Gender=@Gender, Email=@Email, Phone_Number=@Phone_Number, Address=@Address " +
"WHERE studentid=@studentid", con);
cmd.Parameters.AddWithValue("@StudentID", int.Parse(textBox1.Text));
cmd.Parameters.AddWithValue("@Student_Name", textBox2.Text);
cmd.Parameters.AddWithValue("@Gender", textBox3.Text);
cmd.Parameters.AddWithValue("@Email", textBox4.Text);
cmd.Parameters.AddWithValue("@Phone_Number", textBox5.Text);
cmd.Parameters.AddWithValue("@Address", textBox6.Text);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Record Updated");
LoadStudents();
Delete Button Code
if (MessageBox.Show("Are you sure you want to delete?",
"Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
SqlConnection con = new SqlConnection(@"Data Source=localhost;Initial Catalog=LibraryDB;Integrated Security=True;TrustServerCertificate=True");
con.Open();
SqlCommand cmd = new SqlCommand("DELETE FROM students WHERE studentid=@studentid", con);
cmd.Parameters.AddWithValue("@StudentID", int.Parse(textBox1.Text));
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Record Deleted");
LoadStudents();
}
Dashboard.cs Code
private void display1()
{
SqlConnection con = new SqlConnection(@"Data Source=localhost;Initial Catalog=LibraryDB;Integrated Security=True;TrustServerCertificate=True");
con.Open();
SqlCommand comm = new SqlCommand("SELECT COUNT(*) FROM students", con);
Int32 count = Convert.ToInt32(comm.ExecuteScalar());
if (count > 0)
{
lblCount1.Text = Convert.ToString(count.ToString()); //For example a Label
}
else
{
lblCount1.Text = "0";
}
con.Close(); //Remember close the connection
}
private void display2()
{
SqlConnection con = new SqlConnection(@"Data Source=localhost;Initial Catalog=LibraryDB;Integrated Security=True;TrustServerCertificate=True");
con.Open();
SqlCommand comm = new SqlCommand("SELECT COUNT(*) FROM books", con);
Int32 count = Convert.ToInt32(comm.ExecuteScalar());
if (count > 0)
{
lblCount2.Text = Convert.ToString(count.ToString()); //For example a Label
}
else
{
lblCount2.Text = "0";
}
con.Close(); //Remember close the connection
}
private void display3()
{
SqlConnection con = new SqlConnection(@"Data Source=localhost;Initial Catalog=LibraryDB;Integrated Security=True;TrustServerCertificate=True");
con.Open();
SqlCommand comm = new SqlCommand("SELECT COUNT(*) FROM librarians", con);
Int32 count = Convert.ToInt32(comm.ExecuteScalar());
if (count > 0)
{
lblCount3.Text = Convert.ToString(count.ToString()); //For example a Label
}
else
{
lblCount3.Text = "0";
}
con.Close(); //Remember close the connection
}