private void RemoveStep(object sender, RoutedEventArgs e) { int id = Convert.ToInt32((sender as Button).Name.Substring(1)); var step = BL.ChangesBuffer.CurrentState.StepBuffer.First(st => st.Id == id); var buff = new BL.Buffer(BL.ChangesBuffer.CurrentState); buff.StepBuffer.Remove(step); BL.ChangesBuffer.CaptureChanges(buff); var task = BL.ChangesBuffer.CurrentState.TaskBuffer.First(t => t.Description == _parent.Desc.Text); UpdateTree(task,MoveDirections.None); }
private void ChangeCurrentValueOfStep(object sender, RoutedEventArgs e) { int id = Convert.ToInt32((sender as Button).Name.Substring(1)); var step = BL.ChangesBuffer.CurrentState.StepBuffer.First(s => s.Id == id); var crit = BL.ChangesBuffer.CurrentState.CriteriaBuffer.First(c => step.CriteriaId == c.Id); var newStep = new Step(step); var newCrit = new Criteria(crit); newCrit.CurrentValue = Convert.ToInt32((_stepChanger.Children[1] as TextBox).Text); var buff = new BL.Buffer(BL.ChangesBuffer.CurrentState); buff.CriteriaBuffer.Remove(crit); buff.CriteriaBuffer.Add(newCrit); newStep.Criteria = newCrit; buff.StepBuffer.Remove(step); buff.StepBuffer.Add(newStep); BL.ChangesBuffer.CaptureChanges(buff); UpdateTree(BL.ChangesBuffer.CurrentState.TaskBuffer.First(t=>t.Description==_parent.Desc.Text),MoveDirections.None); }
private void ApplyEditing(object sender, RoutedEventArgs e) { var buff = new BL.Buffer(BL.ChangesBuffer.CurrentState); var tas = buff.TaskBuffer.First(task => task.Description == _parent.Desc.Text); var targetTask = new Task(tas); targetTask.Description = DescBox.Text; targetTask.ImportanceName = (Imp.SelectedItem as ComboBoxItem).Content.ToString(); targetTask.Importance = DAL.SqlRepository.Importancies.Cast<Importance>() .First(imp => imp.ImportanceName == targetTask.ImportanceName); targetTask.UrgencyName = (Urg.SelectedItem as ComboBoxItem).Content.ToString(); targetTask.UpdateUrgency(); OkButton.Click -= ApplyEditing; targetTask.BeginDate = Begin.SelectedDate != null ? (DateTime)Begin.SelectedDate : DateTime.MinValue; targetTask.EndDate = End.SelectedDate != null ? (DateTime)End.SelectedDate : DateTime.MaxValue; buff.TaskBuffer.Remove(tas); buff.TaskBuffer.Add(targetTask); foreach (var step in buff.StepBuffer) { if (step.TaskId == tas.Id) step.ParentTask = targetTask; } BL.ChangesBuffer.CaptureChanges(buff); UpdateTree(targetTask,MoveDirections.None); UpdateRawView(); Discard_Click(sender, e); }
private void ApplyStep(object sender, RoutedEventArgs e) { var buff = new BL.Buffer(BL.ChangesBuffer.CurrentState); int id = Convert.ToInt32(DescBox.Name.Substring(1)); var step = BL.ChangesBuffer.CurrentState.StepBuffer.First(s => s.Id == id); var newStep = new Step(step); var crit = BL.ChangesBuffer.CurrentState.CriteriaBuffer.First( c => c.Id == Convert.ToInt32(UnitBox.Name.Substring(1))); var newCrit = new Criteria(crit); buff.CriteriaBuffer.Remove(crit); buff.CriteriaBuffer.Add(newCrit); buff.StepBuffer.Remove(step); newStep.Criteria = newCrit; newStep.Description = DescBox.Text; var tr = BL.ChangesBuffer.CurrentState.TimeRuleBuffer.First(t => t.Id == step.TimeRuleId); var newtr = new TimeRule(tr); if (Periodic.IsChecked.HasValue && Periodic.IsChecked.Value) { newtr.IsPeriodic = true; newtr.Schedule = DAL.SqlRepository.Schedules.Cast<Models.Schedule>().ToList() .First(sc => sc.Id == Convert.ToInt32((Graphs.SelectedItem as ComboBoxItem).Content.ToString())); newtr.ScheduleId = newtr.Schedule.Id; } else { newtr.IsPeriodic = false; } buff.TimeRuleBuffer.Remove(tr); buff.TimeRuleBuffer.Add(newtr); newStep.TimeRule = newtr; buff.StepBuffer.Add(newStep); BL.ChangesBuffer.CaptureChanges(buff); UpdateTree(BL.ChangesBuffer.CurrentState.TaskBuffer.First(task=>task.Description==_parent.Desc.Text),MoveDirections.None); OkButton.Click -= ApplyStep; Discard_Click(sender, e); }
private void Add_Click(object sender, RoutedEventArgs e) { if ( BL.ChangesBuffer.CurrentState.TaskBuffer.Any( entity => Task.GetOldestParent(entity).Id == BL.Application.CurrentTree.MainTaskId && entity.Description == DescBox.Text)) { MessageBox.Show("Такая цель уже есть в этом дереве!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (DescBox.Text.Length < 3) { MessageBox.Show("Слишком короткое описание!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); return; } var imp = DAL.SqlRepository.Importancies.Cast<Importance>() .First(x => ((ComboBoxItem)Imp.SelectedItem).Content.ToString() == x.ImportanceName); var buff = new BL.Buffer(BL.ChangesBuffer.CurrentState); if (StepButton.IsChecked == true) { var tr = new TimeRule { IsPeriodic = Periodic.IsChecked == true, Schedule = DAL.SqlRepository.Schedules.Cast<Models.Schedule>().ToList() .First(x => Periodic.IsChecked != true || x.Id == Convert.ToInt32(((ComboBoxItem)Graphs.SelectedItem).Content.ToString())), }; tr.ScheduleId = tr.Schedule.Id; var t = BL.ChangesBuffer.CurrentState.TaskBuffer.First(x => x.Description == _parent.Desc.Text); if ( BL.ChangesBuffer.CurrentState.StepBuffer .Any(x => x.TaskId == t.Id && x.Description == DescBox.Text)) { MessageBox.Show("Такой шаг у цели уже есть!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } var crit = new Criteria { CurrentValue = 0, TargetValue = Convert.ToInt32(TargetVal.Text), Unit = UnitBox.Text }; var st = new Step { BeginDate = Begin.SelectedDate != null ? (DateTime) Begin.SelectedDate : DateTime.Now, EndDate = End.SelectedDate != null ? (DateTime) End.SelectedDate : Interval.PIOS, Criteria = crit, CriteriaId = crit.Id, Description = DescBox.Text, Importance = imp, ImportanceName = imp.ImportanceName, TimeRule = tr, TimeRuleId = tr.Id, ParentTask = t, TaskId = t.Id }; st.UpdateUrgency(); buff.StepBuffer.Add(st); BL.ChangesBuffer.CaptureChanges(buff); UpdateTree(t,MoveDirections.None); } else { var crit = new Criteria { CurrentValue = 0, TargetValue = 1, Unit = "default" }; var p = BL.ChangesBuffer.CurrentState.TaskBuffer.First(x => x.Description == _parent.Desc.Text); var t = new Task { BeginDate = Begin.SelectedDate != null ? (DateTime)Begin.SelectedDate : DateTime.Now, EndDate = End.SelectedDate != null ? (DateTime)End.SelectedDate : Interval.PIOS, Criteria = crit, CriteriaId = crit.Id, Description = DescBox.Text, Importance = imp, ImportanceName = imp.ImportanceName, Parent = p, ParentId = p.Id, Id = BL.ChangesBuffer.CurrentState.TaskBuffer.Max(taskk=>taskk.Id) + 1 }; t.UpdateUrgency(); buff.TaskBuffer.Add(t); BL.ChangesBuffer.CaptureChanges(buff); UpdateTree(p,MoveDirections.None); } UpdateRawView(); Discard_Click(sender,e); }