Esempio n. 1
0
        private void dataGridgroup_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            dataGridgroup.Rows[e.RowIndex].ReadOnly = true;
            int noOfRows = dataGridgroup.RowCount;


            if (e.ColumnIndex == 2 && e.RowIndex >= 0 && e.RowIndex != (noOfRows - 1)) // when click on add button
            {
                groupId = Convert.ToInt32(dataGridgroup.Rows[e.RowIndex].Cells[0].Value);
                this.Hide();
                AssignProject create = new AssignProject();

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

            if (e.ColumnIndex == 3 && e.RowIndex >= 0 && e.RowIndex != (noOfRows - 1)) // when click on view button
            {
                groupId = Convert.ToInt32(dataGridgroup.Rows[e.RowIndex].Cells[0].Value);
                this.Hide();
                ShowMembers create = new ShowMembers();

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

            else
            {
            }
        }
Esempio n. 2
0
        private void groupProjectDatagrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            groupProjectDatagrid.Rows[e.RowIndex].ReadOnly = true;
            int noOfRows = groupProjectDatagrid.RowCount;

            if (e.ColumnIndex == 4 && e.RowIndex >= 0 && e.RowIndex != (noOfRows - 1))
            {
                projectId = Convert.ToInt32(groupProjectDatagrid.Rows[e.RowIndex].Cells[0].Value);
                groupId   = Convert.ToInt32(groupProjectDatagrid.Rows[e.RowIndex].Cells[1].Value);
                this.Hide();
                AssignProject st = new AssignProject();
                st.ShowDialog();
                this.Close();
            }

            if (e.ColumnIndex == 5 && 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 open

                    con.Open();



                    string cmdText = "DELETE FROM GroupProject WHERE GroupId = @GroupId AND ProjectId =@ProjectId ";

                    SqlCommand c = new SqlCommand(cmdText, con);


                    int pId = Convert.ToInt32(groupProjectDatagrid.Rows[e.RowIndex].Cells[0].Value);
                    int gid = Convert.ToInt32(groupProjectDatagrid.Rows[e.RowIndex].Cells[1].Value);
                    c.Parameters.Add(new SqlParameter("@GroupId", gid));
                    c.Parameters.Add(new SqlParameter("@ProjectId", pId));
                    // execute it

                    c.ExecuteNonQuery();
                    // connection closed

                    con.Close();

                    dataGridgroup.DataSource = null;
                    dataGridgroup.Rows.Clear();
                    dataGridgroup.Columns.Clear();
                    groupProjectDatagrid.DataSource = null;
                    groupProjectDatagrid.Rows.Clear();
                    groupProjectDatagrid.Columns.Clear();
                    update();

                    MessageBox.Show("Successfully Deleted!!");
                }
                else if (dialogResult == DialogResult.No)
                {
                    //do something else
                }
            }
        }