private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.Columns[e.ColumnIndex].Name == "Delete" && (e.RowIndex >= 0))
            {
                try
                {
                    conn.Open();
                    if (MessageBox.Show("Are You Sure You Want to Delete this?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        int        id       = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Id"].Value);
                        int        rows1    = 0;
                        int        rows2    = 0;
                        string     m1       = String.Format("DELETE FROM GroupProject Where ProjectId = @Id ");
                        SqlCommand command1 = new SqlCommand(m1, conn);
                        command1.Parameters.Add(new SqlParameter("@Id", id));
                        if (command1.ExecuteNonQuery() > 0)
                        {
                            rows1 = command1.ExecuteNonQuery();
                        }

                        string     m2       = String.Format("DELETE FROM ProjectAdvisor Where ProjectId = @Id ");
                        SqlCommand command2 = new SqlCommand(m2, conn);
                        command2.Parameters.Add(new SqlParameter("@Id", id));
                        if (command2.ExecuteNonQuery() > 0)
                        {
                            rows2 = command1.ExecuteNonQuery();
                        }


                        string     m       = String.Format("DELETE FROM Project Where Id = @Id ");
                        SqlCommand command = new SqlCommand(m, conn);
                        command.Parameters.Add(new SqlParameter("@Id", id));
                        int rows = command.ExecuteNonQuery();
                        if (rows != 0 || (rows1 > 0 && rows2 > 0))
                        {
                            MessageBox.Show("Data deleted!");
                            this.Close();
                            ManageProject D = new ManageProject();
                            D.Show();
                        }
                    }
                    conn.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            else if (dataGridView1.Columns[e.ColumnIndex].Name == "Edit" && (e.RowIndex >= 0))
            {
                if (MessageBox.Show("Are You Sure You Want to Update this?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Edit_Panel.Show();
                    conn.Open();
                    int        id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Id"].Value);
                    SqlCommand cm = new SqlCommand("Select P.Id, P.Title, P.Description from Project P  where P.Id=@Id ", conn);
                    cm.Parameters.Add(new SqlParameter("@Id", id));
                    SqlDataReader dr;
                    dr = cm.ExecuteReader();
                    try
                    {
                        while (dr.Read())
                        {
                            TitleTxt.Text       = dr.GetString(1);
                            DescriptionTxt.Text = dr.GetString(2);
                            textBox1.Text       = Convert.ToString(dr.GetValue(0));
                        }
                        dr.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    conn.Close();
                }
                else
                {
                    // MessageBox.Show("");
                }
            }
        }
Ejemplo n.º 2
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.Columns[e.ColumnIndex].Name == "DELETE" && (e.RowIndex >= 0))
            {
                conn.Open();
                try
                {
                    if (MessageBox.Show("Are You Sure You Want to Delete this?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        int        id      = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Id"].Value);
                        string     m       = String.Format("Update GroupStudent  SET Status=@Status Where StudentId = @Id ");
                        SqlCommand command = new SqlCommand(m, conn);
                        command.Parameters.Add(new SqlParameter("@Id", id));
                        //command.Parameters.Add(new SqlParameter("@Status", id));
                        command.Parameters.Add(new SqlParameter("@Status", SqlDbType.Int));
                        command.Parameters["@Status"].Value = 4;

                        int rows = command.ExecuteNonQuery();

                        /**string m1 = String.Format("DELETE FROM Person Where Id = @Id ");
                         * SqlCommand command1 = new SqlCommand(m1, conn);
                         * command1.Parameters.Add(new SqlParameter("@Id", id));
                         * int rows1 = command1.ExecuteNonQuery();**/
                        if (rows != 0)
                        {
                            MessageBox.Show("Status Updated!");
                            this.Hide();
                            Dashboard D = new Dashboard();
                            D.Show();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                conn.Close();
            }


            else if (dataGridView1.Columns[e.ColumnIndex].Name == "Edit" && (e.RowIndex >= 0))
            {
                if (MessageBox.Show("Are You Sure You Want to Update this?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Edit_Panel.Show();
                    conn.Open();
                    int        id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Id"].Value);
                    SqlCommand cm = new SqlCommand("Select P.Id, P.FirstName, P.LastName, P.Contact, P.Email, P.DateofBirth, P.Gender, S.RegistrationNo from Person P Inner join Student S on P.Id = S.Id where P.Id=@Id ", conn);
                    cm.Parameters.Add(new SqlParameter("@Id", id));
                    dr = cm.ExecuteReader();
                    try
                    {
                        while (dr.Read())
                        {
                            FirstName.Text        = dr.GetString(1);
                            Last_Name.Text        = dr.GetString(2);
                            ContactTextBox.Text   = dr.GetString(3);
                            EmailTxtBox.Text      = dr.GetString(4);
                            dateTimePicker1.Value = (DateTime)dr.GetValue(5);
                            if ((int)dr.GetValue(6) == 1)
                            {
                                radioButton1.Checked = true;
                            }
                            else
                            {
                                radioButton2.Checked = true;
                            }
                            registrationtxt.Text = dr.GetString(7);
                            textBox1.Text        = Convert.ToString(dr.GetValue(0));
                        }
                        dr.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    conn.Close();
                }
            }
        }
Ejemplo n.º 3
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.Columns[e.ColumnIndex].Name == "Delete" && (e.RowIndex >= 0))
            {
                try
                {
                    conn.Open();
                    if (MessageBox.Show("Are You Sure You Want to Delete this?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        int        id       = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Id"].Value);
                        string     m1       = String.Format("DELETE FROM GroupEvaluation Where EvaluationId = @Id ");
                        SqlCommand command1 = new SqlCommand(m1, conn);
                        command1.Parameters.Add(new SqlParameter("@Id", id));
                        int rows2 = 0;
                        if (command1.ExecuteNonQuery() > 0)
                        {
                            rows2 = command1.ExecuteNonQuery();
                        }

                        //int id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Id"].Value);
                        string     m       = String.Format("DELETE FROM Evaluation Where Id = @Id ");
                        SqlCommand command = new SqlCommand(m, conn);
                        command.Parameters.Add(new SqlParameter("@Id", id));
                        int rows = command.ExecuteNonQuery();
                        if (rows > 0 || rows2 > 0)
                        {
                            MessageBox.Show("Data deleted!");
                            this.Hide();
                            Eval_Dashboards D = new Eval_Dashboards();
                            D.Show();
                        }
                    }
                    conn.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }


            else if (dataGridView1.Columns[e.ColumnIndex].Name == "Edit" && (e.RowIndex >= 0))
            {
                if (MessageBox.Show("Are You Sure You Want to Update this?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Edit_Panel.Show();
                    conn.Open();
                    int        id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Id"].Value);
                    SqlCommand cm = new SqlCommand("Select Id, Name, TotalMarks, TotalWeightage from Evaluation  where Id=@Id ", conn);
                    cm.Parameters.Add(new SqlParameter("@Id", id));
                    SqlDataReader dr;
                    dr = cm.ExecuteReader();
                    try
                    {
                        while (dr.Read())
                        {
                            nametxt.Text     = dr.GetString(1);
                            markstxt.Text    = Convert.ToString(dr.GetValue(2));
                            Weightaetxt.Text = Convert.ToString(dr.GetValue(3));
                            textBox1.Text    = Convert.ToString(dr.GetValue(0));
                        }
                        dr.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                conn.Close();
            }
            else
            {
                MessageBox.Show("This is the header row");
            }
        }
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.Columns[e.ColumnIndex].Name == "DELETE" && (e.RowIndex >= 0))
            {
                try
                {
                    if (MessageBox.Show("Are You Sure You Want to Delete this?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        conn.Open();
                        int        rows1    = 0;
                        int        id       = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Id"].Value);
                        string     m1       = String.Format("DELETE FROM ProjectAdvisor Where AdvisorId = @Id ");
                        SqlCommand command1 = new SqlCommand(m1, conn);
                        command1.Parameters.Add(new SqlParameter("@Id", id));

                        if (command1.ExecuteNonQuery() > 0)
                        {
                            rows1 = command1.ExecuteNonQuery();
                        }



                        string     m       = String.Format("DELETE FROM Advisor Where Id = @Id ");
                        SqlCommand command = new SqlCommand(m, conn);
                        command.Parameters.Add(new SqlParameter("@Id", id));
                        int rows = command.ExecuteNonQuery();

                        string     m2       = String.Format("DELETE FROM Person Where Id = @Id ");
                        SqlCommand command2 = new SqlCommand(m2, conn);
                        command2.Parameters.Add(new SqlParameter("@Id", id));
                        int rows2 = command2.ExecuteNonQuery();
                        if (rows > 0 && rows2 > 0 || rows1 > 0)
                        {
                            MessageBox.Show("Data deleted!");
                            this.Hide();
                            ManageAdviser r = new ManageAdviser();
                            r.Show();
                        }
                        conn.Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                conn.Close();
            }

            else if (dataGridView1.Columns[e.ColumnIndex].Name == "Edit" && (e.RowIndex >= 0))
            {
                if (MessageBox.Show("Are You Sure You Want to Update this?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Edit_Panel.Show();
                    conn.Open();
                    int        id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Id"].Value);
                    SqlCommand cm = new SqlCommand("Select P.Id, P.FirstName, P.LastName, P.Contact, P.Email, P.DateofBirth, P.Gender, S.Designation, S.Salary from Person P Inner join Advisor S on P.Id = S.Id  where P.Id=@Id ", conn);
                    cm.Parameters.Add(new SqlParameter("@Id", id));
                    dr = cm.ExecuteReader();
                    try
                    {
                        while (dr.Read())
                        {
                            FirstName.Text        = dr.GetString(1);
                            Last_Name.Text        = dr.GetString(2);
                            ContactTextBox.Text   = dr.GetString(3);
                            EmailTxtBox.Text      = dr.GetString(4);
                            dateTimePicker1.Value = (DateTime)dr.GetValue(5);
                            if ((int)dr.GetValue(6) == 1)
                            {
                                radioButton1.Checked = true;
                            }
                            else
                            {
                                radioButton2.Checked = true;
                            }
                            registrationtxt.Text = Convert.ToString(dr.GetValue(8));
                            if ((int)dr.GetValue(7) == 6)
                            {
                                advisercombo.Text = "Professor";
                            }
                            if ((int)dr.GetValue(7) == 7)
                            {
                                advisercombo.Text = "Associate Professor";
                            }
                            if ((int)dr.GetValue(7) == 8)
                            {
                                advisercombo.Text = "Assisstant Professor";
                            }
                            if ((int)dr.GetValue(7) == 9)
                            {
                                advisercombo.Text = "Lecturer";
                            }
                            if ((int)dr.GetValue(7) == 10)
                            {
                                advisercombo.Text = "Industry Professional";
                            }
                            //advisercombo.Text = Convert.ToString(dr.GetValue(7));
                            textBox1.Text = Convert.ToString(dr.GetValue(0));
                        }
                        dr.Close();
                        conn.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            else
            {
                MessageBox.Show("No data Availiable");
            }
        }