// Valg at iDatabase
        private IJsonDatabase DatabaseChoice(EnumDatabase databaseChoice)
        {
            int i = (int)databaseChoice;

            switch (i)
            {
            case 0:
            {
                databaseName = "Patient";
                return(iDatabase = new JsonPatientId());
            }

            case 1:
            {
                databaseName = "ProfessionalUser";
                return(iDatabase = new JsonProfessionalUser());
            }

            case 2:
            {
                databaseName = "Measurement";
                return(iDatabase = new JsonMeasurement());
            }

            default:
            {
                return(null);
            }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Cadena de conexion de Sql Server
 /// </summary>
 /// <param name="database">Base de datos</param>
 /// <history>
 /// [wtorres]  14/Abr/2016 Created
 /// [wtorres]  30/Jun/2016 Modified. Agregue el parametro database
 /// </history>
 private static string SqlConnectionString(EnumDatabase database)
 {
     if (string.IsNullOrEmpty(_sqlConnectionString[(int)database]))
     {
         _sqlConnectionString[(int)database] = AppConfigHelper.GetSettingByKey(ConnectionKey(database));
     }
     return(_sqlConnectionString[(int)database]);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Nombre de la base de datos
        /// </summary>
        /// <param name="database">Base de datos</param>
        /// <history>
        /// [wtorres]  12/Abr/2016 Created
        /// [wtorres]  30/Jun/2016 Modified. Agregue el parametro database
        /// </history>
        public static string DatabaseName(EnumDatabase database)
        {
            SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder();

            sqlBuilder.ConnectionString = SqlConnectionString(database);

            return(sqlBuilder.InitialCatalog);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Nombre del servidor
        /// </summary>
        /// <param name="database">Base de datos</param>
        /// <history>
        /// [wtorres]  12/Abr/2016 Created
        /// [wtorres]  30/Jun/2016 Modified. Agregue el parametro database
        /// </history>
        public static string ServerName(EnumDatabase database)
        {
            SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder();

            sqlBuilder.ConnectionString = SqlConnectionString(database);

            return(sqlBuilder.DataSource);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Obtiene las propiedades de una tabla a partir de una entidad
        /// </summary>
        /// <param name="entity">Entidad para buscar su tabla</param>
        /// <param name="database">enumerado para saber a que base de datos se va a conectar</param>
        /// <returns>Lista de tipo ColumnDefinition con todos los datos</returns>
        /// <history>
        /// [emoguel] created 05/08/2016
        /// </history>
        public static List <ColumnDefinition> GetFieldsByTable <T>(T entity, EnumDatabase database) where T : class
        {
            DbContext dbContext = null;

            #region dbContext
            switch (database)
            {
            case EnumDatabase.IntelligentMarketing:
            {
                dbContext = new IMEntities(ConnectionHelper.ConnectionString());
                break;
            }

            case EnumDatabase.Asistencia:
            {
                dbContext = new AsistenciaEntities(ConnectionHelper.ConnectionString(database));
                break;
            }

            case EnumDatabase.IntelligenceContracts:
            {
                dbContext = new ICEntities(ConnectionHelper.ConnectionString(database));
                break;
            }
            }
            #endregion

            using (dbContext)
            {
                string strTableName    = GetTableName(entity, dbContext);
                string strDatabaseName = dbContext.Database.Connection.Database;
                #region Query
                string strQuery = "Use " + strDatabaseName + @"  SELECT
                 C.name as [Column],
                 T.name as [Type],
                 C.Precision,
                 C.Scale,
                 CASE WHEN CE.NUMERIC_PRECISION IS NOT NULL THEN CE.NUMERIC_PRECISION + (CASE WHEN CE.NUMERIC_SCALE > 0 THEN 1 ELSE 0 END)
                       ELSE IsNull(CE.CHARACTER_MAXIMUM_LENGTH, C.precision) END as MaxLength,
                 CE.COLUMN_DEFAULT as [Default Value],
                 CE.IS_NULLABLE as Nullable,
                 IsNull(P.value, '') as Description
          FROM sys.tables as TA
                 LEFT JOIN sysusers S on TA.schema_id = S.uid
                 INNER JOIN sys.columns as C on C.object_id = TA.object_id
                 INNER JOIN sys.types as T on T.system_type_id = C.system_type_id and T.name <> 'sysname'
                 LEFT JOIN INFORMATION_SCHEMA.COLUMNS CE ON CE.TABLE_SCHEMA = S.name AND CE.TABLE_NAME = TA.name AND CE.COLUMN_NAME = C.name
                 LEFT JOIN sys.extended_properties as P on P.major_id = C.object_id and P.minor_id = C.column_id and P.class = 1
          WHERE TA.name = '" + strTableName + @"'
          ORDER BY S.name, TA.name, C.column_id
          ";
                #endregion
                var dQuery = dbContext.Database.SqlQuery <ColumnDefinition>(strQuery);
                return(dQuery.ToList());
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Cadena de conexion
 /// </summary>
 /// <param name="database">Base de datos</param>
 /// <history>
 /// [wtorres]  22/Mar/2016 Created
 /// [wtorres]  30/Jun/2016 Modified. Agregue el parametro database
 /// </history>
 public static string ConnectionString(EnumDatabase database = EnumDatabase.IntelligentMarketing)
 {
     if (string.IsNullOrEmpty(_connectionString[(int)database]))
     {
         EntityConnectionStringBuilder builder = new EntityConnectionStringBuilder();
         builder.Provider = "System.Data.SqlClient";
         builder.ProviderConnectionString = SqlConnectionString(database);
         string databaseModel = EnumToListHelper.GetEnumDescription(database);
         builder.Metadata = $"res://*/{databaseModel}.csdl|res://*/{databaseModel}.ssdl|res://*/{databaseModel}.msl";
         _connectionString[(int)database] = builder.ToString();
     }
     return(_connectionString[(int)database]);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Clave de la cadena de conexion en el servicio web de App Config Manager
        /// </summary>
        /// <param name="database">Base de datos</param>
        /// <history>
        /// [wtorres]  22/Mar/2016 Created
        /// [wtorres]  30/Jun/2016 Modified. Agregue el parametro database
        /// </history>
        private static string ConnectionKey(EnumDatabase database)
        {
            switch (database)
            {
            case EnumDatabase.Asistencia:
                return(ConfigHelper.GetString("Asistencia.ConnectionKey"));

            case EnumDatabase.IntelligenceContracts:
                return(ConfigHelper.GetString("IntelligenceContracts.ConnectionKey"));

            default:
                return(ConfigHelper.GetString("IntelligenceMarketing.ConnectionKey"));
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// call this method to execute this database Action class
        /// </summary>
        /// <returns></returns>
        /// <remarks></remarks>
        internal T Execute(EnumDatabase dbName)
        {
            _connection = GenericDBFactory.GetConnection(dbName);


            ConnectionState FinallyExpected = ConnectionState.Closed; // this is the expected state at the end of the operation
            ConnectionState FinallyActual   = 0;
            T ReturnInstance;

            // 'using' clause will ensure the proper clasong of the connection
            using (_connection)
            {
                try
                {
                    if (_connection.State != System.Data.ConnectionState.Open)
                    {
                        _connection.Open(); //open the connection
                    }
                    // check connection opened proprely
                    if (_connection.State != System.Data.ConnectionState.Open)
                    {
                        throw (new Exception("Problem in opening the DB Connection. Connection not opened"));
                    }
                    // run the command body of this command
                    ReturnInstance = Body(_connection);
                }
                catch (System.Exception ex) // some problem occured in executing this command
                {
                    //US.CreditorPortal.Core.DataAccess.Core.Exception.USPException exp = new US.CreditorPortal.Core.DataAccess.Core.Exception.USPException();
                    //exp.logg(ex.Message);

                    throw (new Exception("Error on data. " + ex.Message));
                }
                finally // close the connection
                {
                    if (!(_connection.State == System.Data.ConnectionState.Closed))
                    {
                        _connection.Close();
                        FinallyActual = _connection.State;
                    }
                }
            }

            if (FinallyExpected != FinallyActual)
            {
                throw (new Exception("Problem in closing the DB connection. Db connection is not properly closed"));
            }
            return(ReturnInstance);
        }
        /// <summary>
        /// To get a new Db connection call this method. Returned connection is not yet opened.
        /// Please make sure that you open it before use and then close it after.
        /// </summary>
        /// <returns>new database connection</returns>
        /// <remarks></remarks>
        internal static DbConnection GetConnection(EnumDatabase dbName)
        {
            string ConnectionString = "";

            if (dbName == EnumDatabase.Recruitment)
            {
                //ConnectionString = "server =USBOXSQL;uid = sa;pwd =box@sql787;database = Recruitment;Connection Timeout=120" providerName = "System.Data.SqlClient";
                ConnectionString = AppSettings.ConnectionString; //"Server= UNICORNDKALP;Integrated Security=True;Database= Recruitment";
                //ConnectionString = ConfigurationManager.ConnectionStrings["Recruitment"].ConnectionString;
            }

            DbConnection Connection = Factory.CreateConnection();

            Connection.ConnectionString = ConnectionString;

            return(Connection);
        }
Exemplo n.º 10
0
        private static DbConnection GetConnectionByName(EnumDatabase dbName)
        {
            string ConnectionString = "";

            switch (dbName)
            {
            case EnumDatabase.HMS:
                ConnectionString = IOSRunTimeVariables.GetConnectionString();
                break;

            case EnumDatabase.IBE:
                break;

            case EnumDatabase.D2S:
                ConnectionString = IOSRunTimeVariables.D2SConnectionString();

                break;

            case EnumDatabase.VNT:
                break;

            case EnumDatabase.Search:
                break;

            case EnumDatabase.RVN:
                break;

            case EnumDatabase.Default:
                ConnectionString = IOSRunTimeVariables.GetConnectionString();
                break;

            default:
                break;
            }


            DbConnection Connection = Factory.CreateConnection();

            Connection.ConnectionString = ConnectionString;

            return(Connection);
        }
Exemplo n.º 11
0
        private static DbConnection GetConnectionByCompanyCode(EnumDatabase dbName, string companyCode)
        {
            string ConnectionString = string.Empty;

            if (dbName == EnumDatabase.Default)
            {
                if ((AppDomain.CurrentDomain.GetData(companyCode) == null))
                {
                    ConnectionString = ConnectionStringProvider.GetConStringFromDb(companyCode);
                    AppDomain.CurrentDomain.SetData(companyCode, ConnectionString);
                }
                else
                {
                    ConnectionString = AppDomain.CurrentDomain.GetData(companyCode).ToString();
                }
            }

            DbConnection Connection = Factory.CreateConnection();

            Connection.ConnectionString = ConnectionString;
            return(Connection);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Le asigna el maximo de escritura a los controles igual al que tienen en la BD
        /// </summary>
        /// <param name="obj">Objeto a validar las propiedades</param>
        /// <param name="ui">Contenedor donde va a buscar controles</param>
        /// <param name="enumMode">Modo en el que se abrió la ventana</param>
        /// <param name="blnCharacters">true. bloquea caracters especiales</param>
        /// <history>
        /// [emoguel] created 08/04/2016
        /// [emoguel] modified 11/07/2016
        /// [erosado] Modified. 12/08/2016. Se agrego para que acepte el MaxLenght de las cajas de texto o si no tuviera aceptaria las de la propiedad MaxLengthPropertyClass
        /// </history>
        public static void SetUpControls <T>(T obj, UIElement ui, EnumMode enumMode = EnumMode.ReadOnly, bool blnCharacters = false, EnumDatabase database = EnumDatabase.IntelligentMarketing) where T : class
        {
            List <Control> lstControls = GetChildParentCollection <Control>(ui);//Obtenemos la lista de controles del contenedor
            List <Model.Classes.ColumnDefinition> lstColumnsDefinitions = BRHelpers.GetFieldsByTable <T>(obj, database);

            Type type = obj.GetType();//Obtenemos el tipo de objeto

            if (lstControls.Count > 0)
            {
                #region DataGrid
                List <DataGrid> lstDataGrids = lstControls.Where(cl => cl is DataGrid && !((DataGrid)cl).IsReadOnly).OfType <DataGrid>().ToList();
                lstDataGrids.ForEach(dtg => dtg.Sorting += GridHelper.dtg_Sorting);
                #endregion

                #region Obtenemos el MaxLength
                foreach (PropertyInfo pi in type.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(pi => !pi.GetMethod.IsVirtual))//recorremos las propiedades
                {
                    //buscamos si existe el control
                    Control control = lstControls.FirstOrDefault(cl => cl.Name == "txt" + pi.Name);
                    //Buscamos la descripción de la columna
                    var columnDefinition = lstColumnsDefinitions.FirstOrDefault(cd => cd.column == pi.Name);
                    #region tooltip
                    var controlTooltip = lstControls.FirstOrDefault(cl => cl.Name.EndsWith(pi.Name));
                    if (controlTooltip != null && columnDefinition != null && !string.IsNullOrWhiteSpace(columnDefinition.description))
                    {
                        controlTooltip.ToolTip = columnDefinition.description;
                    }
                    #endregion

                    if (control != null && columnDefinition != null)        //Verifcamos que tengamos un control
                    {
                        TextBox         txt           = control as TextBox; //Convertimos el control a texbox
                        TypeCode        typeCode      = Type.GetTypeCode(Nullable.GetUnderlyingType(pi.PropertyType) ?? pi.PropertyType);
                        int             maxLengthProp = MaxLengthPropertyClass.GetMaxLength(txt) == 0 ? txt.MaxLength : MaxLengthPropertyClass.GetMaxLength(txt);
                        EnumFormatInput formatInput   = FormatInputPropertyClass.GetFormatInput(txt);//Formato del campo de texto
                        switch (typeCode)
                        {
                            #region String
                        case TypeCode.String:
                        case TypeCode.Char:
                        {
                            txt.MaxLength = (maxLengthProp > 0) ? maxLengthProp : columnDefinition.maxLength;//Asignamos el maxLength
                            if (formatInput == EnumFormatInput.NotSpecialCharacters)
                            {
                                txt.PreviewTextInput += TextBoxHelper.TextInputSpecialCharacters;
                            }
                            break;
                        }
                            #endregion

                            #region Decimal
                        case TypeCode.Decimal:
                        case TypeCode.Double:
                        {
                            //Si permite decimales
                            if (columnDefinition.scale > 0 || PrecisionPropertyClass.GetPrecision(txt) != "0,0")
                            {
                                if (PrecisionPropertyClass.GetPrecision(txt) == "0,0")
                                {
                                    PrecisionPropertyClass.SetPrecision(txt, columnDefinition.precision - columnDefinition.scale + "," + columnDefinition.scale);
                                }
                                txt.PreviewTextInput += TextBoxHelper.DecimalTextInput;
                                txt.PreviewKeyDown   += TextBoxHelper.Decimal_PreviewKeyDown;
                                txt.GotFocus         += TextBoxHelper.DecimalGotFocus;
                                if (enumMode != EnumMode.Search)
                                {
                                    txt.LostFocus += TextBoxHelper.LostFocus;
                                }
                            }
                            //Si sólo permite enteros
                            else
                            {
                                txt.PreviewTextInput += TextBoxHelper.IntTextInput;
                                txt.PreviewKeyDown   += TextBoxHelper.ValidateSpace;
                                if (enumMode != EnumMode.Search)
                                {
                                    txt.LostFocus += TextBoxHelper.LostFocus;
                                    txt.GotFocus  += TextBoxHelper.IntGotFocus;
                                }
                            }
                            txt.MaxLength = (maxLengthProp > 0) ? maxLengthProp : columnDefinition.maxLength;
                            break;
                        }
                            #endregion

                            #region Byte
                        case TypeCode.Byte:
                        {
                            txt.MaxLength         = (maxLengthProp > 0 && maxLengthProp <= 3) ? maxLengthProp : 3;
                            txt.PreviewTextInput += TextBoxHelper.ByteTextInput;
                            txt.PreviewKeyDown   += TextBoxHelper.ValidateSpace;
                            if (enumMode != EnumMode.Search)
                            {
                                txt.LostFocus += TextBoxHelper.LostFocus;
                            }
                            break;
                        }
                            #endregion

                            #region Int
                        case TypeCode.Int16:
                        case TypeCode.Int32:
                        case TypeCode.Int64:
                        {
                            switch (formatInput)
                            {
                            case EnumFormatInput.Number:
                                txt.PreviewTextInput += TextBoxHelper.IntTextInput;
                                txt.MaxLength         = (maxLengthProp > 0) ? maxLengthProp : columnDefinition.maxLength;
                                break;

                            case EnumFormatInput.NumberNegative:
                                txt.PreviewTextInput += TextBoxHelper.IntWithNegativeTextInput;
                                txt.MaxLength         = (maxLengthProp > 0) ? maxLengthProp + 1 : columnDefinition.maxLength + 1;
                                break;
                            }
                            txt.PreviewKeyDown += TextBoxHelper.ValidateSpace;
                            if (enumMode != EnumMode.Search)
                            {
                                txt.LostFocus += TextBoxHelper.LostFocus;
                            }
                            break;
                        }
                            #endregion

                            #region DateTime
                        case TypeCode.DateTime:
                        {
                            if (txt.Name.EndsWith("DT"))
                            {
                                txt.MaxLength = 24;
                            }
                            else if (txt.Name.EndsWith("T"))
                            {
                                txt.MaxLength = 5;
                            }
                            else
                            {
                                txt.MaxLength = 10;
                            }
                            break;
                        }
                            #endregion
                        }
                    }
                }
                #endregion
            }
        }
 // Det er ikke ligegyldigt hvilken database vi skriver til, vi laver dependency injection og vælger
 public CosmosDBService(EnumDatabase databaseChoice)
 {
     // Forsøger at lave det sådan, at man kan vælge hvilken database man skriver til så vi kun har en enkelt klasse.
     iDatabase = DatabaseChoice(databaseChoice);
 }
Exemplo n.º 14
0
        /// <summary>
        /// Configura el Estilo de los DataGridTextColumn
        /// Maxlength, Admision de caracteres especiales, Numerico, Decimal , Precision, Escala,
        /// </summary>
        /// <param name="dtgGrid">Grid a configurar</param>
        /// <param name="objBinding">Objeto con el que se quiere configurar el grid</param>
        /// <history>
        /// [emoguel] 28/07/2016  Created.
        /// [erosado] 29/07/2016  Modified. Se agregó el Tag para definir el Maxlength desde la columna.
        /// [emoguel] 13/10/2016 Modified. Se agrego en los strings que puedan recibir unicamente números
        /// </history>
        public static void SetUpGrid <T>(DataGrid dtgGrid, T objBinding,
                                         EnumDatabase database = EnumDatabase.IntelligentMarketing) where T : class
        {
            List <DataGridTextColumn> lstColumns =
                dtgGrid.Columns.Where(dgc => dgc is DataGridTextColumn).OfType <DataGridTextColumn>().ToList();
            List <Model.Classes.ColumnDefinition> lstColumnsDefinitions = BRHelpers.GetFieldsByTable <T>(objBinding, database);

            //Obtenemos la propiedades desde la BD

            #region Object properties

            Type type = objBinding.GetType();
            List <PropertyInfo> lstProperties =
                type.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(pi => !pi.GetMethod.IsVirtual).ToList();

            #endregion

            lstColumns.ForEach(dgc =>
            {
                if (!string.IsNullOrWhiteSpace(dgc.SortMemberPath))
                {
                    PropertyInfo property = lstProperties.Where(pi => pi.Name == dgc.SortMemberPath).FirstOrDefault();
                    var columnDefinition  = lstColumnsDefinitions.FirstOrDefault(cd => cd.column == dgc.SortMemberPath);
                    if (columnDefinition != null)
                    {
                        TypeCode typeCode =
                            Type.GetTypeCode(Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType);
                        Style style = new Style(typeof(TextBox));
                        EnumFormatInput formatInput = FormatInputPropertyClass.GetFormatInput(dgc); //Formato del campo de texto
                        int maxLengthProp           = MaxLengthPropertyClass.GetMaxLength(dgc);     //Maxlength definido desde la columna
                        switch (typeCode)
                        {
                            #region String

                        case TypeCode.String:
                        case TypeCode.Char:
                            {
                                style.Setters.Add(new Setter(TextBox.MaxLengthProperty,
                                                             (maxLengthProp > 0) ? maxLengthProp : columnDefinition.maxLength)); //Asignamos el maxLength
                                switch (formatInput)
                                {
                                case EnumFormatInput.NotSpecialCharacters: //Bloquea caracteres especiales
                                    {
                                        style.Setters.Add(new EventSetter(UIElement.PreviewTextInputEvent,
                                                                          new TextCompositionEventHandler(TextBoxHelper.TextInputSpecialCharacters)));
                                        break;
                                    }

                                case EnumFormatInput.Number://Cuando un String requiera guardar números enteros
                                    {
                                        style.Setters.Add(new EventSetter()
                                        {
                                            Event   = UIElement.PreviewTextInputEvent,
                                            Handler = new TextCompositionEventHandler(TextBoxHelper.IntTextInput)
                                        });
                                        break;
                                    }
                                }
                                dgc.EditingElementStyle = style;
                                break;
                            }

                            #endregion

                            #region Decimal

                        case TypeCode.Decimal:
                        case TypeCode.Double:
                            {
                                if (columnDefinition.scale > 0 || PrecisionPropertyClass.GetPrecision(dgc) != "0,0")
                                {
                                    style.Setters.Add(new EventSetter(UIElement.PreviewTextInputEvent,
                                                                      new TextCompositionEventHandler(TextBoxHelper.DecimalTextInput))); //Validar texto
                                    var precisionProperty = PrecisionPropertyClass.GetPrecision(dgc);
                                    if (precisionProperty == "0,0")
                                    {
                                        style.Setters.Add(new Setter(PrecisionPropertyClass.PrecisionProperty,
                                                                     columnDefinition.precision - columnDefinition.scale + "," + columnDefinition.scale));
                                        //Agregar Presicion
                                    }
                                    else
                                    {
                                        var precision = precisionProperty.Split(',');
                                        style.Setters.Add(new Setter(MaxLengthPropertyClass.MaxLengthProperty,
                                                                     Convert.ToInt16(precision[0]) + Convert.ToInt16(precision[1]) + 1));
                                        style.Setters.Add(new Setter(PrecisionPropertyClass.PrecisionProperty, precisionProperty));
                                        //Agregar Presicion
                                    }
                                    style.Setters.Add(new EventSetter(UIElement.PreviewKeyDownEvent,
                                                                      new KeyEventHandler(TextBoxHelper.Decimal_PreviewKeyDown))); //Validar espacios en blanco y borrado
                                }
                                else
                                {
                                    style.Setters.Add(new EventSetter(UIElement.PreviewTextInputEvent,
                                                                      new TextCompositionEventHandler(TextBoxHelper.IntTextInput))); //Validar enteros
                                    style.Setters.Add(new EventSetter(UIElement.PreviewKeyDownEvent,
                                                                      new KeyEventHandler(TextBoxHelper.Decimal_PreviewKeyDown)));   //Validar espacios en blanco
                                }
                                style.Setters.Add(new Setter(TextBox.MaxLengthProperty,
                                                             (maxLengthProp > 0) ? maxLengthProp : columnDefinition.maxLength)); //Asignamos el maxLength
                                break;
                            }

                            #endregion

                            #region Int

                        case TypeCode.Int16:
                        case TypeCode.Int32:
                        case TypeCode.Int64:
                            {
                                switch (formatInput)
                                {
                                case EnumFormatInput.Number:
                                    style.Setters.Add(new EventSetter()
                                    {
                                        Event   = UIElement.PreviewTextInputEvent,
                                        Handler = new TextCompositionEventHandler(TextBoxHelper.IntTextInput)
                                    });
                                    style.Setters.Add(new Setter(TextBox.MaxLengthProperty,
                                                                 (maxLengthProp > 0) ? maxLengthProp : columnDefinition.maxLength)); //Asignamos el maxLength
                                    break;

                                case EnumFormatInput.NumberNegative:
                                    style.Setters.Add(new EventSetter()
                                    {
                                        Event   = UIElement.PreviewTextInputEvent,
                                        Handler = new TextCompositionEventHandler(TextBoxHelper.IntWithNegativeTextInput)
                                    });
                                    style.Setters.Add(new Setter(TextBox.MaxLengthProperty,
                                                                 (maxLengthProp > 0) ? maxLengthProp + 1 : columnDefinition.maxLength + 1));
                                    break;
                                }
                                style.Setters.Add(new EventSetter()
                                {
                                    Event   = UIElement.PreviewKeyDownEvent,
                                    Handler = new KeyEventHandler(TextBoxHelper.ValidateSpace)
                                });
                                break;
                            }

                            #endregion

                            #region Byte

                        case TypeCode.Byte:
                            {
                                style.Setters.Add(new Setter(TextBox.MaxLengthProperty,
                                                             (maxLengthProp > 0 && maxLengthProp <= 3) ? maxLengthProp : 3));     //Asignamos el maxLength
                                style.Setters.Add(new EventSetter(UIElement.PreviewTextInputEvent,
                                                                  new TextCompositionEventHandler(TextBoxHelper.ByteTextInput))); //Validar enteros
                                style.Setters.Add(new EventSetter(UIElement.KeyDownEvent,
                                                                  new KeyEventHandler(TextBoxHelper.Decimal_PreviewKeyDown)));    //Validar enteros
                                break;
                            }

                            #endregion
                        }
                        dgc.EditingElementStyle = style;
                    }
                }
            });
        }
Exemplo n.º 15
0
 /// <summary>
 /// To get a new Db connection call this method. Returned connection is not yet opened.
 /// Please make sure that you open it before use and then close it after.
 /// </summary>
 /// <returns>new database connection</returns>
 /// <remarks></remarks>
 public static DbConnection GetConnection(EnumDatabase dbName)
 {
     return(GetConnectionByName(dbName));
 }