/// <summary> /// function creates a new object of viewstudent form and close the current form /// </summary> /// <param name="sender">sender is the object sender that raised the event.</param> /// <param name="e"> e is the Event Argument of the object and basically contains the event data</param> private void button2_Click_1(object sender, EventArgs e) { ViewStudent stu = new ViewStudent(); this.Hide(); stu.Show(); }
/// <summary> /// function creates a new object of viewstudent form and close the current form /// </summary> /// <param name="sender">sender is the object sender that raised the event.</param> /// <param name="e"> e is the Event Argument of the object and basically contains the event data</param> private void button2_Click_2(object sender, EventArgs e) { ViewStudent vs = new ViewStudent(); this.Hide(); vs.Show(); }
/// <summary> /// Update the student /// </summary> /// <param name="sender">sender is the object sender that raised the event.</param> /// <param name="e"> e is the Event Argument of the object and basically contains the event data</param> private void button6_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(connection); con.Open(); if (con.State == ConnectionState.Open) { string query = "UPDATE dbo.Student SET FirstName = '" + textBox1.Text + "', LastName = '" + textBox2.Text + "',Contact = '" + textBox3.Text + "', Email = '" + textBox4.Text + "', RegistrationNumber = '" + textBox5.Text + "', Status = '" + 5 + "' WHERE Id = '" + ID + "'"; SqlCommand cmd = new SqlCommand(query, con); cmd.ExecuteNonQuery(); MessageBox.Show("Updated"); ViewStudent vs = new ViewStudent(); this.Hide(); vs.Show(); } }
/// <summary> /// Edit and Delete Funcytionality Against each of the student in gridview /// </summary> /// <param name="sender">sender is the object sender that raised the event.</param> /// <param name="e"> e is the Event Argument of the object and basically contains the event data</param> private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { //this code excuted when e.columnindex is equal to the edit column Index if (e.ColumnIndex == dataGridView1.Columns["Edit"].Index) { SqlConnection con = new SqlConnection(connection); con.Open(); if (con.State == ConnectionState.Open) { int ID = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Id"].Value); string fname = (dataGridView1.Rows[e.RowIndex].Cells["FirstName"].Value).ToString(); string lname = (dataGridView1.Rows[e.RowIndex].Cells["LastName"].Value).ToString(); string contact = (dataGridView1.Rows[e.RowIndex].Cells["Contact"].Value).ToString(); string email = (dataGridView1.Rows[e.RowIndex].Cells["Email"].Value).ToString(); string rg = (dataGridView1.Rows[e.RowIndex].Cells["RegistrationNumber"].Value).ToString(); int status = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Status"].Value); StudentEdit frm = new StudentEdit(ID, fname, lname, contact, email, rg, status); this.Hide(); frm.Show(); } } //this code excuted when e.columnindex is equal to the Delete column Index if (e.ColumnIndex == dataGridView1.Columns["Delete"].Index) { SqlConnection con = new SqlConnection(connection); con.Open(); if (con.State == ConnectionState.Open) { int ID = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Id"].Value); string query = "UPDATE dbo.Student SET Status = '" + 6 + "' WHERE Id = '" + ID + "'"; SqlCommand cmd = new SqlCommand(query, con); cmd.ExecuteNonQuery(); MessageBox.Show("Updated"); ViewStudent vs = new ViewStudent(); this.Hide(); vs.Show(); } } }