/**
         * Busca los registros que coincidan con los datos enviados
         * @param DIAFESTIVO obj
         * @return Retorna la lista de los registros que coinciden
         */
        public DIAFESTIVO[] buscarDIAFESTIVO(DIAFESTIVO obj)
        {
            DIAFESTIVO[]      result = null;
            List <DIAFESTIVO> lista  = null;

            try
            {
                DIAFESTIVODao dao = new DIAFESTIVODao();
                conn  = conexion.conection();
                lista = dao.search(conn, obj);
                if (lista != null && lista.Count > 0)
                {
                    result = lista.ToArray();
                }
            }
            catch (Exception e)
            {
                result = null;
            } finally {
                if (conn != null && conn.State == System.Data.ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            return(result);
        }
示例#2
0
        private List <DIAFESTIVO> listQuery(SqlCommand stmt)
        {
            List <DIAFESTIVO> searchResults = new List <DIAFESTIVO>();
            SqlDataReader     reader        = null;

            try
            {
                int intt = 0; long longg = 0; double doublee = 0; float floatt = 0; DateTime datee; byte[] bytee;
                reader = stmt.ExecuteReader();
                while (reader.Read())
                {
                    DIAFESTIVO temp = createValueObject();

                    temp.ID          = reader["ID"] != null && int.TryParse(reader["ID"].ToString(), out intt) ? intt : 0;
                    temp.FECHA       = reader["FECHA"] != null && !String.IsNullOrEmpty(reader["FECHA"].ToString()) ? (DateTime)reader["FECHA"] : DateTime.MinValue;
                    temp.DESCRIPCION = reader["DESCRIPCION"] != null ? reader["DESCRIPCION"].ToString() : null;
                    searchResults.Add(temp);
                }
            }
            finally {
                if (!reader.IsClosed)
                {
                    reader.Close();
                }
                if (stmt != null)
                {
                    stmt.Dispose();
                }
            }
            return(searchResults);
        }
示例#3
0
        public void delete(SqlConnection conn, DIAFESTIVO valueObject)
        {
            SqlCommand stmt = null;
            String     sql  = "";

            try
            {
                sql  = "DELETE FROM DIAFESTIVO WHERE ( id = @id )";
                stmt = new SqlCommand(sql, conn);
                stmt.Parameters.AddWithValue("@id", valueObject.ID);
                int rowcount = databaseUpdate(stmt);
                if (rowcount == 0)
                {
                    throw new Exception("Object could not be deleted! (PrimaryKey not found)");
                }
                if (rowcount > 1)
                {
                    throw new Exception("PrimaryKey Error when updating DB! (Many objects were deleted!)");
                }
            } finally {
                if (stmt != null)
                {
                    stmt.Dispose();
                }
            }
        }
        /**
         * Inserta nuevo registro en la tabla
         * @param DIAFESTIVO obj
         * @return Retorna el mismo objeto pero con la llave primaria configurada
         */
        public DIAFESTIVO crearDIAFESTIVO(DIAFESTIVO obj)
        {
            List <DIAFESTIVO> lista = null;

            try
            {
                DIAFESTIVODao dao = new DIAFESTIVODao();
                conn = conexion.conection();
                dao.create(conn, obj);
                //verificar existencia
                lista = dao.search(conn, obj);
                if (lista != null && lista.Count > 0)
                {
                    obj = (DIAFESTIVO)lista[0];
                }
                else
                {
                    obj.ID = -1;
                }
            }
            catch (Exception e)
            {
                obj.ID = -1;
            } finally {
                if (conn != null && conn.State == System.Data.ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            return(obj);
        }
示例#5
0
        public void save(SqlConnection conn, DIAFESTIVO valueObject)
        {
            SqlCommand stmt = null;
            String     sql  = "";

            try
            {
                sql = "UPDATE DIAFESTIVO SET ID = @ID ," +
                      " FECHA = @FECHA , DESCRIPCION = @DESCRIPCION  WHERE (id = @id)";
                stmt = new SqlCommand(sql, conn);


                if (valueObject.FECHA > DateTime.MinValue)
                {
                    stmt.Parameters.AddWithValue("@FECHA", valueObject.FECHA);
                }
                else
                {
                    stmt.Parameters.AddWithValue("@FECHA", DBNull.Value);
                }

                if (!String.IsNullOrEmpty(valueObject.DESCRIPCION) && valueObject.DESCRIPCION.Length <= 20)
                {
                    stmt.Parameters.AddWithValue("@DESCRIPCION", valueObject.DESCRIPCION);
                }
                else
                {
                    stmt.Parameters.AddWithValue("@DESCRIPCION", DBNull.Value);
                }

                stmt.Parameters.AddWithValue("@id", valueObject.ID);

                int rowcount = databaseUpdate(stmt);
                if (rowcount == 0)
                {
                    throw new Exception("Object could not be saved! (PrimaryKey not found)");
                }
            }
            finally
            {
                if (stmt != null)
                {
                    stmt.Dispose();
                }
            }
        }
示例#6
0
        public List <DIAFESTIVO> search(SqlConnection conn, DIAFESTIVO valueObject)
        {
            List <DIAFESTIVO> searchResults = new List <DIAFESTIVO>();
            bool   first = true;
            String sql   = "SELECT * FROM DIAFESTIVO WHERE 1=1 ";

            if (!String.IsNullOrEmpty(valueObject.ID.ToString()))
            {
                if (first)
                {
                    first = false;
                }
                sql += "AND ID= '" + valueObject.ID + "' ";
            }

            if (valueObject.FECHA > DateTime.MinValue)
            {
                if (first)
                {
                    first = false;
                }
                sql += "AND FECHA= '" + valueObject.FECHA.ToString("dd/MM/yyyy HH:mm:ss") + "' ";
            }

            if (!String.IsNullOrEmpty(valueObject.DESCRIPCION.ToString()))
            {
                if (first)
                {
                    first = false;
                }
                sql += "AND DESCRIPCION= '" + valueObject.DESCRIPCION + "' ";
            }

            sql += "ORDER BY id ASC ";

            if (first)
            {
                searchResults = new List <DIAFESTIVO>();
            }
            else
            {
                searchResults = listQuery(new SqlCommand(sql, conn));
            }

            return(searchResults);
        }
示例#7
0
        public void create(SqlConnection conn, DIAFESTIVO valueObject)
        {
            String     sql  = "";
            SqlCommand stmt = null;

            try
            {
                sql = "INSERT INTO DIAFESTIVO ( ID," +
                      " FECHA, DESCRIPCION)" +
                      "VALUES (@ID,@FECHA,@DESCRIPCION)";

                stmt = new SqlCommand(sql, conn);


                if (valueObject.FECHA > DateTime.MinValue)
                {
                    stmt.Parameters.AddWithValue("@FECHA", valueObject.FECHA);
                }
                else
                {
                    stmt.Parameters.AddWithValue("@FECHA", DBNull.Value);
                }

                if (!String.IsNullOrEmpty(valueObject.DESCRIPCION) && valueObject.DESCRIPCION.Length <= 20)
                {
                    stmt.Parameters.AddWithValue("@DESCRIPCION", valueObject.DESCRIPCION);
                }
                else
                {
                    stmt.Parameters.AddWithValue("@DESCRIPCION", DBNull.Value);
                }

                databaseUpdate(stmt);
            } finally {
                if (stmt != null)
                {
                    stmt.Dispose();
                }
            }
        }
        /**
         * Edita un registro en la tabla
         * @param DIAFESTIVO obj
         * @return boolean indicando si se realizo o no la actualizacion
         */
        public bool editarDIAFESTIVO(DIAFESTIVO obj)
        {
            bool resultado;

            resultado = false;
            try
            {
                DIAFESTIVODao dao = new DIAFESTIVODao();
                conn = conexion.conection();
                dao.save(conn, obj);
                resultado = true;
            }
            catch (Exception e)
            {
                resultado = false;
            } finally {
                if (conn != null && conn.State == System.Data.ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            return(resultado);
        }
 public bool eliminarDIAFESTIVO(DIAFESTIVO obj)
 {
     return(gestionDIAFESTIVO.eliminarDIAFESTIVO(obj));
 }
 public DIAFESTIVO[] buscarDIAFESTIVO(DIAFESTIVO obj)
 {
     return(gestionDIAFESTIVO.buscarDIAFESTIVO(obj));
 }
 public DIAFESTIVO buscarPrimeroDIAFESTIVO(DIAFESTIVO obj)
 {
     return(gestionDIAFESTIVO.buscarPrimeroDIAFESTIVO(obj));
 }
 public bool editarDIAFESTIVO(DIAFESTIVO obj)
 {
     return(gestionDIAFESTIVO.editarDIAFESTIVO(obj));
 }
 public DIAFESTIVO crearDIAFESTIVO(DIAFESTIVO obj)
 {
     return(gestionDIAFESTIVO.crearDIAFESTIVO(obj));
 }