示例#1
0
        private void btnBuscaNomeCurso_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(txtBuscaNomeInstrumento.Text))
            {
                instrumento = new Instrumento
                {
                    Nome = txtBuscaNomeInstrumento.Text
                };

                instrumento = InstrumentoDAO.BuscarInstrumentoPorNome(instrumento);

                if (instrumento != null)
                {
                    txtNomeInstrumento.Text = instrumento.Nome;

                    txtPrecoInstrumento.Text      = instrumento.Preço.ToString();
                    txtQuantidadeInstrumento.Text = instrumento.Quantidade.ToString();
                    HabilitarCampos(true);
                }
                else
                {
                    MessageBox.Show("Esse Instrumento não existe!", "Escola de Musica",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("Favor preencher o nome!", "Escola de Musica",
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        /// <summary>
        /// Modifica el instrumento seleccionado con los valores ingresados, lo guarda en la DB
        /// y avisa al FormPrincipal.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnModificar_Click(object sender, EventArgs e)
        {
            if (this.ValidarDatos())
            {
                float precio = float.Parse(this.txtPrecio.Text);

                if (this.cmbInstrumento.SelectedIndex == 0)
                {
                    Guitarra.ETipoGuitarra tipo;
                    Enum.TryParse <Guitarra.ETipoGuitarra>(this.cmbTipo.SelectedValue.ToString(), out tipo);

                    Guitarra g = new Guitarra(this.txtSerie.Text, this.txtMarca.Text, this.txtModelo.Text, precio, tipo);
                    InstrumentoDAO.Modificar(g);
                    this.ModificacionInstrumentos.Invoke();
                    MessageBox.Show("Se modificó con exito");
                    this.Close();
                }
                else if (this.cmbInstrumento.SelectedIndex == 1)
                {
                    Bajo.ETipoBajo tipo;
                    Enum.TryParse <Bajo.ETipoBajo>(this.cmbTipo.SelectedValue.ToString(), out tipo);

                    Bajo b = new Bajo(this.txtSerie.Text, this.txtMarca.Text, this.txtModelo.Text, precio, tipo);
                    InstrumentoDAO.Modificar(b);
                    this.ModificacionInstrumentos();
                    MessageBox.Show("Se modificó con exito");
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("Los datos ingresados no son correctos");
            }
        }
        private void btnBuscar_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(txtNomeInstrumentoBuscar.Text))
            {
                instrumento = new Instrumento
                {
                    Nome = txtNomeInstrumentoBuscar.Text
                };

                instrumento = InstrumentoDAO.BuscarInstrumentoPorNome(instrumento);

                if (instrumento != null)
                {
                    //Mostrar os dados
                    HabilitarCampos(true);
                }
                else
                {
                    MessageBox.Show("Esse Instrumento não existe!", "Escola de Musica",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("Favor preencher o nome!", "Escola de Musica",
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#4
0
 private void btnCadastrarInstrumento_Click(object sender, RoutedEventArgs e)
 {
     if (!string.IsNullOrEmpty(TxtNomeInstrumento.Text) &&
         !string.IsNullOrEmpty(TxtPrecoInstrumento.Text) &&
         !string.IsNullOrEmpty(TxtQtdInstrumento.Text))
     {
         //Gravar
         instrumento = new Instrumento
         {
             Nome       = TxtNomeInstrumento.Text,
             Preço      = Convert.ToDouble(TxtPrecoInstrumento.Text),
             Quantidade = Convert.ToInt32(TxtQtdInstrumento.Text)
         };
         if (InstrumentoDAO.CadastrarInstrumento(instrumento))
         {
             MessageBox.Show("Instrumento cadastrado com sucesso!", "Escola de Musica",
                             MessageBoxButton.OK, MessageBoxImage.Information);
         }
         else
         {
             MessageBox.Show("Esse Instrumento já existe!", "Escola de Musica",
                             MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     else
     {
         MessageBox.Show("Favor preencher os campos corretamente!", "Escola de Musica",
                         MessageBoxButton.OK, MessageBoxImage.Error);
     }
     LimpaCampos();
 }
        public void ProbarAltaInstrumentoRepetido()
        {
            Guitarra g  = new Guitarra("test", "test", "test", 0, Guitarra.ETipoGuitarra.Acustica);
            Guitarra g2 = new Guitarra("test", "test", "test", 0, Guitarra.ETipoGuitarra.Acustica);

            InstrumentoDAO.Guardar(g);
            InstrumentoDAO.Guardar(g2);
        }
示例#6
0
 /// <summary>
 /// Actgualiza la lista de instrumentos leyendola de la DB.
 /// </summary>
 private void ManejadorActualizaLista()
 {
     try
     {
         this.tienda.Instrumentos = InstrumentoDAO.LeerInstrumentos();
     }
     catch (DatabaseException ex)
     {
         MessageBox.Show(ex.Message + " Por favor intente nuevamente", "Error de base de datos");
     }
 }
示例#7
0
 public FrmPrincipal()
 {
     InitializeComponent();
     //inicializo la tienda y leo la db para traer los instrumentos.
     this.tienda = new TiendaMusical();
     this.tienda.Instrumentos = InstrumentoDAO.LeerInstrumentos();
     //simulo clientes utilizando las salas de prueba. El simulador se ejecutara
     //Aleatoriamente según el tick del timer.
     this.timer          = new System.Windows.Forms.Timer();
     this.timer.Tick    += new EventHandler(this.SimuladorClientes);
     this.timer.Interval = new Random().Next(1000, 5000);
     this.timer.Start();
 }
        /// <summary>
        /// Elimina el instrumento, avisando si pudo hacerlo correctamente, e informando mediante
        /// el evento ModificacionInstrumento al FormPrincipal.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            if (this.listInstrumentos.SelectedValue is Guitarra && InstrumentoDAO.EliminarGuitarra(this.txtSerie.Text) == 1)
            {
                MessageBox.Show("Se elimino correctamente el instrumento");
            }

            else if (this.listInstrumentos.SelectedValue is Bajo && InstrumentoDAO.EliminarGuitarra(this.txtSerie.Text) == 1)
            {
                MessageBox.Show("Se elimino correctamente el instrumento");
            }

            this.ModificacionInstrumentos.Invoke();
            this.Close();
        }
 /// <summary>
 /// Guarda el alta de un nuevo instrumento en la base de datos, validando los datos
 /// y arrojando error de encontrarse repetido o haber algún dato erroneo.
 /// Dispara un evento que avisa de la modificación al form principal.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnAlta_Click(object sender, EventArgs e)
 {
     if (this.ValidarDatos())
     {
         //Leo los datos del instrumento
         float precio = float.Parse(this.txtPrecio.Text);
         if (this.cmbInstrumento.SelectedIndex == 0)
         {
             Guitarra.ETipoGuitarra tipo;
             Enum.TryParse <Guitarra.ETipoGuitarra>(this.cmbTipo.SelectedValue.ToString(), out tipo);
             try
             {
                 //Guardo la guitarra en la base y disparo el evento.
                 Guitarra g = new Guitarra(this.txtSerie.Text, this.txtMarca.Text, this.txtModelo.Text, precio, tipo);
                 InstrumentoDAO.Guardar(g);
                 this.ModificacionInstrumentos.Invoke();
                 MessageBox.Show("Se dio el alta con exito");
                 this.Close();
             }
             catch (InstrumentoRepetidoException ex)
             {
                 MessageBox.Show(ex.Message);
             }
         }
         else if (this.cmbInstrumento.SelectedIndex == 1)
         {
             Bajo.ETipoBajo tipo;
             Enum.TryParse <Bajo.ETipoBajo>(this.cmbTipo.SelectedValue.ToString(), out tipo);
             try
             {
                 //Guardo el Bajo en la base y disparo el evento.
                 Bajo b = new Bajo(this.txtSerie.Text, this.txtMarca.Text, this.txtModelo.Text, precio, tipo);
                 InstrumentoDAO.Guardar(b);
                 this.ModificacionInstrumentos.Invoke();
                 MessageBox.Show("Se dio el alta con exito");
                 this.Close();
             }
             catch (InstrumentoRepetidoException ex)
             {
                 MessageBox.Show(ex.Message);
             }
         }
     }
     else //si la validacion falla
     {
         MessageBox.Show("Los datos ingresados no son correctos");
     }
 }
 private void btnRemover_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBox.Show("Deseja remover esse registro?",
                         "Escola de Musica",
                         MessageBoxButton.YesNo,
                         MessageBoxImage.Question) == MessageBoxResult.Yes)
     {
         //Remover o produto
         InstrumentoDAO.RemoverInstrumento(instrumento);
         MessageBox.Show("Instrumento removido com sucesso!",
                         "Escola de Musica",
                         MessageBoxButton.OK,
                         MessageBoxImage.Information);
         HabilitarCampos(false);
         txtNomeInstrumentoBuscar.Clear();
     }
 }
示例#11
0
        /// <summary>
        /// Verifica que se haya seleccionado un instrumento. Solicita confirmación antes de realizar
        /// la venta del instrumento y su eliminacion de la DB.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnComprar_Click(object sender, EventArgs e)
        {
            if (object.ReferenceEquals(this.instrumentoSeleccionado, null))
            {
                MessageBox.Show("Debe elegir un instrumento primero");
            }
            else
            {
                DialogResult comprar = MessageBox.Show($"Desea comprar el instrumento: {this.instrumentoSeleccionado.ToString()}", "Confirmar compra", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (comprar == DialogResult.Yes)
                {
                    try
                    {
                        //Vendo el instrumento seleccionado y serializo.
                        this.tienda.Vender(this.instrumentoSeleccionado, "ventas.xml");
                        try
                        {
                            if (this.instrumentoSeleccionado is Bajo)
                            {
                                InstrumentoDAO.EliminarBajo(this.instrumentoSeleccionado.NumSerie);
                            }
                            else
                            {
                                InstrumentoDAO.EliminarGuitarra(this.instrumentoSeleccionado.NumSerie);
                            }
                        }
                        catch (DatabaseException ex)
                        {
                            MessageBox.Show(ex.Message + " Por favor intente nuevamente");
                        }
                        MessageBox.Show("Se efectuó la compra");

                        //Elimino el instrumento seleccionado.
                        this.toolStripLabel.Text     = "Ningún instrumento seleccionado";
                        this.instrumentoSeleccionado = null;
                        //Vuelvo a leer la base de datos para que no muestre el eliminado.
                        this.ManejadorActualizaLista();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }
示例#12
0
        private void btnGravarInstrumento_Click(object sender, RoutedEventArgs e)
        {
            int         aux = Convert.ToInt32(cboCategorias.SelectedValue);
            Instrumento i   = new Instrumento();

            i.InstrumentoNome      = txtInstNome.Text;
            i.InstrumentoPreco     = float.Parse(txtInstPreco.Text);
            i.InstrumentoCategoria = CategoriaDAO.RetornarCategoriaId(aux);

            if (InstrumentoDAO.AdicionarInstrumento(i))
            {
                MessageBox.Show("Instrumento cadastrado com sucesso!");
            }
            else
            {
                MessageBox.Show("Não foi possivel cadastrar instrumento!!");
            }
        }
示例#13
0
        /// <summary>
        /// Elimina el instrumento, avisando si pudo hacerlo correctamente, e informando mediante
        /// el evento ModificacionInstrumento al FormPrincipal.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.listInstrumentos.SelectedValue is Guitarra && InstrumentoDAO.EliminarGuitarra(this.txtSerie.Text) == 1)
                {
                    MessageBox.Show("Se elimino correctamente la Guitarra");
                }
                else if (this.listInstrumentos.SelectedValue is Bajo && InstrumentoDAO.EliminarBajo(this.txtSerie.Text) == 1)
                {
                    MessageBox.Show("Se elimino correctamente el Bajo");
                }

                this.ModificacionInstrumentos.Invoke();
                this.Close();
            }
            catch (DatabaseException ex)
            {
                MessageBox.Show(ex.Message + " Por favor intente nuevamente", "Error al eliminar");
            }
        }
示例#14
0
        private void btnAlteraCurso_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Deseja Alterar esse registro?",
                                "Escola de Musica",
                                MessageBoxButton.YesNo,
                                MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                //Remover o produto
                instrumento.Nome = txtNomeInstrumento.Text;

                instrumento.Quantidade = Convert.ToInt32(txtQuantidadeInstrumento.Text);
                instrumento.Preço      = Convert.ToDouble(txtPrecoInstrumento.Text);
                InstrumentoDAO.AlterarInstrumento(instrumento);
                MessageBox.Show("Instrumento Alterado com sucesso!",
                                "Escola de Musica",
                                MessageBoxButton.OK,
                                MessageBoxImage.Information);

                HabilitarCampos(false);
                LimpaCampos();
            }
        }
示例#15
0
        static void Main(string[] args)
        {
            Guitarra g1 = new Guitarra("F123ASD3415", "Fender", "Telecaster Custom", 150000, Guitarra.ETipoGuitarra.Electrica);
            Guitarra g2 = new Guitarra("QWEaz321654", "Schecter", "Hellraiser", 650000, Guitarra.ETipoGuitarra.Electrica);
            Guitarra g3 = new Guitarra("12345aASJQ415", "Taylor", "GS Mini", 80000, Guitarra.ETipoGuitarra.Acustica);
            Bajo     b1 = new Bajo("3216ASQwq65", "Fender", "Jazz Bass", 200000, Bajo.ETipoBajo.Pasivo);
            Bajo     b2 = new Bajo("aSFKQOPWFAs", "Ernie Ball", "MusicMan", 300000, Bajo.ETipoBajo.Pasivo);

            InstrumentoDAO.Guardar(g1);
            InstrumentoDAO.Guardar(g2);
            InstrumentoDAO.Guardar(g3);
            InstrumentoDAO.Guardar(b1);
            InstrumentoDAO.Guardar(b2);

            Console.WriteLine(g1.ToString());
            Console.WriteLine(g2.ToString());
            Console.WriteLine(b1.ToString());
            Console.WriteLine(b2.ToString());

            TiendaMusical t = new TiendaMusical();

            t.Instrumentos = InstrumentoDAO.LeerInstrumentos();
            foreach (Instrumento instrumento in t.Instrumentos)
            {
                Console.WriteLine(instrumento.ToString());
            }


            g3.Marca = "Anderson";
            InstrumentoDAO.Modificar(g3);

            Bajo b3 = new Bajo("aSFKQOPWFAs", "cambiado", "cambiado", 50, Bajo.ETipoBajo.Activo);

            InstrumentoDAO.Modificar(b3);


            Console.ReadKey();
        }
示例#16
0
        static void Main(string[] args)
        {
            Guitarra g1 = new Guitarra("G12305423", "Gibson", "Les Paul", 300000, Guitarra.ETipoGuitarra.Electrica);
            Guitarra g2 = new Guitarra("A12124828", "Fender", "Stratocaster", 850000, Guitarra.ETipoGuitarra.Electrica);
            Guitarra g3 = new Guitarra("ISSJQ415", "Ibanez", "EC100", 70000, Guitarra.ETipoGuitarra.Acustica);
            Bajo     b1 = new Bajo("F29331991", "Fender", "P-Bass", 200000, Bajo.ETipoBajo.Pasivo);
            Bajo     b2 = new Bajo("X01238412", "Gibson", "Hummingbird", 300000, Bajo.ETipoBajo.Activo);

            InstrumentoDAO.Guardar(g1);
            InstrumentoDAO.Guardar(g2);
            InstrumentoDAO.Guardar(g3);
            InstrumentoDAO.Guardar(b1);
            InstrumentoDAO.Guardar(b2);

            Console.WriteLine(g1.ToString());
            Console.WriteLine(g2.ToString());
            Console.WriteLine(b1.ToString());
            Console.WriteLine(b2.ToString());

            TiendaMusical t = new TiendaMusical();

            t.Instrumentos = InstrumentoDAO.LeerInstrumentos();
            foreach (Instrumento instrumento in t.Instrumentos)
            {
                Console.WriteLine(instrumento.ToString());
            }


            g3.Marca = "Anderson";
            InstrumentoDAO.Modificar(g3);

            Bajo b3 = new Bajo("aSFKQOPWFAs", "cambiado", "cambiado", 50, Bajo.ETipoBajo.Activo);

            InstrumentoDAO.Modificar(b3);


            Console.ReadKey();
        }
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     dtaInstrumentos.ItemsSource = InstrumentoDAO.RetornarInstrumentos();
 }
示例#18
0
 /// <summary>
 /// Actgualiza la lista de instrumentos leyendola de la DB.
 /// </summary>
 private void ManejadorActualizaLista()
 {
     this.tienda.Instrumentos = InstrumentoDAO.LeerInstrumentos();
 }
        private void btnAdionarItemVenda(object sender, RoutedEventArgs e)
        {
            ///vincula o instrumento com o item venda

            Instrumento instrumento = new Instrumento
            {
                InstrumentoId = Convert.ToInt32(cbInstrumentos.SelectedValue)
            };

            instrumento = InstrumentoDAO.BuscarInstrumentoPorId(instrumento);

            double subtotal = instrumento.Preço *
                              Convert.ToInt32(txtQuantidadeInstrumento.Text);

            total           += subtotal;
            lblTotal.Content = "Total: " + total.ToString("C2");


            ItemVenda itemVenda = new ItemVenda
            {
                Instrumento = instrumento,
                Quantidade  = Convert.ToInt32(txtQuantidadeInstrumento.Text),
                PrecoVenda  = instrumento.Preço,
                Subtotal    = subtotal
            };

            if (itemVenda.Instrumento != null)
            {
                itemVenda.Subtotal = subtotal;

                if (Validar.QuantidadeInstrumento(itemVenda.Instrumento, itemVenda.Quantidade))
                {
                    itemVenda.PrecoVenda = itemVenda.Instrumento.Preço;
                    if (Validar.InstrumentoNaVenda(venda, itemVenda))
                    {
                        MessageBox.Show("Instrumento Adicionado com Sucesso!",
                                        "Escola de Musica",
                                        MessageBoxButton.OK,
                                        MessageBoxImage.Information);

                        dtaVendas.ItemsSource = venda.ItensVenda;
                        dtaVendas.Items.Refresh();
                    }
                    else
                    {
                        MessageBox.Show("Instrumento Alterado!",
                                        "Escola de Musica",
                                        MessageBoxButton.OK,
                                        MessageBoxImage.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Quantidade de instrumento indisponivel!",
                                    "Escola de Musica",
                                    MessageBoxButton.OK,
                                    MessageBoxImage.Information);
                }
            }
            else
            {
                MessageBox.Show("Instrumento não encontrado!",
                                "Escola de Musica",
                                MessageBoxButton.OK,
                                MessageBoxImage.Information);
            }
            dtaVendas.Items.Refresh();
        }
 private void Window_Loaded_1(object sender, RoutedEventArgs e)
 {
     cbInstrumentos.ItemsSource       = InstrumentoDAO.RetornarInstrumentos();
     cbInstrumentos.DisplayMemberPath = "Nome";
     cbInstrumentos.SelectedValuePath = "InstrumentoId";
 }