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
/
FinanceController.cs
225 lines (177 loc) · 7.42 KB
/
FinanceController.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
public class FinanceTokenDeg
{
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; }
}
//Pay_id, user_id, status, type, Total_Amount, Paid_Amount
public class FinancePayment
{
public string Pay_id { get; set; }
public string user_id { get; set; }
public string status { get; set; }
public string type { get; set; }
public string Total_Amount { get; set; }
public string Paid_Amount { get; set; }
}
public class FinanceTrackTime
{
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 FinanceController
{
private static readonly FinanceController instance = new FinanceController();
private readonly string connectionString = "Data Source=DESKTOP-DH5VMPH\\SQLEXPRESS;Initial Catalog=final_se;Integrated Security=True;";
private FinanceController() { }
public static FinanceController GetFinanceInstance()
{
return instance;
}
public static FinanceController GetFinancePaymentInstance()
{
return instance;
}
public List<TokenDeg> GetFinanceTokenDegList()
{
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<FinancePayment> GetFinancePaymentList(string selectedTokenID)
{
List<FinancePayment> FinancePaymentList = new List<FinancePayment>();
using (SqlConnection connection = new SqlConnection(connectionString))
{
string query = "SELECT * FROM Payment WHERE user_id IN (SELECT user_id FROM TokenDeg WHERE Token_id = @selectedTokenID)";
SqlCommand command = new SqlCommand(query, connection);
command.Parameters.AddWithValue("@selectedTokenID", selectedTokenID);
try
{
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
FinancePayment FinancePayment = new FinancePayment
{
Pay_id = reader["Pay_id"].ToString(),
user_id = reader["user_id"].ToString(),
status = reader["status"].ToString(),
type = reader["type"].ToString(),
Total_Amount = reader["Total_Amount"].ToString(),
Paid_Amount = reader["Paid_Amount"].ToString()
};
FinancePaymentList.Add(FinancePayment);
}
reader.Close();
}
catch (Exception ex)
{
Console.WriteLine("An error occurred while fetching FinancePayment data: " + ex.Message);
}
}
// Print statement to check if FinancePayment data is fetched
Console.WriteLine("FinancePayment data fetched successfully.");
return FinancePaymentList;
}
public FinanceTokenDeg GetTokenDetails(string tokenID)
{
FinanceTokenDeg 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 FinanceTokenDeg
{
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 UpdateFinanceTokenDegDecision(string tokenID, string decision, string comment)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
string query = "UPDATE TokenDeg SET finance_decision = @decision, finance_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);
}
}
}
}