private void mnuUserExercise_Click(object sender, RoutedEventArgs e) { var item = (StrengthTrainingItemViewModel)(sender as FrameworkElement).DataContext; List <StrengthTrainingItemDTO> itemsToCopy = new List <StrengthTrainingItemDTO>(); if (Settings.TreatSuperSetsAsOne && !string.IsNullOrEmpty(item.Item.SuperSetGroup)) {//if we should treat superset as one then when we copy one exercise which is a part of superset then we should copy all of them itemsToCopy.AddRange(item.Item.StrengthTrainingEntry.Entries.Where(x => x.SuperSetGroup == item.Item.SuperSetGroup).OrderBy(x => x.Position)); } else { itemsToCopy.Add(item.Item); } foreach (var itemDto in itemsToCopy) { var newItem = itemDto.Copy(true); TrainingBuilder builder = new TrainingBuilder(); builder.PrepareCopiedStrengthTraining(newItem, Settings.CopyStrengthTrainingMode); builder.SetPreviewSets(itemDto, newItem); Entry.AddEntry(newItem); } //_viewModel.AddExercise(item.Item.Exercise); lblNoExercises.Visibility = Entry.Entries.Count == 0? System.Windows.Visibility.Visible: System.Windows.Visibility.Collapsed; StrengthWorkoutViewModel.ResetPositions(Entry); show(true); pivot.SelectedIndex = 0; }
public StrengthTrainingEntryDTO GetStrengthTrainingEntry() { Entry.Entries.Clear(); for (int index = 0; index < Items.Count; index++) { var itemViewModel = Items[index]; if (!itemViewModel.IsNew) { var item = itemViewModel.GetStrengthTrainingItem(); item.Position = index; Entry.AddEntry(item); } } return(Entry); }
private void btnADDEntry_Click(object sender, EventArgs e) { folder = new ClassFolder(); if (txtEntry.Text == "" || txtDes.Text == "") { MessageBox.Show("Please complete all the fields required to register."); } else { if (File.Exists(folder.getEntry() + txtEntry.Text + ".xml")) { MessageBox.Show("This Entry is already registered. Please try again."); } else { XmlSerializer serializer2 = new XmlSerializer(typeof(UserConcrete)); Stream stream2 = File.Open(folder.getUser() + getname + ".xml", FileMode.Open); UserConcrete user = (UserConcrete)serializer2.Deserialize(stream2); Entry entry = new Entry(); /* * entry.entry = txtEntry.Text; * entry.description = txtDes.Text; * * entry.entryuser = getname; * */ entry.AddEntry(txtEntry.Text, txtDes.Text, txtEntry.Text); if (!user.status) { Stream stream = File.Create(folder.getEntry() + entry.entry + ".xml"); /* * XmlSerializer serialize = new XmlSerializer(typeof(Entry)); * serialize.Serialize(stream, entry); * stream.Close();*/ entry.Serialize(stream, entry); foreach (ListViewItem item in lviEntry.Items) { item.SubItems[0].Text = txtEntry.Text; item.SubItems[1].Text = txtDes.Text; } userstatus = "true"; XmlDocument xmlDoc = new XmlDocument(); stream2.Position = 0; xmlDoc.Load(stream2); XmlNode node = xmlDoc.SelectSingleNode("/UserConcrete/status") as XmlElement; if (node != null) { node.InnerText = userstatus; } stream2.Position = 0; stream2.SetLength(0); xmlDoc.Save(stream2); stream2.Close(); lviEntry.Items.Clear(); this.get(); } else { MessageBox.Show("Entry should be 1"); } stream2.Close(); } } }