-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddStudentDetails.cs
128 lines (110 loc) · 3.97 KB
/
AddStudentDetails.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
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 AddStudentDetails : Form
{
// all the methods mostly act as event listeners and updated the values stored in the
// student object created. When the add button is pressed this object is passed onto the
// DBRepo function to add it to the database
readonly private Student newStudent;
public AddStudentDetails()
{
newStudent = new Student();
InitializeComponent();
}
private void Label1_Click(object sender, EventArgs e)
{
}
private void Label4_Click(object sender, EventArgs e)
{
}
private void StudendIDBoxTextChangedEvent(object sender, EventArgs e)
{
this.newStudent.StudentId = ((TextBox)sender).Text;
Debug.WriteLine(newStudent.StudentId);
}
private void Label9_Click(object sender, EventArgs e)
{
}
private void Branch_SelectedIndexChanged(object sender, EventArgs e)
{
Console.WriteLine("Branch Index changed");
this.newStudent.Branch = ((ComboBox)sender).SelectedItem.ToString();
Console.WriteLine(newStudent);
}
private void Campus_SelectedIndexChanged(object sender, EventArgs e)
{
this.newStudent.Campus = ((ComboBox)sender).SelectedItem.ToString();
Console.WriteLine(this.newStudent);
}
private void FirstNameBox_TextChanged(object sender, EventArgs e)
{
this.newStudent.FirstName = ((TextBox)sender).Text;
}
private void LastNameBox_TextChanged(object sender, EventArgs e)
{
this.newStudent.LastName = ((TextBox)sender).Text;
}
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.newStudent.Cgpa = result;
}
}
private void AddStudentButtonClick(object sender, EventArgs e)
{
this.SaveStudentButton.DialogResult = DialogResult.None;
this.CancelButton.DialogResult = DialogResult.None;
this.DialogResult = DialogResult.None;
if (this.newStudent.ValidateEntries())
{
Debug.WriteLine(this.newStudent.ToString());
bool result = DBRepo.AddStudent(this.newStudent);
if (!result)
{
MessageBox.Show("Student already exists");
}
else
{
this.SaveStudentButton.DialogResult = DialogResult.OK;
this.CancelButton.DialogResult = DialogResult.OK;
this.DialogResult = DialogResult.OK;
MessageBox.Show("User added successfully");
}
}
else
{
MessageBox.Show("Please fill all the values");
}
}
private void YearBox_SelectedIndexChanged(object sender, EventArgs e)
{
this.newStudent.Year = Int32.Parse(((ComboBox)sender).SelectedItem.ToString());
Console.WriteLine(this.newStudent);
}
private void Button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void Label11_Click(object sender, EventArgs e)
{
}
}
}