-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManageCourseForm.cs
116 lines (96 loc) · 3.61 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace SMS_Server
{
public partial class ManageCourseForm : Form
{
CourseClass course = new CourseClass();
public ManageCourseForm()
{
InitializeComponent();
}
private void ManageCourserForm_Load(object sender, EventArgs e)
{
showData();
}
private void showData()
{
dataGridCourse.DataSource = course.getCourse(new MySqlCommand("SELECT * FROM `course`"));
}
private void btnClear_Click(object sender, EventArgs e)
{
txtBoxCourseName.Clear();
txtBoxCourseHour.Clear();
txtBoxCourseDesc.Clear();
txtBoxCourseID.Clear();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
if (txtBoxCourseName.Text == "" || txtBoxCourseHour.Text == "" || txtBoxCourseID.Text.Equals(""))
{
MessageBox.Show("Empty text box", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
int id = Convert.ToInt32(txtBoxCourseID.Text);
string course_name = txtBoxCourseName.Text;
int hour = Convert.ToInt32(txtBoxCourseHour.Text);
string desc = txtBoxCourseDesc.Text;
if (course.updateCourse(id, course_name, hour, desc))
{
showData();
btnClear.PerformClick();
MessageBox.Show("Successfully changed", "Changed", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Error while updating", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
if (txtBoxCourseID.Text.Equals(""))
{
MessageBox.Show("Empty text box", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
try
{
int id = Convert.ToInt32(txtBoxCourseID.Text);
if (course.deleteCourse(id))
{
showData();
btnClear.PerformClick();
MessageBox.Show("Succesfully deleted", "Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}catch(Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void dataGridCourse_Click(object sender, EventArgs e)
{
txtBoxCourseID.Text = dataGridCourse.CurrentRow.Cells[0].Value.ToString();
txtBoxCourseName.Text = dataGridCourse.CurrentRow.Cells[1].Value.ToString();
txtBoxCourseHour.Text = dataGridCourse.CurrentRow.Cells[2].Value.ToString();
txtBoxCourseDesc.Text = dataGridCourse.CurrentRow.Cells[3].Value.ToString();
}
private void btnSearch_Click(object sender, EventArgs e)
{
dataGridCourse.DataSource = course.searchCourse(txtBoxSearch.Text);
txtBoxSearch.Clear();
}
}
}