public MechanicalEquipmentPropertiesViewModel(MechanicalEquipmentComponent mechanicalEquipmentComponent)
        {
            mMechanicalEquipmentComponent = mechanicalEquipmentComponent;

            LastInspectedCommand = new DelegateCommand<object>(LastInspectedHandler, CanModify);
            NextInspectionCommand = new DelegateCommand<object>(NextInspectionHandler, CanModify);

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);

            cmsWebServiceClient.GetManufacturersCompleted +=
                (s, e) =>
                {
                    mManufacturers = e.Result;
                    RaisePropertyChanged("Manufacturers");
                    RaisePropertyChanged("Manufacturer");

                    if (mMechanicalEquipmentComponent.ManufacturerId.HasValue)
                    {
                        LoadModels(mMechanicalEquipmentComponent.ManufacturerId.Value);
                    }
                    else if (Loaded != null)
                    {
                        Loaded();
                        Loaded = null;
                    }
                };
            cmsWebServiceClient.GetManufacturersAsync((int)CommonUtils.EquipmentTypeCode.MECH);
        }
 public AddEditMechanicalComponentViewModel(MechanicalEquipmentComponent mc, IList<string> existingComponentNames)
 {
     ExistingComponentNames = existingComponentNames;
     EditingName = mc.Name;
     mMechanicalEquipmentComponent = mc;
     Initialize();
     InEditMode = true;
 }
 public AddEditMechanicalComponentViewModel(int mechanicalEquipmentId,IList<string> existingComponentNames )
 {
     Initialize();
     ExistingComponentNames = existingComponentNames;
     mMechanicalEquipmentComponent = new MechanicalEquipmentComponent();
     mMechanicalEquipmentComponent.MechanicalPropertyValues = new List<MechanicalPropertyValue>();
     mMechanicalEquipmentComponent.MechanicalEquipmentId = mechanicalEquipmentId;
     InEditMode = false;
 }
        public AddEditMechanicalEquipmentComponentDialog(MechanicalEquipmentComponent mechanicalEquipmentComponent, IList<string> existingComponentNames)
        {
            // Required to initialize variables
            InitializeComponent();

            AddEditMechanicalComponentViewModel addEditMechanicalComponentViewModel = new AddEditMechanicalComponentViewModel(mechanicalEquipmentComponent,existingComponentNames);

            addEditMechanicalComponentViewModel.Loaded += () =>
            {
                addEditMechanicalComponentViewModel.View = this;
                DataContext = addEditMechanicalComponentViewModel;
                Utils.ResetOriginalValues(LayoutRoot);
            };
        }
Ejemplo n.º 5
0
        public void DeleteMechanicalEquipmentComponent(MechanicalEquipmentComponent mec)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                var mechanicalPropertyValues = (from x in cee.MechanicalPropertyValues
                                                where x.MechanicalEquipmentComponentId == mec.Id
                                                select x).ToList();

                foreach (var mechanicalPropertyValue in mechanicalPropertyValues)
                {
                    cee.MechanicalPropertyValues.Remove(mechanicalPropertyValue);
                }

                var q = (from x in cee.MechanicalEquipmentComponents
                         where x.Id == mec.Id
                         select x).FirstOrDefault();
                if (q != null)
                {
                    cee.MechanicalEquipmentComponents.Remove(q);
                    cee.SaveChanges();
                }
            }
        }
Ejemplo n.º 6
0
        public bool SaveMechanicalEquipmentComponents(List<MechanicalEquipmentComponent> mechanicalComponents, int userId)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                foreach (var mechanicalComponent in mechanicalComponents)
                {
                    var q = (from x in cee.MechanicalEquipmentComponents
                             where x.Id == mechanicalComponent.Id
                             select x).FirstOrDefault();

                    if (q != null)
                    {

                        if (q.LastInspectedDate != mechanicalComponent.LastInspectedDate)
                        {
                            MechanicalEquipmentRevisionHistory rv = new MechanicalEquipmentRevisionHistory
                            {
                                MechanicalEquipmentId = mechanicalComponent.MechanicalEquipmentId,
                                Date = DateTime.Now,
                                UserId = userId,
                                Description = string.Format("Component '{0}': Last Inspected Date changed from '{1}' to '{2}'.",mechanicalComponent.Name,  q.LastInspectedDate, mechanicalComponent.LastInspectedDate),
                                IsSystemMessage = true
                            };

                            AddMechanicalRevisionHistoryInternal(rv, cee);
                        }

                        //Update Mechanical Componet
                        cee.Entry(q).CurrentValues.SetValues(mechanicalComponent);
                    }
                    else
                    {
                        q = new MechanicalEquipmentComponent();
                        q.MechanicalEquipmentId = mechanicalComponent.MechanicalEquipmentId;
                        q.MechanicalEquipmentComponentTypeId = mechanicalComponent.MechanicalEquipmentComponentTypeId;
                        q.Name = mechanicalComponent.Name;
                        q.Ordinal = mechanicalComponent.Ordinal;
                        q.NextInspectionDate = mechanicalComponent.NextInspectionDate;
                        q.LastInspectedById = mechanicalComponent.LastInspectedById;
                        q.LastInspectedDate = mechanicalComponent.LastInspectedDate;
                        q.LastModifiedById = mechanicalComponent.LastModifiedById;
                        q.LastModifiedDate = mechanicalComponent.LastModifiedDate;
                        q.Description = mechanicalComponent.Description;
                        q.ManufacturerId = mechanicalComponent.ManufacturerId;
                        q.ModelId = mechanicalComponent.ModelId;

                        //Add new Mechanical Component
                        cee.MechanicalEquipmentComponents.Add(q);
                    }

                    foreach (var mechanicalComponentPropertyValue in mechanicalComponent.MechanicalPropertyValues)
                    {
                        var qq = (from x in cee.MechanicalPropertyValues
                                  where x.Id == mechanicalComponentPropertyValue.Id
                                  select x).FirstOrDefault();

                        if (qq != null)
                        {
                            cee.Entry(qq).CurrentValues.SetValues(mechanicalComponentPropertyValue);
                        }
                        else
                        {
                            cee.MechanicalPropertyValues.Add(mechanicalComponentPropertyValue);
                        }
                    }
                    cee.SaveChanges();
                }
            }
            return true;
        }
Ejemplo n.º 7
0
        public DbOperationResult SaveMechanicalEquipmentComponent(MechanicalEquipmentComponent mechanicalEquipmentComponent)
        {
            DbOperationResult result = new DbOperationResult();

            if (mechanicalEquipmentComponent == null)
            {
                result.ServerInformationMessages.Add("Save Completed");
                return result;
            }

            using (CmsEntities cee = new CmsEntities())
            {
                var match = (from x in cee.MechanicalEquipmentComponents where x.Id == mechanicalEquipmentComponent.Id select x).FirstOrDefault();

                if (match == null)
                {
                    //So component doesnt exist in the database so lets create it
                    mechanicalEquipmentComponent.MechanicalEquipment = null;
                    mechanicalEquipmentComponent.MechanicalEquipmentComponentType = null;
                    cee.MechanicalEquipmentComponents.Add(mechanicalEquipmentComponent);
                }
                else
                {
                    //Compoent exist, change the ID of Equipment
                    match.MechanicalEquipmentId = mechanicalEquipmentComponent.MechanicalEquipmentId;
                }

                cee.SaveChanges();
                result.ServerInformationMessages.Add("Save Completed");
                return result;
            }
        }
        private void InsertData(IList<MechanicalComponentDataAdapter> adapters)
        {
            for (int index = 0; index < adapters.Count; index++)
            {
                MechanicalComponentDataAdapter adapter = adapters[index];
                if (!adapter.IsValid())
                {
                    continue;
                }

                IList<string> componentNames = (from x in adapters select x.ComponentName).ToList();
                if (DuplicateItemNameFoundInExcell(adapter.ComponentName, componentNames, adapter.RowNumber))
                {
                    continue;
                }

                componentNames = (from x in  Cee.MechanicalEquipmentComponents select x.Name).ToList();
                if (DuplicateItemNameFoundInDatabase(adapter.ComponentName, componentNames, adapter.RowNumber))
                {
                    continue;
                }

                var newComponent = new MechanicalEquipmentComponent();

                newComponent.LastModifiedDate = DateTime.Now;
                newComponent.LastModifiedById = MetaData.UserId;

                newComponent.Name = adapter.ComponentName;
                newComponent.Description = adapter.ComponentDescription;

                if (GetMechanicalEquipment(adapter.Tag, newComponent, adapter.RowNumber)) continue;
                if (GetMechanicalEquipmentComponentType(adapter.ComponentType, newComponent, adapter.RowNumber)) continue;

                MechanicalEquipmentComponent existing = (from x in Cee.MechanicalEquipmentComponents
                    where x.Name.Equals(adapter.Tag,StringComparison.CurrentCultureIgnoreCase) && x.MechanicalEquipmentComponentTypeId == newComponent.MechanicalEquipmentComponentTypeId
                    select x).FirstOrDefault();

                if (existing != null)
                {
                    //error - should not already exist
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format("Tag '{0}' Row '{1}': '{2}' with a component type of '{3}' already exists in the database.  Skipping.",
                        adapter.Tag, adapter.RowNumber, adapter.Tag, newComponent.MechanicalEquipmentComponentType.Name));
                    continue;
                }

                bool skipRow = ChangeManufacturerModel(adapter, newComponent);

                if (skipRow) continue;

                BuildPropertyValues(newComponent, adapter);

                Cee.MechanicalEquipmentComponents.Add(newComponent);
                mSavedResults.Add(newComponent);

                newComponent.MechanicalEquipment.MechanicalEquipmentRevisionHistories.Add(new MechanicalEquipmentRevisionHistory
                {
                    Date = DateTime.Now,
                    MechanicalEquipmentId = newComponent.MechanicalEquipmentId,
                    UserId = MetaData.UserId,
                    Description = BuildRevisionHistoryInsertVersionComment(MetaData.RevisionHistoryComment, new decimal(0.001)),
                    Revision = new decimal(0.001),
                    IsSystemMessage = true
                });
            }

            if (mSavedResults.Count == 0)
            {
                RaiseMessage(CommonUtils.MessageType.Warning, string.Format("No Equipment Components were added from from worksheet {0}.", WorkSheetName));
            }
            else
            {
                //|---   S A V E
                Cee.SaveChanges();
            }

            foreach (MechanicalEquipmentComponent result in mSavedResults)
            {
                RaiseMessage(CommonUtils.MessageType.Added, string.Format("Added Equipment Component {0} from worksheet {1}.", result.Name, WorkSheetName));
            }
        }
        private bool GetMechanicalEquipmentComponentType(string typeName, MechanicalEquipmentComponent component, int rowIndex)
        {
            MechanicalEquipmentComponentType componentType = (from x in mExistingEquipmentComponentTypes
                where string.Compare(typeName, x.Name, true, CultureInfo.CurrentCulture) == 0
                      && !string.IsNullOrEmpty(x.Name)
                select x).FirstOrDefault();

            if (componentType != null)
            {
                component.MechanicalEquipmentComponentType = componentType;
                component.MechanicalEquipmentComponentTypeId = componentType.Id;
            }
            else
            {
                if (CanCreateProperties)
                {
                    string code = typeName.Replace(" ", "_").ToUpper();
                    componentType = new MechanicalEquipmentComponentType {Name = typeName, Code = code, Description = typeName + " (created by importer)", IsActive = true};
                    mExistingEquipmentComponentTypes.Add(componentType);
                    component.MechanicalEquipmentComponentType = componentType;
                }
                else
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Line '{1}': Could not find Mechanical EquipmentComponent Type '{2}' in database. Skipping this row.", WorkSheetName, rowIndex, typeName));
                    return true;
                }
            }

            return false;
        }
Ejemplo n.º 10
0
        private bool GetMechanicalEquipment(string tag, MechanicalEquipmentComponent newComponent, int rowIndex)
        {
            bool skipRow = false;

            //Check if the Area exist in the database

            MechanicalEquipment equipment = (from x in Cee.MechanicalEquipments where x.Name.Equals(tag, StringComparison.CurrentCultureIgnoreCase) && !string.IsNullOrEmpty(x.Name) select x).FirstOrDefault();

            if (equipment == null)
            {
                //try db
                equipment = (from x in Cee.MechanicalEquipments
                    where string.Compare(tag, x.Name, true, CultureInfo.CurrentCulture) == 0
                          && !string.IsNullOrEmpty(x.Name)
                    select x).FirstOrDefault();
            }

            if (equipment != null)
            {
                newComponent.MechanicalEquipment = equipment;
                newComponent.MechanicalEquipmentId = equipment.Id;
            }
            else
            {
                RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Line '{1}': Could not find Equipment '{2}' in database. Skipping this row.", WorkSheetName, rowIndex, tag));
                skipRow = true;
            }

            return skipRow;
        }
Ejemplo n.º 11
0
        private bool ChangeManufacturerModel(MechanicalComponentDataAdapter adapter, MechanicalEquipmentComponent newComponent)
        {
            //CHANGING Manufacturer
            if (!string.IsNullOrEmpty(adapter.Manufacturer))
            {
                if (adapter.Manufacturer.ToLower() != "null")
                {
                    Manufacturer manufactuer = (from x in mExistingManufacturers where x.Name.ToLower() == adapter.Manufacturer.ToLower() select x).FirstOrDefault();

                    if (manufactuer == null)
                    {
                        RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildItemNotFoundInDatabaseMessage("Manufacturer", adapter.Manufacturer, adapter.RowNumber)));
                        return false;
                    }

                    newComponent.Manufacturer = manufactuer;
                    newComponent.ManufacturerId = manufactuer.Id;

                    if (adapter.Model.ToLower() != "null")
                    {
                        //CHANGING Model
                        if (!string.IsNullOrEmpty(adapter.Model))
                        {
                            Model model = (from x in manufactuer.Models where x.Name.ToLower() == adapter.Model.ToLower() select x).FirstOrDefault();

                            if (model == null)
                            {
                                RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildItemNotFoundInDatabaseMessage("Model", adapter.Model, adapter.RowNumber)));
                                return false;
                            }

                            newComponent.Model = model;
                            newComponent.ModelId = model.Id;
                        }
                    }
                    else
                    {
                        newComponent.Model = null;
                        newComponent.ModelId = null;
                    }
                }
                else
                {
                    newComponent.Manufacturer = null;
                    newComponent.ManufacturerId = null;
                    newComponent.Model = null;
                    newComponent.ModelId = null;
                }
            }
            return false;
        }
Ejemplo n.º 12
0
        private MechanicalEquipmentRevisionHistory BuildRevisionHistory(MechanicalEquipmentComponent existing)
        {
            const decimal incrediment = 0.001m;
            var revision = new decimal(1.000);

            List<decimal> foo = (from x in Cee.MechanicalEquipmentRevisionHistories where x.MechanicalEquipmentId == existing.MechanicalEquipmentId orderby x.Revision descending select x.Revision).ToList();

            if (foo.Count > 0)
            {
                revision = foo[0] + incrediment;
            }

            var rvh = new MechanicalEquipmentRevisionHistory
            {
                Date = DateTime.Now,
                MechanicalEquipmentId = existing.MechanicalEquipmentId,
                UserId = MetaData.UserId,
                Description = BuildRevisionHistoryUpdateComment(MetaData.RevisionHistoryComment),
                Revision = revision,
                IsSystemMessage = true
            };
            return rvh;
        }
Ejemplo n.º 13
0
        private void BuildPropertyValues(MechanicalEquipmentComponent componentIn, MechanicalComponentDataAdapter adapter)
        {
            foreach (var pair in adapter.PropertyValues)
            {
                //DOES PROPERTY EXIST?
                MechanicalEquipmentProperty property = (from x in mExistingEquipmentProperties where x.Name.ToLower() == pair.Key.ToLower() select x).FirstOrDefault();
                if (property == null)
                {
                    if (CanCreateProperties)
                    {
                        property = new MechanicalEquipmentProperty {Name = pair.Key, DefaultValue = pair.Value, Description = " (created by importer)."};
                        mExistingEquipmentProperties.Add(property); //update cache
                    }
                    else
                    {
                        //ERROR!
                        RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Line '{1} Tag {2} Component Name {3}' : The property does not exist.",
                            WorkSheetName, adapter.RowNumber, adapter.Tag, adapter.ComponentName));
                        continue;
                    }
                }

                //CHECK MechanicalEquipmentComponentTypeProperty Exists
                MechanicalEquipmentComponentTypeProperty equipmentComponentTypeProperty = null;
                if (mExistingEquipmentComponentTypeProperty.Any())
                {
                    equipmentComponentTypeProperty =
                        (from x in mExistingEquipmentComponentTypeProperty
                            where x.MechanicalEquipmentComponentType.Name.ToLower() == componentIn.MechanicalEquipmentComponentType.Name.ToLower()
                                  && x.MechanicalEquipmentProperty.Name.ToLower() == property.Name.ToLower()
                            select x).FirstOrDefault();
                }

                if (equipmentComponentTypeProperty == null)
                {
                    if (CanCreateProperties)
                    {
                        //CREATE JOIN ROW
                        equipmentComponentTypeProperty = new MechanicalEquipmentComponentTypeProperty();
                        equipmentComponentTypeProperty.MechanicalEquipmentComponentType = componentIn.MechanicalEquipmentComponentType; //note: set the object!
                        equipmentComponentTypeProperty.MechanicalEquipmentProperty = property; //not set the object!
                        mExistingEquipmentComponentTypeProperty.Add(equipmentComponentTypeProperty); //update cache
                    }
                    else
                    {
                        //ERROR!
                        RaiseMessage(CommonUtils.MessageType.Warning, string.Format("WorkSheet '{0}' Row '{1} Tag {2} Component Type {3}' : The property {4} does not belong to the Component Type.",
                            WorkSheetName, adapter.RowNumber, adapter.Tag, componentIn.MechanicalEquipmentComponentType.Name, property.Name));
                        continue;
                    }
                }
                property.MechanicalEquipmentComponentTypeProperties.Add(equipmentComponentTypeProperty);

                //CHECK PROPERTYVALUE EXISTS
                MechanicalPropertyValue propertyValue = null;
                if (mExistingPropertyValues.Any())
                {
                    propertyValue = (from x in mExistingPropertyValues
                        where x.MechanicalEquipmentComponent.Name.ToLower() == componentIn.Name.ToLower()
                              && x.MechanicalEquipmentProperty.Name.ToLower() == property.Name.ToLower()
                        select x).FirstOrDefault();
                }

                if (propertyValue == null)
                {
                    propertyValue = new MechanicalPropertyValue();
                    propertyValue.MechanicalEquipmentComponent = componentIn;
                    propertyValue.MechanicalEquipmentProperty = property;
                    mExistingPropertyValues.Add(propertyValue); //update cache
                }

                //set value
                if (!string.IsNullOrEmpty(pair.Value))
                {
                    propertyValue.Value = pair.Value.ChangeNullToEmptyString();
                }
                componentIn.MechanicalPropertyValues.Add(propertyValue);
            }
        }