public Boolean GrabarDB(tb_comprobante_exportado_base_ext_Info Comprobante_info, ref string MensajeError)
        {
            try
            {
                using (EntitiesFactElectronica Context = new EntitiesFactElectronica())
                {
                    var Address = new tb_comprobante_exportado_base_ext();

                    Address.IdEmpresa              = Comprobante_info.IdEmpresa;
                    Address.IdComprobante          = Comprobante_info.IdComprobante;
                    Address.IdTipoDocumento        = Comprobante_info.IdTipoDocumento;
                    Address.observacion            = Comprobante_info.observacion;
                    Address.fecha_hora_exportacion = DateTime.Now;
                    Context.tb_comprobante_exportado_base_ext.Add(Address);
                    Context.SaveChanges();
                    MensajeError = "Proceso OK";
                }

                return(true);
            }
            catch (Exception ex)
            {
                MensajeError = ex.InnerException + " " + ex.Message;
                tb_sis_Log_Error_Vzen_Data oDataLog      = new tb_sis_Log_Error_Vzen_Data();
                tb_sis_Log_Error_Vzen_Info Log_Error_sis = new tb_sis_Log_Error_Vzen_Info(ex.ToString(), eTipoError.ERROR, MensajeError, "",
                                                                                          "", "", "", "", DateTime.Now);
                oDataLog.Guardar_Log_Error(Log_Error_sis, ref MensajeError);
                return(false);
            }
        }
 public Boolean GrabarDB(tb_comprobante_exportado_base_ext_Info Comprobante_info, ref string MensajeError)
 {
     try
     {
         return(Odata.GrabarDB(Comprobante_info, ref MensajeError));
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
        public List <tb_comprobante_exportado_base_ext_Info> consultar(ref string MensajeError)
        {
            try
            {
                List <tb_comprobante_exportado_base_ext_Info> lista = new List <tb_comprobante_exportado_base_ext_Info>();
                using (EntitiesFactElectronica conexion = new EntitiesFactElectronica())
                {
                    conexion.Database.CommandTimeout = 3000;


                    var q = from C in conexion.tb_comprobante_exportado_base_ext
                            select C;
                    foreach (var item in q)
                    {
                        tb_comprobante_exportado_base_ext_Info infoC = new tb_comprobante_exportado_base_ext_Info();

                        infoC.IdEmpresa              = item.IdEmpresa;
                        infoC.IdComprobante          = item.IdComprobante;
                        infoC.IdTipoDocumento        = item.IdTipoDocumento;
                        infoC.fecha_hora_exportacion = item.fecha_hora_exportacion;
                        infoC.observacion            = item.observacion;

                        lista.Add(infoC);

                        MensajeError = "Proceso OK";
                    }
                }
                return(lista);
            }
            catch (Exception ex)
            {
                string arreglo = ToString();
                tb_sis_Log_Error_Vzen_Data oDataLog      = new tb_sis_Log_Error_Vzen_Data();
                tb_sis_Log_Error_Vzen_Info Log_Error_sis = new tb_sis_Log_Error_Vzen_Info(ex.ToString(), eTipoError.ERROR, arreglo, "",
                                                                                          "", "", "", "", DateTime.Now);

                MensajeError = ex.InnerException + " " + ex.Message;
                oDataLog.Guardar_Log_Error(Log_Error_sis, ref MensajeError);

                return(new List <tb_comprobante_exportado_base_ext_Info>());
            }
        }
Esempio n. 4
0
        public bool GrabarDB(Info.tb_Comprobante_Info InfoCbte, ref string MensajeErrorOut, string cadena)
        {
            tb_comprobante_exportado_base_ext_Data DataCbte_Expo = new tb_comprobante_exportado_base_ext_Data();
            tb_comprobante_exportado_base_ext_Info InfoCbte_Expo = new tb_comprobante_exportado_base_ext_Info();


            tb_Empresa_Info InfoEmpresa = new tb_Empresa_Info();
            tb_Empresa_Data EmpresaData = new tb_Empresa_Data();
            string          SQL = "", id_Comprobante = "", TipoDoc = "";


            InfoEmpresa = EmpresaData.GetEmpresa(InfoCbte.IdEmpresa, ref MensajeErrorOut);
            Formato     = InfoEmpresa.Formato_fecha_Base_ext;

            // cambio el formato de la fecha de  autorizacion del documento
            fecha_a_cambiar_autorizacion = InfoCbte.FechaAutorizacion.ToString();
            Fecha_cambiada_autorizacion  = Convert.ToDateTime(fecha_a_cambiar_autorizacion).ToString(Formato + " " + "HH:mm:ss");
            Fecha_Autorizacion           = Fecha_cambiada_autorizacion.ToString();
            // cambio el formato de la fecha de envio del documento

            fecha_a_cambiar_envio_doc = InfoCbte.Fecha_transaccion.ToString();
            Fecha_cambiada_envio_doc  = Convert.ToDateTime(fecha_a_cambiar_envio_doc).ToString(Formato + " " + "HH:mm:ss");
            Fecha_cambiada_envio_doc  = Fecha_cambiada_envio_doc.ToString();
            try
            {
                using (SqlConnection conexion = new SqlConnection(cadena))
                {
                    SqlCommand    cmd    = new SqlCommand();
                    SqlDataReader reader = null;


                    conexion.Open();
                    TipoDoc = InfoCbte.IdTipoDocumento;
                    switch (TipoDoc)
                    {
                    case "01":
                        id_Comprobante = "FC " + InfoCbte.IdComprobante.Substring(3, 3) + "-" + InfoCbte.IdComprobante.Substring(7, 3) + "-" + InfoCbte.IdComprobante.Substring(11, 9);
                        #region integracion antigua
                        // UPDATE A LA TABLA TLEPAR220
                        //SQL = "UPDATE TLEPAR220 SET T_AUTO='" + InfoCbte.Numero_Autorizacion + "',T_FEEN='" + Fecha_cambiada_envio_doc + "',T_FECO='" + Fecha_Autorizacion + "',T_FERE='" + Fecha_Autorizacion + "',T_STAT='5'" +
                        //  "WHERE T_NINV = '" + id_Comprobante + "' AND DATAAREAID ='expg'";
                        // cmd = new SqlCommand(SQL, conexion);
                        // reader = cmd.ExecuteReader();
                        // reader.Close();


                        // // UPDATE A LA TABLA TLEPAR221
                        //   id_Comprobante = "F_" + InfoCbte.IdComprobante.Substring(3, 3) + InfoCbte.IdComprobante.Substring(7, 3) + InfoCbte.IdComprobante.Substring(11, 9);

                        //   SQL = "UPDATE TLEPAR221 SET T_AUTO='" + InfoCbte.Numero_Autorizacion + "',T_FEEN='" + Fecha_cambiada_envio_doc + "',T_FECO='" + Fecha_Autorizacion + "',T_FERE='" + Fecha_Autorizacion + "',T_STAT='5'" +
                        //   "WHERE T_NINV = '" + id_Comprobante + "' AND DATAAREAID ='expg'";
                        //   cmd = new SqlCommand(SQL, conexion);
                        //   reader = cmd.ExecuteReader();
                        //   reader.Close();
                        #endregion

                        // UPDATE A LA TABLA custInvoiceJour
                        SQL    = "UPDATE custInvoiceJour SET MNT_EInvoiceAuthNum='" + InfoCbte.Numero_Autorizacion + "',MNT_EInvoiceAuthDate='" + Fecha_Autorizacion + "',MNT_EInvoiceStatusId='2'" + "WHERE INVOICEID = '" + id_Comprobante + "' AND DATAAREAID ='expg'";
                        cmd    = new SqlCommand(SQL, conexion);
                        reader = cmd.ExecuteReader();
                        reader.Close();


                        // UPDATE A LA TABLA ProjInvoiceJour
                        id_Comprobante = "FC " + InfoCbte.IdComprobante.Substring(3, 3) + "-" + InfoCbte.IdComprobante.Substring(7, 3) + "-" + InfoCbte.IdComprobante.Substring(11, 9);

                        SQL    = "UPDATE ProjInvoiceJour SET MNT_EInvoiceAuthNum='" + InfoCbte.Numero_Autorizacion + "',MNT_EInvoiceAuthDate='" + Fecha_Autorizacion + "',MNT_EInvoiceStatusId='2'" + "WHERE PROJINVOICEID = '" + id_Comprobante + "' AND DATAAREAID ='expg'";
                        cmd    = new SqlCommand(SQL, conexion);
                        reader = cmd.ExecuteReader();
                        reader.Close();
                        break;

                    case "04":

                        id_Comprobante = "NC " + InfoCbte.IdComprobante.Substring(3, 3) + "-" + InfoCbte.IdComprobante.Substring(7, 3) + "-" + InfoCbte.IdComprobante.Substring(11, 9);
                        #region integracion antigua
                        // UPDATE EN LA TABLA TLEPAR220
                        //SQL = "UPDATE TLEPAR220 SET T_AUTO='" + InfoCbte.Numero_Autorizacion + "',T_FEEN='" + Fecha_cambiada_envio_doc + "',T_FECO='" + Fecha_Autorizacion + "',T_FERE='" + Fecha_Autorizacion + "',T_STAT='5'" +
                        // "WHERE T_NINV = '" + id_Comprobante + "' AND DATAAREAID ='expg'";

                        //cmd = new SqlCommand(SQL, conexion);
                        //reader = cmd.ExecuteReader();
                        //reader.Close();


                        //// UPDATE EN LA TABLA TLEPAR221
                        // id_Comprobante = "NC_" + InfoCbte.IdComprobante.Substring(3, 3) + InfoCbte.IdComprobante.Substring(7, 3) + InfoCbte.IdComprobante.Substring(11, 9);

                        // SQL = "UPDATE TLEPAR221 SET T_AUTO='" + InfoCbte.Numero_Autorizacion + "',T_FEEN='" + Fecha_cambiada_envio_doc + "',T_FECO='" + Fecha_Autorizacion + "',T_FERE='" + Fecha_Autorizacion + "',T_STAT='5'" +
                        // "WHERE T_NINV = '" + id_Comprobante + "' AND DATAAREAID ='expg'";
                        // cmd = new SqlCommand(SQL, conexion);
                        // reader = cmd.ExecuteReader();
                        // reader.Close();
                        #endregion

                        // UPDATE A LA TABLA custInvoiceJour
                        SQL    = "UPDATE custInvoiceJour SET MNT_EInvoiceAuthNum='" + InfoCbte.Numero_Autorizacion + "',MNT_EInvoiceAuthDate='" + Fecha_Autorizacion + "',MNT_EInvoiceStatusId='2'" + "WHERE INVOICEID = '" + id_Comprobante + "' AND DATAAREAID ='expg'";
                        cmd    = new SqlCommand(SQL, conexion);
                        reader = cmd.ExecuteReader();
                        reader.Close();

                        // UPDATE A LA TABLA ProjInvoiceJour
                        id_Comprobante = "NC " + InfoCbte.IdComprobante.Substring(3, 3) + "-" + InfoCbte.IdComprobante.Substring(7, 3) + "-" + InfoCbte.IdComprobante.Substring(11, 9);

                        SQL    = "UPDATE ProjInvoiceJour SET MNT_EInvoiceAuthNum='" + InfoCbte.Numero_Autorizacion + "',MNT_EInvoiceAuthDate='" + Fecha_Autorizacion + "',MNT_EInvoiceStatusId='2'" + "WHERE PROJINVOICEID = '" + id_Comprobante + "' AND DATAAREAID ='expg'";
                        cmd    = new SqlCommand(SQL, conexion);
                        reader = cmd.ExecuteReader();
                        reader.Close();

                        break;

                    case "07":


                        id_Comprobante = InfoCbte.IdComprobante.Substring(3, 3) + "-" + InfoCbte.IdComprobante.Substring(7, 3) + "-" + InfoCbte.IdComprobante.Substring(11, 9);

                        SQL    = "UPDATE MNT_OCRetentionTable SET MNT_EInvoiceAuthNum='" + InfoCbte.Numero_Autorizacion + "',MNT_EInvoiceAuthDate='" + Fecha_Autorizacion + "',MNT_EInvoiceStatusId='2'" + "WHERE NUMCHECKRETENTION = '" + id_Comprobante + "' AND DATAAREAID ='expg'";
                        cmd    = new SqlCommand(SQL, conexion);
                        reader = cmd.ExecuteReader();
                        reader.Close();

                        #region integracion antigua
                        // // UPDATE EN LA TABLA TLEPAR220
                        // SQL = "UPDATE TLEPAR220 SET T_AUTO='" + InfoCbte.Numero_Autorizacion + "',T_FEEN='" + Fecha_cambiada_envio_doc + "',T_FECO='" + Fecha_Autorizacion + "',T_FERE='" + Fecha_Autorizacion + "',T_STAT='5'" +
                        // "WHERE T_NINV = '" + id_Comprobante + "' AND DATAAREAID ='expg'";
                        // cmd = new SqlCommand(SQL, conexion);
                        // reader = cmd.ExecuteReader();
                        // reader.Close();

                        // // UPDATE EN LA TABLA TLEPAR223
                        // id_Comprobante = InfoCbte.IdComprobante.Substring(3, 3) + InfoCbte.IdComprobante.Substring(7, 3) + InfoCbte.IdComprobante.Substring(11, 9);
                        // SQL = "UPDATE TLEPAR222 SET T_AUTO='" + InfoCbte.Numero_Autorizacion + "',T_FEEN='" + Fecha_cambiada_envio_doc + "',T_FECO='" + Fecha_Autorizacion + "',T_FERE='" + Fecha_Autorizacion + "',T_STAT='5'" +
                        // "WHERE T_NINV = '" + id_Comprobante + "' AND DATAAREAID ='expg'";
                        // cmd = new SqlCommand(SQL, conexion);
                        // reader = cmd.ExecuteReader();
                        // reader.Close();
                        #endregion

                        break;

                    default:
                        break;
                    }
                }


                InfoCbte_Expo.IdEmpresa              = InfoCbte.IdEmpresa;
                InfoCbte_Expo.IdComprobante          = InfoCbte.IdComprobante;
                InfoCbte_Expo.IdTipoDocumento        = InfoCbte.IdTipoDocumento;
                InfoCbte_Expo.observacion            = "exportado por efirm";
                InfoCbte_Expo.fecha_hora_exportacion = DateTime.Now;
                DataCbte_Expo.GrabarDB(InfoCbte_Expo, ref MensajeErrorOut);

                return(true);
            }
            catch (Exception ex)
            {
                MensajeErrorOut = ex.Message;
                return(false);
            }
        }
Esempio n. 5
0
      public bool GrabarDB(Info.tb_Comprobante_Info InfoCbte, ref string MensajeErrorOut, string cadena)
      {
          tb_comprobante_exportado_base_ext_Data DataCbte_Expo = new tb_comprobante_exportado_base_ext_Data();
          tb_comprobante_exportado_base_ext_Info InfoCbte_Expo = new tb_comprobante_exportado_base_ext_Info();


          tb_Empresa_Info InfoEmpresa = new tb_Empresa_Info();
          tb_Empresa_Data EmpresaData = new tb_Empresa_Data();
          string          SQL = "", id_Comprobante = "", TipoDoc = "";


          InfoEmpresa = EmpresaData.GetEmpresa(InfoCbte.IdEmpresa, ref MensajeErrorOut);
          Formato     = InfoEmpresa.Formato_fecha_Base_ext;

          // cambio el formato de la fecha de  autorizacion del documento
          fecha_a_cambiar_autorizacion = InfoCbte.FechaAutorizacion.ToString();
          Fecha_cambiada_autorizacion  = Convert.ToDateTime(fecha_a_cambiar_autorizacion).ToString(Formato + " " + "HH:mm:ss");
          Fecha_Autorizacion           = Fecha_cambiada_autorizacion.ToString();
          // cambio el formato de la fecha de envio del documento

          fecha_a_cambiar_envio_doc = InfoCbte.Fecha_transaccion.ToString();
          Fecha_cambiada_envio_doc  = Convert.ToDateTime(fecha_a_cambiar_envio_doc).ToString(Formato + " " + "HH:mm:ss");
          Fecha_cambiada_envio_doc  = Fecha_cambiada_envio_doc.ToString();
          try
          {
              using (SqlConnection conexion = new SqlConnection(cadena))
              {
                  SqlCommand    cmd    = new SqlCommand();
                  SqlDataReader reader = null;


                  conexion.Open();
                  TipoDoc = InfoCbte.IdTipoDocumento;
                  string serie1       = "";
                  string serie2       = "";
                  string NumDocumento = "";

                  switch (TipoDoc)
                  {
                  // UPDATE A LA TABLA TLEPAR220
                  case "01":

                      serie1       = InfoCbte.IdComprobante.Substring(3, 3);
                      serie2       = InfoCbte.IdComprobante.Substring(7, 3);
                      NumDocumento = InfoCbte.IdComprobante.Substring(11, 9);

                      SQL = "UPDATE fa_factura SET vt_autorizacion='" + InfoCbte.Numero_Autorizacion + "',Fecha_Autorizacion='" + InfoCbte.FechaAutorizacion + "'" +
                            "from vwfa_factura_x_empresa as E " +
                            "where E.IdEmpresa=fa_factura.IdEmpresa " +
                            "and E.vt_serie1=fa_factura.vt_serie1 " +
                            "and E.vt_serie2=fa_factura.vt_serie2 " +
                            "and E.vt_NumFactura=fa_factura.vt_NumFactura " +
                            "and E.em_ruc='" + InfoEmpresa.RUC + "' " +
                            "and E.vt_serie1='" + serie1 + "' " +
                            "and E.vt_serie2 ='" + serie2 + "' " +
                            "and E.vt_NumFactura ='" + NumDocumento + "' ";
                      cmd    = new SqlCommand(SQL, conexion);
                      reader = cmd.ExecuteReader();
                      reader.Close();

                      // actualizo el talonario

                      SQL = "UPDATE tb_sis_Documento_Tipo_Talonario SET NumAutorizacion='" + InfoCbte.Numero_Autorizacion + "'" +
                            "from vwtb_tb_sis_Documento_Tipo_Talonario as E " +
                            "where E.IdEmpresa=tb_sis_Documento_Tipo_Talonario.IdEmpresa " +
                            "and E.Establecimiento=tb_sis_Documento_Tipo_Talonario.Establecimiento " +
                            "and E.PuntoEmision=tb_sis_Documento_Tipo_Talonario.PuntoEmision " +
                            "and tb_sis_Documento_Tipo_Talonario.CodDocumentoTipo='FACT'" +
                            "and E.NumDocumento=tb_sis_Documento_Tipo_Talonario.NumDocumento " +
                            "and E.em_ruc='" + InfoEmpresa.RUC + "' " +
                            "and E.Establecimiento='" + serie1 + "' " +
                            "and E.PuntoEmision ='" + serie2 + "' " +
                            "and E.NumDocumento ='" + NumDocumento + "' ";
                      cmd    = new SqlCommand(SQL, conexion);
                      reader = cmd.ExecuteReader();
                      reader.Close();


                      break;

                  case "04":


                      serie1       = InfoCbte.IdComprobante.Substring(3, 3);
                      serie2       = InfoCbte.IdComprobante.Substring(7, 3);
                      NumDocumento = InfoCbte.IdComprobante.Substring(11, 9);
                      SQL          = "UPDATE fa_notaCreDeb SET NumAutorizacion='" + InfoCbte.Numero_Autorizacion + "',Fecha_Autorizacion='" + InfoCbte.FechaAutorizacion + "'" +
                                     "from vwfa_fa_notaCreDeb_x_empresa as E " +
                                     "where E.IdEmpresa=fa_factura.IdEmpresa " +
                                     "and fa_notaCreDeb.CreDeb='C'" +
                                     "and E.Serie1=fa_factura.Serie1 " +
                                     "and E.Serie2=fa_factura.Serie2 " +
                                     "and E.NumNota_Impresa=fa_notaCreDeb.NumNota_Impresa " +
                                     "and E.em_ruc='" + InfoEmpresa.RUC + "' " +
                                     "and E.Serie1='" + serie1 + "' " +
                                     "and E.Serie1 ='" + serie2 + "' " +
                                     "and E.NumNota_Impresa ='" + NumDocumento + "' ";

                      cmd    = new SqlCommand(SQL, conexion);
                      reader = cmd.ExecuteReader();
                      reader.Close();

                      // actualizo el talonario

                      SQL = "UPDATE tb_sis_Documento_Tipo_Talonario SET NumAutorizacion='" + InfoCbte.Numero_Autorizacion + "'" +
                            "from vwtb_tb_sis_Documento_Tipo_Talonario as E " +
                            "where E.IdEmpresa=tb_sis_Documento_Tipo_Talonario.IdEmpresa " +
                            "and E.Establecimiento=tb_sis_Documento_Tipo_Talonario.Establecimiento " +
                            "and E.PuntoEmision=tb_sis_Documento_Tipo_Talonario.PuntoEmision " +
                            "and tb_sis_Documento_Tipo_Talonario.CodDocumentoTipo='NTCR'" +
                            "and E.NumDocumento=tb_sis_Documento_Tipo_Talonario.NumDocumento " +
                            "and E.em_ruc='" + InfoEmpresa.RUC + "' " +
                            "and E.Establecimiento='" + serie1 + "' " +
                            "and E.PuntoEmision ='" + serie2 + "' " +
                            "and E.NumDocumento ='" + NumDocumento + "' ";
                      cmd    = new SqlCommand(SQL, conexion);
                      reader = cmd.ExecuteReader();
                      reader.Close();


                      break;


                  case "07":

                      serie1       = InfoCbte.IdComprobante.Substring(3, 3);
                      serie2       = InfoCbte.IdComprobante.Substring(7, 3);
                      serie1       = serie1 + "-" + serie2;
                      NumDocumento = InfoCbte.IdComprobante.Substring(11, 9);
                      SQL          = "UPDATE cp_retencion SET NAutorizacion='" + InfoCbte.Numero_Autorizacion + "',Fecha_Autorizacion='" + InfoCbte.FechaAutorizacion + "'" +
                                     "FROM dbo.cp_retencion AS ret INNER JOIN" +
                                     " dbo.vwcp_cp_retencion_x_empresa AS ret_x_emp ON ret.IdEmpresa = ret_x_emp.IdEmpresa AND ret.IdRetencion = ret_x_emp.IdRetencion " +
                                     " where em_ruc='" + InfoEmpresa.RUC + "' " +
                                     " and serie='" + serie1 + "' " +
                                     " and ret.NumRetencion ='" + NumDocumento + "' ";

                      cmd    = new SqlCommand(SQL, conexion);
                      reader = cmd.ExecuteReader();
                      reader.Close();


                      // actualizo el talonario

                      SQL = "UPDATE tb_sis_Documento_Tipo_Talonario SET NumAutorizacion='" + InfoCbte.Numero_Autorizacion + "'" +
                            "from vwtb_tb_sis_Documento_Tipo_Talonario as E " +
                            "where E.IdEmpresa=tb_sis_Documento_Tipo_Talonario.IdEmpresa " +
                            "and E.Establecimiento=tb_sis_Documento_Tipo_Talonario.Establecimiento " +
                            "and E.PuntoEmision=tb_sis_Documento_Tipo_Talonario.PuntoEmision " +
                            "and tb_sis_Documento_Tipo_Talonario.CodDocumentoTipo='RETEN'" +
                            "and E.NumDocumento=tb_sis_Documento_Tipo_Talonario.NumDocumento " +
                            "and E.em_ruc='" + InfoEmpresa.RUC + "' " +
                            "and E.Establecimiento='" + serie1 + "' " +
                            "and E.PuntoEmision ='" + serie2 + "' " +
                            "and E.NumDocumento ='" + NumDocumento + "' ";
                      cmd    = new SqlCommand(SQL, conexion);
                      reader = cmd.ExecuteReader();
                      reader.Close();

                      break;



                  case "06":

                      serie1       = InfoCbte.IdComprobante.Substring(3, 3);
                      serie2       = InfoCbte.IdComprobante.Substring(7, 3);
                      serie1       = serie1 + "-" + serie2;
                      NumDocumento = InfoCbte.IdComprobante.Substring(11, 9);
                      SQL          = "UPDATE fa_guia_remision SET NUAutorizacion='" + InfoCbte.Numero_Autorizacion + "',Fecha_Autorizacion='" + InfoCbte.FechaAutorizacion + "'" +
                                     "from vwfa_fa_guia_remision_x_empresa as E " +
                                     "where E.IdEmpresa=fa_guia_remision.IdEmpresa " +
                                     "and E.Serie1=fa_guia_remision.Serie1 " +
                                     "and E.Serie2=fa_guia_remision.Serie2 " +
                                     "and E.NumGuia_Preimpresa=fa_guia_remision.NumGuia_Preimpresa " +
                                     "and E.em_ruc='" + InfoEmpresa.RUC + "' " +
                                     "and E.Serie1='" + serie1 + "' " +
                                     "and E.Serie2='" + serie1 + "' " +
                                     "and E.NumGuia_Preimpresa ='" + NumDocumento + "' ";

                      cmd    = new SqlCommand(SQL, conexion);
                      reader = cmd.ExecuteReader();
                      reader.Close();


                      // actualizo el talonario

                      SQL = "UPDATE tb_sis_Documento_Tipo_Talonario SET NumAutorizacion='" + InfoCbte.Numero_Autorizacion + "'" +
                            "from vwtb_tb_sis_Documento_Tipo_Talonario as E " +
                            "where E.IdEmpresa=tb_sis_Documento_Tipo_Talonario.IdEmpresa " +
                            "and E.Establecimiento=tb_sis_Documento_Tipo_Talonario.Establecimiento " +
                            "and E.PuntoEmision=tb_sis_Documento_Tipo_Talonario.PuntoEmision " +
                            "and tb_sis_Documento_Tipo_Talonario.CodDocumentoTipo='GUIA'" +
                            "and E.NumDocumento=tb_sis_Documento_Tipo_Talonario.NumDocumento " +
                            "and E.em_ruc='" + InfoEmpresa.RUC + "' " +
                            "and E.Establecimiento='" + serie1 + "' " +
                            "and E.PuntoEmision ='" + serie2 + "' " +
                            "and E.NumDocumento ='" + NumDocumento + "' ";
                      cmd    = new SqlCommand(SQL, conexion);
                      reader = cmd.ExecuteReader();
                      reader.Close();

                      break;

                  default:
                      break;
                  }
              }


              InfoCbte_Expo.IdEmpresa              = InfoCbte.IdEmpresa;
              InfoCbte_Expo.IdComprobante          = InfoCbte.IdComprobante;
              InfoCbte_Expo.IdTipoDocumento        = InfoCbte.IdTipoDocumento;
              InfoCbte_Expo.observacion            = "exportado por efirm";
              InfoCbte_Expo.fecha_hora_exportacion = DateTime.Now;
              DataCbte_Expo.GrabarDB(InfoCbte_Expo, ref MensajeErrorOut);



              return(true);
          }
          catch (Exception ex)
          {
              MensajeErrorOut = ex.Message;
              return(false);
          }
      }