From 4cba7a92071712c6b5d758a62e2a51a4bdf51005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Qui=C3=B1anola=20CJ?= Date: Sun, 29 Mar 2026 11:26:17 +0800 Subject: [PATCH 1/3] Refactor student management methods in Form1 --- TestWins/Form1.cs | 48 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/TestWins/Form1.cs b/TestWins/Form1.cs index fcefc88..9d9ce41 100644 --- a/TestWins/Form1.cs +++ b/TestWins/Form1.cs @@ -1,13 +1,10 @@ using System.Drawing.Text; using TestWins.Controller; - namespace TestWins; - public partial class Form1 : Form { - //business - private readonly StudentController controller = new StudentController(); + public Form1() { InitializeComponent(); @@ -21,23 +18,56 @@ private void loadData() 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 624fed999bb17dbf3265234b960798f76a8f952a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Qui=C3=B1anola=20CJ?= Date: Sun, 29 Mar 2026 11:41:20 +0800 Subject: [PATCH 2/3] Add txtStudentId TextBox to Form1 --- TestWins/Form1.Designer.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/TestWins/Form1.Designer.cs b/TestWins/Form1.Designer.cs index eb976a2..05a2314 100644 --- a/TestWins/Form1.Designer.cs +++ b/TestWins/Form1.Designer.cs @@ -50,6 +50,7 @@ private void InitializeComponent() this.txtName = new System.Windows.Forms.TextBox(); this.txtAge = new System.Windows.Forms.TextBox(); this.txtCourse = new System.Windows.Forms.TextBox(); + this.txtStudentId = new System.Windows.Forms.TextBox(); this.btnAdd = new System.Windows.Forms.Button(); this.btnUpdate = new System.Windows.Forms.Button(); @@ -91,6 +92,10 @@ private void InitializeComponent() this.txtCourse.Size = new System.Drawing.Size(200, 23); this.txtCourse.PlaceholderText = "Course"; + this.txtStudentId.Location = new System.Drawing.Point(20, 70); + this.txtStudentId.Size = new System.Drawing.Size(200, 23); + this.txtStudentId.PlaceholderText = "Student ID"; + // =============== // BUTTONS From 142fa1334a01f8c9eb164752c75d177ed417c8eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Qui=C3=B1anola=20CJ?= Date: Sun, 29 Mar 2026 11:44:41 +0800 Subject: [PATCH 3/3] Update event handler parameter type for CellClick --- TestWins/Form1.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/TestWins/Form1.cs b/TestWins/Form1.cs index 9d9ce41..37a3047 100644 --- a/TestWins/Form1.cs +++ b/TestWins/Form1.cs @@ -1,3 +1,4 @@ +using System.Windows.Forms; using System.Drawing.Text; using TestWins.Controller; namespace TestWins; @@ -51,7 +52,7 @@ private void btnDelete_Click(object sender, EventArgs e) clearFields(); } - private void dataGridView1_CellClick(object sender, EventArgs e) + private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (dataGridView1.CurrentRow != null) {