private void frmPrincipal_FormClosing(object sender, FormClosingEventArgs e)
 {
     try
     {
         if (agregarVenta.HayProductos)
         {
             DialogResult confirmacion = MessageBox.Show(this, "¿Desea guardar la venta actual?\n", "Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
             if (confirmacion == DialogResult.Yes)
             {
                 GuardarVenta.Guardar(agregarVenta.Guardar());
             }
             else
             {
                 agregarVenta.Cancelar();
             }
         }
         else if (File.Exists(Application.StartupPath + "\\Maxima_Distribuidores_VS.xml"))
         {
             File.Delete(Application.StartupPath + "\\Maxima_Distribuidores_VS.xml");
         }
         Directory.Delete(Application.StartupPath + "\\corte\\", true);
         Directory.Delete(Application.StartupPath + "\\reportes\\", true);
     }
     catch (Exception) { }
     Usuario.DestruirInstancia();
 }
示例#2
0
        public void Recuperar()
        {
            if (File.Exists(Application.StartupPath + "\\Tostatronic_Venta.xml"))
            {
                try
                {
                    InformacionVenta informacionVenta = GuardarVenta.Leer();

                    List <string[]> listaCliente = Sql.BuscarDatos("SELECT id_cliente, rfc, nombres, apellido_paterno, id_tipo_cliente FROM clientes WHERE id_cliente = '" +
                                                                   informacionVenta.Id_cliente + "'");

                    id_cliente              = int.Parse(listaCliente[0][0]);
                    txtRfc.Text             = listaCliente[0][1];
                    txtNombre.Text          = listaCliente[0][2];
                    txtApellidoPaterno.Text = listaCliente[0][3];
                    tipoCliente             = int.Parse(listaCliente[0][4]);
                    ActivarVenta();

                    foreach (Producto producto in informacionVenta.Productos)
                    {
                        List <string[]> lista = Sql.BuscarDatos("SELECT * FROM productos WHERE codigo = '" +
                                                                producto.Id_producto + "'");
                        float descuentoTemp = Descuento(lista[0][0]);
                        float subTotalTemp  = producto.Cantidad * float.Parse(lista[0][7 - tipoCliente]);
                        dgvVentas.Rows.Add(new string[] { lista[0][0], lista[0][1],
                                                          producto.Cantidad.ToString(), lista[0][7 - tipoCliente],
                                                          (subTotalTemp - subTotalTemp * descuentoTemp / 100).ToString(), lista[0][2], descuentoTemp.ToString() });
                    }
                    Total();
                }
                catch (Exception) { }
            }
        }
示例#3
0
        public void GenerarCotizacion(Venta venta)
        {
            try
            {
                try
                {
                    List <string[]> listaCliente = Sql.BuscarDatos("SELECT id_cliente, rfc, nombres, apellido_paterno, id_tipo_cliente FROM clientes WHERE rfc = '" +
                                                                   venta.Cliente.rfc + "'");
                    id_cliente              = int.Parse(listaCliente[0][0]);
                    txtRfc.Text             = listaCliente[0][1];
                    txtNombre.Text          = listaCliente[0][2];
                    txtApellidoPaterno.Text = listaCliente[0][3];
                    tipoCliente             = int.Parse(listaCliente[0][4]);
                }
                catch (Exception)
                {
                    MessageBox.Show("La operación ha fallado porque el cliente ha sido eliminado.", "Error: Archivos corrompidos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                foreach (ProductoCompleto producto in venta.Productos)
                {
                    List <string[]> lista    = Sql.BuscarDatos("SELECT * FROM productos WHERE codigo = '" + producto.Codigo + "'");
                    float           cantidad = 0;
                    float.TryParse(lista[0][2], out cantidad);
                    if (cantidad > 0)
                    {
                        if (cantidad >= producto.Cantidad)
                        {
                            Sql.InsertarDatos("UPDATE productos SET existencia=" + (cantidad - producto.Cantidad) +
                                              " WHERE codigo = '" + producto.Codigo + "'");
                        }
                        float subtotal  = producto.Cantidad * producto.Precio;
                        float descuento = Descuento(lista[0][0]);
                        subtotal -= subtotal * descuento / 100;
                        dgvVentas.Rows.Add(new string[] { lista[0][0], lista[0][1], producto.Cantidad.ToString(),
                                                          producto.Precio.ToString(), subtotal.ToString(), (cantidad - producto.Cantidad).ToString(), descuento.ToString() });
                    }
                    else
                    {
                        MessageBox.Show("El producto: " + producto.Codigo + " ha sido eliminado o no tiene la cantidad necesaria para generarse",
                                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("No se pudo transladar la cotización", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            GuardarVenta.Guardar(Guardar());
            ActivarVenta();
            Total();
            MessageBox.Show("Se ha convertido esta cotización a venta.\nEn caso de ya no requerirla eliminela.", "Exito en la conversión", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
示例#4
0
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            List <string[]> listaEliminar = new List <string[]>();

            for (int i = 0; i < dgvVentas.RowCount; i++)
            {
                if (bool.Parse(dgvVentas.Rows[i].Cells["seleccionador"].EditedFormattedValue.ToString()))
                {
                    listaEliminar.Add(new string[4] {
                        dgvVentas.Rows[i].Cells["codigo"].Value.ToString(),
                        dgvVentas.Rows[i].Cells["descripcion"].Value.ToString(), dgvVentas.Rows[i].Cells["cantidad"].Value.ToString(),
                        dgvVentas.Rows[i].Cells["existencia"].Value.ToString()
                    });
                }
            }
            if (listaEliminar.Count > 0)
            {
                string mensajeConfirmacion = "";
                foreach (string[] datos in listaEliminar)
                {
                    mensajeConfirmacion += datos[0] + "\n";
                }
                DialogResult confirmacion = MessageBox.Show(this, "¿Esta seguro que desea eliminar " + "estos productos de la venta? \nListado: \n" +
                                                            mensajeConfirmacion, "Confirmacion", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (confirmacion == DialogResult.Yes)
                {
                    foreach (string[] datos in listaEliminar)
                    {
                        Sql.InsertarDatos("UPDATE productos SET existencia ='" + (float.Parse(datos[2]) + float.Parse(datos[3])) + "' WHERE codigo = '" + datos[0] + "'");
                    }
                    for (int i = 0; i < dgvVentas.RowCount; i++)
                    {
                        if (bool.Parse(dgvVentas.Rows[i].Cells["seleccionador"].EditedFormattedValue.ToString()))
                        {
                            dgvVentas.Rows.RemoveAt(i);
                            i--;
                        }
                    }
                    MessageBox.Show("Eliminados");
                    Buscador("SELECT  codigo, nombre, existencia FROM productos " +
                             "WHERE codigo LIKE '%" + buscador + "%' OR nombre LIKE '%" + buscador + "%'");
                    Total();
                    GuardarVenta.Guardar(Guardar());
                }
            }
            else
            {
                MessageBox.Show("Seleccione al menos un producto a eliminar.");
            }
        }
示例#5
0
        private void dgvProductos_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                List <string[]> lista = Sql.BuscarDatos("SELECT * FROM productos WHERE codigo = '" +
                                                        ValorCelda(dgvProductos, e.RowIndex, "clmCodigo") + "'");

                dialogCantidad frmCantidad = new dialogCantidad(lista[0][0] + " (" + lista[0][1] + ")", Decimal.Parse(lista[0][2]), float.Parse(lista[0][7 - tipoCliente]), Descuento(lista[0][0]));
                frmCantidad.ShowDialog();
                if (frmCantidad.Cantidad > 0)
                {
                    decimal cantidad = Decimal.Parse(lista[0][2]) - frmCantidad.Cantidad;
                    float   subtotal;
                    subtotal  = (float)frmCantidad.Cantidad * float.Parse(lista[0][7 - tipoCliente]);
                    subtotal -= subtotal * Descuento(lista[0][0]) / 100;
                    Sql.InsertarDatos("UPDATE productos SET existencia ='" + cantidad +
                                      "' WHERE codigo = '" + lista[0][0] + "'");

                    dgvProductos.Rows[e.RowIndex].Cells["clmCantidad"].Value = decimal.Parse(dgvProductos.Rows[e.RowIndex].Cells["clmCantidad"].Value.ToString()) - frmCantidad.Cantidad;

                    for (int i = 0; i < dgvVentas.RowCount; i++)
                    {
                        if (dgvVentas.Rows[i].Cells["codigo"].Value.ToString() == lista[0][0])
                        {
                            dgvVentas.Rows[i].Cells["cantidad"].Value = decimal.Parse(dgvVentas.Rows[i].Cells["cantidad"].Value.ToString()) + frmCantidad.Cantidad;
                            subtotal = float.Parse(dgvVentas.Rows[i].Cells["cantidad"].Value.ToString()) * float.Parse(dgvVentas.Rows[i].Cells["precio"].Value.ToString());
                            dgvVentas.Rows[i].Cells["existencia"].Value = decimal.Parse(dgvVentas.Rows[i].Cells["existencia"].Value.ToString()) - frmCantidad.Cantidad;
                            dgvVentas.Rows[i].Cells["subtotal"].Value   = subtotal - subtotal * Descuento(lista[0][0]) / 100;
                            frmCantidad.Dispose();
                            GuardarVenta.Guardar(Guardar());
                            Total();
                            return;
                        }
                    }
                    dgvVentas.Rows.Add(new string[] { lista[0][0], lista[0][1], frmCantidad.Cantidad.ToString(),
                                                      lista[0][7 - tipoCliente], subtotal.ToString(), cantidad.ToString(), Descuento(lista[0][0]).ToString() });
                    GuardarVenta.Guardar(Guardar());
                    Total();
                }
                frmCantidad.Dispose();
            }
            catch (Exception) { }
        }
示例#6
0
 private void dgvVentas_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == 3)
     {
         string codigo   = ValorCelda(e.RowIndex, "codigo");
         float  minPrice = float.Parse(Sql.BuscarDatos("SELECT precio_minimo FROM productos WHERE codigo = '" + codigo + "';")[0][0]);
         if (float.Parse(ValorCelda(e.RowIndex, "precio")) < minPrice)
         {
             dgvVentas.Rows[e.RowIndex].Cells[3].ErrorText = "El precio minimo es de: " + minPrice.ToString();
             dgvVentas.Rows[e.RowIndex].Cells[3].Value     = ValorAnterior(codigo).ToString();
         }
         else
         {
             float sub = float.Parse(dgvVentas.Rows[e.RowIndex].Cells[3].Value.ToString());
             sub *= float.Parse(dgvVentas.Rows[e.RowIndex].Cells[2].Value.ToString());
             sub -= sub * Descuento(codigo) / 100;
             dgvVentas.Rows[e.RowIndex].Cells[4].Value = sub;
             Total();
             GuardarVenta.Guardar(Guardar());
             dgvVentas.Rows[e.RowIndex].Cells[3].ErrorText = "";
         }
     }
 }