Ejemplo n.º 1
0
        public bool GetElectricalEquipmentType(string typeName, ElectricalEquipment newEquipment, int rowIndex)
        {
            if (string.IsNullOrEmpty(typeName))
            {
                if (MetaData.ImportType == CommonUtils.ImportType.UpdateElectrical)
                {
                    return false;
                }
            }

            if (string.IsNullOrEmpty(typeName))
            {
                RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1}': Type row  is blank. Skipping.", WorkSheetName, rowIndex));
                return true;
            }

            ElectricalEquipmentType equipmentType = (from x in mExistingEquipmentTypes where string.Compare(x.Name, typeName, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault();
            if (equipmentType == null)
            {
                if (CanCreateProperties)
                {
                    equipmentType = new ElectricalEquipmentType { Name = typeName };
                    mExistingEquipmentTypes.Add(equipmentType);
                }
                else
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1}':Could not match '{2}' Mech Equip Type. Skipping.",
                        WorkSheetName, rowIndex, typeName));
                    return true;
                }
            }

            newEquipment.ElectricalEquipmentTypeId = equipmentType.Id;
            return false;
        }
        public AddEditElectricalEquipmentTypeModel()
        {
            mElectricalEquipmentType = new ElectricalEquipmentType();

            OkButtonCommand = new DelegateCommand<object>(OkButtonHander, CanModifyConfig);
            CancelButtonCommand = new DelegateCommand<object>(CancelButtonHander, x => true);
        }
        private void LoadData()
        {
            var getElectricalEquipmentTypesTask = DatabaseLoader.GetElectricalEquipmentTypes();
            var pidDocumentsTask = DatabaseLoader.GetQuickDocuments(CommonUtils.DoctypePidCode);
            var specificationDocumentsTask = DatabaseLoader.GetQuickDocuments(CommonUtils.DoctypeFuncspecCode);
            var getElectricalEquipmentComponentTypesTask = DatabaseLoader.GetElectricalEquipmentComponentTypes();
            var getManufacturersTask = DatabaseLoader.GetManufacturers(CommonUtils.EquipmentTypeCode.ELECT);
            var getModelsTask = DatabaseLoader.GetModels(CommonUtils.EquipmentTypeCode.ELECT);

            List<Task> tasks = new List<Task>();
            tasks.Add(getElectricalEquipmentTypesTask);
            tasks.Add(pidDocumentsTask);
            tasks.Add(specificationDocumentsTask);
            tasks.Add(getElectricalEquipmentComponentTypesTask);
            tasks.Add(getManufacturersTask);

            Task.Factory.ContinueWhenAll(tasks.ToArray(), x =>
            {
                CMS.UiFactory.StartNew(() =>
                {
                    //EquipmentType
                    var allItem = new ElectricalEquipmentType { Id = -1, Name = All };
                    EquipmentTypes = getElectricalEquipmentTypesTask.Result;
                    EquipmentTypes.Insert(0, allItem);
                    mSelectedEquipmentType = EquipmentTypes[0];

                    //Pid Documents
                    PandIDDocuments = pidDocumentsTask.Result;
                    PandIDDocuments.Insert(0, new QuickDocument { Id = -1, Name = All });
                    mSelectedPAndIdDocument = PandIDDocuments[0];

                    //Component Types
                    ComponentTypes = getElectricalEquipmentComponentTypesTask.Result;
                    ComponentTypes.Insert(0, new ElectricalEquipmentComponentType { Id = -1, Name = All });
                    mSelectedComponentType = ComponentTypes[0];

                    //Specification Documents
                    SpecificationDocuments = specificationDocumentsTask.Result;
                    SpecificationDocuments.Insert(0, new QuickDocument { Id = -1, Name = All });
                    mSelectedSpecificationDocument = SpecificationDocuments[0];

                    //Classified
                    Classifieds = new List<String> { All, Yes, No };
                    mSelectedClassified = Classifieds[0];

                    //Classified
                    IsActiveChoices = new List<String> { All, Yes, No };
                    mSelectedIsActive = IsActiveChoices[0];

                    //Model
                    mModelsCache = getModelsTask.Result;

                    //Manufacturer
                    Manufacturers = getManufacturersTask.Result;
                    Manufacturers.Insert(0, new Manufacturer { Id = -1, Name = All });
                    SelectedManufacturer = Manufacturers[0];

                    ProcessSearchFilter();

                    AllDataLoadedAction();
                });
            });

            LoadAreas();
            LoadSubAreas();
        }
Ejemplo n.º 4
0
        public ElectricalEquipmentType SaveElectricalEquipmentType(ElectricalEquipmentType electricalEquipmentType)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                ElectricalEquipmentType original = (from x in cee.ElectricalEquipmentTypes where x.Id == electricalEquipmentType.Id select x).FirstOrDefault();

                if (original == null)
                {
                    electricalEquipmentType.Code = electricalEquipmentType.Name.Replace(" ", "");
                    electricalEquipmentType.IsActive = true;
                    cee.ElectricalEquipmentTypes.Add(electricalEquipmentType);
                }
                else
                {
                    original.Name = electricalEquipmentType.Name;
                    original.Description = electricalEquipmentType.Description;
                    original.Code = electricalEquipmentType.Name.Replace(" ", "");
                    original.Ordinal = electricalEquipmentType.Ordinal;
                    original.IsActive = electricalEquipmentType.IsActive;
                }

                cee.SaveChanges();
            }
            return electricalEquipmentType;
        }
        private void SetControlValuesFromSearchFilterList(SearchFilterList searchFilterList)
        {
            mSearchFilterControl.SetFilterIsOn(true);
            ClearControls();

            //1. Manufacturer
            SearchFilter manufactuerFilter = (from x in searchFilterList.SearchFilters where x.Name.Equals(CommonUtils.ElectricalSearchFilterNames.Manufacturer.ToString(), StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault();
            if (manufactuerFilter != null)
            {
                int result;
                if (int.TryParse(manufactuerFilter.Value, out result))
                {
                    Manufacturer match = (from x in Manufacturers where x.Id == result select x).FirstOrDefault();
                    mSelectedManufacturer = match;
                    RaisePropertyChanged("SelectedManufacturer");
                }
            }

            //2. Model
            SearchFilter modelFilter = (from x in searchFilterList.SearchFilters where x.Name.Equals(CommonUtils.ElectricalSearchFilterNames.Model.ToString(), StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault();
            if (modelFilter != null)
            {
                int result;
                if (int.TryParse(modelFilter.Value, out result))
                {
                    Model match = (from x in mModelsCache where x.Id == result select x).FirstOrDefault();
                    mSelectedModel = match;
                    RaisePropertyChanged("SelectedModel");
                }
            }

            //1. Area
            SearchFilter areaFilter = (from x in searchFilterList.SearchFilters where x.Name.Equals(CommonUtils.ElectricalSearchFilterNames.Area.ToString(), StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault();
            if (areaFilter != null)
            {
                int result;
                if (int.TryParse(areaFilter.Value, out result))
                {
                    Area match = (from x in Areas where x.Id == result select x).FirstOrDefault();
                    mSelectedArea = match;
                    RaisePropertyChanged("SelectedArea");
                }
            }

            //2. SubArea
            SearchFilter subareaFilter = (from x in searchFilterList.SearchFilters where x.Name.Equals(CommonUtils.ElectricalSearchFilterNames.SubArea.ToString(), StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault();
            if (subareaFilter != null)
            {
                int result;
                if (int.TryParse(subareaFilter.Value, out result))
                {
                    Cell match = (from x in SubAreas where x.Id == result select x).FirstOrDefault();
                    mSelectedSubArea = match;
                    RaisePropertyChanged("SelectedSubArea");
                }
            }

            foreach (SearchFilter filter in searchFilterList.SearchFilters)
            {
                if (!string.IsNullOrEmpty(filter.Value))
                {
                    //KeyWords
                    if (filter.Name.Equals(CommonUtils.ElectricalSearchFilterNames.KeyWord.ToString(), StringComparison.CurrentCultureIgnoreCase))
                    {
                        mKeyword = filter.Value;
                        RaisePropertyChanged("Keyword");
                    }

                    //KeyWords
                    if (filter.Name.Equals(CommonUtils.ElectricalSearchFilterNames.MaintSystemId.ToString(), StringComparison.CurrentCultureIgnoreCase))
                    {
                        mMainSystId = filter.Value;
                        RaisePropertyChanged("MainSystId");
                    }

                    //Classified
                    if (filter.Name.Equals(CommonUtils.ElectricalSearchFilterNames.Classified.ToString(), StringComparison.CurrentCultureIgnoreCase))
                    {
                        //For compatibility as previously it was saved as Id
                        if (filter.Value == "-1") filter.Value = All;
                        if (filter.Value == "-2") filter.Value = Yes;
                        if (filter.Value == "-3") filter.Value = No;

                        var match = (from x in Classifieds where x == filter.Value select x).FirstOrDefault();
                        mSelectedClassified = match;
                        RaisePropertyChanged("Classified");
                    }

                    //Type
                    if (filter.Name.Equals(CommonUtils.ElectricalSearchFilterNames.Type.ToString(), StringComparison.CurrentCultureIgnoreCase))
                    {
                        int result;
                        if (int.TryParse(filter.Value, out result))
                        {
                            ElectricalEquipmentType match = (from x in EquipmentTypes where x.Id == result select x).FirstOrDefault();
                            mSelectedEquipmentType = match;
                            RaisePropertyChanged("SelectedEquipmentType");
                        }
                    }

                    //ComponentType
                    if (filter.Name.Equals(CommonUtils.ElectricalSearchFilterNames.ComponentType.ToString(), StringComparison.CurrentCultureIgnoreCase))
                    {
                        int result;
                        if (int.TryParse(filter.Value, out result))
                        {
                            ElectricalEquipmentComponentType match = (from x in ComponentTypes where x.Id == result select x).FirstOrDefault();
                            mSelectedComponentType = match;
                            RaisePropertyChanged("SelectedComponentType");
                        }
                    }

                    //IsActive
                    if (filter.Name.Equals(CommonUtils.ElectricalSearchFilterNames.IsActive.ToString(), StringComparison.CurrentCultureIgnoreCase))
                    {
                        //For compatibility as previously it was saved as Id
                        if (filter.Value == "-1") filter.Value = All;
                        if (filter.Value == "-2") filter.Value = Yes;
                        if (filter.Value == "-3") filter.Value = No;

                        var match = (from x in IsActiveChoices where x == filter.Value select x).FirstOrDefault();
                        mSelectedIsActive = match;
                        RaisePropertyChanged("SelectedIsActive");

                    }

                    //PidDocument
                    if (filter.Name.Equals(CommonUtils.ElectricalSearchFilterNames.PidDocument.ToString(), StringComparison.CurrentCultureIgnoreCase))
                    {
                        int result;
                        if (int.TryParse(filter.Value, out result))
                        {
                            QuickDocument match = (from x in PandIDDocuments where x.Id == result select x).FirstOrDefault();
                            mSelectedPAndIdDocument = match;
                            RaisePropertyChanged("SelectedPAndIdDocument");
                        }
                    }

                    //Specification
                    if (filter.Name.Equals(CommonUtils.ElectricalSearchFilterNames.Specification.ToString(), StringComparison.CurrentCultureIgnoreCase))
                    {
                        int result;
                        if (int.TryParse(filter.Value, out result))
                        {
                            QuickDocument match = (from x in SpecificationDocuments where x.Id == result select x).FirstOrDefault();
                            mSelectedSpecificationDocument = match;
                            RaisePropertyChanged("SelectedSpecificationDocument");
                        }
                    }
                }
            }

            ProcessSearchFilter();
        }
        private void ClearControls()
        {
            mKeyword = string.Empty;
            RaisePropertyChanged("Keyword");

            mSelectedArea = Areas[0];
            RaisePropertyChanged("SelectedArea");

            mMainSystId = string.Empty;
            RaisePropertyChanged("MainSystId");

            mSelectedEquipmentType = EquipmentTypes[0];
            RaisePropertyChanged("SelectedEquipmentType");

            mSelectedSubArea = SubAreas[0];
            RaisePropertyChanged("SelectedSubArea");

            mSelectedPAndIdDocument = PandIDDocuments[0];
            RaisePropertyChanged("SelectedPAndIdDocument");

            mSelectedComponentType = ComponentTypes[0];
            RaisePropertyChanged("SelectedComponentType");

            mSelectedSpecificationDocument = SpecificationDocuments[0];
            RaisePropertyChanged("SelectedSpecificationDocument");

            mSelectedClassified = Classifieds[0];
            RaisePropertyChanged("Classified");

            mSelectedIsActive = IsActiveChoices[0];
            RaisePropertyChanged("SelectedIsActive");

            mSelectedManufacturer = Manufacturers[0];
            RaisePropertyChanged("SelectedManufacturer");

            mSelectedModel = Models[0];
            RaisePropertyChanged("SelectedModel");

            mSelectedPAndIdDocument = PandIDDocuments[0];
            RaisePropertyChanged("SelectedPAndIDDocument");
        }
 private void cmsWebServiceClient_GetElectricalEquipmentTypeCompleted(object sender, GetElectricalEquipmentTypeCompletedEventArgs e)
 {
     mElectricalEquipmentType = e.Result;
     OnDataSourceLoaded();
 }