Exemplo n.º 1
0
        public bool SendNewCalibrationEmail(CalibrationComponent component)
        {
            var foo = new NewCalibrationComponentEmailer();
            return foo.Send(component);

            #endregion
        }
        public InstrumentCalibrationPropertiesViewModel(CalibrationComponent calibrationComponent)
        {
            mCalibrationComponent = calibrationComponent;

            LastInspectedCommand = new DelegateCommand<object>(LastInspectedHandler, CanModify);
            NextInspectionCommand = new DelegateCommand<object>(NextInspectionHandler, CanModify);
        }
        public CalibrationAttachmentsControl(CalibrationComponent calibrationComponent)
        {
            InitializeComponent();
            mCalibrationComponent = calibrationComponent;

            var viewModel = new CalibrationAttachmentsViewModel(mCalibrationComponent) {View = this};
            DataContext = viewModel;
        }
 public AddEditCalibrationComponentViewModel(CalibrationComponent mc, IList<string> existingComponentNames)
 {
     ExistingComponentNames = existingComponentNames;
     EditingName = mc.Name;
     mCalibrationComponent = mc;
     mCalibrationComponent.LastModifiedDate = DateTime.Now;
     mCalibrationComponent.LastModifiedById = CMS.User.Id;
     Initialize();
     InEditMode = true;
 }
        public CalibrationAttachmentsViewModel(CalibrationComponent calibrationComponent)
        {
            AddAttachmentCommand = new DelegateCommand<object>(AddButtonHandler, CanAdd);
            RemoveAttachmentCommand = new DelegateCommand<object>(DeleteButtonHandler, CanDelete);

            CompositionInitializer.SatisfyImports(this);
            mCalibrationComponent = calibrationComponent;

            Attachments = new ObservableCollection<CalibrationComponentAttachment>();

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
            cmsWebServiceClient.GetCalibrationAttachmentsCompleted += cmsWebServiceClient_GetCalibrationAttachmentsCompleted;
            cmsWebServiceClient.GetCalibrationAttachmentsAsync(calibrationComponent.Id);
        }
        public AddEditCalibrationComponentViewModel(int instrumentId, IList<string> existingComponentNames)
        {
            ExistingComponentNames = existingComponentNames;
            mCalibrationComponent = new CalibrationComponent();
            mCalibrationComponent.LastModifiedDate = DateTime.Now;
            mCalibrationComponent.LastModifiedById = CMS.User.Id;

            mCalibrationComponent.LastInspectedById = CMS.User.Id;
            mCalibrationComponent.LastInspectedDate = DateTime.Now;

            Initialize();

            mCalibrationComponent.CalibrationComponentPropertyValues = new List<CalibrationComponentPropertyValue>();
            mCalibrationComponent.InstrumentId = instrumentId;
            InEditMode = false;
        }
        public AddEditCalibrationComponentDialog(CalibrationComponent calibrationComponent, IList<string> existingComponentNames)
        {
            // Required to initialize variables
            InitializeComponent();

            this.Title = "Edit Calibration Component";

            AddEditCalibrationComponentViewModel addEditCalibrationComponentViewModel = new AddEditCalibrationComponentViewModel(calibrationComponent, existingComponentNames);

            addEditCalibrationComponentViewModel.Loaded += () =>
            {
                addEditCalibrationComponentViewModel.View = this;
                DataContext = addEditCalibrationComponentViewModel;
                Utils.ResetOriginalValues(LayoutRoot);
            };
        }
        public CalibrationPropertiesControl(CalibrationComponent calibrationComponent)
        {
            if (DesignerProperties.IsInDesignTool) { return; }

            InitializeComponent();
            CompositionInitializer.SatisfyImports(this);
            mCalibrationComponent = calibrationComponent;

            DatabaseLoader.GetCalibrationEngineeringUnits().ContinueWith(getCalibrationEngineeringUnitsTask =>
            {
                CMS.UiFactory.StartNew(() =>
                {
                    mCalibrationEngineeringUnits = getCalibrationEngineeringUnitsTask.Result;
                    mViewModel = new InstrumentCalibrationPropertiesViewModel(mCalibrationComponent);
                    CalibrationComponentPropertyWrapViewModelList = new List<CalibrationComponentPropertyWrapViewModel>();
                    DataContext = mViewModel;

                    PopulatePropertyValues(calibrationComponent);
                });
            });
        }
Exemplo n.º 9
0
        private void DeleteCalibrationComponent(CalibrationComponent mec)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                var calibrationPropertyValues = (from x in cee.CalibrationComponentPropertyValues
                                                 where x.CalibrationComponentId == mec.Id
                                                 select x).ToList();

                foreach (var calibrationPropertyValue in calibrationPropertyValues)
                {
                    cee.CalibrationComponentPropertyValues.Remove(calibrationPropertyValue);
                }

                cee.DeleteWhere<CalibrationComponentAttachment>(cee, x => x.CalibrationComponentId == mec.Id);

                var q = (from x in cee.CalibrationComponents
                         where x.Id == mec.Id
                         select x).FirstOrDefault();
                if (q != null)
                {
                    cee.CalibrationComponents.Remove(q);
                    cee.SaveChanges();
                }
            }
        }
        private void InsertData(IList<CalibrationComponentDataAdapter> adapters)
        {
            for (int index = 0; index < adapters.Count; index++)
            {
                CalibrationComponentDataAdapter adapter = adapters[index];
                if (!adapter.IsValid())
                {
                    continue;
                }

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

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

                CalibrationComponent newComponent = new CalibrationComponent();

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

                newComponent.Name = adapter.CalibrationName;
                newComponent.Description = adapter.CalibrationDescription;
                if (GetInstrument(adapter.Tag, newComponent, adapter.RowNumber)) continue;
                if (GetCalibrationComponentType(adapter.CalibrationType, newComponent, adapter.RowNumber)) continue;
                newComponent.Notes = adapter.Notes;

                CalibrationComponent existing = (from x in Cee.CalibrationComponents
                                                 where string.Compare(x.Name, adapter.CalibrationName, true, CultureInfo.CurrentCulture) == 0
                                                     && x.CalibrationComponentTypeId == newComponent.CalibrationComponentTypeId
                                                 select x).FirstOrDefault();
                if (existing != null)
                {
                    //error - should not already exist
                    RaiseMessage(CommonUtils.MessageType.Warning, BuildDuplicateNameExistsInDbMessage(existing.Name, adapter.RowNumber));
                    continue;
                }

                BuildPropertyValues(newComponent, adapter);

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

                InstrumentRevisionHistory rvh = BuildRevisionHistory(newComponent);

                newComponent.Instrument.InstrumentRevisionHistories.Add(rvh);
            }

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

            foreach (CalibrationComponent result in mSavedResults)
            {
                RaiseMessage(CommonUtils.MessageType.Added, string.Format("Added Component '{0}' from worksheet {1}.", result.Name, WorkSheetName));
            }
        }
        private bool GetInstrument(string tag, CalibrationComponent newComponent, int rowIndex)
        {
            bool skipRow = false;

            //Check if the Area exist in the database
            Instrument equipment = (from x in Cee.Instruments
                                    where string.Compare(tag, x.Name, true, CultureInfo.CurrentCulture) == 0
                                          && !string.IsNullOrEmpty(x.Name)
                                    select x).FirstOrDefault();

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

            if (equipment != null)
            {
                newComponent.Instrument = equipment;
                newComponent.InstrumentId = 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;
        }
        private bool GetCalibrationComponentType(string typeName, CalibrationComponent newComponent, int rowIndex)
        {
            bool skipRow = false;

            //Check if the Area exist in the database
            CalibrationComponentType componentType = (from x in Cee.CalibrationComponentTypes where x.Name.Equals(typeName, StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault();

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

            return skipRow;
        }
        private InstrumentRevisionHistory BuildRevisionHistory(CalibrationComponent componentIn)
        {
            const decimal incrediment = 0.001m;
            decimal revision = new decimal(1.000);

            List<decimal> foo = (from x in Cee.InstrumentRevisionHistories where x.InstrumentId == componentIn.InstrumentId orderby x.Revision descending select x.Revision).ToList();

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

            InstrumentRevisionHistory rvh = new InstrumentRevisionHistory
                                                {
                                                    Date = DateTime.Now,
                                                    InstrumentId = componentIn.InstrumentId,
                                                    UserId = MetaData.UserId,
                                                    Description = BuildRevisionHistoryUpdateComment(MetaData.RevisionHistoryComment),
                                                    Revision = revision,
                                                    IsSystemMessage = true
                                                };
            return rvh;
        }
        private void DeleteButtonHandler(object parameter)
        {
            if (SelectedComponent != null)
            {
                string message = string.Format("Remove selected Calibration? ({0})", SelectedComponent.Name);
                PopupDialog popupDialog = new PopupDialog(PopupDialogType.ConfirmDelete, message);
                popupDialog.Show();
                popupDialog.Closed +=
                    (s2, e2) =>
                    {
                        if (popupDialog.PopupDialogResult == PopupDialogResult.Yes)
                        {
                            mInstrument.CalibrationComponents.Remove(SelectedComponent);

                            View.ComponentPropertiesControl.Content = null;
                            RaisePropertyChanged("Components");
                            RaisePropertyChanged("SelectedComponent");

                            mSelectedComponent = null;
                            RaiseChangeEvent();

                            OnCollectionChanged();
                        }
                    };

            }
        }
        public bool Send(CalibrationComponent component)
        {
            string emailSendEnabledSetting = CommonUtils.GetAppSettingValue(CommonUtils.AppSettingKey.EmailSendEnabled);

            if (emailSendEnabledSetting.ToLower() != "true")
            {
                log.Info("WebConfig setting 'SendEmailEnabled' is set to False.  Exiting SendEmail() method.");
                return false;
            }

            StringBuilder emailTemplate = new StringBuilder();
            string filePath = EmailCommon.GetMailDefinitionFilePath("NewCalibrationComponentMailMessageDefinition.html");

            if (!File.Exists(filePath))
            {
                log.Error("Could not find html file for email named '{0}'.", filePath);
                throw new FileNotFoundException(string.Format("Could not find html file for email named '{0}'.", filePath));
            }

            emailTemplate.Append(EmailCommon.ReadEmailTemplate(filePath));

            //full fetch
            component = GetComponentWithFullProperties(component);

            List<string> recipients = BuildCalibrationRecipientList();
            ListDictionary replacements = BuildEmailReplacements(component);

            MailDefinition md = new MailDefinition();
            MailMessage message = md.CreateMailMessage(string.Join(",", recipients.ToArray()), replacements, emailTemplate.ToString(), new System.Web.UI.Control());

            //FROM
            string emailAdminAccount = CommonUtils.GetAppSettingValue(CommonUtils.AppSettingKey.EmailAdminAccount);
            message.From = new MailAddress(emailAdminAccount);
            message.IsBodyHtml = true;

            //SUBJECT
            message.Subject = string.Format("Calibration has been added to Instrument '{0}'.", component.Instrument.Name);

            SmtpClient client = new SmtpClient();

            client.Host = CommonUtils.GetAppSettingValue(CommonUtils.AppSettingKey.EmailMailHost);

            try
            {
                //SEND!
                string testEmail = CommonUtils.GetAppSettingValue(CommonUtils.AppSettingKey.EmailDefaultTest);

                if (EmailCommon.IsValidEmailaddress(testEmail))
                {
                    EmailCommon.InterceptEmail(message, testEmail);
                }

                log.Info("Sending email.{0}From = {1}{0}To = {2}{0}Cc = {3}{0}Host = {4}.", Environment.NewLine, message.From, message.To, message.CC, client.Host);
                log.Verbose("Email body: {0}", message.Body);

                client.Send(message);
            }
            catch (Exception exception)
            {
                log.Error(exception.Message, exception, "Possible relay error");
                if (exception.InnerException != null)
                {
                    log.Error(exception.InnerException.Message, exception.InnerException, "Possible relay error inner exception.");
                }
            }

            return true;
        }
        private static string BuildPropertyHtmlRows(CalibrationComponent component)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                var enableAsFound = component.CalibrationComponentPropertyValues.Any(x => x.CalibrationProperty.EnableAsFound);

                StringBuilder sb = new StringBuilder();

                sb.AppendFormat("<tr>");

                sb.AppendFormat("<td class=\"SectionSubHeader\" style=\"width: 250px\">");
                sb.AppendFormat("Parameter");
                sb.AppendFormat("</td>");

                //sb.AppendFormat(EmailCommon.SECTIONSUBHEADERSTYLEROW);
                sb.AppendFormat("<td class=\"SectionSubHeader\" style=\"width: 300px\">");
                sb.AppendFormat("Parameter Description");
                sb.AppendFormat("</td>");

                sb.AppendFormat("<td class=\"SectionSubHeader\" style=\"width: 150px\">");
                sb.AppendFormat("Units");
                sb.AppendFormat("</td>");

                if (enableAsFound)
                {
                    sb.AppendFormat("<td class=\"SectionSubHeader\" style=\"width: 150px\">");
                    sb.AppendFormat("As Found");
                    sb.AppendFormat("</td>");
                }

                sb.AppendFormat(EmailCommon.SECTIONSUBHEADERSTYLEROW);
                sb.AppendFormat("As Left");
                sb.AppendFormat("</td>");

                sb.AppendFormat("</tr>");

                foreach (CalibrationComponentPropertyValue propertyValue in component.CalibrationComponentPropertyValues)
                {

                    sb.AppendFormat("<tr>");

                    sb.AppendFormat(EmailCommon.SECTIONSUBHEADERSTYLEROW);
                    sb.AppendFormat(EmailCommon.HtmlEncode(propertyValue.CalibrationProperty.Name));
                    sb.AppendFormat("</td>");

                    sb.AppendFormat(EmailCommon.BODYSTYLEROW);
                    sb.AppendFormat(EmailCommon.HtmlEncode(propertyValue.CalibrationProperty.Description));
                    sb.AppendFormat("</td>");

                    int typeId = propertyValue.CalibrationComponent.CalibrationComponentType.Id;
                    int propertyId = propertyValue.CalibrationPropertyId;

                    var unit = (from x in cee.CalibrationComponentTypeProperties
                                where x.CalibrationComponentTypeId == typeId
                                && x.CalibrationPropertyId == propertyId
                                select x.CalibrationEngineeringUnit.Name).FirstOrDefault();

                    sb.AppendFormat(EmailCommon.BODYSTYLEROW);
                    sb.AppendFormat(EmailCommon.HtmlEncode(unit));
                    sb.AppendFormat("</td>");

                    if (enableAsFound)
                    {
                        sb.AppendFormat(EmailCommon.BODYSTYLEROW);
                        if (propertyValue.CalibrationProperty.EnableAsFound)
                        {
                            sb.AppendFormat(EmailCommon.HtmlEncode(propertyValue.Value));
                        }
                        else
                        {
                            sb.AppendFormat(EmailCommon.HtmlEncode("-"));
                        }
                        sb.AppendFormat("</td>");
                    }

                    sb.AppendFormat(EmailCommon.BODYSTYLEROW);
                    sb.AppendFormat(EmailCommon.HtmlEncode(propertyValue.Value2));
                    sb.AppendFormat("</td>");

                    sb.AppendFormat("</tr>");
                }

                return sb.ToString();
            }
        }
        private CalibrationComponentPropertyValue GetCalibrationComponentPropertyValue(CalibrationComponent calibrationComponent, CalibrationComponentTypeProperty calibrationComponentProperty)
        {
            var propertyValue = (from x in calibrationComponent.CalibrationComponentPropertyValues
                                 where x.CalibrationPropertyId == calibrationComponentProperty.CalibrationPropertyId &&
                                 x.CalibrationComponentId == calibrationComponent.Id
                                 select x).FirstOrDefault();

            if (propertyValue == null)
            {
                propertyValue = new CalibrationComponentPropertyValue
                    {
                        CalibrationComponentId = calibrationComponent.Id,
                        CalibrationPropertyId = calibrationComponentProperty.CalibrationPropertyId,
                        Value = calibrationComponentProperty.CalibrationProperty.DefaultValue, //As Found
                        Value2 = calibrationComponentProperty.CalibrationProperty.DefaultValue //As Left
                    };
                calibrationComponent.CalibrationComponentPropertyValues.Add(propertyValue);
            }

            return propertyValue;
        }
        private void PopulatePropertyValues(CalibrationComponent calibrationComponent)
        {
            int rowCount = 2;
            const int rowHeight = 25;

            var calibrationComponentProperies = calibrationComponent.CalibrationComponentType.CalibrationComponentTypeProperties.OrderBy(x => x.Ordinal);

            foreach (var calibrationComponentProperty in calibrationComponentProperies)
            {
                PropertiesGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(rowHeight - 2) });

                var propertyValue = GetCalibrationComponentPropertyValue(calibrationComponent, calibrationComponentProperty);

                if (calibrationComponentProperty.CalibrationEngineeringUnit == null)
                {
                    calibrationComponentProperty.CalibrationEngineeringUnit = new CalibrationEngineeringUnit
                                                                       {
                                                                           Id = calibrationComponentProperty.CalibrationEngineeringUnitId,
                                                                           Name = (from x in mCalibrationEngineeringUnits
                                                                                   where x.Id == calibrationComponentProperty.CalibrationEngineeringUnitId
                                                                                   select x.Name).FirstOrDefault()
                                                                       };
                }

                BindLabel(calibrationComponentProperty, "CalibrationProperty.Name", rowCount, 0, true);
                BindLabel(calibrationComponentProperty, "CalibrationEngineeringUnit.Name", rowCount, 1, false);

                CalibrationComponentPropertyWrapViewModel ccpwvm = new CalibrationComponentPropertyWrapViewModel(propertyValue,
                                                                  calibrationComponentProperty.CalibrationProperty.Type);

                CalibrationComponentPropertyWrapViewModelList.Add(ccpwvm);

                BindTextBox(ccpwvm, "AsFound", rowCount, 2, calibrationComponentProperty.CalibrationProperty.EnableAsFound);
                BindTextBox(ccpwvm, "AsLeft", rowCount, 4, true);

                rowCount++;
            }

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

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

            NotesTextBox.ResetOriginalValue();
            NotesTextBox.ControlChanged += ControlChanged;
        }
        private ListDictionary BuildEmailReplacements(CalibrationComponent component)
        {
            ListDictionary replacements = new ListDictionary();

            string url = CommonUtils.GetAppSettingValue(CommonUtils.AppSettingKey.ApplicationUrl);

            string instrumentIdHef = String.Format(@"<a href='{0}?instrument={1}'>{2}</a>", url, component.InstrumentId, component.Instrument.Name);

            replacements.Add("<%InstrumentTag%>", instrumentIdHef);
            replacements.Add("<%WorkOrder%>", EmailCommon.HtmlEncode(component.Name));
            replacements.Add("<%InstrumentDescription%>", EmailCommon.HtmlEncode(component.Instrument.Description));
            replacements.Add("<%InstrumentType%>", component.Instrument.InstrumentType.Name + " - " + component.Instrument.InstrumentType.Description);
            replacements.Add("<%CalibrationDescription%>", EmailCommon.HtmlEncode(component.Description));
            replacements.Add("<%CalibrationType%>", component.CalibrationComponentType.Name);

            //LastModified
            if (component.LastModifiedDate.HasValue && component.LastModifiedById.HasValue)
            {
                using (CmsEntities cee = new CmsEntities())
                {
                    User user = (from x in cee.Users where x.Id == component.LastModifiedById.Value select x).FirstOrDefault();
                    replacements.Add("<%LastModified%>", EmailCommon.HtmlEncode(String.Format("{0} by {1} {2}", component.LastModifiedDate.Value.ToString("dd/MM/yyyy HH:mm"), user.FirstName, user.LastName)));
                }
            }

            //LastInspected
            if (component.LastInspectedDate.HasValue && component.LastInspectedById.HasValue)
            {
                using (CmsEntities cee = new CmsEntities())
                {
                    User user = (from x in cee.Users where x.Id == component.LastInspectedById.Value select x).FirstOrDefault();
                    replacements.Add("<%LastInspected%>", EmailCommon.HtmlEncode(String.Format("{0} by {1} {2}", component.LastInspectedDate.Value.ToString("dd/MM/yyyy HH:mm"), user.FirstName, user.LastName)));
                }
            }

            //NextInspection
            if (component.NextInspectionDate.HasValue)
            {
                Debug.WriteLine(EmailCommon.HtmlEncode(String.Format("{0}", component.NextInspectionDate.Value.ToString("dd/MM/yyyy HH:mm"))));

                replacements.Add("<%NextInspection%>", EmailCommon.HtmlEncode(String.Format("{0}", component.NextInspectionDate.Value.ToString("dd/MM/yyyy HH:mm"))));
            }

            //Notes
            replacements.Add("<%Notes%>", EmailCommon.HtmlEncode(component.Notes));

            //CalibrationProperties
            replacements.Add("<%CalibrationProperties%>", BuildPropertyHtmlRows(component));

            //attachments
            replacements.Add("<%Attachments%>", BuildAttachmentsTableHtml(component.Id));

            return replacements;
        }
Exemplo n.º 20
0
        private void SaveCalibrationComponents(IEnumerable<CalibrationComponent> calibrationComponents)
        {
            bool isInsert = false;

            using (CmsEntities cee = new CmsEntities())
            {
                foreach (var calibrationComponent in calibrationComponents)
                {
                    CalibrationComponent match = (from x in cee.CalibrationComponents
                                                  where x.Id == calibrationComponent.Id
                                                  && x.Id > 0
                                                  select x).FirstOrDefault();

                    if (match != null)
                    {
                        //Update Calibration Componet
                        cee.Entry(match).CurrentValues.SetValues(calibrationComponent);
                    }
                    else
                    {
                        isInsert = true;

                        match = new CalibrationComponent
                        {
                            InstrumentId = calibrationComponent.InstrumentId,
                            CalibrationComponentTypeId = calibrationComponent.CalibrationComponentTypeId,
                            Name = calibrationComponent.Name,
                            Ordinal = calibrationComponent.Ordinal,
                            NextInspectionDate = calibrationComponent.NextInspectionDate,
                            LastInspectedById = calibrationComponent.LastInspectedById,
                            LastInspectedDate = calibrationComponent.LastInspectedDate,
                            LastModifiedById = calibrationComponent.LastModifiedById,
                            LastModifiedDate = calibrationComponent.LastModifiedDate,
                            Description = calibrationComponent.Description,
                            Notes = calibrationComponent.Notes
                        };

                        //Add new Calibration Component
                        cee.CalibrationComponents.Add(match);
                    }
                    //delete all Calibration Component Attachments

                    cee.DeleteWhere<CalibrationComponentAttachment>(cee,x=>x.CalibrationComponentId == match.Id);

                    //Add current Calibration Component Attachments
                    foreach (var attachment in calibrationComponent.CalibrationComponentAttachments)
                    {
                        match.CalibrationComponentAttachments.Add(new CalibrationComponentAttachment {CalibrationComponentId = attachment.CalibrationComponentId, AttachmentId = attachment.AttachmentId});
                    }

                    foreach (var calibrationComponentPropertyValue in calibrationComponent.CalibrationComponentPropertyValues)
                    {
                        var qq = (from x in cee.CalibrationComponentPropertyValues
                                  where x.Id == calibrationComponentPropertyValue.Id
                                  select x).FirstOrDefault();

                        if (qq != null)
                        {
                            cee.Entry(qq).CurrentValues.SetValues(calibrationComponentPropertyValue);
                        }
                        else
                        {
                            cee.CalibrationComponentPropertyValues.Add(calibrationComponentPropertyValue);
                        }
                    }
                    cee.SaveChanges();

                    if (isInsert)
                    {
                        //https://jira.issgroup.com.au/browse/BODCMS-998
                        SendNewCalibrationComponentEmail(match);
                    }

                }
            }
        }
        private CalibrationComponent GetComponentWithFullProperties(CalibrationComponent component)
        {
            using (CmsEntities cee = new CmsEntities())
            {
                CalibrationComponent calibrationComponent = (from x in cee.CalibrationComponents
                                                                          .Include("Instrument")
                                                                          .Include("Instrument.InstrumentType")
                                                                          .Include("CalibrationComponentPropertyValues")
                                                                          .Include("CalibrationComponentPropertyValues.CalibrationProperty")
                                                                          .Include("CalibrationComponentType")

                                                             where x.Id == component.Id
                                                             select x).FirstOrDefault();

                return calibrationComponent;
            }
        }
Exemplo n.º 22
0
 private void SendNewCalibrationComponentEmail(CalibrationComponent component)
 {
     BackgroundWorker bw = new BackgroundWorker();
     bw.WorkerReportsProgress = false;
     bw.DoWork += BackgroundNewCalibrationWork;
     bw.RunWorkerAsync(component);
 }
        private void EditComponentHandler(object parameter)
        {
            if (SelectedComponent != null)
            {
                CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);

                cmsWebServiceClient.GetCalibrationComponentsCompleted +=
                    (s, e) =>
                    {

                        CalibrationComponent clone = new CalibrationComponent();
                        CommonUtils.CloneObject(clone, SelectedComponent, "");
                        clone.CalibrationComponentType = SelectedComponent.CalibrationComponentType;//not done by CloneObject method.

                        IList<string> existingComponentNames = (from x in Components select x.Name).ToList();
                        AddEditCalibrationComponentDialog dialog = new AddEditCalibrationComponentDialog(mSelectedComponent, existingComponentNames);
                        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)
                                {
                                    SelectedComponent = dialog.Component;
                                }
                                else
                                {
                                    SelectedComponent.Name = clone.Name;
                                    SelectedComponent.CalibrationComponentType = clone.CalibrationComponentType;
                                    SelectedComponent.Description = clone.Description;
                                    SelectedComponent.Notes = clone.Notes;
                                }

                                RaisePropertyChanged("Components");

                            };
                    };
                cmsWebServiceClient.GetCalibrationComponentsAsync();

            }
        }
        private void BuildPropertyValues(CalibrationComponent componentIn, CalibrationComponentDataAdapter adapter)
        {
            foreach (CalibrationPropertyDto dto in adapter.PropertyValues)
            {

                CalibrationProperty property = (from x in mExistingProperties where x.Name.ToLower() == dto.PropertyName.ToLower() select x).FirstOrDefault();

                if (property == null)
                {
                    if (CanCreateProperties)
                    {
                        property = new CalibrationProperty { Name = dto.PropertyName, Type = "not used", Description = "(created by importer.)" };
                        mExistingProperties.Add(property);

                        //JOIN TABLE - joins the Property with the Type
                        CalibrationComponentTypeProperty typePropertyJoin = new CalibrationComponentTypeProperty();
                        typePropertyJoin.CalibrationComponentType = componentIn.CalibrationComponentType;

                        //EngineeringUnit
                        if (dto.NewUnit != null)
                        {
                            CalibrationEngineeringUnit unit = (from x in mExistingUnits where x.Name == dto.NewUnit.Name select x).FirstOrDefault();
                            if (unit == null)
                            {
                                typePropertyJoin.CalibrationEngineeringUnit = dto.NewUnit;
                            }
                            else
                            {
                                typePropertyJoin.CalibrationEngineeringUnit = unit;
                            }
                        }

                        property.CalibrationComponentTypeProperties.Add(typePropertyJoin);

                        mExistingProperties.Add(property);

                    }
                    else
                    {
                        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.CalibrationName));
                        continue;
                    }
                }
                else
                {

                    //do we have a record in the join table for this property and comp type?
                    CalibrationComponentTypeProperty equipmentComponentTypeProperty =
                        (from x in Cee.CalibrationComponentTypeProperties
                         where x.CalibrationComponentType.Name.ToLower() == componentIn.CalibrationComponentType.Name.ToLower()
                         && x.CalibrationProperty.Name.ToLower() == property.Name.ToLower()
                         select x).FirstOrDefault();

                    if (equipmentComponentTypeProperty == null)
                    {
                        ////no row in join table - so create one.
                        CalibrationComponentTypeProperty typePropertyJoin = new CalibrationComponentTypeProperty();

                        if (dto.NewUnit != null)
                        {
                            CalibrationEngineeringUnit unit = (from x in mExistingUnits where x.Name == dto.NewUnit.Name select x).FirstOrDefault();

                            if (unit == null)
                            {
                                typePropertyJoin.CalibrationEngineeringUnit = dto.NewUnit;
                            }
                            else
                            {
                                typePropertyJoin.CalibrationEngineeringUnit = unit;
                            }
                        }

                        typePropertyJoin.CalibrationComponentType = componentIn.CalibrationComponentType;
                        property.CalibrationComponentTypeProperties.Add(typePropertyJoin);
                    }

                }

                CalibrationComponentPropertyValue propertyValue = (from x in Cee.CalibrationComponentPropertyValues
                                                                   where x.CalibrationComponentId == componentIn.Id
                                                                   && x.CalibrationPropertyId == property.Id
                                                                   select x).FirstOrDefault();
                if (propertyValue == null)
                {
                    propertyValue = new CalibrationComponentPropertyValue {CalibrationComponent = componentIn, CalibrationProperty = property};
                    property.Type = "Text";//not used but not nullable
                    property.EnableAsFound = false; //not used but not nullable
                }

                //Set AsFoundValue
                if (!string.IsNullOrEmpty(dto.AsFoundValue))
                {
                    propertyValue.Value = dto.AsFoundValue;
                }

                //Set AsLeftValue
                if (!string.IsNullOrEmpty(dto.AsLeftValue))
                {
                    propertyValue.Value2 = dto.AsLeftValue;
                }

                componentIn.CalibrationComponentPropertyValues.Add(propertyValue);

            }
        }