From a8259945850b7384dd0b7d017684eaad51f172f8 Mon Sep 17 00:00:00 2001 From: JoshyyCoded Date: Sun, 29 Mar 2026 15:35:01 +0800 Subject: [PATCH 1/4] Update Form1.cs --- TestWins/Form1.cs | 49 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/TestWins/Form1.cs b/TestWins/Form1.cs index fcefc88..8c7dce6 100644 --- a/TestWins/Form1.cs +++ b/TestWins/Form1.cs @@ -6,38 +6,67 @@ namespace TestWins; public partial class Form1 : Form { //business - private readonly StudentController controller = new StudentController(); + public Form1() { InitializeComponent(); - loadData(); - } - - private void loadData() - { - dataGridView1.DataSource = controller.getAll(); } private void btnAdd_Click(object sender, EventArgs e) { + var student = new TestWins.Model.Student + { + studentId = txtStudentId.Text, + Name = txtName.Text, + age = int.Parse(txtAge.Text), + course = txtCourse.Text + }; + controller.createStudent(student); + loadData(); + clearFields(); } private void btnUpdate_Click(object sender, EventArgs e) { + var student = new TestWins.Model.Student + { + studentId = txtStudentId.Text, + Name = txtName.Text, + age = int.Parse(txtAge.Text), + course = txtCourse.Text + }; + controller.update(student); + loadData(); + clearFields(); } private void btnDelete_Click(object sender, EventArgs e) { - - - + controller.delete(txtStudentId.Text); + loadData(); + clearFields(); } private void dataGridView1_CellClick(object sender, EventArgs e) { + if (dataGridView1.CurrentRow != null) + { + DataGridViewRow row = dataGridView1.CurrentRow; + txtStudentId.Text = row.Cells[0].Value.ToString(); + txtName.Text = row.Cells[1].Value.ToString(); + txtAge.Text = row.Cells[2].Value.ToString(); + txtCourse.Text = row.Cells[3].Value.ToString(); + } + } + private void clearFields() + { + txtStudentId.Text = ""; + txtName.Text = ""; + txtAge.Text = ""; + txtCourse.Text = ""; } } From e08047755e5807f925c76e0103b887ca147df067 Mon Sep 17 00:00:00 2001 From: JoshyyCoded Date: Sun, 29 Mar 2026 23:03:04 +0800 Subject: [PATCH 2/4] Update Form1.cs --- TestWins/Form1.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/TestWins/Form1.cs b/TestWins/Form1.cs index 8c7dce6..b68c031 100644 --- a/TestWins/Form1.cs +++ b/TestWins/Form1.cs @@ -8,11 +8,16 @@ public partial class Form1 : Form //business private readonly StudentController controller = new StudentController(); - public Form1() + public Form1() { InitializeComponent(); + loadData(); } + private void loadData() + { + dataGridView1.DataSource = controller.getAll(); + } private void btnAdd_Click(object sender, EventArgs e) { var student = new TestWins.Model.Student From d748eded1714fb68df4e26adf93bead8a6cd9471 Mon Sep 17 00:00:00 2001 From: JoshyyCoded Date: Sun, 29 Mar 2026 23:14:38 +0800 Subject: [PATCH 3/4] Update StudentRepository.cs --- TestWins/repository/StudentRepository.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TestWins/repository/StudentRepository.cs b/TestWins/repository/StudentRepository.cs index a823e74..bb06d47 100644 --- a/TestWins/repository/StudentRepository.cs +++ b/TestWins/repository/StudentRepository.cs @@ -16,7 +16,7 @@ public void create(Student student) using var conn = _db.connectSql(); //Connection conn.Open(); //Open Connection - string query = "INSERT INTO students VALUES(@name, @age, @course)"; + string query = "INSERT INTO (name, age, course) students VALUES(@name, @age, @course)"; using var cmd = new MySqlCommand(query, conn); @@ -56,7 +56,7 @@ public void update(Student student) using var conn = _db.connectSql(); conn.Open(); - string query = "UPDATE students SET name = @name, age=@age, course=@course where studentId = @ID"; + string query = "UPDATE students SET name=@name, age=@age, course=@course where studentId = @id"; using var cmd = new MySqlCommand(query, conn); @@ -82,4 +82,4 @@ public void delete(string id) cmd.ExecuteNonQuery(); } -} \ No newline at end of file +} From 60586dd4500d588c9d279620d5719e1fd06750d4 Mon Sep 17 00:00:00 2001 From: JoshyyCoded Date: Sun, 29 Mar 2026 23:16:26 +0800 Subject: [PATCH 4/4] Update Form1.cs --- TestWins/Form1.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TestWins/Form1.cs b/TestWins/Form1.cs index b68c031..8fbab1c 100644 --- a/TestWins/Form1.cs +++ b/TestWins/Form1.cs @@ -8,7 +8,7 @@ public partial class Form1 : Form //business private readonly StudentController controller = new StudentController(); - public Form1() + public Form1() { InitializeComponent(); loadData();