-
Notifications
You must be signed in to change notification settings - Fork 9
/
ManageCourseForm.cs
117 lines (101 loc) · 3.96 KB
/
ManageCourseForm.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
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;
using System.IO;
using MySql.Data.MySqlClient;
namespace Student_Management_System
{
public partial class ManageCourseForm : Form
{
CourseClass course = new CourseClass();
public ManageCourseForm()
{
InitializeComponent();
}
private void ManageCourseForm_Load(object sender, EventArgs e)
{
showTable();
}
// show course data
private void showTable()
{
DataGridView_courses.DataSource = course.GetCourse(new MySqlCommand("SELECT * FROM `courses`"));
}
private void button_clearcourse_Click(object sender, EventArgs e)
{
textBox_courseID.Clear();
textbox_coursename.Clear();
textbox_coursedur.Clear();
textBox_coursedes.Clear();
}
private void button_updatecourse_Click(object sender, EventArgs e)
{
if (textbox_coursename.Text == "" || textbox_coursedur.Text == "" || textBox_courseID.Text.Equals(""))
{
MessageBox.Show("Please Insert Course Details", "Field Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
int id = Convert.ToInt32(textBox_courseID.Text);
string Cname = textbox_coursename.Text;
int dur = Convert.ToInt32(textbox_coursedur.Text);
string desc = textBox_coursedes.Text;
if (course.UpdateCourse(id, Cname, dur, desc))
{
showTable();
button_clearcourse.PerformClick();
MessageBox.Show("Course Updated Succefully", "Update Course", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Error Updating Course", "Update Course", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void button_deletecourse_Click(object sender, EventArgs e)
{
if (textBox_courseID.Text.Equals(""))
{
MessageBox.Show("Please Insert Course ID", "Field Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
try
{
int id = Convert.ToInt32(textBox_courseID.Text);
string Cname = textbox_coursename.Text;
int dur = Convert.ToInt32(textbox_coursedur.Text);
string desc = textBox_coursedes.Text;
if (course.deleteCourse(id))
{
showTable();
button_clearcourse.PerformClick();
MessageBox.Show("Course Deleted Succefully", "Delete Course", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}catch(Exception ex)
{
MessageBox.Show(ex.Message, "Delete Course", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void DataGridView_student_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
textBox_courseID.Text = DataGridView_courses.CurrentRow.Cells[0].Value.ToString();
textbox_coursename.Text = DataGridView_courses.CurrentRow.Cells[1].Value.ToString();
textbox_coursedur.Text = DataGridView_courses.CurrentRow.Cells[2].Value.ToString();
textBox_coursedes.Text = DataGridView_courses.CurrentRow.Cells[3].Value.ToString();
}
private void button_search_Click(object sender, EventArgs e)
{
}
private void textBox_search_TextChanged(object sender, EventArgs e)
{
}
}
}