Exemple #1
0
        //FUNCION PARA INSERTAR UN NUEVO REGISTRO
        private void insertarRegistro()
        {
            try
            {
                sSql  = "";
                sSql += "select * from cv401_productos" + Environment.NewLine;
                sSql += "where codigo = '" + (cmbPadre.SelectedValue.ToString() + "." + txtCodigo.Text.Trim()) + "'" + Environment.NewLine;
                sSql += "and estado = 'A'";

                dtConsulta = new DataTable();
                dtConsulta.Clear();

                bRespuesta = conexion.GFun_Lo_Busca_Registro(dtConsulta, sSql);

                if (bRespuesta == true)
                {
                    if (dtConsulta.Rows.Count > 0)
                    {
                        ok.lblMensaje.Text = "Ya existe un registro con el código ingresado.";
                        ok.ShowDialog();
                        txtCodigo.Clear();
                        txtCodigo.Focus();
                        return;
                    }
                }

                else
                {
                    ok.lblMensaje.Text = "Ocurrió un problema al realizar la búsqueda del código.";
                    ok.ShowDialog();
                    return;
                }


                if (!conexion.GFun_Lo_Maneja_Transaccion(Program.G_INICIA_TRANSACCION))
                {
                    ok.lblMensaje.Text = "Error al abrir transacción.";
                    ok.ShowDialog();
                    limpiar();
                    return;
                }

                //INSERTAR EN LA TABLA CV401_PRODUCTOS
                sSql  = "";
                sSql += "insert into cv401_productos (" + Environment.NewLine;
                sSql += "idempresa, codigo, id_producto_padre, estado, nivel, modificable, precio_modificable," + Environment.NewLine;
                sSql += "paga_iva, secuencia, modificador, subcategoria, ultimo_nivel, fecha_ingreso," + Environment.NewLine;
                sSql += "usuario_ingreso,terminal_ingreso)" + Environment.NewLine;
                sSql += "values(" + Environment.NewLine;
                sSql += Convert.ToInt32(cmbEmpresa.SelectedValue) + ", '" + (cmbPadre.SelectedValue.ToString() + "." + (txtCodigo.Text.Trim())) + "'," + Environment.NewLine;
                sSql += iIdProductoPadre + ", 'A', 3, " + iModificable + ", " + iPrecioModificable + "," + Environment.NewLine;
                sSql += iPagaIva + ", '" + txtSecuencia.Text.Trim() + "', " + iModificador + ", " + iSubcategoria + "," + Environment.NewLine;
                sSql += iUltimo + ", GETDATE(), '" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "')";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.lblMensaje.Text = "ERROR EN LA INSTRUCCION:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //PROCEDIMINTO PARA EXTRAER EL ID DEL PRODUCTO REGISTRADO
                dtConsulta = new DataTable();
                dtConsulta.Clear();

                string sTabla = "cv401_productos";
                string sCampo = "id_Producto";;

                long iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                if (iMaximo == -1)
                {
                    ok.lblMensaje.Text = "No se pudo obtener el codigo de productos";
                    ok.ShowDialog();
                    goto reversa;
                }

                else
                {
                    iIdProducto = Convert.ToInt32(iMaximo);
                }

                //INSERTAR EN LA TABLA CV401_NOMBRES_PRODUCTOS
                sSql  = "";
                sSql += "insert into cv401_nombre_productos (" + Environment.NewLine;
                sSql += "id_producto, cg_tipo_nombre, nombre, nombre_interno, estado,numero_replica_trigger," + Environment.NewLine;
                sSql += "numero_control_replica, fecha_ingreso, usuario_ingreso, terminal_ingreso)" + Environment.NewLine;
                sSql += "values (" + Environment.NewLine;
                sSql += iIdProducto + ", " + cg_tipoNombre + ", '" + txtDescripcion.Text.Trim() + "', " + nombInterno + "," + Environment.NewLine;
                sSql += "'A', 1, 1, GETDATE(), '" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "')";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.lblMensaje.Text = "ERROR EN LA INSTRUCCION:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                sSql  = "";
                sSql += "insert into cv401_unidades_productos (" + Environment.NewLine;
                sSql += "id_producto, cg_tipo_unidad, cg_unidad, unidad_compra, estado," + Environment.NewLine;
                sSql += "usuario_creacion, terminal_creacion, fecha_creacion, numero_replica_trigger," + Environment.NewLine;
                sSql += "numero_control_replica, fecha_ingreso, usuario_ingreso, terminal_ingreso)" + Environment.NewLine;
                sSql += "values (" + Environment.NewLine;
                sSql += iIdProducto + ", " + Program.iCgTipoUnidad + ", " + Convert.ToInt32(cmbCompra.SelectedValue) + ", 1, 'A'," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "', GETDATE(), 1, 1," + Environment.NewLine;
                sSql += "GETDATE(), '" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "')";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.lblMensaje.Text = "ERROR EN LA INSTRUCCION:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                sSql  = "";
                sSql += "insert into cv401_unidades_productos (" + Environment.NewLine;
                sSql += "id_producto, cg_tipo_unidad, cg_unidad, unidad_compra, estado," + Environment.NewLine;
                sSql += "usuario_creacion, terminal_creacion, fecha_creacion, numero_replica_trigger," + Environment.NewLine;
                sSql += "numero_control_replica, fecha_ingreso, usuario_ingreso, terminal_ingreso)" + Environment.NewLine;
                sSql += "values (" + Environment.NewLine;
                sSql += iIdProducto + "," + (Program.iCgTipoUnidad + 1) + ", " + Convert.ToInt32(cmbConsumo.SelectedValue) + ", 0, 'A'," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "', GETDATE(), 1, 1, GETDATE()," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "')";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.lblMensaje.Text = "ERROR EN LA INSTRUCCION:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                conexion.GFun_Lo_Maneja_Transaccion(Program.G_TERMINA_TRANSACCION);
                ok.lblMensaje.Text = "Registro ingresado correctamente";
                ok.ShowDialog();
                limpiarNuevo();
                grupoDatos.Enabled = false;
                llenarGrid(0);
                return;
            }

            catch (Exception ex)
            {
                catchMensaje.lblMensaje.Text = ex.ToString();
                catchMensaje.ShowDialog();
                goto reversa;
            }

            reversa : { conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION); return; }
        }
        private void insertarFactura()
        {
            try
            {
                //sFechaCompleta = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                sFechaCorta = Program.sFechaSistema.ToString("yyyy/MM/dd");

                //INICIAMOS UNA NUEVA TRANSACCION
                //-------------------------------------------------------------------------------------------------------------------------------------------------
                if (!conexion.GFun_Lo_Maneja_Transaccion(Program.G_INICIA_TRANSACCION))
                {
                    ok.LblMensaje.Text = "Error al abrir transacción";
                    ok.ShowDialog();
                    goto fin;
                }

                //EXTRAER EL NUMERO DE FACTURA
                sSql  = "";
                sSql += "select numero_factura, id_localidad_impresora" + Environment.NewLine;
                sSql += "from tp_localidades_impresoras" + Environment.NewLine;
                sSql += "where id_localidad = " + Program.iIdLocalidad + Environment.NewLine;
                sSql += "and estado = 'A'";

                dtConsulta = new DataTable();
                dtConsulta.Clear();

                bRespuesta = conexion.GFun_Lo_Busca_Registro(dtConsulta, sSql);

                if (bRespuesta == true)
                {
                    if (dtConsulta.Rows.Count > 0)
                    {
                        sNumeroFactura        = dtConsulta.Rows[0].ItemArray[0].ToString();
                        iIdLocalidadImpresora = Convert.ToInt32(dtConsulta.Rows[0].ItemArray[1].ToString());
                    }

                    else
                    {
                        ok.LblMensaje.Text = "No se puede extraer el número de factura";
                        ok.ShowDialog();
                        goto reversa;
                    }
                }

                else
                {
                    catchMensaje.LblMensaje.Text = sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //INSERTAR EN LA TABLA CV403_FACTURAS
                //-------------------------------------------------------------------------------------------------------------------------------------------------
                sSql  = "";
                sSql += "insert into cv403_facturas (idempresa, id_persona, cg_empresa, idtipocomprobante," + Environment.NewLine;
                sSql += "id_localidad, idformulariossri, id_vendedor, id_forma_pago, fecha_factura, fecha_vcto," + Environment.NewLine;
                sSql += "cg_moneda, valor, cg_estado_factura, editable, fecha_ingreso, usuario_ingreso, " + Environment.NewLine;
                sSql += "terminal_ingreso, estado, numero_replica_trigger, numero_control_replica, " + Environment.NewLine;
                sSql += "Direccion_Factura,Telefono_Factura, Ciudad_Factura, correo_electronico, servicio)" + Environment.NewLine;
                sSql += "values(" + Environment.NewLine;
                sSql += Program.iIdEmpresa + ", " + iIdPersona + ", " + Program.iCgEmpresa + "," + Environment.NewLine;
                sSql += iIdTipoComprobante + "," + Program.iIdLocalidad + ", " + Program.iIdFormularioSri + ", " + Program.iIdVendedor + ", 14, '" + sFechaCorta + "'," + Environment.NewLine;
                sSql += "'" + sFechaCorta + "', " + Program.iMoneda + ", " + dTotal + ", 0, 0, GETDATE()," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "', 'A', 1, 0," + Environment.NewLine;
                sSql += "'" + sDireccion + "', '" + sTelefono + "', '" + sCiudad + "'," + Environment.NewLine;
                sSql += "'" + sMail + "', 0)";

                //EJECUTA LA INSTRUCCÓN SQL
                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //EXTRAER ID DEL REGISTRO CV403_FACTURAS
                //-------------------------------------------------------------------------------------------------------------------------------------------------
                dtConsulta = new DataTable();
                dtConsulta.Clear();

                sTabla = "cv403_facturas";
                sCampo = "id_factura";

                iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                if (iMaximo == -1)
                {
                    ok.LblMensaje.Text = "No se pudo obtener el codigo de la tabla " + sTabla;
                    ok.ShowDialog();
                    goto reversa;
                }

                else
                {
                    iIdFactura = Convert.ToInt32(iMaximo);
                }

                //INSERTAR EN LA TABLA CV403_NUMEROS_FACTURAS
                //-------------------------------------------------------------------------------------------------------------------------------------------------
                sSql  = "";
                sSql += "insert into cv403_numeros_facturas (id_factura, idtipocomprobante, numero_factura, " + Environment.NewLine;
                sSql += "fecha_ingreso, usuario_ingreso, terminal_ingreso, estado, numero_replica_trigger, " + Environment.NewLine;
                sSql += "numero_control_replica) " + Environment.NewLine;
                sSql += "values (" + Environment.NewLine;
                sSql += iIdFactura + ", " + iIdTipoComprobante + ", " + Convert.ToInt32(sNumeroFactura) + ", GETDATE()," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "', 'A', 1, 0 )";

                //EJECUTA LA INSTRUCCÓN SQL
                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //ACTUALIZAMOS LA TABLA CV403_DCTOS_POR_COBRAR Y CV403_FACTURAS_PEDIDOS
                //-------------------------------------------------------------------------------------------------------------------------------------------------
                for (int i = 0; i < dtCopiaConsulta.Rows.Count; i++)
                {
                    //ACTUALIZAMOS LA TABLA CV403_DCTOS_POR_COBRAR
                    //-------------------------------------------------------------------------------------------------------------------------------------------------
                    sSql  = "";
                    sSql += "update cv403_dctos_por_cobrar set" + Environment.NewLine;
                    sSql += "id_factura = " + iIdFactura + "," + Environment.NewLine;
                    sSql += "numero_documento = " + Convert.ToInt32(sNumeroFactura) + Environment.NewLine;
                    sSql += " where id_pedido = " + Convert.ToInt32(dtCopiaConsulta.Rows[i].ItemArray[0].ToString());

                    //EJECUTA LA INSTRUCCÓN SQL
                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.LblMensaje.Text = sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }


                    //INSERTAR EN LA TABLA CV403_FACTURAS_PEDIDOS
                    //-------------------------------------------------------------------------------------------------------------------------------------------------
                    sSql  = "";
                    sSql += "insert into cv403_facturas_pedidos (" + Environment.NewLine;
                    sSql += "id_factura, id_pedido, fecha_ingreso," + Environment.NewLine;
                    sSql += "usuario_ingreso, terminal_ingreso, estado," + Environment.NewLine;
                    sSql += "numero_replica_trigger, numero_control_replica) " + Environment.NewLine;
                    sSql += "values (" + Environment.NewLine;
                    sSql += iIdFactura + ", " + Convert.ToInt32(dtCopiaConsulta.Rows[i].ItemArray[0].ToString()) + "," + Environment.NewLine;
                    sSql += "GETDATE(), '" + Program.sDatosMaximo[0] + "'," + Environment.NewLine;
                    sSql += "'" + Program.sDatosMaximo[1] + "', 'A', 1, 0 )";

                    //EJECUTA LA INSTRUCCÓN SQL
                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.LblMensaje.Text = sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }

                    //ACTUALIZAR EL ESTADO A PAGADA Y AGREGAMOS LA FECHA DE CIERRE DE ORDENEN CV403_CAB_PEDIDOS
                    //-------------------------------------------------------------------------------------------------------------------------------------------------
                    sSql  = "";
                    sSql += "update cv403_cab_pedidos set" + Environment.NewLine;
                    sSql += "id_persona = " + iIdPersona + "," + Environment.NewLine;
                    sSql += "fecha_cierre_orden = GETDATE()," + Environment.NewLine;
                    sSql += "consumo_alimentos = 1" + Environment.NewLine;
                    sSql += "where id_pedido = " + Convert.ToInt32(dtCopiaConsulta.Rows[i].ItemArray[0].ToString());

                    //EJECUCIÓN DE LA INSTRUCCIÓN SQL
                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.LblMensaje.Text = sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }
                }
                //------------------- FIN DE CICLO FOR -------------------------------------------------------

                //ACTUALIZAMOS EN LA TABLA TP_LOCALIDADES_IMPRESORAS
                //-------------------------------------------------------------------------------------------------------------------------------------------------
                sSql  = "";
                sSql += "update tp_localidades_impresoras set" + Environment.NewLine;
                sSql += "numero_factura = " + (Convert.ToInt32(sNumeroFactura) + 1) + Environment.NewLine;
                sSql += "where id_localidad_impresora = " + iIdLocalidadImpresora + Environment.NewLine;
                sSql += "and estado = 'A'";

                //EJECUTA LA INSTRUCCÓN SQL
                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //EJECUCIÓN DEL COMMIT PARA GUARDAR LA INFORMACION EN LA BASE DE DATOS
                conexion.GFun_Lo_Maneja_Transaccion(Program.G_TERMINA_TRANSACCION);

                ok.LblMensaje.Text = "Factura generada éxitosamente.";
                ok.ShowDialog();
                limpiar();
                goto fin;
            }

            catch (Exception ex)
            {
                catchMensaje.LblMensaje.Text = ex.ToString();
                catchMensaje.ShowDialog();
                goto reversa;
            }

reversa:
            {
                conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION);
            }

            fin : { }
        }
Exemple #3
0
        //FUNCION PARA REGISTRAR EL EQUIPO
        private void insertarRegistro(int iOpDemo_P)
        {
            try
            {
                if (txtNombreEquipo.Text.Trim() == "")
                {
                    ok = new VentanasMensajes.frmMensajeNuevoOk();
                    ok.lblMensaje.Text = "Favor ingrese el nombre del equipo.";
                    ok.ShowDialog();
                    txtNombreEquipo.Focus();
                    return;
                }

                int iCantDisp_P = 0;
                int iCantPerm_P = 0;

                if (iOpDemo_P == 1)
                {
                    iCantPerm_P = 50;
                }

                consultarMaximoCodigo();
                recuperarIP();

                if (!conexion.GFun_Lo_Maneja_Transaccion(Program.G_INICIA_TRANSACCION))
                {
                    ok = new VentanasMensajes.frmMensajeNuevoOk();
                    ok.lblMensaje.Text = "Error al abrir transacción.";
                    ok.ShowDialog();
                    return;
                }

                sSql  = "";
                sSql += "insert into pos_terminal (" + Environment.NewLine;
                sSql += "codigo, descripcion, nombre_maquina, ip_maquina, id_registro," + Environment.NewLine;
                sSql += "serial_registro, demo, cantidad_permitida, cantidad_usada," + Environment.NewLine;
                sSql += "is_active, estado, fecha_ingreso, usuario_ingreso, terminal_ingreso)" + Environment.NewLine;
                sSql += "values (" + Environment.NewLine;
                sSql += "@codigo, @descripcion, @nombre_maquina, @ip_maquina, @id_registro," + Environment.NewLine;
                sSql += "@serial_registro, @demo, @cantidad_permitida, @cantidad_usada," + Environment.NewLine;
                sSql += "@is_active, @estado, getdate(), @usuario_ingreso, @terminal_ingreso)";

                int i = 0;
                parametro    = new SqlParameter[13];
                parametro[i] = new SqlParameter();
                parametro[i].ParameterName = "@codigo";
                parametro[i].SqlDbType     = SqlDbType.VarChar;
                parametro[i].Value         = iCodigo.ToString();
                i++;

                parametro[i] = new SqlParameter();
                parametro[i].ParameterName = "@descripcion";
                parametro[i].SqlDbType     = SqlDbType.VarChar;
                parametro[i].Value         = txtNombreEquipo.Text.Trim().ToUpper();
                i++;

                parametro[i] = new SqlParameter();
                parametro[i].ParameterName = "@nombre_maquina";
                parametro[i].SqlDbType     = SqlDbType.VarChar;
                parametro[i].Value         = Environment.MachineName.ToString();
                i++;

                parametro[i] = new SqlParameter();
                parametro[i].ParameterName = "@ip_maquina";
                parametro[i].SqlDbType     = SqlDbType.VarChar;
                parametro[i].Value         = sIpEquipo;
                i++;

                parametro[i] = new SqlParameter();
                parametro[i].ParameterName = "@id_registro";
                parametro[i].SqlDbType     = SqlDbType.VarChar;
                parametro[i].Value         = sId_P;
                i++;

                parametro[i] = new SqlParameter();
                parametro[i].ParameterName = "@serial_registro";
                parametro[i].SqlDbType     = SqlDbType.VarChar;
                parametro[i].Value         = sVerificarSerial;
                i++;

                parametro[i] = new SqlParameter();
                parametro[i].ParameterName = "@demo";
                parametro[i].SqlDbType     = SqlDbType.Int;
                parametro[i].Value         = iOpDemo_P;
                i++;

                parametro[i] = new SqlParameter();
                parametro[i].ParameterName = "@cantidad_permitida";
                parametro[i].SqlDbType     = SqlDbType.Int;
                parametro[i].Value         = iCantPerm_P;
                i++;

                parametro[i] = new SqlParameter();
                parametro[i].ParameterName = "@cantidad_usada";
                parametro[i].SqlDbType     = SqlDbType.Int;
                parametro[i].Value         = iCantDisp_P;
                i++;

                parametro[i] = new SqlParameter();
                parametro[i].ParameterName = "@is_active";
                parametro[i].SqlDbType     = SqlDbType.Int;
                parametro[i].Value         = 1;
                i++;

                parametro[i] = new SqlParameter();
                parametro[i].ParameterName = "@estado";
                parametro[i].SqlDbType     = SqlDbType.VarChar;
                parametro[i].Value         = sDatosMaximo[2];
                i++;

                parametro[i] = new SqlParameter();
                parametro[i].ParameterName = "@usuario_ingreso";
                parametro[i].SqlDbType     = SqlDbType.VarChar;
                parametro[i].Value         = sDatosMaximo[0];
                i++;

                parametro[i] = new SqlParameter();
                parametro[i].ParameterName = "@terminal_ingreso";
                parametro[i].SqlDbType     = SqlDbType.VarChar;
                parametro[i].Value         = sDatosMaximo[1];

                //EJECUTAR LA INSTRUCCIÓN SQL
                if (!conexion.GFun_Lo_Ejecutar_SQL_Parametros(sSql, parametro))
                {
                    conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION);
                    catchMensaje = new VentanasMensajes.frmMensajeNuevoCatch();
                    catchMensaje.lblMensaje.Text = conexion.sMensajeError;
                    catchMensaje.ShowDialog();
                    return;
                }

                //OBTENER EL ID DEL EQUIPO
                sCampo = "id_pos_terminal";
                sTabla = "pos_terminal";

                iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", sDatosMaximo);

                if (iMaximo == -1)
                {
                    conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION);
                    ok = new VentanasMensajes.frmMensajeNuevoOk();
                    ok.lblMensaje.Text = "No se pudo obtener el codigo de la tabla " + sTabla;
                    ok.ShowDialog();
                    return;
                }

                Program.iIdPosTerminal = Convert.ToInt32(iMaximo);

                conexion.GFun_Lo_Maneja_Transaccion(Program.G_TERMINA_TRANSACCION);

                if (iOpDemo_P == 1)
                {
                    ok = new VentanasMensajes.frmMensajeNuevoOk();
                    ok.lblMensaje.Text = "La versión de prueba ha iniciado con éxito.";
                    ok.ShowDialog();
                }

                else
                {
                    Program.iVersionDemo = 0;
                    ok = new VentanasMensajes.frmMensajeNuevoOk();
                    ok.lblMensaje.Text = "La aplicación se ha registrado con éxito.";
                    ok.ShowDialog();
                }

                this.DialogResult = DialogResult.OK;
            }

            catch (Exception ex)
            {
                conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION);
                catchMensaje = new VentanasMensajes.frmMensajeNuevoCatch();
                catchMensaje.lblMensaje.Text = ex.Message;
                catchMensaje.ShowDialog();
            }
        }
        //INSERTAR LA SEGUNDA FASE DE PAGOS
        private bool insertarPago()
        {
            try
            {
                //EXTRAER EL ID DE LA TABLA CV403_DCTOS_POR_COBRAR
                sSql  = "";
                sSql += "select id_documento_cobrar" + Environment.NewLine;
                sSql += "from cv403_dctos_por_cobrar" + Environment.NewLine;
                sSql += "where id_pedido = " + iIdPedido + Environment.NewLine;
                sSql += "and estado = 'A'";

                dtConsulta = new DataTable();
                dtConsulta.Clear();

                bRespuesta = conexion.GFun_Lo_Busca_Registro(dtConsulta, sSql);

                if (bRespuesta == true)
                {
                    iIdDocumentoCobrar = Convert.ToInt32(dtConsulta.Rows[0][0].ToString());
                }
                else
                {
                    ok.LblMensaje.Text = "Ocurrió un problema al extraer el id de la tabla" + Environment.NewLine + "cv403_dctos_por_cobrar.";
                    ok.ShowDialog();
                    goto reversa;
                }

                //EXTRAER EL ID DE LA TABLA CV403_DCTOS_POR_COBRAR
                sSql  = "";
                sSql += "select id_pago, id_documento_pagado" + Environment.NewLine;
                sSql += "from cv403_documentos_pagados" + Environment.NewLine;
                sSql += "where id_documento_cobrar = " + iIdDocumentoCobrar + Environment.NewLine;
                sSql += "and estado = 'A'";

                dtConsulta = new DataTable();
                dtConsulta.Clear();

                bRespuesta = conexion.GFun_Lo_Busca_Registro(dtConsulta, sSql);

                if (bRespuesta == true)
                {
                    if (dtConsulta.Rows.Count > 0)
                    {
                        iIdPago            = Convert.ToInt32(dtConsulta.Rows[0][0].ToString());
                        iIdDocumentoPagado = Convert.ToInt32(dtConsulta.Rows[0][1].ToString());
                        iCuenta            = 1;
                    }

                    else
                    {
                        iCuenta = 0;
                    }
                }
                else
                {
                    catchMensaje.LblMensaje.Text = "ERROR EN LA INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //INSERTAR O ACTUALIZAR LA TABLA CV403_PAGOS
                if (iCuenta == 0)
                {
                    sSql  = "";
                    sSql += "select numero_pago, id_localidad_impresora" + Environment.NewLine;
                    sSql += "from tp_localidades_impresoras" + Environment.NewLine;
                    sSql += "where id_localidad = " + Program.iIdLocalidad + Environment.NewLine;
                    sSql += "and estado = 'A'";

                    dtConsulta = new DataTable();
                    dtConsulta.Clear();

                    bRespuesta = conexion.GFun_Lo_Busca_Registro(dtConsulta, sSql);

                    if (bRespuesta == true)
                    {
                        if (dtConsulta.Rows.Count > 0)
                        {
                            iNumeroPago           = Convert.ToInt32(dtConsulta.Rows[0][0].ToString());
                            iIdLocalidadImpresora = Convert.ToInt32(dtConsulta.Rows[0][1].ToString());
                        }

                        else
                        {
                            ok.LblMensaje.Text = "No se pudo obtener el número secuencial para pagos.";
                            ok.ShowDialog();
                            goto reversa;
                        }
                    }

                    else
                    {
                        catchMensaje.LblMensaje.Text = "ERROR EN LA INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }

                    sSql  = "";
                    sSql += "update tp_localidades_impresoras set" + Environment.NewLine;
                    sSql += "numero_pago = numero_pago + 1" + Environment.NewLine;
                    sSql += "where id_localidad_impresora = " + iIdLocalidadImpresora;

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.LblMensaje.Text = "ERROR EN LA INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }

                    //INSERTAR EN LA TABLA CV403_PAGOS
                    sSql  = "";
                    sSql += "insert into cv403_pagos (" + Environment.NewLine;
                    sSql += "idempresa, id_persona, fecha_pago, cg_moneda, valor," + Environment.NewLine;
                    sSql += "propina, cg_empresa, id_localidad, cg_cajero, fecha_ingreso," + Environment.NewLine;
                    sSql += "usuario_ingreso, terminal_ingreso, estado, " + Environment.NewLine;
                    sSql += "numero_replica_trigger, numero_control_replica, cambio) " + Environment.NewLine;
                    sSql += "values(" + Environment.NewLine;
                    sSql += Program.iIdEmpresa + ", " + Program.iIdPersona + ", '" + sFechaCorta + "', " + Program.iMoneda + "," + Environment.NewLine;
                    sSql += dbTotal + ", 0, " + Program.iCgEmpresa + "," + Environment.NewLine;
                    sSql += Program.iIdLocalidad + ", 7799, GETDATE(), '" + Program.sDatosMaximo[0] + "'," + Environment.NewLine;
                    sSql += "'" + Program.sDatosMaximo[1] + "', 'A' , 1, 0, 0)";

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.LblMensaje.Text = "ERROR EN LA INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }

                    //EXTRAER ID DEL REGISTRO CV403_PAGOS
                    dtConsulta = new DataTable();
                    dtConsulta.Clear();

                    sTabla = "cv403_pagos";
                    sCampo = "id_pago";

                    iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                    if (iMaximo == -1)
                    {
                        ok.LblMensaje.Text = "No se pudo obtener el codigo de la tabla " + sTabla;
                        ok.ShowDialog();
                        goto reversa;
                    }

                    else
                    {
                        iIdPago = Convert.ToInt32(iMaximo);
                    }

                    //INSERTAMOS EN LA TABLA CV403_NUMEROS_PAGOS
                    sSql  = "";
                    sSql += "insert into cv403_numeros_pagos (" + Environment.NewLine;
                    sSql += "id_pago, serie, numero_pago, fecha_ingreso, usuario_ingreso," + Environment.NewLine;
                    sSql += "terminal_ingreso, estado, numero_replica_trigger, numero_control_replica)" + Environment.NewLine;
                    sSql += "values(" + Environment.NewLine;
                    sSql += iIdPago + ", 'A', " + iNumeroPago + ", GETDATE(), '" + Program.sDatosMaximo[0] + "'," + Environment.NewLine;
                    sSql += "'" + Program.sDatosMaximo[1] + "', 'A', 0, 0)";

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.LblMensaje.Text = "ERROR EN LA INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }
                }

                else
                {
                    sSql  = "";
                    sSql += "update cv403_pagos set" + Environment.NewLine;
                    sSql += "valor = valor + " + dbTotal + Environment.NewLine;
                    sSql += "where id_pago = " + iIdPago + Environment.NewLine;
                    sSql += "and estado = 'A'";

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.LblMensaje.Text = "ERROR EN LA INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }
                }

                //EXTRAER EL REGISTRO DE EFECTIVO
                sSql  = "";
                sSql += "select id_pos_tipo_forma_cobro, descripcion" + Environment.NewLine;
                sSql += "from pos_tipo_forma_cobro" + Environment.NewLine;
                sSql += "where cg_tipo_documento = " + iCgTipoDocumento + Environment.NewLine;
                sSql += "and estado = 'A'";

                dtConsulta = new DataTable();
                dtConsulta.Clear();

                bRespuesta = conexion.GFun_Lo_Busca_Registro(dtConsulta, sSql);

                if (bRespuesta == false)
                {
                    catchMensaje.LblMensaje.Text = "ERROR EN LA INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                else
                {
                    iIdPosTipoFormaCobro = Convert.ToInt32(dtConsulta.Rows[0][0].ToString());
                    sDescripcionPago     = dtConsulta.Rows[0][1].ToString();
                }

                //INSERTAMOS EN LA TABLA CV403_DOCUMENTOS_PAGOS
                sSql  = "";
                sSql += "insert into cv403_documentos_pagos (" + Environment.NewLine;
                sSql += "id_pago, cg_tipo_documento, numero_documento, fecha_vcto, " + Environment.NewLine;
                sSql += "cg_moneda, cotizacion, valor, id_pos_tipo_forma_cobro," + Environment.NewLine;
                sSql += "estado, fecha_ingreso, usuario_ingreso, terminal_ingreso," + Environment.NewLine;
                sSql += "numero_replica_trigger, numero_control_replica, valor_recibido) " + Environment.NewLine;
                sSql += "values(" + Environment.NewLine;
                sSql += iIdPago + ", " + iCgTipoDocumento + ", 9999, '" + sFechaCorta + "', " + Environment.NewLine;
                sSql += Program.iMoneda + ", 1, " + dbTotal + ", " + iIdPosTipoFormaCobro + ", 'A', GETDATE()," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "', 0, 0, " + dbTotal + ")";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = "ERROR EN LA INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //PARA INSERTAR O ACTUALIZAR EL CV403_DOCUMENTOS_PAGADOS
                if (iCuenta == 0)
                {
                    //INSERTAMOS EL ÚNICO DOCUMENTO PAGADO
                    sSql  = "";
                    sSql += "insert into cv403_documentos_pagados (" + Environment.NewLine;
                    sSql += "id_documento_cobrar, id_pago, valor," + Environment.NewLine;
                    sSql += "estado, numero_replica_trigger,numero_control_replica," + Environment.NewLine;
                    sSql += "fecha_ingreso, usuario_ingreso, terminal_ingreso)" + Environment.NewLine;
                    sSql += "values (" + Environment.NewLine;
                    sSql += iIdDocumentoCobrar + ", " + iIdPago + ", " + dbTotal + ", 'A', 1, 0, " + Environment.NewLine;
                    sSql += "GETDATE(), '" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "')";

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.LblMensaje.Text = "ERROR EN LA INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }
                }

                else
                {
                    sSql  = "";
                    sSql += "update cv403_documentos_pagados set" + Environment.NewLine;
                    sSql += "valor = valor + " + dbTotal + Environment.NewLine;
                    sSql += "where id_documento_pagado = " + iIdDocumentoPagado + Environment.NewLine;
                    sSql += "and estado = 'A'";

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.LblMensaje.Text = "ERROR EN LA INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }
                }

                //CONSULTAR SI AUN EXISTEN LINEAS POR COBRAR
                sSql  = "";
                sSql += "select count(*) cuenta" + Environment.NewLine;
                sSql += "from cv403_det_pedidos" + Environment.NewLine;
                sSql += "where id_pedido = " + iIdPedido + Environment.NewLine;
                sSql += "and estado_pago is null" + Environment.NewLine;
                sSql += "and estado = 'A'";

                dtConsulta = new DataTable();
                dtConsulta.Clear();

                bRespuesta = conexion.GFun_Lo_Busca_Registro(dtConsulta, sSql);

                if (bRespuesta == true)
                {
                    iCuenta = Convert.ToInt32(dtConsulta.Rows[0][0].ToString());

                    if (iCuenta == 0)
                    {
                        iEjecutarCierre = 1;
                    }

                    else
                    {
                        iEjecutarCierre = 0;
                    }
                }

                else
                {
                    catchMensaje.LblMensaje.Text = "ERROR EN LA INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                if (iEjecutarCierre == 1)
                {
                    //ACTUALIZAR LOS DATOS EN DCTOS_POR_COBRAR
                    sSql  = "";
                    sSql += "update cv403_dctos_por_cobrar set" + Environment.NewLine;
                    sSql += "cg_estado_dcto = " + iCgEstadoDctoPorCobrarPagado + Environment.NewLine;
                    sSql += "where id_pedido = " + iIdPedido + Environment.NewLine;
                    sSql += "and estado = 'A'" + Environment.NewLine;

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.LblMensaje.Text = "ERROR EN LA INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }
                }

                else
                {
                    //ACTUALIZAR LOS DATOS EN DCTOS_POR_COBRAR
                    sSql  = "";
                    sSql += "update cv403_dctos_por_cobrar set" + Environment.NewLine;
                    sSql += "cg_estado_dcto = " + iCgEstadoDctoPorCobrarParcial + Environment.NewLine;
                    sSql += "where id_pedido = " + iIdPedido + Environment.NewLine;
                    sSql += "and estado = 'A'" + Environment.NewLine;

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.LblMensaje.Text = "ERROR EN LA INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }
                }

                return(true);
            }

            catch (Exception ex)
            {
                catchMensaje.LblMensaje.Text = ex.ToString();
                catchMensaje.ShowDialog();
                goto reversa;
            }

            reversa : { conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION); return(false); }
        }
        //FUNCION PARA INSERTAR UN NUEVO REGISTRO
        private void insertarRegistro()
        {
            try
            {
                sSql  = "";
                sSql += "select * from cv401_productos" + Environment.NewLine;
                sSql += "where codigo = '" + sValor + "'" + Environment.NewLine;
                sSql += "and estado = 'A'";

                dtConsulta = new DataTable();
                dtConsulta.Clear();

                bRespuesta = conexion.GFun_Lo_Busca_Registro(dtConsulta, sSql);

                if (bRespuesta == true)
                {
                    if (dtConsulta.Rows.Count > 0)
                    {
                        ok.lblMensaje.Text = "Ya existe un registro con el código ingresaado.";
                        ok.ShowDialog();
                        txtCodigoCategoria.Clear();
                        txtCodigoCategoria.Focus();
                        return;
                    }
                }

                else
                {
                    catchMensaje.lblMensaje.Text = "ERROR EN  LA INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    return;
                }


                if (!conexion.GFun_Lo_Maneja_Transaccion(Program.G_INICIA_TRANSACCION))
                {
                    ok.lblMensaje.Text = "Error al abrir transacción para guardar el registro.";
                    ok.ShowDialog();
                    limpiar();
                    return;
                }

                sSql  = "";
                sSql += " select id_producto from cv401_productos" + Environment.NewLine;
                sSql += "where codigo = '" + cmbPadre.SelectedValue + "'" + Environment.NewLine;
                sSql += "and estado = 'A'";

                dtConsulta = new DataTable();
                dtConsulta.Clear();

                bRespuesta = conexion.GFun_Lo_Busca_Registro(dtConsulta, sSql);

                if (bRespuesta == true)
                {
                    if (dtConsulta.Rows.Count > 0)
                    {
                        idPadre = Convert.ToInt32(dtConsulta.Rows[0].ItemArray[0].ToString());
                    }
                }

                else
                {
                    catchMensaje.lblMensaje.Text = "ERROR EN  LA INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                sSql  = "";
                sSql += "insert into cv401_productos (" + Environment.NewLine;
                sSql += "idempresa, codigo, id_producto_padre, estado, nivel, modificable," + Environment.NewLine;
                sSql += "precio_modificable, paga_iva, secuencia, modificador, subcategoria," + Environment.NewLine;
                sSql += "ultimo_nivel, otros, fecha_ingreso, usuario_ingreso, terminal_ingreso," + Environment.NewLine;
                sSql += "menu_pos, maneja_almuerzos)" + Environment.NewLine;
                sSql += "values (" + Environment.NewLine;
                sSql += Convert.ToInt32(cmbEmpresa.SelectedValue) + ", '" + sValor + "', " + idPadre + ", 'A'," + Environment.NewLine;
                sSql += iNivel + ", " + iModificable + ", " + iPrecioModificable + ", " + iPagaIva + "," + Environment.NewLine;
                sSql += "'" + txtSecuencia.Text.Trim() + "', " + iModificador + ", " + iTieneSubCategoria + "," + Environment.NewLine;
                sSql += iUltimo + ", " + iOtros + ", GETDATE(), '" + Program.sDatosMaximo[0] + "'," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[1] + "', " + iMenuPos + ", " + iManejaAlmuerzos + ")";

                //sisque no me ejuta el query
                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.lblMensaje.Text = "ERROR EN  LA INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //PROCEDIMINTO PARA EXTRAER EL ID DEL PRODUCTO REGISTRADO
                dtConsulta = new DataTable();
                dtConsulta.Clear();

                string sTabla = "cv401_productos";
                string sCampo = "id_Producto";;

                long iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                if (iMaximo == -1)
                {
                    ok.lblMensaje.Text = "No se pudo obtener el codigo de productos.";
                    ok.ShowDialog();
                    goto reversa;
                }

                else
                {
                    iIdCategoria = Convert.ToInt32(iMaximo);
                }

                sSql  = "";
                sSql += "insert into cv401_nombre_productos (" + Environment.NewLine;
                sSql += "id_producto, cg_tipo_nombre, nombre, nombre_interno," + Environment.NewLine;
                sSql += "estado, numero_replica_trigger, numero_control_replica," + Environment.NewLine;
                sSql += "fecha_ingreso, usuario_ingreso, terminal_ingreso)" + Environment.NewLine;
                sSql += "values (" + Environment.NewLine;
                sSql += iIdCategoria + ", 5076, '" + txtDescripcion.Text.Trim() + "', 1, 'A', 1, 1, GETDATE()," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "')";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.lblMensaje.Text = "ERROR EN  LA INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                sSql  = "";
                sSql += "insert into cv401_unidades_productos (" + Environment.NewLine;
                sSql += "id_producto, cg_tipo_unidad, cg_unidad, unidad_compra," + Environment.NewLine;
                sSql += "estado, usuario_creacion, terminal_creacion, fecha_creacion, numero_replica_trigger," + Environment.NewLine;
                sSql += "numero_control_replica, fecha_ingreso, usuario_ingreso, terminal_ingreso)" + Environment.NewLine;
                sSql += "values (" + Environment.NewLine;
                sSql += iIdCategoria + ", " + Program.iCgTipoUnidad + ", " + Convert.ToInt32(cmbCompra.SelectedValue) + ", 1, 'A'," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "', GETDATE(), 1, 1, GETDATE()," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "')";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.lblMensaje.Text = "ERROR EN  LA INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                sSql  = "";
                sSql += "insert into cv401_unidades_productos (" + Environment.NewLine;
                sSql += "id_producto, cg_tipo_unidad, cg_unidad, unidad_compra," + Environment.NewLine;
                sSql += "estado, usuario_creacion, terminal_creacion, fecha_creacion, numero_replica_trigger," + Environment.NewLine;
                sSql += "numero_control_replica, fecha_ingreso, usuario_ingreso, terminal_ingreso)" + Environment.NewLine;
                sSql += "values (" + Environment.NewLine;
                sSql += iIdCategoria + ", " + (Program.iCgTipoUnidad + 1) + ", " + Convert.ToInt32(cmbConsumo.SelectedValue) + ", 0, 'A'," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "', GETDATE(), 1, 1, GETDATE()," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "')";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.lblMensaje.Text = "ERROR EN  LA INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }


                //si no se ejecuta bien hara un commit
                conexion.GFun_Lo_Maneja_Transaccion(Program.G_TERMINA_TRANSACCION);
                ok.lblMensaje.Text = "Registro ingresado correctamente.";
                ok.ShowDialog();
                limpiarNuevo();
                grupoDatos.Enabled = false;
                llenarGrid(0);
                return;
            }

            catch (Exception ex)
            {
                catchMensaje.lblMensaje.Text = ex.ToString();
                catchMensaje.ShowDialog();
            }

            reversa : { conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION); return; }
        }
        //FUNCION PARA INSERTAR EL EGRESO DE BODEGA
        private bool insertarRegistroEgreso()
        {
            try
            {
                sSql  = "";
                sSql += "Insert Into cv402_cabecera_movimientos (" + Environment.NewLine;
                sSql += "CG_EMPRESA, idEmpresa, ID_BODEGA, CG_TIPO_MOVIMIENTO," + Environment.NewLine;
                sSql += "CG_MOTIVO_MOVIMIENTO_BODEGA, CG_CLIENTE_PROVEEDOR, ID_AUXILIAR," + Environment.NewLine;
                sSql += "ID_PERSONA, ID_LOCALIDAD, Fecha, CG_MONEDA_BASE, REFERENCIA_EXTERNA," + Environment.NewLine;
                sSql += "NOTA_PEDIDO, FACTURA, NOTA_ENTREGA, OBSERVACION, NUMERO_MOVIMIENTO," + Environment.NewLine;
                sSql += "usuario_ingreso, terminal_ingreso, ESTADO )" + Environment.NewLine;
                sSql += "Values (" + Environment.NewLine;
                sSql += Program.iCgEmpresa + ", " + Program.iIdEmpresa + ", " + iIdBodega + "," + Environment.NewLine;
                sSql += "7999, " + iMotivo + ", 6162, " + iIdProveedor + "," + Environment.NewLine;
                sSql += iIdPersona + ", " + iIdOficina + ", '" + sFechaInsertar + "'," + Environment.NewLine;
                sSql += Program.iMoneda + ", '" + sComentarios + "', '" + sOrdenFabricacion + "'," + Environment.NewLine;
                sSql += "'" + sOrdenDisenio + "', '" + sNotaEntrega + "', '" + sComentarios + "'," + Environment.NewLine;
                sSql += "'" + sCorrelativo + "', '" + Program.sDatosMaximo[0] + "'," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[1] + "', 'A' )";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.lblMensaje.Text = sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                int NewCodigo = 0;

                //PROCEDIMINTO PARA EXTRAER EL ID DE LA TABLA CV403_CAB_DESPACHOS_PEDIDOS
                dtConsulta = new DataTable();
                dtConsulta.Clear();

                sTabla = "cv402_cabecera_movimientos";
                sCampo = "Id_Movimiento_Bodega";

                iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                if (iMaximo == -1)
                {
                    ok.lblMensaje.Text = "No se pudo obtener el codigo de la tabla " + sTabla;
                    ok.ShowDialog();
                    goto reversa;
                }

                else
                {
                    NewCodigo = Convert.ToInt32(iMaximo);
                }

                for (int i = 0; i < dgvDatos.Rows.Count; i++)
                {
                    int    iIdProducto     = Convert.ToInt32(dgvDatos.Rows[i].Cells[9].Value.ToString());
                    double dbCantidad      = Convert.ToDouble(dgvDatos.Rows[i].Cells[4].Value.ToString());
                    double dbValorUnitario = Convert.ToDouble(dgvDatos.Rows[i].Cells[5].Value.ToString());

                    sSql  = "";
                    sSql += "Insert Into cv402_movimientos_bodega (" + Environment.NewLine;
                    sSql += "ID_PRODUCTO, ID_MOVIMIENTO_BODEGA, CG_UNIDAD_COMPRA, CANTIDAD,ESTADO)" + Environment.NewLine;
                    sSql += "Values (" + Environment.NewLine;
                    sSql += iIdProducto + ", " + NewCodigo + ", 546," + (dbCantidad * -1) + ", 'A')";

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.lblMensaje.Text = sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }
                }

                return(true);
            }

            catch (Exception ex)
            {
                catchMensaje.lblMensaje.Text = ex.ToString();
                catchMensaje.ShowDialog();
                return(false);
            }

            reversa : { conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION); return(false); }
        }
Exemple #7
0
        //=================================================================================================
        private void insertarPedido()
        {
            try
            {
                sFecha = Program.sFechaSistema.ToString("yyyy/MM/dd");

                //EXTRAER EL NUMERO DE PEDIDO DE LA TABLA TP_LOCALIDADES_IMPRESORAS
                sSql  = "";
                sSql += "select numero_pedido" + Environment.NewLine;
                sSql += "from tp_localidades_impresoras" + Environment.NewLine;
                sSql += "where id_localidad = " + Program.iIdLocalidad + Environment.NewLine;
                sSql += "and estado = 'A'";

                dtConsulta = new DataTable();
                dtConsulta.Clear();

                bRespuesta = conexion.GFun_Lo_Busca_Registro(dtConsulta, sSql);

                if (bRespuesta == true)
                {
                    if (dtConsulta.Rows.Count > 0)
                    {
                        iNumeroPedido = Convert.ToInt32(dtConsulta.Rows[0][0].ToString());
                    }
                }

                else
                {
                    catchMensaje.LblMensaje.Text = sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //INSTRUCCION PARA INSERTAR EN LA TABLA CV403_CAB_PEDIDOS
                sSql  = "";
                sSql += "Insert Into cv403_cab_pedidos (idEmpresa, cg_empresa, Id_Localidad," + Environment.NewLine;
                sSql += "Fecha_Pedido, id_persona, Cg_Tipo_Cliente, Cg_Moneda, Porcentaje_Iva," + Environment.NewLine;
                sSql += "id_vendedor, Fabricante, referencia, Comentarios, cg_estado_Pedido," + Environment.NewLine;
                sSql += "Porcentaje_Dscto, Cg_Facturado, Fecha_Ingreso, Usuario_Ingreso," + Environment.NewLine;
                sSql += "Terminal_Ingreso, Estado, numero_replica_trigger, numero_control_replica, porcentaje_servicio) " + Environment.NewLine;
                sSql += "Values (" + Environment.NewLine;
                sSql += Program.iIdEmpresa + ", " + Program.iCgEmpresa + ", " + Program.iIdLocalidad + "," + Environment.NewLine;
                sSql += "'" + sFecha + "', " + Program.iIdPersona + ", 8032, " + Program.iMoneda + "," + Environment.NewLine;
                sSql += (Program.iva * 100) + ", " + Program.iIdVendedor + ", 78, '', '', 6967, 0, 7469," + Environment.NewLine;
                sSql += "GETDATE(), '" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "'," + Environment.NewLine;
                sSql += "'A', 0, 0, " + (Program.servicio * 100) + ")";

                //EJECUTA INSTRUCCION SQL
                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //PROCEDIMINTO PARA EXTRAER EL ID DE LA TABLA CV403_CAB_PEDIDOS
                dtConsulta = new DataTable();
                dtConsulta.Clear();

                sTabla = "cv403_cab_pedidos";
                sCampo = "Id_Pedido";

                iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                if (iMaximo == -1)
                {
                    ok.LblMensaje.Text = "No se pudo obtener el codigo de la tabla " + sTabla;
                    ok.ShowInTaskbar   = false;
                    ok.ShowDialog();
                    goto reversa;
                }

                else
                {
                    iIdCabPedido_F = Convert.ToInt32(iMaximo);
                }

                //INSTRUCCION PARA INSERTAR EN LA TABLA CV403_CAB_DESPACHOS
                sSql  = "";
                sSql += "Insert Into cv403_cab_despachos (idEmpresa, id_persona, cg_empresa, Id_Localidad," + Environment.NewLine;
                sSql += "Fecha_Despacho, Cg_Motivo_Despacho, Id_Destinatario, Punto_Partida, Cg_Ciudad_Entrega," + Environment.NewLine;
                sSql += "Direccion_Entrega, Id_Transportador, Fecha_Inicio_Transporte, Fecha_Fin_Transporte," + Environment.NewLine;
                sSql += "cg_estado_Despacho, Punto_Venta, Comentarios, Fecha_Ingreso, Usuario_Ingreso, Terminal_Ingreso," + Environment.NewLine;
                sSql += "Estado, numero_replica_trigger, numero_control_replica)" + Environment.NewLine;
                sSql += "Values (" + Environment.NewLine;
                sSql += Program.iIdEmpresa + ", " + Program.iIdPersona + ", " + Program.iCgEmpresa + ", " + Program.iIdLocalidad + "," + Environment.NewLine;
                sSql += "'" + sFecha + "', 6972, " + Program.iIdPersona + ", '" + Program.sCiudadDefault + "'," + Environment.NewLine;
                sSql += "0, '" + Program.sCiudadDefault + "', " + Program.iIdPersona + ", '" + sFecha + "'," + Environment.NewLine;
                sSql += "'" + sFecha + "', 6970, 1, '', GETDATE(), '" + Program.sDatosMaximo[0] + "'," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[1] + "', 'A', 0, 0)";

                //EJECUTA INSTRUCCION SQL
                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //PROCEDIMINTO PARA EXTRAER EL ID DE LA TABLA CV403_CAB_DESPACHOS
                dtConsulta = new DataTable();
                dtConsulta.Clear();

                sTabla = "cv403_cab_despachos";
                sCampo = "Id_Despacho";

                iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                if (iMaximo == -1)
                {
                    ok.LblMensaje.Text = "No se pudo obtener el codigo de la tabla " + sTabla;
                    ok.ShowInTaskbar   = false;
                    ok.ShowDialog();
                    goto reversa;
                }

                else
                {
                    iIdCabDespacho_F = Convert.ToInt32(iMaximo);
                }

                //INSTRUCCION PARA INSERTAR EN LA TABLA CV403_DESPACHOS_PEDIDOS
                sSql  = "";
                sSql += "Insert Into cv403_despachos_pedidos (Id_Despacho, Id_Pedido, fecha_ingreso," + Environment.NewLine;
                sSql += "usuario_ingreso, terminal_ingreso, Estado, numero_replica_trigger, numero_control_replica)" + Environment.NewLine;
                sSql += "Values (" + Environment.NewLine;
                sSql += iIdCabDespacho_F + ", " + iIdCabPedido_F + ", GETDATE(), '" + Program.sDatosMaximo[0] + "'," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[1] + "', 'A', 0, 0)";

                //EJECUTA INSTRUCCION SQL
                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //PROCEDIMINTO PARA EXTRAER EL ID DE LA TABLA CV403_DESPACHOS_PEDIDOS
                dtConsulta = new DataTable();
                dtConsulta.Clear();

                sTabla = "cv403_despachos_pedidos";
                sCampo = "Id_Despacho_Pedido";

                iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                if (iMaximo == -1)
                {
                    ok.LblMensaje.Text = "No se pudo obtener el codigo de la tabla " + sTabla;
                    ok.ShowInTaskbar   = false;
                    ok.ShowDialog();
                    goto reversa;
                }

                else
                {
                    iIdDespachoPedido_F = Convert.ToInt32(iMaximo);
                }

                //INSTRUCCION PARA INSERTAR EN  LA TABLA CV403_NUMERO_CAB_PEDIDO
                sSql  = "";
                sSql  = "insert into cv403_numero_cab_pedido (" + Environment.NewLine;
                sSql += "idtipocomprobante,id_pedido, numero_pedido," + Environment.NewLine;
                sSql += "fecha_ingreso, usuario_ingreso, terminal_ingreso, estado," + Environment.NewLine;
                sSql += "numero_control_replica, numero_replica_trigger)" + Environment.NewLine;
                sSql += "values (" + Environment.NewLine;
                sSql += "1," + iIdCabPedido_F + ", " + iNumeroPedido + ", GETDATE()," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "', 'A', 0, 0)";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //ACTUALIZAR EL NUMERO DE PEDIDO EN LA TABLA TP_LOCALIDADES_IMPRESORAS
                sSql  = "";
                sSql += "update tp_localidades_impresoras set" + Environment.NewLine;
                sSql += "numero_pedido = numero_pedido + 1" + Environment.NewLine;
                sSql += "where id_localidad = " + Program.iIdLocalidad + Environment.NewLine;
                sSql += "and estado = 'A'";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = sSql;
                    catchMensaje.ShowInTaskbar   = false;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //INSTRUCCION PARA INSERTAR EN LA TABLA CV403_DET_PEDIDOS
                sSql  = "";
                sSql += "Insert Into cv403_det_pedidos(Id_Pedido, id_producto, Cg_Unidad_Medida, precio_unitario," + Environment.NewLine;
                sSql += "Cantidad, Valor_Dscto, Valor_Ice, Valor_Iva, comentario, Id_Definicion_Combo," + Environment.NewLine;
                sSql += "fecha_ingreso, Usuario_Ingreso, Terminal_ingreso, Estado, numero_replica_trigger, numero_control_replica)" + Environment.NewLine;
                sSql += "Values (" + Environment.NewLine;
                sSql += iIdCabPedido_F + ", " + Program.iIdProductoAnular + ", 546, " + Program.dValorProductoAnular + "," + Environment.NewLine;
                sSql += "1, 0, 0, " + (Program.iva * 100) + ", '', null, GETDATE(), '" + Program.sDatosMaximo[0] + "'," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[1] + "', 'A', 0, 0)";

                //EJECUTA INSTRUCCION SQL
                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //INSTRUCCION PARA INSERTAR EN LA TABLA CV403_CANTIDADES_DESPACHADAS
                sSql  = "";
                sSql += "Insert Into cv403_cantidades_despachadas (Id_Despacho_Pedido, id_producto," + Environment.NewLine;
                sSql += "Cantidad, Estado, numero_replica_trigger, numero_control_replica) " + Environment.NewLine;
                sSql += "Values (" + Environment.NewLine;
                sSql += iIdDespachoPedido_F + ", " + Program.iIdProductoAnular + ", 1, 'A', 0, 0)";

                //EJECUTA INSTRUCCION SQL
                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //INSTRUCCION PARA INSERTAR EN LA TABLA CV403_EVENTOS_COBROS
                sSql  = "";
                sSql += "Insert Into cv403_eventos_cobros (idEmpresa, cg_empresa, id_persona, Id_Localidad," + Environment.NewLine;
                sSql += "Cg_Evento_Cobro, Cg_Moneda, Valor,Fecha_Ingreso, Usuario_Ingreso, Terminal_Ingreso," + Environment.NewLine;
                sSql += "Estado, numero_replica_trigger, numero_control_replica)" + Environment.NewLine;
                sSql += "Values (" + Environment.NewLine;
                sSql += Program.iIdEmpresa + ", " + Program.iCgEmpresa + ", " + Program.iIdPersona + "," + Environment.NewLine;
                sSql += Program.iIdLocalidad + ", 7466, " + Program.iMoneda + ", " + Program.dValorProductoAnular + "," + Environment.NewLine;
                sSql += "GETDATE(), '" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "', 'A', 0, 0)";

                //EJECUTA INSTRUCCION SQL
                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //PROCEDIMINTO PARA EXTRAER EL ID DE LA TABLA CV403_EVENTOS_COBROS
                dtConsulta = new DataTable();
                dtConsulta.Clear();

                sTabla = "cv403_eventos_cobros ";
                sCampo = "id_evento_cobro";

                iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                if (iMaximo == -1)
                {
                    ok.LblMensaje.Text = "No se pudo obtener el codigo de la tabla " + sTabla;
                    ok.ShowInTaskbar   = false;
                    ok.ShowDialog();
                    goto reversa;
                }

                else
                {
                    iIdEventoCobro_F = Convert.ToInt32(iMaximo);
                }

                //INSTRUCCIONES PARA OBTENER DATOS DE LAS TABLAS CV403_FACTURAS_PEDIDOS Y CV403_NUMEROS_FACTURAS
                sSql  = "";
                sSql += "select FP.id_facturas_pedidos, FP.id_factura, NF.numero_factura" + Environment.NewLine;
                sSql += "from cv403_facturas_pedidos FP, cv403_numeros_facturas NF" + Environment.NewLine;
                sSql += "where FP.id_factura = NF.id_factura" + Environment.NewLine;
                sSql += "and FP.id_pedido = " + Convert.ToInt32(sIdOrden) + Environment.NewLine;
                sSql += "and FP.estado = 'A'" + Environment.NewLine;
                sSql += "and NF.estado = 'A'" + Environment.NewLine;

                dtConsulta = new DataTable();
                dtConsulta.Clear();

                bRespuesta = conexion.GFun_Lo_Busca_Registro(dtConsulta, sSql);

                if (bRespuesta == true)
                {
                    if (dtConsulta.Rows.Count > 0)
                    {
                        iIdFacturasPedidos_F = Convert.ToInt32(dtConsulta.Rows[0][0].ToString());
                        iIdFactura_F         = Convert.ToInt32(dtConsulta.Rows[0][1].ToString());
                        iNumeroFactura_F     = Convert.ToInt32(dtConsulta.Rows[0][2].ToString());
                    }

                    else
                    {
                        ok.LblMensaje.Text = "No existen datos en las tablas cv403_facturas_pedidos" + Environment.NewLine + "y" + Environment.NewLine + "cv403_numeros_facturas";
                        ok.ShowDialog();
                        goto reversa;
                    }
                }

                else
                {
                    catchMensaje.LblMensaje.Text = sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //INSTRUCCION PARA INSERTAR EL MOTIVO DE ANULACIÓN DE LA FACTURA
                sSql  = "";
                sSql += "insert into pos_anulacion_factura (" + Environment.NewLine;
                sSql += "id_factura, motivo_anulacion, estado, fecha_ingreso," + Environment.NewLine;
                sSql += "usuario_ingreso, terminal_ingreso)" + Environment.NewLine;
                sSql += "values (" + Environment.NewLine;
                sSql += iIdFactura_F + ", '" + sMotivoAnulacion + "', 'A'," + Environment.NewLine;
                sSql += "GETDATE(), '" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "')";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //INSTRUCCION PARA INSERTAR EN LA TABLA CV403_DCTOS_POR_COBRAR
                sSql  = "";
                sSql += "Insert Into cv403_dctos_por_cobrar (id_evento_cobro, cg_tipo_documento," + Environment.NewLine;
                sSql += "id_factura, Numero_Documento, Fecha_Vcto, Cg_moneda, Valor, cg_estado_dcto," + Environment.NewLine;
                sSql += "Estado, Fecha_Ingreso, Usuario_Ingreso, Terminal_Ingreso," + Environment.NewLine;
                sSql += "numero_replica_trigger, numero_control_replica)" + Environment.NewLine;
                sSql += "Values (" + Environment.NewLine;
                sSql += iIdEventoCobro_F + ", 2725, " + iIdFactura_F + ", " + iNumeroFactura_F + "," + Environment.NewLine;
                sSql += "'" + sFecha + "', " + Program.iMoneda + ", " + Program.dValorProductoAnular + ", 7460," + Environment.NewLine;
                sSql += "'A', GETDATE(), '" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "', 0, 0)";

                //EJECUTA INSTRUCCION SQL
                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //INSTRUCCION PARA ACTUALIZAR EL ID DEL PEDIDO EN LA TABLA CV403_FACTURAS_PEDIDOS
                sSql  = "";
                sSql += "update cv403_facturas_pedidos set" + Environment.NewLine;
                sSql += "id_pedido = " + iIdCabPedido_F + Environment.NewLine;
                sSql += "where id_facturas_pedidos = " + iIdFacturasPedidos_F;

                //EJECUTA INSTRUCCION SQL
                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //INSTRUCCION PARA DEJAR LOS CAMPOS NULOS EN CV403_DCTOS_POR_COBRAR
                sSql  = "";
                sSql += "update cv403_dctos_por_cobrar set" + Environment.NewLine;
                sSql += "id_factura = null," + Environment.NewLine;
                sSql += "numero_documento = null" + Environment.NewLine;
                sSql += "where id_pedido = " + Convert.ToInt32(sIdOrden);

                //EJECUTA INSTRUCCION SQL
                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                if (eliminarPagos() == false)
                {
                    goto reversa;
                }

                //INSTRUCCION PARA CAMBIAR EL ESTADO A ABIERTA DE LA ORDEN
                sSql  = "";
                sSql += "update cv403_cab_pedidos set" + Environment.NewLine;
                sSql += "estado_orden = 'Abierta'" + Environment.NewLine;
                sSql += "where id_pedido = " + Convert.ToInt32(sIdOrden);

                //EJECUTA INSTRUCCION SQL
                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                conexion.GFun_Lo_Maneja_Transaccion(Program.G_TERMINA_TRANSACCION);

                //if (iOp == 1)
                //{
                //    if (enviarMail() == true)
                //    {
                //        ok.LblMensaje.Text = "No se pudo enviar el informe de anulación de factura al administrador.";
                //    }
                //}

                consultarRegistro();

                //ABRIR EL FORMULARIO DE ORDEN

                Orden o = new Orden(iIdOrigenOrden, sDescripcionOrigen, iNumeroPersonas, iIdMesa, Convert.ToInt32(sIdOrden), "OK", Program.iIdPersona, iIdCajero, iIdMesero, sNombreMesero);
                o.ShowDialog();
                this.DialogResult       = DialogResult.OK;
                Program.iBanderaReabrir = 1;

                goto fin;
            }

            catch (Exception ex)
            {
                catchMensaje.LblMensaje.Text = ex.ToString();
                catchMensaje.ShowInTaskbar   = false;
                catchMensaje.ShowDialog();
            }

reversa:
            {
                conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION);
            }

            fin : { }
        }
Exemple #8
0
        //FUNCION PARA INSERTAR LA COMANDA
        private void insertarComanda()
        {
            try
            {
                Cursor = Cursors.WaitCursor;
                extraerNumeroCuenta();

                sFechaOrden = Program.sFechaSistema.ToString("yyyy/MM/dd");

                if (!conexion.GFun_Lo_Maneja_Transaccion(Program.G_INICIA_TRANSACCION))
                {
                    ok.LblMensaje.Text = "Error al abrir transacción";
                    ok.ShowDialog();
                    return;
                }

                sSql  = "";
                sSql += "insert into cv403_cab_pedidos(" + Environment.NewLine;
                sSql += "idempresa, cg_empresa, id_localidad, fecha_pedido, id_persona, " + Environment.NewLine;
                sSql += "cg_tipo_cliente, cg_moneda, porcentaje_iva, id_vendedor, cg_estado_pedido, porcentaje_dscto, " + Environment.NewLine;
                sSql += "cg_facturado, fecha_ingreso, usuario_ingreso, terminal_ingreso, cuenta, id_pos_mesa, id_pos_cajero, " + Environment.NewLine;
                sSql += "id_pos_origen_orden, id_pos_orden_dividida, id_pos_jornada, fecha_orden, fecha_apertura_orden, " + Environment.NewLine;
                sSql += "fecha_cierre_orden, estado_orden, numero_personas, origen_dato, numero_replica_trigger, " + Environment.NewLine;
                sSql += "estado_replica, numero_control_replica, estado, idtipoestablecimiento, comentarios, id_pos_modo_delivery," + Environment.NewLine;
                sSql += "id_pos_mesero, id_pos_terminal, porcentaje_servicio, consumo_alimentos) " + Environment.NewLine;
                sSql += "values(" + Environment.NewLine;
                sSql += Program.iIdEmpresa + "," + Program.iCgEmpresa + "," + Program.iIdLocalidad + "," + Environment.NewLine;
                sSql += "'" + sFechaOrden + "', " + iIdPersonaEmpresa + ",8032," + Program.iMoneda + "," + Environment.NewLine;
                sSql += (Program.iva * 100) + "," + Program.iIdVendedor + ",6967, 0, 7471," + Environment.NewLine;
                sSql += "GETDATE(),'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "'," + iCuentaDiaria + ", 0, ";
                sSql += Program.iIdCajeroDefault + "," + iIdOrigenOrden + ", 0," + Program.iJORNADA + "," + Environment.NewLine;
                sSql += "'" + sFechaOrden + "', GETDATE(), null, 'Cerrada'," + Environment.NewLine;
                sSql += "1, 1, 1, 0, 0, 'A', 1, null, null," + Environment.NewLine;
                sSql += Program.iIdMesero + ", " + Program.iIdTerminal + ", " + (Program.servicio * 100) + ", 0)";

                Program.iBanderaCliente = 0;

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                sSql  = "";
                sSql += "insert into cv403_cab_despachos (" + Environment.NewLine;
                sSql += "idempresa, id_persona, cg_empresa, id_localidad, fecha_despacho," + Environment.NewLine;
                sSql += "cg_motivo_despacho, id_destinatario, punto_partida, cg_ciudad_entrega," + Environment.NewLine;
                sSql += "direccion_entrega, id_transportador, fecha_inicio_transporte," + Environment.NewLine;
                sSql += "fecha_fin_transporte, cg_estado_despacho, punto_venta, fecha_ingreso," + Environment.NewLine;
                sSql += "usuario_ingreso, terminal_ingreso, estado, numero_replica_trigger, numero_control_replica)" + Environment.NewLine;
                sSql += "values (" + Environment.NewLine;
                sSql += Program.iIdEmpresa + ", " + iIdPersonaEmpresa + ", " + Program.iCgEmpresa + ", " + Program.iIdLocalidad + "," + Environment.NewLine;
                sSql += "'" + sFechaOrden + "', " + Program.iCgMotivoDespacho + ", " + iIdPersonaEmpresa + "," + Environment.NewLine;
                sSql += "'" + Program.sPuntoPartida + "', " + Program.iCgCiudadEntrega + ", '" + Program.sDireccionEntrega + "'," + Environment.NewLine;
                sSql += "'" + Program.iIdPersona + "', '" + sFechaOrden + "', '" + sFechaOrden + "', " + Program.iCgEstadoDespacho + "," + Environment.NewLine;
                sSql += "1, GETDATE(), '" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "', 'A', 1, 0)";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                dtConsulta = new DataTable();
                dtConsulta.Clear();
                sTabla  = "cv403_cab_pedidos";
                sCampo  = "Id_Pedido";
                iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                if (iMaximo == -1)
                {
                    ok.LblMensaje.Text = "No se pudo obtener el codigo de la tabla " + sTabla;
                    ok.ShowDialog();
                    goto reversa;
                }

                iIdPedido = Convert.ToInt32(iMaximo);
                sSql      = "";
                sSql     += "select numero_pedido" + Environment.NewLine;
                sSql     += "from tp_localidades_impresoras" + Environment.NewLine;
                sSql     += "where estado = 'A'" + Environment.NewLine;
                sSql     += "and id_localidad = " + Program.iIdLocalidad;

                dtConsulta = new DataTable();
                dtConsulta.Clear();

                bRespuesta = conexion.GFun_Lo_Busca_Registro(dtConsulta, sSql);

                if (bRespuesta == false)
                {
                    catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                iNumeroPedidoOrden = Convert.ToInt32(dtConsulta.Rows[0][0].ToString());

                sSql  = "";
                sSql += "update tp_localidades_impresoras set" + Environment.NewLine;
                sSql += "numero_pedido = numero_pedido + 1" + Environment.NewLine;
                sSql += "where id_localidad = " + Program.iIdLocalidad;

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                sSql  = "";
                sSql += "insert into cv403_numero_cab_pedido (" + Environment.NewLine;
                sSql += "idtipocomprobante,id_pedido, numero_pedido," + Environment.NewLine;
                sSql += "fecha_ingreso, usuario_ingreso, terminal_ingreso," + Environment.NewLine;
                sSql += "estado, numero_control_replica, numero_replica_trigger)" + Environment.NewLine;
                sSql += "values (" + Environment.NewLine;
                sSql += "1, " + iIdPedido + ", " + iNumeroPedidoOrden + ", GETDATE()," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "', 'A', 0, 0)";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                dtConsulta = new DataTable();
                dtConsulta.Clear();

                sTabla  = "cv403_cab_despachos";
                sCampo  = "id_despacho";
                iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                if (iMaximo == -1)
                {
                    ok.LblMensaje.Text = "No se pudo obtener el codigo de la tabla " + sTabla;
                    ok.ShowDialog();
                    goto reversa;
                }

                iIdCabDespachos = Convert.ToInt32(iMaximo);

                sSql  = "";
                sSql += "insert into cv403_despachos_pedidos (" + Environment.NewLine;
                sSql += "id_despacho, id_pedido, estado, fecha_ingreso, usuario_ingreso," + Environment.NewLine;
                sSql += "terminal_ingreso, numero_replica_trigger, numero_control_replica)" + Environment.NewLine;
                sSql += "values (" + Environment.NewLine;
                sSql += iIdCabDespachos + "," + iIdPedido + ", 'A', GETDATE(), '" + Program.sDatosMaximo[0] + "'," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[1] + "', 1, 0)";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                dtConsulta = new DataTable();
                dtConsulta.Clear();

                sTabla  = "cv403_despachos_pedidos";
                sCampo  = "id_despacho_pedido";
                iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                if (iMaximo == -1)
                {
                    ok.LblMensaje.Text = "No se pudo obtener el codigo de la tabla " + sTabla;
                    ok.ShowDialog();
                    goto reversa;
                }

                iIdDespachoPedido = Convert.ToInt32(iMaximo);

                sSql  = "";
                sSql += "insert into cv403_eventos_cobros (" + Environment.NewLine;
                sSql += "idempresa, cg_empresa, id_persona, id_localidad, cg_evento_cobro," + Environment.NewLine;
                sSql += "fecha_ingreso, usuario_ingreso, terminal_ingreso, estado," + Environment.NewLine;
                sSql += "numero_replica_trigger, numero_control_replica)" + Environment.NewLine;
                sSql += "values(" + Environment.NewLine;
                sSql += Program.iIdEmpresa + ", " + Program.iCgEmpresa + ", " + iIdPersonaEmpresa + "," + Program.iIdLocalidad + "," + Environment.NewLine;
                sSql += "7466, GETDATE(), '" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "', 'A', 1, 0)";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                dtConsulta = new DataTable();
                dtConsulta.Clear();

                sTabla  = "cv403_eventos_cobros";
                sCampo  = "id_evento_cobro";
                iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                if (iMaximo == -1)
                {
                    ok.LblMensaje.Text = "No se pudo obtener el codigo de la tabla " + sTabla;
                    ok.ShowDialog();
                    goto reversa;
                }

                iIdEventoCobro = Convert.ToInt32(iMaximo);

                sSql  = "";
                sSql += "insert into cv403_dctos_por_cobrar (" + Environment.NewLine;
                sSql += "id_evento_cobro, id_pedido, cg_tipo_documento, fecha_vcto, cg_moneda," + Environment.NewLine;
                sSql += "valor, cg_estado_dcto, estado, fecha_ingreso, usuario_ingreso, terminal_ingreso," + Environment.NewLine;
                sSql += "numero_replica_trigger, numero_control_replica)" + Environment.NewLine;
                sSql += "values (" + Environment.NewLine;
                sSql += iIdEventoCobro + ", " + iIdPedido + ", " + iCgTipoDocumento + "," + Environment.NewLine;
                sSql += "'" + sFechaOrden + "', " + Program.iMoneda + ", " + dTotalDebido + "," + Environment.NewLine;
                sSql += "7460, 'A', GETDATE(), '" + Program.sDatosMaximo[0] + "'," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[1] + "', 1, 0)";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                for (int i = 0; i < dgvPedido.Rows.Count; i++)
                {
                    iIdProducto_P     = Convert.ToInt32(dgvPedido.Rows[i].Cells["idProducto"].Value);
                    dPrecioUnitario_P = Convert.ToDecimal(dgvPedido.Rows[i].Cells["valuni"].Value);
                    dCantidad_P       = Convert.ToDecimal(dgvPedido.Rows[i].Cells["cantidad"].Value);
                    sPagaIva_P        = dgvPedido.Rows[i].Cells["pagaIva"].Value.ToString();

                    if (sPagaIva_P == "1")
                    {
                        dIVA_P = dPrecioUnitario_P * Convert.ToDecimal(Program.iva);
                    }

                    else
                    {
                        dIVA_P = 0;
                    }

                    sSql  = "";
                    sSql += "Insert Into cv403_det_pedidos(" + Environment.NewLine;
                    sSql += "Id_Pedido, id_producto, Cg_Unidad_Medida, precio_unitario," + Environment.NewLine;
                    sSql += "Cantidad, Valor_Dscto, Valor_Ice, Valor_Iva ,Valor_otro," + Environment.NewLine;
                    sSql += "comentario, Id_Definicion_Combo, fecha_ingreso," + Environment.NewLine;
                    sSql += "Usuario_Ingreso, Terminal_ingreso, id_pos_mascara_item, secuencia," + Environment.NewLine;
                    sSql += "id_pos_secuencia_entrega, Estado, numero_replica_trigger," + Environment.NewLine;
                    sSql += "numero_control_replica, id_empleado_cliente_empresarial)" + Environment.NewLine;
                    sSql += "values(" + Environment.NewLine;
                    sSql += iIdPedido + ", " + iIdProducto_P + ", 546, " + dPrecioUnitario_P + ", " + Environment.NewLine;
                    sSql += dCantidad_P + ", 0, 0, " + dIVA_P + ", 0, " + Environment.NewLine;
                    sSql += "null, null, GETDATE(), '" + Program.sDatosMaximo[0] + "'," + Environment.NewLine;
                    sSql += "'" + Program.sDatosMaximo[1] + "', 0, 1, null, 'A', 0, 0, " + iIdPersona + ")";

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }

                    sSql  = "";
                    sSql += "insert into cv403_cantidades_despachadas(" + Environment.NewLine;
                    sSql += "id_despacho_pedido, id_producto, cantidad, estado," + Environment.NewLine;
                    sSql += "numero_replica_trigger, numero_control_replica)" + Environment.NewLine;
                    sSql += "values (" + Environment.NewLine;
                    sSql += iIdDespachoPedido + ", " + dgvPedido.Rows[i].Cells["idProducto"].Value + "," + Environment.NewLine;
                    sSql += dgvPedido.Rows[i].Cells["cantidad"].Value + ", 'A', 1, 0)";

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }
                }

                conexion.GFun_Lo_Maneja_Transaccion(Program.G_TERMINA_TRANSACCION);

                if (Program.iImprimirCocina == 1)
                {
                    if (Program.iEjecutarImpresion == 1)
                    {
                        Pedidos.frmVerReporteCocinaTextBox cocina = new Pedidos.frmVerReporteCocinaTextBox(iIdPedido.ToString(), 1);
                        cocina.ShowDialog();
                    }

                    ReportesTextBox.frmVerPrecuentaEmpresaTextBox precuenta = new ReportesTextBox.frmVerPrecuentaEmpresaTextBox(iIdPedido.ToString(), 1);
                    precuenta.ShowDialog();
                }

                ok.LblMensaje.Text = "Guardado en la orden: " + iNumeroPedidoOrden.ToString() + ".";
                ok.ShowDialog();
                Cursor            = Cursors.Default;
                this.DialogResult = DialogResult.OK;
                Close();
                return;
            }

            catch (Exception ex)
            {
                Cursor = Cursors.Default;
                catchMensaje.LblMensaje.Text = ex.Message;
                catchMensaje.ShowDialog();
            }

            reversa : { conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION); }
        }
        //Función para grabar un registro
        private void grabarRegistro(int iBandera)
        {
            try
            {
                string sfecha            = Convert.ToDateTime(txtFechaAplicacion.Text).ToString("yyy/MM/dd");
                int    iCgTipoMovimiento = buscarTipoMovimiento();

                if (iCgTipoMovimiento != 0)
                {
                    //INICIAMOS UNA NUEVA TRANSACCION

                    if (!conexion.GFun_Lo_Maneja_Transaccion(Program.G_INICIA_TRANSACCION))
                    {
                        ok.LblMensaje.Text = "Error al abrir transacción";
                        ok.ShowDialog();
                        goto fin;
                    }

                    string sNumeroMovimiento;

                    if (iBandera == 1)
                    {
                        string sAño      = txtFechaAplicacion.Text.Substring(6, 4);
                        string sMes      = txtFechaAplicacion.Text.Substring(3, 2);
                        int    iIdBodega = Convert.ToInt32(cmbBodega.SelectedValue);

                        //Clases.ObtenerNumeroMovimiento movimiento = new Clases.ObtenerNumeroMovimiento();
                        sNumeroMovimiento = devuelveCorrelativo("TE", iIdBodega, sAño, sMes, "MOV");
                    }
                    else
                    {
                        sNumeroMovimiento = txtNumeroTraslado.Text;
                    }

                    sSql  = "";
                    sSql += "Insert Into cv402_cabecera_movimientos (" + Environment.NewLine;
                    sSql += "CG_EMPRESA, ID_BODEGA, CG_TIPO_MOVIMIENTO, CG_MOTIVO_MOVIMIENTO_BODEGA," + Environment.NewLine;
                    sSql += "CG_CLIENTE_PROVEEDOR, ID_LOCALIDAD, Fecha, CG_MONEDA_BASE, REFERENCIA_EXTERNA," + Environment.NewLine;
                    sSql += "OBSERVACION, NUMERO_MOVIMIENTO, ID_BODEGA_DESTINO, ID_LOCALIDAD_DESTINO," + Environment.NewLine;
                    sSql += "EXTERNO,usuario_ingreso, terminal_ingreso, ESTADO)" + Environment.NewLine;
                    sSql += "Values (" + Environment.NewLine;
                    sSql += Program.iCgEmpresa + ", " + Convert.ToInt32(cmbBodega.SelectedValue) + ", " + iCgTipoMovimiento + "," + Environment.NewLine;
                    sSql += Convert.ToInt32(cmbMotivos.SelectedValue) + ", 6161," + Convert.ToInt32(cmbOficina.SelectedValue) + "," + Environment.NewLine;
                    sSql += "Convert(DateTime,'" + sfecha + "', 120), " + Program.iMoneda + ", '" + txtReferencia.Text.Trim() + "'," + Environment.NewLine;
                    sSql += "'" + txtComentarios.Text.Trim() + "', '" + sNumeroMovimiento + "', " + Convert.ToInt32(cmbBodega2.SelectedValue) + "," + Environment.NewLine;
                    sSql += Convert.ToInt32(cmbOficina2.SelectedValue) + ", 0,'" + Program.sDatosMaximo[0] + "'," + Environment.NewLine;
                    sSql += "'" + Program.sDatosMaximo[1] + "', 'A')";

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        //hara el rolBAck
                        goto reversa;
                    }

                    int NewCodigo = 0;

                    //PROCEDIMINTO PARA EXTRAER EL ID DE LA TABLA CV402_CABECERA_MOVIMIENTOS
                    dtConsulta = new DataTable();
                    dtConsulta.Clear();

                    sTabla = "cv402_cabecera_movimientos";
                    sCampo = "Id_Movimiento_Bodega";;

                    iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                    if (iMaximo == -1)
                    {
                        ok.LblMensaje.Text = "No se pudo obtener el codigo de la tabla " + sTabla;
                        ok.ShowInTaskbar   = false;
                        ok.ShowDialog();
                        goto reversa;
                    }

                    else
                    {
                        NewCodigo = Convert.ToInt32(iMaximo);
                    }


                    for (int i = 0; i < dgvDetalleVenta.Rows.Count; i++)
                    {
                        int    iIdProducto = Convert.ToInt32(dgvDetalleVenta.Rows[i].Cells[7].Value.ToString());
                        string sEspecificacion;
                        if (dgvDetalleVenta.Rows[i].Cells[3].Value != null)
                        {
                            sEspecificacion = dgvDetalleVenta.Rows[i].Cells[3].Value.ToString();
                        }
                        else
                        {
                            sEspecificacion = null;
                        }
                        double dbCantidad = Convert.ToDouble(dgvDetalleVenta.Rows[i].Cells[5].Value.ToString());
                        int    iCorrelativoUnidadCompra = buscarCorrelativoUnidadCompra();

                        if (iCorrelativoUnidadCompra != 0)
                        {
                            sSql  = "";
                            sSql += "Insert Into cv402_movimientos_bodega (" + Environment.NewLine;
                            sSql += "ID_PRODUCTO, ESPECIFICACION, ID_MOVIMIENTO_BODEGA," + Environment.NewLine;
                            sSql += "CG_UNIDAD_COMPRA, CANTIDAD,ESTADO)" + Environment.NewLine;
                            sSql += "values (" + Environment.NewLine;
                            sSql += iIdProducto + ", '" + sEspecificacion + "', " + NewCodigo + "," + Environment.NewLine;
                            sSql += iCorrelativoUnidadCompra + ", -" + dbCantidad.ToString() + ", 'A')";

                            if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                            {
                                //hara el rolBAck
                                goto reversa;
                            }
                        }
                        else
                        {
                            goto reversa;
                        }
                    }

                    conexion.GFun_Lo_Maneja_Transaccion(Program.G_TERMINA_TRANSACCION);
                    MessageBox.Show("Registro Guardado Correctamente");
                    goto fin;
                }
                else
                {
                    goto reversa;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Ocurrió un problema al guardar el registro en la base de datos", "Bodega", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            #region Funciones de ayuda
reversa:
            {
                conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION);
                MessageBox.Show("Ocurrió un problema en la transacción. No se guardarán los cambios");
            }
fin:
            {
                limpiarCampos();
            }
            #endregion
        }
Exemple #10
0
        //FUNCION PARA ACTUALIZAR EN LA BASE DE DATOS
        private void actualizarRegistro()
        {
            try
            {
                //SE INICIA LA TRANSACCIÓN
                if (!conexion.GFun_Lo_Maneja_Transaccion(Program.G_INICIA_TRANSACCION))
                {
                    ok.lblMensaje.Text = "Ocurrió un problema al realizar la transacción. Por favor comuníquese con el administrador en caso de continuar con el inconveniente.";
                    ok.ShowDialog();
                    return;
                }

                //ACTUALIZAR EN LA TABLA TP_PERSONAS
                sSql  = "";
                sSql += "update tp_personas set" + Environment.NewLine;
                sSql += "apellidos = '" + txtApellidos.Text.Trim() + "'," + Environment.NewLine;
                sSql += "nombres = '" + txtNombres.Text.Trim() + "'," + Environment.NewLine;
                sSql += "codigo_alterno = '" + txtTelefono.Text.Trim() + "'," + Environment.NewLine;
                sSql += "correo_electronico = '" + txtMail.Text.Trim() + "'," + Environment.NewLine;
                sSql += "cg_tipo_persona = " + iIdTipoPersona + "," + Environment.NewLine;
                sSql += "cg_tipo_identificacion = " + iIdTipoIdentificacion + Environment.NewLine;
                sSql += "where id_persona = " + iIdPersona + Environment.NewLine;
                sSql += "and estado = 'A'";

                //EJECUTAMOS LA INSTRUCCIÒN SQL
                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.lblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                if (iIdDireccion == 0)
                {
                    //PARA INSERTAR LA DIRECCION
                    sSql  = "";
                    sSql += "Insert Into  tp_direcciones (" + Environment.NewLine;
                    sSql += "id_persona, IdTipoEstablecimiento, Direccion, calle_principal," + Environment.NewLine;
                    sSql += "numero_vivienda, calle_interseccion, referencia," + Environment.NewLine;
                    sSql += "Cg_Localidad, Estado, usuario_ingreso, terminal_ingreso," + Environment.NewLine;
                    sSql += "fecha_ingreso, numero_replica_trigger, numero_control_replica)" + Environment.NewLine;
                    sSql += "Values (" + Environment.NewLine;
                    sSql += iIdPersona + ", 1, '" + txtSector.Text.Trim().ToUpper() + "', '" + txtPrincipal.Text.Trim().ToUpper() + "'," + Environment.NewLine;
                    sSql += "'" + txtNumeracion.Text.Trim().ToUpper() + "','" + txtSecundaria.Text.Trim().ToUpper() + "'," + Environment.NewLine;
                    sSql += "'" + txtReferencia.Text.Trim().ToUpper() + "', " + Program.iCgLocalidad + "," + Environment.NewLine;
                    sSql += "'A','" + Program.sDatosMaximo[0] + "','" + Program.sDatosMaximo[1] + "'," + Environment.NewLine;
                    sSql += "GetDate(), 0, 0)";

                    //EJECUTAMOS LA INSTRUCCIÒN SQL
                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.lblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }

                    sTabla = "tp_direcciones";
                    sCampo = "correlativo";

                    iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                    if (iMaximo == -1)
                    {
                        ok.lblMensaje.Text = "No se pudo obtener el codigo de la tabla " + sTabla;
                        ok.ShowDialog();
                        goto reversa;
                    }

                    iIdDireccion = Convert.ToInt32(iMaximo);
                }

                else
                {
                    //ACTUALIZAMOS LA TABLA DE DIRECCIONES
                    //=================================================================================================================
                    sSql  = "";
                    sSql += "update tp_direcciones set" + Environment.NewLine;
                    sSql += "direccion = '" + txtSector.Text.Trim() + "'," + Environment.NewLine;
                    sSql += "calle_principal = '" + txtPrincipal.Text.Trim() + "'," + Environment.NewLine;
                    sSql += "calle_interseccion = '" + txtSecundaria.Text.Trim() + "'," + Environment.NewLine;
                    sSql += "numero_vivienda = '" + txtNumeracion.Text.Trim() + "'," + Environment.NewLine;
                    sSql += "referencia = '" + txtReferencia.Text.Trim() + "'" + Environment.NewLine;
                    sSql += "where correlativo = " + iIdDireccion;

                    //EJECUTAMOS LA INSTRUCCIÒN SQL
                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.lblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }
                }

                if (iIdTelefono == 0)
                {
                    //PARA INSERTAR EL TELEFONO
                    sSql  = "";
                    sSql += "Insert Into tp_telefonos (" + Environment.NewLine;
                    sSql += "id_persona, idTipoEstablecimiento, CODIGO_AREA," + Environment.NewLine;
                    sSql += "domicilio, Estado, fecha_ingreso, usuario_ingreso," + Environment.NewLine;
                    sSql += "terminal_ingreso, numero_replica_trigger, numero_control_replica)" + Environment.NewLine;
                    sSql += "Values (" + Environment.NewLine;
                    sSql += iIdPersona + ", 1, '02','" + txtTelefono.Text.Trim() + "','A', GetDate()," + Environment.NewLine;
                    sSql += "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "', 0, 0)";

                    //EJECUTAMOS LA INSTRUCCIÒN SQL
                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.lblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }

                    sTabla = "tp_telefonos";
                    sCampo = "correlativo";

                    iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                    if (iMaximo == -1)
                    {
                        ok.lblMensaje.Text = "No se pudo obtener el codigo de la tabla " + sTabla;
                        ok.ShowDialog();
                        goto reversa;
                    }

                    iIdTelefono = Convert.ToInt32(iMaximo);
                }

                else
                {
                    //ACTUALIZAMOS LA TABLA DE TELEFONOS
                    //=================================================================================================================
                    sSql  = "";
                    sSql += "update tp_telefonos set" + Environment.NewLine;
                    sSql += "domicilio = '" + txtTelefono.Text.Trim() + "'" + Environment.NewLine;
                    sSql += "where correlativo = " + iIdTelefono;

                    //EJECUTAMOS LA INSTRUCCIÒN SQL
                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.lblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }
                }

                conexion.GFun_Lo_Maneja_Transaccion(Program.G_TERMINA_TRANSACCION);

                ok.lblMensaje.Text = "Su registro se ha actualizado con éxito";
                ok.ShowDialog();
                this.DialogResult = DialogResult.OK;
                return;
            }

            catch (Exception ex)
            {
                catchMensaje.lblMensaje.Text = ex.Message;
                catchMensaje.ShowDialog();
                goto reversa;
            }

            reversa : { conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION); }
        }
Exemple #11
0
        //FUNCION PARA

        //INSERTAR UN NUEVO CLIENTE
        private void insertarCliente()
        {
            try
            {
                //INICIAR LA TRANSACCION
                if (!conexion.GFun_Lo_Maneja_Transaccion(Program.G_INICIA_TRANSACCION))
                {
                    ok = new VentanasMensajes.frmMensajeOK();
                    ok.LblMensaje.Text = "Error al abrir transacción.";
                    ok.ShowDialog();
                    return;
                }

                if (txtIdentificacion.Text.Trim().Length == 13)
                {
                    int iTercero = Convert.ToInt32(txtIdentificacion.Text.Trim().Substring(2, 1));

                    iIdTipoIdentificacion = 179;

                    if (iTercero == 9)
                    {
                        iIdTipoPersona = 2448;
                    }

                    else if (iTercero == 6)
                    {
                        iIdTipoPersona = 2448;
                    }

                    else if (iTercero < 6)
                    {
                        iIdTipoPersona = 2447;
                    }
                }

                else if (txtIdentificacion.Text.Trim().Length == 10)
                {
                    iIdTipoIdentificacion = 178;
                    iIdTipoPersona        = 2447;
                }

                else
                {
                    iIdTipoIdentificacion = 180;
                    iIdTipoPersona        = 2447;
                }

                //INSTRUCCION PARA INSERTAR UN NUEVO CLIENTE EN  LA TABLA TP_PERSONAS
                sSql = "";
                sSql = sSql + "Insert Into tp_personas (" + Environment.NewLine;
                sSql = sSql + "idempresa, Cg_Tipo_Persona, Cg_Pais_Residencia," + Environment.NewLine;
                sSql = sSql + "Cg_Tipo_Identificacion, Identificacion, Nombres, Apellidos, Cliente," + Environment.NewLine;
                sSql = sSql + "Correo_Electronico, codigo_alterno, Estado, Usuario_Ingreso, terminal_ingreso,contador," + Environment.NewLine;
                sSql = sSql + "porcentaje_descuento, hacerlaretencionfuenteir, numero_replica_trigger," + Environment.NewLine;
                sSql = sSql + "numero_control_replica ) " + Environment.NewLine;
                sSql = sSql + "Values (" + Environment.NewLine;
                sSql = sSql + Program.iIdEmpresa + ", " + iIdTipoPersona + ", 2843, " + iIdTipoIdentificacion + "," + Environment.NewLine;
                sSql = sSql + "'" + txtIdentificacion.Text.Trim() + "', '" + txtNombres.Text.Trim() + "'," + Environment.NewLine;
                sSql = sSql + "'" + txtApellidos.Text.Trim() + "', 1, '" + txtMail.Text.Trim() + "', '" + txtTelefono.Text.Trim() + "'," + Environment.NewLine;
                sSql = sSql + "'A','" + Program.sDatosMaximo[0] + "','" + Program.sDatosMaximo[1] + "',0,0,0,0,0 )";

                //EJECUTAMOS LA INSTRUCCIÒN SQL
                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje = new VentanasMensajes.frmMensajeCatch();
                    catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //PROCEDIMINTO PARA EXTRAER EL ID DEL PRODUCTO REGISTRADO
                dtConsulta = new DataTable();
                dtConsulta.Clear();

                string sTabla = "tp_personas";
                string sCampo = "id_persona";

                long iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                if (iMaximo == -1)
                {
                    ok = new VentanasMensajes.frmMensajeOK();
                    ok.LblMensaje.Text = "No se pudo obtener el codigo del cliente.";
                    ok.ShowDialog();
                    goto reversa;
                }

                else
                {
                    iIdPersona = Convert.ToInt32(iMaximo);
                }

                //INSTRUCCION PARA INSERTAR EN LA TABLA TP_DIRECCIONES
                sSql = "";
                sSql = sSql + "Insert Into  tp_direcciones (" + Environment.NewLine;
                sSql = sSql + "id_persona,IdTipoEstablecimiento, " + Environment.NewLine;
                sSql = sSql + "Direccion,calle_principal,numero_vivienda,calle_interseccion, referencia," + Environment.NewLine;
                sSql = sSql + "Cg_Localidad,Estado,usuario_ingreso,terminal_ingreso, " + Environment.NewLine;
                sSql = sSql + "fecha_ingreso,numero_replica_trigger,numero_control_replica) " + Environment.NewLine;
                sSql = sSql + "Values (" + Environment.NewLine;
                sSql = sSql + iIdPersona + ", 1, '" + txtSector.Text.Trim() + "'," + Environment.NewLine;
                sSql = sSql + "'" + txtCallePrincipal.Text.Trim() + "','" + txtNumeracion.Text.Trim() + "'," + Environment.NewLine;
                sSql = sSql + "'" + txtCalleSecundaria.Text.Trim() + "', '" + txtReferencia.Text.Trim() + "'," + Environment.NewLine;
                sSql = sSql + Program.iCgLocalidad + ", 'A','" + Program.sDatosMaximo[0] + "','" + Program.sDatosMaximo[1] + "', GetDate(),0,0 )";

                //EJECUTAMOS LA INSTRUCCIÒN SQL
                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje = new VentanasMensajes.frmMensajeCatch();
                    catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //PARA INSERTAR EL TELEFONO EN LA TABLA TP_TELEFONOS
                sSql = "";
                sSql = sSql + "Insert Into tp_telefonos (" + Environment.NewLine;
                sSql = sSql + "id_persona,idTipoEstablecimiento, " + Environment.NewLine;
                sSql = sSql + "CODIGO_AREA,domicilio,celular,Estado,fecha_ingreso, usuario_ingreso, " + Environment.NewLine;
                sSql = sSql + "terminal_ingreso,numero_replica_trigger,numero_control_replica ) " + Environment.NewLine;
                sSql = sSql + "Values (" + iIdPersona + ", 1, '02'," + Environment.NewLine;

                if (txtTelefono.Text.Substring(0, 2) == "09")
                {
                    sSql = sSql + " '', '" + txtTelefono.Text.Trim() + "'" + Environment.NewLine;
                }

                else
                {
                    sSql = sSql + " '" + txtTelefono.Text.Trim() + "', ''" + Environment.NewLine;
                }

                sSql = sSql + ",'A', GetDate(), '" + Program.sDatosMaximo[0] + "'," + Environment.NewLine;
                sSql = sSql + "'" + Program.sDatosMaximo[1] + "', 0,0 )";

                //EJECUTAMOS LA INSTRUCCIÒN SQL
                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje = new VentanasMensajes.frmMensajeCatch();
                    catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                conexion.GFun_Lo_Maneja_Transaccion(Program.G_TERMINA_TRANSACCION);

                ok = new VentanasMensajes.frmMensajeOK();
                ok.LblMensaje.Text = "Cliente registrado éxitosamente";
                ok.ShowDialog();

                if (ok.DialogResult == DialogResult.OK)
                {
                    iCodigo         = iIdPersona;
                    sIdentificacion = txtIdentificacion.Text.Trim();
                    sNombre         = txtNombres.Text.Trim();
                    sApellido       = txtApellidos.Text.Trim();
                    sTelefono       = txtTelefono.Text.Trim();
                    sMail           = txtMail.Text.Trim();
                    sDireccion      = txtSector.Text.Trim() + ", " + txtCallePrincipal.Text.Trim() + " " +
                                      txtNumeracion.Text.Trim() + " " + txtCalleSecundaria.Text.Trim();
                    sCiudad           = txtSector.Text.Trim();
                    this.DialogResult = DialogResult.OK;
                    return;
                }
            }

            catch (Exception ex)
            {
                catchMensaje = new VentanasMensajes.frmMensajeCatch();
                catchMensaje.LblMensaje.Text = ex.Message;
                catchMensaje.ShowDialog();
                goto reversa;
            }

reversa:
            {
                conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION);
            }
        }
Exemple #12
0
        //FUNCION PARA INSERTAR EN LA BASE DE DATOS
        private void insertarRegistro()
        {
            try
            {
                //SE INICIA LA TRANSACCIÓN
                if (!conexion.GFun_Lo_Maneja_Transaccion(Program.G_INICIA_TRANSACCION))
                {
                    ok.LblMensaje.Text = "Ocurrió un problema al realizar la transacción. Por favor comuníquese con el administrador en caso de continuar con el inconveniente.";
                    ok.ShowDialog();
                    //Limpiar();
                    goto reversa;
                }

                else
                {
                    sSql = "";
                    sSql = sSql + "Insert Into tp_personas (" + Environment.NewLine;
                    sSql = sSql + "idempresa, Cg_Tipo_Persona, Cg_Pais_Residencia," + Environment.NewLine;
                    sSql = sSql + "Cg_Tipo_Identificacion, Identificacion, Nombres, Apellidos," + Environment.NewLine;
                    sSql = sSql + "Cliente, codigo_alterno, correo_electronico, estado, fecha_ingreso, Usuario_Ingreso," + Environment.NewLine;
                    sSql = sSql + "terminal_ingreso,contador, porcentaje_descuento," + Environment.NewLine;
                    sSql = sSql + "hacerlaretencionfuenteir,numero_replica_trigger, numero_control_replica)" + Environment.NewLine;
                    sSql = sSql + "Values (" + Environment.NewLine;
                    sSql = sSql + Program.iIdEmpresa + ", " + iIdTipoPersona + ", 2843, " + iIdTipoIdentificacion + ", '" + txtIdentificacion.Text.Trim() + "'," + Environment.NewLine;
                    sSql = sSql + "'" + txtNombres.Text.Trim() + "', '" + txtApellidos.Text.Trim() + "', 1," + Environment.NewLine;
                    sSql = sSql + "'" + txtTelefono.Text.Trim() + "', " + txtMail.Text.Trim() + ", 'A', GETDATE()," + Environment.NewLine;
                    sSql = sSql + "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "',0,0,0,0,0 )";

                    //EJECUTAMOS LA INSTRUCCIÒN SQL
                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.LblMensaje.Text = sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }


                    //PROCEDIMINTO PARA EXTRAER EL ID DE LA TABLA TP_PERSONAS
                    dtConsulta = new DataTable();
                    dtConsulta.Clear();

                    sTabla = "tp_personas";
                    sCampo = "id_persona";

                    iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                    if (iMaximo == -1)
                    {
                        ok.LblMensaje.Text = "No se pudo obtener el codigo de la tabla " + sTabla;
                        ok.ShowDialog();
                        goto reversa;
                    }

                    else
                    {
                        iIdPersona = Convert.ToInt32(iMaximo);
                    }

                    //PARA INSERTAR LA DIRECCION
                    sSql = "";
                    sSql = sSql + "Insert Into  tp_direcciones (" + Environment.NewLine;
                    sSql = sSql + "id_persona, IdTipoEstablecimiento, Direccion, calle_principal," + Environment.NewLine;
                    sSql = sSql + "numero_vivienda, calle_interseccion, referencia," + Environment.NewLine;
                    sSql = sSql + "Cg_Localidad, Estado, usuario_ingreso, terminal_ingreso," + Environment.NewLine;
                    sSql = sSql + "fecha_ingreso, numero_replica_trigger, numero_control_replica)" + Environment.NewLine;
                    sSql = sSql + "Values (" + Environment.NewLine;
                    sSql = sSql + iIdPersona + ", 1, '" + txtSector.Text.Trim() + "', '" + txtPrincipal.Text.Trim() + "'," + Environment.NewLine;
                    sSql = sSql + "'" + txtNumeracion.Text.Trim() + "','" + txtSecundaria.Text.Trim() + "'," + Environment.NewLine;
                    sSql = sSql + "'" + txtReferencia.Text.Trim() + "', " + Program.iCgLocalidad + "," + Environment.NewLine;
                    sSql = sSql + "'A','" + Program.sDatosMaximo[0] + "','" + Program.sDatosMaximo[1] + "'," + Environment.NewLine;
                    sSql = sSql + "GetDate(), 0, 0)";

                    //EJECUTAMOS LA INSTRUCCIÒN SQL
                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.LblMensaje.Text = sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }

                    //PARA INSERTAR EL TELEFONO
                    sSql = "";
                    sSql = sSql + "Insert Into tp_telefonos (" + Environment.NewLine;
                    sSql = sSql + "id_persona, idTipoEstablecimiento, CODIGO_AREA," + Environment.NewLine;
                    sSql = sSql + "domicilio, Estado, fecha_ingreso, usuario_ingreso," + Environment.NewLine;
                    sSql = sSql + "terminal_ingreso, numero_replica_trigger, numero_control_replica)" + Environment.NewLine;
                    sSql = sSql + "Values (" + Environment.NewLine;
                    sSql = sSql + iIdPersona + ", 1, '02','" + txtTelefono.Text.Trim() + "','A', GetDate()," + Environment.NewLine;
                    sSql = sSql + "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "', 0, 0)";

                    //EJECUTAMOS LA INSTRUCCIÒN SQL
                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.LblMensaje.Text = sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }

                    conexion.GFun_Lo_Maneja_Transaccion(Program.G_TERMINA_TRANSACCION);
                    ok.LblMensaje.Text = "El registro se ha guardado con éxito.";
                    ok.ShowInTaskbar   = false;
                    Program.sIDPERSONA = iIdPersona.ToString();;
                    ok.ShowDialog();

                    if (ok.DialogResult == DialogResult.OK)
                    {
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                    goto fin;
                }
            }
            catch (Exception ex)
            {
                catchMensaje.LblMensaje.Text = ex.ToString();
                catchMensaje.ShowDialog();
                goto reversa;
            }

reversa:
            {
                conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION);
            }
            fin : { }
        }
Exemple #13
0
        //FUNCION PARA INSERTAR EN LA BASE DE DATOS
        private void insertarRegistros()
        {
            try
            {
                if (!conexion.GFun_Lo_Maneja_Transaccion(Program.G_INICIA_TRANSACCION))
                {
                    ok.lblMensaje.Text = "Error al iniciar la transacción para guardar los registros.";
                    ok.ShowDialog();
                    return;
                }

                for (int i = 0; i < dgvDatos.Rows.Count; i++)
                {
                    sIdentificacion = dgvDatos.Rows[i].Cells[0].Value.ToString();
                    sApellidos      = dgvDatos.Rows[i].Cells[1].Value.ToString();
                    sNombres        = dgvDatos.Rows[i].Cells[2].Value.ToString();

                    iTipoIdentificacion = Convert.ToInt32(dgvDatos.Rows[i].Cells[3].Value.ToString());
                    iTipoPersona        = Convert.ToInt32(dgvDatos.Rows[i].Cells[4].Value.ToString());

                    //PRIMERO CONSULTAMOS EL REGISTRO EN LA BASE DE DATOS
                    sSql  = "";
                    sSql += "select count(*) cuenta" + Environment.NewLine;
                    sSql += "from tp_personas" + Environment.NewLine;
                    sSql += "where identificacion = '" + sIdentificacion + "'" + Environment.NewLine;
                    sSql += "and estado = 'A'";

                    dtConsulta = new DataTable();
                    dtConsulta.Clear();

                    bRespuesta = conexion.GFun_Lo_Busca_Registro(dtConsulta, sSql);

                    if (bRespuesta == false)
                    {
                        conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION);
                        catchMensaje.lblMensaje.Text = "ERROR EN LA INSTRUCCION:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        break;
                    }

                    if (Convert.ToInt32(dtConsulta.Rows[0][0].ToString()) != 0)
                    {
                        goto continuar;
                    }

                    sSql  = "";
                    sSql += "insert into tp_personas (" + Environment.NewLine;
                    sSql += "idempresa, cg_tipo_persona, cg_tipo_identificacion, identificacion," + Environment.NewLine;
                    sSql += "nombres, apellidos, estado, fecha_ingreso, usuario_ingreso, terminal_ingreso," + Environment.NewLine;
                    sSql += "numero_replica_trigger, numero_control_replica)" + Environment.NewLine;
                    sSql += "values (" + Environment.NewLine;
                    sSql += Program.iIdEmpresa + ", " + iTipoPersona + ", " + iTipoIdentificacion + ", ";
                    sSql += "'" + sIdentificacion + "', '" + sNombres + "', '" + sApellidos + "'," + Environment.NewLine;
                    sSql += "'A', GETDATE(), '" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "', 0, 0)";

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION);
                        catchMensaje.lblMensaje.Text = "ERROR EN LA INSTRUCCION:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        break;
                    }

                    sTabla = "tp_personas";
                    sCampo = "id_persona";

                    long iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                    if (iMaximo == -1)
                    {
                        conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION);
                        ok.lblMensaje.Text = "No se pudo obtener el codigo del cliente.";
                        ok.ShowDialog();
                        break;
                    }

                    iIdPersona = Convert.ToInt32(iMaximo);

                    //INSTRUCCION PARA INSERTAR EN LA TABLA TP_DIRECCIONES
                    sSql  = "";
                    sSql += "Insert Into tp_direcciones (" + Environment.NewLine;
                    sSql += "id_persona, IdTipoEstablecimiento, cg_Localidad, direccion, estado," + Environment.NewLine;
                    sSql += "fecha_ingreso, usuario_ingreso,terminal_ingreso," + Environment.NewLine;
                    sSql += "numero_replica_trigger,numero_control_replica) " + Environment.NewLine;
                    sSql += "Values (" + Environment.NewLine;
                    sSql += iIdPersona + ", 1, " + Program.iCgLocalidad + ", ";
                    sSql += "'QUITO', 'A', GETDATE(), '" + Program.sDatosMaximo[0] + "','" + Program.sDatosMaximo[1] + "', 0, 0)";

                    //EJECUTAMOS LA INSTRUCCIÒN SQL
                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION);
                        catchMensaje.lblMensaje.Text = "ERROR EN LA INSTRUCCION:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        break;
                    }

                    //PARA INSERTAR EL TELEFONO EN LA TABLA TP_TELEFONOS
                    sSql  = "";
                    sSql += "Insert Into tp_telefonos (" + Environment.NewLine;
                    sSql += "id_persona, idTipoEstablecimiento, codigo_area, domicilio," + Environment.NewLine;
                    sSql += "estado, fecha_ingreso, usuario_ingreso, terminal_ingreso," + Environment.NewLine;
                    sSql += "numero_replica_trigger,numero_control_replica ) " + Environment.NewLine;
                    sSql += "Values (" + Environment.NewLine;
                    sSql += iIdPersona + ", 1, '02', '2222222', 'A', GETDATE()," + Environment.NewLine;
                    sSql += "'" + Program.sDatosMaximo[0] + "','" + Program.sDatosMaximo[1] + "', 0, 0)";

                    //EJECUTAMOS LA INSTRUCCIÒN SQL
                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION);
                        catchMensaje.lblMensaje.Text = "ERROR EN LA INSTRUCCION:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        break;
                    }

                    //INSERTAMOS EN LA TABLA POS_EMPLEADOS
                    sSql  = "";
                    sSql += "insert into pos_empleado_cliente (" + Environment.NewLine;
                    sSql += "id_pos_cliente_empresarial, id_persona, aplica_almuerzo," + Environment.NewLine;
                    sSql += "estado, fecha_ingreso, usuario_ingreso, terminal_ingreso)" + Environment.NewLine;
                    sSql += "values (" + Environment.NewLine;
                    sSql += dgvDatos.Rows[i].Cells[5].Value.ToString() + ", " + iIdPersona + ", ";
                    sSql += "1, 'A', GETDATE()," + Environment.NewLine;
                    sSql += "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "')";

                    //EJECUTAMOS LA INSTRUCCIÒN SQL
                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION);
                        catchMensaje.lblMensaje.Text = "ERROR EN LA INSTRUCCION:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        break;
                    }

                    continuar : { }
                }

                sSql  = "";
                sSql += "update pos_parametro_localidad set" + Environment.NewLine;
                sSql += "secuencia_codigo_empleado_cliente = " + iSecuencia + Environment.NewLine;
                sSql += "where id_localidad = " + Program.iIdLocalidad + Environment.NewLine;
                sSql += "and estado = 'A'";

                //EJECUTAMOS LA INSTRUCCIÒN SQL
                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION);
                    catchMensaje.lblMensaje.Text = "ERROR EN LA INSTRUCCION:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    return;
                }

                conexion.GFun_Lo_Maneja_Transaccion(Program.G_TERMINA_TRANSACCION);

                ok.lblMensaje.Text = "Registros ingresados éxitosamente";
                ok.ShowDialog();

                limpiar();
            }

            catch (Exception ex)
            {
                catchMensaje.lblMensaje.Text = ex.Message;
                catchMensaje.ShowDialog();
            }
        }
        //FUNCION PARA INSERTAR
        private void insertarRegistro()
        {
            try
            {
                sFecha = Program.sFechaSistema.ToString("yyyy/MM/dd");

                //AQUI INICIA PROCESO DE ACTUALIZACION
                if (!conexion.GFun_Lo_Maneja_Transaccion(Program.G_INICIA_TRANSACCION))
                {
                    ok.LblMensaje.Text = "Error al abrir transacción.";
                    ok.ShowDialog();
                    limpiar();
                    goto fin;
                }

                //INSTRUCCION INSERTAR EN LA TABLA POS_MOVIMIENTO_CAJA
                sSql  = "";
                sSql += "insert into pos_movimiento_caja (" + Environment.NewLine;
                sSql += "tipo_movimiento, idempresa, id_localidad, id_persona," + Environment.NewLine;
                sSql += "id_caja, id_pos_cargo, fecha, hora, cg_moneda, valor, concepto," + Environment.NewLine;
                sSql += "id_pos_jornada, estado, fecha_ingreso, usuario_ingreso, terminal_ingreso)" + Environment.NewLine;
                sSql += "values (" + Environment.NewLine;
                sSql += iTipoMovimiento + ", " + Program.iIdEmpresa + ", " + Program.iIdLocalidad + "," + Environment.NewLine;
                sSql += Convert.ToInt32(cmbEmpleados.SelectedValue) + ", " + Convert.ToInt32(cmbCaja.SelectedValue) + "," + Environment.NewLine;
                sSql += Convert.ToInt32(cmbCargo.SelectedValue) + ", '" + sFecha + "', GETDATE()," + Environment.NewLine;
                sSql += Program.iMoneda + ", " + Convert.ToDouble(txtValor.Text.Trim()) + "," + Environment.NewLine;
                sSql += "'" + txtConcepto.Text.Trim() + "', " + Program.iJORNADA + ", 'A', GETDATE()," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "')";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //PROCEDIMINTO PARA EXTRAER EL ID DE LA TABLA POS_MOVIMIENTO_CAJA
                dtConsulta = new DataTable();
                dtConsulta.Clear();

                sTabla = "pos_movimiento_caja";
                sCampo = "id_pos_movimiento_caja";;

                long iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                if (iMaximo == -1)
                {
                    ok.LblMensaje.Text = "No se pudo obtener el codigo del movimiento.";
                    ok.ShowDialog();
                    goto reversa;
                }

                else
                {
                    iIdPosMovimientoCaja = Convert.ToInt32(iMaximo);
                }

                //INSTRUCCION INSERTAR EN LA TABLA POS_NUMERO_MOVIMIENTO_CAJA
                sSql  = "";
                sSql += "insert into pos_numero_movimiento_caja (" + Environment.NewLine;
                sSql += "id_pos_movimiento_caja, numero_movimiento_caja, estado," + Environment.NewLine;
                sSql += "fecha_ingreso, usuario_ingreso, terminal_ingreso)" + Environment.NewLine;
                sSql += "values (" + Environment.NewLine;
                sSql += iIdPosMovimientoCaja + ", " + Convert.ToInt32(txtNumero.Text.Trim()) + "," + Environment.NewLine;
                sSql += "'A', GETDATE(), '" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "')";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                //INSTRUCCION ACTUALIZAR EL NUMERO DE MOVIMIENTO EN TP_LOCALIDADES_IMPRESORAS
                sSql  = "";
                sSql += "update tp_localidades_impresoras set" + Environment.NewLine;
                sSql += "numeromovimientocaja = numeromovimientocaja + 1" + Environment.NewLine;
                sSql += "where id_localidad = " + Program.iIdLocalidad + Environment.NewLine;
                sSql += "and estado = 'A'";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                conexion.GFun_Lo_Maneja_Transaccion(Program.G_TERMINA_TRANSACCION);
                ok.LblMensaje.Text = "Movimiento ingresado éxitosamente.";
                ok.ShowDialog();
                llenarGrid(1);
                limpiar();

                goto fin;
            }

            catch (Exception ex)
            {
                catchMensaje.LblMensaje.Text = ex.ToString();
                catchMensaje.ShowDialog();
                goto reversa;
            }

reversa:
            {
                conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION);
            }

            fin : { }
        }
Exemple #15
0
        //FUNCION PARA INSERTAR LA FACTURA
        private bool insertarFactura()
        {
            try
            {
                //SELECCIONAR LOS DATOS DE LA LOCALIDAD
                //----------------------------------------------------------------------------------------------------
                sSql  = "";
                sSql += "select L.establecimiento, L.punto_emision, " + Environment.NewLine;
                sSql += "P.numero_factura, P.numero_pago, P.id_localidad_impresora" + Environment.NewLine;
                sSql += "from tp_localidades L, tp_localidades_impresoras P " + Environment.NewLine;
                sSql += "where L.id_localidad = P.id_localidad" + Environment.NewLine;
                sSql += "and L.id_localidad = " + Program.iIdLocalidad + Environment.NewLine;
                sSql += "and L.estado = 'A'" + Environment.NewLine;
                sSql += "and P.estado = 'A'";

                dtConsulta = new DataTable();
                dtConsulta.Clear();

                bRespuesta = conexion.GFun_Lo_Busca_Registro(dtConsulta, sSql);

                if (bRespuesta == false)
                {
                    catchMensaje.lblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    return(false);
                }

                sEstablecimiento      = dtConsulta.Rows[0]["establecimiento"].ToString();
                sPuntoEmision         = dtConsulta.Rows[0]["punto_emision"].ToString();
                sNumeroFactura        = dtConsulta.Rows[0]["numero_factura"].ToString();
                sNumeroPago           = dtConsulta.Rows[0]["numero_pago"].ToString();
                iIdLocalidadImpresora = Convert.ToInt32(dtConsulta.Rows[0]["id_localidad_impresora"].ToString());

                //SELECCIONAR LOS DATOS DEL CLIENTE
                //----------------------------------------------------------------------------------------------------
                sSql  = "";
                sSql += "SELECT TP.identificacion, isnull(TP.nombres, '') nombres, TP.apellidos, TP.correo_electronico," + Environment.NewLine;
                sSql += "TD.direccion + ', ' + TD.calle_principal + ' ' + TD.numero_vivienda + ' ' + TD.calle_interseccion direccion_cliente," + Environment.NewLine;
                sSql += conexion.GFun_St_esnulo() + "(TT.domicilio, TT.oficina) telefono_domicilio, TT.celular, TD.direccion" + Environment.NewLine;
                sSql += "FROM tp_personas TP" + Environment.NewLine;
                sSql += "LEFT OUTER JOIN tp_direcciones TD ON TP.id_persona = TD.id_persona" + Environment.NewLine;
                sSql += "and TP.estado = 'A'" + Environment.NewLine;
                sSql += "and TD.estado = 'A'" + Environment.NewLine;
                sSql += "LEFT OUTER JOIN tp_telefonos TT ON TP.id_persona = TT.id_persona" + Environment.NewLine;
                sSql += "and TT.estado = 'A'" + Environment.NewLine;
                sSql += "WHERE TP.id_persona = " + iIdPersona;

                dtConsulta = new DataTable();
                dtConsulta.Clear();

                bRespuesta = conexion.GFun_Lo_Busca_Registro(dtConsulta, sSql);

                if (bRespuesta == false)
                {
                    catchMensaje.lblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    return(false);
                }

                sIdentificacion    = dtConsulta.Rows[0]["identificacion"].ToString();
                sCliente           = (dtConsulta.Rows[0]["nombres"].ToString().Trim().ToUpper() + " " + dtConsulta.Rows[0]["apellidos"].ToString().Trim().ToUpper()).Trim();
                sCorreoElectronico = dtConsulta.Rows[0]["correo_electronico"].ToString().Trim().ToLower();
                sDireccion         = dtConsulta.Rows[0]["direccion_cliente"].ToString().Trim().ToUpper();
                sCiudadFactura     = dtConsulta.Rows[0]["direccion"].ToString().Trim().ToUpper();

                if (dtConsulta.Rows[0]["telefono_domicilio"].ToString().Trim() != "")
                {
                    sTelefono = dtConsulta.Rows[0]["telefono_domicilio"].ToString().Trim();
                }

                else
                {
                    dtConsulta.Rows[0]["celular"].ToString().Trim();
                }

                //SELECCIONAR LOS DATOS DEL METODO PAGO
                //----------------------------------------------------------------------------------------------------
                sSql  = "";
                sSql += "select FC.id_pos_metodo_pago, FPA.id_forma_pago, FC.cg_tipo_documento" + Environment.NewLine;
                sSql += "from pos_tipo_forma_cobro FC INNER JOIN" + Environment.NewLine;
                sSql += "pos_metodo_pago MP ON MP.id_pos_metodo_pago = FC.id_pos_metodo_pago" + Environment.NewLine;
                sSql += "and MP.estado = 'A'" + Environment.NewLine;
                sSql += "and FC.estado = 'A' INNER JOIN" + Environment.NewLine;
                sSql += "sri_forma_pago SFP ON SFP.id_sri_forma_pago = MP.id_sri_forma_pago" + Environment.NewLine;
                sSql += "and SFP.estado = 'A' INNER JOIN" + Environment.NewLine;
                sSql += "cv403_formas_pagos FPA ON SFP.id_sri_forma_pago = FPA.id_sri_forma_pago" + Environment.NewLine;
                sSql += "and FPA.estado = 'A'" + Environment.NewLine;
                sSql += "where MP.codigo = 'CR'" + Environment.NewLine;
                sSql += "and FPA.id_localidad = " + Program.iIdLocalidad;

                dtConsulta = new DataTable();
                dtConsulta.Clear();

                bRespuesta = conexion.GFun_Lo_Busca_Registro(dtConsulta, sSql);

                if (bRespuesta == false)
                {
                    catchMensaje.lblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    return(false);
                }

                if (dtConsulta.Rows.Count == 0)
                {
                    ok.lblMensaje.Text = "No se encuentra configurado el registro para cobros. Comuníquese con el administrador.";
                    ok.ShowDialog();
                    return(false);
                }

                iIdTipoFormaCobro = Convert.ToInt32(dtConsulta.Rows[0]["id_pos_metodo_pago"].ToString());
                iIdFormaPago      = Convert.ToInt32(dtConsulta.Rows[0]["id_forma_pago"].ToString());
                iCgTipoDocumento  = Convert.ToInt32(dtConsulta.Rows[0]["cg_tipo_documento"].ToString());

                sFecha = Program.sFechaSistema.ToString("yyyy/MM/dd");
                iFacturaElectronica_P = 0;

                if (Program.iFacturacionElectronica == 1)
                {
                    iFacturaElectronica_P = 1;

                    if (configuracionFacturacion() == false)
                    {
                        return(false);
                    }

                    sClaveAcceso = sGenerarClaveAcceso();
                }

                //INICIAMOS UNA NUEVA TRANSACCION
                //------------------------------------------------------------------------------------------------------------------
                if (!conexion.GFun_Lo_Maneja_Transaccion(Program.G_INICIA_TRANSACCION))
                {
                    ok.lblMensaje.Text = "Error al abrir transacción";
                    ok.ShowDialog();
                    return(false);
                }

                //INSERTAR EN LA TABLA CV403_FACTURAS
                //------------------------------------------------------------------------------------------------------------------
                sSql  = "";
                sSql += "insert into cv403_facturas (idempresa, id_persona, cg_empresa, idtipocomprobante," + Environment.NewLine;
                sSql += "id_localidad, idformulariossri, id_vendedor, id_forma_pago, id_forma_pago2, id_forma_pago3," + Environment.NewLine;
                sSql += "fecha_factura, fecha_vcto, cg_moneda, valor, cg_estado_factura, editable, fecha_ingreso, " + Environment.NewLine;
                sSql += "usuario_ingreso, terminal_ingreso, estado, numero_replica_trigger, numero_control_replica, " + Environment.NewLine;
                sSql += "Direccion_Factura,Telefono_Factura,Ciudad_Factura, correo_electronico, servicio," + Environment.NewLine;
                sSql += "facturaelectronica, id_tipo_emision, id_tipo_ambiente, clave_acceso)" + Environment.NewLine;
                sSql += "values(" + Environment.NewLine;
                sSql += Program.iIdEmpresa + ", " + iIdPersona + ", " + Program.iCgEmpresa + "," + Environment.NewLine;
                sSql += "1," + Program.iIdLocalidad + ", " + Program.iIdFormularioSri + ", " + Program.iIdVendedor + ", " + iIdFormaPago + ", " + Environment.NewLine;
                sSql += "null, null, '" + sFecha + "', '" + sFecha + "', " + Program.iMoneda + ", " + dbTotal + ", 0, 0, GETDATE()," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "', 'A', 1, 0," + Environment.NewLine;
                sSql += "'" + sDireccion + "', '" + sTelefono + "', '" + sCiudadFactura + "'," + Environment.NewLine;
                sSql += "'" + sCorreoElectronico + "', 0, " + iFacturaElectronica_P + ", " + iIdTipoEmision + ", " + iIdTipoAmbiente + "," + Environment.NewLine;

                if (iFacturaElectronica_P == 1)
                {
                    sSql += "'" + sClaveAcceso + "')";
                }

                else
                {
                    sSql += "null)";
                }

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.lblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    return(false);
                }

                sTabla = "cv403_facturas";
                sCampo = "id_factura";

                iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                if (iMaximo == -1)
                {
                    ok.lblMensaje.Text = "No se pudo obtener el codigo de la tabla " + sTabla;
                    ok.ShowDialog();
                    return(false);
                }

                iIdFactura = Convert.ToInt32(iMaximo);

                //INSERTAR EN LA TABLA CV403_NUMEROS_FACTURAS
                //-----------------------------------------------------------------------------------------------------
                sSql  = "";
                sSql += "insert into cv403_numeros_facturas (id_factura, idtipocomprobante, numero_factura," + Environment.NewLine;
                sSql += "fecha_ingreso, usuario_ingreso, terminal_ingreso, estado, numero_replica_trigger," + Environment.NewLine;
                sSql += "numero_control_replica) " + Environment.NewLine;
                sSql += "values (" + Environment.NewLine;
                sSql += iIdFactura + ", 1, " + sNumeroFactura + ", GETDATE()," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "', 'A', 1, 0 )";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.lblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    return(false);
                }

                //ACTUALIZAR LOS NUMEROS EN TP_LOCALIDADES_IMPRESORAS
                //-----------------------------------------------------------------------------------------------------
                sSql  = "";
                sSql += "update tp_localidades_impresoras set" + Environment.NewLine;
                sSql += "numero_factura = numero_factura + 1," + Environment.NewLine;
                sSql += "numero_pago = numero_pago + 1" + Environment.NewLine;
                sSql += "where id_localidad = " + Program.iIdLocalidad;

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.lblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    return(false);
                }

                //INSERTAR EN LA TABLA CV403_PAGOS
                //------------------------------------------------------------------------------------
                sSql  = "";
                sSql += "insert into cv403_pagos (" + Environment.NewLine;
                sSql += "idempresa, id_persona, fecha_pago, cg_moneda, valor," + Environment.NewLine;
                sSql += "propina, cg_empresa, id_localidad, cg_cajero, fecha_ingreso," + Environment.NewLine;
                sSql += "usuario_ingreso, terminal_ingreso, estado, " + Environment.NewLine;
                sSql += "numero_replica_trigger, numero_control_replica,cambio) " + Environment.NewLine;
                sSql += "values(" + Environment.NewLine;
                sSql += Program.iIdEmpresa + ", " + iIdPersona + ", '" + sFecha + "', " + Program.iMoneda + "," + Environment.NewLine;
                sSql += dbTotal + ", 0, " + Program.iCgEmpresa + ", " + Program.iIdLocalidad + ", 7799, GETDATE()," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "', 'A' , 1, 0, 0)";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.lblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    return(false);
                }

                sTabla = "cv403_pagos";
                sCampo = "id_pago";

                iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                if (iMaximo == -1)
                {
                    ok.lblMensaje.Text = "No se pudo obtener el codigo de la tabla " + sTabla;
                    ok.ShowDialog();
                    return(false);
                }

                iIdPago = Convert.ToInt32(iMaximo);

                //INSERTAR EN LA TABLA CV403_NUMEROS_PAGOS
                //-----------------------------------------------------------------------------------------------------
                sSql  = "";
                sSql += "insert into cv403_numeros_pagos (" + Environment.NewLine;
                sSql += "id_pago, serie, numero_pago, fecha_ingreso, usuario_ingreso," + Environment.NewLine;
                sSql += "terminal_ingreso, estado, numero_replica_trigger, numero_control_replica)" + Environment.NewLine;
                sSql += "values(" + Environment.NewLine;
                sSql += iIdPago + ", 'A', " + sNumeroPago + ", GETDATE(), '" + Program.sDatosMaximo[0] + "'," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[1] + "', 'A', 1, 0)";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.lblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    return(false);
                }

                //INSERTAR EN LA TABLA CV403_DOCUMENTOS_PAGOS
                //-----------------------------------------------------------------------------------------------------
                sSql  = "";
                sSql += "insert into cv403_documentos_pagos (" + Environment.NewLine;
                sSql += "id_pago, cg_tipo_documento, numero_documento, fecha_vcto, " + Environment.NewLine;
                sSql += "cg_moneda, cotizacion, valor, id_pos_tipo_forma_cobro," + Environment.NewLine;
                sSql += "estado, fecha_ingreso, usuario_ingreso, terminal_ingreso," + Environment.NewLine;
                sSql += "numero_replica_trigger, numero_control_replica, valor_recibido)" + Environment.NewLine;
                sSql += "values(" + Environment.NewLine;
                sSql += iIdPago + ", " + iCgTipoDocumento + ", 9999, '" + sFecha + "', " + Environment.NewLine;
                sSql += Program.iMoneda + ", 1, " + dbTotal + ", " + iIdTipoFormaCobro + ", " + Environment.NewLine;
                sSql += "'A', GETDATE(), '" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "', 0, 0, " + dbTotal + ")";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.lblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    return(false);
                }

                for (int i = 0; i < dtPedidos.Rows.Count; i++)
                {
                    iIdPedido          = Convert.ToInt32(dtPedidos.Rows[i]["id_pedido"].ToString());
                    iIdDocumentoCobrar = Convert.ToInt32(dtPedidos.Rows[i]["id_documento_cobrar"].ToString());
                    dbTotalPorCuenta   = Convert.ToDecimal(dtPedidos.Rows[i]["valor"].ToString());

                    //INSERTAR EN LA TABLA CV403_DOCUMENTOS_PAGADOS
                    //-----------------------------------------------------------------------------------------------------
                    sSql  = "";
                    sSql += "insert into cv403_documentos_pagados (" + Environment.NewLine;
                    sSql += "id_documento_cobrar, id_pago, valor," + Environment.NewLine;
                    sSql += "estado, numero_replica_trigger,numero_control_replica," + Environment.NewLine;
                    sSql += "fecha_ingreso, usuario_ingreso, terminal_ingreso)" + Environment.NewLine;
                    sSql += "values (" + Environment.NewLine;
                    sSql += iIdDocumentoCobrar + ", " + iIdPago + ", " + dbTotalPorCuenta + ", 'A', 1, 0, " + Environment.NewLine;
                    sSql += "GETDATE(), '" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "')";

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.lblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        return(false);
                    }

                    //INSERTAR EN LA TABLA CV403_FACTURAS_PEDIDOS
                    //-----------------------------------------------------------------------------------------------------
                    sSql  = "";
                    sSql += "insert into cv403_facturas_pedidos (" + Environment.NewLine;
                    sSql += "id_factura, id_pedido, fecha_ingreso, usuario_ingreso, terminal_ingreso," + Environment.NewLine;
                    sSql += "estado, numero_replica_trigger, numero_control_replica) " + Environment.NewLine;
                    sSql += "values (" + Environment.NewLine;
                    sSql += iIdFactura + ", " + iIdPedido + ", GETDATE()," + Environment.NewLine;
                    sSql += "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "', 'A', 0, 0)";

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.lblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        return(false);
                    }

                    //ACTUALIZAR EN LA TABLA CV403_DCTOS_POR_COBRAR
                    //-----------------------------------------------------------------------------------------------------
                    sSql  = "";
                    sSql += "update cv403_dctos_por_cobrar set" + Environment.NewLine;
                    sSql += "id_factura = " + iIdFactura + "," + Environment.NewLine;
                    sSql += "cg_estado_dcto = 7461," + Environment.NewLine;
                    sSql += "numero_documento = " + sNumeroFactura + Environment.NewLine;
                    sSql += "where id_documento_cobrar = " + iIdDocumentoCobrar;

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.lblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        return(false);
                    }

                    //ACTUALIZAR EN LA TABLA CV403_CAB_PEDIDOS
                    //-----------------------------------------------------------------------------------------------------
                    sSql  = "";
                    sSql += "update cv403_cab_pedidos set" + Environment.NewLine;
                    sSql += "estado_orden = 'Pagada'," + Environment.NewLine;
                    sSql += "fecha_cierre_orden = GETDATE()" + Environment.NewLine;
                    sSql += "where id_pedido = " + iIdPedido;

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.lblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        return(false);
                    }
                }

                return(true);
            }

            catch (Exception ex)
            {
                catchMensaje.lblMensaje.Text = ex.Message;
                catchMensaje.ShowDialog();
                return(false);
            }
        }
Exemple #16
0
        //FUNCION PARA GUARDAR EL REGISTRO
        private void insertarRegistro()
        {
            try
            {
                //SE INICIA UNA TRANSACCION
                if (!conexion.GFun_Lo_Maneja_Transaccion(Program.G_INICIA_TRANSACCION))
                {
                    ok = new VentanasMensajes.frmMensajeNuevoOk();
                    ok.lblMensaje.Text = "Error al abrir transacción.";
                    ok.ShowDialog();
                    return;
                }

                sSql = "";
                if (iOp == 1)
                {
                    sSql += "insert into pos_cajero (" + Environment.NewLine;
                }
                else if (iOp == 2)
                {
                    sSql += "insert into pos_mesero (" + Environment.NewLine;
                }
                else if (iOp == 3)
                {
                    sSql += "insert into pos_promotor (" + Environment.NewLine;
                }
                else if (iOp == 4)
                {
                    sSql += "insert into pos_repartidor (" + Environment.NewLine;
                }

                sSql += "id_persona, codigo, descripcion, claveacceso," + Environment.NewLine;

                if (iOp == 1)
                {
                    sSql += "administracion, ";
                }

                sSql += "is_active, estado, fecha_ingreso, usuario_ingreso, terminal_ingreso)" + Environment.NewLine;
                sSql += "values (" + Environment.NewLine;
                sSql += "@id_persona, @codigo, @descripcion, @claveacceso," + Environment.NewLine;

                if (iOp == 1)
                {
                    sSql += "1, ";
                }

                sSql += "@is_active, @estado, getdate(), @usuario_ingreso, @terminal_ingreso)";

                int i = 0;
                parametro    = new SqlParameter[8];
                parametro[i] = new SqlParameter();
                parametro[i].ParameterName = "@id_persona";
                parametro[i].SqlDbType     = SqlDbType.Int;
                parametro[i].Value         = dbAyudaPersonal.iId;
                i++;

                parametro[i] = new SqlParameter();
                parametro[i].ParameterName = "@codigo";
                parametro[i].SqlDbType     = SqlDbType.VarChar;
                parametro[i].Value         = txtCodigo.Text.Trim();
                i++;

                parametro[i] = new SqlParameter();
                parametro[i].ParameterName = "@descripcion";
                parametro[i].SqlDbType     = SqlDbType.VarChar;
                parametro[i].Value         = txtDescripcion.Text.Trim().ToUpper();
                i++;

                parametro[i] = new SqlParameter();
                parametro[i].ParameterName = "@claveacceso";
                parametro[i].SqlDbType     = SqlDbType.VarChar;
                parametro[i].Value         = txtClaveAcceso.Text.Trim();
                i++;

                parametro[i] = new SqlParameter();
                parametro[i].ParameterName = "@is_active";
                parametro[i].SqlDbType     = SqlDbType.Int;
                parametro[i].Value         = 1;
                i++;

                parametro[i] = new SqlParameter();
                parametro[i].ParameterName = "@estado";
                parametro[i].SqlDbType     = SqlDbType.VarChar;
                parametro[i].Value         = sDatosMaximo[2];
                i++;

                parametro[i] = new SqlParameter();
                parametro[i].ParameterName = "@usuario_ingreso";
                parametro[i].SqlDbType     = SqlDbType.VarChar;
                parametro[i].Value         = sDatosMaximo[0];
                i++;

                parametro[i] = new SqlParameter();
                parametro[i].ParameterName = "@terminal_ingreso";
                parametro[i].SqlDbType     = SqlDbType.VarChar;
                parametro[i].Value         = sDatosMaximo[1];

                //EJECUTAR LA INSTRUCCIÓN SQL
                if (!conexion.GFun_Lo_Ejecutar_SQL_Parametros(sSql, parametro))
                {
                    conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION);
                    catchMensaje = new VentanasMensajes.frmMensajeNuevoCatch();
                    catchMensaje.lblMensaje.Text = conexion.sMensajeError;
                    catchMensaje.ShowDialog();
                    return;
                }

                //OBTENER EL MAXIMO ID
                if (iOp == 1)
                {
                    sTabla = "pos_cajero";
                    sCampo = "id_pos_cajero";
                }

                else if (iOp == 2)
                {
                    sTabla = "pos_mesero";
                    sCampo = "id_pos_mesero";
                }

                else if (iOp == 3)
                {
                    sTabla = "pos_promotor";
                    sCampo = "id_pos_promotor";
                }

                else if (iOp == 4)
                {
                    sTabla = "pos_repartidor";
                    sCampo = "id_pos_repartidor";
                }

                iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", sDatosMaximo);

                if (iMaximo == -1)
                {
                    conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION);
                    ok = new VentanasMensajes.frmMensajeNuevoOk();
                    ok.lblMensaje.Text = "No se pudo obtener el codigo de la tabla " + sTabla;
                    ok.ShowDialog();
                    return;
                }

                iIdRegistro = Convert.ToInt32(iMaximo);

                //SI SE EJECUTA TODO REALIZA EL COMMIT
                conexion.GFun_Lo_Maneja_Transaccion(Program.G_TERMINA_TRANSACCION);

                ok = new VentanasMensajes.frmMensajeNuevoOk();
                ok.lblMensaje.Text = "El registro se ha guardado con éxito.";
                ok.ShowDialog();

                this.DialogResult = DialogResult.OK;
                return;
            }

            catch (Exception ex)
            {
                conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION);
                catchMensaje = new VentanasMensajes.frmMensajeNuevoCatch();
                catchMensaje.lblMensaje.Text = ex.Message;
                catchMensaje.ShowDialog();
            }
        }
        //FUNCION PARA CAMBIAR LAS FORMAS DE PAGO
        private void cambiarFormasPagos()
        {
            try
            {
                if (Convert.ToDouble(dgvDetalleDeuda.Rows[1].Cells[1].Value) != 0)
                {
                    ok.LblMensaje.Text = "No ha realizado el cobro completo de la comanda.";
                    ok.ShowDialog();
                    return;
                }

                string sFecha_P = Program.sFechaSistema.ToString("yyyy/MM/dd");

                if (!conexion.GFun_Lo_Maneja_Transaccion(Program.G_INICIA_TRANSACCION))
                {
                    ok.LblMensaje.Text = "Error al abrir transacción.";
                    ok.ShowDialog();
                    return;
                }

                sSql  = "";
                sSql += "select id_documento_pago" + Environment.NewLine;
                sSql += "from pos_vw_pedido_forma_pago" + Environment.NewLine;
                sSql += "where id_pedido = " + Convert.ToInt32(sIdOrden);

                dtConsulta = new DataTable();
                dtConsulta.Clear();

                bRespuesta = conexion.GFun_Lo_Busca_Registro(dtConsulta, sSql);

                if (bRespuesta == false)
                {
                    catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                for (int i = 0; i < dtConsulta.Rows.Count; i++)
                {
                    sSql  = "";
                    sSql += "update pos_movimiento_caja set" + Environment.NewLine;
                    sSql += "estado = 'E'," + Environment.NewLine;
                    sSql += "fecha_anula = GETDATE()," + Environment.NewLine;
                    sSql += "usuario_anula = '" + Program.sDatosMaximo[0] + "'," + Environment.NewLine;
                    sSql += "terminal_anula = '" + Program.sDatosMaximo[1] + "'" + Environment.NewLine;
                    sSql += "where id_documento_pago = " + Convert.ToInt32(dtConsulta.Rows[i][0].ToString()) + Environment.NewLine;

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }
                }

                sSql  = "";
                sSql += "select id_documento_cobrar" + Environment.NewLine;
                sSql += "from cv403_dctos_por_cobrar" + Environment.NewLine;
                sSql += "where id_pedido = " + sIdOrden + Environment.NewLine;
                sSql += "and estado = 'A'";

                dtConsulta = new DataTable();
                dtConsulta.Clear();

                bRespuesta = conexion.GFun_Lo_Busca_Registro(dtConsulta, sSql);

                if (bRespuesta == false)
                {
                    catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                iIdDocumentoCobrar = Convert.ToInt32(dtConsulta.Rows[0]["id_documento_cobrar"].ToString());
                iCuenta            = 0;

                sSql  = "";
                sSql += "select count(*) cuenta" + Environment.NewLine;
                sSql += "from  cv403_documentos_pagados" + Environment.NewLine;
                sSql += "where id_documento_cobrar = " + iIdDocumentoCobrar + Environment.NewLine;
                sSql += "and estado = 'A'";

                dtConsulta = new DataTable();
                dtConsulta.Clear();

                bRespuesta = conexion.GFun_Lo_Busca_Registro(dtConsulta, sSql);

                if (bRespuesta == false)
                {
                    catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                iCuenta = Convert.ToInt32(dtConsulta.Rows[0][0].ToString());

                if (iCuenta > 0)
                {
                    sSql  = "";
                    sSql += "select id_pago, id_documento_pagado" + Environment.NewLine;
                    sSql += "from  cv403_documentos_pagados" + Environment.NewLine;
                    sSql += "where id_documento_cobrar = " + iIdDocumentoCobrar + Environment.NewLine;
                    sSql += "and estado = 'A'";

                    dtConsulta = new DataTable();
                    dtConsulta.Clear();

                    bRespuesta = conexion.GFun_Lo_Busca_Registro(dtConsulta, sSql);

                    if (bRespuesta == false)
                    {
                        catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }

                    if (dtConsulta.Rows.Count > 0)
                    {
                        iIdPago            = Convert.ToInt32(dtConsulta.Rows[0][0].ToString());
                        iIdDocumentoPagado = Convert.ToInt32(dtConsulta.Rows[0][1].ToString());
                    }

                    sSql  = "";
                    sSql += "update cv403_pagos set" + Environment.NewLine;
                    sSql += "estado = 'E'," + Environment.NewLine;
                    sSql += "fecha_anula = GETDATE()," + Environment.NewLine;
                    sSql += "usuario_anula = '" + Program.sDatosMaximo[0] + "'," + Environment.NewLine;
                    sSql += "terminal_anula = '" + Program.sDatosMaximo[1] + "'" + Environment.NewLine;
                    sSql += "where id_pago = " + iIdPago;

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }

                    sSql  = "";
                    sSql += "update cv403_documentos_pagos set" + Environment.NewLine;
                    sSql += "estado = 'E'," + Environment.NewLine;
                    sSql += "fecha_anula = GETDATE()," + Environment.NewLine;
                    sSql += "usuario_anula = '" + Program.sDatosMaximo[0] + "'," + Environment.NewLine;
                    sSql += "terminal_anula = '" + Program.sDatosMaximo[1] + "'" + Environment.NewLine;
                    sSql += "where id_pago = " + iIdPago;

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }

                    sSql  = "";
                    sSql += "update cv403_numeros_pagos set" + Environment.NewLine;
                    sSql += "estado = 'E'," + Environment.NewLine;
                    sSql += "fecha_anula = GETDATE()," + Environment.NewLine;
                    sSql += "usuario_anula = '" + Program.sDatosMaximo[0] + "'," + Environment.NewLine;
                    sSql += "terminal_anula = '" + Program.sDatosMaximo[1] + "'" + Environment.NewLine;
                    sSql += "where id_pago = " + iIdPago;

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }

                    sSql  = "";
                    sSql += "update cv403_documentos_pagados set" + Environment.NewLine;
                    sSql += "estado = 'E'," + Environment.NewLine;
                    sSql += "fecha_anula = GETDATE()," + Environment.NewLine;
                    sSql += "usuario_anula = '" + Program.sDatosMaximo[0] + "'," + Environment.NewLine;
                    sSql += "terminal_anula = '" + Program.sDatosMaximo[1] + "'" + Environment.NewLine;
                    sSql += "where id_documento_pagado = " + iIdDocumentoPagado;

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }
                }

                sSql  = "";
                sSql += "insert into cv403_pagos (" + Environment.NewLine;
                sSql += "idempresa, id_persona, fecha_pago, cg_moneda, valor," + Environment.NewLine;
                sSql += "propina, cg_empresa, id_localidad, cg_cajero, fecha_ingreso," + Environment.NewLine;
                sSql += "usuario_ingreso, terminal_ingreso, estado, " + Environment.NewLine;
                sSql += "numero_replica_trigger, numero_control_replica,cambio) " + Environment.NewLine;
                sSql += "values(" + Environment.NewLine;
                sSql += Program.iIdEmpresa + ", " + Program.iIdPersona + ", '" + sFecha_P + "', " + Program.iMoneda + "," + Environment.NewLine;
                sSql += dTotal + ", " + Convert.ToDouble(dgvDetalleDeuda.Rows[3].Cells[1].Value) + ", " + Program.iCgEmpresa + "," + Environment.NewLine;
                sSql += Program.iIdLocalidad + ", 7799, GETDATE(), '" + Program.sDatosMaximo[0] + "'," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[1] + "', 'A' , 1, 0, " + Convert.ToDouble(dgvDetalleDeuda.Rows[2].Cells[1].Value) + ")";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                dtConsulta = new DataTable();
                dtConsulta.Clear();
                sTabla = "cv403_pagos";
                sCampo = "id_pago";

                iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                if (iMaximo == -1)
                {
                    ok.LblMensaje.Text = "No se pudo obtener el codigo de la tabla " + sTabla;
                    ok.ShowDialog();
                    goto reversa;
                }

                else
                {
                    iIdPago = Convert.ToInt32(iMaximo);
                }

                sSql  = "";
                sSql += "select numero_pago" + Environment.NewLine;
                sSql += "from tp_localidades_impresoras" + Environment.NewLine;
                sSql += "where id_localidad = " + Program.iIdLocalidad + Environment.NewLine;
                sSql += "and estado = 'A'";

                dtConsulta = new DataTable();
                dtConsulta.Clear();

                bRespuesta = conexion.GFun_Lo_Busca_Registro(dtConsulta, sSql);

                if (bRespuesta == false)
                {
                    catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                sSql  = "";
                sSql += "insert into cv403_numeros_pagos (" + Environment.NewLine;
                sSql += "id_pago, serie, numero_pago, fecha_ingreso, usuario_ingreso," + Environment.NewLine;
                sSql += "terminal_ingreso, estado, numero_replica_trigger, numero_control_replica)" + Environment.NewLine;
                sSql += "values(" + Environment.NewLine;
                sSql += iIdPago + ", 'A', " + iNumeroPago + ", GETDATE(), '" + Program.sDatosMaximo[0] + "'," + Environment.NewLine;
                sSql += "'" + Program.sDatosMaximo[1] + "', 'A', 1, 0)";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                for (int i = 0; i < dgvPagos.Rows.Count; i++)
                {
                    sSql  = "";
                    sSql += "select cg_tipo_documento" + Environment.NewLine;
                    sSql += "from pos_tipo_forma_cobro " + Environment.NewLine;
                    sSql += "where id_pos_tipo_forma_cobro = " + dgvPagos.Rows[i].Cells[0].Value;

                    dtConsulta = new DataTable();
                    dtConsulta.Clear();
                    bRespuesta = conexion.GFun_Lo_Busca_Registro(dtConsulta, sSql);

                    if (bRespuesta == false)
                    {
                        catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }

                    iCgTipoDocumento = Convert.ToInt32(dtConsulta.Rows[0][0].ToString());
                    sSql             = "";
                    sSql            += "insert into cv403_documentos_pagos (" + Environment.NewLine;
                    sSql            += "id_pago, cg_tipo_documento, numero_documento, fecha_vcto, " + Environment.NewLine;
                    sSql            += "cg_moneda, cotizacion, valor, id_pos_tipo_forma_cobro," + Environment.NewLine;
                    sSql            += "estado, fecha_ingreso, usuario_ingreso, terminal_ingreso," + Environment.NewLine;
                    sSql            += "numero_replica_trigger, numero_control_replica, valor_recibido) " + Environment.NewLine;
                    sSql            += "values(" + Environment.NewLine;
                    sSql            += iIdPago + ", " + iCgTipoDocumento + ", 9999, '" + sFecha_P + "', " + Environment.NewLine;
                    sSql            += Program.iMoneda + ", 1, " + Convert.ToDouble(dgvPagos.Rows[i].Cells[2].Value) + "," + Environment.NewLine;
                    sSql            += Convert.ToInt32(dgvPagos.Rows[i].Cells[0].Value) + ", 'A', GETDATE()," + Environment.NewLine;
                    sSql            += "'" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "', 1, 0,";

                    if (Convert.ToInt32(dgvPagos.Rows[i].Cells[0].Value) == 1)
                    {
                        sSql += (Convert.ToDouble(dgvPagos.Rows[i].Cells[2].Value) + Convert.ToDouble(dgvDetalleDeuda.Rows[2].Cells[1].Value));
                    }

                    else
                    {
                        sSql += "null";
                    }

                    sSql += ")";

                    if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                    {
                        catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                        catchMensaje.ShowDialog();
                        goto reversa;
                    }

                    if (Convert.ToInt32(dgvPagos.Rows[i].Cells[0].Value) != 1 || Convert.ToInt32(dgvPagos.Rows[i].Cells[0].Value) != 11)
                    {
                        dtConsulta = new DataTable();
                        dtConsulta.Clear();

                        sTabla = "cv403_documentos_pagos";
                        sCampo = "id_documento_pago";

                        iMaximo = conexion.GFun_Ln_Saca_Maximo_ID(sTabla, sCampo, "", Program.sDatosMaximo);

                        if (iMaximo == -1)
                        {
                            ok.LblMensaje.Text = "No se pudo obtener el codigo de la tabla " + sTabla;
                            ok.ShowDialog();
                            goto reversa;
                        }

                        else
                        {
                            iIdDocumentoPago = Convert.ToInt32(iMaximo);
                        }
                    }
                }

                sSql  = "";
                sSql += "insert into cv403_documentos_pagados (" + Environment.NewLine;
                sSql += "id_documento_cobrar, id_pago, valor, " + Environment.NewLine;
                sSql += "estado, numero_replica_trigger,numero_control_replica," + Environment.NewLine;
                sSql += "fecha_ingreso, usuario_ingreso, terminal_ingreso) " + Environment.NewLine;
                sSql += "values (" + Environment.NewLine;
                sSql += iIdDocumentoCobrar + ", " + iIdPago + ", " + dTotal + ", 'A', 1, 0," + Environment.NewLine;
                sSql += "GETDATE(), '" + Program.sDatosMaximo[0] + "', '" + Program.sDatosMaximo[1] + "')";

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                sSql  = "";
                sSql += "update tp_localidades_impresoras set" + Environment.NewLine;
                sSql += "numero_pago = numero_pago + 1" + Environment.NewLine;
                sSql += "where id_localidad = " + Program.iIdLocalidad + Environment.NewLine;

                if (!conexion.GFun_Lo_Ejecuta_SQL(sSql))
                {
                    catchMensaje.LblMensaje.Text = "ERROR EN LA SIGUIENTE INSTRUCCIÓN:" + Environment.NewLine + sSql;
                    catchMensaje.ShowDialog();
                    goto reversa;
                }

                if (actualizarMovimientosCaja() == false)
                {
                    goto reversa;
                }

                conexion.GFun_Lo_Maneja_Transaccion(Program.G_TERMINA_TRANSACCION);
                ok.LblMensaje.Text = "Las formas de pago se han actualizado éxitosamente";
                ok.ShowDialog();
                this.DialogResult = DialogResult.OK;
                return;
            }

            catch (Exception ex)
            {
                catchMensaje.LblMensaje.Text = ex.ToString();
                catchMensaje.ShowDialog();
            }

            reversa : { conexion.GFun_Lo_Maneja_Transaccion(Program.G_REVERSA_TRANSACCION); }
        }