-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateDeleteForm.cs
155 lines (136 loc) · 4.35 KB
/
UpdateDeleteForm.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
153
154
155
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace VisualProgrammingProject
{
public partial class UpdateDeleteForm : Form
{
Student student;
public UpdateDeleteForm(String studentId)
{
Student fetchedStudent = DBRepo.FetchStudentById(studentId);
Debug.WriteLine(fetchedStudent.ToString());
this.student = fetchedStudent;
InitializeComponent();
studentIDBox.Text = fetchedStudent.StudentId;
firstNameBox.Text = fetchedStudent.FirstName;
lastNameBox.Text = fetchedStudent.LastName;
branchBox.SelectedItem = fetchedStudent.Branch;
campusBox.SelectedItem = fetchedStudent.Campus;
yearBox.SelectedItem = fetchedStudent.Year;
cgpaBox.Text = fetchedStudent.Cgpa.ToString();
yearBox.Text = fetchedStudent.Year.ToString();
}
private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e)
{
}
private void groupBox2_Enter(object sender, EventArgs e)
{
}
private void UpdateDeleteForm_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
this.UpdateDetailsButton.DialogResult = DialogResult.None;
this.CancelButton.DialogResult = DialogResult.None;
this.DialogResult = DialogResult.None;
if (this.student.ValidateEntries())
{
bool result = DBRepo.UpdateStudentData(stud: this.student);
if (!result)
{
MessageBox.Show("Failed to update student");
}
else
{
this.UpdateDetailsButton.DialogResult = DialogResult.OK;
this.CancelButton.DialogResult = DialogResult.OK;
this.DialogResult = DialogResult.OK;
MessageBox.Show("User updated successfully");
}
}
else {
MessageBox.Show("Please fill all the values");
}
}
private void studentIDBox_TextChanged(object sender, EventArgs e)
{
student.StudentId = ((TextBox)sender).Text;
Debug.WriteLine(student.StudentId);
}
private void firstNameBox_TextChanged(object sender, EventArgs e)
{
student.FirstName = ((TextBox)sender).Text;
Debug.WriteLine(student.FirstName);
}
private void lastNameBox_TextChanged(object sender, EventArgs e)
{
student.LastName = ((TextBox)sender).Text;
Debug.WriteLine(student.LastName);
}
private void branchBox_SelectedIndexChanged(object sender, EventArgs e)
{
student.Branch = ((ComboBox)sender).SelectedItem.ToString();
Debug.WriteLine(student.Branch);
}
private void campusBox_SelectedIndexChanged(object sender, EventArgs e)
{
student.Campus = ((ComboBox)sender).SelectedItem.ToString();
Debug.WriteLine(student.Campus);
}
private void yearBox_SelectedIndexChanged(object sender, EventArgs e)
{
student.Year = Int32.Parse(((ComboBox)sender).SelectedItem.ToString());
Debug.WriteLine(student.Year);
}
private void CgpaBox_TextChanged(object sender, EventArgs e)
{
string cgpaText = ((TextBox)sender).Text;
double result = 0.0;
if ((cgpaText != "") && ((cgpaText.Contains(",")) || !Double.TryParse(cgpaText, out result) || result > 10 || result < 0.0))
{
MessageBox.Show("This is not a valid CGPA, Enter valid CGPA value");
((TextBox)sender).Text = "";
}
else
{
this.student.Cgpa = result;
}
}
private void DeleteButton_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show(text: "Are you sure you want to delete student?", caption: "This will not be reversible", buttons: MessageBoxButtons.OKCancel);
this.UpdateDetailsButton.DialogResult = DialogResult.None;
this.CancelButton.DialogResult = DialogResult.None;
this.DialogResult = DialogResult.None;
if (result == DialogResult.OK)
{
bool delresult = DBRepo.DeleteStudent(stud: this.student);
if (!delresult)
{
MessageBox.Show("Failed to delete student");
} else
{
MessageBox.Show("Deleted successfully!");
this.UpdateDetailsButton.DialogResult = DialogResult.OK;
this.CancelButton.DialogResult = DialogResult.OK;
this.DialogResult = DialogResult.OK;
}
} else
{
}
}
private void CancelButton_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
}
}
}