public ControlTestingPropertyWrapViewModel(ControlSystemTestingProperty controlTestingProperty, ControlSystemTestingPropertyValue propertyValue)
 {
     mControlTestingProperty = controlTestingProperty;
     mType = (CommonUtils.PropertyType) Enum.Parse(typeof (CommonUtils.PropertyType), controlTestingProperty.Type, true);
     var name = controlTestingProperty.Name;
     mRequired = controlTestingProperty.Required;
     mPropertyValue = propertyValue;
     mErrorNumbericalValidationResult = new ValidationResult(string.Format("Field {0} is numerical", name));
     mErrorRequiredValidationResult = new ValidationResult(string.Format("Field {0} is required", name));
     AcceptCommand = new DelegateCommand<object>(AcceptCommandHandler, CanModifyHandler);
 }
Пример #2
0
        private bool BuildTestPropertiesFailed(List<TestSet> testSets, CmsEntities cee, out List<ControlSystemTestingProperty> associatedProperties)
        {
            bool hasChanges = false;
            associatedProperties = new List<ControlSystemTestingProperty>();

            foreach (var testSet in testSets.OrderBy(x => x.TestId))
            {
                var match = (from x in cee.ControlSystemTestingProperties where x.Description.Equals(testSet.Test.Description, StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault();
                if (match == null)
                {
                    if (!mTestidsDictionary.ContainsKey(testSet.TestId))
                    {
                        mTestidsDictionary.Add(testSet.TestId, testSet.Test.Description);

                        var tp = new ControlSystemTestingProperty
                        {
                            Name = string.Format("Test {0}", testSet.Test.Id),
                            Description = testSet.Test.Description,
                            IsVisible = true,
                            IsEditable = true
                        };

                        switch (testSet.TestId)
                        {
                            case 14:
                            case 15:
                            case 16:
                                tp.Type = "Numerical";
                                break;
                            default:
                                tp.Type = "VerifiedCheckBox";
                                tp.DefaultValue = "False";
                                break;
                        }

                        cee.ControlSystemTestingProperties.Add(tp);
                        Logger.Out(string.Format("Created ControlSystemTestingProperty: Name {0}({1}-{2})", tp.Name, tp.Description, tp.Type));
                        hasChanges = true;
                        associatedProperties.Add(tp);
                    }
                    else
                    {
                        Logger.Out(string.Format("Error - Could not find property that should have been previously Saved. ID: {0}  Desc: {1}", testSet.Test, testSet.Test.Description));
                        return true;
                    }

                }
                else
                {
                    associatedProperties.Add(match);
                }
            }

            if (hasChanges)
            {
                cee.SaveChanges();
            }

            return false;
        }
Пример #3
0
        private bool BuildPropertyValueFailed(ControlSystem controlSystem, ControlSystemTestingProperty testingProperty, TestResult testResult, CmsEntities cee, ControlModule cm, out ControlSystemTestingPropertyValue pv)
        {
            pv = new ControlSystemTestingPropertyValue
            {
                ContolSystemId = controlSystem.Id,
                TestPropertyId = testingProperty.Id,
            };

            if (testResult.Notes != null && !string.IsNullOrEmpty(testResult.Notes.Trim()))
            {
                pv.Notes = testResult.Notes; //sets the new Notes property.
            }

            //Numerical
            if (testingProperty.Type.Equals(TestingType.Numerical.ToString(), StringComparison.CurrentCultureIgnoreCase))
            {
                pv.Value = GetNumbers(testResult.Entry); //sets the Numerical checkbox value.
            }

            //VerifiedCheckBox
            else if (testingProperty.Type.Equals(TestingType.VerifiedCheckBox.ToString(), StringComparison.CurrentCultureIgnoreCase))
            {
                pv.Value = testResult.Tested.ToString(); //sets the verified checkbox value.

                if (testResult.TestedDate.HasValue && testResult.TestedUserId.HasValue)
                {
                    var user = (from x in cee.Users where x.Id == testResult.TestedUserId.Value select x).FirstOrDefault();
                    if (user == null)
                    {
                        Logger.Out(string.Format("Warning: Control {0} - No matchng User found in CMS using USer.Idn = '{1}'.", cm.Tag, testResult.TestedUserId.Value));
                        return true;
                    }

                    pv.VerifiedUserDate = string.Format("{0} by {1} {2}", testResult.TestedDate.Value.ToString(DATE_FORMAT), user.FirstName, user.LastName);
                }
            }

            return false;
        }
Пример #4
0
 private static bool MatchTestingPropertyFailed(CmsEntities cee, Test test, ControlModule cm, out ControlSystemTestingProperty testingProperty)
 {
     testingProperty = (from x in cee.ControlSystemTestingProperties where x.Description.Equals(test.Description, StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault();
     if (testingProperty == null)
     {
         //log error
         Logger.Out(string.Format("Warning: Control {0} - No matchng ControlSystemTestingPropertyt found in CMS using Test.Description = '{1}'.", cm.Tag, test.Description));
         return true;
     }
     return false;
 }
        public DbOperationResult<ControlSystemTestingProperty> SaveControlSystemTestingProperty(ControlSystemTestingProperty property)
        {
            DbOperationResult<ControlSystemTestingProperty> result = new DbOperationResult<ControlSystemTestingProperty>();

            try
            {
                using (var cee = new CmsEntities())
                {
                    var original = (from x in cee.ControlSystemTestingProperties where x.Id == property.Id select x).FirstOrDefault();

                    if (original == null)
                    {
                        cee.ControlSystemTestingProperties.Add(property);
                        cee.SaveChanges();
                        result.EntityResult = property;
                    }
                    else
                    {
                        cee.Entry(original).CurrentValues.SetValues(property);
                        cee.SaveChanges();
                        result.EntityResult = original;
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("", ex, ex.ToString());
                result.ServerErrorMessages.Add(string.Format("Could not Save Control System  Testing Property.{0}{1}", Environment.NewLine, ex.Message));
            }
            return result;
        }