private void btnCancel_Click(object sender, EventArgs e)
        {
            ProjectDashboard projectDashboard = ProjectDashboard.GetInstance();

            projectDashboard.Show();
            this.Hide();
        }
        private void btnAddProject_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtTitle.Text))
            {
                lblTitleWarning.Visible = true;
            }
            else if (string.IsNullOrWhiteSpace(txtDescription.Text))
            {
                lblDescriptionWarning.Visible = true;
            }
            else
            {
                DatabaseConnection.createStatement("INSERT INTO Project ( Title, Description)" +
                                                   " VALUES('" + txtTitle.Text + "' , '" + txtDescription.Text + "') ");
                DatabaseConnection.performAction();
                Project project = new Project();
                project.Title = txtTitle.Text;

                DatabaseConnection.createStatement("Select @@identity as id from Project");
                SqlDataReader reader = DatabaseConnection.getData();
                while (reader.Read())
                {
                    project.Id = int.Parse(reader["id"].ToString());
                }
                TempData.CurrentProject = project;
                ProjectDashboard dashboard = ProjectDashboard.GetInstance();
                dashboard.Show();
                this.Hide();
            }
        }
 private void gvStudents_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
 {
     if (gvStudents.Columns[e.ColumnIndex].Name.ToString() == "Action")
     {
         Project project = new Project();
         project.Title = gvStudents.Rows[e.RowIndex].Cells[1].Value.ToString();
         DatabaseConnection.createStatement("select Description from Project where Id = " + gvStudents.Rows[e.RowIndex].Cells[0].Value.ToString());
         SqlDataReader newReader = DatabaseConnection.getData();
         if (newReader.Read())
         {
             project.Description = newReader["Description"].ToString();
         }
         project.Id = int.Parse(gvStudents.Rows[e.RowIndex].Cells[0].Value.ToString());
         TempData.CurrentProject = project;
         ProjectDashboard projectDashboard = ProjectDashboard.GetInstance();
         projectDashboard.Show();
         this.Hide();
     }
     if (gvStudents.Columns[e.ColumnIndex].Name.ToString() == "Action3")
     {
         if (MessageBox.Show("Are you sure you want to delete?", "Delete Confirmation", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             string id = gvStudents.Rows[e.RowIndex].Cells[0].Value.ToString();
             DatabaseConnection.start();
             DatabaseConnection.createStatement("Delete from ProjectAdvisor where ProjectId =" + id);
             DatabaseConnection.performAction();
             DatabaseConnection.createStatement("Delete from GroupProject where ProjectId =" + id);
             DatabaseConnection.performAction();
             DatabaseConnection.createStatement("Delete from Project where Id =" + id);
             DatabaseConnection.performAction();
         }
     }
 }
        private void gvStudents_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (gvStudents.Columns[e.ColumnIndex].Name.ToString() == "Assign")
            {
                bool IsAlready = false;
                DatabaseConnection.createStatement("select ProjectId from GroupProject where GroupId = " + gvStudents.Rows[e.RowIndex].Cells[0].Value.ToString());
                SqlDataReader newReader = DatabaseConnection.getData();
                if (newReader.Read())
                {
                    IsAlready = true;
                }
                if (IsAlready)
                {
                    MessageBox.Show("This group is already assigned");
                }
                else
                {
                    string sqlFormattedDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    DatabaseConnection.start();
                    DatabaseConnection.createStatement("Insert into GroupProject (ProjectId, GroupId, AssignmentDate)" +
                                                       " Values (" + TempData.CurrentProject.Id + ", " + gvStudents.Rows[e.RowIndex].Cells[0].Value.ToString() + ", '" +
                                                       sqlFormattedDate + "')");
                    DatabaseConnection.performAction();

                    DatabaseConnection.createStatement("Update GroupStudent set Status = 4 where GroupId = " + gvStudents.Rows[e.RowIndex].Cells[0].Value.ToString());
                    DatabaseConnection.performAction();

                    ProjectDashboard projectDashboard = ProjectDashboard.GetInstance();
                    projectDashboard.Show();
                    this.Hide();
                }
            }
        }
Exemplo n.º 5
0
 public static ProjectDashboard GetInstance()
 {
     if (Instance == null)
     {
         ProjectDashboard new_Instance = new ProjectDashboard();
         return(new_Instance);
     }
     return(Instance);
 }
        private void lblAdd_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(cmbSelctAdvisor.Text))
            {
                lblWarning.Visible = true;
            }
            else
            {
                string[] names = cmbSelctAdvisor.Text.Split(new char[] { ' ' });

                DatabaseConnection.createStatement("select Advisor.Id[id] from Person join Advisor on Advisor.Id = Person.Id where FirstName = '" + names[0] + "'" +
                                                   " and LastName = '" + names[1] + "'");
                SqlDataReader reader  = DatabaseConnection.getData();
                Advisor       advisor = new Advisor();
                if (reader.Read())
                {
                    int x = advisor.AdvisorId1 = int.Parse(reader["id"].ToString());
                    MessageBox.Show(x.ToString());
                    TempData.CurrentAdvisor = advisor;
                }
                MessageBox.Show(TempData.CurrentAdvisor.AdvisorId1.ToString());
                string sqlFormattedDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                DatabaseConnection.createStatement("Insert into ProjectAdvisor (AdvisorId, ProjectId, AdvisorRole, AssignmentDate)" +
                                                   " Values (" + TempData.CurrentAdvisor.AdvisorId1.ToString() + ", " + TempData.CurrentProject.Id + "," +
                                                   TempData.CurrentRole.ToString() + ", '" + sqlFormattedDate + "') ");
                try
                {
                    DatabaseConnection.performAction();
                }
                catch
                {
                    MessageBox.Show("Advisor already assigned to the group");
                }
                ProjectDashboard projectDashboard = ProjectDashboard.GetInstance();
                projectDashboard.Show();
                this.Hide();
            }
        }