Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string TokenCode = Request.QueryString["TokenCode"] == null ? string.Empty : Request.QueryString["TokenCode"].Trim();
            string From      = Request.QueryString["From"] == null ? string.Empty : Request.QueryString["From"].Trim();
            string Type      = Request.QueryString["Type"] == null ? string.Empty : Request.QueryString["Type"].Trim();
            int    eventID   = Request.QueryString["EventID"] == null ? -1 : Int32.Parse(Request.QueryString["EventID"].Trim());

            //1. SignIn by UserName (From)
            string userName = SS.SU.Query.QueryProvider.SuUserQuery.FindByIdentity(UIHelper.ParseLong(From)).UserName;

            UserEngine.SignIn(userName);

            this.Title       = "Approval via Email By :" + userName;
            this.ProgramCode = "ApprovalViaEmail";
            UserAccount.CurrentProgramCode = this.ProgramCode;

            //1.1 If cannot SignIn , we not need to call workflow
            if (UserAccount.Authentication)
            {
                try
                {
                    WorkFlowResponseToken token = WorkFlowResponseTokenQuery.GetByTokenCode_WorkFlowStateEventID(TokenCode, eventID);


                    if (token == null)
                    {
                        Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();
                        errors.AddError("General.Error", new Spring.Validation.ErrorMessage(
                                            GetMessage("InvalidTokenID")
                                            ));
                        throw new ServiceValidationException(errors);
                    }
                    else
                    {
                        string successText = GetMessage("ApproveRejectResultMessage",
                                                        token.WorkFlow.Document.DocumentNo,
                                                        WorkFlowStateEventQuery.GetTranslatedEventName(
                                                            token.WorkFlowStateEvent.WorkFlowStateEventID,
                                                            UserAccount.CurrentLanguageID));

                        WorkFlowService.NotifyEventFromToken(TokenCode, UserAccount.UserID, eventID, TokenType.Email);

                        ctlResult.Text = successText;
                    }
                }
                catch (ServiceValidationException ex)
                {
                    this.ValidationErrors.MergeErrors(ex.ValidationErrors);
                }
                finally
                {
                    UserEngine.SignOut(UserAccount.UserID);
                }
            }
            else
            {
                this.ValidationErrors.AddError("General.Error",
                                               new Spring.Validation.ErrorMessage("ApproveRejectResultLoginFail"));
            }
        }
Exemplo n.º 2
0
        private bool CallWorkFlow(string TokenCode, string approveFlag, string From)
        {
            //1.1 If cannot SignIn , we not need to call workflow



            string docNo = "";

            if (UserAccount != null && UserAccount.Authentication)
            {
                try
                {
                    IList <WorkFlowResponseToken> responseTokens = WorkFlowQueryProvider.WorkFlowResponseTokenQuery.FindByTokenCode(TokenCode);

                    int?eventID = null;

                    foreach (WorkFlowResponseToken responseToken in responseTokens)
                    {
                        if (responseToken.WorkFlowStateEvent.Name.ToLower() == approveFlag.ToLower())
                        {
                            eventID = responseToken.WorkFlowStateEvent.WorkFlowStateEventID;
                            break;
                        }
                        else if (responseToken.WorkFlowStateEvent.Name.ToLower() == approveFlag.ToLower())
                        {
                            eventID = responseToken.WorkFlowStateEvent.WorkFlowStateEventID;
                            break;
                        }
                    }


                    WorkFlowResponseToken token = WorkFlowResponseTokenQuery.GetByTokenCode_WorkFlowStateEventID(TokenCode, eventID.Value);

                    if (token == null)
                    {
                        Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();
                        string error = new Spring.Validation.ErrorMessage("InvalidTokenID").ToString();
                        //errors.AddError("General.Error", new Spring.Validation.ErrorMessage("InvalidTokenID"));

                        //send sms notify error
                        SCGSMSService.SendSMS09(error, TokenCode, From, true);

                        //throw new ServiceValidationException(errors);
                    }
                    else
                    {
                        docNo = token.WorkFlow.Document.DocumentNo;
                        string successText = GetMessage("ApproveRejectResultMessage",
                                                        token.WorkFlow.Document.DocumentNo,
                                                        WorkFlowStateEventQuery.GetTranslatedEventName(
                                                            token.WorkFlowStateEvent.WorkFlowStateEventID,
                                                            UserAccount.CurrentLanguageID));

                        WorkFlowService.NotifyEventFromSMSToken(TokenCode, UserAccount.UserID, eventID.Value, TokenType.SMS);


                        //send sms notify approve comleted user
                        SCGSMSService.SendSMS05(TokenCode, UserAccount.UserID, true, approveFlag);
                    }
                }
                catch (ServiceValidationException ex)
                {
                    this.ValidationErrors.MergeErrors(ex.ValidationErrors);

                    string error = ex.ValidationErrors.ToString();
                    //send sms notify approve comleted user
                    //SCGSMSService.SendSMS04(TokenCode + " " + approveFlag + " ", UserAccount.UserID, true);
                    //send sms notify error
                    SCGSMSService.SendSMS09(error, TokenCode, From, true);
                }
                catch (Exception exm)
                {
                    string error = exm.Message.ToString();
                    //send sms notify approve comleted user
                    //SCGSMSService.SendSMS04(TokenCode + " " + approveFlag + " ", UserAccount.UserID, true);
                    //send sms notify error
                    SCGSMSService.SendSMS09(error, TokenCode, From, true);
                }
                finally
                {
                    UserEngine.SignOut(UserAccount.UserID);
                }
            }
            else
            {
                this.ValidationErrors.AddError("General.Error",
                                               new Spring.Validation.ErrorMessage("ApproveRejectResultLoginFail"));

                //send sms notify approve comleted user
                SCGSMSService.SendSMS06(TokenCode, UserAccount.UserID, true);
            }
            return(true);
        }