-
Notifications
You must be signed in to change notification settings - Fork 0
/
EditPatronForm.cs
72 lines (65 loc) · 2.28 KB
/
EditPatronForm.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
//Granding ID: T6181
//CIS 200-01
//4/3/2020
//Program 3
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace LibraryItems
{
public partial class EditPatronForm : Form
{
private List<LibraryPatron> _patrons; //Declares the patron variable
public EditPatronForm(List<LibraryPatron> patronList) //Declares the patron list
{
InitializeComponent();
_patrons = patronList; //Matches the patron variable to the list
}
//Precondition: none
//Postcondition: Outputs the list of patrons when the user clicks on the combo box
private void EditPatronForm_Load(object sender, EventArgs e)
{
foreach (LibraryPatron patron in _patrons)
patronBox.Items.Add($"{patron.PatronName}, {patron.PatronID}");
}
public int PatronIndex
{
// Precondition: None
// Postcondition: The index of form's selected patron combo box has been returned
get
{
return patronBox.SelectedIndex;
}
}
//Precondition: none
//Postcondition: Validates the combo box
private void patronCbo_Validating(object sender, CancelEventArgs e)
{
if (patronBox.SelectedIndex == -1) // Nothing selected
{
e.Cancel = true;
errorProvider.SetError(patronBox, "Must select Patron");
}
}
//Precondition: none
//Postcondition: Outputs the values of the selected patron into the edit book form
private void editButton_Click(object sender, EventArgs e)
{
LibraryPatron b = _lib._patrons[PatronIndex];
PatronForm pf = new PatronForm();
pf.PatronID = b.PatronID;
pf.PatronName = b.PatronName;
DialogResult result = pf.ShowDialog();
if(result == DialogResult.OK)
{
b.PatronID = pf.PatronID;
b.PatronName = pf.PatronName;
}
}
}
}