public static Medicamento Buscar(Int64 oRUC, int oCodigo)
        {
            Int64  ruc;
            int    codigo, precio;
            string nombre, descripcion;

            Medicamento   oMed = null;
            SqlDataReader oReader;

            SqlConnection oConexion = new SqlConnection(Conexion.STR);
            SqlCommand    oComando  = new SqlCommand("BuscarMedicamento", oConexion);

            oComando.CommandType = CommandType.StoredProcedure;

            oComando.Parameters.AddWithValue("@far", oRUC);
            oComando.Parameters.AddWithValue("@codigo", oCodigo);

            try
            {
                oConexion.Open();
                oReader = oComando.ExecuteReader();

                if (oReader.HasRows)
                {
                    if (oReader.Read())
                    {
                        ruc         = (Int64)oReader["ruc"];
                        codigo      = (int)oReader["codigo"];
                        precio      = (int)oReader["precio"];
                        nombre      = (string)oReader["nombre"];
                        descripcion = (string)oReader["descripcion"];

                        Farmaceutica oFar = PersistenciaFarmaceutica.Buscar(oRUC);

                        oMed = new Medicamento(oFar, codigo, nombre, descripcion, precio);
                    }
                }
                oReader.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                oConexion.Close();
            }

            return(oMed);
        }
Beispiel #2
0
        //BUSCAR MEDICAMENTO
        public Medicamento BuscarMedicamento(int Codigo, string RucFarmaceutica)
        {
            //GET CONNECTION STRING
            SqlConnection connection = new SqlConnection(Conexion.ConnectionString);

            //STORED PROCEDURE
            SqlCommand sp = new SqlCommand("BuscarMedicamento", connection);

            sp.CommandType = CommandType.StoredProcedure;

            //PARAMETROS
            sp.Parameters.AddWithValue("@Codigo", Codigo);
            sp.Parameters.AddWithValue("@Farmaceutica", RucFarmaceutica);

            //READER
            SqlDataReader reader;

            try
            {
                //PREPARAR VARIABLES
                PersistenciaFarmaceutica persistenciaFarmaceutica = new PersistenciaFarmaceutica();
                Medicamento  medicamento;
                string       Nombre;
                double       Precio;
                string       Descripcion;
                Farmaceutica farmaceutica = persistenciaFarmaceutica.BuscarFarmaceutica(RucFarmaceutica);

                connection.Open();
                reader = sp.ExecuteReader();

                if (reader.Read())
                {
                    Nombre      = (string)reader["Nombre"];
                    Precio      = (double)reader["Precio"];
                    Descripcion = (string)reader["Descripcion"];

                    medicamento = new Medicamento(Codigo, farmaceutica, Nombre, Descripcion, Precio);
                    reader.Close();
                }
                else
                {
                    return(null);
                }

                return(medicamento);
            }
            catch { throw; }

            finally { connection.Close(); }
        }
Beispiel #3
0
        //LISTAR MEDICAMENTO POR FARMACEUTICA
        public List <Medicamento> ListarMedicamentoPorFarmaceutica(Farmaceutica farmaceutica)
        {
            //GET CONNECTION STRING
            SqlConnection connection = new SqlConnection(Conexion.ConnectionString);

            //STORED PROCEDURE
            SqlCommand Command = new SqlCommand("ListarMedicamentoPorFarmaceutica", connection);

            Command.CommandType = CommandType.StoredProcedure;

            //PARAMETRO
            Command.Parameters.AddWithValue("@RUC", farmaceutica.pRUC);

            //READER
            SqlDataReader Reader;

            //PREPARAR VARIABLES
            int                      Codigo;
            string                   Descripcion;
            double                   Precio;
            string                   Nombre;
            Medicamento              medicamento = null;
            List <Medicamento>       List        = new List <Medicamento>();
            PersistenciaFarmaceutica persistenciaFarmaceutica = new PersistenciaFarmaceutica();

            try
            {
                connection.Open();
                Reader = Command.ExecuteReader();
                while (Reader.Read())
                {
                    Codigo      = (int)Reader["Codigo"];
                    Descripcion = (string)Reader["Descripcion"];
                    Precio      = (double)Reader["Precio"];
                    Nombre      = (string)Reader["Nombre"];
                    medicamento = new Medicamento(Codigo, farmaceutica, Nombre, Descripcion, Precio);
                    List.Add(medicamento);
                }
                Reader.Close();
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Error en la base de datos: " + ex.Message);
            }
            finally
            {
                connection.Close();
            }
            return(List);
        }
        public static List <Medicamento> ListarMedicamentoUnico(Medicamento Medi)
        {
            Medicamento        oMed;
            List <Medicamento> oLista = new List <Medicamento>();
            SqlDataReader      oReader;

            SqlConnection oConexion = new SqlConnection(Conexion.STR);
            SqlCommand    oComando  = new SqlCommand("ListarMedicamentoUnico", oConexion);

            oComando.CommandType = CommandType.StoredProcedure;

            oComando.Parameters.AddWithValue("@ruc", Medi.Far.ruc);
            oComando.Parameters.AddWithValue("@codigo", Medi.Codigo);

            try
            {
                oConexion.Open();
                oReader = oComando.ExecuteReader();

                if (oReader.HasRows)
                {
                    oReader.Read();

                    Int64  ruc         = (Int64)oReader["ruc"];
                    int    codigo      = (int)oReader["codigo"];
                    string nombre      = (string)oReader["nombre"];
                    string descripcion = (string)oReader["descripcion"];
                    int    precio      = (int)oReader["precio"];

                    Farmaceutica oFar = PersistenciaFarmaceutica.Buscar(ruc);

                    oMed = new Medicamento(oFar, codigo, nombre, descripcion, precio);

                    oLista.Add(oMed);
                }
                oReader.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                oConexion.Close();
            }

            return(oLista);
        }
        public static List <Medicamento> Listar()
        {
            Medicamento        oMed;
            List <Medicamento> oLista = new List <Medicamento>();
            SqlDataReader      oReader;

            SqlConnection oConexion = new SqlConnection(Conexion.STR);
            SqlCommand    oComando  = new SqlCommand("ListarMedicamento", oConexion);

            oComando.CommandType = CommandType.StoredProcedure;

            try
            {
                oConexion.Open();
                oReader = oComando.ExecuteReader();

                if (oReader.HasRows)
                {
                    while (oReader.Read())
                    {
                        Int64 ruc = (Int64)oReader["ruc"];

                        Farmaceutica oFar = PersistenciaFarmaceutica.Buscar(ruc);

                        oMed = new Medicamento(oFar, (int)oReader["codigo"], (string)oReader["nombre"], (string)oReader["descripcion"],
                                               (int)oReader["precio"]);

                        oLista.Add(oMed);
                    }
                }
                oReader.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                oConexion.Close();
            }

            return(oLista);
        }
        public static List <Farmaceutica> ListarFarmaceuticas()
        {
            Farmaceutica        oFar;
            Int64               ruc;
            List <Farmaceutica> oLista = new List <Farmaceutica>();
            SqlDataReader       oReader;

            SqlConnection oConexion = new SqlConnection(Conexion.STR);
            SqlCommand    oComando  = new SqlCommand("ListarFarmaceuticas", oConexion);

            oComando.CommandType = CommandType.StoredProcedure;

            try
            {
                oConexion.Open();
                oReader = oComando.ExecuteReader();

                if (oReader.HasRows)
                {
                    while (oReader.Read())
                    {
                        ruc = (Int64)oReader["ruc"];

                        oFar = PersistenciaFarmaceutica.Buscar(ruc);

                        oLista.Add(oFar);
                    }

                    oReader.Close();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                oConexion.Close();
            }

            return(oLista);
        }
Beispiel #7
0
        public static Medicamento Buscar(int codigo, int ruc)
        {
            Medicamento   m   = null;
            SqlConnection cn  = new SqlConnection(Conexion.str);
            SqlCommand    cmd = new SqlCommand("buscarmedicamento", cn);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("codigo", codigo);
            cmd.Parameters.AddWithValue("ruc", ruc);
            SqlDataReader reader;

            try
            {
                cn.Open();
                reader = cmd.ExecuteReader();

                if (reader.HasRows)
                {
                    reader.Read();
                    codigo = (int)reader["codigo"];
                    string nombre = (string)reader["nombre"];
                    string desc   = (string)reader["descripcion"];
                    ruc = (int)reader["ruc"];
                    double precio = (double)reader["precio"];

                    Farmaceutica farma = PersistenciaFarmaceutica.Buscar(ruc);
                    m = new Medicamento(codigo, farma, nombre, desc, precio);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cn.Close();
            }
            return(m);
        }
Beispiel #8
0
        public static List <Medicamento> Listar()
        {
            List <Medicamento> listMed = new List <Medicamento>();
            SqlConnection      cn      = new SqlConnection(Conexion.str);
            SqlCommand         cmd     = new SqlCommand("listamedicamentos", cn);

            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataReader reader;

            try
            {
                cn.Open();
                reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        int          codigo = (int)reader["codigo"];
                        int          ruc    = (int)reader["ruc"];
                        string       nombre = (string)reader["nombre"];
                        string       desc   = (string)reader["descripcion"];
                        double       precio = (double)reader["precio"];
                        Farmaceutica f      = PersistenciaFarmaceutica.Buscar(ruc);
                        Medicamento  m      = new Medicamento(codigo, f, nombre, desc, precio);
                        listMed.Add(m);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cn.Close();
            }
            return(listMed);
        }