private void btnmlp_Click(object sender, RoutedEventArgs e)
        {
            var    newW = new WindowAgregarLpme();
            string nombre;
            string anexo;

            newW.ShowDialog();


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


                if (newW.txtAnexo.Text == "")
                {
                    anexo = "";
                }
                else
                {
                    anexo = newW.txtAnexo.Text;
                }



                String sql;
                sql = "INSERT into listadeprecios(nombre, fecha,tipo,anexo) values('" + nombre + "', '" + hoy.ToString("yyyy/MM/dd") + "','" + 1 + "','" + anexo + "')";
                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);
                }



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

            try
            {
                int modificado;

                modificado = ltsLpme.SelectedIndex;
                int    idlista = (int)ltsLpme.SelectedValue;
                String nombrelp;
                String fecha;
                String anexo;

                int coin;

                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;
                String consulta2  = "SELECT anexo from listadeprecios where idLista='" + idlista + "';";
                String anexolista = conexion.ValorEnVariable(consulta2);
                String consulta3  = "SELECT moneda from listadeprecios where idLista='" + idlista + "';";
                String moneda     = conexion.ValorEnVariable(consulta3);
                coin  = int.Parse(moneda);
                anexo = anexolista;

                var newW = new WindowAgregarLpme(idlista, lblnombre.Content.ToString(), listadeprecios, fecha, coin, lbltienea.Content.ToString());

                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;
                    anexo  = newW.txtAnexo.Text;
                    coin   = newW.cmbMoneda.SelectedIndex + 1;

                    String update = "update listadeprecios set nombre = '" + nombre + "', fecha = '" + fecha + "', anexo= '" + anexo + "', moneda='" + coin + "' 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();
                }


                ltsLpme.Items.Refresh();


                ltsLpme.SelectedIndex = modificado;
                ActualizaDGVlp();

                lblnombre.Content  = nombre;
                lblultimam.Content = hoy.ToString("yyyy/MM/dd");
                lbltienea.Content  = anexo;

                if (coin == 1)
                {
                    lblcoin.Content = "USD";
                }
                else if (coin == 2)
                {
                    lblcoin.Content = "EUROS";
                }
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Seleccione una Lista de precios a modificar", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }


            bandera = false;


            ActualizaDGVlp();
        }
Beispiel #3
0
        private void btnAgregar_Click(object sender, RoutedEventArgs e)
        {
            bandera = true;
            var    newW = new WindowAgregarLpme();
            string nombre;
            string anexo;

            newW.lblpreciolista.Visibility = Visibility.Collapsed;
            newW.txtPreciolista.Visibility = Visibility.Collapsed;
            newW.btnModpl.Visibility       = Visibility.Collapsed;
            newW.ShowDialog();
            int moneda;

            if (newW.DialogResult == true)
            {
                nombre = newW.txtNombre.Text;
                DateTime hoy;
                hoy = DateTime.Today;
                if (newW.txtAnexo.Text == "")
                {
                    anexo = "";
                }
                else
                {
                    anexo = newW.txtAnexo.Text;
                }


                if (newW.cmbMoneda.Text == "USD")
                {
                    moneda = 1;
                }
                else
                {
                    moneda = 2;
                }



                if (newW.txtAnexo.Text == "")
                {
                    String sql;
                    sql = "INSERT into listadeprecios(nombre, fecha,tipo,moneda) values('" + nombre + "', '" + hoy.ToString("yyyy/MM/dd") + "','" + 1 + "','" + moneda + "')";
                    conexion.operaciones(sql);
                }
                else
                {
                    String sql;
                    sql = "INSERT into listadeprecios(nombre, fecha,tipo,anexo,moneda) values('" + nombre + "', '" + hoy.ToString("yyyy/MM/dd") + "','" + 1 + "','" + anexo + "','" + moneda + "')";
                    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();
                ltsLpme.SelectedIndex = ltsLpme.Items.Count - 1;
                bandera = false;
                ActualizaDGVlp();
                MessageBox.Show("Se agrego la lista de precio correctamente", "Información", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                bandera = false;
            }
        }