Exemplo n.º 1
0
        private void button4_Click(object sender, EventArgs e)
        {
            this.Hide();
            studetails s1 = new studetails();

            s1.Show();
        }
Exemplo n.º 2
0
        // edit delete
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                conn.Open();

                if (e.RowIndex == dataGridView1.NewRowIndex || e.RowIndex < 0)
                {
                    return;
                }

                //Check if click is on specific column
                if (e.ColumnIndex == dataGridView1.Columns["DeleteButton"].Index)
                {
                    int index = e.RowIndex;
                    int ID    = Convert.ToInt32(dataGridView1.Rows[index].Cells[3].Value.ToString());

                    string     delete3 = string.Format("DELETE FROM GroupStudent WHERE StudentId = '{0}'", ID);
                    SqlCommand del3    = new SqlCommand(delete3, conn);
                    int        k       = del3.ExecuteNonQuery();

                    string     delete1 = String.Format("DELETE FROM Student WHERE Id = '{0}'", ID);
                    SqlCommand de11    = new SqlCommand(delete1, conn);
                    int        i       = de11.ExecuteNonQuery();

                    string     delete2 = string.Format("DELETE FROM Person WHERE Id = '{0}'", ID);
                    SqlCommand del2    = new SqlCommand(delete2, conn);
                    int        j       = del2.ExecuteNonQuery();

                    // to check if the student is registered or not
                    if (i >= 1 && j >= 1)
                    {
                        MessageBox.Show(" Student Deleted ");
                        this.Refresh();
                    }
                    else
                    {
                        MessageBox.Show(" Student not Deleted ");
                    }

                    this.Refresh();
                    Refresh();
                    this.Hide();
                    student ss = new student();
                    ss.Show();
                }


                else if (e.ColumnIndex == dataGridView1.Columns["EditButton"].Index)
                {
                    int indexx = e.RowIndex;
                    IDD = Convert.ToInt32(dataGridView1.Rows[indexx].Cells[3].Value.ToString());
                    panel3.Show();
                    button5.Hide();
                    button6.Show();

                    string     fn  = "SELECT FirstName FROM Person WHERE Id = '" + IDD + "' ";
                    SqlCommand fnn = new SqlCommand(fn, conn);
                    fnn.ExecuteNonQuery();
                    string first = Convert.ToString(fnn.ExecuteScalar());
                    textBox1.Text = first;

                    string     ln  = "SELECT LastName FROM Person WHERE Id = '" + IDD + "' ";
                    SqlCommand lnn = new SqlCommand(ln, conn);
                    lnn.ExecuteNonQuery();
                    string last = Convert.ToString(lnn.ExecuteScalar());
                    textBox2.Text = last;


                    string     con  = "SELECT Contact FROM Person WHERE Id = '" + IDD + "' ";
                    SqlCommand cont = new SqlCommand(con, conn);
                    cont.ExecuteNonQuery();
                    string contact = Convert.ToString(cont.ExecuteScalar());
                    textBox3.Text = contact;


                    string     em  = "SELECT Email FROM Person WHERE Id = '" + IDD + "' ";
                    SqlCommand emi = new SqlCommand(em, conn);
                    emi.ExecuteNonQuery();
                    string email = Convert.ToString(emi.ExecuteScalar());
                    textBox4.Text = email;

                    string     regno = "SELECT RegistrationNo FROM Student WHERE Id = '" + IDD + "' ";
                    SqlCommand reg   = new SqlCommand(regno, conn);
                    reg.ExecuteNonQuery();
                    string rollno = Convert.ToString(reg.ExecuteScalar());
                    textBox5.Text = rollno;

                    string     gen    = "SELECT Gender FROM Person WHERE Id = '" + IDD + "' ";
                    SqlCommand gender = new SqlCommand(gen, conn);
                    gender.ExecuteNonQuery();
                    int genn = Convert.ToInt32(gender.ExecuteScalar());

                    string     designn      = "SELECT Value FROM Lookup WHERE Category= 'GENDER' AND Id ='" + genn + "' ";
                    SqlCommand InvAmountcom = new SqlCommand(designn, conn);
                    string     mf           = Convert.ToString(InvAmountcom.ExecuteScalar().ToString());

                    comboBox1.Text = mf;
                }

                else if (e.ColumnIndex == dataGridView1.Columns["DetailsButton"].Index)
                {
                    this.Hide();
                    studetails s1 = new studetails();
                    s1.Show();
                }

                conn.Close();
            }
            catch (Exception a)
            {
                MessageBox.Show(a.Message);
            }
        }