Exemple #1
0
        public void Duplicate()
        {
            if (!isProcessingMultipleDuplicates)
            {
                MainViewModel.EntitiesUndoRedoManager.PauseActionId();
            }

            foreach (BASELINE_ITEMProjection selectedEntity in MainViewModel.SelectedEntities)
            {
                BASELINE_ITEMProjection newProjection = new BASELINE_ITEMProjection();
                DataUtils.ShallowCopy(newProjection.BASELINE_ITEM, selectedEntity.BASELINE_ITEM);
                newProjection.BASELINE_ITEM.GUID = Guid.Empty;
                AREA       selectedAREA       = AREACollection.FirstOrDefault(x => x.GUID == newProjection.BASELINE_ITEM.GUID_AREA);
                DISCIPLINE selectedDISCIPLINE = DISCIPLINECollection.FirstOrDefault(x => x.GUID == newProjection.BASELINE_ITEM.GUID_DISCIPLINE);
                DOCTYPE    selectedDOCTYPE    = DOCTYPECollection.FirstOrDefault(x => x.GUID == newProjection.BASELINE_ITEM.GUID_DOCTYPE);
                newProjection.BASELINE_ITEM.INTERNAL_NUM = BluePrintDataUtils.BASELINEITEM_Generate_InternalNumber(loadPROJECT, MainViewModel.Entities, selectedAREA, selectedDISCIPLINE, selectedDOCTYPE, newProjection.GUID);
                MainViewModel.EntitiesUndoRedoManager.AddUndo(newProjection, null, null, null, EntityMessageType.Added);
                MainViewModel.Save(newProjection);
            }

            if (!isProcessingMultipleDuplicates)
            {
                MainViewModel.EntitiesUndoRedoManager.UnpauseActionId();
            }
        }
Exemple #2
0
        public void CellValueChanging(CellValueChangedEventArgs e)
        {
            if (e.Column.FieldName == "GUID_DDOCTYPE")
            {
                WORKPACK changingWORKPACK = (WORKPACK)e.Row;
                DOCTYPE  chosenDOCTYPE    = LookUpDOCTYPES.Entities.FirstOrDefault(entity => entity.GUID == (Guid)e.Value);
                if (chosenDOCTYPE != null && chosenDOCTYPE.GUID_DDEPARTMENT != null)
                {
                    changingWORKPACK.GUID_DDEPARTMENT = chosenDOCTYPE.DEPARTMENT.GUID;
                    PROJECTWORKPACKSDetails.UpdateSelectedEntity();
                }
            }
            else if (e.Column.FieldName == "STARTDATE" || e.Column.FieldName == "ENDDATE")
            {
                DateTime startDate;
                DateTime endDate;

                WORKPACK changingWORKPACK = (WORKPACK)e.Row;
                if (e.Column.FieldName == "STARTDATE")
                {
                    startDate = (DateTime)e.Value;
                    endDate   = changingWORKPACK.ENDDATE;
                    if (endDate < startDate)
                    {
                        endDate = BluePrintDataUtils.WORKPACK_Calculate_EndDate(startDate, Entity);
                        changingWORKPACK.ENDDATE = endDate;
                    }
                }
                else
                {
                    endDate   = (DateTime)e.Value;
                    startDate = changingWORKPACK.STARTDATE;
                    if (endDate < startDate)
                    {
                        startDate = BluePrintDataUtils.WORKPACK_Calculate_StartDate(endDate, Entity);
                        changingWORKPACK.STARTDATE = startDate;
                    }
                }

                DateTime reviewStartDate = startDate;
                DateTime reviewEndDate   = endDate;

                BluePrintDataUtils.WORKPACK_Calculate_ReviewPeriod(ref reviewStartDate, ref reviewEndDate, Entity, false);
                changingWORKPACK.REVIEWSTARTDATE = reviewStartDate;

                if (reviewEndDate >= endDate)
                {
                    changingWORKPACK.REVIEWENDDATE = endDate;
                }
                else
                {
                    changingWORKPACK.REVIEWENDDATE = reviewEndDate;
                }

                PROJECTWORKPACKSDetails.UpdateSelectedEntity();
            }
        }
Exemple #3
0
        /// <summary>
        /// Allow cells to commit immediately upon losing focus
        /// </summary>
        public void CellValueChanged(CellValueChangedEventArgs e)
        {
            if (e.Column.FieldName == "GUID_DDISCIPLINE" || e.Column.FieldName == "GUID_DDOCTYPE")
            {
                WORKPACK changedWORKPACK = (WORKPACK)e.Row;
                changedWORKPACK.INTERNAL_NAME1 = BluePrintDataUtils.WORKPACK_Generate_InternalNumber1(Entity, changedWORKPACK, PROJECTWORKPACKSDetails.Entities, LookUpAREAS, LookUpDISCIPLINES, LookUpDOCTYPES);

                if (e.Column.FieldName == "GUID_DDISCIPLINE")
                {
                    changedWORKPACK.INTERNAL_NAME2 = BluePrintDataUtils.WORKPACK_Generate_InternalNumber2(Entity, changedWORKPACK, PROJECTWORKPACKSDetails.Entities, LookUpAREAS, LookUpDISCIPLINES, LookUpPHASES);
                }
            }
            else if (e.Column.FieldName == "GUID_DPHASE" || e.Column.FieldName == "GUID_DAREA")
            {
                WORKPACK changedWORKPACK = (WORKPACK)e.Row;
                changedWORKPACK.INTERNAL_NAME2 = BluePrintDataUtils.WORKPACK_Generate_InternalNumber2(Entity, changedWORKPACK, PROJECTWORKPACKSDetails.Entities, LookUpAREAS, LookUpDISCIPLINES, LookUpPHASES);
            }
            else if (e.Column.FieldName == "STARTDATE" || e.Column.FieldName == "ENDDATE" || e.Column.FieldName == "REVIEWSTARTDATE" || e.Column.FieldName == "REVIEWENDDATE")
            {
                WORKPACK changedWORKPACK = (WORKPACK)e.Row;
                changedWORKPACK.AUTOGENERATED = false;
            }
        }
Exemple #4
0
        /// <summary>
        /// Influence column(s) when changes happens in other column
        /// </summary>
        public void CellValueChanging(CellValueChangedEventArgs e)
        {
            if (e.RowHandle != GridControl.NewItemRowHandle)
            {
                return;
            }

            BASELINE_ITEMProjection activeBASELINE_ITEM = (BASELINE_ITEMProjection)e.Row;

            if (e.Column.FieldName == BindableBase.GetPropertyName(() => new BASELINE_ITEMProjection().BASELINE_ITEM) + "." + BindableBase.GetPropertyName(() => new BASELINE_ITEM().GUID_WORKPACK))
            {
                WORKPACK chosenWORKPACK = WORKPACKCollection.FirstOrDefault(entity => entity.GUID == (Guid)e.Value);
                if (chosenWORKPACK != null)
                {
                    activeBASELINE_ITEM.BASELINE_ITEM.GUID_AREA       = chosenWORKPACK.GUID_DAREA;
                    activeBASELINE_ITEM.BASELINE_ITEM.GUID_DOCTYPE    = chosenWORKPACK.GUID_DDOCTYPE;
                    activeBASELINE_ITEM.BASELINE_ITEM.GUID_DEPARTMENT = chosenWORKPACK.GUID_DDEPARTMENT;
                    activeBASELINE_ITEM.BASELINE_ITEM.GUID_DISCIPLINE = chosenWORKPACK.GUID_DDISCIPLINE;
                    activeBASELINE_ITEM.BASELINE_ITEM.GUID_PHASE      = chosenWORKPACK.PHASE != null ? chosenWORKPACK.GUID_DPHASE : null;
                    var SelectedAREA       = AREACollection.FirstOrDefault(x => x.GUID == chosenWORKPACK.GUID_DAREA);
                    var SelectedDOCTYPE    = DOCTYPECollection.FirstOrDefault(x => x.GUID == chosenWORKPACK.GUID_DDOCTYPE);
                    var SelectedDISCIPLINE = DISCIPLINECollection.FirstOrDefault(x => x.GUID == chosenWORKPACK.GUID_DDISCIPLINE);

                    activeBASELINE_ITEM.BASELINE_ITEM.INTERNAL_NUM = BluePrintDataUtils.BASELINEITEM_Generate_InternalNumber(loadPROJECT, MainViewModel.Entities, SelectedAREA, SelectedDISCIPLINE, SelectedDOCTYPE);
                    MainViewModel.UpdateSelectedEntity();
                }
            }
            else if (e.Column.FieldName == BindableBase.GetPropertyName(() => new BASELINE_ITEMProjection().BASELINE_ITEM) + "." + BindableBase.GetPropertyName(() => new BASELINE_ITEM().GUID_DOCTYPE))
            {
                DOCTYPE chosenDOCTYPE = DOCTYPECollection.FirstOrDefault(entity => entity.GUID == (Guid)e.Value);
                if (chosenDOCTYPE != null && chosenDOCTYPE.GUID_DDEPARTMENT != null)
                {
                    activeBASELINE_ITEM.BASELINE_ITEM.GUID_DEPARTMENT = chosenDOCTYPE.DEPARTMENT.GUID;
                    MainViewModel.UpdateSelectedEntity();
                }
            }
        }
Exemple #5
0
        public void AutoPopulate(object button)
        {
            MainViewModel.EntitiesUndoRedoManager.PauseActionId();
            var info = GridPopupMenuBase.GetGridMenuInfo((DependencyObject)button) as GridMenuInfo;

            string departmentFieldName     = BindableBase.GetPropertyName(() => new BASELINE_ITEMProjection().BASELINE_ITEM) + "." + BindableBase.GetPropertyName(() => new BASELINE_ITEM().GUID_DEPARTMENT);
            string disciplineFieldName     = BindableBase.GetPropertyName(() => new BASELINE_ITEMProjection().BASELINE_ITEM) + "." + BindableBase.GetPropertyName(() => new BASELINE_ITEM().GUID_DISCIPLINE);
            string docTypeFieldName        = BindableBase.GetPropertyName(() => new BASELINE_ITEMProjection().BASELINE_ITEM) + "." + BindableBase.GetPropertyName(() => new BASELINE_ITEM().GUID_DOCTYPE);
            string areaFieldName           = BindableBase.GetPropertyName(() => new BASELINE_ITEMProjection().BASELINE_ITEM) + "." + BindableBase.GetPropertyName(() => new BASELINE_ITEM().GUID_AREA);
            string workpackFieldName       = BindableBase.GetPropertyName(() => new BASELINE_ITEMProjection().BASELINE_ITEM) + "." + BindableBase.GetPropertyName(() => new BASELINE_ITEM().GUID_WORKPACK);
            string internalNumberFieldName = BindableBase.GetPropertyName(() => new BASELINE_ITEMProjection().BASELINE_ITEM) + "." + BindableBase.GetPropertyName(() => new BASELINE_ITEM().INTERNAL_NUM);

            List <BASELINE_ITEMProjection> entitiesToSave = new List <BASELINE_ITEMProjection>();

            if (info.Column.FieldName == internalNumberFieldName)
            {
                foreach (BASELINE_ITEMProjection entity in MainViewModel.SelectedEntities)
                {
                    entity.BASELINE_ITEM.INTERNAL_NUM = string.Empty;
                }
            }

            foreach (BASELINE_ITEMProjection entity in MainViewModel.SelectedEntities)
            {
                WORKPACK entityWORKPACK = WORKPACKCollection.FirstOrDefault(x => x.GUID == entity.BASELINE_ITEM.GUID_WORKPACK);
                if (info.Column.FieldName == internalNumberFieldName)
                {
                    string internalNum = BluePrintDataUtils.BASELINEITEM_Generate_InternalNumber(loadPROJECT, MainViewModel.Entities, entity.BASELINE_ITEM.AREA, entity.BASELINE_ITEM.DISCIPLINE, entity.BASELINE_ITEM.DOCTYPE, entity.GUID);
                    MainViewModel.SetNestedValueWithUndo(entity, info.Column.FieldName, internalNum);
                    entitiesToSave.Add(entity);
                }
                else if (info.Column.FieldName == departmentFieldName || info.Column.FieldName == disciplineFieldName || info.Column.FieldName == docTypeFieldName || info.Column.FieldName == areaFieldName)
                {
                    if (entityWORKPACK == null)
                    {
                        continue;
                    }

                    if (info.Column.FieldName == departmentFieldName)
                    {
                        MainViewModel.SetNestedValueWithUndo(entity, info.Column.FieldName, entityWORKPACK.GUID_DDEPARTMENT);
                    }
                    else if (info.Column.FieldName == disciplineFieldName)
                    {
                        MainViewModel.SetNestedValueWithUndo(entity, info.Column.FieldName, entityWORKPACK.GUID_DDISCIPLINE);
                    }
                    else if (info.Column.FieldName == docTypeFieldName)
                    {
                        MainViewModel.SetNestedValueWithUndo(entity, info.Column.FieldName, entityWORKPACK.GUID_DDOCTYPE);
                    }
                    else if (info.Column.FieldName == areaFieldName)
                    {
                        MainViewModel.SetNestedValueWithUndo(entity, info.Column.FieldName, entityWORKPACK.GUID_DAREA);
                    }

                    entitiesToSave.Add(entity);
                }
                else if (info.Column.FieldName == workpackFieldName)
                {
                    if (entity.BASELINE_ITEM.GUID_DISCIPLINE == Guid.Empty || entity.BASELINE_ITEM.GUID_DEPARTMENT == Guid.Empty ||
                        entity.BASELINE_ITEM.GUID_DOCTYPE == Guid.Empty || entity.BASELINE_ITEM.GUID_AREA == Guid.Empty)
                    {
                        continue;
                    }

                    WORKPACK findWORKPACK = WORKPACKCollection.FirstOrDefault(x => x.GUID_DDEPARTMENT == entity.BASELINE_ITEM.GUID_DEPARTMENT && x.GUID_DDISCIPLINE == entity.BASELINE_ITEM.GUID_DISCIPLINE);
                    if (findWORKPACK == null)
                    {
                        WORKPACK newWORKPACK = new WORKPACK();
                        newWORKPACK.GUID_PROJECT = loadPROJECT.GUID;
                        newWORKPACK.GUID_DAREA   = (Guid)entity.BASELINE_ITEM.GUID_AREA;
                        if (entity.BASELINE_ITEM.GUID_PHASE != null)
                        {
                            newWORKPACK.GUID_DPHASE = entity.BASELINE_ITEM.GUID_PHASE;
                        }
                        newWORKPACK.GUID_DDISCIPLINE = (Guid)entity.BASELINE_ITEM.GUID_DISCIPLINE;
                        newWORKPACK.GUID_DDEPARTMENT = (Guid)entity.BASELINE_ITEM.GUID_DEPARTMENT;
                        newWORKPACK.GUID_DDOCTYPE    = (Guid)entity.BASELINE_ITEM.GUID_DOCTYPE;
                        newWORKPACK.INTERNAL_NAME1   = BluePrintDataUtils.WORKPACK_Generate_InternalNumber1(loadPROJECT, newWORKPACK, WORKPACKCollection, loaderCollection.GetViewModel <AREA>(), loaderCollection.GetViewModel <DISCIPLINE>(), loaderCollection.GetViewModel <DOCTYPE>());
                        newWORKPACK.INTERNAL_NAME2   = BluePrintDataUtils.WORKPACK_Generate_InternalNumber2(loadPROJECT, newWORKPACK, WORKPACKCollection, loaderCollection.GetViewModel <AREA>(), loaderCollection.GetViewModel <DISCIPLINE>(), loaderCollection.GetViewModel <PHASE>());

                        newWORKPACK.STARTDATE = DateTime.Now;
                        newWORKPACK.ENDDATE   = BluePrintDataUtils.WORKPACK_Calculate_EndDate(newWORKPACK.STARTDATE, loadPROJECT);
                        DateTime reviewStartDate = newWORKPACK.STARTDATE;
                        DateTime reviewEndDate   = newWORKPACK.ENDDATE;
                        BluePrintDataUtils.WORKPACK_Calculate_ReviewPeriod(ref reviewStartDate, ref reviewEndDate, loadPROJECT, false);
                        newWORKPACK.REVIEWSTARTDATE = reviewStartDate;
                        newWORKPACK.REVIEWENDDATE   = reviewEndDate;
                        newWORKPACK.AUTOGENERATED   = true;
                        ((CollectionViewModel <WORKPACK, WORKPACK, Guid, IBluePrintsEntitiesUnitOfWork>)loaderCollection.GetViewModel <WORKPACK>()).Save(newWORKPACK);

                        MainViewModel.SetNestedValueWithUndo(entity, info.Column.FieldName, newWORKPACK.GUID);
                    }
                    else
                    {
                        MainViewModel.SetNestedValueWithUndo(entity, info.Column.FieldName, findWORKPACK.GUID);
                    }

                    entitiesToSave.Add(entity);
                }
            }

            MainViewModel.BulkSave(entitiesToSave);
            MainViewModel.EntitiesUndoRedoManager.UnpauseActionId();
        }
        /// <summary>
        /// Approves an entity.
        /// Since CollectionViewModelBase is a POCO view model, an the instance of this class will also expose the ApproveCommand property that can be used as a binding source in views.
        /// </summary>
        /// <param name="projectionEntity">An entity to approve.</param>
        public void Approve(VARIATION entity)
        {
            string errorMessage = string.Empty;

            if (entity == null)
            {
                errorMessage = "Nothing within variation to approve";
            }
            else if (loadPROJECT == null)
            {
                errorMessage = "Project doesn't exists";
            }
            else if (loadBASELINE == null)
            {
                errorMessage = "Live baseline doesn't exists";
            }
            else if (loadPROGRESS == null)
            {
                errorMessage = "Live progress doesn't exists";
            }

            if (errorMessage != string.Empty)
            {
                MessageBoxService.ShowMessage(errorMessage);
                return;
            }

            IBluePrintsEntitiesUnitOfWork unitOfWork = bluePrintsUnitOfWorkFactory.CreateUnitOfWork();
            BASELINE LiveBASELINE = loadBASELINE;
            IEnumerable <VARIATION_ITEM> editVARIATION_ITEMS = unitOfWork.VARIATION_ITEMS.Where(x => x.GUID_VARIATION == entity.GUID).ToArray().AsEnumerable();
            IEnumerable <BASELINE_ITEM>  addBASELINE_ITEMS   = unitOfWork.BASELINE_ITEMS.Where(x => x.GUID_VARIATION == entity.GUID && x.GUID_BASELINE == null).ToArray().AsEnumerable();
            IQueryable <BASELINE_ITEM>   editBASELINE_ITEMS  = loaderCollection.GetCollection <BASELINE_ITEM>();
            IEnumerable <PROGRESS_ITEM>  livePROGRESS_ITEMS  = loaderCollection.GetCollection <PROGRESS_ITEM>();

            BASELINE newBASELINE = new BASELINE();

            DataUtils.ShallowCopy(newBASELINE, LiveBASELINE);
            newBASELINE.GUID     = Guid.Empty;
            newBASELINE.REVISION = ((char)(LiveBASELINE.REVISION.Last() + 1)).ToString();
            //not saving new baseline as live yet because editBASELINE_ITEMS still depends on the current live baseline for copying BASELINE_ITEMS
            newBASELINE.STATUS = BaselineStatus.Superseded;

            CollectionViewModel <BASELINE, BASELINE, Guid, IBluePrintsEntitiesUnitOfWork>           BASELINECollectionViewModel      = (CollectionViewModel <BASELINE, BASELINE, Guid, IBluePrintsEntitiesUnitOfWork>)loaderCollection.GetViewModel <BASELINE>();
            CollectionViewModel <BASELINE_ITEM, BASELINE_ITEM, Guid, IBluePrintsEntitiesUnitOfWork> BASELINE_ITEMCollectionViewModel = (CollectionViewModel <BASELINE_ITEM, BASELINE_ITEM, Guid, IBluePrintsEntitiesUnitOfWork>)loaderCollection.GetViewModel <BASELINE_ITEM>();

            BASELINECollectionViewModel.Save(newBASELINE);

            entity.APPROVED         = DateTime.Now;
            entity.GUID_ORIBASELINE = LiveBASELINE.GUID;
            entity.GUID_BASELINE    = newBASELINE.GUID;
            MainViewModel.Save(entity);

            ObservableCollection <BASELINE_ITEM> newBASELINE_ITEMS = new ObservableCollection <BASELINE_ITEM>();

            foreach (BASELINE_ITEM editBASELINE_ITEM in editBASELINE_ITEMS)
            {
                BASELINE_ITEM copyBASELINE_ITEM = new BASELINE_ITEM();
                DataUtils.ShallowCopy(copyBASELINE_ITEM, editBASELINE_ITEM);

                VARIATION_ITEM editVARIATION_ITEM = editVARIATION_ITEMS.FirstOrDefault(x => x.GUID_ORIBASEITEM == editBASELINE_ITEM.GUID_ORIGINAL);
                if (editVARIATION_ITEM != null)
                {
                    if (editVARIATION_ITEM.ACTION == VariationAction.Cancel)
                    {
                        decimal progressItemEARNED_UNITS = livePROGRESS_ITEMS.Where(x => x.GUID_ORIBASEITEM == editBASELINE_ITEM.GUID_ORIGINAL).Sum(y => y.EARNED_UNITS);
                        if (progressItemEARNED_UNITS == 0)
                        {
                            copyBASELINE_ITEM.DC_HOURS = -1 * copyBASELINE_ITEM.ESTIMATED_HOURS;
                        }
                        else
                        {
                            copyBASELINE_ITEM.DC_HOURS = -1 * (copyBASELINE_ITEM.TOTAL_HOURS - progressItemEARNED_UNITS);
                        }
                    }
                    else if (editVARIATION_ITEM.ACTION == VariationAction.Append)
                    {
                        copyBASELINE_ITEM.DC_HOURS += editVARIATION_ITEM.VARIATION_UNITS;
                    }

                    if (editVARIATION_ITEM.ACTION != VariationAction.NoAction)
                    {
                        copyBASELINE_ITEM.GUID_VARIATION = entity.GUID;
                    }
                }

                copyBASELINE_ITEM.GUID          = Guid.Empty;
                copyBASELINE_ITEM.GUID_BASELINE = newBASELINE.GUID;
                newBASELINE_ITEMS.Add(copyBASELINE_ITEM);
            }

            foreach (BASELINE_ITEM addBASELINE_ITEM in addBASELINE_ITEMS)
            {
                BASELINE_ITEM newBASELINE_ITEM = new BASELINE_ITEM();
                DataUtils.ShallowCopy(newBASELINE_ITEM, addBASELINE_ITEM);
                newBASELINE_ITEM.GUID          = Guid.Empty;
                newBASELINE_ITEM.GUID_BASELINE = newBASELINE.GUID;
                newBASELINE_ITEM.INTERNAL_NUM  = BluePrintDataUtils.BASELINEITEM_Generate_InternalNumber(this.loadPROJECT, newBASELINE_ITEM, newBASELINE_ITEMS, addBASELINE_ITEM.AREA, addBASELINE_ITEM.DISCIPLINE, addBASELINE_ITEM.DOCTYPE);
                VARIATION_ITEM editVARIATION_ITEM = editVARIATION_ITEMS.First(x => x.GUID_ORIBASEITEM == newBASELINE_ITEM.GUID_ORIGINAL);
                newBASELINE_ITEM.DC_HOURS       = editVARIATION_ITEM.VARIATION_UNITS;
                newBASELINE_ITEM.GUID_VARIATION = entity.GUID;

                newBASELINE_ITEMS.Add(newBASELINE_ITEM);
            }

            foreach (BASELINE_ITEM newBASELINE_ITEM in newBASELINE_ITEMS)
            {
                BASELINE_ITEMCollectionViewModel.Save(newBASELINE_ITEM);
            }

            LiveBASELINE.STATUS = BaselineStatus.Superseded;
            BASELINECollectionViewModel.Save(LiveBASELINE);
            newBASELINE.STATUS = BaselineStatus.Live;
            BASELINECollectionViewModel.Save(newBASELINE);
        }