Exemplo n.º 1
0
    private void GeneralSet()
    {
        System.Collections.Hashtable parametros = new Hashtable();
        FacturaElectronica.DBEngine.SQLEngine sqle = new SQLEngine();
        parametros = sqle.GetGeneralSettings("3");

        foreach (DictionaryEntry uno in parametros)
        {
            WriteText(string.Format("<br>[{0}]=[{1}]",
                uno.Key,
                uno.Value));
        }
    }
Exemplo n.º 2
0
        /// <summary>
        /// GetConnestionStringXMLSetting()
        /// Busca en el archivo app.config el connectionstring de la base
        /// </summary>
        /// <returns>string</returns>
        public static string GetConnestionStringXMLSetting()
        {
            try
            {
                FacturaElectronica.DBEngine.SQLEngine sqle = new SQLEngine();

                System.Configuration.Configuration config =
                    System.Configuration.ConfigurationManager.OpenExeConfiguration(sqle.GetPath());

                System.Configuration.KeyValueConfigurationElement keyvalue =
                    config.AppSettings.Settings[KEYCONNECTIONSTRING];

                if (keyvalue.Value == null)
                {
                    throw (new Exception("Error: Archivo de Configuration es incorrecto o no existe (FacturaElectronica.DBEngine.dll.config)"));
                }

                return keyvalue.Value;
            }
            catch (Exception ex)
            {
                throw (new Exception(ex.Message));
            }
        }
Exemplo n.º 3
0
        protected void btnGetCAE_Click(object sender, EventArgs e)
        {
            try
            {
                Settings oSettings = new Settings(ddlEmpresa.SelectedItem.Value);

                AfipConnection afipConnFex = new AfipConnection("wsfex", oSettings);
                AfipConnection afipConnFe = new AfipConnection("wsfe", oSettings);
                AfipConnection afipConnFeB = new AfipConnection("wsbfe", oSettings);

                wsfex.Service fexService = new wsfex.Service();
                fexService.Url = oSettings.UrlAFIPwsfex;

                wsfe.Service feService = new wsfe.Service();
                feService.Url = oSettings.UrlAFIPwsfe;

                wsfeb.Service febService = new wsfeb.Service();
                febService.Url = oSettings.UrlAFIPwsbfe;

                wsfex.ClsFEX_LastCMP afipLastEx = new wsfex.ClsFEX_LastCMP();
                wsfex.ClsFEXAuthRequest objFEXAuthRequest = new wsfex.ClsFEXAuthRequest();
                wsfex.FEXGetCMPResponse objFEXGetCMPResponse = new wsfex.FEXGetCMPResponse();
                wsfex.ClsFEXRequest objFEXRequest = new wsfex.ClsFEXRequest();
                wsfex.FEXResponseAuthorize fexResponse = new wsfex.FEXResponseAuthorize();

                wsfe.FEAuthRequest objFEAuthRequest = new wsfe.FEAuthRequest();
                wsfe.FECompConsultaReq objFERequest = new wsfe.FECompConsultaReq();
                wsfe.FECompConsultaResponse feResponse = new wsfe.FECompConsultaResponse();

                //wsfe.FELastCMPtype objFELastCMType = new wsfe.FELastCMPtype();
                //wsfe.FEConsultaCAEResponse objFEConsultaCAEResponse = new wsfe.FEConsultaCAEResponse();
                //wsfe.FEConsultaCAEReq objCMPFE = new wsfe.FEConsultaCAEReq();
                //wsfe.FEResponse feResponse = new wsfe.FEResponse();
                //wsfe.FERequest objFERequest = new wsfe.FERequest();

                wsfeb.BFEGetCMPResponse objBFEGetCMPResponse = new wsfeb.BFEGetCMPResponse();
                wsfeb.ClsBFEGetCMP objCMP = new wsfeb.ClsBFEGetCMP();
                wsfeb.ClsBFEAuthRequest objBFEAuthRequest = new wsfeb.ClsBFEAuthRequest();

                DataTable returnDTable = new DataTable();

                SQLEngine sqlEngine = new SQLEngine();

                switch (ddlTipoComprobanteCAE.SelectedValue)
                {
                    case "1":
                    case "2":
                    case "3":
                    case "6":
                    case "7":
                    case "8":
                        lblErrorMessages.Text = "";

                        if (afipConnFeB.ConnectionErrorDescription == string.Empty)
                        {
                            objBFEAuthRequest.Cuit = afipConnFeB.Cuit;
                            objBFEAuthRequest.Sign = afipConnFeB.Sign;
                            objBFEAuthRequest.Token = afipConnFeB.Token;

                            objCMP.Punto_vta = Convert.ToInt16(ddlSucursalCAE.SelectedValue);
                            objCMP.Tipo_cbte = Convert.ToInt16(ddlTipoComprobanteCAE.SelectedValue);
                            objCMP.Cbte_nro = Convert.ToInt64(txtNroComprobante.Text);

                            objBFEGetCMPResponse = febService.BFEGetCMP(objBFEAuthRequest, objCMP);

                            if (objBFEGetCMPResponse.BFEResultGet != null && objBFEGetCMPResponse.BFEResultGet.Fch_venc_Cae != null)
                            {
                                lblCAE.Text = objBFEGetCMPResponse.BFEResultGet.Cae;
                                lblVto.Text = objBFEGetCMPResponse.BFEResultGet.Fch_venc_Cae;//objBFEGetCMPResponse.BFEResultGet.Fch_venc_Cae.Substring(3, 2) + "/" + objBFEGetCMPResponse.BFEResultGet.Fch_venc_Cae.Substring(4, 2) + "/" + objBFEGetCMPResponse.BFEResultGet.Fch_venc_Cae.Substring(0, 4);
                            }
                            else
                            {
                                objFEAuthRequest.Cuit = afipConnFe.Cuit;
                                objFEAuthRequest.Sign = afipConnFe.Sign;
                                objFEAuthRequest.Token = afipConnFe.Token;

                                objFERequest.CbteNro = Convert.ToInt64(txtNroComprobante.Text);
                                objFERequest.CbteTipo = Convert.ToInt16(ddlTipoComprobanteCAE.SelectedValue);
                                objFERequest.PtoVta = Convert.ToInt16(ddlSucursalCAE.SelectedValue);

                                feResponse = feService.FECompConsultar(objFEAuthRequest, objFERequest);

                                if (feResponse.ResultGet != null && feResponse.ResultGet.CodAutorizacion != null)
                                {
                                    lblCAE.Text = feResponse.ResultGet.CodAutorizacion;
                                    lblVto.Text = feResponse.ResultGet.FchVto; //.Substring(6, 2) + "/" + feResponse.FecResp.fecha_cae.Substring(4, 2) + "/" + feResponse.FecResp.fecha_cae.Substring(0, 4); ;
                                }
                                else
                                {
                                    lblCAE.Text = "Comprobante inexistente.";
                                    lblVto.Text = "XX/XX/XXXX";
                                }

                                ////si es bienes y servicios hay que reprocesar para obtener CAE, lo busco en la base
                                //returnDTable = sqlEngine.GetItems("cbtecabecera", "*", "NroComprobanteDesde = '" + FillWithCeros(txtNroComprobante.Text) + "' and PuntoVenta = '" + ddlSucursalCAE.SelectedValue + "' and TipoComprobante = '" + ddlTipoComprobanteCAE.SelectedValue + "'", 0);

                                //if (returnDTable.Rows.Count > 0)
                                //{
                                //    if (returnDTable.Rows[0]["BatchUniqueId"].ToString() != string.Empty)
                                //    {
                                //        wsfe.FECabeceraRequest objFECabeceraRequest = new wsfe.FECabeceraRequest();
                                //        objFECabeceraRequest.cantidadreg = 0;
                                //        objFECabeceraRequest.id = Convert.ToInt64(returnDTable.Rows[0]["BatchUniqueId"].ToString());
                                //        objFECabeceraRequest.presta_serv = 0;

                                //        wsfe.FEDetalleRequest[] aObjFEDetalleRequest = new wsfe.FEDetalleRequest[1];

                                //        wsfe.FEDetalleRequest objFEDetalleRequest = new wsfe.FEDetalleRequest();
                                //        objFEDetalleRequest.tipo_doc = Convert.ToInt16(returnDTable.Rows[0]["CompradorCodigoDocumento"]);
                                //        objFEDetalleRequest.nro_doc = (long)Convert.ToDouble(returnDTable.Rows[0]["CompradorNroDocumento"]);
                                //        objFEDetalleRequest.tipo_cbte = Convert.ToInt16(returnDTable.Rows[0]["TipoComprobante"]);
                                //        objFEDetalleRequest.punto_vta = Convert.ToInt16(returnDTable.Rows[0]["PuntoVenta"]);
                                //        objFEDetalleRequest.cbt_desde = (long)Convert.ToDouble(returnDTable.Rows[0]["NroComprobanteDesde"]);
                                //        objFEDetalleRequest.cbt_hasta = (long)Convert.ToDouble(returnDTable.Rows[0]["NroComprobanteHasta"]);
                                //        objFEDetalleRequest.imp_total = Convert.ToDouble(returnDTable.Rows[0]["Importe"]);
                                //        objFEDetalleRequest.imp_tot_conc = Convert.ToDouble(returnDTable.Rows[0]["ImporteNoGravado"]);
                                //        objFEDetalleRequest.imp_neto = Convert.ToDouble(returnDTable.Rows[0]["ImporteGravado"]);
                                //        objFEDetalleRequest.impto_liq = Convert.ToDouble(returnDTable.Rows[0]["ImporteImpuestoLiquidado"]);
                                //        objFEDetalleRequest.impto_liq_rni = Convert.ToDouble(returnDTable.Rows[0]["ImporteRNI_Percepcion"]);
                                //        objFEDetalleRequest.imp_op_ex = Convert.ToDouble(returnDTable.Rows[0]["ImporteExento"]);

                                //        // Las fechas deben venir en formato "YYYY-MM-DD"
                                //        objFEDetalleRequest.fecha_cbte = Convert.ToDateTime(returnDTable.Rows[0]["FechaComprobante"]).ToString("yyyyMMdd");
                                //        objFEDetalleRequest.fecha_serv_desde = Convert.ToDateTime(returnDTable.Rows[0]["FechaDesdeServicioFacturado"]).ToString("yyyyMMdd");
                                //        objFEDetalleRequest.fecha_serv_hasta = Convert.ToDateTime(returnDTable.Rows[0]["FechaHastaServicioFacturado"]).ToString("yyyyMMdd");
                                //        objFEDetalleRequest.fecha_venc_pago = Convert.ToDateTime(returnDTable.Rows[0]["FechaVencimientoPago"]).ToString("yyyyMMdd");
                                //        aObjFEDetalleRequest[0] = objFEDetalleRequest;

                                //        objFERequest.Fecr = objFECabeceraRequest;
                                //        objFERequest.Fedr = aObjFEDetalleRequest;

                                //        feResponse = feService.FEAutRequest(objFEAuthRequest, objFERequest);

                                //        if (feResponse.FedResp != null && feResponse.FedResp[0].cae != null)
                                //        {
                                //            lblCAE.Text = feResponse.FedResp[0].cae;
                                //            lblVto.Text = feResponse.FedResp[0].fecha_vto; //.Substring(6, 2) + "/" + feResponse.FecResp.fecha_cae.Substring(4, 2) + "/" + feResponse.FecResp.fecha_cae.Substring(0, 4); ;
                                //        }
                                //        else
                                //        {
                                //            lblCAE.Text = "Comprobante inexistente.";
                                //            lblVto.Text = "XX/XX/XXXX";
                                //        }
                                //    }
                                //    else
                                //    {
                                //        lblCAE.Text = "Comprobante sin BatchUniqueId.";
                                //        lblVto.Text = "XX/XX/XXXX";
                                //    }
                                //}
                                //else
                                //{
                                //    lblCAE.Text = "Comprobante inexistente.";
                                //    lblVto.Text = "XX/XX/XXXX";
                                //}
                            }
                        }
                        else
                        {
                            lblNumCbte.Text = "XXXXXXXX";
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('Error de login con AFIP, vuelva a intentar la operacion en unos minutos.')", true);
                        }
                        break;

                    case "19":
                    case "20":
                    case "21":

                        lblErrorMessages.Text = "";
                        if (afipConnFex.ConnectionErrorDescription == string.Empty)
                        {
                            //si es bienes y servicios hay que reprocesar para obtener CAE, lo busco en la base
                            returnDTable = sqlEngine.GetItems("cbtecabecera", "*", "NroComprobanteDesde = '" + FillWithCeros(txtNroComprobante.Text) + "' and PuntoVenta = '" + ddlSucursalCAE.SelectedValue + "' and TipoComprobante = '" + ddlTipoComprobanteCAE.SelectedValue + "' and BatchUniqueId IS NOT NULL", 0);

                            objFEXAuthRequest.Cuit = afipConnFex.Cuit;
                            objFEXAuthRequest.Sign = afipConnFex.Sign;
                            objFEXAuthRequest.Token = afipConnFex.Token;

                            if (returnDTable.Rows.Count > 0)
                            {
                                if (returnDTable.Rows[0]["BatchUniqueId"].ToString() != string.Empty)
                                {
                                    objFEXRequest.Id = (long)Convert.ToDouble(returnDTable.Rows[0]["BatchUniqueId"]);
                                    objFEXRequest.Tipo_cbte = Convert.ToInt16(returnDTable.Rows[0]["TipoComprobante"]);
                                    objFEXRequest.Punto_vta = Convert.ToInt16(returnDTable.Rows[0]["PuntoVenta"]);
                                    objFEXRequest.Cbte_nro = (long)Convert.ToDouble(returnDTable.Rows[0]["NroComprobanteDesde"]);
                                    objFEXRequest.Tipo_expo = Convert.ToInt16(returnDTable.Rows[0]["TipoExportacion"]);
                                    objFEXRequest.Permiso_existente = returnDTable.Rows[0]["PermisoExistente"].ToString();
                                    objFEXRequest.Dst_cmp = Convert.ToInt16(sqlEngine.ObtenerEquivalencia("EquivAFIPPais", ddlEmpresa.SelectedItem.Value, returnDTable.Rows[0]["PaisComprador"].ToString()));
                                    objFEXRequest.Cliente = returnDTable.Rows[0]["CompradorRazonSocial"].ToString();
                                    objFEXRequest.Domicilio_cliente = returnDTable.Rows[0]["CompradorDireccion"].ToString();
                                    objFEXRequest.Moneda_Id = returnDTable.Rows[0]["CodigoMoneda"].ToString();
                                    objFEXRequest.Moneda_ctz = Convert.ToDouble(returnDTable.Rows[0]["TasaCambio"]);
                                    objFEXRequest.Imp_total = Convert.ToDouble(returnDTable.Rows[0]["ImporteMonedaFacturacion"]);
                                    objFEXRequest.Idioma_cbte = Convert.ToInt16(returnDTable.Rows[0]["Idioma"]);
                                    objFEXRequest.Id_impositivo = returnDTable.Rows[0]["CompradorNroDocumento"].ToString();
                                    objFEXRequest.Fecha_cbte = Convert.ToDateTime(returnDTable.Rows[0]["FechaComprobante"]).ToString("yyyyMMdd");
                                    objFEXRequest.Forma_pago = returnDTable.Rows[0]["FormaPagoDescrip"].ToString();
                                    objFEXRequest.Obs = returnDTable.Rows[0]["Observaciones"].ToString();
                                    objFEXRequest.Obs_comerciales = returnDTable.Rows[0]["ObservacionesComerciales"].ToString();
                                    objFEXRequest.Incoterms = returnDTable.Rows[0]["IncoTerms"].ToString();

                                    fexResponse = fexService.FEXAuthorize(objFEXAuthRequest, objFEXRequest);

                                    if (fexResponse.FEXResultAuth != null && fexResponse.FEXResultAuth.Cae != null)
                                    {
                                        lblCAE.Text = fexResponse.FEXResultAuth.Cae;
                                        lblVto.Text = fexResponse.FEXResultAuth.Fch_venc_Cae;//.Substring(6, 2) + "/" + fexResponse.FEXResultAuth.Fch_venc_Cae.Substring(4, 2) + "/" + fexResponse.FEXResultAuth.Fch_venc_Cae.Substring(0, 4);
                                    }
                                    else
                                    {
                                        lblCAE.Text = "Comprobante inexistente.";
                                        lblVto.Text = "XX/XX/XXXX";
                                    }
                                }
                                else
                                {
                                    lblCAE.Text = "Comprobante sin BatchUniqueId.";
                                    lblVto.Text = "XX/XX/XXXX";
                                }
                            }
                            else
                            {
                                lblCAE.Text = "Comprobante inexistente.";
                                lblVto.Text = "XX/XX/XXXX";
                            }
                        }
                        else
                        {
                            lblNumCbte.Text = "XXXXXXXX";
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('Error de login con AFIP, vuelva a intentar la operacion en unos minutos.')", true);
                        }

                        break;
                }
                sqlEngine.Close();
            }
            catch (Exception ex)
            {
                lblNumCbte.Text = "XXXXXXXX";
                lblErrorMessages.Text = "Error: " + ex.Message;
            }
        }
Exemplo n.º 4
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            Settings oSettings = null;

            wsfex.Service afipFEXService = null;
            wsfex.ClsFEXAuthRequest afipObjFEXAuthRequest = null;

            wsfeb.Service afipFEBService = null;
            wsfeb.ClsBFEAuthRequest afipObjFEBAuthRequest = null;

            AfipConnection afipConnFEX = null;
            AfipConnection afipConnFEB = null;

            string strCodigo = string.Empty;
            string strDescripcion = string.Empty;

            FacturaElectronica.DBEngine.SQLEngine sqlEngine = new FacturaElectronica.DBEngine.SQLEngine();

            try
            {
                oSettings = new Settings(ddlEmpresa.SelectedItem.Value);

                //Exportacion
                afipFEXService = new wsfex.Service();
                afipFEXService.Url = oSettings.UrlAFIPwsfex;
                afipObjFEXAuthRequest = new wsfex.ClsFEXAuthRequest();

                afipConnFEX = new AfipConnection("wsfex", oSettings);
                afipConnFEB = new AfipConnection("wsbfe", oSettings);

                //Inicializo el objeto AuthRequest de la Afip
                afipObjFEXAuthRequest.Cuit = afipConnFEX.Cuit;
                afipObjFEXAuthRequest.Sign = afipConnFEX.Sign;
                afipObjFEXAuthRequest.Token = afipConnFEX.Token;

                //Bienes y Servicios
                afipFEBService = new wsfeb.Service();
                afipFEBService.Url = oSettings.UrlAFIPwsbfe;
                afipObjFEBAuthRequest = new wsfeb.ClsBFEAuthRequest();

                if (afipConnFEB.ConnectionErrorDescription == string.Empty)
                {
                    //Inicializo el objeto AuthRequest de la Afip
                    afipObjFEBAuthRequest.Cuit = afipConnFEB.Cuit;
                    afipObjFEBAuthRequest.Sign = afipConnFEB.Sign;
                    afipObjFEBAuthRequest.Token = afipConnFEB.Token;

                    if (chkIncoterms.Checked)
                    {
                        wsfex.FEXResponse_Inc resultInc = afipFEXService.FEXGetPARAM_Incoterms(afipObjFEXAuthRequest);
                        for (int u = 0; u < resultInc.FEXResultGet.Length; u++)
                        {
                            wsfex.ClsFEXResponse_Inc thisValue = (wsfex.ClsFEXResponse_Inc)resultInc.FEXResultGet.GetValue(u);
                            strCodigo = thisValue.Inc_Id.ToString();
                            strDescripcion = thisValue.Inc_Ds.ToString();
                            sqlEngine.InsertarCodigo("AFIPIncoterms", strCodigo, strDescripcion);
                        }
                    }

                    if (chkJurisdiccion.Checked)
                    {
                        //No hay clase en AFIP
                    }

                    if (chkMoneda.Checked)
                    {
                        wsfex.FEXResponse_Mon resultMon = afipFEXService.FEXGetPARAM_MON(afipObjFEXAuthRequest);
                        for (int u = 0; u < resultMon.FEXResultGet.Length; u++)
                        {
                            wsfex.ClsFEXResponse_Mon thisValue = (wsfex.ClsFEXResponse_Mon)resultMon.FEXResultGet.GetValue(u);
                            strCodigo = thisValue.Mon_Id.ToString();
                            strDescripcion = thisValue.Mon_Ds.ToString();
                            sqlEngine.InsertarCodigo("AFIPMoneda", strCodigo, strDescripcion);
                        }
                    }

                    if (chkOperacion.Checked)
                    {
                        //No hay clase en AFIP
                    }

                    if (chkPais.Checked)
                    {
                        wsfex.FEXResponse_DST_pais resultPais = afipFEXService.FEXGetPARAM_DST_pais(afipObjFEXAuthRequest);
                        for (int u = 0; u < resultPais.FEXResultGet.Length; u++)
                        {
                            wsfex.ClsFEXResponse_DST_pais thisValue = (wsfex.ClsFEXResponse_DST_pais)resultPais.FEXResultGet.GetValue(u);
                            strCodigo = thisValue.DST_Codigo.ToString();
                            strDescripcion = thisValue.DST_Ds.ToString();
                            sqlEngine.InsertarCodigo("AFIPPais", strCodigo, strDescripcion);
                        }
                    }

                    if (chkTasaIVA.Checked)
                    {
                        wsfeb.BFEResponse_Tipo_IVA resultTipoIVA = afipFEBService.BFEGetPARAM_Tipo_IVA(afipObjFEBAuthRequest);
                        for (int u = 0; u < resultTipoIVA.BFEResultGet.Length; u++)
                        {
                            wsfeb.ClsBFEResponse_Tipo_IVA thisValue = (wsfeb.ClsBFEResponse_Tipo_IVA)resultTipoIVA.BFEResultGet.GetValue(u);
                            strCodigo = thisValue.IVA_Id.ToString();
                            strDescripcion = thisValue.IVA_Ds.ToString();
                            sqlEngine.InsertarCodigo("AFIPTasaIVA", strCodigo, strDescripcion);
                        }
                    }

                    if (chkTipoCbte.Checked)
                    {
                        wsfex.FEXResponse_Tipo_Cbte resultCbtes = afipFEXService.FEXGetPARAM_Tipo_Cbte(afipObjFEXAuthRequest);
                        for (int u = 0; u < resultCbtes.FEXResultGet.Length; u++)
                        {
                            wsfex.ClsFEXResponse_Tipo_Cbte thisValue = (wsfex.ClsFEXResponse_Tipo_Cbte)resultCbtes.FEXResultGet.GetValue(u);
                            strCodigo = thisValue.Cbte_Id.ToString();
                            strDescripcion = thisValue.Cbte_Ds.ToString();
                            sqlEngine.InsertarCodigo("AFIPTipoComprobante", strCodigo, strDescripcion);
                        }
                    }

                    if (chkTipoDoc.Checked)
                    {
                        wsfeb.BFEResponse_Tipo_doc resultTipoDoc = afipFEBService.BFEGetPARAM_Tipo_doc(afipObjFEBAuthRequest);
                        for (int u = 0; u < resultTipoDoc.BFEResultGet.Length; u++)
                        {
                            wsfeb.ClsBFEResponse_Tipo_doc thisValue = (wsfeb.ClsBFEResponse_Tipo_doc)resultTipoDoc.BFEResultGet.GetValue(u);
                            strCodigo = thisValue.Doc_Id.ToString();
                            strDescripcion = thisValue.Doc_Ds.ToString();
                            sqlEngine.InsertarCodigo("AFIPTipoDocumento", strCodigo, strDescripcion);
                        }
                    }

                    if (chkUnidadMedida.Checked)
                    {
                        wsfex.FEXResponse_Umed resultUmed = afipFEXService.FEXGetPARAM_UMed(afipObjFEXAuthRequest); ;
                        for (int u = 0; u < resultUmed.FEXResultGet.Length; u++)
                        {
                            wsfex.ClsFEXResponse_UMed thisValue = (wsfex.ClsFEXResponse_UMed)resultUmed.FEXResultGet.GetValue(u);
                            strCodigo = thisValue.Umed_Id.ToString();
                            strDescripcion = thisValue.Umed_Ds.ToString();
                            sqlEngine.InsertarCodigo("AFIPUnidadMedida", strCodigo, strDescripcion);
                        }
                    }

                    if (chkTipoResponsable.Checked)
                    {
                        //No hay clase en AFIP
                    }

                    if (chkZona.Checked)
                    {
                        wsfeb.BFEResponse_Zon resultZon = afipFEBService.BFEGetPARAM_Zonas(afipObjFEBAuthRequest);
                        for (int u = 0; u < resultZon.BFEResultGet.Length; u++)
                        {
                            wsfeb.ClsBFEResponse_Zon thisValue = (wsfeb.ClsBFEResponse_Zon)resultZon.BFEResultGet.GetValue(u);
                            strCodigo = thisValue.Zon_Id.ToString();
                            strDescripcion = thisValue.Zon_Ds.ToString();
                            sqlEngine.InsertarCodigo("AFIPZona", strCodigo, strDescripcion);
                        }
                    }

                    if (chkTipoNCM.Checked)
                    {
                        wsfeb.BFEResponse_NCM resultNCM = afipFEBService.BFEGetPARAM_NCM(afipObjFEBAuthRequest);

                        if (resultNCM.BFEResultGet != null)
                        {
                            for (int u = 0; u < resultNCM.BFEResultGet.Length; u++)
                            {
                                wsfeb.ClsBFEResponse_NCM thisValue = (wsfeb.ClsBFEResponse_NCM)resultNCM.BFEResultGet.GetValue(u);
                                strCodigo = thisValue.NCM_Codigo.ToString();
                                strDescripcion = thisValue.NCM_Ds.ToString();
                                sqlEngine.InsertarCodigo("AFIPCodigoNCM", strCodigo, strDescripcion);
                            }
                        }
                        else if (resultNCM.BFEErr != null)
                        {
                            lblErrorMessages.Text = "Error al procesar Tabla AFIPCodigoNCM.<br>Codigo: " + resultNCM.BFEErr.ErrCode.ToString() + "<br>Error: " + resultNCM.BFEErr.ErrMsg;
                        }
                    }
                }
                else
                {
                    string errorMessage = "Error de login con AFIP.";

                    if (afipConnFEB != null && afipConnFEB.ConnectionErrorDescription != string.Empty)
                        errorMessage += "Error: " + afipConnFEB.ConnectionErrorDescription;

                    Page.ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('" + errorMessage + "')", true);
                }
            }
            catch (Exception ex)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "Popup", "alert('Error: " + ex.Message + "')", true);
            }
            sqlEngine.Close();
        }
Exemplo n.º 5
0
 /// <summary>
 /// GetpathConfig()
 /// Publica el path de busqueda de la dll se usa en tiempo de ejecucion
 /// </summary>
 /// <returns>string</returns>
 public static string GetpathConfig()
 {
     FacturaElectronica.DBEngine.SQLEngine sqle = new SQLEngine();
     return sqle.GetPath();
 }
Exemplo n.º 6
0
        public AfipConnection(string serviceID, Settings oSettings)
        {
            SQLEngine sqlEngine = new SQLEngine();

            RutaCertSigner = oSettings.PathCertificate;
            UrlWsaaWsdl = oSettings.UrlAFIPwsaa;
            IdServicioNegocio = serviceID;

            try
            {
                // Si el archivo con info de conexión no existe, lo creo
                //if (!System.IO.File.Exists(@"C:\" + IdServicioNegocio + ".XML"))
                if (!System.IO.File.Exists(oSettings.PathConnectionFiles + @"\" + IdServicioNegocio + ".XML"))
                {
                    this.Connect();
                    if (IsConnected)
                    {
                        string connectionTicket = ConnectionTicket;
                        // Grabar el archivo de salida
                        XmlDocument x_xmld = new XmlDocument();
                        x_xmld.LoadXml(connectionTicket);
                        x_xmld.Save(oSettings.PathConnectionFiles + @"\" + IdServicioNegocio + ".XML");
                    }
                }

                // Usar el token del archivo, si es que no está vencido
                if (System.IO.File.Exists(oSettings.PathConnectionFiles + @"\" + IdServicioNegocio + ".XML"))
                {
                    // #### Obtengo del tikcet de acceso TA.xml los campos token y sign ####
                    XmlDocument m_xmld;
                    XmlNodeList m_nodelist;
                    //XmlNode m_expiration_node;

                    m_xmld = new XmlDocument();
                    m_xmld.Load(oSettings.PathConnectionFiles + @"\" + IdServicioNegocio + ".XML"); // Debe indicar la Ruta de su Ticket de acceso
                    string stringExpirationTime = m_xmld.SelectSingleNode("/loginTicketResponse/header/expirationTime").FirstChild.Value;
                    DateTime expirationTime = Convert.ToDateTime(stringExpirationTime);
                    //Uso el ticket existente hasta que la fecha de vencimiento esté a 15 minutos de vencer
                    if (DateTime.Compare(expirationTime, DateTime.Now.AddMinutes(15)) > 0)
                    {
                        m_nodelist = m_xmld.SelectNodes("/loginTicketResponse/credentials");
                        // Loop through the nodes
                        foreach (XmlNode m_node in m_nodelist)
                        {
                            Token = m_node.ChildNodes.Item(0).InnerText;
                            Sign = m_node.ChildNodes.Item(1).InnerText;
                        }
                        XmlNode m_source = m_xmld.SelectSingleNode("/loginTicketResponse/header/destination").FirstChild;
                        Cuit = (long)Convert.ToDouble(m_source.Value.ToString().Substring(m_source.Value.ToString().IndexOf("CUIT ") + 5, 11));
                        IsConnected = true;
                    }
                    else
                    {
                        this.Connect();
                        if (IsConnected)
                        {
                            string connectionTicket = ConnectionTicket;
                            // Grabar el archivo de salida
                            XmlDocument x_xmld = new XmlDocument();
                            x_xmld.LoadXml(connectionTicket);
                            x_xmld.Save(oSettings.PathConnectionFiles + @"\" + IdServicioNegocio + ".XML");

                            // Setear las variables de la clase
                            stringExpirationTime = x_xmld.SelectSingleNode("/loginTicketResponse/header/expirationTime").FirstChild.Value;
                            expirationTime = Convert.ToDateTime(stringExpirationTime);
                            m_nodelist = x_xmld.SelectNodes("/loginTicketResponse/credentials");
                            // Loop through the nodes
                            foreach (XmlNode m_node in m_nodelist)
                            {
                                Token = m_node.ChildNodes.Item(0).InnerText;
                                Sign = m_node.ChildNodes.Item(1).InnerText;
                            }
                            XmlNode m_source = x_xmld.SelectSingleNode("/loginTicketResponse/header/destination").FirstChild;
                            Cuit = (long)Convert.ToDouble(m_source.Value.ToString().Substring(m_source.Value.ToString().IndexOf("CUIT ") + 5, 11));
                        }
                        else
                        {
                            string connectionErrorDescription = ConnectionErrorDescription;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
               sqlEngine.LogError("0", "0", "AFIP Connection", "Error: " + ex.Message);
            }

            sqlEngine.Close();
        }