-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReturnBook.cs
116 lines (92 loc) · 3.43 KB
/
ReturnBook.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Library_Management_System
{
public partial class ReturnBook : Form
{
public ReturnBook()
{
InitializeComponent();
}
private void txtSearchStudent_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=BT-2105617\\SQLEXPRESS;Initial Catalog=library;Integrated Security=True;";
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select * from IRBook where std_enroll = '" + txtEnterEnroll.Text + "' and book_return_date IS NULL";
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
if(ds.Tables[0].Rows.Count != 0)
{
dataGridView1.DataSource = ds.Tables[0];
}
else
{
MessageBox.Show("Invalid ID or No Book Issued","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
private void ReturnBook_Load(object sender, EventArgs e)
{
panel2.Visible = false;
txtEnterEnroll.Clear();
}
String bname;
String bdate;
Int64 rowid;
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
panel2.Visible = true;
if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
{
rowid = Int64.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
bname = dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString();
bdate = dataGridView1.Rows[e.RowIndex].Cells[8].Value.ToString();
}
txtBookName.Text = bname;
txtBookIssueDate.Text = bdate;
}
private void btnReturn_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=BT-2105617\\SQLEXPRESS;Initial Catalog=library;Integrated Security=True;";
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
con.Open();
cmd.CommandText = "update IRBook set book_return_date = '" + dateTimePicker1.Text + "' where std_enroll = '"+txtEnterEnroll.Text+"' and id = "+rowid+"";
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Return Successful.","Success",MessageBoxButtons.OK,MessageBoxIcon.Information);
ReturnBook_Load(this, null);
}
private void txtEnterEnroll_TextChanged(object sender, EventArgs e)
{
if(txtEnterEnroll.Text == "")
{
panel2.Visible = false;
dataGridView1.DataSource = null;
}
}
private void btnRefresh_Click(object sender, EventArgs e)
{
txtEnterEnroll.Clear();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
panel2.Visible=false;
}
}
}