public static ActiveRecordBase GetEntityControlForm(Column column)
        {
            ActiveRecordBase entity = null;
            if (column == null)
                return null;

            Table selectedTable = column.Table;
            using (ISession session = ActiveRecordConfiguration.GetISession())
            {
                IQueryable<KPMappingEntity> queryable = session.Query<KPMappingEntity>()
                    .Where(x => x.OwnerSchema.Equals(selectedTable.OwnerSchema) &&
                                x.Database.Equals(selectedTable.DatabaseName) &&
                                x.Table.Equals(selectedTable.Name) &&
                                x.Column.Equals(column.Name));

                KPMappingEntity mapEntity = queryable.FirstOrDefault();
                if (mapEntity != null)
                {
                    switch (column.ColumnTypeForm)
                    {
                        case KPComponentsFormsEnum.KPFormItemButton:
                            entity = new KPFormItemButtonEntity().GetEntityByMapping(mapEntity, column);
                            break;
                        case KPComponentsFormsEnum.KPFormItemCheckBox:
                            entity = new KPFormItemCheckBoxEntity().GetEntityByMapping(mapEntity, column);
                            break;
                        case KPComponentsFormsEnum.KPFormItemCombo:
                            entity = new KPFormItemComboEntity().GetEntityByMapping(mapEntity, column);
                            break;
                        case KPComponentsFormsEnum.KPFormItemEntity:
                            entity = new KPFormItemEntityEntity().GetEntityByMapping(mapEntity, column);
                            break;
                        case KPComponentsFormsEnum.KPFormItemGrid:
                            entity = new KPFormItemGridEntity().GetEntityByMapping(mapEntity, column);
                            break;
                        case KPComponentsFormsEnum.KPFormItemPassword:
                            entity = new KPFormItemPasswordEntity().GetEntityByMapping(mapEntity, column);
                            break;
                        case KPComponentsFormsEnum.KPFormItemText:
                            entity = new KPFormItemTextEntity().GetEntityByMapping(mapEntity, column);
                            break;
                        case KPComponentsFormsEnum.KPFormItemDateTime:
                            entity = new KPFormItemDateTimeEntity().GetEntityByMapping(mapEntity, column);
                            break;
                        case KPComponentsFormsEnum.KPFormItemZoom:
                            entity = new KPFormItemZoomEntity().GetEntityByMapping(mapEntity, column);
                            break;
                    }
                }
            }

            return entity;
        }
 public static KPComponentsViewEnum GetKPComponentsView(Column column)
 {
     if (column.MappedDataType == typeof(bool) || column.MappedDataType == typeof(bool?))
     {
         return KPComponentsViewEnum.KPBooleanModel;
     }
     else if (column.IsForeignKey)
     {
         return KPComponentsViewEnum.KPEntityModel;
     }
     return KPComponentsViewEnum.KPColumnModel;
 }
 public static KPComponentsFormsEnum GetKPComponentsForms(Column column)
 {
     if (column.MappedDataType == typeof(bool) || column.MappedDataType == typeof(bool?))
     {
         return KPComponentsFormsEnum.KPFormItemCheckBox;
     }
     else if (column.MappedDataType == typeof(DateTime) || column.MappedDataType == typeof(DateTime?))
     {
         return KPComponentsFormsEnum.KPFormItemDateTime;
     }
     else if (column.IsForeignKey)
     {
         return KPComponentsFormsEnum.KPFormItemZoom;
     }
     else if (column.IsPrimaryKey)
     {
         return KPComponentsFormsEnum.KPFormItemKey;
     }
     return KPComponentsFormsEnum.KPFormItemText;
 }
        public static ActiveRecordBase GetEntityControlView(Column column)
        {
            ActiveRecordBase entity = null;
            if (column == null)
                return null;

            Table selectedTable = column.Table;
            using (ISession session = ActiveRecordConfiguration.GetISession())
            {
                IQueryable<KPMappingEntity> queryable = session.Query<KPMappingEntity>()
                    .Where(x => x.OwnerSchema.Equals(selectedTable.OwnerSchema) &&
                                x.Database.Equals(selectedTable.DatabaseName) &&
                                x.Table.Equals(selectedTable.Name) &&
                                x.Column.Equals(column.Name));

                KPMappingEntity mapEntity = queryable.FirstOrDefault();
                if (mapEntity != null)
                {
                    switch (column.ColumnTypeView)
                    {
                        case KPComponentsViewEnum.KPColumnModel:
                            entity = new KPColumnModelEntity().GetEntityByMapping(mapEntity, column);
                            break;
                        case KPComponentsViewEnum.KPEnumModel:
                            entity = new KPEnumModelEntity().GetEntityByMapping(mapEntity, column);
                            break;
                        case KPComponentsViewEnum.KPEntityModel:
                            entity = new KPEntityModelEntity().GetEntityByMapping(mapEntity, column);
                            break;
                        case KPComponentsViewEnum.KPBooleanModel:
                            entity = new KPBooleanModelEntity().GetEntityByMapping(mapEntity, column);
                            break;
                    }
                }
            }

            return entity;
        }
        private string GetControlKPFormItemZoomEntity(Column column)
        {
            KPFormItemZoomEntity entity = column.EntityComponentForm as KPFormItemZoomEntity;
            StringBuilder sbEvent = new StringBuilder();
            if (entity == null)
                return String.Empty;

            if (entity.KPEventZoomLostFocus)
            {
                sbEvent.AppendFormat(@"{0}{0}protected void {1}_KPEventZoomLostFocus()", UtilCharacter.TAB_SPACE, column.Name.GetFormattedText()).Append(UtilCharacter.NEW_LINE);
                sbEvent.AppendFormat(@"{0}{0}{{", UtilCharacter.TAB_SPACE).Append(UtilCharacter.NEW_LINE);
                sbEvent.AppendFormat(@"{0}{0}}}", UtilCharacter.TAB_SPACE).Append(UtilCharacter.NEW_LINE);
            }

            return sbEvent.ToString();
        }
        private string GetControlKPFormItemGridEntity(Column column)
        {
            KPFormItemGridEntity entity = column.EntityComponentForm as KPFormItemGridEntity;
            StringBuilder sbEvent = new StringBuilder();
            if (entity == null)
                return String.Empty;

            if (entity.KPEventDeleteLine)
            {
                sbEvent.AppendFormat(@"{0}{0}protected void {1}_KPDeleteLine(object sender, GridViewDeleteEventArgs e)", UtilCharacter.TAB_SPACE, column.Name.GetFormattedText()).Append(UtilCharacter.NEW_LINE);
                sbEvent.AppendFormat(@"{0}{0}{{", UtilCharacter.TAB_SPACE).Append(UtilCharacter.NEW_LINE);
                sbEvent.AppendFormat(@"{0}{0}}}", UtilCharacter.TAB_SPACE).Append(UtilCharacter.NEW_LINE);
            }

            return sbEvent.ToString();
        }
        private int GetWidthComponent(KPMaskTypeClassEnum? markType, Column column)
        {
            int width = 100;
            if (column.IsPrimaryKey)
                return 100;

            if (Int32.TryParse(column.DataSize, out width))
                width = width * 9;
            else
                width = 400;

            if (width > 400)
                width = 400;

            if (!markType.HasValue)
                return width;

            switch (markType.Value)
            {
                case KPMaskTypeClassEnum.CGC:
                case KPMaskTypeClassEnum.CNPJ:
                case KPMaskTypeClassEnum.CPF:
                    return 135;
                case KPMaskTypeClassEnum.DATE:
                    return 90;
                case KPMaskTypeClassEnum.DATEHOUR:
                    return 110;
                case KPMaskTypeClassEnum.DATEMINUTE:
                    return 130;
                case KPMaskTypeClassEnum.DATETIME:
                    return 150;
                case KPMaskTypeClassEnum.INTEGER:
                    return 70;
                case KPMaskTypeClassEnum.POSTCODE:
                    return 70;
                case KPMaskTypeClassEnum.TELEPHONE:
                    return 106;
            }
            return width;
        }
        private string GetControlKPFormItemDateTimeEntity(Column column)
        {
            string propertyConcat = String.Empty;
            KPFormItemDateTimeEntity entity = column.EntityComponentForm as KPFormItemDateTimeEntity;
            if (entity == null)
            {
                entity = new KPFormItemDateTimeEntity()
                {
                    Title = GlobalizationLanguage.GetString("KPEntity_Title"),
                    IsRequired = !column.IsNullable
                };
            }

            if (!String.IsNullOrWhiteSpace(entity.Title))
                propertyConcat += String.Format(@" Title=""{0}""", entity.Title);
            if (entity.IsRequired)
                propertyConcat += String.Format(@" IsRequired=""{0}""", entity.IsRequired.ToString().ToLower());
            if (entity.Type.HasValue)
                propertyConcat += String.Format(@" Type=""{0}""", entity.Type.Value.ToString());
            if (entity.KPEventTextLostFocus)
                propertyConcat += String.Format(@" OnKPEventTextLostFocus=""{0}_KPEventTextLostFocus""", column.Name.GetFormattedText());

            return propertyConcat;
        }
 public ZoomConfig(Column column, KPFormItemZoomEntity zoomEntity)
 {
     Column = column;
     ZoomEntity = zoomEntity;
     if (ZoomEntity == null)
         ZoomEntity = new KPFormItemZoomEntity();
 }
        private string GetControlKPFormItemTextEntity(Column column)
        {
            string propertyConcat = String.Empty;
            KPFormItemTextEntity entity = column.EntityComponentForm as KPFormItemTextEntity;
            if (entity == null)
            {
                entity = new KPFormItemTextEntity()
                {
                    Title = GlobalizationLanguage.GetString("KPEntity_Title"),
                    IsRequired = !column.IsNullable
                };
            }

            var title = entity.Title;
            var isRequired = entity.IsRequired;
            var isMultiLine = entity.IsMultiline;
            var height = entity.Height;
            var eventLostFocus = entity.KPEventTextLostFocus;

            if (!String.IsNullOrWhiteSpace(title))
                propertyConcat += String.Format(@" Title=""{0}""", title);
            if (isRequired)
                propertyConcat += String.Format(@" IsRequired=""{0}""", isRequired.ToString().ToLower());
            if (isMultiLine)
                propertyConcat += String.Format(@" MultiLine=""{0}""", isMultiLine.ToString().ToLower());
            if (height > 0)
                propertyConcat += String.Format(@" Height=""{0}""", height);
            if (eventLostFocus)
                propertyConcat += String.Format(@" OnKPEventTextLostFocus=""{0}_KPEventTextLostFocus""", column.Name.GetFormattedText());

            return propertyConcat;
        }
        private string GetControlKPFormItemZoomEntity(Column column)
        {
            string propertyConcat = String.Empty;
            KPFormItemZoomEntity entity = column.EntityComponentForm as KPFormItemZoomEntity;
            if (entity == null)
            {
                entity = new KPFormItemZoomEntity()
                {
                    Title = GlobalizationLanguage.GetString("KPEntity_Title"),
                    IsRequired = !column.IsNullable
                };
            }

            var title = entity.Title;
            var isRequired = entity.IsRequired;
            var descriptionWidth = entity.DescriptionWidth;
            var eventLostFocus = entity.KPEventZoomLostFocus;

            if (!String.IsNullOrWhiteSpace(title))
                propertyConcat += String.Format(@" Title=""{0}""", title);
            if (isRequired)
                propertyConcat += String.Format(@" IsRequired=""{0}""", isRequired.ToString().ToLower());
            if (descriptionWidth > 0)
                propertyConcat += String.Format(@" DescriptionWidth=""{0}""", descriptionWidth);
            if (eventLostFocus)
                propertyConcat += String.Format(@" OnKPEventZoomLostFocus=""{0}_KPEventZoomLostFocus""", column.Name.GetFormattedText());

            return propertyConcat;
        }
        private string GetControlKPFormItemGridEntity(Column column)
        {
            string propertyConcat = String.Empty;
            KPFormItemGridEntity entity = column.EntityComponentForm as KPFormItemGridEntity;
            if (entity == null)
                entity = new KPFormItemGridEntity();

            var isRequired = entity.IsRequired;
            var height = entity.Height;
            var eventDeleteLine = entity.KPEventDeleteLine;

            if (height > 0)
                propertyConcat += String.Format(@" Height=""{0}""", height);
            if (isRequired)
                propertyConcat += String.Format(@" IsRequired=""{0}""", isRequired.ToString().ToLower());
            if (eventDeleteLine)
                propertyConcat += String.Format(@" OnKPDeleteLine=""{0}_KPDeleteLine""", column.Name.GetFormattedText());

            return propertyConcat;
        }
        private string GetControlKPFormItemEntityEntity(Column column)
        {
            string propertyConcat = String.Empty;
            KPFormItemEntityEntity entity = column.EntityComponentForm as KPFormItemEntityEntity;
            if (entity == null)
            {
                entity = new KPFormItemEntityEntity()
                {
                    Title = GlobalizationLanguage.GetString("KPEntity_Title"),
                    IsRequired = !column.IsNullable
                };
            }

            var isRequired = entity.IsRequired;
            var title = entity.Title;
            var fieldNameDescription = entity.FieldNameDescription;

            if (!String.IsNullOrWhiteSpace(title))
                propertyConcat += String.Format(@" Title=""{0}""", title);
            if (!String.IsNullOrWhiteSpace(fieldNameDescription))
                propertyConcat += String.Format(@" Description=""{0}""", fieldNameDescription);
            if (isRequired)
                propertyConcat += String.Format(@" IsRequired=""{0}""", isRequired.ToString().ToLower());

            return propertyConcat;
        }
        private string GetControlKPFormItemComboEntity(Column column)
        {
            string propertyConcat = String.Empty;
            KPFormItemComboEntity entity = column.EntityComponentForm as KPFormItemComboEntity;
            if (entity == null)
            {
                entity = new KPFormItemComboEntity()
                {
                    Title = GlobalizationLanguage.GetString("KPEntity_Title"),
                    IsRequired = !column.IsNullable
                };
            }

            var isRequired = entity.IsRequired;
            var title = entity.Title;
            var namespaceEnum = entity.NamespaceEnum;
            var dataName = entity.DataName;
            var dataValue = entity.DataValue;
            var eventSelectChange = entity.KPEventComboSelectChange;

            if (!String.IsNullOrWhiteSpace(title))
                propertyConcat += String.Format(@" Title=""{0}""", title);
            if (!String.IsNullOrWhiteSpace(namespaceEnum))
                propertyConcat += String.Format(@" NamespaceEnum=""{0}""", namespaceEnum);
            if (isRequired)
                propertyConcat += String.Format(@" IsRequired=""{0}""", isRequired.ToString().ToLower());
            if (!String.IsNullOrWhiteSpace(dataName) && !String.IsNullOrWhiteSpace(dataValue))
                propertyConcat += String.Format(@" DataName=""{0}"" DataValue=""{1}""", dataName, dataValue);
            if (eventSelectChange)
                propertyConcat += String.Format(@" OnKPEventComboSelectChange=""{0}_KPEventComboSelectChange""", column.Name.GetFormattedText());

            return propertyConcat;
        }
        private string GetControlKPFormItemCheckBoxEntity(Column column)
        {
            string propertyConcat = String.Empty;
            KPFormItemCheckBoxEntity entity = column.EntityComponentForm as KPFormItemCheckBoxEntity;
            if (entity == null)
            {
                entity = new KPFormItemCheckBoxEntity()
                {
                    Description = GlobalizationLanguage.GetString("KP_Description"),
                    IsRequired = !column.IsNullable
                };
            }

            var isRequired = entity.IsRequired;
            var isGroupStyleDisplay = entity.IsGroupStyleDisplay;
            var description = entity.Description;
            var eventSelect = entity.KPEventCheckBoxSelect;

            if (!String.IsNullOrWhiteSpace(description))
                propertyConcat += String.Format(@" Description=""{0}""", description);
            if (isRequired)
                propertyConcat += String.Format(@" IsRequired=""{0}""", isRequired.ToString().ToLower());
            if (isGroupStyleDisplay)
                propertyConcat += String.Format(@" IsGroupStyleDisplay=""{0}""", isGroupStyleDisplay.ToString().ToLower());
            if (eventSelect)
                propertyConcat += String.Format(@" OnKPEventCheckBoxSelect=""{0}_KPEventCheckBoxSelect""", column.Name.GetFormattedText());

            return propertyConcat;
        }
        private string GetControlKPFormItemButtonEntity(Column column)
        {
            string propertyConcat = String.Empty;
            KPFormItemButtonEntity entity = column.EntityComponentForm as KPFormItemButtonEntity;
            if (entity == null)
            {
                entity = new KPFormItemButtonEntity()
                {
                    Title = GlobalizationLanguage.GetString("KPEntity_Title")
                };
            }

            var title = entity.Title;
            var eventClick = entity.KPEventClick;

            if (!String.IsNullOrWhiteSpace(title))
                propertyConcat += String.Format(@" Title=""{0}""", title);
            if (eventClick)
                propertyConcat += String.Format(@" OnKPClick=""{0}_KPClick""", column.Name.GetFormattedText());

            return propertyConcat;
        }