This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FypController.cs
198 lines (161 loc) · 6.7 KB
/
FypController.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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
public class TokenDeg
{
public string Token_id { get; set; }
public string form_id { get; set; }
public string fyp_decision { get; set; }
public string finance_decision { get; set; }
public string fyp_comment { get; set; }
public string finance_comment { get; set; }
}
public class TrackTime
{
public string Token_id { get; set; }
public DateTime Starting_time { get; set; }
public DateTime Estimated_time { get; set; }
public DateTime Generation_date { get; set; }
public DateTime Fyp_time { get; set; }
}
public class FypController
{
private static readonly FypController instance = new FypController();
private readonly string connectionString = "Data Source=DESKTOP-DH5VMPH\\SQLEXPRESS;Initial Catalog=final_se;Integrated Security=True;";
private FypController() { }
public static FypController GetInstance()
{
return instance;
}
public List<TokenDeg> GetTokenDegList()
{
List<TokenDeg> tokenDegList = new List<TokenDeg>();
using (SqlConnection connection = new SqlConnection(connectionString))
{
string query = "SELECT * FROM TokenDeg";
SqlCommand command = new SqlCommand(query, connection);
try
{
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
TokenDeg tokenDeg = new TokenDeg
{
Token_id = reader["Token_id"].ToString(),
form_id = reader["form_id"].ToString(),
fyp_decision = reader["fyp_decision"].ToString(),
finance_decision = reader["finance_decision"].ToString(),
fyp_comment = reader["fyp_comment"].ToString(),
finance_comment = reader["finance_comment"].ToString()
};
tokenDegList.Add(tokenDeg);
}
reader.Close();
}
catch (Exception ex)
{
Console.WriteLine("An error occurred while fetching TokenDeg data: " + ex.Message);
}
}
// Print statement to check if TokenDeg data is fetched
Console.WriteLine("TokenDeg data fetched successfully.");
return tokenDegList;
}
public List<TrackTime> GetTrackTimeList()
{
List<TrackTime> trackTimeList = new List<TrackTime>();
using (SqlConnection connection = new SqlConnection(connectionString))
{
string query = "SELECT Token_id, Starting_time, Estimated_time, Generation_date, Fyp_time FROM TrackTime";
SqlCommand command = new SqlCommand(query, connection);
try
{
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
TrackTime trackTime = new TrackTime
{
Token_id = reader["Token_id"].ToString(),
Starting_time = Convert.ToDateTime(reader["Starting_time"]),
Estimated_time = Convert.ToDateTime(reader["Estimated_time"]),
Generation_date = Convert.ToDateTime(reader["Generation_date"]),
Fyp_time = Convert.ToDateTime(reader["Fyp_time"])
};
trackTimeList.Add(trackTime);
}
reader.Close();
}
catch (Exception ex)
{
Console.WriteLine("An error occurred while fetching TrackTime data: " + ex.Message);
}
}
// Print statement to check if TrackTime data is fetched
Console.WriteLine("TrackTime data fetched successfully.");
return trackTimeList;
}
public TokenDeg GetTokenDetails(string tokenID)
{
TokenDeg tokenDetails = null;
using (SqlConnection connection = new SqlConnection(connectionString))
{
string query = "SELECT * FROM TokenDeg WHERE Token_id = @tokenID";
SqlCommand command = new SqlCommand(query, connection);
command.Parameters.AddWithValue("@tokenID", tokenID);
try
{
connection.Open();
SqlDataReader reader = command.ExecuteReader();
if (reader.Read())
{
tokenDetails = new TokenDeg
{
Token_id = reader["Token_id"].ToString(),
form_id = reader["form_id"].ToString(),
fyp_decision = reader["fyp_decision"].ToString(),
finance_decision = reader["finance_decision"].ToString(),
fyp_comment = reader["fyp_comment"].ToString(),
finance_comment = reader["finance_comment"].ToString()
};
}
reader.Close();
}
catch (Exception ex)
{
Console.WriteLine("An error occurred while fetching token details: " + ex.Message);
}
}
return tokenDetails;
}
public void UpdateTokenDegDecision(string tokenID, string decision, string comment)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
string query = "UPDATE TokenDeg SET fyp_decision = @decision, fyp_comment = @comment WHERE Token_id = @tokenID";
SqlCommand command = new SqlCommand(query, connection);
command.Parameters.Add("@decision", SqlDbType.VarChar).Value = decision;
command.Parameters.Add("@comment", SqlDbType.VarChar).Value = comment;
command.Parameters.Add("@tokenID", SqlDbType.VarChar).Value = tokenID;
try
{
connection.Open();
int rowsAffected = command.ExecuteNonQuery();
if (rowsAffected > 0)
{
Console.WriteLine("Rows affected: " + rowsAffected);
}
else
{
Console.WriteLine("No rows affected.");
}
}
catch (Exception ex)
{
Console.WriteLine("An error occurred while updating TokenDeg data: " + ex.Message);
}
}
}
}