private async void MainPage_Loaded(object sender, RoutedEventArgs e) { if (FocusCount == 0) { SaveAndLoad DataSaverLoader = new SaveAndLoad(); await DataSaverLoader.CreateAppLocalData(); AllData = await DataSaverLoader.LoadData(); foreach (CardObj Card in AllData.AllCardData) { MyUserControl1 control = new MyUserControl1(500, 300, Card); control.Width = 600; control.Height = 400; control.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left; control.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Top; control.disableEditing(); MainPage.AllCards.Add(control); } this.cardCarousel.setup(); } FocusCount++; }
public async void SaveDataOfCard() { SaveAndLoad DataSaverLoader = new SaveAndLoad(); CardObj DataToBeSaved = new CardObj(); StackPanel Tmp_SP = new StackPanel(); TextBox Tmp_TX = new TextBox(); //First time loop through to delete and correct empty entries foreach (UIElement IngredientEntry in this.recipePanel.Children) { if (IngredientEntry.GetType() == Tmp_SP.GetType()) { StackPanel ThisEntry = (StackPanel)IngredientEntry; //this entry could be empty NumberSelector NS = (NumberSelector)ThisEntry.Children[0]; UnitSelector US = (UnitSelector)ThisEntry.Children[1]; TextBox TX = (TextBox)ThisEntry.Children[2]; //non empty entry if (NS.getSelectedValue() != "" && TX.Text.ToString() != "Drag and drop ingredient here") { TextBox FinalEntryBox = new TextBox(); FinalEntryBox.Text = NS.getSelectedValue() + " " + US.getSelectedValue() + " " + TX.Text; /******INSERT TAG******/ DataToBeSaved.TagsList.Add(TX.Text); /******INSERT TAG******/ FinalEntryBox.Width = width; ThisEntry.Children.Clear(); StackPanel Card = (StackPanel)ThisEntry.Parent; int index = Card.Children.IndexOf(ThisEntry); Card.Children.Remove(ThisEntry); Card.Children.Insert(index, FinalEntryBox); } //empty entry else { ThisEntry.Children.Clear(); StackPanel Card = (StackPanel)ThisEntry.Parent; Card.Children.Remove(ThisEntry); } } } //All entries should be textboxes now disableEditing(); for (int i = 0; i < this.recipePanel.Children.Count; i++) { TextBox ThisEntry = (TextBox)this.recipePanel.Children[i]; DataToBeSaved.IngredientList.Add(ThisEntry.Text.ToString()); if (i == 0) //first entry is title add to tags { DataToBeSaved.TagsList.Add(ThisEntry.Text.ToString()); DataToBeSaved.CardTitle = ThisEntry.Text.ToString(); } } for (int i = 0; i < this.reversePanel.Children.Count; i++) { TextBox ThisEntry; if (this.reversePanel.Children[i].GetType() == Tmp_TX.GetType()) { ThisEntry = (TextBox)this.reversePanel.Children[i]; DataToBeSaved.InstructionList.Add(ThisEntry.Text.ToString()); if (i == 0) //first entry is title add to tags DataToBeSaved.TagsList.Add(ThisEntry.Text.ToString()); } } LocalAppData AllCardsCollection = await DataSaverLoader.LoadData(); int ReplaceIndex = -1; for (int i = 0; i < AllCardsCollection.AllCardData.Count; i++) { if (DataToBeSaved.CardTitle == AllCardsCollection.AllCardData[i].CardTitle) { ReplaceIndex = i; break; } } if (ReplaceIndex != -1) //Replace { AllCardsCollection.AllCardData[ReplaceIndex] = DataToBeSaved; } else { AllCardsCollection.AddCard(DataToBeSaved); } //Create File name //string CardFileName = "CardFile" + CurrentCardCount.ToString(); await DataSaverLoader.SaveData(AllCardsCollection); }