From 137b0396ffd984c20de9229958dfda6e31bd6af0 Mon Sep 17 00:00:00 2001 From: RalphDante <106255342+RalphDante@users.noreply.github.com> Date: Sun, 29 Mar 2026 11:31:16 +0800 Subject: [PATCH] Implement student management functionality 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 = ""; } }