Пример #1
0
        private int _linkId; // LoanId, SavingsId or ClientId

        #endregion Fields

        #region Constructors

        public CustomizableFieldsControl(OCustomizableFieldEntities entity, int? linkId, bool showUpdateButton)
        {
            InitializeComponent();

            _entity = entity;

            if (linkId.HasValue)
            {
                _linkId = linkId.Value;
                panelUpdate.Visible = showUpdateButton;
            }

            switch (_entity)
            {
                case OCustomizableFieldEntities.Loan:
                    _entityType = 'L';
                    break;
                case OCustomizableFieldEntities.Savings:
                    _entityType = 'S';
                    break;
                default:
                    _entityType = 'C';
                    break;
            }

            _advancedFields = new CustomClass();
            _advancedFieldsCollections = new CollectionList();
            LoanAdvancedCustomizableFields();
        }
        public bool CustomizableFieldsExistFor(OCustomizableFieldEntities entity)
        {
            string sqlText = @"SELECT COUNT(*) AS [number] 
                               FROM dbo.AdvancedFields 
                               WHERE [entity_id] = @entity_id ";

            using (SqlConnection conn = GetConnection())
                using (OpenCbsCommand selectCmd = new OpenCbsCommand(sqlText, conn))
                {
                    selectCmd.AddParam("@entity_id",
                                       (int)Enum.Parse(typeof(OCustomizableFieldEntities), entity.ToString()));

                    using (OpenCbsReader reader = selectCmd.ExecuteReader())
                    {
                        if (reader == null || reader.Empty)
                        {
                            return(false);
                        }
                        reader.Read();
                        if (reader.GetInt("number") > 0)
                        {
                            return(true);
                        }
                    }
                }

            return(false);
        }
        public CustomizableFieldsControl(OCustomizableFieldEntities entity, int?linkId, bool showUpdateButton)
        {
            InitializeComponent();

            _entity = entity;

            if (linkId.HasValue)
            {
                _linkId             = linkId.Value;
                panelUpdate.Visible = showUpdateButton;
            }

            switch (_entity)
            {
            case OCustomizableFieldEntities.Loan:
                _entityType = 'L';
                break;

            case OCustomizableFieldEntities.Savings:
                _entityType = 'S';
                break;

            default:
                _entityType = 'C';
                break;
            }

            _advancedFields            = new CustomClass();
            _advancedFieldsCollections = new CollectionList();
            LoanAdvancedCustomizableFields();
        }
Пример #4
0
        public bool CustomizableFieldsExistFor(OCustomizableFieldEntities entity)
        {
            string sqlText = @"SELECT COUNT(*) AS [number]
                               FROM dbo.AdvancedFields
                               WHERE [entity_id] = @entity_id ";
            using (SqlConnection conn = GetConnection())
            using (OpenCbsCommand selectCmd = new OpenCbsCommand(sqlText, conn))
            {
                selectCmd.AddParam("@entity_id",
                                   (int) Enum.Parse(typeof (OCustomizableFieldEntities), entity.ToString()));

                using (OpenCbsReader reader = selectCmd.ExecuteReader())
                {
                    if (reader == null || reader.Empty) return false;
                    reader.Read();
                    if (reader.GetInt("number") > 0) return true;
                }
            }

            return false;
        }
Пример #5
0
        private void InitializeCustomizableFields(OCustomizableFieldEntities entity, int? linkId, bool isActive)
        {
            if (entity == OCustomizableFieldEntities.Loan)
            {
                tabPageLoanCustomizableFields.Controls.Clear();
                _customizableLoanFieldsControl = new CustomizableFieldsControl(entity, linkId, isActive)
                {
                    Dock = DockStyle.Fill,
                    Enabled = true,
                    Name = "customizableLoanFieldsControl",
                    Visible = true
                };
                tabPageLoanCustomizableFields.Controls.Add(_customizableLoanFieldsControl);

            }
            else if (entity == OCustomizableFieldEntities.Savings)
            {
                tabPageSavingsCustomizableFields.Controls.Clear();
                _customizableSavingsFieldsControl = new CustomizableFieldsControl(entity, linkId, isActive)
                {
                    Dock = DockStyle.Fill,
                    Enabled = true,
                    Name = "customizableSavingsFieldsControl",
                    Visible = true
                };
                tabPageSavingsCustomizableFields.Controls.Add(_customizableSavingsFieldsControl);
            }
        }
Пример #6
0
        public List<CustomizableFieldValue> CheckCustomizableFields(OCustomizableFieldEntities entity, CustomClass customFields, 
            CollectionList customizableFieldsCollections, int linkId, char linkType)
        {
            List<CustomizableFieldValue> fieldValues = new List<CustomizableFieldValue>();

            var customizableFieldsServices = ServicesProvider.GetInstance().GetCustomizableFieldsServices();
            List<CustomizableField> customizableFields = customizableFieldsServices.
                SelectCustomizableFields((int)Enum.Parse(typeof(OCustomizableFieldEntities), entity.ToString()));

            if (customizableFields != null)
            {
                foreach (CustomizableField field in customizableFields)
                {
                    CustomizableFieldValue customizableFieldValue = new CustomizableFieldValue {Field = field};

                    var fieldName = field.Name;
                    switch (field.Type)
                    {
                        case OCustomizableFieldTypes.Boolean:
                            customizableFieldValue.Value = ((bool) customFields.GetPropertyValueByName(fieldName)).ToString(CultureInfo.InvariantCulture);
                            break;
                        case OCustomizableFieldTypes.Number:
                            customizableFieldValue.Value = ((string)customFields.GetPropertyValueByName(fieldName));
                            break;
                        case OCustomizableFieldTypes.String:
                            customizableFieldValue.Value = (string)customFields.GetPropertyValueByName(fieldName);
                            break;
                        case OCustomizableFieldTypes.Date:
                            DateTime dateValue = (DateTime) customFields.GetPropertyValueByName(fieldName);
                            customizableFieldValue.Value = Converter.CustomFieldDateToString(dateValue);
                            break;
                        case OCustomizableFieldTypes.Client:
                            customizableFieldValue.Value = customFields.GetPropertyValueByName(fieldName).ToString();
                            break;
                        case OCustomizableFieldTypes.Collection:
                            {
                                int index = customizableFieldsCollections.GetItemIndexByName(fieldName, (string)customFields.GetPropertyValueByName(fieldName));
                                if (index != -1) customizableFieldValue.Value = index.ToString(CultureInfo.InvariantCulture);
                            }
                            break;
                    }

                    var fieldType = field.Type;
                    var fieldValue = customizableFieldValue.Value;
                    if (customizableFieldValue.Field.IsMandatory)
                        if (
                            (fieldType == OCustomizableFieldTypes.Number && fieldValue == string.Empty) ||
                            (fieldType == OCustomizableFieldTypes.String && fieldValue == string.Empty) ||
                            (fieldType == OCustomizableFieldTypes.Date && Converter.CustomFieldValueToDate(fieldValue) == DateTime.MinValue) ||
                            (fieldType == OCustomizableFieldTypes.Collection && fieldValue == null) ||
                            (fieldType == OCustomizableFieldTypes.Client && fieldValue == string.Empty)
                        )
                            throw new OpenCbsContractSaveException(OpenCbsContractSaveExceptionEnum.FieldIsMandatory);

                    if (fieldType == OCustomizableFieldTypes.Number)
                    {
                        if (fieldValue != string.Empty)
                        {
                            decimal result;
                            if (!Converter.CustomFieldDecimalParse(out result, fieldValue))
                                throw new OpenCbsContractSaveException(
                                    OpenCbsContractSaveExceptionEnum.NumberFieldIsNotANumber);
                        }
                    }

                    if (fieldType == OCustomizableFieldTypes.String)
                    {
                        if (fieldValue.Length>300)
                            throw new OpenCbsCustomFieldNameException(OCustomFieldExceptionEnum.FieldLimited);
                    }

                    if (field.IsUnique)
                    {
                        if (
                            fieldType == OCustomizableFieldTypes.Number ||
                            fieldType == OCustomizableFieldTypes.String ||
                            fieldType == OCustomizableFieldTypes.Date ||
                            fieldType == OCustomizableFieldTypes.Client
                        )
                        {
                            if (customizableFieldsServices.FieldValueExists(linkId, linkType, customizableFieldValue.Field.Id, fieldValue))
                                throw new OpenCbsContractSaveException(OpenCbsContractSaveExceptionEnum.FieldIsNotUnique);
                        }
                    }

                    fieldValues.Add(customizableFieldValue);
                }
            }
            return fieldValues;
        }
Пример #7
0
 public void SaveValues(OCustomizableFieldEntities entity, CustomClass customFields, CollectionList customizableFieldsCollections, int linkId, char linkType)
 {
     List<CustomizableFieldValue> fieldValues = CheckCustomizableFields(entity, customFields, customizableFieldsCollections, linkId, linkType);
     _customizableFieldsManager.SaveCustomizableFieldValues(fieldValues, linkId, linkType);
 }
Пример #8
0
 public bool CustomizableFieldsExistFor(OCustomizableFieldEntities entity)
 {
     return _customizableFieldsManager.CustomizableFieldsExistFor(entity);
 }
 public bool CustomizableFieldsExistFor(OCustomizableFieldEntities entity)
 {
     return(_customizableFieldsManager.CustomizableFieldsExistFor(entity));
 }
        public void SaveValues(OCustomizableFieldEntities entity, CustomClass customFields, CollectionList customizableFieldsCollections, int linkId, char linkType)
        {
            List <CustomizableFieldValue> fieldValues = CheckCustomizableFields(entity, customFields, customizableFieldsCollections, linkId, linkType);

            _customizableFieldsManager.SaveCustomizableFieldValues(fieldValues, linkId, linkType);
        }
        public List <CustomizableFieldValue> CheckCustomizableFields(OCustomizableFieldEntities entity, CustomClass customFields,
                                                                     CollectionList customizableFieldsCollections, int linkId, char linkType)
        {
            List <CustomizableFieldValue> fieldValues = new List <CustomizableFieldValue>();

            var customizableFieldsServices = ServicesProvider.GetInstance().GetCustomizableFieldsServices();
            List <CustomizableField> customizableFields = customizableFieldsServices.
                                                          SelectCustomizableFields((int)Enum.Parse(typeof(OCustomizableFieldEntities), entity.ToString()));

            if (customizableFields != null)
            {
                foreach (CustomizableField field in customizableFields)
                {
                    CustomizableFieldValue customizableFieldValue = new CustomizableFieldValue {
                        Field = field
                    };

                    var fieldName = field.Name;
                    switch (field.Type)
                    {
                    case OCustomizableFieldTypes.Boolean:
                        customizableFieldValue.Value = ((bool)customFields.GetPropertyValueByName(fieldName)).ToString(CultureInfo.InvariantCulture);
                        break;

                    case OCustomizableFieldTypes.Number:
                        customizableFieldValue.Value = ((string)customFields.GetPropertyValueByName(fieldName));
                        break;

                    case OCustomizableFieldTypes.String:
                        customizableFieldValue.Value = (string)customFields.GetPropertyValueByName(fieldName);
                        break;

                    case OCustomizableFieldTypes.Date:
                        DateTime dateValue = (DateTime)customFields.GetPropertyValueByName(fieldName);
                        customizableFieldValue.Value = Converter.CustomFieldDateToString(dateValue);
                        break;

                    case OCustomizableFieldTypes.Client:
                        customizableFieldValue.Value = customFields.GetPropertyValueByName(fieldName).ToString();
                        break;

                    case OCustomizableFieldTypes.Collection:
                    {
                        int index = customizableFieldsCollections.GetItemIndexByName(fieldName, (string)customFields.GetPropertyValueByName(fieldName));
                        if (index != -1)
                        {
                            customizableFieldValue.Value = index.ToString(CultureInfo.InvariantCulture);
                        }
                    }
                    break;
                    }

                    var fieldType  = field.Type;
                    var fieldValue = customizableFieldValue.Value;
                    if (customizableFieldValue.Field.IsMandatory)
                    {
                        if (
                            (fieldType == OCustomizableFieldTypes.Number && fieldValue == string.Empty) ||
                            (fieldType == OCustomizableFieldTypes.String && fieldValue == string.Empty) ||
                            (fieldType == OCustomizableFieldTypes.Date && Converter.CustomFieldValueToDate(fieldValue) == DateTime.MinValue) ||
                            (fieldType == OCustomizableFieldTypes.Collection && fieldValue == null) ||
                            (fieldType == OCustomizableFieldTypes.Client && fieldValue == string.Empty)
                            )
                        {
                            throw new OpenCbsContractSaveException(OpenCbsContractSaveExceptionEnum.FieldIsMandatory);
                        }
                    }

                    if (fieldType == OCustomizableFieldTypes.Number)
                    {
                        if (fieldValue != string.Empty)
                        {
                            decimal result;
                            if (!Converter.CustomFieldDecimalParse(out result, fieldValue))
                            {
                                throw new OpenCbsContractSaveException(
                                          OpenCbsContractSaveExceptionEnum.NumberFieldIsNotANumber);
                            }
                        }
                    }

                    if (fieldType == OCustomizableFieldTypes.String)
                    {
                        if (fieldValue.Length > 300)
                        {
                            throw new OpenCbsCustomFieldNameException(OCustomFieldExceptionEnum.FieldLimited);
                        }
                    }

                    if (field.IsUnique)
                    {
                        if (
                            fieldType == OCustomizableFieldTypes.Number ||
                            fieldType == OCustomizableFieldTypes.String ||
                            fieldType == OCustomizableFieldTypes.Date ||
                            fieldType == OCustomizableFieldTypes.Client
                            )
                        {
                            if (customizableFieldsServices.FieldValueExists(linkId, linkType, customizableFieldValue.Field.Id, fieldValue))
                            {
                                throw new OpenCbsContractSaveException(OpenCbsContractSaveExceptionEnum.FieldIsNotUnique);
                            }
                        }
                    }

                    fieldValues.Add(customizableFieldValue);
                }
            }
            return(fieldValues);
        }