Ejemplo n.º 1
0
        private void Create_Click(object sender, EventArgs e)
        {
            this.Hide();
            InsertProject create = new InsertProject();

            create.ShowDialog();
            this.Close();
        }
Ejemplo n.º 2
0
        private void ProjectData_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            ProjectData.Rows[e.RowIndex].ReadOnly = true;

            int noOfRows = ProjectData.RowCount;

            if (e.ColumnIndex == 3 && e.RowIndex >= 0 && e.RowIndex != (noOfRows - 1))
            {
                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 Project WHERE Id = @Id";

                        SqlCommand c = new SqlCommand(cmdText, con);


                        int Idy = Convert.ToInt32(ProjectData.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");
                        }

                        // connection closed
                        con.Close();
                        // update the grid after deletion
                        ProjectData.DataSource = null;
                        ProjectData.Rows.Clear();
                        ProjectData.Columns.Clear();
                        update();

                        // show dialog box if added in table of database

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

                    {
                        MessageBox.Show("Project might be assigned to group or any advisor assign to this project. So first delete from assignment record then delete it here.");
                    }
                }
                else if (dialogResult == DialogResult.No)
                {
                    //do something else
                }
            }

            if (e.ColumnIndex == 4 && e.RowIndex >= 0 && e.RowIndex != (noOfRows - 1))
            {
                id = Convert.ToInt32(ProjectData.Rows[e.RowIndex].Cells[0].Value);
                this.Hide();
                InsertProject create = new InsertProject();
                create.ShowDialog();
                this.Close();
            }
            else
            {
            }
        }