-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcourse.cpp
155 lines (127 loc) · 3.58 KB
/
course.cpp
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include"course.h"
#include "register_open.h"
#include "register_close.h"
#include"withdraw_open.h"
#include"withdraw_close.h"
course::course() {};
course::course(string code, string title, int crd, vector<string> sem, int Offerto)
{
course_code = code, course_title = title, credit_hrs = crd; offeredTo = Offerto;
sems_taught = sem;
}
void course::add_section(section s) // setter
{
sections.push_back(s);
}
bool course::open_registration()
{
for (int i = 0; i < sections.size(); i++)
{
state* s = new register_open(sections[i]);
sections[i].change_reg_state(s);
SAConnection con;
SACommand update(&con, _TSA("update Section set regState=:1 where coursecode=:2"));
update.Param(1).setAsInt64() = 1;
update.Param(2).setAsString() = course_code.c_str();
//update.Param(3).setAsString() = course_title.c_str();
try {
con.Connect(_TSA("LAPTOP-MAPPIP6B@LMS"), _TSA("sa"), _TSA("password"), SA_SQLServer_Client);
update.Execute();
update.Close();
con.Disconnect();
}
catch (SAException &x) {
con.Rollback();
printf("%s\n", x.ErrText().GetMultiByteChars());
}
}
return true;
}
bool course::close_registration()
{
for (int i = 0; i < sections.size(); i++)
{
state* s = new register_close(sections[i]);
sections[i].change_reg_state(s);//change of all sections will be changed
SAConnection con;
SACommand update(&con, _TSA("update Section set regState=:1 where coursecode=:2"));
update.Param(1).setAsInt64() = 2;
update.Param(2).setAsString() = course_code.c_str();
try {
con.Connect(_TSA("LAPTOP-MAPPIP6B@LMS"), _TSA("sa"), _TSA("password"), SA_SQLServer_Client);
update.Execute();
update.Close();
con.Disconnect();
}
catch (SAException &x) {
con.Rollback();
printf("%s\n", x.ErrText().GetMultiByteChars());
}
}
return true;
}
bool course::open_withdraw()
{
for (int i = 0; i < sections.size(); i++)
{
state* s = new withdraw_open(sections[i]);
sections[i].change_reg_state(s);//update open
SAConnection con;
SACommand update(&con, _TSA("update Section set regState=:1 where coursecode=:2"));
update.Param(1).setAsInt64() = 4;
update.Param(2).setAsString() = course_code.c_str();
try {
con.Connect(_TSA("LAPTOP-MAPPIP6B@LMS"), _TSA("sa"), _TSA("password"), SA_SQLServer_Client);
update.Execute();
update.Close();
con.Disconnect();
}
catch (SAException &x) {
con.Rollback();
printf("%s\n", x.ErrText().GetMultiByteChars());
}
}
return true;
}
bool course::close_withdraw()
{
for (int i = 0; i < sections.size(); i++)
{
state* s = new withdraw_close(sections[i]);
sections[i].change_reg_state(s);//change of all sections will be changed
SAConnection con;
SACommand update(&con, _TSA("update Section set regState=:1 where coursecode=:2"));
update.Param(1).setAsInt64() = 5;
update.Param(2).setAsString() = course_code.c_str();
try {
con.Connect(_TSA("LAPTOP-MAPPIP6B@LMS"), _TSA("sa"), _TSA("password"), SA_SQLServer_Client);
update.Execute();
update.Close();
con.Disconnect();
}
catch (SAException &x) {
con.Rollback();
printf("%s\n", x.ErrText().GetMultiByteChars());
}
}
return true;
}
string course::getcoursecode()
{
return course_code;
}
void course::printCourse()
{
cout << "\nCourse Code " << course_code << "\nCourse Title " << course_title << "\nCredit Hours " << credit_hrs<<" ";
}
bool course::operator==(string code)
{
if (course_code == code)
return true;
else
return false;
}
string course::get_title()
{
return course_code;
}