public ActivityInventoryViewModel()
        {
            Activities = new ObservableCollection <Activity>();

            var activityPropertyChanged     = new ObservableEventHandler <Activity, PropertyChangedEventArgs>();
            var activitiesCollectionChanged = new Utilities.ObservableEventHandler <NotifyCollectionChangedEventArgs>();

            Activities.CollectionChanged += activitiesCollectionChanged.Handler;

            activitiesCollectionChanged.Where(e => e.EventArgs.Action == NotifyCollectionChangedAction.Add)
            .SelectMany(e => e.EventArgs.NewItems.Cast <Activity>())
            .Subscribe(a => a.PropertyChanged += activityPropertyChanged.Handler);

            activitiesCollectionChanged.Where(e => e.EventArgs.Action == NotifyCollectionChangedAction.Remove)
            .SelectMany(e => e.EventArgs.OldItems.Cast <Activity>())
            .Subscribe(a => a.PropertyChanged -= activityPropertyChanged.Handler);

            activitiesCollectionChanged.Select(e => Unit.Default)
            .Merge(activityPropertyChanged.Where(e => e.EventArgs.PropertyName == "ExpectedEffort").Select(e => Unit.Default))
            .Subscribe(u => ExpectedEffortSum = Activities.Select(a => a.ExpectedEffort).Sum());

            activitiesCollectionChanged.Select(e => Unit.Default)
            .Merge(activityPropertyChanged.Where(e => e.EventArgs.PropertyName == "ActualEffort").Select(e => Unit.Default))
            .Subscribe(u => ActualEffortSum = Activities.Select(a => a.ActualEffort).Sum());

            var selectedActivitiesNotEmpty = new Func <bool>(() => !EnumerableExtensions.IsNullOrEmpty(SelectedActivities));

            DeleteActivityCommand       = new RelayCommand(() => SelectedActivities.ForEach(DeleteActivity), selectedActivitiesNotEmpty);
            ArchiveActivityCommand      = new RelayCommand(() => SelectedActivities.ForEach(ArchiveActivity), selectedActivitiesNotEmpty);
            IncreaseActualEffortCommand = new RelayCommand(() => SelectedActivities.ForEach(IncreaseActualEffort), selectedActivitiesNotEmpty);
            DecreaseActualEffortCommand = new RelayCommand(() => SelectedActivities.ForEach(DecreaseActualEffort), selectedActivitiesNotEmpty);
            EditActivityCommand         = new RelayCommand(() => EditActivity(SelectedActivities[0]), selectedActivitiesNotEmpty);
        }
Beispiel #2
0
        public ActivityPlanViewModel(ActivityPlan plan) : this()
        {
            _isEdit     = true;
            _editedPlan = plan;
            Name        = plan.Name;

            foreach (var selectedActivity in plan.ActivityPlanActivities)
            {
                SelectedActivities.Add(selectedActivity);
            }
        }
        /// <summary>
        /// Fyller listan med redan existerande placeringar
        /// </summary>
        private void LoadExistingPlacements()
        {
            foreach (Employee e in EmployeeList)
            {
                foreach (ActivityPlacement ap in ActivityManagement.Instance.GetActivityPlacementsByEmployeeAndDepartment(e, DepartmentID))
                {
                    foreach (DataItemActivity DIA in MyList)
                    {
                        if (DIA.EmployeeID.Equals(e.EmployeeID))
                        {
                            DIA.DataList.Add(ap);

                            //Create column if it doesn't exist
                            if (!ColumnExists(ap.Activity.ActivityName))
                            {
                                DataGridTextColumn activityColumn = new DataGridTextColumn {
                                    Header = ap.Activity.ActivityName
                                };
                                activityColumn.Binding = new Binding("DataList[" + dgActivityPlacements.Columns.Count + "].ActivityAllocate");
                                dgActivityPlacements.Columns.Add(activityColumn);
                                SelectedActivities.Add(ap.Activity);
                            }
                        }
                    }
                }
            }

            foreach (DataItemActivity DIA in MyList)
            {
                foreach (DataGridTextColumn DGTC in dgActivityPlacements.Columns)
                {
                    ActivityPlacement tempAP = DIA.DataList.SingleOrDefault(a => a.Activity.ActivityName.Equals(DGTC.Header.ToString()));

                    if (tempAP == null)
                    {
                        Activity          tempAct      = ActivityManagement.Instance.GetActivityByName(DGTC.Header.ToString());
                        ActivityPlacement newPlacement = new ActivityPlacement
                        {
                            EmployeeID       = DIA.EmployeeID,
                            Activity         = tempAct,
                            ActivityID       = tempAct.ActivityID,
                            ExpenseBudgetID  = DateTime.Now.Year,
                            ActivityAllocate = 0
                        };
                        DIA.DataList.Add(newPlacement);
                        ActivityPlacementList.Add(newPlacement);
                    }
                }
            }
        }
        private void LoadEmployees()
        {
            dgActivityPlacements.Columns.Clear();
            EmployeeList.Clear();
            MyList.Clear();
            ActivityPlacementList.Clear();
            SelectedActivities.Clear();

            foreach (Employee e in EmployeeManagement.Instance.GetEmployeeAtributes(DepartmentID))
            {
                m_EmployeeList.Add(e);
            }

            CreateRow();
            LoadExistingPlacements();
        }
 private void SetSelectedManagedActivities(SelectionChangedEventArgs args)
 {
     if (args?.AddedItems != null)
     {
         SelectedActivities.AddRange(args?.AddedItems.OfType <ManagedActivityViewModel>());
     }
     if (args?.RemovedItems != null)
     {
         foreach (var managedActivityViewModel in args?.RemovedItems.OfType <ManagedActivityViewModel>())
         {
             SelectedActivities.Remove(managedActivityViewModel);
         }
     }
     RaisePropertyChanged(nameof(SelectedActivity));
     RaiseCanExecuteChangedAllCommands();
 }
        private void btnChooseAktivity_Click(object sender, RoutedEventArgs e)
        {
            ActivityRegister activityRegister = new ActivityRegister(true, DepartmentID);

            if (activityRegister.ShowDialog() == true)
            {
                if (SelectedActivities.Contains(activityRegister.Activity))
                {
                    MessageBox.Show("Du kan inte välja samma produkt flera gånger");
                }
                else
                {
                    SelectedActivities.Add(activityRegister.Activity);
                    CreateColumn(activityRegister.Activity);
                }
            }
        }
        public async Task DoRemoveManagedActivityAsync()
        {
            try
            {
                IsBusy = true;

                lock (m_Lock)
                {
                    IEnumerable <IDependentActivity <int, int> > dependentActivities = SelectedActivities.ToList();
                    var activityIds = new HashSet <int>(dependentActivities.Select(x => x.Id));

                    if (!activityIds.Any())
                    {
                        return;
                    }

                    m_CoreViewModel.RecordRedoUndo(() =>
                    {
                        m_CoreViewModel.RemoveManagedActivities(activityIds);
                    });
                }

                HasStaleOutputs  = true;
                IsProjectUpdated = true;

                await RunAutoCompileAsync().ConfigureAwait(true);
            }
            catch (Exception ex)
            {
                DispatchNotification(
                    Resource.ProjectPlan.Properties.Resources.Title_Error,
                    ex.Message);
            }
            finally
            {
                SelectedActivities.Clear();
                RaisePropertyChanged(nameof(Activities));
                RaisePropertyChanged(nameof(SelectedActivities));
                IsBusy = false;
                RaiseCanExecuteChangedAllCommands();
            }
        }
        public async Task DoRemoveManagedActivityAsync()
        {
            try
            {
                IsBusy = true;

                lock (m_Lock)
                {
                    var activityIds = new HashSet <int>(SelectedActivities.Select(x => x.Id));
                    if (!activityIds.Any())
                    {
                        return;
                    }
                    m_CoreViewModel.RemoveManagedActivities(activityIds);
                }

                HasStaleOutputs  = true;
                IsProjectUpdated = true;

                await RunAutoCompileAsync();
            }
            catch (Exception ex)
            {
                DispatchNotification(
                    Properties.Resources.Title_Error,
                    ex.Message);
            }
            finally
            {
                SelectedActivities.Clear();
                RaisePropertyChanged(nameof(Activities));
                RaisePropertyChanged(nameof(SelectedActivities));
                IsBusy = false;
                RaiseCanExecuteChangedAllCommands();
            }
        }
 private bool CanRemoveManagedActivity()
 {
     return(SelectedActivities.Any());
 }
Beispiel #10
0
        private void initialize_Onload()
        {
            DateTimeStamp = ".DATE=" + DateTime.Now.Year
                            + "-" + DateTime.Now.Month.ToString().PadLeft(2, '0')
                            + "-" + DateTime.Now.Day.ToString().PadLeft(2, '0')
                            + " " + DateTime.Now.Hour.ToString().PadLeft(2, '0')
                            + "." + DateTime.Now.Minute.ToString().PadLeft(2, '0')
                            + "." + DateTime.Now.Second.ToString().PadLeft(2, '0');

            var qualitivityReportsPath = Path.Combine(Tracked.Settings.ApplicationPaths.ApplicationMyDocumentsPath.Trim(), "Reports");

            if (!Directory.Exists(qualitivityReportsPath))
            {
                Directory.CreateDirectory(qualitivityReportsPath);
            }

            var qualitivityReportsYear = Path.Combine(qualitivityReportsPath, DateTime.Now.Year.ToString());

            if (!Directory.Exists(qualitivityReportsYear))
            {
                Directory.CreateDirectory(qualitivityReportsYear);
            }

            var qualitivityReportsMonth = Path.Combine(qualitivityReportsYear, DateTime.Now.Month.ToString().PadLeft(2, '0'));

            if (!Directory.Exists(qualitivityReportsMonth))
            {
                Directory.CreateDirectory(qualitivityReportsMonth);
            }

            textBox_output_folder.Text = qualitivityReportsMonth;

            textBox_report_compresson_name.Text = @"Activity Report - PID=" + (SelectedProject != null ? SelectedProject.Id.ToString().PadLeft(6, '0') : "000000") + DateTimeStamp;
            try
            {
                objectListView1.BeginUpdate();

                objectListView1.ShowGroups = false;

                if (SelectedProject != null)
                {
                    objectListView1.SetObjects(SelectedProject.Activities);

                    foreach (var activity in SelectedProject.Activities)
                    {
                        activity.IsChecked = false;
                    }
                }


                if (objectListView1.Items.Count > 0)
                {
                    foreach (OLVListItem lvi in objectListView1.Items)
                    {
                        var activity = lvi.RowObject as Activity;
                        if (SelectedActivities.Exists(a => activity != null && a.Id == activity.Id))
                        {
                            lvi.Checked = true;
                        }
                    }
                    objectListView1.SelectedIndex = 0;
                }

                checkBox_project_activity_export_to_file_CheckedChanged(null, null);
                checkBox_project_activity_report_CheckedChanged(null, null);
                checkBox_report_compression_CheckedChanged(null, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                objectListView1.EndUpdate();

                check_enabled();
            }
        }