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);
        }
        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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }