Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
        protected void gvwDetalleFactura_SelectedIndexChanged(object sender, EventArgs e)
        {
            var tempCategoria = new CAT_CATEGORIA();

            tempCategoria.Nombre = gvwDetalleFactura.SelectedRow.Cells[4].Text;
            tempCategoria        = objCat.ConsultarPorNombre(tempCategoria).FirstOrDefault();

            var tempProducto = new PRO_PRODUCTO();

            tempProducto.NombreProducto = gvwDetalleFactura.SelectedRow.Cells[2].Text;
            tempProducto.CodigoNumerico = Convert.ToInt32(gvwDetalleFactura.SelectedRow.Cells[3].Text);
            tempProducto.IdCategoria    = tempCategoria.idCategoria;
            tempProducto = objProd.ConsultarPorNombreCodigoCategoria(tempProducto).FirstOrDefault();

            hdfIdDetalleFactura.Value = gvwDetalleFactura.SelectedRow.Cells[0].Text;
            int noFactura   = Convert.ToInt32(gvwDetalleFactura.SelectedRow.Cells[1].Text);
            int idProducto  = tempProducto.IdProducto;
            int idCategoria = tempCategoria.idCategoria;
            int Cantidad    = Convert.ToInt32(gvwDetalleFactura.SelectedRow.Cells[5].Text);

            ddlProducto.SelectedValue = tempProducto.IdProducto.ToString();

            var detFac = new DEF_DETALLE_FACTURA();

            detFac.idDetalleFactura = Convert.ToInt32(hdfIdDetalleFactura.Value);
            actualizarFacturaLuegoDeBorrado(noFactura, idProducto, Cantidad);
            actualizarCantidadProducto(idProducto, Cantidad, false);
            objDeF.Eliminar(detFac);

            CargarTablaDetalleFacturas(Convert.ToInt32(hdfIdFactura.Value));
            CargarTablaFacturas(txtCriterio.Text);
        }
Ejemplo n.º 3
0
        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;
            }
        }
Ejemplo n.º 4
0
        private decimal calcularMonto(int idProducto, int cantidad)
        {
            var tempProd = new PRO_PRODUCTO();

            tempProd.IdProducto = idProducto;

            tempProd = objProd.ConsultarPorId(tempProd).FirstOrDefault();

            return(tempProd.Precio * cantidad);
        }
        private void CargarTablaDetalleFacturas(int idFactura)
        {
            try
            {
                var dt   = new System.Data.DataTable();
                var rows = objDeF.ConsultarPorIdFactura(-1, "");
                //var contadorDeFilas = 0;
                gvwDetalleFactura.DataSource = null;
                gvwDetalleFactura.DataBind();
                if (idFactura != -1)
                {
                    rows = objDeF.ConsultarPorIdFactura(idFactura, "");
                }

                dt.Columns.Add("categoria", typeof(System.String));
                dt.Columns.Add("idProducto", typeof(System.String));
                dt.Columns.Add("CantidadProducto", typeof(System.String));

                // Recorrer las filas.
                foreach (Vista_ProductosPorDetalleFactura r in rows)
                {
                    //// Crear una fila por cada unidad del producto.
                    var tempProducto  = new PRO_PRODUCTO();
                    var tempCategoria = new CAT_CATEGORIA();

                    tempProducto.IdProducto = r.idProducto;
                    tempProducto            = objProd.ConsultarPorId(tempProducto).FirstOrDefault();

                    tempCategoria.idCategoria = tempProducto.IdCategoria;
                    tempCategoria             = objCateg.ConsultarPorId(tempCategoria).FirstOrDefault();
                    // Crear la fila, asignar valores y agregarla.
                    DataRow fila = dt.NewRow();
                    fila["categoria"]        = tempProducto.NombreProducto + " " + tempCategoria.Nombre;
                    fila["idProducto"]       = tempProducto.CodigoNumerico;
                    fila["CantidadProducto"] = r.CantidadProducto;

                    dt.Rows.Add(fila);
                }
                gvwDetalleFactura.DataSource = dt;
                gvwDetalleFactura.DataBind();
            }
            catch (Exception ex)
            {
                var err = ex.Message;
            }
        }
Ejemplo n.º 6
0
        private void actualizarCantidadProducto(int idProducto, int cantidadProducto, Boolean resta)
        {
            var tempPro = new PRO_PRODUCTO();

            tempPro.IdProducto = idProducto;
            tempPro            = objProd.ConsultarPorId(tempPro).FirstOrDefault();
            if (resta)
            {
                tempPro.Inventario = tempPro.Inventario - cantidadProducto;
            }
            else
            {
                tempPro.Inventario = tempPro.Inventario + cantidadProducto;
            }

            objProd.Actualizar(tempPro);
        }
Ejemplo n.º 7
0
        public int guardarActualizar(int id)
        {
            PRO_PRODUCTO temp   = new PRO_PRODUCTO();
            int          existe = 0;

            temp.IdProducto     = id;
            temp.CodigoNumerico = Convert.ToInt32(txtCodNumerico.Text);
            temp.IdCategoria    = Convert.ToInt32(ddlCategoria.SelectedValue);
            temp.Inventario     = Convert.ToInt32(txtCantidad.Text);
            temp.NombreProducto = txtNombreProducto.Text;
            temp.Precio         = Convert.ToInt32(txtPrecio.Text);

            existe = objProd.ConsultarPorNombreCodigoCategoria(temp).Count();

            CQR_CODIGO_QR tempQR = new CQR_CODIGO_QR();

            if (existe > 0 && id != -1)
            {
                //tempQR.idProducto = temp.IdProducto;
                //tempQR.idQR = Convert.ToInt32(temp.IdProducto+""+ temp.CodigoNumerico);
                //tempQR.urlImagen = generarQR(Convert.ToString(tempQR.idQR));
                objProd.Actualizar(temp);
                //objQR.Actualizar(tempQR);
            }
            else
            {
                if (objProd.Existe(temp))
                {
                    ErrorMensajer("Producto ya existe con esta categoria!");
                }
                else
                {
                    temp = objProd.Insertar(temp);
                }


                //tempQR.idProducto = temp.IdProducto;
                //tempQR.idQR = Convert.ToInt32(temp.IdProducto + "" + temp.CodigoNumerico);
                //tempQR.urlImagen = generarQR(Convert.ToString(tempQR.idQR));

                //objQR.Insertar(tempQR);
            }
            return(1);
        }
Ejemplo n.º 8
0
        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;
            }
        }
        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();
            }
        }
Ejemplo n.º 10
0
        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;
            }
        }