Exemplo n.º 1
0
        private void Create_Click(object sender, EventArgs e)
        {
            this.Hide();
            Create_Student st = new Create_Student();

            st.ShowDialog();
            this.Close();
        }
Exemplo n.º 2
0
        private void StudentData_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            StudentData.Rows[e.RowIndex].ReadOnly = true;
            int noOfRows = StudentData.RowCount;

            if (e.ColumnIndex == 8 && e.RowIndex >= 0 && e.RowIndex != (noOfRows - 1)) // when click on del button
            {
                DialogResult dialogResult = MessageBox.Show("Are you sure that you want to delete it?", "Confirmation", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    SqlConnection con = new SqlConnection(conURL);

                    // connection opens

                    con.Open();
                    try
                    {
                        string cmdText = "DELETE FROM Student WHERE Id = @Id";

                        SqlCommand c = new SqlCommand(cmdText, con);


                        int Idy = Convert.ToInt32(StudentData.Rows[e.RowIndex].Cells[0].Value);
                        c.Parameters.Add(new SqlParameter("@Id", Idy));
                        // execute it

                        int result = c.ExecuteNonQuery();
                        if (result < 0)
                        {
                            MessageBox.Show("Error");
                        }
                        string     cmdText2 = "DELETE FROM Person WHERE Id = @Id";
                        SqlCommand c2       = new SqlCommand(cmdText2, con);
                        c2.Parameters.Add(new SqlParameter("@Id", Idy));
                        c2.ExecuteNonQuery();
                        // connection closed

                        con.Close();

                        StudentData.DataSource = null;
                        StudentData.Rows.Clear();
                        StudentData.Columns.Clear();
                        update();

                        MessageBox.Show("Successfully Deleted");
                    }
                    catch (Exception)

                    {
                        MessageBox.Show("This student might be assign to any project. So first delete that record then delete it from here");
                    }
                }
                else if (dialogResult == DialogResult.No)
                {
                    //do something else
                }
            }

            if (e.ColumnIndex == 9 && e.RowIndex >= 0 && e.RowIndex != (noOfRows - 1)) // when click on update button
            {
                stId = Convert.ToInt32(StudentData.Rows[e.RowIndex].Cells[0].Value);
                this.Hide();
                Create_Student create = new Create_Student();

                create.ShowDialog();
                this.Close();
            }
            else
            {
            }
        }