Пример #1
0
        // GenerateProjectPreview: creates the UI for a project
        // ------------------------------------------------------------
        // param int index: current selected index for the list box     
        // -----------------------------------------------------
        // returns: FlowLayoutPanel with lots of things or exception
        private FlowLayoutPanel GenerateProjectPreview(int index)
        {
            FlowLayoutPanel panel = new FlowLayoutPanel();
            panel.WrapContents = true;
            panel.AutoSize = true;
            panel.FlowDirection = FlowDirection.TopDown;

            // get the actual project id from the dictionary which maps the list indices to the db ids.
            int id = ProjectMap[index];
            
            Tuple<string, string, DateTime, DateTime, DateTime, bool> project = PM.GetProjectData(id);
                    
            Label projectlbl = new Label();
                    
            RichTextBox projectdsc = new RichTextBox();
                    
            Button btnOpen = new Button();
            Button btnEdit = new Button();
            Button btnDelete = new Button();
                    
            projectlbl.Text = project.Item1;
            projectlbl.Width = panel.Width;

            projectdsc.ReadOnly = true;
            projectdsc.Text = project.Item2;
            projectdsc.Width = panel.Width;
            projectdsc.BorderStyle = BorderStyle.None;

            btnOpen.Text = "View";
            btnEdit.Text = "Edit";
            btnDelete.Text = "Delete";

            FlowLayoutPanel bPanel = new FlowLayoutPanel();
            bPanel.AutoSize = true;
                    
            bPanel.FlowDirection = FlowDirection.LeftToRight;

            // open the project viewer
            btnOpen.Click += new EventHandler(delegate(object sender, EventArgs e) 
            {
                frmViewProject view = new frmViewProject(id, ref project);
                view.ShowDialog();
            });

            // open the project creator in edit mode.
            btnEdit.Click += new EventHandler(delegate(object sender, EventArgs e)
            {
                frmCreateProject editor = new frmCreateProject(PM, id, ref project);
                editor.ShowDialog();

                // update the dictionary of projects and the menu (in case the name is changed)
                project = PM.GetProject(id);
                PM.SetProjectData(id, project);
                lbSelectProject.Items[index] = project.Item1;

            });

            // delete the project
            btnDelete.Click += new EventHandler(delegate(object sender, EventArgs e)
            {
                DialogResult result = MessageBox.Show("Do you want to delete " + project.Item1, "Delete Project?", MessageBoxButtons.YesNo);

                if (result == DialogResult.Yes)
                {
                    // delete the project and remove it from the menu
                    PM.DeleteProject(id);
                    
                    // update the map
                    for (int i = index+1; i < ProjectMap.Count; i++)
                    {
                        ProjectMap[i-1] = ProjectMap[i];
                    }

                    ProjectMap.Remove(ProjectMap.Count - 1);
                    lbSelectProject.Items.RemoveAt(index);
                
                }
            });
                    
            bPanel.Controls.Add(btnOpen);
            bPanel.Controls.Add(btnEdit);
            bPanel.Controls.Add(btnDelete);

            panel.Controls.Add(projectlbl);
            panel.Controls.Add(projectdsc);
            panel.Controls.Add(bPanel);

            return panel;
        }
Пример #2
0
 private void createNewProjectToolStripMenuItem_Click(object sender, EventArgs e)
 {
     frmCreateProject creator = new frmCreateProject(PM);
     creator.ShowDialog();
     UpdateView();
 }