// If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override bool Execute(CodeActivityContext context)
        {
            bool doCopy = true;

            try
            {
                string _codeDmd = context.GetValue <string>(this.CodeDemande);
                Guid   _pkIdDmd = context.GetValue <Guid>(this.PKIDDmd);
                Guid   _pkRWK   = context.GetValue <Guid>(this.PkRWK);

                //On va essayé de faire une copie du circuit
                doCopy = new DB_WORKFLOW().CopieCicruitEtapeDemande(_pkRWK, _pkIdDmd, _codeDmd);
                if (doCopy)
                {
                    MessageErreur.Set(context, string.Empty);
                }
                else
                {
                    MessageErreur.Set(context, "Une erreur s'est produite");
                }
            }
            catch (Exception ex)
            {
                doCopy = false;
                MessageErreur.Set(context, ex.Message);
            }

            return(doCopy);
        }
        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void Execute(CodeActivityContext context)
        {
            Guid   pkID    = context.GetValue <Guid>(PKIDDemande);
            string codedmd = context.GetValue <string>(CodeDemande);

            //Suppression de la demande dans la table demande
            List <CsDemandeWorkflow> lsDemandes = new DB_WORKFLOW().SelectAllDemande()
                                                  .Where(dmd => dmd.PK_ID == pkID && dmd.CODE == codedmd)
                                                  .ToList();

            //Une fois on les a trouvé on supprime Hi Hi Hi Hi Hi !!!!
            bool delete = new DB_WORKFLOW().DeleteDemande(lsDemandes);

            //et tout est ok, on dispose tout pour libérer la mémoire
            GC.SuppressFinalize(lsDemandes);
        }
Пример #3
0
        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override RESULTACTION Execute(CodeActivityContext context)
        {
            RESULTACTION _resultAction = RESULTACTION.ERREURINCONNUE;

            string _matriculeUser    = context.GetValue <string>(MatriculeUser);
            string _codeDemande      = context.GetValue <string>(CodeDemande);
            string _actionOnDemande  = string.Empty;
            string _commentaireRejet = context.GetValue <string>(Commentaire);

            //On va mettre transmettre la demande à l'étape suivante
            try
            {
                DB_WORKFLOW dbWKF = new DB_WORKFLOW();

                //On récupère toutes les infos de la demande
                CsDemandeWorkflow dmdWorkflow = dbWKF.SelectLaDemande(_codeDemande);
                if (null != dmdWorkflow)
                {
                    //Infos sur la table de travail
                    CsTableDeTravail table = dbWKF.SelectAllTableDeTravail().Where(t => t.PK_ID == dmdWorkflow.FK_IDTABLETRAVAIL)
                                             .FirstOrDefault();

                    //La demande doit être forcement liée à une table de travail
                    //if (null != table)
                    //{
                    //Avant de rejeter  la demande on cherche les infos de l'étape actuelle
                    KeyValuePair <CsCopieDmdCircuit, CsCopieDmdConditionBranchement> CurrentStep = dbWKF.RecupererEtapeCourante(_codeDemande);
                    if (null != CurrentStep.Key)
                    {
                        //ici on pas besoin de condition, on rejette ooh
                        bool   LastStep = false;
                        string msgErr   = string.Empty;
                        //On rejette
                        if (dbWKF.RejeteDemande(_codeDemande, dmdWorkflow.FK_IDETAPEACTUELLE, ref msgErr, ref LastStep,
                                                ref dmdWorkflow))
                        {
                            //On a bien transmis,
                            dmdWorkflow.FK_IDSTATUS = (int)STATUSDEMANDE.Rejetee;       //Pour la prochaine étape
                            dmdWorkflow.DATEDERNIEREMODIFICATION = DateTime.Now;
                            _resultAction    = RESULTACTION.REJETEE;
                            _actionOnDemande = "Rejet de l'étape " + CurrentStep.Key.LIBELLEETAPE;
                            MessageErreur.Set(context, "");

                            #region CommentaireRejet

                            DBAdmUsers    dbUser = new DBAdmUsers();
                            CsUtilisateur u      = dbUser.GetUtilisateurByMatricule(_matriculeUser);

                            //ON supprime les autres commentaires de la demande concernée
                            dbWKF.DeleteCommentaireRejet(dmdWorkflow.PK_ID);
                            CsCommentaireRejet commentaire = new CsCommentaireRejet()
                            {
                                PK_ID           = Guid.NewGuid(),
                                DATECOMMENTAIRE = DateTime.Today.Date,
                                CODEDEMANDE     = dmdWorkflow.CODE_DEMANDE_TABLETRAVAIL,
                                COMMENTAIRE     = _commentaireRejet,
                                PIECE_JOINTE    = null,
                                FK_IDDEMANDE    = dmdWorkflow.PK_ID,
                                UTILISATEUR     = (null != u && null != u.NOM && string.Empty != u.NOM) ? u.NOM : _matriculeUser
                            };

                            dbWKF.InsertCommentaireRejet(new List <CsCommentaireRejet>()
                            {
                                commentaire
                            });

                            #endregion

                            #region Mise à jour de la demande et insertion des journaux
                            //On met à jour la demande
                            bool update = dbWKF.UpdateDemande(new List <CsDemandeWorkflow>()
                            {
                                dmdWorkflow
                            });
                            if (update)
                            {
                                //maintenant on écrit dans le journal de la demande
                                CsJournalDemandeWorkflow jrnal = new CsJournalDemandeWorkflow();
                                jrnal.PK_ID               = Guid.NewGuid();
                                jrnal.CODE_DEMANDE        = dmdWorkflow.CODE;
                                jrnal.FK_IDDEMANDE        = dmdWorkflow.PK_ID;
                                jrnal.LIBELLEACTION       = _actionOnDemande;
                                jrnal.DATEACTION          = DateTime.Today.Date;
                                jrnal.OBSERVATIONS        = string.Empty;
                                jrnal.MATRICULEUSERACTION = _matriculeUser;

                                dbWKF.InsertJournalDemande(new List <CsJournalDemandeWorkflow>()
                                {
                                    jrnal
                                });

                                //Suppresion de la demande dans la table des affectations user
                                dbWKF.SupprimerAffectationDemande(dmdWorkflow.CODE);
                            }
                            else
                            {
                                MessageErreur.Set(context, "Une erreur interne est survenue");
                                _resultAction = RESULTACTION.ERREURINCONNUE;
                            }

                            #endregion
                        }
                        else
                        {
                            //On na pas bien rejeté, donc on check si on est déjà à la 1ere étape
                            if (LastStep)
                            {
                                //Bon la, la demande est comme si elle est initiée
                                dmdWorkflow.FK_IDSTATUS = (int)STATUSDEMANDE.Rejetee;
                                _resultAction           = RESULTACTION.DEBUTDECIRCUIT;

                                //Si on est revenue au début du circuit, on n'a plus de journaux à insérer,
                                //car aucune action n'a été faite en principe
                                bool update = dbWKF.UpdateDemande(new List <CsDemandeWorkflow>()
                                {
                                    dmdWorkflow
                                });

                                //Suppresion de la demande dans la table des affectations user
                                dbWKF.SupprimerAffectationDemande(dmdWorkflow.CODE);

                                MessageErreur.Set(context, "");
                            }
                            else
                            {
                                //La la, ya vraiment une erreur qui s'est produite
                                _resultAction = RESULTACTION.ERREURINCONNUE;
                                MessageErreur.Set(context, msgErr);
                            }
                        }

                        GC.SuppressFinalize(dbWKF);
                        return(_resultAction);
                    }
                    else
                    {
                        GC.SuppressFinalize(dbWKF);
                        MessageErreur.Set(context, "Impossible de rejeter une demande n'étant à aucune étape");
                        return(RESULTACTION.ERREURINCONNUE);
                    }
                    //}
                    //else
                    //{
                    //    GC.SuppressFinalize(dbWKF);
                    //    MessageErreur.Set(context, "Impossible de rejeter une demande n'étant pas liée à une table de travail");
                    //    return RESULTACTION.ERREURINCONNUE;
                    //}
                }
                else
                {
                    GC.SuppressFinalize(dbWKF);
                    MessageErreur.Set(context, "Impossible de transmettre une demande qui n'existe pas");
                    return(RESULTACTION.ERREURINCONNUE);
                }
            }
            catch (Exception ex)
            {
                MessageErreur.Set(context, ex.Message);
                return(RESULTACTION.ERREURINCONNUE);
            }
        }
        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override RESULTACTION Execute(CodeActivityContext context)
        {
            RESULTACTION _resultAction = RESULTACTION.ERREURINCONNUE;

            string _codeDemande     = context.GetValue <string>(CodeDemande);
            string _matricule       = context.GetValue <string>(MatriculeUser);
            string _actionOnDemande = string.Empty;

            //On va mettre transmettre la demande à l'étape suivante
            try
            {
                DB_WORKFLOW dbWKF = new DB_WORKFLOW();

                //On récupère toutes les infos de la demande
                CsDemandeWorkflow dmdWorkflow = dbWKF.SelectLaDemande(_codeDemande);
                if (null != dmdWorkflow)
                {
                    //Infos sur la table de travail
                    CsTableDeTravail table = dbWKF.SelectAllTableDeTravail().Where(t => t.PK_ID == dmdWorkflow.FK_IDTABLETRAVAIL)
                                             .FirstOrDefault();

                    //La demande doit être forcement liée à une table de travail
                    //if (null != table)        --> Une opération peut ne peut avoir une table de travail
                    //{
                    //Avant de transmettre  la demande on cherche les infos de l'étape actuelle
                    KeyValuePair <CsCopieDmdCircuit, CsCopieDmdConditionBranchement> CurrentStep = dbWKF.RecupererEtapeCourante(_codeDemande);
                    if (null != CurrentStep.Key)
                    {
                        //On verifie la condition actuelle de l'étape
                        bool IlYaUneCondition = (null != CurrentStep.Value &&
                                                 (null != CurrentStep.Key.CONDITION && string.Empty != CurrentStep.Key.CONDITION));

                        bool transmissionOk = true;
                        bool LastStep       = false;

                        string msgErr = string.Empty;
                        if (IlYaUneCondition)
                        {
                            //On utilise la condition pour transmettre
                            bool onABienTeste      = true;
                            bool conditionRespecte = ConditionChecker.CheckIfConditionIsRespected(CurrentStep.Key.CONDITION,
                                                                                                  table.TABLE_NAME, ref msgErr, dmdWorkflow.FK_IDLIGNETABLETRAVAIL, ref onABienTeste);
                            if (onABienTeste)
                            {
                                transmissionOk = dbWKF.TransmettreDemande(_codeDemande, dmdWorkflow.FK_IDETAPEACTUELLE, ref msgErr, ref LastStep,
                                                                          ref dmdWorkflow, conditionRespecte);
                            }
                            else
                            {
                                transmissionOk = false;
                            }
                        }
                        else
                        {
                            //On transmet sans condition
                            transmissionOk = dbWKF.TransmettreDemande(_codeDemande, dmdWorkflow.FK_IDETAPEACTUELLE, ref msgErr, ref LastStep,
                                                                      ref dmdWorkflow, false);
                        }
                        if (transmissionOk)
                        {
                            //On a bien transmis,
                            dmdWorkflow.FK_IDSTATUS = (int)STATUSDEMANDE.EnAttenteValidation;       //Pour la prochaine étape
                            dmdWorkflow.DATEDERNIEREMODIFICATION = DateTime.Now;
                            _resultAction = RESULTACTION.TRANSMISE;


                            /** ZEG 29/08/2017 **/
                            //_actionOnDemande = "Validation à l'étape " + CurrentStep.Key.LIBELLEETAPE;
                            CsEtape _etape = dbWKF.SelectAllEtapes().Find(e => e.PK_ID == dmdWorkflow.FK_IDETAPEPRECEDENTE);
                            _actionOnDemande = "Etape " + _etape.NOM + " traitée";
                            /****/



                            MessageErreur.Set(context, "");

                            #region Mise à jour de la demande et insertion des journaux
                            //On met à jour la demande
                            bool update = dbWKF.UpdateDemande(new List <CsDemandeWorkflow>()
                            {
                                dmdWorkflow
                            });
                            if (update)
                            {
                                //maintenant on écrit dans le journal de la demande
                                CsJournalDemandeWorkflow jrnal = new CsJournalDemandeWorkflow();
                                jrnal.PK_ID               = Guid.NewGuid();
                                jrnal.CODE_DEMANDE        = dmdWorkflow.CODE;
                                jrnal.FK_IDDEMANDE        = dmdWorkflow.PK_ID;
                                jrnal.LIBELLEACTION       = _actionOnDemande;
                                jrnal.DATEACTION          = DateTime.Today.Date;
                                jrnal.OBSERVATIONS        = string.Empty;
                                jrnal.MATRICULEUSERACTION = _matricule;

                                dbWKF.InsertJournalDemande(new List <CsJournalDemandeWorkflow>()
                                {
                                    jrnal
                                });

                                //Suppresion de la demande dans la table des affectations user
                                dbWKF.SupprimerAffectationDemande(dmdWorkflow.CODE);
                            }
                            else
                            {
                                MessageErreur.Set(context, "Une erreur interne est survenue");
                                _resultAction = RESULTACTION.ERREURINCONNUE;
                            }

                            #endregion
                        }
                        else
                        {
                            //On na pas bien transmis, donc on check si on est déjà à la dernière étape
                            if (LastStep)
                            {
                                //Bon la, la demande est terminée oh, donc après on va parser la table pour la purger
                                //si le paramètre SUPPRIMER_DEMANDE_TERMINE est à OUI
                                dmdWorkflow.FK_IDSTATUS = (int)STATUSDEMANDE.Terminee;
                                dmdWorkflow.DATEDERNIEREMODIFICATION = DateTime.Now;
                                _resultAction = RESULTACTION.FINDECIRCUIT;

                                //Si on est à la fin du circuit, on n'a plus de journaux à insérer,
                                //car aucune action n'a été faite en principe, mais on va juste insérer
                                //demande terminée par ... le ... à l'étape ...
                                bool update = dbWKF.UpdateDemande(new List <CsDemandeWorkflow>()
                                {
                                    dmdWorkflow
                                });
                                if (update)
                                {
                                    /** ZEG 29/08/2017 **/
                                    CsEtape _etape2 = dbWKF.SelectAllEtapes().Find(e => e.PK_ID == dmdWorkflow.FK_IDETAPEPRECEDENTE);

                                    //Insertion du journal
                                    CsJournalDemandeWorkflow jrnal = new CsJournalDemandeWorkflow()
                                    {
                                        CODE_DEMANDE = dmdWorkflow.CODE,
                                        DATEACTION   = DateTime.Today.Date,
                                        FK_IDDEMANDE = dmdWorkflow.PK_ID,
                                        PK_ID        = Guid.NewGuid(),

                                        /** ZEG 29/08/2017 **/
                                        //LIBELLEACTION = "Dernière validation à l'étape " + CurrentStep.Key.LIBELLEETAPE,
                                        LIBELLEACTION = "Dernière étape " + _etape2.NOM + " validée",


                                        MATRICULEUSERACTION = _matricule,
                                        OBSERVATIONS        = string.Empty
                                    };

                                    dbWKF.InsertJournalDemande(new List <CsJournalDemandeWorkflow>()
                                    {
                                        jrnal
                                    });

                                    //Suppresion de la demande dans la table des affectations user
                                    dbWKF.SupprimerAffectationDemande(dmdWorkflow.CODE);
                                }
                                MessageErreur.Set(context, "");
                            }
                            else
                            {
                                //La la, ya vraiment une erreur qui s'est produite
                                _resultAction = RESULTACTION.ERREURINCONNUE;
                                MessageErreur.Set(context, msgErr);
                            }
                        }


                        return(_resultAction);
                    }
                    else
                    {
                        MessageErreur.Set(context, "Impossible d'avancer une demande n'étant à aucune étape");
                        return(RESULTACTION.ERREURINCONNUE);
                    }
                    //}
                    //else
                    //{
                    //    MessageErreur.Set(context, "Impossible de transmettre une demande n'étant pas liée à une table de travail");
                    //    return RESULTACTION.ERREURINCONNUE;
                    //}
                }
                else
                {
                    MessageErreur.Set(context, "Impossible de transmettre une demande qui n'existe pas");
                    return(RESULTACTION.ERREURINCONNUE);
                }
            }
            catch (Exception ex)
            {
                MessageErreur.Set(context, ex.Message);
                return(RESULTACTION.ERREURINCONNUE);
            }
        }
Пример #5
0
        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override bool Execute(CodeActivityContext context)
        {
            bool _result = true;

            try
            {
                //On obtient les valeurs des paramètres
                string pk_IDLine           = context.GetValue <string>(this.PKIDLine);
                int    cId                 = context.GetValue <int>(this.CentreId);
                Guid   _wkfId              = context.GetValue <Guid>(this.WKFId);
                Guid   _opId               = context.GetValue <Guid>(this.OpId);
                string _matUser            = context.GetValue <string>(this.MatriculeUser);
                string _codeDemandeTravail = context.GetValue <string>(this.CodeDemandeTravail);

                //On recherche les infos sur le circuit
                CsRWorkflow rWKFCentre = null;
                rWKFCentre = new DB_WORKFLOW().SelectAllRWorkflowCentre(_wkfId, cId, _opId)
                             .FirstOrDefault();
                if (null != rWKFCentre)
                {
                    //Récupération des infos
                    CsCentre   centre   = new DB_Centre().SelectAllCentre().Where(c => c.PK_ID == cId).FirstOrDefault();
                    CsWorkflow workflow = new DB_WORKFLOW().SelectAllWorkflows().Where(w => w.PK_ID == _wkfId)
                                          .FirstOrDefault();
                    CsOperation operation = new DB_WORKFLOW().SelectAllOperation2().Where(o => o.PK_ID == _opId)
                                            .FirstOrDefault();

                    //Récupération du circuit
                    Dictionary <CsRAffectationEtapeWorkflow, CsConditionBranchement> lsRAffCircuit = new Dictionary <CsRAffectationEtapeWorkflow, CsConditionBranchement>();
                    lsRAffCircuit = new DB_WORKFLOW().SelectAllAffectationEtapeWorkflow(rWKFCentre.PK_ID);

                    List <CsRAffectationEtapeWorkflow> leCircuitNormal = lsRAffCircuit.Keys.Where(aff => !aff.FK_IDRETAPEWORKFLOWORIGINE.HasValue ||
                                                                                                  aff.FK_IDRETAPEWORKFLOWORIGINE.Value == Guid.Empty)
                                                                         .OrderBy(aff => aff.ORDRE)
                                                                         .ToList();

                    CsRAffectationEtapeWorkflow _1sStep  = leCircuitNormal.FirstOrDefault();
                    CsRAffectationEtapeWorkflow _2ndStep = leCircuitNormal.Where(step => step.ORDRE == _1sStep.ORDRE + 1)
                                                           .FirstOrDefault();

                    //Création de la demande
                    CsDemandeWorkflow dmd = new CsDemandeWorkflow()
                    {
                        PK_ID                  = Guid.NewGuid(),
                        DATECREATION           = DateTime.Today.Date,
                        MATRICULEUSERCREATION  = _matUser,
                        ALLCENTRE              = false,
                        FK_IDCENTRE            = cId,
                        FK_IDOPERATION         = _opId,
                        FK_IDRWORKLOW          = rWKFCentre.PK_ID,
                        FK_IDSTATUS            = (int)STATUSDEMANDE.Initiee,
                        FK_IDWORKFLOW          = _wkfId,
                        FK_IDLIGNETABLETRAVAIL = pk_IDLine,
                        FK_IDETAPEPRECEDENTE   = 0,
                        FK_IDETAPEACTUELLE     = _1sStep.FK_IDETAPE,
                        FK_IDETAPESUIVANTE     = _2ndStep.FK_IDETAPE,
                        CODE = centre.CODESITE + centre.CODE + DateTime.Today.Year + DateTime.Today.Month +
                               DateTime.Now.Minute +
                               DateTime.Now.Millisecond,
                        FK_IDTABLETRAVAIL         = workflow.FK_IDTABLE_TRAVAIL.Value,
                        CODE_DEMANDE_TABLETRAVAIL = _codeDemandeTravail,
                        DATEDERNIEREMODIFICATION  = DateTime.Today.Date
                    };


                    _result = new DB_WORKFLOW().InsertDemande(new List <CsDemandeWorkflow>()
                    {
                        dmd
                    });

                    if (_result) /* tout es bon */
                    {
                        CodeDemande.Set(context, dmd.CODE);
                        PKIDDemande.Set(context, dmd.PK_ID);
                        PKRWKF.Set(context, dmd.FK_IDRWORKLOW);

                        //On récupère les emails pour notifier les utilisateurs de l'arrivée de la demande
                        KeyValuePair <CsGroupeValidation, List <CsRHabilitationGrouveValidation> > grpValidation = new DB_WORKFLOW().SelectAllGroupeValidation()
                                                                                                                   .Where(g => g.Key.PK_ID == _1sStep.FK_IDGROUPEVALIDATIOIN)
                                                                                                                   .FirstOrDefault();

                        if (null != grpValidation.Key)
                        {
                            if (string.Empty != grpValidation.Key.EMAILDIFFUSION)
                            {
                                Emails.Set(context, grpValidation.Key.EMAILDIFFUSION + ";");
                            }
                            else
                            {
                                string _email = string.Empty;
                                foreach (var habilUser in grpValidation.Value)
                                {
                                    _email += habilUser.EMAIL + ";";
                                }

                                Emails.Set(context, _email);
                            }
                        }
                    }
                }
                else
                {
                    _result = false;
                    CodeDemande.Set(context, "Aucun circuit n'a été configuré pour cette opération et ce centre");
                    PKIDDemande.Set(context, Guid.Empty);
                    PKRWKF.Set(context, Guid.Empty);
                }
            }
            catch (Exception ex)
            {
                _result = false;
                CodeDemande.Set(context, ex.Message);
            }


            return(_result);
        }
Пример #6
0
        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override RESULTACTION Execute(CodeActivityContext context)
        {
            RESULTACTION _result = RESULTACTION.ERREURINCONNUE;

            try
            {
                string _codeDemande   = CodeDemande.Get(context);
                string _commentaire   = Commentaire.Get(context);
                Guid   _fkIdEtape     = FKIDEtape.Get(context);
                string _matriculeUser = Matricule.Get(context);

                CODEACTION _codeAction = CodeAction.Get(context);

                DB_WORKFLOW       dbWKF       = new DB_WORKFLOW();
                CsDemandeWorkflow dmdWorkflow = dbWKF.SelectLaDemande(_codeDemande);

                if (null != dmdWorkflow)
                {
                    //Journal
                    CsJournalDemandeWorkflow jrnal        = null;
                    CsCopieDmdCircuit        etapeDemande = dbWKF.SelectAllCircuitEtapeDemandeWorkflow(dmdWorkflow.PK_ID)
                                                            .Keys.ToList()
                                                            .Where(e => e.PK_ID == _fkIdEtape)
                                                            .FirstOrDefault();

                    if (null == etapeDemande)
                    {
                        _result = RESULTACTION.ERREURINCONNUE;
                        MessageErreur.Set(context, "Aucune étape n'a été configurée avec cette ID");

                        return(_result);
                    }


                    switch (_codeAction)
                    {
                    case CODEACTION.TRANSMETTRE:
                    {
                        int precedent = dmdWorkflow.FK_IDETAPEACTUELLE;
                        dmdWorkflow.FK_IDETAPEACTUELLE   = etapeDemande.FK_IDETAPE;
                        dmdWorkflow.FK_IDETAPECIRCUIT    = etapeDemande.PK_ID;
                        dmdWorkflow.FK_IDETAPEPRECEDENTE = precedent;

                        var etapeSuivante = dbWKF.ProchaineOuPrecedenteEtape(dmdWorkflow.CODE, etapeDemande.FK_IDETAPE, etapeDemande.PK_ID, 1, false);
                        if (null != etapeSuivante.Key)
                        {
                            dmdWorkflow.FK_IDETAPESUIVANTE = etapeSuivante.Key.FK_IDETAPE;
                        }
                        else
                        {
                            //On suppose qu'on est à la dernière étape
                            dmdWorkflow.FK_IDETAPESUIVANTE = 0;
                        }

                        dbWKF.DeleteCommentaireRejet(dmdWorkflow.PK_ID);
                        CsCommentaireRejet Com = new CsCommentaireRejet()
                        {
                            CODEDEMANDE     = dmdWorkflow.CODE,
                            DATECOMMENTAIRE = DateTime.Today.Date,
                            FK_IDDEMANDE    = dmdWorkflow.PK_ID,
                            PK_ID           = Guid.NewGuid(),
                            COMMENTAIRE     = _commentaire,
                            PIECE_JOINTE    = null,
                            UTILISATEUR     = _matriculeUser
                        };
                        dbWKF.InsertCommentaireRejet(new List <CsCommentaireRejet>()
                            {
                                Com
                            });


                        dmdWorkflow.FK_IDSTATUS = (int)STATUSDEMANDE.EnAttenteValidation;
                        dmdWorkflow.DATEDERNIEREMODIFICATION = DateTime.Now;

                        _result = RESULTACTION.TRANSMISE;
                        MessageErreur.Set(context, "");

                        jrnal = new CsJournalDemandeWorkflow()
                        {
                            CODE_DEMANDE        = dmdWorkflow.CODE,
                            DATEACTION          = DateTime.Today.Date,
                            FK_IDDEMANDE        = dmdWorkflow.PK_ID,
                            PK_ID               = Guid.NewGuid(),
                            LIBELLEACTION       = "Transmission à l'étape " + etapeDemande.LIBELLEETAPE,
                            MATRICULEUSERACTION = _matriculeUser,
                            OBSERVATIONS        = string.Empty
                        };
                    }
                    break;

                    case CODEACTION.REJETER:
                    {
                        var etapeSuivante = dbWKF.ProchaineOuPrecedenteEtape(dmdWorkflow.CODE, etapeDemande.FK_IDETAPE, etapeDemande.PK_ID, -1, false);
                        if (null != etapeSuivante.Key)
                        {
                            dmdWorkflow.FK_IDETAPEPRECEDENTE = etapeSuivante.Key.FK_IDETAPE;
                        }
                        else
                        {
                            //On suppose qu'on est à la 1ere étape
                            dmdWorkflow.FK_IDETAPEPRECEDENTE = 0;
                        }

                        dbWKF.DeleteCommentaireRejet(dmdWorkflow.PK_ID);
                        CsCommentaireRejet Com = new CsCommentaireRejet()
                        {
                            CODEDEMANDE     = dmdWorkflow.CODE,
                            DATECOMMENTAIRE = DateTime.Today.Date,
                            FK_IDDEMANDE    = dmdWorkflow.PK_ID,
                            PK_ID           = Guid.NewGuid(),
                            COMMENTAIRE     = _commentaire,
                            PIECE_JOINTE    = null,
                            UTILISATEUR     = _matriculeUser
                        };
                        dbWKF.InsertCommentaireRejet(new List <CsCommentaireRejet>()
                            {
                                Com
                            });

                        int suivant = dmdWorkflow.FK_IDETAPEACTUELLE;
                        dmdWorkflow.FK_IDETAPEACTUELLE = etapeDemande.FK_IDETAPE;
                        dmdWorkflow.FK_IDETAPECIRCUIT  = etapeDemande.PK_ID;
                        dmdWorkflow.FK_IDETAPESUIVANTE = suivant;

                        dmdWorkflow.FK_IDSTATUS = (int)STATUSDEMANDE.Rejetee;
                        dmdWorkflow.DATEDERNIEREMODIFICATION = DateTime.Now;

                        _result = RESULTACTION.REJETEE;
                        MessageErreur.Set(context, "");

                        jrnal = new CsJournalDemandeWorkflow()
                        {
                            CODE_DEMANDE        = dmdWorkflow.CODE,
                            DATEACTION          = DateTime.Today.Date,
                            FK_IDDEMANDE        = dmdWorkflow.PK_ID,
                            PK_ID               = Guid.NewGuid(),
                            LIBELLEACTION       = "Rejet à l'étape " + etapeDemande.LIBELLEETAPE,
                            MATRICULEUSERACTION = _matriculeUser,
                            OBSERVATIONS        = string.Empty
                        };
                    }
                    break;
                    }

                    if (_result != RESULTACTION.ERREURINCONNUE)
                    {
                        dbWKF.UpdateDemande(new List <CsDemandeWorkflow>()
                        {
                            dmdWorkflow
                        });
                        dbWKF.SupprimerAffectationDemande(dmdWorkflow.CODE);

                        //Insertion du journal
                        dbWKF.InsertJournalDemande(new List <CsJournalDemandeWorkflow>()
                        {
                            jrnal
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                _result = RESULTACTION.ERREURINCONNUE;
                MessageErreur.Set(context, ex.Message);
            }
            return(_result);
        }
Пример #7
0
        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override RESULTACTION  Execute(CodeActivityContext context)
        {
            RESULTACTION result = RESULTACTION.ERREURINCONNUE;

            string      _codeDemande = context.GetValue <string>(CodeDemande);
            string      _matricule   = context.GetValue <string>(MatriculeUser);
            DB_WORKFLOW dbWKF        = new DB_WORKFLOW();

            CsDemandeWorkflow dmd = dbWKF.SelectLaDemande(_codeDemande);

            if (null != dmd)
            {
                CODEACTION codeA = context.GetValue <CODEACTION>(CodeAction);
                KeyValuePair <CsCopieDmdCircuit, CsCopieDmdConditionBranchement> EtapeCourrante = dbWKF.RecupererEtapeCourante(dmd.CODE);
                string _actionOnDemande = string.Empty;
                if (null != EtapeCourrante.Key)
                {
                    try
                    {
                        if (codeA == CODEACTION.ANNULER)
                        {
                            //On annule la demande
                            dmd.FK_IDSTATUS  = (int)STATUSDEMANDE.Annulee;
                            _actionOnDemande = "Annulation  à l'étape " + EtapeCourrante.Key.LIBELLEETAPE;
                            result           = RESULTACTION.ANNULEE;
                        }
                        else if (codeA == CODEACTION.SUSPENDRE)
                        {
                            //On suspend la demande
                            dmd.FK_IDSTATUS  = (int)STATUSDEMANDE.Suspendue;
                            _actionOnDemande = "Suspendue à l'étape " + EtapeCourrante.Key.LIBELLEETAPE;
                            result           = RESULTACTION.SUSPENDUE;
                        }

                        dmd.DATEDERNIEREMODIFICATION = DateTime.Now;
                        //On met à jour la demande
                        bool insertion = dbWKF.UpdateDemande(new List <CsDemandeWorkflow>()
                        {
                            dmd
                        });

                        if (insertion)
                        {
                            //Maintenant on met le journal
                            CsJournalDemandeWorkflow jrnal = new CsJournalDemandeWorkflow();
                            jrnal.PK_ID               = Guid.NewGuid();
                            jrnal.CODE_DEMANDE        = dmd.CODE;
                            jrnal.FK_IDDEMANDE        = dmd.PK_ID;
                            jrnal.LIBELLEACTION       = _actionOnDemande;
                            jrnal.DATEACTION          = DateTime.Today.Date;
                            jrnal.OBSERVATIONS        = string.Empty;
                            jrnal.MATRICULEUSERACTION = _matricule;

                            dbWKF.InsertJournalDemande(new List <CsJournalDemandeWorkflow>()
                            {
                                jrnal
                            });
                            MessageErreur.Set(context, "");
                        }
                        else
                        {
                            MessageErreur.Set(context, "Une erreur interne est survenue");
                            result = RESULTACTION.ERREURINCONNUE;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageErreur.Set(context, ex.Message);
                        result = RESULTACTION.ERREURINCONNUE;
                    }
                }
                else
                {
                    MessageErreur.Set(context, "Impossible d'effectuer une action sur une demande n'étant pas à une étape");
                    result = RESULTACTION.ERREURINCONNUE;
                }
            }
            else
            {
                MessageErreur.Set(context, "Impossible d'annuler une demande nulle");
                result = RESULTACTION.ERREURINCONNUE;
            }

            return(result);
        }