public AddEditPipeComponentDialog(Pipe pipe, PipeComponent pipeComponent)
        {
            InitializeComponent();

            Title = "Edit Pipe Component";

            mModel = new AddEditPipeComponentViewModel(pipeComponent, pipe.PipeComponents.Select(x => x.Name).ToList()) { View = this };
            mModel.Loaded += () =>
            {
                DataContext = mModel;
                Utils.ResetOriginalValues(this);
            };
        }
        public AddEditPipeComponentViewModel(Pipe pipe, IList<string> existingNonSavedComponents)
        {
            //NEW
            InEditMode = false;
            ExistingComponentNames = existingNonSavedComponents;

            OKButton = new DelegateCommand<object>(OKButtonHandler, CanAddHandler);
            CancelButton = new DelegateCommand<object>(CancelButtonHandler, CanAddHandler);

            mPipeComponent = new PipeComponent {Pipe = pipe, PipeId = pipe.Id};

            PopulateData();
        }
        public AddEditPipeComponentViewModel(PipeComponent pc, IList<String> existingNonSavedComponents)
        {
            //EDIT
            InEditMode = true;
            OKButton = new DelegateCommand<object>(OKButtonHandler, CanAddHandler);
            CancelButton = new DelegateCommand<object>(CancelButtonHandler, CanAddHandler);
            ExistingComponentNames = existingNonSavedComponents;
            EditingName = pc.Name;
            mPipeComponent = pc;
            OriginalName = Name;
            PopulateData();

            if (pc.PipeComponentType.DefaultAreadId.HasValue)
            {
                SelectedArea = (from x in Areas where x.Id == pc.PipeComponentType.DefaultAreadId.Value select x).FirstOrDefault();
                RaisePropertyChanged("SelectedArea");
            }
        }
        public PipePropertiesControl(PipeComponent controlSystemComponent)
        {
            if (DesignerProperties.IsInDesignTool) { return; }

            InitializeComponent();
            CompositionInitializer.SatisfyImports(this);
            mPipeComponent = controlSystemComponent;

            ComponentName = mPipeComponent.Name;

            mViewModel = new PipePropertiesViewModel(mPipeComponent);
            mViewModel.Loaded += () =>
            {
                PopulatePropertyValues(controlSystemComponent);
                DataContext = mViewModel;

                ManufacturerComboBox.ResetOriginalValue();
                ManufacturerComboBox.ControlChanged += ControlChanged;

                ModelComboBox.ResetOriginalValue();
                ModelComboBox.ControlChanged += ControlChanged;
            };
        }
예제 #5
0
        private bool ChangeManufacturerModel(PipeComponentDataAdapter adapter, PipeComponent 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;
        }
        private void CreateAndBindDynamicProperties(PipeComponent pipeComponent, List<String> pidDocuments, List<String> specDocuments)
        {
            int rowCount = 5;

            var controlSystemComponentProperies = pipeComponent.PipeComponentType.PipeComponentTypeProperties.OrderBy(x => x.Ordinal).ToList();

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
            cmsWebServiceClient.GetAllPropertyListsCompleted += (s, e) =>
            {
                foreach (var controlSystemComponentProperty in controlSystemComponentProperies.Where(x => x.PipeProperty.IsVisible))
                {

                    Label label = new Label();

                    Binding labelBinding = new Binding("Name")
                    {
                        Mode = BindingMode.OneTime,
                        Source = controlSystemComponentProperty.PipeProperty
                    };

                    label.SetBinding(ContentControl.ContentProperty, labelBinding);
                    label.VerticalAlignment = VerticalAlignment.Center;
                    label.Margin = new Thickness(1);

                    PropertiesGrid.Children.Add(label);
                    Grid.SetRow(label, rowCount);
                    Grid.SetColumn(label, 0);

                    var propertyValue = GetPropertyValue(pipeComponent, controlSystemComponentProperty);

                    var element = Utils.BindElement(controlSystemComponentProperty.PipeProperty, propertyValue,
                        e.Result, ComponentPropertyWrapViewModels, ControlChanged, pidDocuments,specDocuments);

                    PropertiesGrid.Children.Add(element);
                    Grid.SetRow((FrameworkElement)element, rowCount);
                    Grid.SetColumn((FrameworkElement)element, 1);

                    PropertiesGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(element.Height + 2) });

                    rowCount++;
                }

                LastInspectedTextBox.ResetOriginalValue();
                LastInspectedTextBox.ControlChanged += ControlChanged;

                NextInspectionTextBox.ResetOriginalValue();
                NextInspectionTextBox.ControlChanged += ControlChanged;
            };
            cmsWebServiceClient.GetAllPropertyListsAsync();
        }
예제 #7
0
파일: Form1.cs 프로젝트: barrett2474/CMS2
        private bool GetPipeComponent(Worksheet worksheet, string pipeComponentName, ref PipeComponent newPipeComponent, int rowIndex)
        {
            bool skipRow = false;

            if (!String.IsNullOrEmpty(pipeComponentName))
            {
                //Check if the Pipe Component exist in the database
                PipeComponent pipeComponent = mExistingPipeComponents.Where(x => x.Name.ToLower() == pipeComponentName.Trim().ToLower()).FirstOrDefault();
                if (pipeComponent != null)
                {
                    newPipeComponent = pipeComponent;
                }
                else
                {
                    //Pipe Component doesnt exist in the database lets create it
                    //Pipe Component format: 611-SPL-1-001 where 611 is Area, SPL is Component Type, 1 is Sub Area and 001 is Number
                    string[] pipeComponentNameSplitted = pipeComponentName.Split('-');

                    if (pipeComponentNameSplitted.Count() == 4)
                    {
                        int subArea = -1;
                        int number = -1;
                        string area = pipeComponentNameSplitted[0];
                        string componentTypeCode = pipeComponentNameSplitted[1];
                        Int32.TryParse(pipeComponentNameSplitted[2], out subArea);
                        Int32.TryParse(pipeComponentNameSplitted[3], out number);

                        if (area.Trim().ToLower().Equals(newPipeComponent.Pipe.Area.Name.ToLower()))
                        {
                            var componentType = (from x in mExistingPipeComponentTypes where x.Code.ToLower() == componentTypeCode.ToLower() select x).FirstOrDefault();

                            if (componentType != null)
                            {
                                //Add new Pipe Component
                                newPipeComponent.PipeComponentType = componentType;
                                newPipeComponent.ComponentTypeId = componentType.Id;
                                newPipeComponent.SubArea = subArea;
                                newPipeComponent.Number = number;

                                mCee.PipeComponents.AddObject(newPipeComponent);
                                mCee.SaveChanges();

                                mExistingPipeComponents.Add(newPipeComponent);

                                AddMessage(MessageType.Added, String.Format("WorkSheet '{0}' Line '{1}': Added Pipe Component Name '{2}'.", worksheet.Name, rowIndex, pipeComponentName));
                            }
                            else
                            {
                                AddMessage(MessageType.Error, String.Format("WorkSheet '{0}' Line '{1}': Component Type Code '{2}' does not exist in Database. Skipping this row.", worksheet.Name, rowIndex, componentType));
                                skipRow = true;
                            }
                        }
                        else
                        {
                            AddMessage(MessageType.Error, String.Format("WorkSheet '{0}' Line '{1}': Component Area '{2}' does not match Pipe Area '{3}'. Skipping this row.",
                                                                        worksheet.Name, rowIndex, pipeComponentName, newPipeComponent.Pipe.Area.Name));
                            skipRow = true;
                        }
                    }
                    else
                    {
                        AddMessage(MessageType.Warning, String.Format("WorkSheet '{0}' Line '{1}': Pipe Component Name '{2}' is not in correct format. Skipping this row.", worksheet.Name, rowIndex, pipeComponentName));
                        skipRow = true;
                    }
                }
            }
            else
            {
                AddMessage(MessageType.Warning, String.Format("WorkSheet '{0}' Line '{1}': Pipe Name is empty. Skipping this row.", worksheet.Name, rowIndex));
                skipRow = true;
            }
            return skipRow;
        }
예제 #8
0
 private void GetDrawing(Worksheet worksheet, string drawing, PipeComponent newPipeComponent, int rowIndex)
 {
     if (!string.IsNullOrEmpty(drawing))
     {
         //Check if the Area exist in the database
         CmsEquipmentDatabase.CmsWebService.Document document = mDrawings.Where(x => x.Name.ToLower() == drawing.Trim().ToLower()).FirstOrDefault();
         if (document != null)
         {
             newPipeComponent.DrawingId = document.Id;
         }
         else
         {
             RaiseMessage(MessageType.Warning, string.Format("WorkSheet '{0}' Line '{1}': Could not find drawing '{2}' in database.", worksheet.Name, rowIndex, drawing));
         }
     }
     else
     {
         RaiseMessage(MessageType.Warning, string.Format("WorkSheet '{0}' Line '{1}': Drawing is empty.", worksheet.Name, rowIndex));
     }
 }
예제 #9
0
파일: Form1.cs 프로젝트: barrett2474/CMS2
        private bool GetPipe(Worksheet worksheet, string pipeName, PipeComponent newPipeComponent, int rowIndex)
        {
            bool skipRow = false;

            if (!String.IsNullOrEmpty(pipeName))
            {
                //Check if the Area exist in the database
                Pipe pipe = mExistingPipes.Where(x => x.Name.ToLower() == pipeName.Trim().ToLower()).FirstOrDefault();
                if (pipe != null)
                {
                    newPipeComponent.Pipe = pipe;
                    newPipeComponent.PipeId = pipe.Id;
                }
                else
                {
                    AddMessage(MessageType.Error, String.Format("WorkSheet '{0}' Line '{1}': Could not find pipe '{2}' in database. Skipping this row.", worksheet.Name, rowIndex, pipeName));
                    skipRow = true;
                }
            }
            else
            {
                AddMessage(MessageType.Warning, String.Format("WorkSheet '{0}' Line '{1}': Pipe Name is empty. Skipping this row.", worksheet.Name, rowIndex));

                skipRow = true;
            }
            return skipRow;
        }
예제 #10
0
        private void SavePipeComponents(Pipe pipe, CmsEntities cee, int pipeId, int userId)
        {
            foreach (var pipeComponent in pipe.PipeComponents)
            {
                var q = (from x in cee.PipeComponents
                         where x.Id == pipeComponent.Id
                         select x).FirstOrDefault();

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

                        AddPipeRevisionHistoryInternal(rv, cee);
                    }

                    //Update Pipe Componet
                    cee.Entry(q).CurrentValues.SetValues(pipeComponent);
                }
                else
                {
                    q = new PipeComponent
                    {
                        PipeId = pipeComponent.PipeId,
                        PipeComponentTypeId = pipeComponent.PipeComponentTypeId,
                        SpecialFeature = pipeComponent.SpecialFeature,
                        Ordinal = pipeComponent.Ordinal,
                        Description = pipeComponent.Description,
                        SubArea = pipeComponent.SubArea,
                        Number = pipeComponent.Number,
                        DrawingId = pipeComponent.DrawingId,
                        NextInspectionDate = pipeComponent.NextInspectionDate,
                        LastInspectedById = pipeComponent.LastInspectedById,
                        LastInspectedDate = pipeComponent.LastInspectedDate,
                        LastModifiedDate = pipeComponent.LastModifiedDate,
                        LastModifiedById = pipeComponent.LastModifiedById,
                        ManufacturerId = pipeComponent.ManufacturerId,
                        ModelId = pipeComponent.ModelId,
                        AreaId = pipeComponent.AreaId
                    };

                    //Add new Pipe Component
                    cee.PipeComponents.Add(q);
                }

                foreach (var pipeComponentPropertyValue in pipeComponent.PipePropertyValues)
                {
                    var qq = (from x in cee.PipePropertyValues
                              where x.Id == pipeComponentPropertyValue.Id
                              select x).FirstOrDefault();

                    if (qq != null)
                    {
                        cee.Entry(qq).CurrentValues.SetValues(pipeComponentPropertyValue);
                    }
                    else
                    {
                        cee.PipePropertyValues.Add(pipeComponentPropertyValue);
                    }
                }
            }
            cee.SaveChanges();
        }
예제 #11
0
        private bool GetPipe(Worksheet worksheet, LineNumberParser parser, PipeComponent newPipeComponent, int rowIndex)
        {
            bool skipRow = false;

            //Check if the Area exist in the database
            Pipe pipe = (from x in mExistingPipes where string.Compare(parser.Name.Trim(), x.Name, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault();

            if (pipe != null)
            {
                newPipeComponent.Pipe = pipe;
                newPipeComponent.PipeId = pipe.Id;
            }
            else
            {
                RaiseMessage(MessageType.Error, string.Format("WorkSheet '{0}' Line '{1}': Could not find pipe '{2}' in database. Skipping this row.", worksheet.Name, rowIndex, parser.Name));
                skipRow = true;
            }

            return skipRow;
        }
예제 #12
0
        private PipeComponent CloneComponent(PipeComponent selectedComponent)
        {
            PipeComponent clone = new PipeComponent();
            clone.Id = selectedComponent.Id;
            clone.PipeId = selectedComponent.PipeId;
            clone.Pipe = selectedComponent.Pipe;
            clone.PipeComponentTypeId = selectedComponent.PipeComponentTypeId;
            clone.Name = selectedComponent.Name;
            clone.Description = selectedComponent.Description;
            clone.Ordinal = selectedComponent.Ordinal;
            clone.LastModifiedById = selectedComponent.LastModifiedById;
            clone.SpecialFeature = selectedComponent.SpecialFeature;
            clone.Ordinal = selectedComponent.Ordinal;
            clone.SubArea = selectedComponent.SubArea;
            clone.Number = selectedComponent.Number;
            clone.DrawingId = selectedComponent.DrawingId;
            clone.LastModifiedById = selectedComponent.LastModifiedById;
            clone.LastModifiedDate = selectedComponent.LastModifiedDate;
            clone.NextInspectionDate = selectedComponent.NextInspectionDate;
            clone.LastInspectedById = selectedComponent.LastInspectedById;
            clone.LastInspectedDate = selectedComponent.LastInspectedDate;

            clone.PipePropertyValues = new List<PipePropertyValue>();

            foreach (var pipePropertyValue in selectedComponent.PipePropertyValues)
            {
                clone.PipePropertyValues.Add(new PipePropertyValue
                {
                    PipePropertyId = pipePropertyValue.PipePropertyId,
                    ComponentId = pipePropertyValue.ComponentId,
                    Value = pipePropertyValue.Value
                });
            }

            return clone;
        }
예제 #13
0
        public PipeComponent SavePipeComponent(PipeComponent pipeComponent)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                var q = (from x in cee.PipeComponents
                         where x.Id == pipeComponent.Id
                         select x).FirstOrDefault();

                if (q != null)
                {
                    //Update Pipe Componet
                    q.PipeComponentTypeId = pipeComponent.PipeComponentTypeId;
                    q.SpecialFeature = pipeComponent.SpecialFeature;
                    q.SubArea = pipeComponent.SubArea;
                    q.Number = pipeComponent.Number;
                    q.NextInspectionDate = pipeComponent.NextInspectionDate;
                    q.LastInspectedById = pipeComponent.LastInspectedById;
                    q.LastInspectedDate = pipeComponent.LastInspectedDate;
                    q.LastModifiedById = pipeComponent.LastModifiedById;
                    q.LastModifiedDate = pipeComponent.LastModifiedDate;
                    q.DrawingId = pipeComponent.DrawingId;
                    q.Description = pipeComponent.Description;
                    pipeComponent = q;
                }
                else
                {
                    PipeComponent pc = new PipeComponent();
                    pc.PipeId = pipeComponent.Pipe.Id;
                    pc.PipeComponentTypeId = pipeComponent.PipeComponentTypeId;
                    pc.SpecialFeature = pipeComponent.SpecialFeature;
                    pc.SubArea = pipeComponent.SubArea;
                    pc.Number = pipeComponent.Number;
                    pc.NextInspectionDate = pipeComponent.NextInspectionDate;
                    pc.LastInspectedById = pipeComponent.LastInspectedById;
                    pc.LastInspectedDate = pipeComponent.LastInspectedDate;
                    pc.LastModifiedById = pipeComponent.LastModifiedById;
                    pc.LastModifiedDate = pipeComponent.LastModifiedDate;
                    pc.DrawingId = pipeComponent.DrawingId;
                    pc.Description = pipeComponent.Description;

                    //Add new Pipe Component
                    cee.PipeComponents.Add(pc);
                    cee.SaveChanges();

                    pipeComponent = pc;
                }

                pipeComponent = (from x in cee.PipeComponents.Include("Pipe").Include("PipeComponentType")
                                 where x.Id == pipeComponent.Id
                                 select x).FirstOrDefault();

                pipeComponent.Pipe.Area = (from x in cee.Areas
                                           where x.Id == pipeComponent.Pipe.AreaId
                                           select x).FirstOrDefault();
            }
            return pipeComponent;
        }
예제 #14
0
        private PipeRevisionHistory BuildRevisionHistory(PipeComponent existingPipeComponent)
        {
            const decimal incrediment = 0.001m;
            var revision = new decimal(1.000);

            List<decimal> foo = (from x in Cee.PipeRevisionHistories where x.PipeId == existingPipeComponent.PipeId orderby x.Revision descending select x.Revision).ToList();

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

            var rvh = new PipeRevisionHistory
            {
                Date = DateTime.Now,
                PipeId = existingPipeComponent.PipeId,
                UserId = MetaData.UserId,
                Description = BuildRevisionHistoryUpdateComment(MetaData.RevisionHistoryComment),
                Revision = revision,
                IsSystemMessage = true
            };
            return rvh;
        }
예제 #15
0
        private void BuildPropertyValues(PipeComponent componentIn, PipeComponentDataAdapter adapter, int index)
        {
            foreach (var pair in adapter.PropertyValues)
            {
                //DOES PROPERTY EXIST?
                PipeProperty property = (from x in mExistingComponentProperties where x.Name.ToLower() == pair.Key.ToLower() select x).FirstOrDefault();
                if (property == null)
                {
                    if (CanCreateProperties)
                    {
                        property = new PipeProperty {Name = pair.Key, DefaultValue = pair.Value, Description = " (created by importer)."};
                        mExistingComponentProperties.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, index, adapter.Tag, adapter.ComponentName));
                        continue;
                    }
                }

                //CHECK PipeEquipmentComponentTypeProperty Exists
                PipeComponentTypeProperty equipmentComponentTypeProperty = null;
                if (mExistingEquipmentComponentTypeProperty.Any())
                {
                    equipmentComponentTypeProperty =
                        (from x in mExistingEquipmentComponentTypeProperty
                            where x.PipeComponentType.Name.ToLower() == componentIn.PipeComponentType.Name.ToLower()
                                  && x.PipeProperty.Name.ToLower() == property.Name.ToLower()
                            select x).FirstOrDefault();
                }

                if (equipmentComponentTypeProperty == null)
                {
                    if (CanCreateProperties)
                    {
                        //CREATE JOIN ROW
                        equipmentComponentTypeProperty = new PipeComponentTypeProperty();
                        equipmentComponentTypeProperty.PipeComponentType = componentIn.PipeComponentType; //note: set the object!
                        equipmentComponentTypeProperty.PipeProperty = 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.PipeComponentType.Name, property.Name));
                        continue;
                    }
                }
                property.PipeComponentTypeProperties.Add(equipmentComponentTypeProperty);

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

                if (propertyValue == null)
                {
                    propertyValue = new PipePropertyValue();
                    propertyValue.PipeComponent = componentIn;
                    propertyValue.PipeProperty = property;
                    mExistingPropertyValues.Add(propertyValue); //update cache
                }

                //set value
                if (!string.IsNullOrEmpty(pair.Value))
                {
                    propertyValue.Value = pair.Value.ChangeNullToEmptyString();
                }
                componentIn.PipePropertyValues.Add(propertyValue);
            }
        }
예제 #16
0
        private void MoveComponentHandler(object parameter)
        {
            if (SelectedComponent != null)
            {
                AddRelatedPipeDialog dialog = new AddRelatedPipeDialog("Select Destination Tag", true, SelectedComponent.PipeId);
                dialog.Show();

                //Select the component as user might have changed the component type
                //and this needs to reload the component type properties
                dialog.Closed += (s1, e1) =>
                                     {
                                         if (dialog.DialogResult.HasValue && dialog.DialogResult.Value)
                                         {
                                             if (dialog.SelectedPipe != null)
                                             {
                                                 SelectedComponent.PipeId = dialog.SelectedPipe.Id;

                                                 //need to CLONE due to the line "RaisePropertyChanged("Components");"
                                                 MovedComponent = CloneComponent(SelectedComponent);
                                                 MovedComponent.Pipe = new Pipe
                                                                           {
                                                                               Id = dialog.SelectedPipe.Id,
                                                                               Name = dialog.SelectedPipe.Name
                                                                           };

                                                 //remove
                                                 mPipe.PipeComponents.Remove(SelectedComponent);
                                                 RaiseChangeEvent();
                                                 OnCollectionChanged();
                                                 mSelectedComponent = null;

                                                 RaisePropertyChanged("Components");
                                             }
                                         }
                                     };

            }
        }
예제 #17
0
        private void DisplayEditComponentDialog(PipeComponent pipeComponent)
        {
            PipeComponent clone = new PipeComponent();
            CommonUtils.CloneObject(clone, SelectedComponent, "");
            clone.PipeComponentType = SelectedComponent.PipeComponentType;//not done by CloneObject method.

            AddEditPipeComponentDialog dialog = new AddEditPipeComponentDialog(mPipe, pipeComponent);
            dialog.Show();

            dialog.Closed += (s1, e1) =>
                                    {
                                        if (dialog.DialogResult.HasValue && dialog.DialogResult.Value)
                                        {
                                            Utils.OnCollectionChanged(EventAggregator, mPipe, PROPERTYNAME, true);
                                        }
                                        else
                                        {
                                            SelectedComponent.Name = clone.Name;
                                            SelectedComponent.PipeComponentType = clone.PipeComponentType;
                                            SelectedComponent.Description = clone.Description;
                                        }
                                        RaisePropertyChanged("Components");
                                    };
        }
예제 #18
0
 private void DeleteButtonHandler(object parameter)
 {
     if (SelectedComponent != null)
     {
         string message = string.Format("Remove selected Component? ({0})", SelectedComponent.Name);
         PopupDialog popupDialog = new PopupDialog(PopupDialogType.ConfirmDelete, message);
         popupDialog.Show();
         popupDialog.Closed +=
             (s2, e2) =>
             {
                 if (popupDialog.PopupDialogResult == PopupDialogResult.Yes)
                 {
                     mPipe.PipeComponents.Remove(SelectedComponent);
                     mSelectedComponent = null;
                     RaiseChangeEvent();
                     RaisePropertyChanged("Components");
                     OnCollectionChanged();
                 }
             };
     }
 }
예제 #19
0
        public DbOperationResult MovePipeComponent(PipeComponent pipeComponent)
        {
            DbOperationResult result = new DbOperationResult();

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

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

                if (match == null)
                {
                    //So component doesnt exist in the database so lets create it
                    pipeComponent.Pipe = null;
                    pipeComponent.PipeComponentType = null;
                    cee.PipeComponents.Add(pipeComponent);
                }
                else
                {
                    //Compoent exist, change the ID of Equipment
                    match.PipeId = pipeComponent.PipeId;
                }

                cee.SaveChanges();
                result.ServerInformationMessages.Add("Save Completed");
                return result;
            }
        }
예제 #20
0
        private bool ComponentIsUnique(PipeComponent newComponent, int row)
        {
            int count = (from x in mExistingComponents
                where x.SubArea == newComponent.SubArea
                      && x.PipeComponentType.Name == newComponent.PipeComponentType.Name
                      && x.Number == newComponent.Number
                select x).Count();

            if (count > 0)
            {
                RaiseMessage(CommonUtils.MessageType.Error, BuildDuplicateNameExistsInDbMessage(newComponent.Name, row));
                return false;
            }

            return true;
        }
예제 #21
0
        private void DeletePipeComponent(PipeComponent pc)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                var pipeComponentPropertyValues = (from x in cee.PipePropertyValues
                                                   where x.ComponentId == pc.Id
                                                   select x).ToList();

                foreach (var pipeComponentPropertyValue in pipeComponentPropertyValues)
                {
                    cee.PipePropertyValues.Remove(pipeComponentPropertyValue);
                }

                var q = (from x in cee.PipeComponents
                         where x.Id == pc.Id
                         select x).FirstOrDefault();
                if (q != null)
                {
                    cee.PipeComponents.Remove(q);
                    cee.SaveChanges();
                }
            }
        }
예제 #22
0
        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));
            }
        }
예제 #23
0
        private void ImportPipeComponentSheet(Array sheetValues, Worksheet worksheet, List<CellValue> cellValues)
        {
            try
            {
                RaiseMessage(MessageType.Added, "----------------------------------");
                RaiseMessage(MessageType.Added, string.Format("Importing Sheet '{0}'.", worksheet.Name));
                RaiseMessage(MessageType.Added, "----------------------------------");


                int tagNameIndex = cellValues.Where(x => x.ExpectedValue == mTagNumberCellName).FirstOrDefault().Y;
                int lineNumberIndex = cellValues.Where(x => x.ExpectedValue == mLineNumberCellName).FirstOrDefault().Y;
                int pandIdIndex = cellValues.Where(x => x.ExpectedValue == mPandIDCellName).FirstOrDefault().Y;

                int emptyPipesCount = 0;
                int rowCount = sheetValues.GetUpperBound(0);
                int columnCount = sheetValues.GetUpperBound(1);

                int firstRowIndex = cellValues.Where(x => x.ExpectedValue == mPandIDCellName).FirstOrDefault().X + 1;

                //Get Property Names and their column indexes
                Dictionary<string, int> propertyPositions = new Dictionary<string, int>();
                for (int colIndex = pandIdIndex + 1; colIndex <= columnCount; colIndex++)
                {
                    string propertyName = sheetValues.GetValue(firstRowIndex, colIndex) == null ? string.Empty : sheetValues.GetValue(firstRowIndex, colIndex).ToString();

                    if (!string.IsNullOrEmpty(propertyName))
                    {
                        var property = (from x in mExistingPipeComponentProperties where x.Name.ToLower() == propertyName.Trim().ToLower() select x).FirstOrDefault();

                        if (property != null)
                        {
                            if (!propertyPositions.ContainsKey(property.Name))
                            {
                                propertyPositions.Add(property.Name, colIndex);
                            }
                            else
                            {
                                RaiseMessage(MessageType.Warning, string.Format("WorkSheet '{0}': Found duplicate property names '{1}'. Skipping Worksheet.", worksheet.Name, propertyName));
                            }
                        }
                        else
                        {
                            RaiseMessage(MessageType.Error, string.Format("WorkSheet '{0}': Property name '{1}' will be skipped as it does not exist in the Database.", worksheet.Name, propertyName));
                        }
                    }
                }

                for (int rowIndex = firstRowIndex; rowIndex <= rowCount; rowIndex++)
                {
                    PipeComponent newPipeComponent = new PipeComponent();

                    string lineNumber = sheetValues.GetValue(rowIndex, lineNumberIndex) == null ? string.Empty : sheetValues.GetValue(rowIndex, lineNumberIndex).ToString();
                    string tagNumber = sheetValues.GetValue(rowIndex, lineNumberIndex) == null ? string.Empty : sheetValues.GetValue(rowIndex, tagNameIndex).ToString();
                    string drawing = sheetValues.GetValue(rowIndex, pandIdIndex) == null ? string.Empty : sheetValues.GetValue(rowIndex, pandIdIndex).ToString();


                    LineNumberParser lineNumberParser = new LineNumberParser(lineNumber);
                    if (!lineNumberParser.IsValid())
                    {
                        string msg = string.Format("Worksheet {0}, Row {1} :  Pipe Number Format '{2}'.  Reason: {3}", worksheet.Name, rowIndex, tagNumber, lineNumberParser.ErrorMessage);
                        RaiseMessage(MessageType.Error, msg);

                        continue;
                    }

                    TagNumberParser tagNumberParser = new TagNumberParser(tagNumber);
                    if (!tagNumberParser.IsValid())
                    {
                        string msg = string.Format("Worksheet {0}, Row {1} :  Invalid Tag Number Format '{2}'.  Reason: {3}", worksheet.Name, rowIndex, tagNumber, tagNumberParser.ErrorMessage);
                        RaiseMessage(MessageType.Error, msg);
                        continue;
                    }


                    if (GetPipe(worksheet, lineNumberParser, newPipeComponent, rowIndex))
                    {
                        emptyPipesCount++;
                        if (emptyPipesCount == 3)
                        {
                            RaiseMessage(MessageType.Warning, string.Format("WorkSheet '{0}' Line '{1}': Found 3 empty Pipes. Continuing on to next Sheet.", worksheet.Name, rowIndex));
                            break;
                        }

                        continue;
                    }


                    GetDrawing(worksheet, drawing, newPipeComponent, rowIndex);

                    AttachComponentProperties(worksheet, propertyPositions, sheetValues, newPipeComponent, rowIndex);

                    //SAVE
                    SavePipeComponent(worksheet, tagNumberParser, newPipeComponent, rowIndex);
                }

                RaiseMessage(MessageType.Added, string.Format("Finished importing Sheet '{0}'.", worksheet.Name));
            }
            catch (Exception ex)
            {
                RaiseMessage(MessageType.Error, string.Format("Error occured: {0}", ex.Message));
                RaiseMessage(MessageType.Error, string.Format("Error Stack trace: {0}", ex.StackTrace));
            }

            RaiseMessage(MessageType.Added, "Finished Job");
        }
예제 #24
0
        private PipePropertyValue GetPropertyValue(PipeComponent controlSystemComponent,
            PipeComponentTypeProperty controlSystemComponentProperty)
        {
            var propertyValue = (from x in controlSystemComponent.PipePropertyValues
                                 where x.PipePropertyId == controlSystemComponentProperty.PipePropertyId &&
                                       x.ComponentId == controlSystemComponent.Id
                                 select x).FirstOrDefault();

            if (propertyValue == null)
            {
                propertyValue = new PipePropertyValue
                {
                    ComponentId = controlSystemComponent.Id,
                    PipePropertyId = controlSystemComponentProperty.PipePropertyId,
                    Value = controlSystemComponentProperty.PipeProperty.DefaultValue
                };

                controlSystemComponent.PipePropertyValues.Add(propertyValue);
            }
            return propertyValue;
        }
예제 #25
0
        private void SavePipeComponent(Worksheet worksheet, TagNumberParser parser, PipeComponent newPipeComponent, int rowIndex)
        {
            //Check Component Type Code exists
            PipeComponentType componentType = (from x in mExistingPipeComponentTypes
                                               where string.Compare(x.Code.Trim(), parser.ComponentTypeCode, true, CultureInfo.CurrentCulture) == 0
                                               select x).FirstOrDefault();
            if (componentType == null)
            {
                RaiseMessage(MessageType.Error, string.Format("WorkSheet '{0}' Line '{1}': Component Type Code '{2}' does not exist in Database. Skipping this row.", worksheet.Name, rowIndex, parser.ComponentTypeCode));
                return;
            }

            //All good to Add new Pipe Component
            newPipeComponent.PipeComponentType = componentType;
            newPipeComponent.ComponentTypeId = componentType.Id;

            //now we can Check if the Pipe Component exist in the database using the 'Name' Property
            PipeComponent existingPipeComponent = mImportResult.Where(x => string.Compare(x.Name, parser.Name, true, CultureInfo.CurrentCulture) == 0).FirstOrDefault();

            if (existingPipeComponent != null)
            {
                newPipeComponent = existingPipeComponent;
                return; // did not skip
            }

            //Check Area Numbers Match
            if (string.Compare(parser.AreaNumber.Trim(), newPipeComponent.Pipe.Area.AreaNumber.ToString(), true, CultureInfo.CurrentCulture) != 0)
            {
                RaiseMessage(MessageType.Error, string.Format("WorkSheet '{0}' Line '{1}': Component Area '{2}' does not match Pipe Area '{3}'. Skipping this row.",
                                                              worksheet.Name, rowIndex, parser.AreaNumber, newPipeComponent.Pipe.Area.AreaNumber));
                return;
            }

            newPipeComponent.SubArea = int.Parse(parser.SubArea);
            newPipeComponent.Number = parser.Number;

            mCee.PipeComponents.AddObject(newPipeComponent);

            //|---   S A V E
            try
            {
                mCee.SaveChanges();
            }
            catch (Exception ex1)
            {
                RaiseMessage(MessageType.Error, string.Format("WorkSheet '{0}' Line '{1}': PipeComponent Name '{2}':- Exception thrown by program  as follows: {3} {4}.", worksheet.Name, rowIndex, parser.Name, ex1, ex1.InnerException));
                return;
            }

            mImportResult.Add(newPipeComponent);

            RaiseMessage(MessageType.Added, string.Format("WorkSheet '{0}' Line '{1}': Added Pipe Component Name '{2}'.", worksheet.Name, rowIndex, parser.Name));
        }
예제 #26
0
        private void PopulatePropertyValues(PipeComponent pipeComponent)
        {
            var controlSystemComponentProperies = pipeComponent.PipeComponentType.PipeComponentTypeProperties.OrderBy(x => x.Ordinal).ToList();

            if (controlSystemComponentProperies.Any(x => x.PipeProperty.SystemComboType == CommonUtils.SystemComboBoxType.PandIdDocuments.ToString() ||
                                                         x.PipeProperty.SystemComboType == CommonUtils.SystemComboBoxType.SpecificationDocuments.ToString()))
            {
                Task<List<QuickDocument>> getPidDocumentsTask = null;
                Task<List<QuickDocument>> getSpecDocumentsTask = null;

                getPidDocumentsTask = DatabaseLoader.GetQuickDocuments(CommonUtils.DoctypePidCode);
                getSpecDocumentsTask = DatabaseLoader.GetQuickDocuments(CommonUtils.DoctypeFuncspecCode);

                List<Task> tasks = new List<Task> { getPidDocumentsTask, getSpecDocumentsTask };
                Task.Factory.ContinueWhenAll(tasks.ToArray(), x =>
                {
                    CMS.UiFactory.StartNew(() =>
                    {

                        CreateAndBindDynamicProperties(pipeComponent, getPidDocumentsTask.Result.Select(d => d.Name).ToList(), getSpecDocumentsTask.Result.Select(d => d.Name).ToList());
                    });
                });

            }
            CreateAndBindDynamicProperties(pipeComponent, null, null);
        }
예제 #27
0
        private void AttachComponentProperties(Worksheet worksheet, Dictionary<string, int> propertyPositions, Array sheetValues, PipeComponent newPipeComponent, int rowIndex)
        {
            List<PipeComponentPropertyValue> componentPropertyValues = new List<PipeComponentPropertyValue>();

            foreach (var propertyPossition in propertyPositions)
            {
                string propertyValue = sheetValues.GetValue(rowIndex, propertyPossition.Value) == null ? string.Empty : sheetValues.GetValue(rowIndex, propertyPossition.Value).ToString();

                var property = (from x in mExistingPipeComponentProperties where x.Name.ToLower() == propertyPossition.Key.Trim().ToLower() select x).FirstOrDefault();

                if (property != null)
                {
                    PipeComponentPropertyValue pcpv = new PipeComponentPropertyValue();
                    pcpv.ComponentId = newPipeComponent.Id;
                    pcpv.ComponentPropertyId = property.Id;
                    pcpv.Value = propertyValue;
                    componentPropertyValues.Add(pcpv);
                    RaiseMessage(MessageType.Added, string.Format("WorkSheet '{0}': Property name '{1}' with value '{2}' has beed added to Component '{3}'.",
                                                                  worksheet.Name, propertyPossition.Key, propertyValue, newPipeComponent.Name));
                }
                else
                {
                    RaiseMessage(MessageType.Warning, string.Format("WorkSheet '{0}': Property name '{1}' will be skipped as it does not exist in the Database.", worksheet.Name, propertyPossition.Key));
                }
            }


            foreach (var pipeComponentPropertyValue in componentPropertyValues)
            {
                var q = (from x in mCee.PipeComponentPropertyValues
                         where x.Id == pipeComponentPropertyValue.Id
                         select x).FirstOrDefault();

                if (q == null)
                {
                    q = new PipeComponentPropertyValue
                            {
                                ComponentId = pipeComponentPropertyValue.ComponentId,
                                ComponentPropertyId = pipeComponentPropertyValue.ComponentPropertyId,
                                Value = pipeComponentPropertyValue.Value
                            };
                    mCee.PipeComponentPropertyValues.AddObject(q);
                    //cee.AddToPipeComponentPropertyValues(q);
                }
                else
                {
                    q.ComponentPropertyId = pipeComponentPropertyValue.ComponentPropertyId;
                    q.ComponentId = pipeComponentPropertyValue.ComponentId;
                    q.Value = pipeComponentPropertyValue.Value;
                }
                mCee.SaveChanges();
            }
        }
예제 #28
0
파일: Form1.cs 프로젝트: barrett2474/CMS2
        private void ImportPipeComponentSheet(Array sheetValues, Worksheet worksheet, List<CellValue> cellValues)
        {
            try
            {
                AddMessage(MessageType.Added, "----------------------------------");
                AddMessage(MessageType.Added, String.Format("Importing Sheet '{0}'.", worksheet.Name));
                AddMessage(MessageType.Added, "----------------------------------");

                int pipeNameIndex = cellValues.Where(x => x.ExpectedValue == mPipeCellName).FirstOrDefault().Y;
                int componentTypeIndex = cellValues.Where(x => x.ExpectedValue == mComponentTypeCellName).FirstOrDefault().Y;
                int componentNameIndex = cellValues.Where(x => x.ExpectedValue == mComponentCellName).FirstOrDefault().Y;
                int mDrawingIndex = cellValues.Where(x => x.ExpectedValue == mDrawingCellName).FirstOrDefault().Y;

                int emptyPipesCount = 0;
                int rowCount = sheetValues.GetUpperBound(0);
                int columnCount = sheetValues.GetUpperBound(1);

                int firstRowIndex = cellValues.Where(x => x.ExpectedValue == mPipeCellName).FirstOrDefault().X;

                //Get Property Names and thier column indexes
                Dictionary<string, int> propertyPossitions = new Dictionary<string, int>();
                for (int colIndex = mDrawingIndex + 1; colIndex <= columnCount; colIndex++)
                {
                    PropertyPosition propertyPosition = new PropertyPosition();
                    string propertyName = sheetValues.GetValue(firstRowIndex, colIndex) == null ? String.Empty : sheetValues.GetValue(firstRowIndex, colIndex).ToString();

                    if (!String.IsNullOrEmpty(propertyName))
                    {
                        var property = (from x in mExistingPipeComponentProperties where x.Name.ToLower() == propertyName.Trim().ToLower() select x).FirstOrDefault();

                        if (property != null)
                        {
                            if (!propertyPossitions.ContainsKey(property.Name))
                            {
                                propertyPossitions.Add(property.Name, colIndex);
                            }
                            else
                            {
                                AddMessage(MessageType.Warning, String.Format("WorkSheet '{0}': Found duplicate property names '{1}'. Skipping Worksheet.", worksheet.Name, propertyName));
                            }
                        }
                        else
                        {
                            AddMessage(MessageType.Warning, String.Format("WorkSheet '{0}': Property name '{1}' will be skipped as it does not exist in the Database.", worksheet.Name, propertyName));
                        }
                    }
                }

                for (int rowIndex = firstRowIndex + 1; rowIndex <= rowCount; rowIndex++)
                {
                    PipeComponent newPipeComponent = new PipeComponent();

                    string pipeName = sheetValues.GetValue(rowIndex, pipeNameIndex) == null ? String.Empty : sheetValues.GetValue(rowIndex, pipeNameIndex).ToString();
                    string componentType = sheetValues.GetValue(rowIndex, componentTypeIndex) == null ? String.Empty : sheetValues.GetValue(rowIndex, componentTypeIndex).ToString();
                    string componentName = sheetValues.GetValue(rowIndex, componentNameIndex) == null ? String.Empty : sheetValues.GetValue(rowIndex, componentNameIndex).ToString();
                    string drawing = sheetValues.GetValue(rowIndex, mDrawingIndex) == null ? String.Empty : sheetValues.GetValue(rowIndex, mDrawingIndex).ToString();

                    pipeName = pipeName.Insert(3, "-");

                    if (GetPipe(worksheet, pipeName, newPipeComponent, rowIndex))
                    {
                        emptyPipesCount++;
                        if (emptyPipesCount == 3)
                        {
                            AddMessage(MessageType.Warning, String.Format("WorkSheet '{0}' Line '{1}': Found 3 empty Pipes. Continuing on to next Sheet.", worksheet.Name, rowIndex));
                            break;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    if (GetPipeComponent(worksheet, componentName, ref newPipeComponent, rowIndex))
                        continue;

                    GetDrawing(worksheet, drawing, newPipeComponent, rowIndex);

                    AttachComponentProperties(worksheet, propertyPossitions, sheetValues, newPipeComponent, rowIndex);
                }
                AddMessage(MessageType.Added, String.Format("Finished importing Sheet '{0}'.", worksheet.Name));
            }
            catch (Exception ex)
            {
                AddMessage(MessageType.Error, String.Format("Error occured: {0}", ex.Message));
                AddMessage(MessageType.Error, String.Format("Error Stack trace: {0}", ex.StackTrace));
            }
        }