public PipeComponentTypeViewModel() { mPipeComponentType = new PipeComponentType(); PopulateAreas(); OkButtonCommand = new DelegateCommand<object>(OkButtonHander, CanExecuteOkButtonHandler); CancelButtonCommand = new DelegateCommand<object>(CancelButtonHander, x => true); }
public PipeComponentTypeViewModel(int id) { PopulateAreas(); OkButtonCommand = new DelegateCommand<object>(OkButtonHander, CanExecuteOkButtonHandler); CancelButtonCommand = new DelegateCommand<object>(CancelButtonHander, x => true); var cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint); cmsWebServiceClient.GetPipeComponentTypeCompleted += (s1, e1) => { mPipeComponentType = e1.Result; if (DataLoaded != null) { DataLoaded(); } }; cmsWebServiceClient.GetPipeComponentTypeAsync(id); }
private void SetControlValuesFromSearchFilterList(SearchFilterList searchFilterList) { mSearchFilterControl.SetFilterIsOn(true); ClearControls(); //1. Manufacturer SearchFilter manufactuerFilter = (from x in searchFilterList.SearchFilters where x.Name.Equals(CommonUtils.PipeSearchFilterNames.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.PipeSearchFilterNames.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.PipeSearchFilterNames.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.PipeSearchFilterNames.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.PipeSearchFilterNames.KeyWord.ToString(), StringComparison.CurrentCultureIgnoreCase)) { mKeyword = filter.Value; RaisePropertyChanged("Keyword"); } //PipeClass if (filter.Name.Equals(CommonUtils.PipeSearchFilterNames.Class.ToString(), StringComparison.CurrentCultureIgnoreCase)) { int result; if (int.TryParse(filter.Value, out result)) { var match = (from x in PipeClasses where x.Id == result select x).FirstOrDefault(); mSelectedPipeClass = match; RaisePropertyChanged("SelectedPipeClass"); } } //PipeSize if (filter.Name.Equals(CommonUtils.PipeSearchFilterNames.Size.ToString(), StringComparison.CurrentCultureIgnoreCase)) { int result; if (int.TryParse(filter.Value, out result)) { var match = (from x in PipeSizes where x.Id == result select x).FirstOrDefault(); mSelectedPipeSize = match; RaisePropertyChanged("SelectedPipeSize"); } } //PipeFluidCode if (filter.Name.Equals(CommonUtils.PipeSearchFilterNames.FluidCode.ToString(), StringComparison.CurrentCultureIgnoreCase)) { int result; if (int.TryParse(filter.Value, out result)) { var match = (from x in PipeFluidCodes where x.Id == result select x).FirstOrDefault(); mSelectedPipeFluidCode = match; RaisePropertyChanged("SelectedPipeFluidCode"); } } //PipeSpecialFeature if (filter.Name.Equals(CommonUtils.PipeSearchFilterNames.SpecialFeature.ToString(), StringComparison.CurrentCultureIgnoreCase)) { int result; if (int.TryParse(filter.Value, out result)) { var match = (from x in PipeSpecialFeatures where x.Id == result select x).FirstOrDefault(); mSelectedPipeSpecialFeature = match; RaisePropertyChanged("SelectedPipeSpecialFeature"); } } //PidDocument if (filter.Name.Equals(CommonUtils.PipeSearchFilterNames.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"); } } //ComponentType if (filter.Name.Equals(CommonUtils.PipeSearchFilterNames.ComponentType.ToString(), StringComparison.CurrentCultureIgnoreCase)) { int result; if (int.TryParse(filter.Value, out result)) { PipeComponentType match = (from x in ComponentTypes where x.Id == result select x).FirstOrDefault(); mSelectedComponentType = match; RaisePropertyChanged("SelectedComponentType"); } } //IsActive if (filter.Name.Equals(CommonUtils.PipeSearchFilterNames.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"); } } } ProcessSearchFilter(); }
private void LoadData() { var getPipeClassesTask = DatabaseLoader.GetPipeClasses(); var getPipeSizesTask = DatabaseLoader.GetPipeSizes(); var getPipeFluidCodesTask = DatabaseLoader.GetPipeFluidCodes(); var getPipeSpecialFeaturesTask = DatabaseLoader.GetPipeSpecialFeatures(); var pidDocumentsTask = DatabaseLoader.GetQuickDocuments(CommonUtils.DoctypePidCode); var getPipeComponentTypesTask = DatabaseLoader.GetPipeComponentTypes(); var getManufacturersTask = DatabaseLoader.GetManufacturers(CommonUtils.EquipmentTypeCode.PIPE); var getModelsTask = DatabaseLoader.GetModels(CommonUtils.EquipmentTypeCode.PIPE); List<Task> tasks = new List<Task>(); tasks.Add(getPipeClassesTask); tasks.Add(getPipeSizesTask); tasks.Add(getPipeFluidCodesTask); tasks.Add(getPipeSpecialFeaturesTask); tasks.Add(pidDocumentsTask); tasks.Add(getPipeComponentTypesTask); tasks.Add(getManufacturersTask); Task.Factory.ContinueWhenAll(tasks.ToArray(), x => { CMS.UiFactory.StartNew(() => { //Pipe Classes PipeClasses = getPipeClassesTask.Result; PipeClasses.Insert(0, new PipeClass { Id = -1, Name = All }); mSelectedPipeClass = PipeClasses[0]; RaisePropertyChanged("PipeClasses"); RaisePropertyChanged("SelectedPipeClass"); //Pipe Sizes PipeSizes = getPipeSizesTask.Result; PipeSizes.Insert(0, new PipeSize { Id = -1, Name = All }); mSelectedPipeSize = PipeSizes[0]; RaisePropertyChanged("PipeSizes"); RaisePropertyChanged("SelectedPipeSize"); //Pipe FluidCodes PipeFluidCodes = getPipeFluidCodesTask.Result; PipeFluidCodes.Insert(0, new PipeFluidCode { Id = -1, Name = All }); mSelectedPipeFluidCode = PipeFluidCodes[0]; RaisePropertyChanged("PipeFluidCodes"); RaisePropertyChanged("SelectedPipeFluidCode"); //Pipe SpecialFeatures PipeSpecialFeatures = getPipeSpecialFeaturesTask.Result; PipeSpecialFeatures.Insert(0, new PipeSpecialFeature { Id = -1, Name = All }); mSelectedPipeSpecialFeature = PipeSpecialFeatures[0]; RaisePropertyChanged("PipeSpecialFeatures"); RaisePropertyChanged("SelectedPipeSpecialFeature"); //Pid Documents PandIDDocuments = pidDocumentsTask.Result; PandIDDocuments.Insert(0, new QuickDocument { Id = -1, Name = All }); mSelectedPAndIdDocument = PandIDDocuments[0]; RaisePropertyChanged("PandIDDocuments"); RaisePropertyChanged("SelectedPAndIdDocument"); //Component Types ComponentTypes = getPipeComponentTypesTask.Result; ComponentTypes.Insert(0, new PipeComponentType { Id = -1, Name = All }); mSelectedComponentType = ComponentTypes[0]; RaisePropertyChanged("ComponentTypes"); RaisePropertyChanged("SelectedComponentType"); //Model mModelsCache = getModelsTask.Result; //Manufacturer Manufacturers = getManufacturersTask.Result; Manufacturers.Insert(0, new Manufacturer { Id = -1, Name = All }); SelectedManufacturer = Manufacturers[0]; RaisePropertyChanged("Manufacturers"); RaisePropertyChanged("SelectedManufacturer"); //Classified IsActiveChoices = new List<String> { All, Yes, No }; mSelectedIsActive = IsActiveChoices[0]; RaisePropertyChanged("IsActiveChoices"); RaisePropertyChanged("SelectedIsActive"); SetUpFilteredLinkControl(); InitialiseSearchFilterControl(CommonUtils.TabId.Piping); }); }); LoadAreas(); LoadSubAreas(); }
private void ClearControls() { mKeyword = string.Empty; RaisePropertyChanged("Keyword"); mSelectedArea = Areas[0]; RaisePropertyChanged("SelectedArea"); mSelectedSubArea = SubAreas[0]; RaisePropertyChanged("SelectedSubArea"); mSelectedPipeClass = PipeClasses[0]; RaisePropertyChanged("SelectedPipeClass"); mSelectedPipeSize = PipeSizes[0]; RaisePropertyChanged("SelectedPipeSize"); mSelectedPipeFluidCode = PipeFluidCodes[0]; RaisePropertyChanged("SelectedPipeFluidCode"); mSelectedPipeSpecialFeature = PipeSpecialFeatures[0]; RaisePropertyChanged("SelectedPipeSpecialFeature"); mSelectedPAndIdDocument = PandIDDocuments[0]; RaisePropertyChanged("SelectedPAndIdDocument"); mSelectedComponentType = ComponentTypes[0]; RaisePropertyChanged("SelectedComponentType"); mSelectedManufacturer = Manufacturers[0]; RaisePropertyChanged("SelectedManufacturer"); mSelectedModel = Models[0]; RaisePropertyChanged("SelectedModel"); mSelectedIsActive = IsActiveChoices[0]; RaisePropertyChanged("SelectedIsActive"); }
public DbOperationResult<PipeComponentType> AddEditPipeComponentType(PipeComponentType pipeComponentType) { DbOperationResult<PipeComponentType> result = new DbOperationResult<PipeComponentType>(); try { if (!pipeComponentType.InheritArea && pipeComponentType.Area == null) { throw new Exception("Area has not been set and InheritArea is false."); } PipeComponentType newPct = new PipeComponentType(); using (CmsEntities cee = new CmsEntities()) { //Check if this component type already exist PipeComponentType pct = (from x in cee.PipeComponentTypes where x.Id == pipeComponentType.Id select x).FirstOrDefault(); if (pct != null) { //Edit the Component Type pct.Name = pipeComponentType.Name; pct.Description = pipeComponentType.Description; pct.Code = pipeComponentType.Code; pct.Ordinal = pipeComponentType.Ordinal; pct.InheritArea = pipeComponentType.InheritArea; pct.DefaultAreadId = pipeComponentType.DefaultAreadId; cee.SaveChanges(); } else { //Add new Component Type pct = new PipeComponentType { Name = pipeComponentType.Name, Description = pipeComponentType.Description, Code = pipeComponentType.Code, Ordinal = pipeComponentType.Ordinal, InheritArea = pipeComponentType.InheritArea }; if (pipeComponentType.Area != null) { pct.DefaultAreadId = pipeComponentType.Area.Id; } cee.PipeComponentTypes.Add(pct); cee.SaveChanges(); } newPct.Id = pct.Id; newPct.Name = pct.Name; newPct.Description = pct.Description; newPct.Ordinal = pct.Ordinal; newPct.DefaultAreadId = pct.DefaultAreadId; newPct.InheritArea = pct.InheritArea; result.EntityResult = newPct; return result; } } catch (Exception ex) { return BuildOperationalErrorResults<PipeComponentType>(ex); } }
private void SetAreaByComponentTypeOrPipe(PipeComponentType pipeComponentType) { if (pipeComponentType.DefaultAreadId.HasValue) { SelectedArea = (from x in Areas where x.Id == pipeComponentType.DefaultAreadId.Value select x).FirstOrDefault(); } else { SelectedArea = (from x in Areas where x.Id == mPipeComponent.Pipe.AreaId select x).FirstOrDefault(); } RaisePropertyChanged("SelectedArea"); RaisePropertyChanged("Name"); }
private void PopulateData() { List<Area> areas = (from x in CMS.Cache.Areas where x.IsActive && x.SiteId == CMS.AppSetting.DefaultSiteId select x).ToList(); Areas = areas; RaisePropertyChanged("Areas"); var cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint); cmsWebServiceClient.GetPipeComponentTypesCompleted += (s, e) => { ComponentTypes = e.Result; //If the component type was not set pick first one if (mPipeComponent.PipeComponentType == null) { InEditMode = false; mPipeComponent.PipeComponentType = ComponentTypes[0]; SetAreaByComponentTypeOrPipe(ComponentTypes[0]); } else { mOriginalComponentType = mPipeComponent.PipeComponentType; mOriginalSubArea = mPipeComponent.SubArea; mOriginalNumber = mPipeComponent.Number; mOriginalDescription = mPipeComponent.Description; } SelectedComponentType = ComponentTypes.FirstOrDefault(x => x.Id == mPipeComponent.PipeComponentType.Id); SetAreaByComponentTypeOrPipe(SelectedComponentType); RaisePropertyChanged("ComponentTypes"); RaisePropertyChanged("SelectedComponentType"); SelectedSubArea = mPipeComponent.SubArea; SelectedNumber = mPipeComponent.Number; if (Loaded != null) { Loaded(); RaisePropertyChanged("Name"); } }; cmsWebServiceClient.GetPipeComponentTypesAsync(); }
private void InsertData(IList<PipeComponentDataAdapter> adapters) { for (int index = 0; index < adapters.Count; index++) { PipeComponentDataAdapter adapter = adapters[index]; if (!adapter.IsValid()) { continue; } var newComponent = new PipeComponent(); newComponent.LastModifiedDate = DateTime.Now; newComponent.LastModifiedById = MetaData.UserId; Pipe pipeOut; if (GetPipe(adapter, index, out pipeOut)) { continue; } //Pipe newComponent.Pipe = pipeOut; //Number if (adapter.ComponentNumber.HasValue) { newComponent.Number = adapter.ComponentNumber.Value; } //AREA int areaId; if (GetAreaFailed(adapter.ComponentAreaNumber, 0+1, out areaId, false)) { continue; } if (areaId > 0) { newComponent.AreaId = areaId; } //SubArea if (adapter.ComponentSubArea.HasValue) { newComponent.SubArea = adapter.ComponentSubArea.Value; } //ComponentType PipeComponentType pipeComponentType; if (GetPipeComponentType(adapter.ComponentType, index, out pipeComponentType)) { if (!CanCreateProperties) { continue; } string code = adapter.ComponentType.Replace(" ", "_").ToUpper(); var componentType = new PipeComponentType {Name = adapter.ComponentType, Code = code, Description = "(created by importer)"}; newComponent.PipeComponentType = componentType; } else { newComponent.PipeComponentType = pipeComponentType; } //CHECK UNIQUE if (!ComponentIsUnique(newComponent, index)) { continue; } newComponent.Description = adapter.ComponentDescription; newComponent.SpecialFeature = false; //have to set something newComponent.Ordinal = 0; //have to set something bool skipRow = ChangeManufacturerModel(adapter, newComponent); if (skipRow) continue; BuildPropertyValues(newComponent, adapter, index); Cee.PipeComponents.Add(newComponent); mSavedResults.Add(newComponent); const decimal incrediment = 0.001m; decimal revision = new decimal(1.000); List<decimal> foo = (from x in Cee.PipeRevisionHistories where x.PipeId == newComponent.PipeId orderby x.Revision descending select x.Revision).ToList(); if (foo.Count > 0) { revision = foo[0] + incrediment; } newComponent.Pipe.PipeRevisionHistories.Add(new PipeRevisionHistory { Date = DateTime.Now, PipeId = newComponent.PipeId, UserId = MetaData.UserId, Description = BuildRevisionHistoryInsertComment(MetaData.RevisionHistoryComment), IsSystemMessage = true, Revision = revision }); } //|--- S A V E Cee.SaveChanges(); if (mSavedResults.Count == 0) { RaiseMessage(CommonUtils.MessageType.Warning, string.Format("No Pipe Components were added from from worksheet {0}.", WorkSheetName)); return; } foreach (PipeComponent result in mSavedResults) { RaiseMessage(CommonUtils.MessageType.Added, string.Format("Added Pipe Component {0} from worksheet {1}.", result.Name, WorkSheetName)); } }
private bool GetPipeComponentType(string componentTypeName, int rowIndex, out PipeComponentType componentTypeOut) { componentTypeOut = null; PipeComponentType componentType = (from x in mExistingComponentTypes where string.Compare(componentTypeName, x.Code, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault(); if (componentType == null && !CanCreateProperties) { RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Line '{1}': Could not find PipeComponentType '{2}' in database. Skipping this row.", WorkSheetName, rowIndex, componentType)); return true; } componentTypeOut = componentType; return false; }
private void OkButtonHander(object parameter) { if (AreAllValid()) { if (mPipeComponentType.DefaultAreadId==-99) { mPipeComponentType.DefaultAreadId = null; mPipeComponentType.Area = null; } //save var cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint); cmsWebServiceClient.AddEditPipeComponentTypeCompleted += (s1, e1) => { if (e1.Result != null) { if (e1.Result.HasErrors) { if (e1.Result.HasErrors) { var errorDialog = new PopupDialog(PopupDialogType.Error, Utils.DisplayErrorMessages(e1.Result.ServerErrorMessages)); errorDialog.Show(); View.DialogResult = false; } } else { mPipeComponentType = e1.Result.EntityResult; View.PipeComponentType = mPipeComponentType; View.DialogResult = true; } } else { MessageBox.Show("Save Failed."); View.DialogResult = false; } }; cmsWebServiceClient.AddEditPipeComponentTypeAsync(mPipeComponentType); } }