Ejemplo n.º 1
0
        // ButtonClicked Handler for the buttons: Browse, Delete and Create/Edit
        private void ButtonClick(object sender, RoutedEventArgs e)
        {
            string ButtonName = (sender as Button).Name;

            // Open File Explorer so the user can browse after the png file the user needs.
            if (ButtonName == "Browse")
            {
                OpenFileDialog OpenFileDialog = new OpenFileDialog();
                OpenFileDialog.Filter = ".Image files (*.png)|*.png|All files (*.*)|*.*";

                if (OpenFileDialog.ShowDialog() == true)
                {
                    string ChosenFileExt    = System.IO.Path.GetExtension(OpenFileDialog.FileName);
                    string ReferenceFileExt = ".png";

                    if (ChosenFileExt == ReferenceFileExt)
                    {
                        string          Filename        = OpenFileDialog.FileName;
                        string          Filepath        = OpenFileDialog.FileName;
                        FileInformation FileNameDisplay = new FileInformation(Filename, Filepath);
                        UrlBox.Items.Add(FileNameDisplay);
                    }

                    else
                    {
                        MessageBoxResult Result = MessageBox.Show("You must choose .png as input file!", "Error!",
                                                                  MessageBoxButton.OK,
                                                                  MessageBoxImage.Question);
                    }
                }
            }

            // Create a project if all fields have been filled
            if (ButtonName == "Create")
            {
                if (!UrlBox.HasItems)
                {
                    MessageBoxResult Result = MessageBox.Show("You need to upload files in order to create a project!", "Error!",
                                                              MessageBoxButton.OK,
                                                              MessageBoxImage.Question);
                }
                else if (ProjectTitle.Text.Length == 0)
                {
                    MessageBoxResult Result = MessageBox.Show("You need to name the project!", "Error!",
                                                              MessageBoxButton.OK,
                                                              MessageBoxImage.Question);
                }
                else if (ProjectDescription.Text.Length == 0)
                {
                    MessageBoxResult Result = MessageBox.Show("You need to write a discription for your project!", "Error!",
                                                              MessageBoxButton.OK,
                                                              MessageBoxImage.Question);
                }
                else
                {
                    string ProgramRootFolder = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                    string FolderPath        = ProgramRootFolder + "/Projects/" + ProjectTitle.Text;

                    if (!Directory.Exists(FolderPath))
                    {
                        var NewProject = new Project(ProjectTitle.Text, ProjectDescription.Text);
                        foreach (FileInformation item in UrlBox.Items)
                        {
                            NewProject.FilesInProject.Add(item);
                        }
                        NewProject.CreateNewProject();
                        Home Home = new Home();
                        NavigationService.Navigate(Home);
                    }
                    else
                    {
                        MessageBoxResult Result = MessageBox.Show("That name is already taken", "Error!",
                                                                  MessageBoxButton.OK,
                                                                  MessageBoxImage.Question);
                    }
                }
            }

            if (ButtonName == "Delete")
            {
                UrlBox.Items.Remove(UrlBox.SelectedItem);
            }
            // Edits an existing project
            if (ButtonName == "Edit")
            {
                if (!UrlBox.HasItems)
                {
                    MessageBoxResult Result = MessageBox.Show("You need to upload files in order to create a project", "Error!",
                                                              MessageBoxButton.OK,
                                                              MessageBoxImage.Question);
                }
                else if (ProjectTitle.Text.Length == 0)
                {
                    MessageBoxResult Result = MessageBox.Show("Project name must be filled out", "Error!",
                                                              MessageBoxButton.OK,
                                                              MessageBoxImage.Question);
                }
                else if (ProjectDescription.Text.Length == 0)
                {
                    MessageBoxResult Result = MessageBox.Show("Project description must be filled out", "Error!",
                                                              MessageBoxButton.OK,
                                                              MessageBoxImage.Question);
                }
                else
                {
                    //Makes a temporary folder with the project which wis going to be moved later
                    var NewProject = new Project("tmpFolder", ProjectDescription.Text);
                    foreach (FileInformation item in UrlBox.Items)
                    {
                        NewProject.FilesInProject.Add(item);
                    }
                    NewProject.CreateNewProject();

                    //if the project title is changed then move the temporary folder to the new name location
                    if (Project.Title != ProjectTitle.Text)
                    {
                        string ProgramRootFolder = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                        string NewfolderPath     = ProgramRootFolder + "/Projects/" + ProjectTitle.Text;
                        string TmpFolderPath     = ProgramRootFolder + "/Projects/" + NewProject.Title;
                        Directory.Move(TmpFolderPath, NewfolderPath);
                    }

                    /* if the project title has not changed, then delete the older project folder
                     * and move the temporary folder to the older project folders location
                     */
                    else
                    {
                        if (Directory.Exists(Project.FilePath))
                        {
                            Directory.Delete(Project.FilePath, true);
                        }
                        string ProgramRootFolder = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                        string NewfolderPath     = ProgramRootFolder + "/Projects/" + ProjectTitle.Text;
                        string TmpFolderPath     = ProgramRootFolder + "/Projects/" + NewProject.Title;
                        Directory.Move(TmpFolderPath, NewfolderPath);
                    }

                    Home Home = new Home();
                    NavigationService.Navigate(Home);
                }
            }
        }
Ejemplo n.º 2
0
        // Handler for the home Button
        private void HomeClick(object sender, RoutedEventArgs e)
        {
            Home Home = new Home();

            NavigationService.Navigate(Home);
        }