-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfrmBookModify.cs
More file actions
157 lines (143 loc) · 4.93 KB
/
frmBookModify.cs
File metadata and controls
157 lines (143 loc) · 4.93 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
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;
namespace SA47Team10a_GalaxyLibrary
{
public partial class frmBookModify : frmTemplate
{
GalaxyEntities context;
Book b;
Form f;
public frmBookModify()
{
InitializeComponent();
}
private void frmBookModify_Load(object sender, EventArgs e)
{
context = new GalaxyEntities();
readOnlyFields();
}
private void btnMore_Click(object sender, EventArgs e)
{
// Dialog form
frm11BookSearchForStaff f = new frm11BookSearchForStaff();
DialogResult r = f.ShowDialog(this);
// Display all fields of selected record if 'OK' was chosen in dialog
if (r == DialogResult.OK)
{
b = context.Books.Where(x => x.BookID == f.SelectedID).First();
txBookID.Text = b.BookID;
txTitle.Text = b.Title;
txAuthor.Text = b.Author;
txPublisher.Text = b.Publisher;
cbxCategory.Text = b.BookCategory;
cbxFloor.Text = b.Location.Substring(1, 1);
txShelf.Text = b.Location.Substring(4, 3);
txPrice.Text = b.Price.ToString();
txStock.Text = b.TotalStock.ToString();
txNumBorrowed.Text = b.NumberBorrowed.ToString();
if (b.Availability.ToString() == "yes")
rbtnYes.Checked = true;
else
rbtnNo.Checked = true;
enableUpdateFields();
}
}
private void btnClear_Click(object sender, EventArgs e)
{
ResetValues();
readOnlyFields();
}
private void btnConfirm_Click(object sender, EventArgs e)
{
try
{
if (txTitle.Text == "" || txPublisher.Text == "" || txAuthor.Text == "" || txShelf.Text == "" || txPrice.Text == "" || txStock.Text == "")
throw new InvalidInputException();
// Update book details in database
b.Title = txTitle.Text;
b.Publisher = txPublisher.Text;
b.Author = txAuthor.Text;
b.BookCategory = cbxCategory.SelectedItem.ToString();
b.Location = "F" + cbxFloor.SelectedItem.ToString() + "-L" + txShelf.Text;
b.Price = Convert.ToDouble(txPrice.Text);
b.TotalStock = Convert.ToInt32(txStock.Text);
if (rbtnYes.Checked)
b.Availability = "yes";
else
b.Availability = "no";
context.SaveChanges();
MessageBox.Show("Book information successfully updated!");
ResetValues();
readOnlyFields();
}
catch (Exception a)
{
a = new InvalidInputException("Please fill in all fields.");
MessageBox.Show(a.Message);
}
}
private void ResetValues()
{
txBookID.Text = "";
txTitle.Text = "";
txPublisher.Text = "";
txAuthor.Text = "";
cbxCategory.Text = "";
cbxFloor.Text = "";
txShelf.Text = "";
txPrice.Text = "";
txStock.Text = "";
rbtnYes.Checked = false;
rbtnNo.Checked = false;
}
public void readOnlyFields()
{
txTitle.ReadOnly = true;
txPublisher.ReadOnly = true;
txAuthor.ReadOnly = true;
cbxCategory.Enabled = false;
cbxFloor.Enabled = false;
txShelf.ReadOnly = true;
txPrice.ReadOnly = true;
txStock.ReadOnly = true;
rbtnYes.Enabled = false;
rbtnNo.Enabled = false;
}
public void enableUpdateFields()
{
txTitle.ReadOnly = false;
txPublisher.ReadOnly = false;
txAuthor.ReadOnly = false;
cbxCategory.Enabled = true;
cbxFloor.Enabled = true;
txShelf.ReadOnly = false;
txPrice.ReadOnly = false;
txStock.ReadOnly = false;
rbtnYes.Enabled = true;
rbtnNo.Enabled = true;
}
private void btnBack_Click(object sender, EventArgs e)
{
this.Hide();
f = new frm8BookInformation();
f.Location = this.Location;
f.ShowDialog();
this.Close();
}
private void mbtnAdd_Click(object sender, EventArgs e)
{
this.Hide();
f = new frmBookAdd();
f.Location = this.Location;
f.ShowDialog();
this.Close();
}
}
}