-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMarkClass.cs
113 lines (97 loc) · 3.98 KB
/
MarkClass.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
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Threading.Tasks;
namespace SMS_Server
{
internal class MarkClass
{
DBConnect connect = new DBConnect();
public bool insertMark(int student_id, string course_name, int znamk, string Description)
{
MySqlCommand command = new MySqlCommand("INSERT INTO `marks`(`StudentID`, `Course_Name`, `Mark`, `Description`) VALUES (@stid, @cn, @mark, @description)", connect.getconnection);
command.Parameters.Add("@stid", MySqlDbType.Int32).Value = student_id;
command.Parameters.Add("@cn", MySqlDbType.VarChar).Value = course_name;
command.Parameters.Add("@mark", MySqlDbType.Int32).Value = znamk;
command.Parameters.Add("@description", MySqlDbType.VarChar).Value = Description;
connect.openConnect();
if (command.ExecuteNonQuery() == 1)
{
connect.closeConnect();
return true;
}
else
{
connect.closeConnect();
return false;
}
}
public DataTable getMark(MySqlCommand command)
{
command.Connection = connect.getconnection;
MySqlDataAdapter adapter = new MySqlDataAdapter(command);
DataTable table = new DataTable();
adapter.Fill(table);
return table;
}
public bool checkMark(int stdID, string course_name)
{
DataTable table = getMark(new MySqlCommand("SELECT * FROM `marks` WHERE `StudentID` = " + stdID + " AND `Course_Name` = '" + course_name + "'"));
if (table.Rows.Count>0)
{
return true;
}
else
{
return false;
}
}
public bool updateMark(string course_name, int student_id, int znamk, string desc)
{
MySqlCommand command = new MySqlCommand("UPDATE `marks` SET `Mark` = @mark, `Description` = @description WHERE `StudentID`=@stid AND `Course_Name` =@course_name", connect.getconnection);
command.Parameters.Add("@course_name", MySqlDbType.VarChar).Value = course_name;
command.Parameters.Add("@stid", MySqlDbType.Int32).Value = student_id;
command.Parameters.Add("@mark", MySqlDbType.Int32).Value = znamk;
command.Parameters.Add("@description", MySqlDbType.VarChar).Value = desc;
connect.openConnect();
if (command.ExecuteNonQuery() == 1)
{
connect.closeConnect();
return true;
}
else
{
connect.closeConnect();
return false;
}
}
public bool deleteMark(int id)
{
MySqlCommand command = new MySqlCommand("DELETE FROM `marks` WHERE `StudentID`=@stid", connect.getconnection);
command.Parameters.Add("@stid", MySqlDbType.Int32).Value= id;
connect.openConnect();
if (command.ExecuteNonQuery()==1)
{
connect.closeConnect();
return true;
}
else
{
connect.closeConnect();
return false;
}
}
public DataTable searchMark(string searchData)
{
MySqlCommand command = new MySqlCommand("SELECT marks.StudentID, student.Student_FN, student.Student_LN,marks.Mark, marks.Description FROM student INNER JOIN marks ON marks.StudentID = student.StudentID WHERE CONCAT(student.Student_FN, student.Student_LN, marks.Course_Name) LIKE '%" + searchData + "%'", connect.getconnection);
MySqlDataAdapter adapter = new MySqlDataAdapter(command);
DataTable table = new DataTable();
adapter.Fill(table);
return table;
}
}
}