Ejemplo n.º 1
0
        public static TimeBinding CreateTimeBinding(int id, int stepId, Step step, DateTime time, int day, int month, int year)
        {
            var set = DAL.SqlRepository.DBContext.GetDbSet<TimeBinding>();
            var tb = new TimeBinding();

            tb.Id = id;
            tb.StepId = stepId;
            tb.Step = step;
            tb.Time = time;
            tb.Day = day;
            tb.Month = month;
            tb.Year = year;

            set.Add(tb);
            DAL.SqlRepository.Save();
            return tb;
        }
Ejemplo n.º 2
0
 public Step(Step toCopy)
 {
     Order = toCopy.Order;
     ParentTask = toCopy.ParentTask;
     TaskId = toCopy.TaskId;
     Description = toCopy.Description;
     TimeRule = toCopy.TimeRule;
     TimeRuleId = toCopy.TimeRuleId;
     CriteriaId = toCopy.CriteriaId;
     Criteria = toCopy.Criteria;
     Importance = toCopy.Importance;
     ImportanceName = toCopy.ImportanceName;
     Urgency = toCopy.Urgency;
     UrgencyName = toCopy.UrgencyName;
     Id = toCopy.Id;
     EndDate = toCopy.EndDate;
     BeginDate = toCopy.BeginDate;
 }
 private void EditStep(object sender, RoutedEventArgs e)
 {
     int id = Convert.ToInt32((sender as Button).Name.Substring(1));
     var targetStep = new Step(BL.ChangesBuffer.CurrentState.StepBuffer.First(step => step.Id == id));
     Adding.Visibility = Visibility.Visible;
     Adding.IsEnabled = true;
     InAnimation();
     Labl.Content = "Редактирование";
     Chos.Visibility = Visibility.Collapsed;
     DescBox.Text = targetStep.Description;
     Begin.SelectedDate = targetStep.BeginDate;
     End.SelectedDate = targetStep.EndDate;
     Periodic.IsChecked = targetStep.TimeRule.IsPeriodic;
     Graphs.SelectedItem = targetStep.TimeRule.IsPeriodic
                               ? Graphs.Items.Cast<ComboBoxItem>()
                                       .First(
                                           i => i.Content.ToString() == targetStep.TimeRule.ScheduleId.ToString())
                               : null;
     Imp.SelectedItem =
         Imp.Items.Cast<ComboBoxItem>().First(item => item.Content.ToString() == targetStep.ImportanceName);
     Urg.SelectedItem =
         Urg.Items.Cast<ComboBoxItem>().First(item => item.Content.ToString() == targetStep.UrgencyName);
     TargetVal.Text = targetStep.Criteria.TargetValue.ToString();
     UnitBox.Text = targetStep.Criteria.Unit;
     DescBox.Name = "S" + targetStep.Id.ToString();
     UnitBox.Name = "C" + targetStep.CriteriaId.ToString();
     OkButton.Click -= Add_Click;
     _addFlag = true;
     OkButton.Click += ApplyStep;
 }
 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 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);
        }
Ejemplo n.º 7
0
 protected bool Equals(Step other)
 {
     return Id == other.Id && BeginDate.Equals(other.BeginDate) && EndDate.Equals(other.EndDate) &&
            string.Equals(UrgencyName, other.UrgencyName) && Equals(Urgency, other.Urgency) &&
            string.Equals(ImportanceName, other.ImportanceName) && Equals(Importance, other.Importance) &&
            CriteriaId == other.CriteriaId && Equals(Criteria, other.Criteria) && TimeRuleId == other.TimeRuleId &&
            Equals(TimeRule, other.TimeRule) && string.Equals(Description, other.Description) &&
            TaskId == other.TaskId && Equals(ParentTask, other.ParentTask) && Order == other.Order;
 }
Ejemplo n.º 8
0
 public int CompareTo(Step st)
 {
     return Order.CompareTo(st.Order);
 }
Ejemplo n.º 9
0
 public static void DeleteStep(Step step)
 {
     var set = DAL.SqlRepository.Steps;
     var toDelete = set.Find(step.Id);
     if (toDelete == null) return;
     set.Remove(toDelete);
     DAL.SqlRepository.DBContext.SaveChanges();
 }
Ejemplo n.º 10
0
        //private static User[] users;
        //private static Urgency[] urgencies;
        //private static Importance[] importancies;
        //private static Interval[] intervals;
        //private static Criteria[] criterias;
        //private static Models.Schedule[] schedules;
        //private static TimeRule[] timeRules;
        //private static TimeBinding[] timeBindings;
        //private static Models.Task[] tasks;
        //private static Step[] steps;
        //private static Tree[] trees;
        //PLEASE DO NOT CALL THIS METHOD IT IS TOTALLY BAD.
        public static void Seed()
        {
            var user = User.CreateUser("xxxrassiyavperedxxx", "A.Pistoletov", new DateTime(1985, 3, 22), "secret_pass", DateTime.Now);
            //var user = (User)DAL.SqlRepository.Users.Find("xxxrassiyavperedxxx");
            var tree = Tree.CreateTree(user, user.Login, "new era of trees", "must work please");
               // var tree = Tree.FindTreesForUser(user).First();

            var importancies = Importance.GetViableImportanceLevels();
            var urgencies = Urgency.GetViableUrgencyLevels();
            var criterias = new Criteria[] {
                Criteria.CreateCriteria(0, 10, "wtuk"),
                Criteria.CreateCriteria(0, 1, "raz"),
                Criteria.CreateCriteria(0, 666, "fragov v cs")
            };
            //var criterias = DAL.SqlRepository.Criterias.Cast<Criteria>().ToList();

            var tasks = new Task[4];

            tasks[0] =  Task.CreateTask(DateTime.Now, DateTime.Now.AddDays(5), urgencies[0].UrgencyName, importancies[0].ImportanceName, importancies[0], urgencies[0], criterias[0].Id, criterias[0], "task 1", tree.MainTask, tree.MainTask.Id);
            tasks[1] = Task.CreateTask(DateTime.Now, DateTime.Now.AddDays(5), urgencies[1].UrgencyName, importancies[2].ImportanceName, importancies[2], urgencies[1], criterias[1].Id, criterias[1], "task 2", tree.MainTask, tree.MainTask.Id);
            tasks[2] = Task.CreateTask(DateTime.Now, DateTime.Now.AddDays(5), urgencies[2].UrgencyName, importancies[1].ImportanceName, importancies[1], urgencies[2], criterias[2].Id, criterias[2], "task 3", tasks[0], tasks[0].Id);
            tasks[3] = Task.CreateTask(DateTime.Now, DateTime.Now.AddDays(5), urgencies[0].UrgencyName, importancies[0].ImportanceName, importancies[0], urgencies[0], criterias[0].Id, criterias[0], "task 4", tasks[1], tasks[1].Id);

            var intervals = new Interval[] {
                Interval.CreateInterval(DateTime.Now, DateTime.Now.AddHours(3)),
                Interval.CreateInterval(DateTime.Now, DateTime.Now.AddHours(5)),
                Interval.CreateInterval(DateTime.Now, DateTime.Now.AddHours(7)),
                Interval.CreateInterval(DateTime.Now, DateTime.Now.AddHours(13)),
                Interval.CreateInterval(DateTime.Now, DateTime.Now.AddHours(22)),
                Interval.CreateInterval(DateTime.Now, DateTime.Now.AddHours(50))
            };

            var schedules = new Models.Schedule[] {
                Models.Schedule.CreateSchedule(intervals[0],intervals[1],intervals[2],intervals[3],intervals[4],intervals[5],intervals[0], "first"),
                Models.Schedule.CreateSchedule(intervals[1],intervals[2],intervals[3],intervals[4],intervals[5],intervals[0],intervals[1], "second"),
                Models.Schedule.CreateSchedule(intervals[2],intervals[3],intervals[4],intervals[5],intervals[0],intervals[1],intervals[0], "third")

            };

            var timeRules = new TimeRule[] {
                TimeRule.CreateTimeRule(false, schedules[0].Id, schedules[0]),
                TimeRule.CreateTimeRule(true, schedules[1].Id, schedules[1]),
                TimeRule.CreateTimeRule(false, schedules[2].Id, schedules[2]),
                TimeRule.CreateTimeRule(true, schedules[0].Id, schedules[0]),
            };

            var steps = new Step[] {
                Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[0].UrgencyName, urgencies[0], importancies[0].ImportanceName, importancies[0], criterias[2].Id, criterias[2], timeRules[1].Id, timeRules[0], "step 1", tasks[2], tasks[2].Id, 0),
                Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[1].UrgencyName, urgencies[1], importancies[1].ImportanceName, importancies[1], criterias[1].Id, criterias[1], timeRules[2].Id, timeRules[0], "step 1", tasks[2], tasks[2].Id, 1),
                Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[2].UrgencyName, urgencies[2], importancies[2].ImportanceName, importancies[2], criterias[0].Id, criterias[0], timeRules[3].Id, timeRules[0], "step 1", tasks[2], tasks[2].Id, 2),
                Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[1].UrgencyName, urgencies[1], importancies[0].ImportanceName, importancies[0], criterias[1].Id, criterias[1], timeRules[0].Id, timeRules[0], "step 1", tasks[2], tasks[2].Id, 3),
                Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[2].UrgencyName, urgencies[2], importancies[2].ImportanceName, importancies[2], criterias[2].Id, criterias[2], timeRules[1].Id, timeRules[0], "step 1", tasks[2], tasks[2].Id, 4),
                Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[1].UrgencyName, urgencies[1], importancies[1].ImportanceName, importancies[1], criterias[0].Id, criterias[0], timeRules[2].Id, timeRules[0], "step 1", tasks[2], tasks[2].Id, 5),
                Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[2].UrgencyName, urgencies[2], importancies[0].ImportanceName, importancies[0], criterias[0].Id, criterias[0], timeRules[3].Id, timeRules[0], "step 1", tasks[2], tasks[2].Id, 6),
                Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[0].UrgencyName, urgencies[0], importancies[1].ImportanceName, importancies[1], criterias[0].Id, criterias[0], timeRules[0].Id, timeRules[0], "step 1", tasks[2], tasks[2].Id, 7),
                Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[1].UrgencyName, urgencies[1], importancies[2].ImportanceName, importancies[2], criterias[2].Id, criterias[2], timeRules[1].Id, timeRules[0], "step 1", tasks[3], tasks[3].Id, 0),
                Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[0].UrgencyName, urgencies[0], importancies[0].ImportanceName, importancies[0], criterias[0].Id, criterias[0], timeRules[2].Id, timeRules[0], "step 1", tasks[3], tasks[3].Id, 1),
                Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[2].UrgencyName, urgencies[2], importancies[2].ImportanceName, importancies[2], criterias[1].Id, criterias[1], timeRules[3].Id, timeRules[0], "step 1", tasks[3], tasks[3].Id, 2),
                Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[0].UrgencyName, urgencies[0], importancies[1].ImportanceName, importancies[1], criterias[0].Id, criterias[0], timeRules[0].Id, timeRules[0], "step 1", tasks[3], tasks[3].Id, 3),
                Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[2].UrgencyName, urgencies[2], importancies[0].ImportanceName, importancies[0], criterias[0].Id, criterias[0], timeRules[1].Id, timeRules[0], "step 1", tasks[3], tasks[3].Id, 4),
                Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[1].UrgencyName, urgencies[1], importancies[1].ImportanceName, importancies[1], criterias[2].Id, criterias[2], timeRules[2].Id, timeRules[0], "step 1", tasks[3], tasks[3].Id, 5),
                Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[0].UrgencyName, urgencies[0], importancies[2].ImportanceName, importancies[2], criterias[0].Id, criterias[0], timeRules[3].Id, timeRules[0], "step 1", tasks[3], tasks[3].Id, 6),
                Step.CreateStep(DateTime.Now, DateTime.Now.AddDays(30), urgencies[1].UrgencyName, urgencies[1], importancies[0].ImportanceName, importancies[0], criterias[0].Id, criterias[0], timeRules[0].Id, timeRules[0], "step 1", tasks[3], tasks[3].Id, 7)
            };
        }