Exemple #1
0
        private void btnAgregar_Click(object sender, RoutedEventArgs e)
        {
            bandera = true;
            var    newW = new windowAgregarLp();
            string nombre;

            // newW.lblpreciolista.Visibility = Visibility.Hidden;
            //newW.txtPreciolista.Visibility = Visibility.Hidden;
            //newW.btnModpl.Visibility = Visibility.Hidden;
            newW.ShowDialog();

            if (newW.DialogResult == true)
            {
                nombre = newW.txtNombre.Text;
                DateTime hoy;
                hoy = DateTime.Today;



                String sql;
                sql = "INSERT into listadeprecios(nombre, fecha,tipo,moneda) values('" + nombre + "', '" + hoy.ToString("yyyy/MM/dd") + "','" + 0 + "','" + 0 + "')";
                conexion.operaciones(sql);

                string ultimoId = "Select last_insert_id()";
                String id       = conexion.ValorEnVariable(ultimoId);


                String consulta;


                for (int i = 0; i < newW.itemslp.Count; i++)
                {
                    int    fkidp       = newW.itemslp[i].id;
                    double preciolista = newW.itemslp[i].preciolista;
                    consulta = "INSERT into productos_has_listadeprecios(FK_idProductos, FK_idLista, precioLista) values('" + fkidp + "', '" + id + "', '" + preciolista + "')";
                    conexion.operaciones(consulta);
                }


                loadlp();
                ltsLp.SelectedIndex = ltsLp.Items.Count - 1;
                bandera             = false;
                ActualizaDGVlp();
                MessageBox.Show("Se agrego la lista de precio correctamente", "Información", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
Exemple #2
0
        private void btnModificar_Click(object sender, RoutedEventArgs e)
        {
            bandera = true;

            try
            {
                int modificado;
                modificado = ltsLp.SelectedIndex;
                int    idlista = (int)ltsLp.SelectedValue;
                String nombrelp;
                String fecha;

                DateTime hoy;
                hoy = DateTime.Today;

                String consulta = "SELECT nombre from listadeprecios where idLista='" + idlista + "';";
                String nombre   = conexion.ValorEnVariable(consulta);

                fecha = hoy.ToString("yyyy/MM/dd");

                nombrelp = nombre;

                var newW = new windowAgregarLp(idlista, nombrelp, listadeprecios, fecha);

                for (int i = 0; i < newW.itemslp.Count; i++)
                {
                    for (int j = 0; j < newW.items.Count; j++)
                    {
                        if (newW.itemslp[i].nombre == newW.items[j].nombre)
                        {
                            newW.items.Remove(newW.items[j]);
                        }
                    }
                }


                newW.ShowDialog();

                if (newW.DialogResult == true)
                {
                    hoy    = DateTime.Today;
                    fecha  = hoy.ToString("yyyy/MM/dd");
                    nombre = newW.txtNombre.Text;

                    String update = "update listadeprecios set nombre = '" + nombre + "', fecha = '" + fecha + "' where idLista = '" + idlista + "'; ";
                    conexion.operaciones(update);


                    String producto = "delete from productos_has_listadeprecios where FK_idLista= '" + idlista + "'";
                    conexion.operaciones(producto);



                    foreach (var item in newW.itemslp)
                    {
                        string sql;
                        sql = "INSERT INTO productos_has_listadeprecios (FK_idLista,precioLista,FK_idProductos) values('" + idlista + "', '" + item.preciolista + "' , '" + item.id + "')";
                        conexion.operaciones(sql);
                    }
                    loadlp();
                    ActualizaDGVlp();
                }


                ltsLp.Items.Refresh();


                ltsLp.SelectedIndex = modificado;
                ActualizaDGVlp();

                lblnombre.Content  = nombre;
                lblultimam.Content = hoy.ToString("yyyy/MM/dd");
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Seleccione una Lista de precios a modificar", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }


            bandera = false;


            ActualizaDGVlp();
        }