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 diff --git a/TestWins/Form1.cs b/TestWins/Form1.cs index fcefc88..37a3047 100644 --- a/TestWins/Form1.cs +++ b/TestWins/Form1.cs @@ -1,13 +1,11 @@ +using System.Windows.Forms; 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 +19,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) + private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs 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 = ""; } }