static public void Excluir(Suplemento Sup)
 {
     //gera um update
     Sup.Ativo = false;
     contexto.Entry(Sup).State = System.Data.Entity.EntityState.Modified;
     contexto.SaveChanges();
 }
示例#2
0
        /// <summary>
        /// Dispara el form para la modificación de un suplemento
        /// </summary>
        /// <param name="sender"> de tipo object </param>
        /// <param name="e"> de tipo EventArgs </param>
        private void buttonModificarSuplemento_Click(object sender, EventArgs e)
        {
            if (this.dataGridSuplementos.Rows.Count > 0)
            {
                int        indice = this.dataGridSuplementos.SelectedRows[0].Index;
                DataRow    fila   = this.dtSuplementos.Rows[indice];
                Suplemento sup    = new Suplemento(int.Parse(fila[0].ToString()), fila["nombre"].ToString(),
                                                   fila["tipo"].ToString(), float.Parse(fila["precio"].ToString()),
                                                   fila["formato"].ToString(), fila["empaque"].ToString());

                FrmSuplemento frm = new FrmSuplemento(sup);
                frm.StartPosition = FormStartPosition.CenterScreen;
                try
                {
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        fila["nombre"]  = frm.SuplementoDelForm.Nombre;
                        fila["tipo"]    = frm.SuplementoDelForm.Tipo;
                        fila["precio"]  = frm.SuplementoDelForm.Precio;
                        fila["formato"] = frm.SuplementoDelForm.Formato;
                        fila["empaque"] = frm.SuplementoDelForm.Empaque;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
示例#3
0
        public void VerificarOperadorSumaDeStock()
        {
            Stock      storage = new Stock();
            Suplemento sup     = new Suplemento(20, "proteina", "suplemento", 1000, "polvo", "frasco");

            storage += sup;
            Assert.IsTrue(storage.Deposito.Contains(sup));
        }
 /// <summary>
 /// Constructor parametrizado de FrmSuplemento
 /// </summary>
 /// <param name="sup"> de tipo Suplemento </param>
 public FrmSuplemento(Suplemento sup) : this()
 {
     this.suplemento        = sup;
     this.txtNombreSup.Text = this.suplemento.Nombre;
     this.comboTipo.Text    = this.suplemento.Tipo;
     this.txtPrecio.Text    = this.suplemento.Precio.ToString();
     this.comboFormato.Text = this.suplemento.Formato;
     this.comboEmpaque.Text = this.suplemento.Empaque;
 }
 static public void Adicionar(Suplemento Sup)
 {
     if (Sup != null)
     {
         contexto.Suplementos.Add(Sup);
         //problema de contexto
         contexto.SaveChanges();
     }
 }
示例#6
0
        protected void btnSalvar_Click(object sender, EventArgs e)
        {
            Suplemento Suple = new Suplemento();

            Suple.Nome      = txtNome.Text;
            Suple.Descricao = txtDescricao.Text;
            Suple.Marca     = MarcaController.BuscarPorNome(txtMarca.Text);
            Suple.Forma     = txtForma.Text;
            Suple.Origem    = ddlOrigem.Text;
            Suple.Ativo     = true;
            SuplementoController.Adicionar(Suple);
        }
示例#7
0
        protected void btnExucluir_Click(object sender, EventArgs e)
        {
            Suplemento Sup = new Suplemento();

            Sup = SuplementoController.BuscarPorNome(txtBuscar.Text);
            if (Sup != null)
            {
                if (Sup.Ativo == true)
                {
                    Sup.Ativo = false;
                    SuplementoController.Excluir(Sup);
                }
            }
        }
示例#8
0
        protected void btnBuscar_Click(object sender, EventArgs e)
        {
            Suplemento Sup = new Suplemento();

            Sup = SuplementoController.BuscarPorNome(txtBuscar.Text);
            if (Sup != null)
            {
                txtNome.Text      = Sup.Nome;
                txtDescricao.Text = Sup.Descricao;
                txtMarca.Text     = Sup.Marca.ToString();
                ddlOrigem.Text    = Sup.Origem.ToString();
                txtForma.Text     = Sup.Forma;
            }
        }
示例#9
0
 public static bool AdicionarSuplemento(Suplemento suplemento)
 {
     try
     {
         ctx.Suplementos.Add(suplemento);
         ctx.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
         return(false);
     }
 }
示例#10
0
        /// <summary>
        /// Realiza la serialización xml de los stocks de Medicamentos y Suplementos
        /// Serialización (Tema requerido por la consigna del TP Nº4)
        /// </summary>
        /// <param name="sender"> de tipo object </param>
        /// <param name="e"> de tipo EventArgs </param>
        private void buttonSerializarStock_Click(object sender, EventArgs e)
        {
            try
            {
                //Serialización desde la grilla de suplementos
                Stock listaDeSuplementos = new Stock();
                int   index;
                if (this.dataGridSuplementos.Rows.Count > 0)
                {
                    for (index = 0; index < this.dataGridSuplementos.Rows.Count; index++)
                    {
                        Suplemento sup = new Suplemento(int.Parse(this.dataGridSuplementos[0, index].Value.ToString()), this.dataGridSuplementos[1, index].Value.ToString(),
                                                        this.dataGridSuplementos[2, index].Value.ToString(), float.Parse(this.dataGridSuplementos[3, index].Value.ToString()),
                                                        this.dataGridSuplementos[4, index].Value.ToString(), this.dataGridSuplementos[5, index].Value.ToString());
                        listaDeSuplementos += sup;
                    }
                    Stock.GuardarXml(listaDeSuplementos, "StockSuplementos.xml");
                    MessageBox.Show("Se ha serializado el stock de suplementos");
                }
                else
                {
                    MessageBox.Show("No se serializó el stock de suplementos");
                }

                //Serialización desde la grilla de medicamentos
                Stock listaDeMedicamentos = new Stock();
                if (this.dataGridMedicamentos.Rows.Count > 0)
                {
                    for (index = 0; index < this.dataGridMedicamentos.Rows.Count; index++)
                    {
                        Medicamento med = new Medicamento(int.Parse(this.dataGridMedicamentos[0, index].Value.ToString()), this.dataGridMedicamentos[1, index].Value.ToString(),
                                                          this.dataGridMedicamentos[2, index].Value.ToString(), float.Parse(this.dataGridMedicamentos[3, index].Value.ToString()),
                                                          this.dataGridMedicamentos[4, index].Value.ToString(), this.dataGridMedicamentos[5, index].Value.ToString());
                        listaDeMedicamentos += med;
                    }

                    Stock.GuardarXml(listaDeMedicamentos, "StockMedicamentos.xml");
                    MessageBox.Show("Se ha serializado el stock de medicamentos");
                }
                else
                {
                    MessageBox.Show("No se serializó el stock de medicamentos");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#11
0
        /// <summary>
        /// Botón de Vender, que lleva a cabo la venta de los productos seleccionados. En caso de que no haya ningún producto seleccionado o no haya ningún producto
        /// en stock, no permite ejecutar la venta.
        /// En este manejador de eventos, se utiliza el evento ContarVentaEvent, que actualiza el contador de ventas en el FormPrincipal en
        /// tiempo real. (Delegados y eventos - Tema requerido por la consigna del TP Nº4)
        /// </summary>
        /// <param name="sender"> de tipo object </param>
        /// <param name="e"> de tipo eventargs </param>
        private void buttonVender_Click(object sender, EventArgs e)
        {
            if (dataGridMedicamentos.SelectedRows.Count == 0 && dataGridSuplementos.SelectedRows.Count == 0)
            {
                MessageBox.Show("No se puede efectuar la venta porque no se seleccionó ningún producto o no hay stock disponible");
            }
            else
            {
                FrmPrincipal mainForm = new FrmPrincipal();
                DialogResult result   = MessageBox.Show("¿Está seguro de que quiere efectuar la venta de este producto?", "Ventas",
                                                        MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                int index;
                if (result == DialogResult.OK)
                {
                    foreach (DataGridViewRow row in dataGridMedicamentos.SelectedRows)
                    {
                        index = dataGridMedicamentos.CurrentRow.Index;
                        Medicamento med = new Medicamento(int.Parse(this.dataGridMedicamentos[0, index].Value.ToString()), this.dataGridMedicamentos[1, index].Value.ToString(),
                                                          this.dataGridMedicamentos[2, index].Value.ToString(), float.Parse(this.dataGridMedicamentos[3, index].Value.ToString()),
                                                          this.dataGridMedicamentos[4, index].Value.ToString(), this.dataGridMedicamentos[5, index].Value.ToString());
                        this.listaDeVentas += med;
                        dataGridMedicamentos.Rows.Remove(row);
                    }

                    foreach (DataGridViewRow row in dataGridSuplementos.SelectedRows)
                    {
                        index = dataGridSuplementos.CurrentRow.Index;
                        Suplemento sup = new Suplemento(int.Parse(this.dataGridSuplementos[0, index].Value.ToString()), this.dataGridSuplementos[1, index].Value.ToString(),
                                                        this.dataGridSuplementos[2, index].Value.ToString(), float.Parse(this.dataGridSuplementos[3, index].Value.ToString()),
                                                        this.dataGridSuplementos[4, index].Value.ToString(), this.dataGridSuplementos[5, index].Value.ToString());
                        this.listaDeVentas += sup;
                        dataGridSuplementos.Rows.Remove(row);
                    }

                    try
                    {
                        mainForm.SQLAdapterMedicamentos.Update(dtVenta);
                        mainForm.SQLAdapterSuplementos.Update(dtVentaSuplementos);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    this.GenerarTicket();
                    ContarVentaEvent();
                }
            }
        }
示例#12
0
        private void btnAdicionar_Click(object sender, RoutedEventArgs e)
        {
            int        idProduto     = (int)cboSuplementos.SelectedValue;
            Suplemento suplemento    = SuplementoDAO.BuscarSuplementoPorId(idProduto);
            double     precoUnitario = suplemento.Markup * suplemento.Preco;
            double     subtotal      = precoUnitario * Convert.ToInt32(txtQuantidade.Text);

            listaDeItens.Add(new
            {
                NomeSuplemento = suplemento.Nome,
                Quantidade     = txtQuantidade.Text,
                Unitario       = precoUnitario.ToString("C2"),
                Subtotal       = subtotal.ToString("C2")
            });
            dtaSuplementos.ItemsSource = listaDeItens;
            dtaSuplementos.Items.Refresh();
        }
示例#13
0
        /// <summary>
        /// Dispara el form para la eliminación de un suplemento
        /// </summary>
        /// <param name="sender"> de tipo object </param>
        /// <param name="e"> de tipo EventArgs </param>
        private void buttonEliminarSuplemento_Click(object sender, EventArgs e)
        {
            if (this.dataGridSuplementos.Rows.Count > 0)
            {
                int        indice = this.dataGridSuplementos.SelectedRows[0].Index;
                DataRow    fila   = this.dtSuplementos.Rows[indice];
                Suplemento sup    = new Suplemento(int.Parse(fila[0].ToString()), fila["nombre"].ToString(),
                                                   fila["tipo"].ToString(), float.Parse(fila["precio"].ToString()),
                                                   fila["formato"].ToString(), fila["empaque"].ToString());

                FrmSuplemento frm = new FrmSuplemento(sup);
                frm.StartPosition = FormStartPosition.CenterScreen;
                if (frm.ShowDialog() == DialogResult.OK && fila.RowState != DataRowState.Deleted)
                {
                    fila.Delete();
                }
            }
        }
        /// <summary>
        /// Botón de aceptar del Formulario
        /// </summary>
        /// <param name="sender"> de tipo object </param>
        /// <param name="e"> de tipo eventargs </param>
        private void buttonAceptar_Click_1(object sender, EventArgs e)
        {
            try
            {
                int idSup = 0;
                if (this.suplemento != null)
                {
                    idSup = this.suplemento.ID;
                }

                this.suplemento = new Suplemento(idSup, this.txtNombreSup.Text, this.comboTipo.Text,
                                                 float.Parse(this.txtPrecio.Text), this.comboFormato.Text, this.comboEmpaque.Text);


                this.DialogResult = DialogResult.OK;
            }
            catch (Exception)
            {
                MessageBox.Show("Uno o más campos están vacíos");
            }
        }
示例#15
0
        protected void ListarPor()
        {
            Suplemento Sup = new Suplemento();

            Sup = SuplementoController.BuscarPorId(ddlTipo.Items.Count);

            if (Sup != null && ddlTipo.Items.Count.Equals("Nome"))
            {
                gvwTipo.DataSource = SuplementoController.Listar().OrderBy(x => x.Nome);
            }
            else
            {
                if (Sup != null && ddlTipo.Items.Count.Equals("Origem"))
                {
                    gvwTipo.DataSource = SuplementoController.Listar().OrderBy(x => x.Origem);
                }
                else
                {
                    gvwTipo.DataSource = SuplementoController.Listar().OrderBy(x => x.Forma);
                }
            }
        }
 static public void Editar(Suplemento Sup)
 {
     contexto.Entry(Sup).State = System.Data.Entity.EntityState.Modified;
     contexto.SaveChanges();
 }
示例#17
0
 public static Suplemento BuscarSuplementoPorNome(Suplemento suplemento)
 {
     return(ctx.Suplementos.FirstOrDefault(x => x.Nome.Equals(suplemento.Nome)));
 }
示例#18
0
        static void Main(string[] args)
        {
            try
            {
                Medicamento med1 = new Medicamento(30, "3412983", "analgésico", 100, "bayer", "argentina");
            }
            catch (StringInvalidoException ex)
            {
                Console.WriteLine(ex.Message);
            }
            try
            {
                Medicamento med2 = new Medicamento(40, "Ibuprofeno", "analgésico", -10, "bayer", "argentina");
            }
            catch (PrecioInvalidoException ex)
            {
                Console.WriteLine(ex.Message);
            }

            Medicamento med3 = new Medicamento(20, "Aspirina", "analgésico", 20, "gador", "argentina");
            Medicamento med4 = new Medicamento(20, "Paracetamol", "analgésico", 40, "raffo", "argentina");
            Medicamento med5 = new Medicamento(20, "Loratadina", "antihistamínico", 40, "isa", "argentina");

            Console.WriteLine(med3.ToString());

            Stock storage = new Stock();

            storage += med3;
            storage += med4;
            storage += med5;

            Suplemento sup1 = new Suplemento(50, "proteina", "suplemento", 5000, "polvo", "frasco");

            storage += sup1;

            Console.WriteLine(storage.ToString());

            SqlConnection cn = new SqlConnection(@"Server=localhost\SQLEXPRESS;Database=master;Trusted_Connection=True;");

            try
            {
                cn.Open();
                if (cn.State == System.Data.ConnectionState.Open)
                {
                    cn.Close();
                    Console.WriteLine("Conexión exitosa");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            try
            {
                bool rta = Stock.GuardarXml(storage, "PruebaStock.xml");
                if (rta)
                {
                    Console.WriteLine("Se ha guardado el archivo xml");
                }
            }
            catch (ArchivosException)
            {
                Console.WriteLine("No se pudo guardar el archivo xml");
            }
            Console.ReadKey();
            Console.Clear();

            try
            {
                Xml <Stock> file = new Xml <Stock>();
                bool        rta  = file.Leer("PruebaStock.xml", out storage);
                Console.WriteLine(storage.ToString());
            }
            catch (ArchivosException)
            {
                Console.WriteLine("No se pudo leer el archivo xml");
            }



            Console.ReadKey();
        }