Ejemplo n.º 1
0
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            // If user has unsaved data ask them to confirm if they want to save first before closing.
            if (HasTxtChanged == true)
            {
                //Convert the Dialog so it is reusable for this instance
                AreYouSureDialog areYouSureDialog = new AreYouSureDialog();
                areYouSureDialog.Main_Label.Text            = "Would you like to save before closing?";
                areYouSureDialog.Warning_Label.Text         = "";
                areYouSureDialog.AYSD_Cancel_Button.Content = "Dont Save";
                areYouSureDialog.AYSD_Delete_Button.Content = "Save";
                areYouSureDialog.IsThisToDelete             = false;

                //Position window correctly

                areYouSureDialog.Owner = this;
                areYouSureDialog.WindowStartupLocation = WindowStartupLocation.Manual;
                areYouSureDialog.Top  = Owner.Top + 300;
                areYouSureDialog.Left = Owner.Left + 450;

                areYouSureDialog.ShowDialog();

                if (areYouSureDialog.DoesUserWantToSave == true)
                {
                    Recipe_JsonHandler.WriteToJsonFile_Tips(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Recipe Rack\\Tips\\TipsDocument.json", new TextRange(Tips_Rich_TextBox.Document.ContentStart, Tips_Rich_TextBox.Document.ContentEnd).Text.ToString());
                    HasTxtChanged = false;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This returns a List(Recipes) from the recipe.json files.
        /// </summary>
        public static List <Recipes> UpdateObjectsFromFiles()
        {
            // This method Reads the Files from the Recipe Folder
            string[]       FileNames         = System.IO.Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Recipe Rack\\Recipes");
            string         DefaultFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Recipe Rack\\Recipes";
            List <Recipes> RecipeClass_List  = new List <Recipes>();

            int i = 0;

            foreach (var item in FileNames)
            {
                FileNames[i] = FileNames[i].Remove(0, DefaultFolderPath.Length + 1);
                RecipeClass_List.Add((Recipes)Recipe_JsonHandler.ReadFromJsonFile <Recipes>(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Recipe Rack\\Recipes\\" + FileNames[i]));
                i++;
            }

            return(RecipeClass_List);
        }
        //Check if data looks okay one last time and Finalize the Output
        private void FinalizeRecipe_Button_Click(object sender, RoutedEventArgs e)
        {
            CheckIfButtonCanBePressed();

            // Check if user is attempting to save a file with a similiar name and prevent it
            List <Recipes> ListofRecipes = MainWindow.UpdateObjectsFromFiles();

            foreach (var item in ListofRecipes)
            {
                if (item.RecipeName == RecipeName_TextBox.Text && IsThisAnEdit == false)
                {
                    FinalizeRecipe_Button.IsEnabled = false;
                    InformUserOfName informUserOfName = new InformUserOfName();

                    informUserOfName.Owner = this;
                    informUserOfName.WindowStartupLocation = WindowStartupLocation.Manual;
                    informUserOfName.Top  = this.Top + 120;
                    informUserOfName.Left = this.Left + 30;

                    System.Media.SystemSounds.Hand.Play();
                    informUserOfName.ShowDialog();
                    RecipeName_TextBox.Text = "";
                }
            }



            // Check if button is still enabled
            if (FinalizeRecipe_Button.IsEnabled == true)
            {
                if (IsThisAnEdit)
                {
                    System.IO.File.Delete(OldRecipePath);
                }

                Recipes recipe = new Recipes(RecipeCategory_ComboBox.SelectedItem.ToString(), RecipeName_TextBox.Text, new TextRange(Directions_RichTextBox.Document.ContentStart, Directions_RichTextBox.Document.ContentEnd).Text.ToString(), ParseListInfo(EnterNewRecipe_IngredientListView), Int16.Parse(RecipeDifficulty_ComboBox.Text.ToString()), IsFavorite_Checkbox.IsChecked == true);
                this.Close();

                Recipe_JsonHandler.WriteToJsonFile(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Recipe Rack\\Recipes\\" + recipe.RecipeName.Trim() + ".json", recipe);
            }
        }
Ejemplo n.º 4
0
 private void Save_Close_Button_Click(object sender, RoutedEventArgs e)
 {
     Recipe_JsonHandler.WriteToJsonFile_Tips(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Recipe Rack\\Tips\\TipsDocument.json", new TextRange(Tips_Rich_TextBox.Document.ContentStart, Tips_Rich_TextBox.Document.ContentEnd).Text.ToString());
     HasTxtChanged = false;
     this.Close();
 }
Ejemplo n.º 5
0
 private void Window_Initialized(object sender, EventArgs e)
 {
     Tips_Rich_TextBox.AppendText(Recipe_JsonHandler.ReadFromJsonFile_Tips(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Recipe Rack\\Tips\\TipsDocument.json"));
 }