Ejemplo n.º 1
0
    protected void ddlFarmaceutica_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            if (!string.IsNullOrEmpty(ddlFarmaceutica.SelectedItem.Value))
            {
                LogicaFarmaceutica logicaFarmaceutica = new LogicaFarmaceutica();
                Farmaceutica       farmaceutica       = logicaFarmaceutica.BuscarFarmaceutica(ddlFarmaceutica.SelectedItem.Value);

                LogicaMedicamento logicaMedicamento = new LogicaMedicamento();
                Session["ListaMedicamentos"] = logicaMedicamento.ListarMedicamentoPorFarmaceutica(farmaceutica);
                gvMedicamentos.DataSource    = (List <Medicamento>)Session["ListaMedicamentos"];
                gvMedicamentos.DataBind();

                //LIMPIAR GRIDVIEW PEDIDOS
                gvPedidos.DataSource = null;
                gvPedidos.DataBind();
            }
        }
        catch (Exception ex)
        {
            lblERROR.ForeColor = System.Drawing.Color.Red;
            lblERROR.Text      = ex.Message;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                ddl.DataSource     = negFarmaceutica.Listar();
                ddl.DataTextField  = "nombre";
                ddl.DataValueField = "ruc";
                ddl.DataBind();
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
            }
        }
        GridView1.Visible = false;
        ddlEstado.Visible = false;
        Farmaceutica f = negFarmaceutica.Buscar(Convert.ToInt64(ddl.SelectedValue));

        Session["farmaceutica"] = f;

        List <Medicamento> lm = negMedicamento.ListarPorFarmaceutica(f);

        grdMedicamentos.DataSource = lm;
        grdMedicamentos.DataBind();
    }
    protected void btnAlta_Click(object sender, EventArgs e)
    {
        try
        {
            Int64 oRUC = Convert.ToInt64(txtRucMedicamento.Text.Trim());

            Farmaceutica oFar         = LogicaFarmaceutica.Buscar(oRUC);
            int          oCodigo      = Convert.ToInt32(txtCodMedicamento.Text.Trim());
            string       oNombre      = txtNombreMed.Text.Trim();
            string       oDescripcion = txtDescripcion.Text.Trim();
            int          oPrecio      = Convert.ToInt32(txtPrecio.Text.Trim());

            Medicamento oMed = new Medicamento(oFar, oCodigo, oNombre, oDescripcion, oPrecio);

            btnAlta.Enabled   = false;
            btnBuscar.Enabled = false;

            LogicaMedicamento.Alta(oMed);

            lblError.Text = "Alta exitosa";
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
        }
    }
Ejemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    ddlFarmaceuticas.DataSource     = LogicaFarmaceutica.Listar();
                    ddlFarmaceuticas.DataTextField  = "Nombre";
                    ddlFarmaceuticas.DataValueField = "Ruc";
                    ddlFarmaceuticas.AutoPostBack   = true;
                    ddlFarmaceuticas.DataBind();

                    Farmaceutica       f     = LogicaFarmaceutica.Buscar(Convert.ToInt32(ddlFarmaceuticas.SelectedValue));
                    List <Medicamento> lista = LogicaMedicamento.Listar(f);
                    Session["listamed"]       = lista;
                    gvMedicamentos.DataSource = lista;
                    gvMedicamentos.DataBind();
                }

                catch (Exception ex)
                {
                    lblError.Text = ex.Message;
                }
            }
        }
    protected void btnBuscar_Click(object sender, EventArgs e)
    {
        lblError.Text = string.Empty;
        try
        {
            if (txtRuc.Text.Length != 12)
            {
                throw new Exception("Ingrese un Rut valido");
            }
            Farmaceutica f = negFarmaceutica.Buscar(Convert.ToInt64(txtRuc.Text));

            Medicamento m = negMedicamento.Buscar(f, Convert.ToInt32(txtCodigo.Text));

            if (m == null)
            {
                NoEncontrado();
            }
            else
            {
                txtNombre.Text      = m.Nombre;
                txtDescripcion.Text = m.Descripcion;
                txtPrecio.Text      = m.Precio.ToString();
                Encontrado();

                Session["medicamento"] = m;
            }
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
        }
    }
Ejemplo n.º 6
0
        public Medicamento Buscar(Farmaceutica pFarmaceutica, int pCodigo)
        {
            SqlConnection c = Conexion.Conectar();

            SqlCommand cmd = new SqlCommand("BuscarMedicamento", c);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add(new SqlParameter("rut", pFarmaceutica.Ruc));
            cmd.Parameters.Add(new SqlParameter("codigo", pCodigo));

            SqlDataReader dr = cmd.ExecuteReader();

            Medicamento m = null;

            while (dr.Read())
            {
                m = new Medicamento(pFarmaceutica, Convert.ToInt32(dr["codigo"].ToString()), dr["nombre"].ToString(), dr["descipcion"].ToString(), Convert.ToDecimal(dr["precio"].ToString()));
            }

            dr.Close();
            Conexion.Desconectar(c);

            return(m);
        }
Ejemplo n.º 7
0
        public List <Medicamento> ListarPorFarmaceutica(Farmaceutica pFarmaceutica)
        {
            List <Medicamento> lista = new List <Medicamento>();

            SqlConnection c = Conexion.Conectar();

            SqlCommand cmd = new SqlCommand("MedicamentosxFarmaceutica", c);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add(new SqlParameter("rut", pFarmaceutica.Ruc));

            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                Medicamento m = new Medicamento(pFarmaceutica, Convert.ToInt32(dr["codigo"].ToString()), dr["nombre"].ToString(), dr["descipcion"].ToString(), Convert.ToDecimal(dr["precio"].ToString()));
                lista.Add(m);
            }

            dr.Close();
            Conexion.Desconectar(c);

            return(lista);
        }
Ejemplo n.º 8
0
    protected void btnBuscar_Click(object sender, EventArgs e)
    {
        lblError.Text = string.Empty;
        try
        {
            if (txtRuc.Text.Length != 12)
            {
                throw new Exception("ingrese un Rut valido");
            }
            Farmaceutica f = negFarmaceutica.Buscar(Convert.ToInt64(txtRuc.Text));

            if (f == null)
            {
                NoEncontrado();
            }
            else
            {
                txtNombre.Text    = f.Nombre;
                txtCorreo.Text    = f.Correo;
                txtDireccion.Text = f.Direccion;

                Encontrado();
                Session["farmaceutica"] = f;
            }
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
        }
    }
    protected void grdMedicamentos_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            GridView1.Visible       = true;
            ddlEstado.SelectedIndex = 0;
            lblError.Text           = string.Empty;
            Farmaceutica f = (Farmaceutica)Session["farmaceutica"];
            Medicamento  m = negMedicamento.Buscar(f, Convert.ToInt32(grdMedicamentos.SelectedRow.Cells[1].Text));

            Session["m"]         = m;
            GridView1.DataSource = negPedido.ListarPorMedicamento(m, "Todos");
            GridView1.DataBind();
            ddlEstado.Visible = true;
            if (negPedido.ListarPorMedicamento(m, "Todos").Count == 0)
            {
                ddlEstado.Visible = false;
                throw new Exception("No se encontraron pedidos de este medicamento");
            }
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
        }
    }
Ejemplo n.º 10
0
    protected void btnListar_Click(object sender, EventArgs e)
    {
        try
        {
            string Seleccion = ddlListadoMedicamento.SelectedValue;

            Farmaceutica oFar = LogicaFarmaceutica.BuscarXNombre(Seleccion);

            List <Medicamento> oLista = LogicaMedicamento.ListarMedicamentosXFarmaceutica(oFar);

            if (oLista != null)
            {
                gvListadoMedicamento.DataSource = oLista;
                gvListadoMedicamento.DataBind();
            }
            else
            {
                lblError.Text = oFar.nombre + " aun no tiene medicamentos asociados.";
            }
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
        }
    }
Ejemplo n.º 11
0
        public static Medicamento Buscar(Farmaceutica pFarmaceutica, int pCodigo)
        {
            perMedicamento pm = new perMedicamento();

            Medicamento m = pm.Buscar(pFarmaceutica, pCodigo);

            return(m);
        }
Ejemplo n.º 12
0
        public static Farmaceutica Buscar(long pRuc)
        {
            perFarmaceutica pf = new perFarmaceutica();

            Farmaceutica f = pf.Buscar(pRuc);

            return(f);
        }
Ejemplo n.º 13
0
 //LISTAR MEDICAMENTO POR FARMACEUTICA
 public List <Medicamento> ListarMedicamentoPorFarmaceutica(Farmaceutica farmaceutica)
 {
     try
     {
         PersistenciaMedicamento persistenciaMedicamento = new PersistenciaMedicamento();
         return(persistenciaMedicamento.ListarMedicamentoPorFarmaceutica(farmaceutica));
     }
     catch { throw; }
 }
        public static Farmaceutica BuscarXNombre(string Nombre)
        {
            string correo, calle, nombre;
            int    numero, apto;
            Int64  ruc;

            Farmaceutica  oFar = null;
            SqlDataReader oReader;

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

            oComando.CommandType = CommandType.StoredProcedure;

            oComando.Parameters.AddWithValue("@nombre", Nombre);

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

                if (oReader.HasRows)
                {
                    if (oReader.Read())
                    {
                        nombre = (string)oReader["nombre"];
                        ruc    = (Int64)oReader["ruc"];
                        correo = (string)oReader["correo"];
                        calle  = (string)oReader["calle"];
                        numero = (int)oReader["numero"];

                        if (oReader["apto"] != DBNull.Value)
                        {
                            apto = (int)oReader["apto"];
                        }
                        else
                        {
                            apto = 1;
                        }

                        oFar = new Farmaceutica(ruc, nombre, correo, calle, numero, apto);
                    }
                }
                oReader.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                oConexion.Close();
            }

            return(oFar);
        }
Ejemplo n.º 15
0
 //MODIFICAR FARMACEUTICA
 public void ModificarFarmaceutica(Farmaceutica farmaceutica)
 {
     try
     {
         PersistenciaFarmaceutica persistenciaFarmaceutica = new PersistenciaFarmaceutica();
         persistenciaFarmaceutica.ModificarFarmaceutica(farmaceutica);
     }
     catch (Exception ex)
     { throw ex; }
 }
Ejemplo n.º 16
0
        protected void btnEliminar_Click(object sender, EventArgs e)
        {
            try
            {
                Farmaceutica farma = (Farmaceutica)Session["farmaceutica"];

                LogicaFarmaceutica.Eliminar(farma);
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
            }
        }
        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);
        }
Ejemplo n.º 18
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(); }
        }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
0
        //MODIFICAR FARMACEUTICA
        public void ModificarFarmaceutica(Farmaceutica farmaceutica)
        {
            //GET CONNECTION STRING
            SqlConnection connection = new SqlConnection(Conexion.ConnectionString);

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

            sp.CommandType = CommandType.StoredProcedure;

            //PARAMETROS
            sp.Parameters.AddWithValue("@RUC", farmaceutica.pRUC);
            sp.Parameters.AddWithValue("@Nombre", farmaceutica.pNombre);
            sp.Parameters.AddWithValue("@CorreoElectronico", farmaceutica.pCorreoElectronico);
            sp.Parameters.AddWithValue("@Direccion", farmaceutica.pDireccion);

            //RETORNO
            SqlParameter retorno = new SqlParameter("@retorno", SqlDbType.Int);

            retorno.Direction = ParameterDirection.ReturnValue;
            sp.Parameters.Add(retorno);

            try
            {
                connection.Open();

                //MODIFICAR FARMACEUTICA
                sp.ExecuteNonQuery();

                //RETORNO
                switch ((int)retorno.Value)
                {
                case 1:
                    //EXITO
                    break;

                //FARMACEUTICA NO EXISTE
                case -1:
                    throw new Exception("El RUC no existe.");

                //EXCEPCION NO CONTROLADA
                default:
                    throw new Exception("Ha ocurrido un error vuelva a intentarlo mas tarde.");
                }
            }
            catch { throw; }

            finally { connection.Close(); }
        }
Ejemplo n.º 21
0
 protected void ddlFarmaceuticas_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         Farmaceutica       f     = LogicaFarmaceutica.Buscar(Convert.ToInt32(ddlFarmaceuticas.SelectedValue));
         List <Medicamento> lista = LogicaMedicamento.Listar(f);
         Session["listamed"]       = lista;
         gvMedicamentos.DataSource = lista;
         gvMedicamentos.DataBind();
     }
     catch (Exception ex)
     {
         lblError.Text = ex.Message;
     }
 }
        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);
        }
Ejemplo n.º 23
0
        protected void btnModificar_Click(object sender, EventArgs e)
        {
            try
            {
                Farmaceutica farma = (Farmaceutica)Session["farmaceutica"];
                farma.Nombre    = txtNombre.Text.Trim();
                farma.Correo    = txtCorreo.Text.Trim();
                farma.Direccion = txtDireccion.Text.Trim();

                LogicaFarmaceutica.Modificar(farma);
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
            }
        }
Ejemplo n.º 24
0
    protected void btnTodos_Click(object sender, EventArgs e)
    {
        try
        {
            string Seleccion = ddlListadoMedicamento.SelectedValue;

            Farmaceutica oFar = LogicaFarmaceutica.BuscarXNombre(Seleccion);

            gvListadoMedicamento.DataSource = LogicaMedicamento.ListarMedicamentosXFarmaceutica(oFar);
            gvListadoMedicamento.DataBind();
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
        }
    }
Ejemplo n.º 25
0
        //BUSCAR FARMACEUTICA
        public Farmaceutica BuscarFarmaceutica(string RUC)
        {
            //GET CONNECTION STRING
            SqlConnection connection = new SqlConnection(Conexion.ConnectionString);

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

            sp.CommandType = CommandType.StoredProcedure;

            //PARAMETROS
            sp.Parameters.AddWithValue("@RUC", RUC);

            //READER
            SqlDataReader reader;

            //PREPARAR VARIABLES
            Farmaceutica farmaceutica;
            string       Nombre;
            string       CorreoElectronico;
            string       Direccion;

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

                if (reader.Read())
                {
                    Nombre            = (string)reader["Nombre"];
                    CorreoElectronico = (string)reader["CorreoElectronico"];
                    Direccion         = (string)reader["Direccion"];

                    farmaceutica = new Farmaceutica(RUC, Nombre, CorreoElectronico, Direccion);
                    reader.Close();
                }
                else
                {
                    return(null);
                }

                return(farmaceutica);
            }
            catch { throw; }

            finally { connection.Close(); }
        }
Ejemplo n.º 26
0
    protected void btnEliminar_Click(object sender, EventArgs e)
    {
        lblError.Text = string.Empty;
        try
        {
            Farmaceutica f = (Farmaceutica)Session["farmaceutica"];

            negFarmaceutica.Baja(f);
            Limpiar();
            lblError.Text = "Farmacéutica eliminada con éxito";
        }

        catch (Exception ex)
        {
            lblError.Text = ex.Message;
        }
    }
Ejemplo n.º 27
0
        //LISTAR FARMACEUTICAS
        public List <Farmaceutica> ListarFarmaceuticas()
        {
            //GET CONNECTION STRING
            SqlConnection connection = new SqlConnection(Conexion.ConnectionString);

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

            Command.CommandType = CommandType.StoredProcedure;

            //READER
            SqlDataReader Reader;

            //PREPARAR VARIABLES
            string              RUC;
            string              Nombre;
            string              CorreoElectronico;
            string              Direccion;
            Farmaceutica        farmaceutica = null;
            List <Farmaceutica> List         = new List <Farmaceutica>();

            try
            {
                connection.Open();
                Reader = Command.ExecuteReader();
                while (Reader.Read())
                {
                    RUC               = (string)Reader["RUC"];
                    Nombre            = (string)Reader["Nombre"];
                    CorreoElectronico = (string)Reader["CorreoElectronico"];
                    Direccion         = (string)Reader["Direccion"];
                    farmaceutica      = new Farmaceutica(RUC, Nombre, CorreoElectronico, Direccion);
                    List.Add(farmaceutica);
                }
                Reader.Close();
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Error en la base de datos: " + ex.Message);
            }
            finally
            {
                connection.Close();
            }
            return(List);
        }
Ejemplo n.º 28
0
    protected void btnEliminar_Click(object sender, EventArgs e)
    {
        try
        {
            Farmaceutica oFar = (Farmaceutica)Session["FarmaceuticaABM"];

            Logica.LogicaFarmaceutica.Eliminar(oFar);

            this.LimpioFormulario();

            lblError.Text = "Eliminacion exitosa";
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
        }
    }
Ejemplo n.º 29
0
    protected void btnModificar_Click(object sender, EventArgs e)
    {
        try
        {
            LogicaFarmaceutica logicaFarmaceutica = new LogicaFarmaceutica();
            LogicaMedicamento  logicaMedicamento  = new LogicaMedicamento();

            Farmaceutica farmaceutica = logicaFarmaceutica.BuscarFarmaceutica(ddlFarmaceuticas.SelectedItem.Value);

            if (farmaceutica == null)
            {
                throw new Exception("La farmaceutica no existe.");
            }

            string descripcion = txtDescripcion.Text;
            double precio;
            string nombre = txtNombre.Text;
            int    codigo;

            //VARIFICAR INT
            try
            {
                codigo = Convert.ToInt32(txtCodigo.Text);
            }
            catch { throw new Exception("El codigo debe ser un numero."); }

            //VERIFICAR DOUBLE
            try
            {
                precio = double.Parse(txtPrecio.Text);
            }
            catch { throw new Exception("El precio debe ser un numero."); }

            Medicamento medicamento = new Medicamento(codigo, farmaceutica, nombre, descripcion, precio);

            logicaMedicamento.ModificarMedicamento(medicamento);

            lblERROR.ForeColor = System.Drawing.Color.Green;
            lblERROR.Text      = "Modificacion exitosa.";
        }
        catch (Exception ex)
        {
            lblERROR.ForeColor = System.Drawing.Color.Red;
            lblERROR.Text      = ex.Message;
        }
    }
Ejemplo n.º 30
0
        public void Baja(Farmaceutica f)
        {
            SqlConnection c = Conexion.Conectar();

            SqlCommand cmd = new SqlCommand("EliminarFarmaceutica", c);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add(new SqlParameter("rut", f.Ruc));

            SqlParameter r = new SqlParameter();

            r.Direction = ParameterDirection.ReturnValue;

            cmd.Parameters.Add(r);

            cmd.ExecuteNonQuery();

            Conexion.Desconectar(c);

            int a = Convert.ToInt32(r.Value.ToString());

            switch (a)
            {
            case -1:
            {
                throw new Exception("No existe la farmacéutica.");
            }

            case -2:
            {
                throw new Exception("No es posible eliminar ya que tiene pedidos asociados.");
            }

            case 1:
            {
                break;
            }

            default:
            {
                throw new Exception("Error desconocido.");
            }
            }
        }