Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }