protected string mostrarIFS()
    {
        StringBuilder sb = new StringBuilder();

        try
        {
            SqlDataReader dr = INTERFACTSAP.Catalogo();

            sb.Append("<table id='tblDatos' style='font-family:Arial;font-size:8pt;' cellSpacing='0' cellPadding='0' border='1'>");
            sb.Append("<tbody>");
            sb.Append("<tr align='center'>");
            sb.Append("<td style='background-color: #BCD4DF;font-weight:bold;'>idEmpresa</td>");
            sb.Append("<td style='background-color: #BCD4DF;font-weight:bold;'>idCliente</td>");
            sb.Append("<td style='background-color: #BCD4DF;font-weight:bold;'>idProyectosubnodo</td>");
            sb.Append("<td style='background-color: #BCD4DF;font-weight:bold;'>idProyecto</td>");
            sb.Append("<td style='background-color: #BCD4DF;font-weight:bold;'>Grupo</td>");
            sb.Append("<td style='background-color: #BCD4DF;font-weight:bold;'>Serie</td>");
            sb.Append("<td style='background-color: #BCD4DF;font-weight:bold;'>Numero</td>");
            sb.Append("<td style='background-color: #BCD4DF;font-weight:bold;'>Fec_fact</td>");
            sb.Append("<td style='background-color: #BCD4DF;font-weight:bold;'>Importe</td>");
            sb.Append("<td style='background-color: #BCD4DF;font-weight:bold;'>Moneda</td>");
            sb.Append("<td style='background-color: #BCD4DF;font-weight:bold;'>Motivo</td>");
            sb.Append("<td style='background-color: #BCD4DF;font-weight:bold;'>Estado</td>");
            sb.Append("</tr>");

            while (dr.Read())
            {
                sb.Append("<tr>");
                sb.Append("<td>" + dr["t313_idempresa"].ToString() + "</td>");
                sb.Append("<td>" + dr["t302_idcliente"].ToString() + "</td>");
                sb.Append("<td>" + dr["t305_idproyectosubnodo"].ToString() + "</td>");
                sb.Append("<td>" + dr["t301_idproyecto"].ToString() + "</td>");
                sb.Append("<td>" + dr["t445_grupo"].ToString() + "</td>");
                sb.Append("<td>" + dr["t445_serie"].ToString() + "</td>");
                sb.Append("<td>" + dr["t445_numero"].ToString() + "</td>");
                sb.Append("<td>" + dr["t445_fec_fact"].ToString() + "</td>");
                sb.Append("<td>" + dr["t445_imp_fact"].ToString() + "</td>");
                sb.Append("<td>" + dr["t445_moneda"].ToString() + "</td>");
                sb.Append("<td>" + dr["t445_descri"].ToString() + "</td>");
                sb.Append("<td>" + dr["t301_estado"].ToString() + "</td>");
                sb.Append("</tr>");
            }
            dr.Close();
            dr.Dispose();
            sb.Append("</tbody>");
            sb.Append("</table>");

            string sIdCache = "EXCEL_CACHE_" + Session["IDFICEPI_ENTRADA"].ToString() + "_" + DateTime.Now.ToString();
            Session[sIdCache] = sb.ToString();;

            return("OK@#@cacheado@#@" + sIdCache + "@#@" + sb.ToString());
        }
        catch (Exception ex)
        {
            return("Error@#@" + Errores.mostrarError("Error al obtener los datos de INTERFACTSAP.", ex));
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsCallback)
        {
            sErrores                 = "";
            Master.nBotonera         = 43;
            Master.bFuncionesLocales = true;
            Master.TituloPagina      = "Importación de facturas de SAP";

            if (!Page.IsPostBack)
            {
                try
                {
                    //this.txtAnno.Text = DateTime.Now.Year.ToString();
                    //Obtengo el nº de registros de la tabla T445_INTERFACTSAP
                    this.hdnNumfacts.Value = INTERFACTSAP.numFacturas(null).ToString();
                }
                catch (Exception ex)
                {
                    Master.sErrores = Errores.mostrarError("Error al cargar el número de filas en INTERFACTSAP.", ex);
                }
            }

            try{
                cldFilasIFS.InnerText = int.Parse(this.hdnNumfacts.Value).ToString("#,##0");
            }
            catch (Exception ex)
            {
                Master.sErrores = Errores.mostrarError("Error al recuperar el número de filas en INTERFACTSAP.", ex);
            }


            HttpPostedFile selectedFile = this.uplTheFile.PostedFile;
            if (selectedFile != null)
            {
                Validar(selectedFile);
            }

            string cbRespuesta = Page.ClientScript.GetCallbackEventReference(this, "arg", "RespuestaCallBack", "context", false);
            string cbLlamada   = "function RealizarCallBack(arg, context)" + "{" + cbRespuesta + ";" + "}";
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "RealizarCallBack", cbLlamada, true);
        }
    }
    private string Procesar(string sAnomes, string sCadena)
    {//En sCadena tenemos los nº de linea de facturas erróneas
        string sResul = "", lin = "", sLin = "";
        int    iNumLin = 1;

        byte[] linea = new byte[103];
        try
        {
            #region Obtenión de dataset con empresas, proyectos y clientes y creación de HASTABLES
            DataSet ds = INTERFACTSAP.EmpresasProyectos();

            htEmpEnlaceSAP = new Hashtable();
            foreach (DataRow oEmpresa in ds.Tables[0].Rows)//Recorro tabla de empresas
            {
                htEmpEnlaceSAP.Add(oEmpresa["t302_codigoexterno"].ToString(), new EmpFactSAP((int)oEmpresa["t313_idempresa"],
                                                                                             oEmpresa["t313_denominacion"].ToString(),
                                                                                             oEmpresa["t302_codigoexterno"].ToString()
                                                                                             //,(bool)oEmpresa["t313_ute"]
                                                                                             )
                                   );
            }
            //oEmpFactSAP = (EmpFactSAP)htEmpEnlaceSAP["IB01"];

            htProyEnlaceSAP = new Hashtable();
            foreach (DataRow oProy in ds.Tables[1].Rows)//Recorro tabla de proyectos
            {
                htProyEnlaceSAP.Add((int)oProy["t301_idproyecto"], new ProyFactSAP((int)oProy["t301_idproyecto"],
                                                                                   (int)oProy["t305_idproyectosubnodo"])
                                    );
            }
            //oProyFactSAP = (ProyFactSAP)htProyEnlaceSAP[20801];

            htCliEnlaceSAP = new Hashtable();
            foreach (DataRow oCliente in ds.Tables[2].Rows)//Recorro tabla de clientes
            {
                htCliEnlaceSAP.Add(oCliente["t302_codigoexterno"], new CliFactSAP((int)oCliente["t302_idcliente"],
                                                                                  oCliente["t302_codigoexterno"].ToString(),
                                                                                  ((int)oCliente["Interno"] == 1) ? true : false)
                                   );
            }
            //oCliFactSAP = (CliFactSAP)htCliEnlaceSAP[45946];

            ds.Dispose();
            #endregion

            #region Abro transaccion
            try
            {
                oConn = Conexion.Abrir();
                tr    = Conexion.AbrirTransaccion(oConn);
            }
            catch (Exception ex)
            {
                if (oConn.State == ConnectionState.Open)
                {
                    Conexion.Cerrar(oConn);
                }
                sResul = "Error@#@" + Errores.mostrarError("Error al abrir la conexión", ex);
                return(sResul);
            }
            #endregion
            //Leo el fichero de base de datos
            FICHEROSMANIOBRA oFic = FICHEROSMANIOBRA.Select(tr, Constantes.FicheroFacturasSAP);
            if (oFic.t447_fichero.Length > 0)
            {
                //Borrar contenido de T445_INTERFACTSAP
                INTERFACTSAP.Borrar(tr);

                #region Leer fichero de BBDD
                MemoryStream mstr = new MemoryStream(oFic.t447_fichero);
                mstr.Seek(0, SeekOrigin.Begin);
                int    count     = 0;
                byte[] byteArray = new byte[mstr.Length];
                while (count < mstr.Length)
                {
                    byteArray[count++] = System.Convert.ToByte(mstr.ReadByte());
                }
                lin = FromASCIIByteArray(byteArray);
                #endregion

                string[] aArgs = Regex.Split(lin, "\r\n");
                FactSAP  oFact = null;
                //int nInserts = 0;
                //Recorrer lista de facturas e insertar en T445_INTERFACTSAP las que cuyo nº de línea no está en la lista de errores
                for (int iLinea = 0; iLinea < aArgs.Length - 1; iLinea++)
                {
                    if (aArgs[iLinea] != "")
                    {
                        sLin    = aArgs[iLinea];
                        iNumLin = iLinea + 1;
                        if (sCadena.IndexOf("##" + iNumLin.ToString() + "##") == -1)
                        {
                            //oFact = FactSAP.getFactura(sLin);
                            oFact = validarFactura(FactSAP.getFactura(sLin));
                            if (!validarCampos(oFact, sAnomes, false))
                            {
                                continue;
                            }
//, oFact.ute
                            INTERFACTSAP.Insert(tr, oFact.iCodEmpresa, oFact.iCodCliente, oFact.t305_idproyectosubnodo,
                                                oFact.grupo, oFact.serie.Replace(".", ""), oFact.iNumero, oFact.dtFecFact,
                                                oFact.dImpFfact, oFact.moneda, oFact.descri, oFact.refCliente);
                            //nInserts++;
                        }
                    }
                }
            }
            sResul = "OK@#@" + INTERFACTSAP.numFacturas(tr).ToString("#,##0");
            Conexion.CommitTransaccion(tr);
        }
        catch (Exception ex)
        {
            //Errores.mostrarError("Error al tramitar el fichero", ex);
            sResul = "Error@#@" + Errores.mostrarError("Error al tramitar el fichero en la línea " + iNumLin.ToString() + " : " + sLin, ex);
        }
        finally
        {
            Conexion.CerrarTransaccion(tr);
        }
        return(sResul);
    }
    private void Validar(HttpPostedFile selectedFile)
    {
        //StringBuilder sbF = new StringBuilder();
        try
        {
            #region Obtenión de dataset con empresas, proyectos y clientes y creación de HASTABLES
            DataSet ds = INTERFACTSAP.EmpresasProyectos();
            oEmpFactSAP    = null;
            oProyFactSAP   = null;
            oCliFactSAP    = null;
            htEmpEnlaceSAP = new Hashtable();
            foreach (DataRow oEmpresa in ds.Tables[0].Rows)//Recorro tabla de empresas
            {
                try
                {
                    htEmpEnlaceSAP.Add(oEmpresa["t302_codigoexterno"].ToString(), new EmpFactSAP((int)oEmpresa["t313_idempresa"],
                                                                                                 oEmpresa["t313_denominacion"].ToString(),
                                                                                                 oEmpresa["t302_codigoexterno"].ToString()
                                                                                                 //,(bool)oEmpresa["t313_ute"]
                                                                                                 )
                                       );
                }
                catch (Exception ex)
                {
                    sErrores = Errores.mostrarError("Error al existir en la tabla 'T313_EMPRESA' diferentes empresas con el mismo código externo ", ex);
                };
            }
            //oEmpFactSAP = (EmpFactSAP)htEmpEnlaceSAP["IB01"];

            htProyEnlaceSAP = new Hashtable();
            foreach (DataRow oProy in ds.Tables[1].Rows)//Recorro tabla de proyectos
            {
                htProyEnlaceSAP.Add((int)oProy["t301_idproyecto"], new ProyFactSAP((int)oProy["t301_idproyecto"],
                                                                                   (int)oProy["t305_idproyectosubnodo"]));
            }
            //oProyFactSAP = (ProyFactSAP)htProyEnlaceSAP[20801];

            htCliEnlaceSAP = new Hashtable();
            foreach (DataRow oCliente in ds.Tables[2].Rows)//Recorro tabla de clientes
            {
                try
                {
                    htCliEnlaceSAP.Add(oCliente["t302_codigoexterno"], new CliFactSAP((int)oCliente["t302_idcliente"],
                                                                                      oCliente["t302_codigoexterno"].ToString(),
                                                                                      ((int)oCliente["Interno"] == 1)? true : false)
                                       );
                }
                catch (Exception ex)
                {
                    sErrores = Errores.mostrarError("Error al existir en la tabla 'T302_CLIENTE' diferentes clientes con el mismo código externo ", ex);
                };
            }
            //oCliFactSAP = (CliFactSAP)htCliEnlaceSAP[45946];

            ds.Dispose();
            #endregion

            if (selectedFile.ContentLength != 0)
            {
                string sFichero = selectedFile.FileName;
                //Grabo el archivo en base de datos
                byte[] ArchivoEnBinario = new Byte[0];
                ArchivoEnBinario = new Byte[selectedFile.ContentLength];                        //Crear el array de bytes con la longitud del archivo
                selectedFile.InputStream.Read(ArchivoEnBinario, 0, selectedFile.ContentLength); //Forzar al control del archivo a cargar los datos en el array

                int iRows = FICHEROSMANIOBRA.Update(null, Constantes.FicheroFacturasSAP, "Fichero origen de INTERFACTSAP", ArchivoEnBinario);
                if (iRows == 0)
                {
                    sErrores = "No existe entrada asociada a este proceso en el fichero de Maniobra";
                    return;
                }

                selectedFile.InputStream.Position = 0;
                StreamReader r     = new StreamReader(selectedFile.InputStream, System.Text.Encoding.UTF7);
                FactSAP      oFact = null;
                while (r.Peek() > -1)
                {
                    iCont++;
                    //if (iCont==909)
                    //{
                    //    string sAux = "KK";
                    //}
                    //lin = r.ReadLine();
                    //oFact = FactSAP.getFactura(lin);
                    oFact = validarFactura(FactSAP.getFactura(r.ReadLine()));
                    if (!validarCampos(oFact, this.txtAnioMes.Text, true))
                    {
                        continue;
                    }

                    iNumOk++;
                }
            }
            this.divB.InnerHtml    = cabErrores() + sbE + "</table>";
            cldFacProc.InnerText   = iCont.ToString("#,##0");
            cldFacOK.InnerText     = iNumOk.ToString("#,##0");
            cldFacErr.InnerText    = (iCont - iNumOk).ToString("#,##0");
            this.hdnIniciado.Value = "T";
        }
        catch (Exception ex)
        {
            sErrores = Errores.mostrarError("El fichero no tiene el formato requerido para el proceso.\nRevisa la línea " + iCont.ToString(), ex);
        }
    }
Exemple #5
0
    private void CargarFacturas()
    {
        StringBuilder sb = new StringBuilder();

        sb.Append("<table id='tblErrores' style='WIDTH: 680px;'>");
        sb.Append("<colgroup><col style='width:60px' /><col style='width:40px' /><col style='width:60px;' /><col style='width:520px;' /></colgroup>");

        #region Obtenión de dataset con empresas, proyectos y clientes y creación de HASTABLES
        DataSet ds = INTERFACTSAP.EmpresasProyectos();
        oEmpFactSAP  = null;
        oProyFactSAP = null;
        oCliFactSAP  = null;

        htEmpEnlaceSAP = new Hashtable();
        foreach (DataRow oEmpresa in ds.Tables[0].Rows)//Recorro tabla de empresas
        {
            htEmpEnlaceSAP.Add(oEmpresa["t302_codigoexterno"].ToString(), new EmpFactSAP((int)oEmpresa["t313_idempresa"],
                                                                                         oEmpresa["t313_denominacion"].ToString(),
                                                                                         oEmpresa["t302_codigoexterno"].ToString()
                                                                                         //,(bool)oEmpresa["t313_ute"]
                                                                                         )
                               );
        }
        //oEmpFactSAP = (EmpFactSAP)htEmpEnlaceSAP["IB01"];

        htProyEnlaceSAP = new Hashtable();
        foreach (DataRow oProy in ds.Tables[1].Rows)//Recorro tabla de empresas
        {
            htProyEnlaceSAP.Add((int)oProy["t301_idproyecto"], new ProyFactSAP((int)oProy["t301_idproyecto"],
                                                                               (int)oProy["t305_idproyectosubnodo"])
                                );
        }
        //oProyFactSAP = (ProyFactSAP)htProyEnlaceSAP[20801];

        htCliEnlaceSAP = new Hashtable();
        foreach (DataRow oCliente in ds.Tables[2].Rows)//Recorro tabla de clientes
        {
            htCliEnlaceSAP.Add(oCliente["t302_codigoexterno"], new CliFactSAP((int)oCliente["t302_idcliente"],
                                                                              oCliente["t302_codigoexterno"].ToString(),
                                                                              ((int)oCliente["Interno"] == 1) ? true : false)
                               );
        }
        //oCliFactSAP = (CliFactSAP)htCliEnlaceSAP[45946];

        ds.Dispose();
        #endregion

        SqlDataReader dr = INTERFACTSAP.Catalogo();
        while (dr.Read())
        {
            if (iCont == 0)
            {
                sAnomes            = Fechas.FechaAAnnomes((DateTime)dr["t445_fec_fact"]).ToString();
                cldFecha.InnerText = Fechas.AnnomesAFechaDescLarga(int.Parse(sAnomes));
            }
            iCont++;
            if (validarCampos(dr, sAnomes, true))
            {
                iNumOk++;
            }
            if (sFechaFacIncorrecta == "true")
            {
                sbE.Length         = 0;
                iCont              = 0;
                iNumOk             = 0;
                cldFecha.InnerText = "Fecha indefinida";
                break;
            }
        }
        dr.Close();
        dr.Dispose();

        sb.Append("</table>");
        this.divB.InnerHtml   = cabErrores() + sbE + "</table>";
        cldTotalFac.InnerText = INTERFACTSAP.numFacturas(null).ToString("#,##0");
        cldFacOK.InnerText    = iNumOk.ToString("#,##0");
        cldFacErr.InnerText   = (iCont - iNumOk).ToString("#,##0");
    }
Exemple #6
0
    protected string procesar(string sAnomesProceso, string sCadena)
    {
        string sResul = "OK@#@";
        string sEstadoMes = "";
        int    iNumLin = 1, iAnomes;
        int    it325_idsegmesproy, iClaseEco;

        #region abrir conexión y transacción
        try
        {
            oConn = Conexion.Abrir();
            tr    = Conexion.AbrirTransaccion(oConn);
        }
        catch (Exception ex)
        {
            if (oConn.State == ConnectionState.Open)
            {
                Conexion.Cerrar(oConn);
            }
            return("Error@#@" + Errores.mostrarError("Error al abrir la conexión", ex));
        }
        #endregion
        try
        {
            SqlDataReader dr = INTERFACTSAP.Catalogo();
            iAnomes = int.Parse(sAnomesProceso);
            ArrayList slProyPP = new ArrayList();

            while (dr.Read())
            {
                if (sCadena.IndexOf("##" + iNumLin.ToString() + "##") == -1)
                {
                    it325_idsegmesproy = SEGMESPROYECTOSUBNODO.ExisteSegMesProy(tr, (int)dr["t305_idproyectosubnodo"], iAnomes);
                    if (it325_idsegmesproy == 0)
                    {
                        sEstadoMes         = SEGMESPROYECTOSUBNODO.EstadoMesACrear(tr, (int)dr["t305_idproyectosubnodo"], iAnomes);
                        it325_idsegmesproy = SEGMESPROYECTOSUBNODO.Insert(tr, (int)dr["t305_idproyectosubnodo"], iAnomes, sEstadoMes, 0, 0, false, 0, 0);
                    }

                    if ((bool)dr["t445_grupo"])
                    {
                        //if ((bool)dr["t445_ute"]) iClaseEco = Constantes.IngExtServProf;
                        //else iClaseEco = Constantes.IngExtServProfGrupo;
                        iClaseEco = Constantes.IngExtServProfGrupo;
                    }
                    else
                    {
                        iClaseEco = Constantes.IngExtServProf;
                    }

                    DATOECO.InsertFactura(tr, it325_idsegmesproy, iClaseEco,
                                          dr["t445_descri"].ToString(),
                                          decimal.Parse(dr["t445_imp_fact"].ToString()),
                                          null,
                                          null,
                                          DateTime.Parse(dr["t445_fec_fact"].ToString()),
                                          dr["t445_serie"].ToString(),
                                          int.Parse(dr["t445_numero"].ToString()),
                                          int.Parse(dr["t313_idempresa"].ToString()),
                                          int.Parse(dr["t302_idcliente"].ToString()),
                                          Constantes.FicheroFacturasSAP,
                                          dr["t445_refcliente"].ToString());

                    INTERFACTSAP.Delete(tr, (int)dr["t445_id"]);
                    if (dr["t301_estado"].ToString() == "P")
                    {
                        ponerProyPP(int.Parse(dr["t301_idproyecto"].ToString()).ToString("#,###"), slProyPP);
                    }
                }
                iNumLin++;
            }
            dr.Close();
            dr.Dispose();

            Conexion.CommitTransaccion(tr);
            //sResul = "OK@#@";
            //sResul = ObtenerTiposAsunto("3", "0");
            //genero cadena con los proyectos en estado Presupuestado
            foreach (string sProy in slProyPP)
            {
                sResul += sProy + "##";
            }

            sResul += "@#@" + cabErrores() + "</table>@#@" + INTERFACTSAP.numFacturas(null).ToString("#,##0");
        }
        catch (Exception ex)
        {
            Conexion.CerrarTransaccion(tr);
            sResul = "Error@#@" + Errores.mostrarError("Error al procesar", ex);
        }
        finally
        {
            Conexion.Cerrar(oConn);
        }
        return(sResul);
    }