示例#1
0
    public String EliminarAcuse(ObjetoAcuse Datos)
    {
        String         Error       = "";
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            //Primero checo que exista
            Boolean       Existe  = false;
            String        Query   = "SELECT Id_Factura FROM Acuses WHERE Id_Factura = '" + Datos.IdFactura + "' AND Numero = '" + Datos.NumeroString + "';";
            SqlCommand    Comando = new SqlCommand(Query, conn, Transaccion);
            SqlDataReader Lector  = Comando.ExecuteReader();
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    Existe = true;
                }
            }
            Lector.Close();

            if (Existe)
            {
                Query   = "UPDATE Acuses SET Activo = 0, Usuario_Elimina = '" + Datos.IdUsuario + "' WHERE Id_Factura = '" + Datos.IdFactura + "' AND Numero = '" + Datos.NumeroString + "';";
                Comando = new SqlCommand(Query, conn, Transaccion);
                Comando.ExecuteNonQuery();

                //Modificamos numeros
                Query   = "UPDATE Acuses SET Numero = '1' WHERE Id_Factura = '" + Datos.IdFactura + "' AND Activo = '1';";
                Comando = new SqlCommand(Query, conn, Transaccion);
                Comando.ExecuteNonQuery();
            }
            else
            {
                Error = "No Existe el acuse a eliminar";
            }


            Transaccion.Commit();
            conn.Close();
        }
        catch (Exception ex)
        {
            try
            {
                Transaccion.Rollback();
                conn.Close();
            }
            catch
            {
            }
            Error = ex.Message;
        }
        return(Error);
    }
示例#2
0
    public List <ObjetoAcuse> ListarAcuses(int IdFactura)
    {
        List <ObjetoAcuse> Lista = new List <ObjetoAcuse>();

        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            int           Numero  = 1;
            String        Query   = "SELECT Archivo, Numero FROM Acuses WHERE Id_Factura = '" + IdFactura + "' AND Activo = '1';";
            SqlCommand    Comando = new SqlCommand(Query, conn, Transaccion);
            SqlDataReader Lector  = Comando.ExecuteReader();
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    ObjetoAcuse ObjAcu = new ObjetoAcuse();
                    ObjAcu.Archivo = Lector.GetString(0);
                    ObjAcu.Numero  = Lector.GetInt32(1);
                    Lista.Add(ObjAcu);
                }
            }
            Lector.Close();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            try
            {
                Transaccion.Rollback();
                conn.Close();
            }
            catch
            {
                Lista = null;
            }
            Lista = null;
        }

        return(Lista);
    }
示例#3
0
    public Boolean SubirAcuse(ObjetoAcuse Datos)
    {
        Boolean        Correcto    = true;
        SqlConnection  conn        = new SqlConnection(Conexiones.CONEXION);
        SqlTransaction Transaccion = null;

        try
        {
            conn.Open();
            Transaccion = conn.BeginTransaction();

            int           Numero  = 1;
            String        Query   = "SELECT COALESCE(MAX(Numero), 0) + 1 FROM Acuses WHERE Id_factura = '" + Datos.IdFactura + "' AND Activo = 1;";
            SqlCommand    Comando = new SqlCommand(Query, conn, Transaccion);
            SqlDataReader Lector  = Comando.ExecuteReader();
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    Numero = Lector.GetInt32(0);
                }
            }
            Lector.Close();

            Query   = "INSERT INTO Acuses(Id_Factura, Archivo, Usuario_Sube, Numero) VALUES('" + Datos.IdFactura + "', '" + Datos.Archivo + "', '" + Datos.IdUsuario + "', '" + Numero + "');";
            Comando = new SqlCommand(Query, conn, Transaccion);
            Comando.ExecuteNonQuery();

            Transaccion.Commit();
            conn.Close();
        }
        catch
        {
            try
            {
                Transaccion.Rollback();
                conn.Close();
            }
            catch
            {
                Correcto = false;
            }
            Correcto = false;
        }
        return(Correcto);
    }