コード例 #1
0
ファイル: InterlockImporter.cs プロジェクト: barrett2474/CMS2
        private List<PropertyNameComponentNamePair> UpdateDynamicProperties(InterlockDataAdapter adapter, ControlSystem matchingControl, Interlock matchingInterlock, int i, out bool failed)
        {
            failed = false;
            var results = new List<PropertyNameComponentNamePair>();

            foreach (DynamicProperty dynamicProperty in adapter.DynamicProperties)
            {
                //MATCH THE PROPERTY
                InterlockProperty matchProperty = (from x in Cee.InterlockProperties where string.Compare(x.Name, dynamicProperty.PropertyName, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault();

                if (matchProperty == null)
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildItemNotFoundInDatabaseMessage("InterlockProperty", dynamicProperty.PropertyName, i + 1)));
                    failed = true;
                    continue;
                }

                //CHECK ASSOCIATEION TO INTERLOCK TYPE
                InterlockTypeProperty matchCompTypeProperty = (from x in Cee.InterlockTypeProperties
                    where x.InterlockPropertyId == matchProperty.Id
                          && x.InterlockTypeId == matchingInterlock.InterlockTypeId
                    select x).FirstOrDefault();

                if (matchCompTypeProperty == null)
                {
                    InterlockType matchingInterlockType = (from x in Cee.InterlockTypes where x.Id == matchingInterlock.InterlockTypeId select x).FirstOrDefault();

                    string message = string.Format("Missing a entry in Database for the Table 'InterlockTypeProperty' Where InterlockPropertyId = '{0}'({1}) And InterlockTypeId = '{2}' ({3}). Row {4}.",
                        matchProperty.Id, matchProperty.Name, matchingInterlockType.Id, matchingInterlockType.Name, i);

                    RaiseMessage(CommonUtils.MessageType.Error, message);
                    failed = true;
                    continue;
                }

                //CHECK IF THE PROP VALUE ALREADY EXISTS
                InterlockPropertyValue propertyValue = (from x in Cee.InterlockPropertyValues where (x.InterlockId == matchingInterlock.Id) && (x.InterlockPropertyId == matchProperty.Id) select x).FirstOrDefault();

                if (dynamicProperty.PropertyValue.ToLower().Trim() == NULLTEXT)
                {
                    if (propertyValue == null)
                    {
                        //do nothing
                        continue;
                    }

                    //delete
                    Cee.InterlockPropertyValues.Remove(propertyValue);
                }
                else
                {
                    if (PropertyValueToPropertyTypeMismatched(matchProperty.PropertyListId, matchProperty.Type, dynamicProperty, i + 1))
                    {
                        continue;
                    }

                    if (propertyValue == null)
                    {
                        //create
                        propertyValue = new InterlockPropertyValue
                        {
                            InterlockPropertyId = matchProperty.Id,
                            InterlockId = matchingInterlock.Id,
                            Value = dynamicProperty.PropertyValue,
                            VerifiedUserDate = string.Format("{0} by {1}", DateTime.Now.ToString(@"dd/MM/yyyy hh:mm"), mUser.FirstLastName)
                        };
                        Cee.InterlockPropertyValues.Add(propertyValue);
                    }
                    else
                    {
                        //update
                        propertyValue.Value = dynamicProperty.PropertyValue;
                        propertyValue.VerifiedUserDate = string.Format("{0} by {1}", DateTime.Now.ToString(@"dd/MM/yyyy hh:mm"), mUser.FirstLastName);
                    }
                }

                var pair = new PropertyNameComponentNamePair
                {
                    ComponentName = matchingControl.Name,
                    PropertyName = matchProperty.Name,
                    Value = dynamicProperty.PropertyValue
                };

                results.Add(pair);
            }

            return results;
        }
コード例 #2
0
ファイル: InterlockImporter.cs プロジェクト: barrett2474/CMS2
        private List<PropertyNameComponentNamePair> AddDynamicProperties(InterlockDataAdapter adapter, InterlockType interlockType, Interlock interlock, string controlSystemName, int i, out bool failed)
        {
            failed = false;
            var results = new List<PropertyNameComponentNamePair>();

            foreach (DynamicProperty dynamicProperty in adapter.DynamicProperties)
            {
                //InterlockProperty
                InterlockProperty matchProperty = (from x in Cee.InterlockProperties where string.Compare(x.Name, dynamicProperty.PropertyName, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault();

                if (matchProperty == null)
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildItemNotFoundInDatabaseMessage("InterlockProperty", dynamicProperty.PropertyName, i + 1)));
                    failed = true;
                    continue;
                }

                //InterlockTypeProperty
                InterlockTypeProperty matchTypeProperty = (from x in Cee.InterlockTypeProperties
                    where x.InterlockPropertyId == matchProperty.Id
                          && x.InterlockTypeId == interlockType.Id
                    select x).FirstOrDefault();

                if (matchTypeProperty == null)
                {
                    string message = string.Format("Missing a entry in Database for the Table 'InterlockTypeProperty' Where InterlockTypeId = '{0}'({1}) And InterlockPropertyId = '{2}' ({3}). Row {4}.",
                        interlockType.Id, interlockType.Name, matchProperty.Id, matchProperty.Name, i);
                    RaiseMessage(CommonUtils.MessageType.Error, message);
                    failed = true;
                    continue;
                }

                if (PropertyValueToPropertyTypeMismatched(matchProperty.PropertyListId, matchProperty.Type, dynamicProperty, i + 1))
                {
                    continue;
                }

                //NEW
                var propertyValue = new InterlockPropertyValue
                {
                    InterlockPropertyId = matchProperty.Id,
                    Value = dynamicProperty.PropertyValue,
                    VerifiedUserDate = string.Format("{0} by {1}", DateTime.Now.ToString(@"dd/MM/yyyy hh:mm"), mUser.FirstLastName)
                };

                //add to interlock
                interlock.InterlockPropertyValues.Add(propertyValue);

                var pair = new PropertyNameComponentNamePair
                {
                    ComponentName = string.Format("Control:{0}- Interlock:{1}", controlSystemName, interlockType.Name),
                    PropertyName = matchProperty.Name,
                    Value = dynamicProperty.PropertyValue
                };

                results.Add(pair);
            }

            return results;
        }