-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCourseClass.cs
105 lines (88 loc) · 3.48 KB
/
CourseClass.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
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SMS_Server
{
internal class CourseClass
{
//ENG connecting to the MySQL database
//CZ připojení k MySQL databazi
DBConnect connect = new DBConnect();
//ENG method for inserting and creating a Course instance into a database
//CZ vkladaní a vytvoření entity v databazi
public bool insertCourse(string course_name, int hr, string desc)
{
MySqlCommand command = new MySqlCommand("INSERT INTO `course`(`Course_Name`, `Course_Hour`, `Course_Desc`) VALUES (@course_name, @hr, @desc)", connect.getconnection);
command.Parameters.Add("@course_name", MySqlDbType.VarChar).Value = course_name;
command.Parameters.Add("@hr", MySqlDbType.Int32).Value = hr;
command.Parameters.Add("@desc", MySqlDbType.VarChar).Value = desc;
connect.openConnect();
if(command.ExecuteNonQuery() == 1)
{
connect.closeConnect();
return true;
}
else
{
connect.closeConnect();
return false;
}
}
public DataTable getCourse(MySqlCommand command)
{
command.Connection = connect.getconnection;
MySqlDataAdapter adapter = new MySqlDataAdapter(command);
DataTable table = new DataTable();
adapter.Fill(table);
return table;
}
public bool updateCourse(int id, string course_name, int hr, string desc)
{
MySqlCommand command = new MySqlCommand("UPDATE `course` SET `Course_Name`=@course_name,`Course_Hour`=@hr,`Course_Desc`=@desc", connect.getconnection);
command.Parameters.Add("@id", MySqlDbType.Int32).Value = id;
command.Parameters.Add("@course_name", MySqlDbType.VarChar).Value = course_name;
command.Parameters.Add("@hr", MySqlDbType.Int32).Value = hr;
command.Parameters.Add("@desc", MySqlDbType.VarChar).Value = desc;
connect.openConnect();
if (command.ExecuteNonQuery() == 1)
{
connect.closeConnect();
return true;
}
else
{
connect.closeConnect();
return false;
}
}
public bool deleteCourse(int id)
{
MySqlCommand command = new MySqlCommand("DELETE FROM `course` WHERE `Course_ID` = @id", connect.getconnection);
command.Parameters.Add("@id", MySqlDbType.Int32).Value = id;
connect.openConnect();
if (command.ExecuteNonQuery() == 1)
{
connect.closeConnect();
return true;
}
else
{
connect.closeConnect();
return false;
}
}
public DataTable searchCourse(string searchData)
{
MySqlCommand command = new MySqlCommand("SELECT * FROM `course` WHERE CONCAT(`Course_Name`, `Course_Hour`, `Course_Desc`) LIKE '%" + searchData + "%'", connect.getconnection);
MySqlDataAdapter adapter = new MySqlDataAdapter(command);
DataTable table = new DataTable();
adapter.Fill(table);
return table;
}
}
}