Exemple #1
0
        private void btnAgregar_Click(object sender, RoutedEventArgs e)
        {
            var moneda = new windowMonedaOC();

            moneda.ShowDialog();
            if (moneda.DialogResult == true)
            {
                var newW = new windowAgregarOC(moneda.moneda);
                if (newW.existeProveedor)
                {
                    newW.ShowDialog();



                    if (newW.DialogResult == true && !newW.agregado)
                    {
                        //INSERTAR OC
                        int Proveedor = (int)newW.cmbProveedores.SelectedValue;
                        Console.WriteLine(Proveedor);
                        DateTime fecha = newW.fecha;
                        fecha = Convert.ToDateTime(fecha.ToString("yyyy/MM/dd"));
                        Console.WriteLine(fecha);
                        String subtotal    = newW.txtSubtotal.Text;
                        String total       = newW.txtTotal.Text;
                        int    direccion   = (int)newW.cmbDireccion.SelectedValue;
                        int    telefono    = (int)newW.cmbTelefono.SelectedValue;
                        String observacion = newW.txtObservaciones.Text;
                        String formaPago   = newW.txtFormaPago.Text;
                        int    iva         = newW.cmbIVA.SelectedIndex;
                        int    tipoCambio  = newW.cmbTipoCambio.SelectedIndex;
                        String cotizacion  = newW.txtCotizacion.Text;
                        String sql         = "insert into ordencompra(fecha, observaciones, subtotal, total, iva, tipoCambio ,formaPago, FK_idContacto,FK_idDireccion,FK_idProveedor,cotizacion) values( '" + fecha.ToString("yyyy/MM/dd") + "', '" + observacion + "', '" + subtotal.Replace(",", ".") + "', '" + total.Replace(",", ".") + "', '" + iva + "','" + tipoCambio + "','" + formaPago + "','" + telefono + "','" + direccion + "','" + Proveedor + "','" + cotizacion + "')"; conexion.operaciones(sql);
                        string ultimoId    = "Select last_insert_id()";
                        String id          = conexion.ValorEnVariable(ultimoId);
                        foreach (var producto in newW.productos)
                        {
                            String productos = "insert into productos_has_ordencompra(cantidad, subtotal, Crfactura, CrRemito, FK_idProducto, FK_idOC,PUPagado) values( '" + producto.cantidad + "', '" + producto.total.ToString().Replace(",", ".") + "', '" + producto.cantidad + "', '" + producto.cantidad + "', '" + producto.id + "','" + id + "','" + producto.precioUnitario.ToString().Replace(",", ".") + "');"; conexion.operaciones(productos);
                        }
                        MessageBox.Show("Se agregó la orden de compra correctamente", "Información", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    ejecutar = false;
                    loadlistaOC();
                    LoadListaComboProveedor();
                    ltsNumeroOC.Items.MoveCurrentToLast();
                    ejecutar = true;
                    seleccioneParaFiltrar();
                }
            }
        }
Exemple #2
0
        private void btnModificar_Copy_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int    idOC          = (int)ltsNumeroOC.SelectedValue;
                int    index         = (int)ltsNumeroOC.SelectedIndex;
                string existeRemito  = "select count(idremitos) from remito where FK_idOC = " + idOC + " ";
                string existeFactura = "select count(idFacturas) from factura where FK_idOC = " + idOC + " ";

                if (conexion.ValorEnVariable(existeRemito) == "0" && conexion.ValorEnVariable(existeFactura) == "0")
                {
                    //VALORES NECESARIOS PARA LLENAR CONSTRUCTOR
                    String    consulta      = "SELECT * FROM ordencompra where idOrdenCompra = @valor";
                    DataTable OC            = conexion.ConsultaParametrizada(consulta, ltsNumeroOC.SelectedValue);
                    DateTime  fecha         = (DateTime)OC.Rows[0].ItemArray[1];
                    String    observaciones = OC.Rows[0].ItemArray[2].ToString();
                    String    subtotal      = OC.Rows[0].ItemArray[3].ToString();
                    String    total         = OC.Rows[0].ItemArray[4].ToString();
                    int       iva           = (int)OC.Rows[0].ItemArray[5];
                    int       tipoCambio    = (int)OC.Rows[0].ItemArray[6];
                    String    formaPago     = OC.Rows[0].ItemArray[7].ToString();
                    int       telefono      = (int)OC.Rows[0].ItemArray[8];
                    int       proveedor     = (int)OC.Rows[0].ItemArray[10];
                    int       direccion     = (int)OC.Rows[0].ItemArray[9];
                    float     cotizacion    = (float)OC.Rows[0].ItemArray[12];

                    //PRODUCTOS DE LA ORDEN DE COMPRA
                    String          consultaProductos = "SELECT t2.idProductos, t1.cantidad ,t1.subtotal,t2.nombre,t1.PUPagado FROM productos_has_ordencompra t1 inner join productos t2 where FK_idOC = @valor and t1.FK_idProducto = t2.idProductos";
                    DataTable       productos         = conexion.ConsultaParametrizada(consultaProductos, ltsNumeroOC.SelectedValue);
                    List <Producto> listaProd         = new List <Producto>();


                    for (int i = 0; i < productos.Rows.Count; i++)
                    {
                        int    idProducto = (int)productos.Rows[i].ItemArray[0];
                        int    cantitad   = (int)productos.Rows[i].ItemArray[1];
                        float  sub        = (float)productos.Rows[i].ItemArray[2];
                        String nombre     = productos.Rows[i].ItemArray[3].ToString();
                        float  PU         = (float)productos.Rows[i].ItemArray[4];
                        listaProd.Add(new Producto(nombre, idProducto, cantitad, sub, PU));
                    }
                    var newW = new windowAgregarOC(fecha, observaciones, subtotal, iva, tipoCambio, formaPago, telefono, proveedor, direccion, listaProd, idOC, cotizacion, total);

                    newW.Title = "Modificar OC";
                    newW.ShowDialog();

                    if (newW.DialogResult == true)
                    {
                        //INSERTAR OC
                        int Proveedor = (int)newW.cmbProveedores.SelectedValue;
                        fecha = newW.fecha;
                        Console.WriteLine(fecha);
                        String sub = newW.txtSubtotal.Text;
                        total         = newW.txtTotal.Text;
                        direccion     = (int)newW.cmbDireccion.SelectedValue;
                        telefono      = (int)newW.cmbTelefono.SelectedValue;
                        observaciones = newW.txtObservaciones.Text;
                        formaPago     = newW.txtFormaPago.Text;
                        iva           = newW.cmbIVA.SelectedIndex;
                        tipoCambio    = newW.cmbTipoCambio.SelectedIndex;
                        String sql = "UPDATE ordencompra SET fecha = '" + fecha.ToString("yyyy/MM/dd") + "', observaciones = '" + observaciones + "' ,subtotal = '" + sub.Replace(",", ".") + "',total = '" + total.Replace(",", ".") + "',iva = '" + iva + "',tipoCambio = '" + tipoCambio + "',formaPago = '" + formaPago + "',FK_idContacto = '" + telefono + "',FK_idDireccion = '" + direccion + "',FK_idProveedor = '" + Proveedor + "' WHERE ordencompra.idOrdenCompra = '" + idOC + "';"; conexion.operaciones(sql);

                        //ELIMINA REGISTRO DE TABLA INTERMEDIA
                        string sql2 = "delete  from productos_has_ordencompra where FK_idOC =  '" + idOC + "'";
                        conexion.operaciones(sql2);


                        foreach (var producto in newW.productos)
                        {
                            //string CantidadAntigua = "select cantidad from productos_has_ordencompra where FK_idOC = '" + idOC + "' and FK_idProducto =  '" + producto.id + "'";
                            //int.TryParse(conexion.ValorEnVariable(CrRemito), out int CRR);
                            //CRR = producto.cantidad - CRR;
                            String productosActualizar = "insert into productos_has_ordencompra(cantidad, subtotal, Crfactura, CrRemito, FK_idProducto, FK_idOC, PUPagado) values( '" + producto.cantidad + "', '" + producto.total.ToString().Replace(",", ".") + "', '" + producto.cantidad + "', '" + producto.cantidad + "', '" + producto.id + "','" + idOC + "','" + producto.precioUnitario.ToString().Replace(",", ".") + "');"; conexion.operaciones(productosActualizar);
                        }
                        ejecutar = false;
                        loadlistaOC(index);
                        LoadListaComboProveedor();
                        ejecutar = true;
                    }
                }
                else
                {
                    MessageBox.Show("No se puede modificar una orden que tiene remitos o facturas", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Seleccione una orden a modificar", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }