コード例 #1
0
        private void InsertGroupProject_Click_1(object sender, EventArgs e)
        {
            AssignProjectToGroup form = new AssignProjectToGroup(null, null, "add");

            form.Show();
            this.Close();
        }
コード例 #2
0
        private void ProjectGroups_CellClick_1(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == ProjectGroups.NewRowIndex || e.RowIndex < 0)
            {
                return;
            }

            if (e.ColumnIndex == ProjectGroups.Columns["GroupDeleteButton"].Index)
            {
                string       dialog       = string.Format("Remove Project '{0}'?", ProjectGroups.Rows[e.RowIndex].Cells[1].Value);
                DialogResult dialogResult = MessageBox.Show(dialog, "Remove Project", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    SqlConnection connection = new SqlConnection(connString);
                    connection.Open();
                    string     query1 = string.Format("SELECT Id FROM Project WHERE Title = '{0}'", ProjectGroups.Rows[e.RowIndex].Cells[1].Value);
                    SqlCommand cmd    = new SqlCommand(query1, connection);
                    int        id     = (Int32)cmd.ExecuteScalar();
                    string     query  = string.Format("DELETE FROM GroupProject WHERE GroupId = '{0}' AND ProjectId = '{1}'", ProjectGroups.Rows[e.RowIndex].Cells[0].Value, id);
                    cmd.CommandText = query;
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("Project Removed!");
                    ProjectGroups.Rows.RemoveAt(e.RowIndex);
                    connection.Close();
                }
                else
                {
                    MessageBox.Show("Project not Removed!");
                }
            }
            else if (e.ColumnIndex == ProjectGroups.Columns["GroupEditButton"].Index)
            {
                string Groupid            = ProjectGroups.Rows[e.RowIndex].Cells[0].Value.ToString();
                string projectid          = ProjectGroups.Rows[e.RowIndex].Cells[1].Value.ToString();
                AssignProjectToGroup form = new AssignProjectToGroup(Groupid, projectid, "edit");
                form.Show();
                this.Close();
            }
        }