Setup and forms
This commit is contained in:
1 parent
aed55f44f9
commit
eee7548fc8
47 files changed
+2837
-8138
No files matched your search
@@ -0,0 +1,63 @@
|
||||
using MySql.Data.MySqlClient;
|
||||
using PaymentLogs.Domain;
|
||||
using PaymentLogs.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Policy;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PaymentLogs.Repositories
|
||||
{
|
||||
internal class StudentRepo : Repo<int, Student>
|
||||
{
|
||||
|
||||
public override void Load()
|
||||
{
|
||||
DataBase db = new DataBase();
|
||||
db.openConnection();
|
||||
_data.Clear();
|
||||
string sql = " SELECT * FROM students ";
|
||||
MySqlCommand cmd = new MySqlCommand(sql, db.getConnection());
|
||||
MySqlDataReader reader = cmd.ExecuteReader();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
Student student = new Student()
|
||||
{
|
||||
Id = reader.GetInt32("id"),
|
||||
FCs = reader.GetString("fcs"),
|
||||
dateOfBirth = DateTime.ParseExact(reader.GetString("date_of_birth"), "yyyy-MM-dd",null),
|
||||
Address = reader.GetString("address"),
|
||||
CourseId = reader.GetInt32("course_id"),
|
||||
Paid = reader.GetInt32("paid")
|
||||
|
||||
};
|
||||
_data[student.Id] = student;
|
||||
}
|
||||
db.closeConnection();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override void Save()
|
||||
{
|
||||
DataBase db = new DataBase();
|
||||
db.openConnection();
|
||||
foreach (Student student in All())
|
||||
{
|
||||
string sql = $" INSERT INTO `students` (`id`, `fcs`, `date_of_birth`, `address`, `course_id`, `paid`) " +
|
||||
$"VALUES ('{student.Id}','{student.FCs}','{ String.Format("{0:yyyy-MM-dd}", student.dateOfBirth) }', '{student.Address}'," +
|
||||
$"'{student.CourseId}', '{student.Paid}') " +
|
||||
$"ON DUPLICATE KEY UPDATE `fcs`='{student.FCs}', `date_of_birth`='{String.Format("{0:yyyy-MM-dd}", student.dateOfBirth)}'," +
|
||||
$"`address`='{student.Address}', `course_id`='{student.CourseId}', `paid`='{student.Paid}'";
|
||||
MySqlCommand cmd = new MySqlCommand(sql, db.getConnection());
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
|
||||
db.closeConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user