示例#1
0
    private string Procesar(int iPSN, byte bLineaBase, byte bSoloRTPT)
    {
        string sResul = "OK@#@", sAux = "";

        try
        {
            if (bLineaBase == 1)
            {
                //if (HayTareasParaAvisar(iPSN))
                //    sResul = "AVISO@#@Existen tareas cuya fecha de fin planificada\nes superior a la fecha de fin prevista.";
                if (bSoloRTPT == 1)
                {
                    sAux = OpenProj.GetTareasPlanMayorPrevisto(null, iPSN, int.Parse(Session["UsuarioActual"].ToString()));
                }
                else
                {
                    sAux = OpenProj.GetTareasPlanMayorPrevisto(null, iPSN);
                }
                if (sAux != "")
                {
                    sResul = "AVISO@#@" + sAux;
                }
            }
        }
        catch (Exception ex)
        {
            sResul = "Error@#@Operación rechazada.\n\n" + ex.Message;
        }
        return(sResul);
    }
示例#2
0
    //Comprueba si hay tareas donde FFPL > FFPR
    public bool HayTareasParaAvisar(int nCodPE)
    {
        bool bAvisar;

        try
        {
            bAvisar = OpenProj.bTareasParaAvisar(null, nCodPE);
        }
        catch (Exception)
        {
            bAvisar = false;
        }
        return(bAvisar);
    }
示例#3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["IDRED"] == null)
        {
            try
            {
                Response.Redirect("~/SesionCaducadaModal.aspx", true);
            }
            catch (System.Threading.ThreadAbortException) { return; }
        }

        string sPSN  = Request.QueryString["sPSN"].ToString();
        int    idPSN = int.Parse(sPSN);
        string sRTPT = Request.QueryString["RTPT"].ToString();
        //string sNomFich = Utilidades.decodpar(Request.QueryString["sPath"].ToString());

        int           iOrden = 1, iAssignmentUID = 1, iNumDias = 0, iNumDiasBase = 0;//, iUID=0
        StringBuilder sb = new StringBuilder();
        string        sCodItem, sDenProy = "", sCodProy = "", sIniProy = "", sFinProy = "", sResponsable = "", sPdte = "";
        //string sMaxUnits = "0.01000000000000000020816681711721685132943093776702880859375";
        string  sMaxUnits = "1";
        decimal dParticipacion = 0, dParticipacionBase = 0, dEsfuerzo = 0, dEsfuerzoBase = 0, dEsfAcum = 0;
        string  sCodUser = "";
        bool    bIncluirRecursos = false, bConLineBase = true;

        if (Request.QueryString["base"].ToString() == "N")
        {
            bConLineBase = false;
        }
        //try
        //{
        if (sPSN != "")
        {
            #region Obtengo datos del proyectos a exportar
            idPSN = int.Parse(sPSN);
            SqlDataReader drP = PROYECTO.fgGetDatosProy4(idPSN);
            if (drP.Read())
            {
                sCodProy     = drP["t301_idproyecto"].ToString();
                sDenProy     = "Proyecto " + int.Parse(sCodProy).ToString("#,###") + ". " + drP["t301_denominacion"].ToString();
                sIniProy     = drP["t301_fiprev"].ToString();
                sFinProy     = drP["t301_ffprev"].ToString();
                sResponsable = drP["Profesional"].ToString();
            }
            drP.Close();
            drP.Dispose();
            #endregion
        }
        if (sCodProy != "")
        {
            #region Meto la cabecera del XML leyéndola de los datos de la plantilla guardados en la tabla T681_PLANTILLA_OPENPROJ
            //string sArchivoPlant = getPath("Plantilla_" + Session["IDFICEPI_ENTRADA"].ToString(), "xml");
            SqlDataReader dr = OpenProj.GetPlantilla(null, 1);
            if (dr.Read())
            {
                //byte[] fileData = (byte[])dr.GetValue(1);
                byte[] fileData;
                if (dr["t2_iddocumento"].ToString() != "")
                {
                    fileData = IB.Conserva.ConservaHelper.ObtenerDocumento((long)dr.GetValue(0)).content;
                }
                else
                {
                    //fileData = (byte[])dr.GetValue(1);
                    throw new Exception("No se ha encontrado la plantilla de OpenProj en el repositorio de documentos");
                }

                MemoryStream ms = new MemoryStream();
                ms.Write(fileData, 0, fileData.Length);
                ms.Seek(0, SeekOrigin.Begin);    //Hay que ponerse al principio porque sino el XML no se carga correctamente
                docxml.Load(ms);
                ms.Close();
            }
            dr.Close();
            dr.Dispose();
            XmlNode     nodoRaiz = docxml.DocumentElement;
            XmlNodeList LN       = docxml.GetElementsByTagName("Name");
            XmlNode     nodoAux  = LN.Item(0);
            nodoAux.InnerText = "Proyecto " + sCodProy;

            LN                = docxml.GetElementsByTagName("Title");
            nodoAux           = LN.Item(0);
            nodoAux.InnerText = sDenProy;

            LN                = docxml.GetElementsByTagName("Manager");
            nodoAux           = LN.Item(0);
            nodoAux.InnerText = sResponsable;

            LN                = docxml.GetElementsByTagName("StartDate");
            nodoAux           = LN.Item(0);
            nodoAux.InnerText = OpenProj.flGetFechaOpenProj(sIniProy, "ID");

            LN                = docxml.GetElementsByTagName("FinishDate");
            nodoAux           = LN.Item(0);
            nodoAux.InnerText = OpenProj.flGetFechaOpenProj(sFinProy, "ID");

            LN                = docxml.GetElementsByTagName("CurrentDate");
            nodoAux           = LN.Item(0);
            nodoAux.InnerText = OpenProj.flGetFechaOpenProj(DateTime.Now.ToShortDateString(), "IJ");

            //Pongo calendario 24x7 porque sino tiene en cuenta los fines de semana y recalcula la fecha de fin de las tareas
            LN                = docxml.GetElementsByTagName("CalendarUID");
            nodoAux           = LN.Item(0);
            nodoAux.InnerText = OpenProj.fgGetCalendario();    //"2";

            System.Xml.XmlElement Tasks       = docxml.CreateElement("Tasks", en);
            System.Xml.XmlElement Assignments = docxml.CreateElement("Assignments", en);
            System.Xml.XmlElement Resources   = docxml.CreateElement("Resources", en);
            #endregion
            #region cargo los recursos asociados a todas las tareas del proyecto
            //Cargo un recurso ficticio para tareas no asignadas a recursos
            //Resources.AppendChild(CrearResourceXml(docxml, "0", "0", "N", "No asignado", sMaxUnits, "3", "0", "3", "0", "0", "0"));
            Resources.AppendChild(OpenProj.CrearResourceXml(docxml, "1", "1", ".", "Ocupación diaria ", sMaxUnits, "3", "0", "3", "0", "0", "0"));

            //Resources.AppendChild(CrearResourceXml(docxml, "1", "1", "Perdiguero", "0.01000000000000000020816681711721685132943093776702880859375", "3", "0", "3", "0", "0", "10000"));
            if (bIncluirRecursos)
            {
                //Para cada recurso hay que meter un calendario
                XmlNodeList Calendarios    = docxml.GetElementsByTagName("Calendars");
                XmlNode     nodoCalendario = Calendarios.Item(0);//Calendarios.Count - 1

                SqlDataReader dr2 = OpenProj.GetProfesionales(null, idPSN, true);
                while (dr2.Read())
                {
                    sCodUser = dr2["t314_idusuario"].ToString();
                    System.Xml.XmlNode Calendario =
                        nodoCalendario.AppendChild(OpenProj.CrearCalendarioUsuarioXml(docxml, sCodUser, dr2["Profesional"].ToString(), "2"));
                    Resources.AppendChild(OpenProj.CrearResourceXml(docxml, sCodUser, sCodUser, sCodUser, dr2["Profesional"].ToString(), sMaxUnits,
                                                                    "3", "0", "3", "0", "0", "0"));
                }
                dr2.Close();
                dr2.Dispose();
            }
            #endregion
            #region Meto los items del proyecto
            bool          bHayRecursos = false;
            SqlDataReader dr1;
            if (sRTPT == "0")
            {
                dr1 = OpenProj.GetEstructura(null, idPSN);
            }
            else
            {
                dr1 = OpenProj.GetEstructura(null, idPSN, int.Parse(Session["UsuarioActual"].ToString()));
            }
            while (dr1.Read())
            //foreach (int iKey in htItems.Keys)
            {
                //ItemsProyecto oItem = new ItemsProyecto();
                //oItem = (ItemsProyecto)htItems[iKey];
                ItemsProyecto oItem = new ItemsProyecto((int)dr1["codPT"], (int)dr1["codFase"], (int)dr1["codActiv"], (int)dr1["codTarea"],
                                                        dr1["nombre"].ToString(), dr1["descripcion"].ToString(), dr1["tipo"].ToString(),
                                                        iOrden++, /*(int)dr1["orden"],*/ dr1["FIPL"].ToString(), dr1["FFPL"].ToString(),
                                                        decimal.Parse(dr1["ETPL"].ToString()), dr1["PRIMER_CONSUMO"].ToString(),
                                                        dr1["ULTIMO_CONSUMO"].ToString(),
                                                        dr1["FFPR"].ToString(), decimal.Parse(dr1["ETPR"].ToString()),
                                                        decimal.Parse(dr1["Consumido"].ToString()), dr1["SITUACION"].ToString(),
                                                        ((int)dr1["FACTURABLE"] == 0) ? false : true, (int)dr1["MARGEN"]);
                sCodItem = "";
                string sIdent = OpenProj.flGetIdentacion(oItem.margen);
                switch (oItem.tipo)
                {
                case "P":
                    sCodItem = oItem.codPT.ToString();
                    break;

                case "F":
                    sCodItem = oItem.codFase.ToString();
                    break;

                case "A":
                    sCodItem = oItem.codActiv.ToString();
                    break;

                case "T":
                case "HF":
                    sCodItem = oItem.codTarea.ToString();
                    break;
                }
                //if (sCodItem == "143637")
                //    sCodItem = sCodItem;
                if (sCodItem != "" && oItem.FIPL != "" && oItem.FFPL != "")
                {
                    //if (oItem.codTarea == 148600) oItem.Consumido = 6;
                    //if (oItem.Consumido != 0)
                    sPdte = OpenProj.flPdteOpenProj(oItem.ETPR, oItem.Consumido);
                    //else
                    //sPdte = "";
                    bHayRecursos  = false;
                    sCodUser      = "******";
                    dEsfAcum      = 0;
                    iNumDiasBase  = OpenProj.flDuracionDias(oItem.FIPL, oItem.FFPL);
                    iNumDias      = OpenProj.flDuracionDias(oItem.PRIMER_CONSUMO, oItem.FFPR);
                    dEsfuerzo     = oItem.EsfuerzoHoras;
                    dEsfuerzoBase = oItem.ETPL;
                    //Hay que dividir por el nº de dias de duración de la tarea
                    if (iNumDiasBase != 0)
                    {
                        dParticipacionBase = dEsfuerzoBase / (iNumDiasBase * 8);
                    }
                    else
                    {
                        dParticipacionBase = 0;
                    }
                    //if (dParticipacionBase > 1) dParticipacionBase = 1;

                    if (iNumDias != 0)
                    {
                        dParticipacion = dEsfuerzo / (iNumDias * 8);
                    }
                    else
                    {
                        dParticipacion = 0;
                    }
                    //if (dParticipacion > 1) dParticipacion = 1;

                    Tasks.AppendChild(
                        OpenProj.CrearTareaXml(docxml, sCodItem, oItem.orden.ToString(), oItem.nombre, oItem.descripcion, oItem.tipo,
                                               sIdent, "0", OpenProj.flGetFechaOpenProj(oItem.PRIMER_CONSUMO, "IJ"),
                                               OpenProj.flGetFechaOpenProj(oItem.FFPR, "FJ"),
                                               OpenProj.flDuracionOpenProj(0, oItem.PRIMER_CONSUMO, oItem.FFPR),
                                               "7", "0", "2", sPdte, oItem.Consumido,
                                               oItem.FIPL, oItem.FFPL, oItem.ETPL, oItem.ETPR, dParticipacion, bConLineBase)
                        );

                    #region Meto los recursos asociados a cada tarea y las asignaciones de la situación actual
                    //Resources.AppendChild(CrearResourceXml(docxml, "1", "1", "Perdiguero", "0.01000000000000000020816681711721685132943093776702880859375", "3", "0", "3", "0", "0", "10000"));
                    if (bIncluirRecursos)
                    {
                        #region Incluyendo recursos
                        if (oItem.tipo == "T")
                        {    //De momento como no tengo claro lo que hay que hacer con los recursos, solo los calculo para las tareas
                             //Luego, si hace falta, ya pondré los de PT, F y A. Según la reunión del 8/9/2011 con Iñigo Garro
                             //basta con asociar los recursos a las tareas

                            //Leer de BBDD los recursos asignados a la tarea
                            SqlDataReader dr3 = OpenProj.GetProfesionalesTarea(null, int.Parse(sCodItem), true);
                            while (dr3.Read())
                            {
                                bHayRecursos = true;
                                sCodUser     = dr3["t314_idusuario"].ToString();
                                //Segundo hay que calcular el porcentaje de participación del usuario en la tarea
                                //  Para ello yo haria t336_etp / oItem.ETPR (si fuera división por cero, devolver cero)
                                if (dr3["t336_etp"].ToString() == "")
                                {
                                    dEsfuerzo = 0;
                                }
                                else
                                {
                                    dEsfuerzo = decimal.Parse(dr3["t336_etp"].ToString());
                                }
                                dEsfAcum += dEsfuerzo;
                                //if (oItem.ETPR == 0 || dr3["t336_etp"].ToString()=="")
                                //    dParticipacion = 0;
                                //else
                                //    dParticipacion = decimal.Parse(dr3["t336_etp"].ToString()) / oItem.ETPR;

                                //Hay que dividir el esfuerzo en horas por el nº de dias de duración de la tarea
                                if (iNumDiasBase != 0)
                                {
                                    dParticipacionBase = dEsfuerzo / (iNumDiasBase * 8);
                                }
                                else
                                {
                                    dParticipacionBase = 0;
                                }
                                if (iNumDias != 0)
                                {
                                    dParticipacion = dEsfuerzo / (iNumDias * 8);
                                }
                                else
                                {
                                    dParticipacion = 0;
                                }

                                Assignments.AppendChild(
                                    OpenProj.CrearAssignmentXml(docxml, oItem, iAssignmentUID.ToString(), sCodUser, dEsfuerzo,
                                                                dParticipacion, dParticipacionBase, sPdte, bConLineBase, iNumDias));
                                iAssignmentUID++;
                            }
                            dr3.Close();
                            dr3.Dispose();
                            if (bHayRecursos)
                            {
                                //Si la suma de los esfuerzos asignados a la tarea no llegan al esfuerzo total de la tarea
                                //metemos las horas que faltan al recurso imaginario (Sino, no respeta el esfuerzo de la tarea)
                                if (dEsfAcum < oItem.EsfuerzoHoras)
                                {
                                    sCodUser  = "******";
                                    dEsfuerzo = oItem.EsfuerzoHoras - dEsfAcum;
                                    if (iNumDias != 0)
                                    {
                                        dParticipacion = dEsfuerzo / (iNumDias * 8);
                                    }
                                    else
                                    {
                                        dParticipacion = 0;
                                    }
                                    Assignments.AppendChild(
                                        OpenProj.CrearAssignmentXml(docxml, oItem, iAssignmentUID.ToString(), sCodUser,
                                                                    dEsfuerzo, dParticipacion, dParticipacionBase, sPdte, bConLineBase, iNumDias));
                                    iAssignmentUID++;
                                }
                            }
                            else
                            {
                                //meto los elementos Assignement que contiene para cada item del proyecto un elemento por cada día del intervalo
                                Assignments.AppendChild(
                                    OpenProj.CrearAssignmentXml(docxml, oItem, iAssignmentUID.ToString(), sCodUser,
                                                                dEsfuerzo, dParticipacion, dParticipacionBase, sPdte, bConLineBase, iNumDias));
                                iAssignmentUID++;
                            }
                        }
                        else
                        {    //El item no es una tarea -> asignamos recurso ficticio ¿seguro que es necesario?
                            Assignments.AppendChild(
                                OpenProj.CrearAssignmentXml(docxml, oItem, iAssignmentUID.ToString(), "1",
                                                            dEsfuerzo, dParticipacion, dParticipacionBase, sPdte, bConLineBase, iNumDias));
                            iAssignmentUID++;
                        }
                    }
                    #endregion
                    else
                    {    //En el criterio de exportación hemos marcado "No coger recursos" -> asignamos recurso ficticio
                        switch (oItem.tipo)
                        {
                        //case "PT":
                        //case "P":
                        //case "F":
                        //case "A":
                        //    Assignments.AppendChild(
                        //                OpenProj.CrearAssignmentPadreXml(docxml, oItem, iAssignmentUID.ToString(), "-65535"));
                        //    iAssignmentUID++;
                        //    break;
                        case "T":
                            Assignments.AppendChild(
                                OpenProj.CrearAssignmentXml(docxml, oItem, iAssignmentUID.ToString(), "1",
                                                            dEsfuerzo, dParticipacion, dParticipacionBase, sPdte, bConLineBase, iNumDias));
                            iAssignmentUID++;
                            break;

                        case "HF":
                            Assignments.AppendChild(
                                OpenProj.CrearAssignmentXml(docxml, oItem, iAssignmentUID.ToString(), "1", 0, 1, 1, "", false, iNumDias));
                            iAssignmentUID++;
                            break;
                        }
                    }
                    #endregion
                }
            }
            dr1.Close();
            dr1.Dispose();
            #endregion
            nodoRaiz.AppendChild(Tasks);
            nodoRaiz.AppendChild(Resources);
            nodoRaiz.AppendChild(Assignments);

            string sNumProy = PROYECTO.flGetNumProy(null, idPSN);
            sNumProy = sNumProy.Replace(@"@", @"_");
            string sArchivoSalida = Session["IDFICEPI_ENTRADA"].ToString() + "_Proyecto_" + sNumProy + "_" + DateTime.Now.Ticks.ToString() + ".xml";

            Response.ClearContent();
            Response.ClearHeaders();
            Response.Buffer = true;

            Response.AddHeader("Content-Disposition", "attachment; filename=\"" + sArchivoSalida + "\"");
            Response.ContentType = "text/xml";     //RFC 3023
            //Lo codifico en UTF8 para que respete los caracteres especialed (Ñ, tíldes, etc...)
            Response.BinaryWrite(Encoding.UTF8.GetBytes(docxml.OuterXml));

            //Response.Flush();
            //Response.Close();
            Response.End();
        }
        //}
        //catch (Exception ex)
        //{
        //    //return "Error@#@" + Errores.mostrarError("Error al generar el fichero XML con la estructura del proyecto.", ex);
        //    return "Error@#@Error al generar el fichero XML con la estructura del proyecto. " + ex.Message;
        //}
    }
示例#4
0
        /// <summary>
        /// Genera la estructura técnica de un proyecto en SUPER, sobre un proyecto ya existente
        /// Se borran los item que están en SUPER y no están en OpenProj (salvo que tengan consumos)
        /// Si el ítem es nuevo en OpenProj - > se inserta en SUPER
        /// Si el ítem tiene codigo (<Numero1></Numero1>) se updatea en SUPER
        /// </summary>
        private string Importar(bool bBorrarEstructura)
        {
            StringBuilder  sb = new StringBuilder();
            int            idPSN = -1, iMargen = 0, iCodUne = -1, iNumProy = -1, iPos, iAux;
            int            iPT = -1, iFase = -1, iActiv = -1, iTarea = -1, iHito = -1, iOrden = 1;
            string         sSituacion = "1", sAux, sTipo, sCodSuperItem = "", sNota = "", sAccion = "", sTaskUID = "", sCodTarea = "";//sMargen = "0",
            string         sFIPL = "", sFFPL = "", sFFPR = "", sWorkTarea = "", sListaTareas = "", sListaRecursos = "", sDenTarea = "", sCodUser = "";
            string         sMensError = "";
            bool           bFacturable, bHayQueUpdatear = false;//, bEsHito = false
            decimal        dETPL = 0, dETPR = 0;
            DateTime?      dtFIPL = null;
            DateTime?      dtFFPL = null;
            SqlConnection  oConn  = null;
            SqlTransaction tr     = null;

            sListaTareas   = this.hdnTareas.Value;
            sListaRecursos = this.hdnRecursos.Value;
            htTareas       = new Hashtable();

            #region Abro transaccion
            try
            {
                oConn = Conexion.Abrir();
                tr    = Conexion.AbrirTransaccion(oConn);
            }
            catch (Exception ex)
            {
                return("Error@#@" + Errores.mostrarError("Error al abrir la conexión", ex));
            }
            #endregion
            idPSN = int.Parse(this.hdnPSN.Value);

            try
            {
                iCodUne = PROYECTOSUBNODO.GetNodo(tr, idPSN);
                if (bBorrarEstructura)
                {
                    if (PROYECTOSUBNODO.TieneConsumos(tr, idPSN))
                    {
                        Conexion.CerrarTransaccion(tr);
                        return("Error@#@El proyecto tiene consumos. No se puede eliminar la estructura actual.");
                    }
                    else
                    {
                        EstrProy.BorrarEstructura(tr, idPSN);
                    }
                }
                else
                {
                    //Vamos a meter lo que importamos debajo de lo que ya existe. Para ello obtenemos el mayor orden de los PT existentes
                    iOrden = ProyTec.GetMaxOrden(tr, idPSN) + 1;
                }
                bFacturable = PROYECTOSUBNODO.GetFacturable(tr, idPSN);

                #region Inserto y/o updateo los items del proyecto
                string[] aTareas = Regex.Split(sListaTareas, @"/#/");
                for (int i = 0; i < aTareas.Length - 1; i++)
                {
                    string[] aElem = Regex.Split(aTareas[i], @"#@#");
                    #region recojo datos del XML

                    /*
                     * aElem[0]: sTipo + "##";
                     * aElem[1]: UID + "##";
                     * aElem[2]: sMargen + "##";
                     * aElem[3]: DENOMINACION + "##";
                     * aElem[4]: ETPL + "##";
                     * aElem[5]: FIPL + "##";
                     * aElem[6]: FFPL + "##";
                     * aElem[7]: ETPR + "##";
                     * aElem[8]: FFPR + "##";
                     * aElem[9]: NOTAS + "##";
                     */
                    sTipo     = aElem[0];
                    sTaskUID  = aElem[1];
                    iMargen   = int.Parse(aElem[2]);
                    sDenTarea = aElem[3];
                    dETPL     = decimal.Parse(aElem[4]);
                    dETPR     = decimal.Parse(aElem[7]);
                    sFIPL     = aElem[5];
                    sFFPL     = aElem[6];
                    sFFPR     = aElem[8];
                    sNota     = aElem[9];
                    #endregion

                    #region Cálculo de códigos padre
                    switch (sTipo)
                    {
                    case "P":
                        iFase  = -1;
                        iActiv = -1;
                        break;

                    case "F":
                        iActiv = -1;
                        break;

                    case "A":
                        if (iMargen != 40)
                        {
                            iFase = -1;
                        }
                        break;

                    case "T":
                        if (iMargen == 40)
                        {
                            iFase = -1;
                        }
                        else
                        if (iMargen != 60)
                        {
                            iFase = -1; iActiv = -1;
                        }
                        break;
                        //case "HT":
                        //case "HF":
                        //case "HM":
                        //    iHito = int.Parse(aElem[7]);
                        //    if (sEstado == "D") sCadenaBorrado += sTipo + "@#@" + iHito.ToString() + @"##";//hito
                        //    break;
                    }
                    #endregion

                    #region Inserto o updateo el item de la estructura en BBDD
                    if (sCodSuperItem == "" || bBorrarEstructura)
                    {
                        sAccion = "I";
                    }
                    else
                    {
                        if (sCodSuperItem == "0.0" || sCodSuperItem == "0,0")
                        {
                            sAccion = "I";
                        }
                        else
                        {
                            sAccion = "U";
                            //El item esta en OpenProj -> marco en la hashtable para que no lo borre
                            #region obtención del código del elemento updateado
                            sAux = sCodSuperItem.Replace(",", ".");
                            iAux = int.Parse(sAux);
                            ItemsProyecto oItemAux = new ItemsProyecto();
                            switch (sTipo)
                            {
                            case "P":
                                iPT             = iAux;
                                oItemAux        = (ItemsProyecto)htPTs[iPT];
                                oItemAux.borrar = false;
                                htPTs[iPT]      = oItemAux;
                                break;

                            case "F":
                                iFase           = iAux;
                                oItemAux        = (ItemsProyecto)htFs[iFase];
                                oItemAux.borrar = false;
                                htFs[iFase]     = oItemAux;
                                break;

                            case "A":
                                iActiv          = iAux;
                                oItemAux        = (ItemsProyecto)htAs[iActiv];
                                oItemAux.borrar = false;
                                htAs[iActiv]    = oItemAux;
                                break;

                            case "T":
                                iTarea          = iAux;
                                oItemAux        = (ItemsProyecto)htItems[iTarea];
                                oItemAux.borrar = false;
                                htItems[iTarea] = oItemAux;
                                break;

                            case "HF":
                                iHito           = iAux;
                                oItemAux        = (ItemsProyecto)htHFs[iHito];
                                oItemAux.borrar = false;
                                htHFs[iHito]    = oItemAux;
                                break;
                            }
                            //if (sTipo.Substring(0, 1) == "H")
                            //{
                            //    AsociarTareasHitos(tr, iT305IdProy, iPT, iFase, iActiv, iTarea, iHito, iMargen);
                            //}
                            #endregion
                        }
                    }
                    if (sAccion == "I")
                    {
                        sAux = OpenProj.Insertar(tr, iCodUne, iNumProy, idPSN, sTipo, sDenTarea, iPT, iFase, iActiv, iMargen, iOrden,
                                                 sFIPL, sFFPL, dETPL, sFFPR, dETPR, Fechas.primerDiaMes(DateTime.Now).ToShortDateString(), "",
                                                 0, bFacturable, false, true, sSituacion, sNota, 0
                                                 );
                        #region obtención del código del elemento grabado
                        iPos = sAux.IndexOf("##");
                        iAux = int.Parse(sAux.Substring(0, iPos));
                        switch (sTipo)
                        {
                        case "P":
                            iPT = iAux;
                            break;

                        case "F":
                            iFase = iAux;
                            break;

                        case "A":
                            iActiv = iAux;
                            break;

                        case "T":
                            iTarea = iAux;
                            htTareas.Add(sTaskUID, iTarea.ToString());
                            break;
                            //case "HT":
                            //    iHito = iAux;
                            //    break;
                        }
                        //if (sTipo.Substring(0, 1) == "H")
                        //{
                        //    AsociarTareasHitos(tr, iT305IdProy, iPT, iFase, iActiv, iTarea, iHito, iMargen);
                        //}
                        #endregion
                    }
                    else
                    {//Hay que updatear el item (si hay algún cambio)
                        bHayQueUpdatear = false;

                        #region Mira si hay algún datos distinto para ver si hay que updatear el registro en la BBDD
                        ItemsProyecto oItem = new ItemsProyecto();
                        switch (sTipo)
                        {
                        case "T":
                            oItem = (ItemsProyecto)htItems[iTarea];
                            break;

                        case "P":
                            oItem = (ItemsProyecto)htPTs[iPT];
                            break;

                        case "F":
                            oItem = (ItemsProyecto)htFs[iFase];
                            break;

                        case "A":
                            oItem = (ItemsProyecto)htAs[iActiv];
                            break;

                        case "HF":
                            oItem = (ItemsProyecto)htHFs[iHito];
                            break;
                        }
                        if (oItem.nombre != sDenTarea)
                        {
                            bHayQueUpdatear = true;
                        }
                        else
                        {
                            if (oItem.descripcion != sNota)
                            {
                                bHayQueUpdatear = true;
                            }
                            else
                            {
                                if (sTipo == "T")
                                {
                                    if (oItem.PRIMER_CONSUMO.Substring(0, 10) != sFIPL)
                                    {
                                        bHayQueUpdatear = true;
                                    }
                                    else
                                    {
                                        if (oItem.FFPR.Substring(0, 10) != sFFPR)
                                        {
                                            bHayQueUpdatear = true;
                                        }
                                        else
                                        {
                                            if (oItem.ETPR != dETPR)
                                            {
                                                bHayQueUpdatear = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        #endregion

                        if (bHayQueUpdatear)
                        {
                            OpenProj.Modificar(tr, iCodUne, idPSN, sTipo, sDenTarea, iPT, iFase, iActiv, iTarea, iHito,
                                               iMargen, iOrden, sFIPL, sFFPL, dETPL, sNota);
                        }
                    }
                    iOrden++;
                    #endregion
                }
                #endregion

                #region Si hay recursos con nº empleado SUPER y con asignación a tarea, los meto
                bool     bAux      = false;
                string[] aRecursos = Regex.Split(sListaRecursos, @"/#/");
                for (int i = 0; i < aRecursos.Length - 1; i++)
                {
                    string[] aElem = Regex.Split(aRecursos[i], @"#@#");
                    //Recojo el código SUPER del recurso en la tarea
                    sTaskUID   = aElem[0];
                    sCodUser   = aElem[1];
                    sWorkTarea = aElem[2];
                    sFIPL      = aElem[3];
                    sFFPL      = aElem[4];
                    if (sFIPL != "")
                    {
                        dtFIPL = DateTime.Parse(sFIPL);
                    }
                    if (sFFPL != "")
                    {
                        dtFFPL = DateTime.Parse(sFFPL);
                    }
                    if (sCodUser != "")
                    {
                        sCodTarea = htTareas[sTaskUID].ToString();
                        if (sCodTarea != "" && sWorkTarea != "")
                        {
                            bAux = TareaRecurso.InsertarTEC(tr, int.Parse(sCodTarea), int.Parse(sCodUser), null, null,
                                                            double.Parse(sWorkTarea), dtFIPL, dtFFPL,
                                                            null, 1, "", "", true, true, idPSN, -1, -1);
                            if (!bAux)
                            {
                                sMensError += "Por restricciones del proyecto no es posible asignar el empleado " + sCodUser + " a la tarea " + sCodTarea + "\n";
                            }
                            TareaRecurso.UpdateEsfuerzo(tr, int.Parse(sCodTarea), int.Parse(sCodUser), null, double.Parse(sWorkTarea),
                                                        dtFIPL, dtFFPL, null, 1);
                        }
                    }
                }
                #endregion

                #region borro los items que estando en SUPER no están en OpenProj (si es tarea que no tenga consumo)
                //if (!bBorrarEstructura)
                //{
                //    ItemsProyecto oItemD = new ItemsProyecto();
                //    //Borrado de Proyectos Técnicos
                //    foreach (DictionaryEntry item in htPTs)
                //    {
                //        oItemD = (ItemsProyecto)item.Value;
                //        if (oItemD.borrar)
                //            ProyTec.Eliminar(tr, oItemD.codPT);
                //    }
                //    //Borrado de Fases
                //    foreach (DictionaryEntry item in htFs)
                //    {
                //        oItemD = (ItemsProyecto)item.Value;
                //        if (oItemD.borrar)
                //            FASEPSP.Delete(tr, oItemD.codFase);
                //    }
                //    //Borrado de Actividades
                //    foreach (DictionaryEntry item in htAs)
                //    {
                //        oItemD = (ItemsProyecto)item.Value;
                //        if (oItemD.borrar)
                //            ACTIVIDADPSP.Delete(tr, oItemD.codActiv);
                //    }
                //    //Borrado de Hitos de fecha
                //    foreach (DictionaryEntry item in htHFs)
                //    {
                //        oItemD = (ItemsProyecto)item.Value;
                //        if (oItemD.borrar)
                //            HITOPSP.Delete(tr, "HF", oItemD.codTarea);
                //    }
                //    //Borrado de Tareas que no tengan consumos
                //    foreach (DictionaryEntry item in htItems)
                //    {
                //        oItemD = (ItemsProyecto)item.Value;
                //        if (oItemD.borrar)
                //        {
                //            if (oItemD.Consumido == 0)
                //                TAREAPSP.Delete(tr, oItemD.codTarea);
                //        }
                //    }
                //}
                #endregion

                //Cierro transaccion
                Conexion.CommitTransaccion(tr);
                if (sMensError == "")
                {
                    sMensError = "OK";
                }
                else
                {
                    sMensError = "OKMSG@#@" + sMensError;
                }
                return(sMensError);
            }
            catch (Exception ex)
            {
                Conexion.CerrarTransaccion(tr);
                return(Errores.mostrarError("Error al cargar la estructura a partir del fichero XML", ex));
            }
            finally
            {
                Conexion.Cerrar(oConn);
            }
        }