Example #1
0
        private void CargarTablaFacturas(string criterio)
        {
            try
            {
                var dt   = new DataTable();
                var rows = objFact.ConsultarPorNoFactura(criterio);

                dt.Columns.Add("idFactura", typeof(System.String));
                dt.Columns.Add("NoFactura", typeof(System.String));
                //dt.Columns.Add("CodTabla", typeof(System.String));
                dt.Columns.Add("montoFactura", 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("idTipoMetal", typeof(System.String));
                dt.Columns.Add("nombreUsuario", typeof(System.String));
                //dt.Columns.Add("fechaCreacion", typeof(System.String));
                //dt.Columns.Add("fechaLiquidacion", typeof(System.String));

                foreach (FAC_FACTURA r in rows)
                {
                    var tempCliente   = new CLI_CLIENTES();
                    var tempCategoria = new CAT_CATEGORIA();
                    tempCliente.idCliente     = r.idCliente;
                    tempCliente               = objCli.ConsultarPorId(tempCliente).FirstOrDefault();
                    tempCategoria.idCategoria = r.idCategoriaMetal;
                    tempCategoria             = objCat.ConsultarPorIdCategoria(tempCategoria);

                    DataRow fila = dt.NewRow();

                    fila["idFactura"] = r.idFactura;
                    fila["NoFactura"] = r.NoFactura;
                    //fila["CodTabla"] = r.CodTabla;
                    fila["montoFactura"]  = r.montoFactura;
                    fila["estado"]        = EstadoFacturaEnLetras(r.estado);
                    fila["totalPiezas"]   = r.totalPiezas;
                    fila["idCliente"]     = tempCliente.NombreEncargado;
                    fila["idTipoMetal"]   = tempCategoria.Nombre;
                    fila["nombreUsuario"] = obtenerNombreUsuarioPorId(r.idUsuario);
                    //fila["fechaCreacion"] = r.fechaCreacion;
                    //fila["fechaLiquidacion"] = r.fechaLiquidacion;
                    dt.Rows.Add(fila);
                }
                gvwFacturas.DataSource = dt;
                gvwFacturas.DataBind();
            }
            catch (Exception ex)
            {
                var err = ex.Message;
            }
        }
Example #2
0
        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;
            }
        }
Example #3
0
        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";
        }
Example #4
0
        public int guardarActualizar(int id)
        {
            CLI_CLIENTES temp = new CLI_CLIENTES();

            temp.idCliente       = id;
            temp.NombreEncargado = txtNombreEncargado.Text;
            temp.NombreJoyeria   = txtNombreEncargado.Text;
            temp.Provincia       = txtProvincia.Text;
            temp.Telefono        = txtTelefono.Text;
            temp.Celular         = txtCelular.Text;
            temp.Direccion       = txtDirección.Text;
            temp.Canton          = txtCanton.Text;

            if (objCli.ConsultarPorId(temp).Count() > 0)
            {
                objCli.Actualizar(temp);
            }
            else
            {
                objCli.Insertar(temp);
            }
            return(1);
        }
Example #5
0
        protected void btnFinalizarLaFactura_Click(object sender, EventArgs e)
        {
            //var rows = objDeF.Consultar();
            if (hdfIdFactura.Value == "-1")
            {
                //No imprime nada
                DynamicHyperLink1.Visible = false;
            }
            else
            {
                var metal            = "";
                var contadorDeFilas  = 0;
                var rows             = objDeF.ConsultarPorIdFactura(Convert.ToInt32(hdfIdFactura.Value), txtCriterio.Text);
                var datosDeLaFactura = new FAC_FACTURA();
                var tempCategoria    = new CAT_CATEGORIA();
                var fechaCreacion    = CreacionDeFechaDesdeElTxtFecha();

                datosDeLaFactura.idFactura = Convert.ToInt32(hdfIdFactura.Value);

                // obteber el objeto
                datosDeLaFactura = objFact.ConsultarPorId(datosDeLaFactura).FirstOrDefault();

                // actulizar el estado de la factura
                if (datosDeLaFactura.estado == Convert.ToInt32(EstadoFacturas.EnCreacion))
                {
                    datosDeLaFactura = actualizarDatosFactura(datosDeLaFactura);
                }

                tempCategoria.idCategoria = datosDeLaFactura.idCategoriaMetal;
                tempCategoria             = objCat.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
                {
                    var tempCliente = new CLI_CLIENTES();
                    tempCliente.idCliente = Convert.ToInt32(ddlCliente.SelectedValue);
                    tempCliente           = objCli.ConsultarPorIdCliente(tempCliente);
                    //Ponemos la fecha actual, el vendedor y el metal respectivamente.
                    excelSheet.Cells[3, 5] = fechaCreacion;
                    excelSheet.Cells[5, 3] = tempCliente.NombreEncargado;
                    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] = fechaCreacion.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);

                    DynamicHyperLink1.NavigateUrl = "~/ExcelFacturas/" + datosDeLaFactura.NoFactura + ".xls";
                    DynamicHyperLink1.Visible     = true;
                    //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();
                }
            }//Fin else
        }