Beispiel #1
0
        MedicamentoCLS IMedicamentos.RecuperarMedicamento(int iidMedicamento)
        {
            //throw new NotImplementedException();
            MedicamentoCLS oMedicamentoCLS = new MedicamentoCLS();

            try
            {
                using (var bd = new MedicoEntities())
                {
                    Medicamento oMedicamento = bd.Medicamento.Where(p => p.IIDMEDICAMENTO == iidMedicamento).First();
                    oMedicamentoCLS.IidMedicamento       = oMedicamento.IIDMEDICAMENTO;
                    oMedicamentoCLS.IidFormaFarmaceutica = (int)oMedicamento.IIDFORMAFARMACEUTICA;
                    oMedicamentoCLS.Nombre        = oMedicamento.NOMBRE;
                    oMedicamentoCLS.Precio        = (decimal)oMedicamento.PRECIO;
                    oMedicamentoCLS.Stock         = (int)oMedicamento.STOCK;
                    oMedicamentoCLS.Concentracion = oMedicamento.CONCENTRACION;
                    oMedicamentoCLS.Presentacion  = oMedicamento.PRESENTACION;
                }
            }
            catch (Exception)
            {
                oMedicamentoCLS = null;
            }
            return(oMedicamentoCLS);
        }
        public IActionResult Editar(int id)
        {
            MedicamentoCLS oMedicamentoCLS = new MedicamentoCLS();

            try
            {
                using (BDHospitalContext db = new BDHospitalContext())
                {
                    oMedicamentoCLS = (from m in db.Medicamento
                                       where m.Iidmedicamento == id
                                       select new MedicamentoCLS
                    {
                        IdMedicamento = m.Iidmedicamento,
                        Nombre = m.Nombre,
                        Concentracion = m.Concentracion,
                        IdFormaFarmaceutica = m.Iidformafarmaceutica,
                        Precio = m.Precio,
                        Stock = m.Stock,
                        Presentacion = m.Presentacion
                    }).First();
                }
            }
            catch (Exception e)
            {
                Error = e.Message;
            }
            //Siempre para pasar un ComboBox a la vista se hace un ViewBag
            ViewBag.ListaFormaFarmaceutica = ListarFormaFarmaceutica();
            return(View(oMedicamentoCLS));
        }
        public IActionResult Agregar(MedicamentoCLS medicamentoCLS)
        {
            string NombreVista = "";

            try
            {
                using (BDHospitalContext db = new BDHospitalContext())
                {
                    if (medicamentoCLS.IdMedicamento == 0)
                    {
                        NombreVista = "Agregar";
                    }
                    else
                    {
                        NombreVista = "Editar";
                    }

                    if (!ModelState.IsValid)
                    {
                        //Siempre para pasar un ComboBox a la vista se hace un ViewBag
                        ViewBag.ListaFormaFarmaceutica = ListarFormaFarmaceutica();
                        return(View(NombreVista, medicamentoCLS));
                    }
                    else
                    {
                        if (medicamentoCLS.IdMedicamento == 0)
                        {
                            Medicamento m = new Medicamento();
                            m.Nombre               = medicamentoCLS.Nombre;
                            m.Concentracion        = medicamentoCLS.Concentracion;
                            m.Iidformafarmaceutica = medicamentoCLS.IdFormaFarmaceutica;
                            m.Precio               = medicamentoCLS.Precio;
                            m.Stock        = medicamentoCLS.Stock;
                            m.Presentacion = medicamentoCLS.Presentacion;
                            m.Bhabilitado  = 1;
                            db.Medicamento.Add(m);
                            db.SaveChanges();
                        }
                        else
                        {
                            Medicamento m = db.Medicamento
                                            .Where(x => x.Iidmedicamento == medicamentoCLS.IdMedicamento).First();
                            m.Nombre               = medicamentoCLS.Nombre;
                            m.Concentracion        = medicamentoCLS.Concentracion;
                            m.Iidformafarmaceutica = medicamentoCLS.IdFormaFarmaceutica;
                            m.Precio               = medicamentoCLS.Precio;
                            m.Stock        = medicamentoCLS.Stock;
                            m.Presentacion = medicamentoCLS.Presentacion;
                            db.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception)
            {
                return(View(NombreVista, medicamentoCLS));
            }
            return(RedirectToAction("Index"));
        }
Beispiel #4
0
        int IMedicamentos.RegistraryActualizarMedicamento(MedicamentoCLS oMedicamentoCLS)
        {
            //throw new NotImplementedException();
            int rpta = 0;

            try
            {
                using (var bd = new MedicoEntities())
                {
                    if (oMedicamentoCLS.IidMedicamento == 0)
                    {
                        Medicamento oMedicamento = new Medicamento();
                        oMedicamento.IIDMEDICAMENTO = oMedicamentoCLS.IidMedicamento;

                        oMedicamento.NOMBRE = oMedicamentoCLS.Nombre;
                        oMedicamento.PRECIO = oMedicamentoCLS.Precio;
                        oMedicamento.STOCK  = oMedicamentoCLS.Stock;
                        oMedicamento.IIDFORMAFARMACEUTICA = oMedicamentoCLS.IidFormaFarmaceutica;
                        oMedicamento.CONCENTRACION        = oMedicamentoCLS.Concentracion;
                        oMedicamento.PRESENTACION         = oMedicamentoCLS.Presentacion;
                        oMedicamento.BHABILITADO          = 1;

                        bd.Medicamento.Add(oMedicamento);
                        bd.SaveChanges();
                        rpta = 1;
                    }
                    else
                    {
                        Medicamento oMedicamento = bd.Medicamento.Where(p => p.IIDMEDICAMENTO == oMedicamentoCLS.IidMedicamento).First();


                        oMedicamento.NOMBRE = oMedicamentoCLS.Nombre;
                        oMedicamento.PRECIO = oMedicamentoCLS.Precio;
                        oMedicamento.STOCK  = oMedicamentoCLS.Stock;
                        oMedicamento.IIDFORMAFARMACEUTICA = oMedicamentoCLS.IidFormaFarmaceutica;
                        oMedicamento.CONCENTRACION        = oMedicamentoCLS.Concentracion;
                        oMedicamento.PRESENTACION         = oMedicamentoCLS.Presentacion;
                        bd.SaveChanges();
                        rpta = 1;
                    }
                }
            }
            catch (Exception ex)
            {
                rpta = 0;
            }

            return(rpta);
        }
        public IActionResult Index(MedicamentoCLS medicamentoCLS)
        {
            ViewBag.ListaForma = ListarFormaFarmaceutica();
            List <MedicamentoCLS> listaMedicamento = new List <MedicamentoCLS>();

            try
            {
                using (BDHospitalContext db = new BDHospitalContext())
                {
                    if (medicamentoCLS.IdFormaFarmaceutica == null ||
                        medicamentoCLS.IdFormaFarmaceutica == 0)//Validacion ? en propiedades de tipo int y decimal
                    {
                        listaMedicamento = (from m in db.Medicamento
                                            join ff in db.FormaFarmaceutica
                                            on m.Iidformafarmaceutica equals ff.Iidformafarmaceutica
                                            where m.Bhabilitado == 1
                                            select new MedicamentoCLS
                        {
                            IdMedicamento = m.Iidmedicamento,
                            Nombre = m.Nombre,
                            Precio = (decimal)m.Precio,
                            Stock = (int)m.Stock,
                            NombreFormaFarmaceutica = ff.Nombre
                        }).ToList();
                    }
                    else
                    {
                        listaMedicamento = (from m in db.Medicamento
                                            join ff in db.FormaFarmaceutica
                                            on m.Iidformafarmaceutica equals ff.Iidformafarmaceutica
                                            where m.Bhabilitado == 1 &&
                                            m.Iidformafarmaceutica == medicamentoCLS.IdFormaFarmaceutica
                                            select new MedicamentoCLS
                        {
                            IdMedicamento = m.Iidmedicamento,
                            Nombre = m.Nombre,
                            Precio = (decimal)m.Precio,
                            Stock = (int)m.Stock,
                            NombreFormaFarmaceutica = ff.Nombre
                        }).ToList();
                    }
                }
            }
            catch (Exception e)
            {
                Error = e.Message;
            }
            return(View(listaMedicamento));
        }
        public IActionResult Index(MedicamentoCLS oMedicamentoCLS)
        {
            //llamada del metodo para que aparesca desde el inicio
            ViewBag.listaForma = listarFormaFarmaceutica();

            List <MedicamentoCLS> listaMedicamento = new List <MedicamentoCLS>();

            using (BDHospitalContext bd = new BDHospitalContext())
            {
                if (oMedicamentoCLS.iidFormaFarmaceutica == null || oMedicamentoCLS.iidFormaFarmaceutica == 0)
                {
                    listaMedicamento = (from medicamento in bd.Medicamento
                                        join formaFarmaceutica in bd.FormaFarmaceutica
                                        on medicamento.Iidformafarmaceutica equals
                                        formaFarmaceutica.Iidformafarmaceutica
                                        where medicamento.Bhabilitado == 1
                                        select new MedicamentoCLS
                    {
                        iidMedicamento = medicamento.Iidmedicamento,
                        nombre = medicamento.Nombre,
                        precio = (decimal)medicamento.Precio,
                        stock = (int)medicamento.Stock,
                        nombreFormaFarmaceutica = formaFarmaceutica.Nombre
                    }).ToList();
                }
                else
                {
                    listaMedicamento = (from medicamento in bd.Medicamento
                                        join formaFarmaceutica in bd.FormaFarmaceutica
                                        on medicamento.Iidformafarmaceutica equals
                                        formaFarmaceutica.Iidformafarmaceutica
                                        where medicamento.Bhabilitado == 1
                                        &&
                                        medicamento.Iidformafarmaceutica == oMedicamentoCLS.iidFormaFarmaceutica
                                        select new MedicamentoCLS
                    {
                        iidMedicamento = medicamento.Iidmedicamento,
                        nombre = medicamento.Nombre,
                        precio = (decimal)medicamento.Precio,
                        stock = (int)medicamento.Stock,
                        nombreFormaFarmaceutica = formaFarmaceutica.Nombre
                    }).ToList();
                }
            }
            lista = listaMedicamento;
            return(View(listaMedicamento));
        }
        public int AgregarYEditarMedicamento(MedicamentoCLS oMedicamentoCLS)
        {
            int rpta = 0;

            try
            {
                MedicamentosClient oMedicamentoClient = new MedicamentosClient();
                oMedicamentoClient.ClientCredentials.UserName.UserName = "******";
                oMedicamentoClient.ClientCredentials.UserName.Password = "******";
                rpta = oMedicamentoClient.RegistraryActualizarMedicamento(oMedicamentoCLS);
            }
            catch (Exception)
            {
                rpta = 0;
            }
            return(rpta);
        }
Beispiel #8
0
        ////////Extraido de proyecto ASP.NET MVC////////


        public async Task <int> AgregarYEditarMedicamento([FromBody] MedicamentoCLS oMedicamentoCLS)
        {
            int rpta = 0;

            try
            {
                MedicamentosClient oMedicamentoClient = new MedicamentosClient();
                // oMedicamentoClient.ClientCredentials.UserName.UserName = "******";
                // oMedicamentoClient.ClientCredentials.UserName.Password = "******";
                rpta = await oMedicamentoClient.RegistraryActualizarMedicamentoAsync(oMedicamentoCLS);
            }
            catch (Exception)
            {
                rpta = 0;
            }
            return(rpta);
        }
        public IActionResult Index(MedicamentoCLS medicamento)
        {
            ViewBag.listaForma = listaForma();
            List <MedicamentoCLS> medicamentoCLs = new List <MedicamentoCLS>();

            using (BDHospitalContext db = new BDHospitalContext())
            {
                if (medicamento.idformafarmaceutica == 0)
                {
                    medicamentoCLs = (from medi in db.Medicamento
                                      join forma in db.FormaFarmaceutica
                                      on medi.Iidformafarmaceutica equals forma.Iidformafarmaceutica
                                      where medi.Bhabilitado == 1
                                      select new MedicamentoCLS
                    {
                        idmedicamento = medi.Iidmedicamento,
                        nombre = medi.Nombre,
                        precio = (decimal)medi.Precio,
                        stock = (int)medi.Stock,
                        nombreFormaFarmaceutica = forma.Nombre
                    }).ToList();
                }
                else
                {
                    medicamentoCLs = (from medi in db.Medicamento
                                      join forma in db.FormaFarmaceutica
                                      on medi.Iidformafarmaceutica equals forma.Iidformafarmaceutica
                                      where medi.Bhabilitado == 1 && forma.Iidformafarmaceutica == medicamento.idformafarmaceutica
                                      select new MedicamentoCLS
                    {
                        idmedicamento = medi.Iidmedicamento,
                        nombre = medi.Nombre,
                        precio = (decimal)medi.Precio,
                        stock = (int)medi.Stock,
                        nombreFormaFarmaceutica = forma.Nombre
                    }).ToList();
                }
            }
            return(View(medicamentoCLs));
        }
        private void FrmPopupMedicamento_Load(object sender, EventArgs e)
        {
            MedicamentosClient oMedicamentosClient = new MedicamentosClient();

            oMedicamentosClient.ClientCredentials.UserName.UserName = "******";
            oMedicamentosClient.ClientCredentials.UserName.Password = "******";
            List <FormaFarmaceuticaCLS> ListaForma = oMedicamentosClient.ListaFormaFarmaceutica();

            ListaForma.Insert(0, new FormaFarmaceuticaCLS {
                IidFormaFarmaceutica = 0, NombreFormaFarmaceutica = "--Seleccion"
            });

            cboformaFarmaceutica.DataSource    = ListaForma;
            cboformaFarmaceutica.DisplayMember = "NombreFormaFarmaceutica";
            cboformaFarmaceutica.ValueMember   = "IidFormaFarmaceutica";
            //Todo bien
            if (iidmedicamento == 0)
            {
                this.Text = "Agregrar Medicamento";
                //Pintamos la informacion
            }
            else
            {
                this.Text = "Editando Medicamento";
                MedicamentosClient oMedicamentosClientEditar = new MedicamentosClient();
                oMedicamentosClientEditar.ClientCredentials.UserName.UserName = "******";
                oMedicamentosClientEditar.ClientCredentials.UserName.Password = "******";

                MedicamentoCLS oMedicamento = oMedicamentosClientEditar.RecuperarMedicamento(iidmedicamento);
                txtIdMedicamento.Text = oMedicamento.IidMedicamento.ToString();
                txtnombre.Text        = oMedicamento.Nombre;
                txtPrecio.Text        = oMedicamento.Precio.ToString();
                txtStock.Text         = oMedicamento.Stock.ToString();
                txtPresentacion.Text  = oMedicamento.Presentacion;
                txtConcentracion.Text = oMedicamento.Concentracion;
                cboformaFarmaceutica.SelectedValue = oMedicamento.IidFormaFarmaceutica;
            }
        }
        MedicamentoCLS IService1.recuperarMedicamento(int idMedicamento)
        {
            MedicamentoCLS oMedicamentoCLS = new MedicamentoCLS();

            try
            {
                using (var bd = new MedicoEntities())
                {
                    Medicamento medicamento = bd.Medicamento.Where(p => p.IIDMEDICAMENTO == idMedicamento).First();
                    oMedicamentoCLS.idMedicamento = medicamento.IIDMEDICAMENTO;
                    oMedicamentoCLS.nombre        = medicamento.NOMBRE;
                    oMedicamentoCLS.precio        = (decimal)medicamento.PRECIO;
                    oMedicamentoCLS.stock         = (int)medicamento.STOCK;
                    oMedicamentoCLS.concentracion = medicamento.CONCENTRACION;
                    oMedicamentoCLS.presentacion  = medicamento.PRESENTACION;
                }
                return(oMedicamentoCLS);
            }
            catch (Exception)
            {
                return(oMedicamentoCLS);
            }
        }
        //recuperar la informacion
        public IActionResult Editar(int id)
        {
            MedicamentoCLS oMedicamentoCLS = new MedicamentoCLS();

            using (BDHospitalContext bd = new BDHospitalContext())
            {
                //regresa el objeto que tenga todos los datos que da el id
                oMedicamentoCLS = (from medicamento in bd.Medicamento
                                   where medicamento.Iidmedicamento == id
                                   select new MedicamentoCLS
                {
                    iidMedicamento = medicamento.Iidmedicamento,
                    nombre = medicamento.Nombre,
                    concentracion = medicamento.Concentracion,
                    iidFormaFarmaceutica = medicamento.Iidformafarmaceutica,
                    precio = medicamento.Precio,
                    stock = medicamento.Stock,
                    presentacion = medicamento.Presentacion
                }).First();
            }
            ViewBag.listaFormaFarmaceutica = listarFormaFarmaceutica();
            return(View(oMedicamentoCLS));
        }
 int IService1.agregarEditarMedicamento(MedicamentoCLS inputMedicamentoCLS)
 {
     throw new NotImplementedException();
 }
        public IActionResult Guardar(MedicamentoCLS oMedicamentoCLS)
        {
            string nombreVista = "";

            try
            {
                using (BDHospitalContext bd = new BDHospitalContext())
                {
                    if (oMedicamentoCLS.iidMedicamento == 0)
                    {
                        nombreVista = "Agregar";
                    }
                    else
                    {
                        nombreVista = "Editar";
                    }

                    //si no son validos los datos se queda en la vista
                    if (!ModelState.IsValid)
                    {
                        //variable que iguala al metodo de la forma farmaceutica
                        ViewBag.listaFormaFarmaceutica = listarFormaFarmaceutica();
                        return(View(nombreVista, oMedicamentoCLS));
                    }
                    else
                    {
                        //verfica si la id es 0 es guardar
                        if (oMedicamentoCLS.iidMedicamento == 0)
                        {
                            Medicamento medicamento = new Medicamento();
                            medicamento.Nombre               = oMedicamentoCLS.nombre;
                            medicamento.Concentracion        = oMedicamentoCLS.concentracion;
                            medicamento.Iidformafarmaceutica = oMedicamentoCLS.iidFormaFarmaceutica;
                            medicamento.Precio               = oMedicamentoCLS.precio;
                            medicamento.Stock        = oMedicamentoCLS.stock;
                            medicamento.Presentacion = oMedicamentoCLS.presentacion;
                            medicamento.Bhabilitado  = 1;
                            bd.Medicamento.Add(medicamento);
                            bd.SaveChanges();
                        }
                        else
                        {
                            //verifica si el id tiene un valor edita
                            Medicamento medicamento = bd.Medicamento.
                                                      Where(p => p.Iidmedicamento == oMedicamentoCLS.iidMedicamento)
                                                      .First();

                            //modifica los datos que fueron recibidos en el modelo
                            medicamento.Nombre               = oMedicamentoCLS.nombre;
                            medicamento.Concentracion        = oMedicamentoCLS.concentracion;
                            medicamento.Iidformafarmaceutica = oMedicamentoCLS.iidFormaFarmaceutica;
                            medicamento.Precio               = oMedicamentoCLS.precio;
                            medicamento.Stock        = oMedicamentoCLS.stock;
                            medicamento.Presentacion = oMedicamentoCLS.presentacion;
                            bd.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception)
            {
                return(View(nombreVista, oMedicamentoCLS));
            }

            return(RedirectToAction("Index"));
        }
        private void cmdAceptar_Click(object sender, EventArgs e)
        {
            var exito = true;

            if (txtnombre.Text == "")
            {
                errorDatos.SetError(txtnombre, "Ingrese nombre");
                exito = false;
            }
            else
            {
                errorDatos.SetError(txtnombre, "");
            }


            if (txtStock.Text == "")
            {
                errorDatos.SetError(txtStock, "Ingrese Stock");
                exito = false;
            }
            else
            {
                errorDatos.SetError(txtnombre, "");
            }



            if (txtPrecio.Text == "")
            {
                errorDatos.SetError(txtPrecio, "Ingrese precio");
                exito = false;
            }
            else
            {
                errorDatos.SetError(txtPrecio, "");
            }

            if (txtPresentacion.Text == "")
            {
                errorDatos.SetError(txtPresentacion, "Ingrese Presentacion");
                exito = false;
            }
            else
            {
                errorDatos.SetError(txtPresentacion, "");
            }

            if ((int)cboformaFarmaceutica.SelectedValue == 0)
            {
                errorDatos.SetError(cboformaFarmaceutica, "Ingrese Forma Farmaceutica");
                exito = false;
            }
            else
            {
                errorDatos.SetError(cboformaFarmaceutica, "");
            }


            if (exito == false)
            {
                this.DialogResult = DialogResult.None;
                return;
            }
            else
            {
                MedicamentoCLS oMedicamentoCLS = new MedicamentoCLS();
                oMedicamentoCLS.IidMedicamento       = int.Parse(txtIdMedicamento.Text);
                oMedicamentoCLS.Nombre               = txtnombre.Text;
                oMedicamentoCLS.Precio               = decimal.Parse(txtPrecio.Text);
                oMedicamentoCLS.Presentacion         = txtPresentacion.Text;
                oMedicamentoCLS.IidFormaFarmaceutica = (int)cboformaFarmaceutica.SelectedValue;
                oMedicamentoCLS.Stock       = int.Parse(txtStock.Text);
                oMedicamentoCLS.BHabilitado = 1;
                MedicamentosClient oMedicamentosClient = new MedicamentosClient();
                oMedicamentosClient.ClientCredentials.UserName.UserName = "******";
                oMedicamentosClient.ClientCredentials.UserName.Password = "******";
                int rpta = oMedicamentosClient.RegistraryActualizarMedicamento(oMedicamentoCLS);

                if (rpta == 1)
                {
                    MessageBox.Show("Guardado");
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("Error");
                    this.DialogResult = DialogResult.None;
                }
            }

            //ingresando o editando

            //Nuevo
            //if (txtIdMedicamento.Text=="")
            //{

            //}
            //else
            ////Editar
            //{

            //}
        }