当前位置: 首页>>代码示例>>C#>>正文


C# Employee.SetMemberValue方法代码示例

本文整理汇总了C#中Employee.SetMemberValue方法的典型用法代码示例。如果您正苦于以下问题:C# Employee.SetMemberValue方法的具体用法?C# Employee.SetMemberValue怎么用?C# Employee.SetMemberValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Employee的用法示例。


在下文中一共展示了Employee.SetMemberValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TranslateValuesForEmployee

        public void TranslateValuesForEmployee(Employee employee, FieldLegalValueConfiguration fieldLegalValueConfiguration, string[] propertiesForEmployee, out TranslationLogEntry logEntry)
        {
            logEntry = null;

            if (propertiesForEmployee == null)
            {
                propertiesForEmployee = Utilities.GetPropertyNames<Employee>();
            }

            // Loop through all fields for type
            foreach (string fieldName in propertiesForEmployee)
            {
                string fieldValue = Convert.ToString(employee.GetMemberValue(fieldName));
                IEnumerable<FieldLegalValue> legalValuesForFieldName = fieldLegalValueConfiguration.FieldLegalValuesForFieldName(fieldName);

                if (String.IsNullOrEmpty(fieldValue) == false)
                {
                    if (legalValuesForFieldName.Any(v => v.LegalValue == fieldValue) == true || legalValuesForFieldName.Count() == 0) // Check if legal
                    {

                    }
                    else
                    {
                        PropertyInfo propertyInfo = employee.GetType().GetProperty(fieldName);

                        FieldTranslatorChange change = new FieldTranslatorChange();
                        change.FieldName = fieldName;
                        change.PreviousValue = employee.GetMemberValue(fieldName);

                        bool logChange = true;

                        if (legalValuesForFieldName.Any(v => v.FieldTranslations.Cast<FieldTranslation>().Any(t => t.TranslationValue == fieldValue))) // If not legal - check if it can be autocorrected
                        {
                            object newValue = null;

                            var legalValueMatch = legalValuesForFieldName.Where(v => v.FieldTranslations.Cast<FieldTranslation>().Any(t => t.TranslationValue == fieldValue)).FirstOrDefault();

                            if (legalValueMatch != null)
                            {
                                newValue = legalValueMatch.LegalValue;
                            }

                            employee.SetMemberValue(fieldName, Convert.ChangeType(newValue, propertyInfo.PropertyType));
                            change.NewValue = Convert.ChangeType(newValue, propertyInfo.PropertyType);
                            change.Status = FieldTranslatorChangeStatus.Changed;
                        }
                        else // If it cannot be autocorrected
                        {
                            if (legalValuesForFieldName.All(x => x.DisallowOtherValues == false) == true) // Ignore if if it will allow other values than the ones defined as a legal value
                            {
                                logChange = false;
                            }
                            // Else Use the following behaviour
                            else if (Behaviour == FieldTranslatorBehaviour.KeepNonLegalValues)
                            {
                                change.Status = FieldTranslatorChangeStatus.Ignored;
                            }
                            else if (Behaviour == FieldTranslatorBehaviour.RemoveNonLegalValues)
                            {
                                employee.SetMemberValue(fieldName, Convert.ChangeType(null, propertyInfo.PropertyType));
                                change.Status = FieldTranslatorChangeStatus.Removed;
                            }
                        }

                        if (this.CommitChanges == true)
                        {
                            employee.Save();
                        }

                        if (logChange)
                        {
                            change.Employee = employee;
                            Changes.Add(change);
                        }

                        if (this.CommitChanges == true && change.Status != FieldTranslatorChangeStatus.Ignored && change.Status != FieldTranslatorChangeStatus.None)
                        {
                            Customer currentCustomer = CustomerUtilities.CurrentCustomerFromSession(employee.Session);

                            logEntry = new TranslationLogEntry(employee.Session)
                            {
                                PreviousValue = Convert.ToString(change.PreviousValue),
                                FieldName = fieldName,
                                NewValue = Convert.ToString(change.NewValue),
                                Employee = employee,
                                ChangeStatus = Convert.ToInt32(change.Status),
                                Customer = currentCustomer
                            };

                            logEntry.Save();
                        }
                    }
                }
            }
        }
开发者ID:a1exb1,项目名称:DX_Farlon_Data_Consolidator,代码行数:95,代码来源:FieldTranslator.cs


注:本文中的Employee.SetMemberValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。