public void CargarTablaVentas() { try { dgVentas.ItemsSource = null; DataTable tabla = new DataTable(); VentasNEG ventasNEG = new VentasNEG(); List <VentasVIEW> lista = ventasNEG.ListarTodasVentas(); tabla.Columns.Add("ID"); tabla.Columns.Add("FOLIO"); tabla.Columns.Add("TIPO VENTA"); tabla.Columns.Add("FECHA VENTA"); tabla.Columns.Add("SUCURSAL"); tabla.Columns.Add("EMPLEADO"); tabla.Columns.Add("CANTIDAD ART"); tabla.Columns.Add("MONTO_TOTAL"); tabla.Columns.Add("MONEDA"); tabla.Columns.Add("CLIENTE"); tabla.Columns.Add("ESTADO"); AnulacionVentaNEG anulacionVentaNEG = new AnulacionVentaNEG(); List <ANULACION_VENTA> ventaAnulada = anulacionVentaNEG.ListaVentasAnuladas(); if (lista.Count > 0) { foreach (var x in lista) { string folio = x.ID.ToString(); for (int i = 0; i < 9; i++) { if (folio.Length < 8) { folio = "0" + folio; } } string anulacion = "VIGENTE"; foreach (var ven in ventaAnulada) { if (ven.VENTAS_ID == x.ID) { anulacion = "ANULADA"; } } string cantidad = x.CANTIDAD_TOTAL.ToString(); string costo1 = string.Format("{0:n2}", x.MONTO_TOTAL); tabla.Rows.Add(x.ID, folio, x.TIPO_VENTA, x.FECHA_VENTA, x.NOMBRE_SUCURSAL, x.NOMBRE_EMPLEADO + " " + x.APELLIDO_EMPLEADO, cantidad, costo1, x.TIPO_MONEDA, x.NOMBRE_CLIENTE + " " + x.APELLID_CLIENTE, anulacion); } } dgVentas.ItemsSource = tabla.DefaultView; } catch (Exception ex) { MessageBox.Show("Error:\n" + ex.TargetSite + "\n" + ex.Message.ToString()); } }
private void btnBuscar_Click(object sender, RoutedEventArgs e) { try { if (dpkFechaDesde != null) { if (dpkFechaHasta != null) { if (dpkFechaDesde.SelectedDate <= dpkFechaHasta.SelectedDate) { dgVentas.ItemsSource = null; DataTable tabla = new DataTable(); VentasNEG ventasNEG = new VentasNEG(); DateTime desde = DateTime.Parse(dpkFechaDesde.SelectedDate.ToString()); DateTime _hasta = DateTime.Parse(dpkFechaHasta.SelectedDate.ToString()); DateTime hasta = new DateTime(_hasta.Year, _hasta.Month, _hasta.Day, 23, 59, 59); List <VentasVIEW> lista = ventasNEG.ListarVentasRangoFecha(desde, hasta); tabla.Columns.Add("ID"); tabla.Columns.Add("FOLIO"); tabla.Columns.Add("TIPO VENTA"); tabla.Columns.Add("FECHA VENTA"); tabla.Columns.Add("SUCURSAL"); tabla.Columns.Add("EMPLEADO"); tabla.Columns.Add("CANTIDAD ART"); tabla.Columns.Add("MONTO TOTAL"); tabla.Columns.Add("MONEDA"); tabla.Columns.Add("CLIENTE"); tabla.Columns.Add("ESTADO"); AnulacionVentaNEG anulacionVentaNEG = new AnulacionVentaNEG(); List <ANULACION_VENTA> ventaAnulada = anulacionVentaNEG.ListaVentasAnuladas(); if (lista.Count > 0) { foreach (var x in lista) { string folio = x.ID.ToString(); for (int i = 0; i < 9; i++) { if (folio.Length < 8) { folio = "0" + folio; } } string anulacion = "VIGENTE"; foreach (var ven in ventaAnulada) { if (ven.VENTAS_ID == x.ID) { anulacion = "ANULADA"; } } string cantidad = x.CANTIDAD_TOTAL.ToString(); string costo1 = string.Format("{0:n2}", x.MONTO_TOTAL); tabla.Rows.Add(x.ID, folio, x.TIPO_VENTA, x.FECHA_VENTA, x.NOMBRE_SUCURSAL, x.NOMBRE_EMPLEADO + " " + x.APELLIDO_EMPLEADO, cantidad, costo1, x.TIPO_MONEDA, x.NOMBRE_CLIENTE + " " + x.APELLID_CLIENTE, anulacion); } } dgVentas.ItemsSource = tabla.DefaultView; } else { MessageBox.Show("La fecha de término no puede ser menor a la de inicio"); } } else { MessageBox.Show("Debe indicar una fecha de fin del rango"); } } else { MessageBox.Show("Debe indicar una fecha de inicio del rango"); } } catch (Exception ex) { MessageBox.Show("Error:\n" + ex.TargetSite + "\n" + ex.Message.ToString()); } }
private void btnIngresar_Click(object sender, RoutedEventArgs e) { try { if (cbxSucursal.SelectedValue != null) { if (int.Parse(cbxSucursal.SelectedValue.ToString()) > 0) { if (cbxCliente.SelectedValue != null) { if (int.Parse(cbxCliente.SelectedValue.ToString()) > 0) { if (cbxTipoDocumento.SelectedValue != null) { if (int.Parse(cbxTipoDocumento.SelectedValue.ToString()) > 0) { if (cbxMoneda.SelectedValue != null) { if (int.Parse(cbxTipoDocumento.SelectedValue.ToString()) > 0) { if (cbxEmpleado.SelectedValue != null) { if (int.Parse(cbxEmpleado.SelectedValue.ToString()) > 0) { DataTable tabla = ((DataView)dgDetalleDocumento.ItemsSource).ToTable(); if (tabla.Rows.Count > 0) { MessageBox.Show("Espere mientras el documento es generado. Presione 'Aceptar para comenzar'"); int _idCliente = int.Parse(cbxCliente.SelectedValue.ToString()); int _sucursal = int.Parse(cbxSucursal.SelectedValue.ToString()); int _tipoDocumento = int.Parse(cbxTipoDocumento.SelectedValue.ToString()); DateTime _fechaDocumento = DateTime.Parse(dpkFechaCreacion.SelectedDate.ToString()); double _neto = double.Parse(txtNeto.Text); int _idEmpleado = int.Parse(cbxEmpleado.SelectedValue.ToString()); double _iva = double.Parse(txtIva.Text); double _total = double.Parse(txtTotal.Text); double _totalMoneda = double.Parse(txtTotalMoneda.Text); int _idMoneda = int.Parse(cbxTipoDocumento.SelectedValue.ToString()); List <DETALLE_VENTAS> listaDetalle = new List <DETALLE_VENTAS>(); int cantidadTotal = 0; string reservas = ""; foreach (DataRow fila in tabla.Rows) { DETALLE_VENTAS detalle = new DETALLE_VENTAS(); detalle.FECHA_CREACION = DateTime.Now; detalle.FECHA_ULTIMO_UPDATE = DateTime.Now; detalle.CANTIDAD = int.Parse(fila.ItemArray[0].ToString()); detalle.MONTO_TOTAL = int.Parse(fila.ItemArray[5].ToString()); detalle.NOMBRE_PRODUCTO = fila.ItemArray[3].ToString(); detalle.PRECIO_VENTA = Convert.ToDecimal(fila.ItemArray[4].ToString()); detalle.MULTI_MONEDA_ID = _idMoneda; if (fila.ItemArray[1].ToString() == "PRO") { detalle.PRODUCTO_ID = int.Parse(fila.ItemArray[2].ToString()); detalle.SERVICIO_ID = 1; } if (fila.ItemArray[1].ToString() == "SER") { detalle.PRODUCTO_ID = 1; detalle.SERVICIO_ID = int.Parse(fila.ItemArray[2].ToString()); } if (fila.ItemArray[1].ToString() == "OT") { detalle.PRODUCTO_ID = 1; detalle.SERVICIO_ID = 1; reservas = reservas + fila.ItemArray[2].ToString() + ";"; } listaDetalle.Add(detalle); cantidadTotal = cantidadTotal + int.Parse(detalle.CANTIDAD.ToString()); } VENTAS ventas = new VENTAS(); ventas.FECHA_CREACION = DateTime.Now; ventas.FECHA_ULTIMO_UPDATE = DateTime.Now; ventas.CANTIDAD_TOTAL = cantidadTotal; ventas.FECHA_VENTA = DateTime.Now; ventas.MONTO_TOTAL = Convert.ToDecimal(_total); ventas.CLIENTE_ID = _idCliente; ventas.EMPLEADO_ID = _idEmpleado; ventas.MULTI_MONEDA_ID = _idMoneda; ventas.SUCURSAL_ID = _sucursal; ventas.TIPO_VENTA_ID = _tipoDocumento; VentasNEG ventasNEG = new VentasNEG(); string respuesta = ventasNEG.EmitirVenta(ventas, listaDetalle, reservas); if (respuesta == "creado") { int idVenta = ventasNEG.ObtenerUtlimoIdVenta(); VentasDAL ventasDAL = new VentasDAL(); DatosDocumentoPagoVIEW datos = ventasDAL.CargarDatos(idVenta); datos.DETALLE_BOLETA = ventasDAL.ListarDetalleBoleta(idVenta); ExportarArchivos PDF = new ExportarArchivos(); string folio = datos.FOLIO.ToString(); for (int i = 0; i < 9; i++) { if (folio.Length < 8) { folio = "0" + folio; } } string rutaDcoc = PDF.DocumentoPagoPDF(datos, folio); ServerCorreo abrir_server = new ServerCorreo(); Correo correoM = new Correo(); SmtpClient server = abrir_server.InstanciaServer(); //Instancia la libreria que permite armar correo electronico y llama el metodo que lo crea MailMessage email = correoM.CorreoEnvioFactura(rutaDcoc, datos.CORREO_CLIENTE, datos.NOMBRE_CLIENTE + " " + datos.APELLIDO_CLIENTE, folio); //envia el correo server.Send(email); Limpiar(); MessageBox.Show("El documento ha sido generado correctamente. Se ha enviado una copia por correo al cliente y puede tambien buscar una copia del archivo en 'Mis Documentos'"); } } else { MessageBox.Show("Deben ingresar productos o servicios al documento"); } } else { MessageBox.Show("Debe seleccionar un empleado"); } } else { MessageBox.Show("Debe seleccionar un empleado"); } } else { MessageBox.Show("Debe seleccionar un tipo de documento"); } } else { MessageBox.Show("Debe seleccionar una moneda"); } } else { MessageBox.Show("Debe seleccionar un tipo de documento"); } } else { MessageBox.Show("Debe seleccionar un tipo de documento"); } } else { MessageBox.Show("Debe seleccionar un cliente"); } } else { MessageBox.Show("Debe seleccionar un cliente"); } } else { MessageBox.Show("Debe seleccionar una sucursal"); } } else { MessageBox.Show("Debe seleccionar una sucursal"); } } catch (Exception ex) { MessageBox.Show("Error:\n" + ex.TargetSite + "\n" + ex.Message.ToString()); } }