コード例 #1
0
        /// <summary>
        /// Lee la tabla base y retorna entidad con Id coincidente o null.
        /// </summary>
        /// <param name="Id">Entero que especifica la clave principal PK de la entidad.</param>
        /// <returns>Objeto del tipo Entidad definido en clase derivada.</returns>
        public T ReadEntityById(int Id)
        {
            T ent = default(T);

            using (IDbConnection connection = GetConnection())
            {
                IDbCommand command = connection.CreateCommand();
                command.Connection  = connection;
                command.CommandText = this.CommandText;
                command.CommandType = this.CommandType;

                foreach (IDataParameter param in this.GetParameters(command, Id))
                {
                    command.Parameters.Add(param);
                }

                try
                {
                    connection.Open();

                    using (IDataReader reader = command.ExecuteReader())
                    {
                        try
                        {
                            MapperBase <T> mapper = GetMapper();
                            ent = mapper.MapEntity(reader);
                            return(ent);
                        }
                        catch
                        {
                            throw;
                        }
                        finally
                        {
                            reader.Close();
                        }
                    }
                }
                catch
                {
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }
コード例 #2
0
        public Collection <T> ReadCollection(int id)
        {
            Collection <T> collection = new Collection <T>();

            using (IDbConnection connection = GetConnection())
            {
                IDbCommand command = connection.CreateCommand();
                command.Connection  = connection;
                command.CommandText = this.CommandText;
                command.CommandType = this.CommandType;

                foreach (IDataParameter param in this.GetParameters(command, id))
                {
                    command.Parameters.Add(param);
                }

                try
                {
                    connection.Open();

                    using (IDataReader reader = command.ExecuteReader())
                    {
                        try
                        {
                            MapperBase <T> mapper = GetMapper();
                            collection = mapper.MapAll(reader);
                            return(collection);
                        }
                        catch
                        {
                            throw;
                        }
                        finally
                        {
                            reader.Close();
                        }
                    }
                }
                catch
                {
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }
コード例 #3
0
        public override Collection <Checkinout> ReadCollectionBy2Params(string userId, string fecha)
        {
            Collection <Checkinout> collection = new Collection <Checkinout>();

            using (IDbConnection connection = GetConnection())
            {
                IDbCommand command = connection.CreateCommand();
                command.Connection  = connection;
                command.CommandText = this.CommandText;
                command.CommandType = this.CommandType;

                foreach (IDataParameter param in this.GetParameters(command))
                {
                    command.Parameters.Add(param);
                }

                // Creando Parametro para filtrar por userId y fecha
                IDataParameter param1 = command.CreateParameter();
                param1.ParameterName = Constants.FilterOneParam;
                param1.DbType        = DbType.String;
                param1.Value         = userId;
                command.Parameters.Add(param1);

                param1 = command.CreateParameter();
                param1.ParameterName = Constants.FilterTwoParam;
                param1.DbType        = DbType.String;
                param1.Value         = fecha;
                //Console.WriteLine("Fecha: " + fecha.ToString("yyyyMMdd"));

                command.Parameters.Add(param1);

                try
                {
                    connection.Open();

                    using (IDataReader reader = command.ExecuteReader())
                    {
                        try
                        {
                            MapperBase <Checkinout> mapper = GetMapper();
                            collection = mapper.MapAll(reader);
                            return(collection);
                        }
                        catch
                        {
                            throw;
                        }
                        finally
                        {
                            reader.Close();
                        }
                    }
                }
                catch
                {
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }
コード例 #4
0
        public override ClaveMes ReadEntityBy2Params(int mes, int anno)
        {
            using (IDbConnection connection = GetConnection())
            {
                IDbCommand command = connection.CreateCommand();
                command.Connection  = connection;
                command.CommandText = this.CommandText;
                command.CommandType = this.CommandType;

                foreach (IDataParameter param in this.GetParameters(command))
                {
                    command.Parameters.Add(param);
                }

                // Creando Parametro para filtrar por Mes y Anno
                IDataParameter param1 = command.CreateParameter();
                param1.ParameterName = Constants.FilterOneParam;
                param1.DbType        = DbType.Int32;
                param1.Value         = mes;
                command.Parameters.Add(param1);

                param1 = command.CreateParameter();
                param1.ParameterName = Constants.FilterTwoParam;
                param1.DbType        = DbType.Int32;
                param1.Value         = anno;

                command.Parameters.Add(param1);

                ClaveMes ent = null;

                try
                {
                    connection.Open();

                    using (IDataReader reader = command.ExecuteReader())
                    {
                        try
                        {
                            MapperBase <ClaveMes> mapper = GetMapper();
                            ent = mapper.MapEntity(reader);
                            return(ent);
                        }
                        catch
                        {
                            throw;
                        }
                        finally
                        {
                            reader.Close();
                        }
                    }
                }
                catch
                {
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }