private void gestionarCargaDatos(int codProducto, int codFactura) { try { var facturaActual = new FAC_FACTURA(); var detFacturaActual = new DEF_DETALLE_FACTURA(); var productoActual = new PRO_PRODUCTO(); productoActual.CodigoNumerico = codProducto; productoActual = objProd.ConsultarPorCodigoProducto(productoActual); facturaActual.NoFactura = codFactura; facturaActual = objFact.ConsultaPorNumeroDeFactura(facturaActual); detFacturaActual.idFactura = facturaActual.idFactura; detFacturaActual.idProducto = productoActual.IdProducto; detFacturaActual = objDeF.ConsultarPorIdFacturaYIdProducto(detFacturaActual); txtSaldoActual.Text = Session["SaldoActual"].ToString(); CargarTablaDetalleFacturas(facturaActual.idFactura, txtCriterio.Text); //poner en detalle un campo para ir descontando los productos escaneados cargarTablaFacturas(codFactura); } catch (Exception ex) { var err = ex.Message; } }
//private Excel objExcel = new Excel(); protected void Page_Load(object sender, EventArgs e) { if ((string)Session["username"] == "" || Session["username"] == null) { Response.Redirect("~/Default.aspx"); } else { List <string> pages = new List <string>(); pages = (List <string>)Session["paginas"]; if (!pages.Exists(x => string.Equals(x, "frmImprimirFacturas", StringComparison.OrdinalIgnoreCase))) { Response.Redirect("~/AccesoDenegado.aspx"); } } if (!IsPostBack) { cargarFacturas(); if (Session["Factura"].ToString() != "-1") { var tempFactura = new FAC_FACTURA(); tempFactura.NoFactura = Convert.ToInt32(Session["Factura"].ToString()); tempFactura = objFact.ConsultaPorNumeroDeFactura(tempFactura); ddlFacturas.SelectedValue = tempFactura.idFactura.ToString(); CargarTablaDetalleFacturas(tempFactura.idFactura); } else { CargarTablaDetalleFacturas(Convert.ToInt32(ddlFacturas.SelectedValue)); } } }
protected void btnCalcular_Click(object sender, EventArgs e) { try { var tempFactura = new FAC_FACTURA(); tempFactura.NoFactura = Convert.ToInt32(ddlFactura.SelectedValue); tempFactura = objFact.ConsultaPorNumeroDeFactura(tempFactura); var SaldoActual = tempFactura.saldo; var listaProductos = new List <PRO_PRODUCTO>(); var listaDetalles = new List <DEF_DETALLE_FACTURA>(); foreach (GridViewRow mRow in gvwDetalleFactura.Rows) { CheckBox mCheck = (CheckBox)mRow.FindControl("cbSelect"); if (mCheck != null) { if (mCheck.Checked) { var tempProducto = new PRO_PRODUCTO(); var tempCategoria = new CAT_CATEGORIA(); var splitProducto = mRow.Cells[0].Text.Split(','); var splitNombreProducto = splitProducto[0]; tempCategoria.Nombre = splitProducto[1].TrimStart(); tempCategoria = objCat.ConsultarPorNombreDeCategoria(tempCategoria); tempProducto.CodigoNumerico = Convert.ToInt32(mRow.Cells[1].Text); tempProducto.IdCategoria = tempCategoria.idCategoria; tempProducto.NombreProducto = splitNombreProducto; tempProducto = objProd.ConsultarProductoPorNombreCodigoCategoria(tempProducto); tempProducto.Inventario = tempProducto.Inventario + 1; SaldoActual = SaldoActual - tempProducto.Precio; txtSaldoActual.Text = SaldoActual.ToString(); Session["SaldoActual"] = SaldoActual; var tempDetalleFactura = new DEF_DETALLE_FACTURA(); tempDetalleFactura.idFactura = tempFactura.idFactura; tempDetalleFactura.idProducto = tempProducto.IdProducto; tempDetalleFactura = objDeF.ConsultarPorIdFacturaYIdProducto(tempDetalleFactura); tempDetalleFactura.CantidadDevuelta = tempDetalleFactura.CantidadDevuelta + 1; objProd.Actualizar(tempProducto); objDeF.Actualizar(tempDetalleFactura); } } } tempFactura.saldo = SaldoActual; tempFactura.estado = Convert.ToInt32(EstadoFacturas.Cancelada); tempFactura.totalDevuelto = tempFactura.saldo - SaldoActual; objFact.Actualizar(tempFactura); cargarTablaFacturas(tempFactura.NoFactura); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Factura cancelada con éxito, el monto a pagar es: " + SaldoActual + "')", true); } catch (Exception ex) { var err = ex.Message; throw ex; } }
private void actualizarFacturaLuegoDeBorrado(int noFactura, int idProducto, int cantidad) { var tempFactura = new FAC_FACTURA(); tempFactura.NoFactura = noFactura; tempFactura = objFact.ConsultaPorNumeroDeFactura(tempFactura); tempFactura.montoFactura = tempFactura.montoFactura - calcularMonto(idProducto, cantidad); tempFactura.totalPiezas = tempFactura.totalPiezas - cantidad; tempFactura.saldo = tempFactura.saldo - calcularMonto(idProducto, cantidad); objFact.Actualizar(tempFactura); }
private FAC_FACTURA actualizarDatosFactura(FAC_FACTURA factura) { DateTime fechaActual = DateTime.Today; var dia = Convert.ToInt32(fechaActual.Day.ToString()); var mes = Convert.ToInt32(fechaActual.Month.ToString()); var año = Convert.ToInt32(fechaActual.Year.ToString()); DateTime fechaCreacion = new DateTime(año, mes, dia); factura.estado = Convert.ToInt32(EstadoFacturas.Finalizada); factura.fechaCreacion = fechaCreacion; factura.fechaLiquidacion = fechaCreacion.AddDays(50); factura.idUsuario = Convert.ToInt32(Session["userId"]); var actulizado = objFact.Actualizar(factura); return(actulizado); }
private void actualizarFacturaYaInsertada(int idFactura, int cantidad, int idProducto) { var tempFactura = new FAC_FACTURA(); tempFactura.idFactura = idFactura; tempFactura = objFact.ConsultarPorId(tempFactura).FirstOrDefault(); var fechaCrea = CreacionDeFechaDesdeElTxtFecha(); tempFactura.montoFactura = tempFactura.montoFactura + calcularMonto(idProducto, cantidad); tempFactura.saldo = tempFactura.montoFactura; tempFactura.fechaCreacion = fechaCrea; tempFactura.fechaLiquidacion = fechaCrea.AddDays(50); tempFactura.totalDevuelto = 0; tempFactura.totalPiezas = tempFactura.totalPiezas + cantidad; tempFactura = objFact.Actualizar(tempFactura); }
protected void btnCalcularSaldo_Click(object sender, EventArgs e) { try { var tempFactura = new FAC_FACTURA(); tempFactura.NoFactura = Convert.ToInt32(ddlFactura.SelectedValue); tempFactura = objFact.ConsultaPorNumeroDeFactura(tempFactura); var SaldoActual = tempFactura.saldo; foreach (GridViewRow mRow in gvwDetalleFactura.Rows) { CheckBox mCheck = (CheckBox)mRow.FindControl("cbSelect"); if (mCheck != null) { if (mCheck.Checked) { var tempProducto = new PRO_PRODUCTO(); var tempCategoria = new CAT_CATEGORIA(); var splitProducto = mRow.Cells[0].Text.Split(','); var splitNombreProducto = splitProducto[0]; tempCategoria.Nombre = splitProducto[1].TrimStart(); tempCategoria = objCat.ConsultarPorNombreDeCategoria(tempCategoria); tempProducto.CodigoNumerico = Convert.ToInt32(mRow.Cells[1].Text); tempProducto.IdCategoria = tempCategoria.idCategoria; tempProducto.NombreProducto = splitNombreProducto; tempProducto = objProd.ConsultarProductoPorNombreCodigoCategoria(tempProducto); tempProducto.Inventario = tempProducto.Inventario + 1; SaldoActual = SaldoActual - tempProducto.Precio; txtSaldoActual.Text = SaldoActual.ToString(); Session["SaldoActual"] = SaldoActual; //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('" + mRow.Cells[2].Text + "')", true); } } } } catch (Exception ex) { var err = ex.Message; throw ex; } }
private void cargarTablaFacturas(int codFactura) { try { var facturaActual = new FAC_FACTURA(); facturaActual.NoFactura = codFactura; var dt = new DataTable(); var row = objFact.ConsultaPorNumeroDeFactura(facturaActual); dt.Columns.Add("idFactura", typeof(System.String)); dt.Columns.Add("NoFactura", typeof(System.String)); dt.Columns.Add("montoFactura", typeof(System.String)); dt.Columns.Add("saldo", typeof(System.String)); dt.Columns.Add("estado", typeof(System.String)); dt.Columns.Add("totalPiezas", typeof(System.String)); dt.Columns.Add("idCliente", typeof(System.String)); //dt.Columns.Add("fechaCreacion", typeof(System.String)); //dt.Columns.Add("fechaLiquidacion", typeof(System.String)); DataRow fila = dt.NewRow(); var tempCliente = new CLI_CLIENTES(); tempCliente.idCliente = row.idCliente; tempCliente = objCli.ConsultarPorIdCliente(tempCliente); fila["idFactura"] = row.idFactura; fila["NoFactura"] = row.NoFactura; fila["montoFactura"] = row.montoFactura; fila["saldo"] = row.saldo; fila["estado"] = EstadoFacturaEnLetras(row.estado); fila["totalPiezas"] = row.totalPiezas; fila["idCliente"] = tempCliente.NombreEncargado; //fila["fechaCreacion"] = r.fechaCreacion; //fila["fechaLiquidacion"] = r.fechaLiquidacion; dt.Rows.Add(fila); gvwFacturas.DataSource = dt; gvwFacturas.DataBind(); } catch (Exception ex) { var err = ex.Message; } }
private void gestionarCargaDatos(int codFactura) { try { var facturaActual = new FAC_FACTURA(); var detFacturaActual = new DEF_DETALLE_FACTURA(); facturaActual.NoFactura = codFactura; facturaActual = objFact.ConsultaPorNumeroDeFactura(facturaActual); CargarTablaDetalleFacturas(facturaActual.idFactura, txtCriterio.Text); txtSaldoActual.Text = facturaActual.saldo.ToString(); //poner en detalle un campo para ir descontando los productos escaneados Session["SaldoActual"] = facturaActual.saldo.ToString(); cargarTablaFacturas(codFactura); } catch (Exception ex) { var err = ex.Message; } }
public int guardarFactura() { var nuevaFactura = new FAC_FACTURA(); var fechaCreacion = CreacionDeFechaDesdeElTxtFecha(); nuevaFactura.CodTabla = txtCodFactura.Text; nuevaFactura.estado = Convert.ToInt32(EstadoFacturas.EnCreacion); nuevaFactura.idCliente = Convert.ToInt32(ddlCliente.SelectedValue); nuevaFactura.montoFactura = calcularMonto(Convert.ToInt32(ddlProducto.SelectedValue), Convert.ToInt32(txtCantidad.Text)); nuevaFactura.NoFactura = Convert.ToInt32(txtCodFactura.Text); nuevaFactura.fechaCreacion = fechaCreacion; nuevaFactura.fechaLiquidacion = fechaCreacion.AddDays(50); nuevaFactura.saldo = nuevaFactura.montoFactura; nuevaFactura.totalDevuelto = 0; nuevaFactura.totalPiezas = Convert.ToInt32(txtCantidad.Text); nuevaFactura.idCategoriaMetal = Convert.ToInt32(ddlMetal.SelectedValue); nuevaFactura.idUsuario = Convert.ToInt32(Session["userId"]); nuevaFactura = objFact.Insertar(nuevaFactura); return(nuevaFactura.idFactura); }
protected void gvwFacturas_SelectedIndexChanged(object sender, EventArgs e) { hdfIdFactura.Value = gvwFacturas.SelectedRow.Cells[0].Text; //txtCodTabla.Text = gvwFacturas.SelectedRow.Cells[2].Text; txtCodFactura.Text = gvwFacturas.SelectedRow.Cells[1].Text; var tempFactura = new FAC_FACTURA(); tempFactura.NoFactura = Convert.ToInt32(gvwFacturas.SelectedRow.Cells[1].Text); tempFactura = objFact.ConsultaPorNumeroDeFactura(tempFactura); txtFechaFactura.Text = tempFactura.fechaCreacion.ToShortDateString(); ddlMetal.SelectedValue = tempFactura.idCategoriaMetal.ToString(); var tempCliente = new CLI_CLIENTES(); tempCliente.NombreEncargado = gvwFacturas.SelectedRow.Cells[5].Text; tempCliente = objCli.ConsultarPorNombre(tempCliente).FirstOrDefault(); ddlCliente.SelectedValue = tempCliente.idCliente.ToString(); CargarTablaDetalleFacturas(Convert.ToInt32(hdfIdFactura.Value)); cargarProductosPorIdCategoria(tempFactura.idCategoriaMetal); DynamicHyperLink1.Visible = false; DynamicHyperLink1.NavigateUrl = "~/ExcelFacturas/000Machote.xls"; }
protected void btnImprimir_Click(object sender, EventArgs e) { //var rows = objDeF.Consultar(); var metal = ""; var contadorDeFilas = 0; var rows = objDeF.ConsultarPorIdFactura(Convert.ToInt32(ddlFacturas.SelectedValue), ""); var datosDeLaFactura = new FAC_FACTURA(); var tempCategoria = new CAT_CATEGORIA(); datosDeLaFactura.idFactura = Convert.ToInt32(ddlFacturas.SelectedValue); datosDeLaFactura = objFact.ConsultarPorId(datosDeLaFactura).FirstOrDefault(); tempCategoria.idCategoria = datosDeLaFactura.idCategoriaMetal; tempCategoria = objCateg.ConsultarPorId(tempCategoria).FirstOrDefault(); metal = tempCategoria.Nombre; llenaArregloConCeros(); // Recorrer las filas. foreach (Vista_ProductosPorDetalleFactura r in rows) { //// Crear una fila por cada unidad del producto. var tempProducto = new PRO_PRODUCTO(); tempProducto.IdProducto = r.idProducto; tempProducto = objProd.ConsultarPorId(tempProducto).FirstOrDefault(); arregloTemporal[contadorDeFilas, 0] = tempProducto.NombreProducto; arregloTemporal[contadorDeFilas, 1] = tempProducto.CodigoNumerico.ToString(); arregloTemporal[contadorDeFilas, 2] = r.CantidadProducto.ToString(); contadorDeFilas++; } contadorDeFilas = 0; //string sFile = "C:\\joyeriaSYS\\joyeriaSYS\\ExcelFacturas\\000Machote.xls"; string sFile = "C:\\inetpub\\wwwroot\\joyeriasys\\ExcelFacturas\\000Machote.xls"; //string sTemplate = "C:\\Template.xls"; object opc = Type.Missing; var excelApp = new Excel.Application(); excelApp.DisplayAlerts = false; // Make the object visible. //excelApp.Visible = true; //var excelBook = new Excel.Workbook(); //var excelSheet = new Excel.Worksheet(); var excelBook = excelApp.Workbooks.Open(sFile, opc, opc, opc, opc, opc, opc, opc, opc, opc, opc, opc, opc, opc, opc); var excelSheet = (Excel.Worksheet)excelBook.Sheets.get_Item(1); try { //Ponemos la fecha actual, el vendedor y el metal respectivamente. excelSheet.Cells[3, 5] = DateTime.Now.Date; excelSheet.Cells[5, 3] = txtNombreVendedor.Text; excelSheet.Cells[6, 3] = metal; //Ponemos la descripci+on del producto. for (int i = 8; i < 43; i++) { excelSheet.Cells[i, 2] = arregloTemporal[contadorDeFilas, 0].ToString(); excelSheet.Cells[i, 3] = arregloTemporal[contadorDeFilas, 1].ToString(); excelSheet.Cells[i, 4] = arregloTemporal[contadorDeFilas, 2].ToString(); contadorDeFilas++; } excelSheet.Cells[46, 2] = datosDeLaFactura.montoFactura; excelSheet.Cells[47, 3] = datosDeLaFactura.totalPiezas; excelSheet.Cells[48, 3] = DateTime.Now.Date.AddDays(50); excelSheet.SaveAs("C:\\inetpub\\wwwroot\\joyeriasys\\ExcelFacturas\\" + datosDeLaFactura.NoFactura + ".xls", Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing, true, false, Excel.XlSaveAsAccessMode.xlNoChange, Excel.XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing); //excelSheet.SaveAs("C:\\joyeriaSYS\\joyeriaSYS\\ExcelFacturas\\" + datosDeLaFactura.NoFactura + ".xls", Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, opc, opc, true, false, Excel.XlSaveAsAccessMode.xlNoChange, Excel.XlSaveConflictResolution.xlLocalSessionChanges, opc, opc); //excelApp.Visible = true; //excelSheet.PrintOut(); //Marshal.FinalReleaseComObject(excelSheet); excelBook.Close(); excelApp.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(excelBook); System.Runtime.InteropServices.Marshal.ReleaseComObject(excelSheet); System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp); string _open = "window.open('/ExcelFacturas/" + datosDeLaFactura.NoFactura + ".xls', '_newtab');"; ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), _open, true); //btnImprimir.PostBackUrl = "198.38.93.222/ExcelFacturas/"+ datosDeLaFactura.NoFactura +".xls"; //MostrarMensaje("Excel creado"); excelBook = null; excelSheet = null; excelApp = null; System.GC.Collect(); }catch (Exception ex) { Console.Error.Write(ex.Message); excelBook.Close(); excelApp.Quit(); } }
private void CargarTablaDetalleFacturas(int idFactura) { try { var dt = new DataTable(); //var rows = objDeF.Consultar(); gvwDetalleFactura.DataSource = null; gvwDetalleFactura.DataBind(); dt.Columns.Add("idDetalleFactura", typeof(System.String)); dt.Columns.Add("idFactura", typeof(System.String)); dt.Columns.Add("idProducto", typeof(System.String)); dt.Columns.Add("CodProducto", typeof(System.String)); dt.Columns.Add("idCategoria", typeof(System.String)); dt.Columns.Add("CantidadProducto", typeof(System.String)); if (idFactura != -1) { //var rows = objDeF.ConsultarPorIdFactura(idFactura, txtCriterio.Text); var tempDetalleFactura = new DEF_DETALLE_FACTURA(); tempDetalleFactura.idFactura = idFactura; var rows = objDeF.ConsultarDetalleFacturaPorIdFactura(tempDetalleFactura); foreach (DEF_DETALLE_FACTURA r in rows) { var tempCategoria = new CAT_CATEGORIA(); var tempProducto = new PRO_PRODUCTO(); var tempFactura = new FAC_FACTURA(); tempFactura.idFactura = r.idFactura; tempFactura = objFact.ConsultarPorId(tempFactura).FirstOrDefault(); tempProducto.IdProducto = r.idProducto; tempProducto = objProd.ConsultarPorId(tempProducto).FirstOrDefault(); tempCategoria.idCategoria = tempProducto.IdCategoria; DataRow fila = dt.NewRow(); fila["idDetalleFactura"] = r.idDetalleFactura; fila["idFactura"] = tempFactura.NoFactura; fila["idProducto"] = tempProducto.NombreProducto; fila["CodProducto"] = tempProducto.CodigoNumerico; fila["idCategoria"] = objCat.ConsultarPorId(tempCategoria).FirstOrDefault().Nombre; fila["CantidadProducto"] = r.CantidadProducto; dt.Rows.Add(fila); } } else { DataRow fila = dt.NewRow(); fila["idDetalleFactura"] = "---"; fila["idFactura"] = "---"; fila["idProducto"] = "---"; fila["CodProducto"] = "---"; fila["idCategoria"] = "---"; fila["CantidadProducto"] = "---"; dt.Rows.Add(fila); } var estadoFactura = new FAC_FACTURA(); estadoFactura.idFactura = idFactura; estadoFactura = objFact.ConsultarPorId(estadoFactura).FirstOrDefault(); if (estadoFactura.estado == Convert.ToInt32(EstadoFacturas.EnCreacion)) { this.gvwDetalleFactura.Columns[6].Visible = true; } else { this.gvwDetalleFactura.Columns[6].Visible = false; } gvwDetalleFactura.DataSource = dt; gvwDetalleFactura.DataBind(); } catch (Exception ex) { var err = ex.Message; } }