Example #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"));
            }
        }
        private string SaveResponseTokenEmail(long workFlowID, long userID)
        {
            WorkFlowResponseTokenService.ClearResponseTokenByWorkFlowID(workFlowID, TokenType.Email);

            WorkFlow workFlow = WorkFlowQueryProvider.WorkFlowQuery.FindProxyByIdentity(workFlowID);

            string tokenCode = Guid.NewGuid().ToString();
            IList <WorkFlowStateEventPermission> stateEventPermissions = WorkFlowQueryProvider.WorkFlowStateEventPermissionQuery.FindByWorkFlowID_UserID(workFlowID, userID);

            foreach (WorkFlowStateEventPermission stateEventPermission in stateEventPermissions)
            {
                WorkFlowResponseToken responseToken = new WorkFlowResponseToken();
                responseToken.TokenCode          = tokenCode;
                responseToken.UserID             = stateEventPermission.UserID.Value;
                responseToken.WorkFlow           = workFlow;
                responseToken.TokenType          = TokenType.Email.ToString();
                responseToken.WorkFlowStateEvent = stateEventPermission.WorkFlowStateEvent;
                responseToken.Active             = true;
                responseToken.CreBy   = UserAccount.UserID;
                responseToken.CreDate = DateTime.Now;
                responseToken.UpdBy   = UserAccount.UserID;
                responseToken.UpdDate = DateTime.Now;
                responseToken.UpdPgm  = UserAccount.CurrentProgramCode;

                WorkFlowResponseTokenService.Save(responseToken);
            }
            return(tokenCode);
        }
Example #3
0
        public void NotifyEventFromToken(string tokenCode, long userID, int workFlowStateEventID, TokenType tokenType)
        {
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();

            WorkFlowResponseToken responseToken = WorkFlowQueryProvider.WorkFlowResponseTokenQuery.GetByTokenCode_WorkFlowStateEventID(tokenCode, workFlowStateEventID);

            if (responseToken == null)
            {
                errors.AddError("NotifyEventFromToken", new Spring.Validation.ErrorMessage("NotifyEventFromToken_Mismatch_ResponseToken"));
            }
            else if (userID != responseToken.UserID)
            {
                errors.AddError("NotifyEventFromToken", new Spring.Validation.ErrorMessage("NotifyEventFromToken_Mismatch_UserID"));
            }

            if (!errors.IsEmpty)
            {
                throw new SS.Standard.Utilities.ServiceValidationException(errors);
            }

            SubmitResponse eventData = new SubmitResponse(workFlowStateEventID);

            if (tokenType == TokenType.Email)
            {
                eventData.ResponseMethod = ResponseMethod.Email;
            }
            else if (tokenType == TokenType.SMS)
            {
                eventData.ResponseMethod = ResponseMethod.SMS;
            }
            NotifyEvent(responseToken.WorkFlow.WorkFlowID, responseToken.WorkFlowStateEvent.Name, eventData);

            WorkFlowResponseTokenService.ClearResponseToken(tokenCode);
        }
        private string SaveResponseTokenSMS(long workFlowID, long userID)
        {
            WorkFlowResponseTokenService.ClearResponseTokenByWorkFlowID(workFlowID, TokenType.SMS);

            WorkFlow workFlow = WorkFlowQueryProvider.WorkFlowQuery.FindProxyByIdentity(workFlowID);

            //string tokenCode = WorkFlowsmsTokenService.GetRunning().ToString().PadLeft(5,'0');
            string tokenCode = WorkFlowsmsTokenService.GetSMSTokenCode(workFlowID).Substring(0, 5);
            IList <WorkFlowStateEventPermission> stateEventPermissions = WorkFlowQueryProvider.WorkFlowStateEventPermissionQuery.FindByWorkFlowID_UserID(workFlowID, userID);

            foreach (WorkFlowStateEventPermission stateEventPermission in stateEventPermissions)
            {
                WorkFlowResponseToken responseToken = new WorkFlowResponseToken();
                responseToken.TokenCode          = "1" + tokenCode;
                responseToken.UserID             = stateEventPermission.UserID.Value;
                responseToken.WorkFlow           = workFlow;
                responseToken.TokenType          = TokenType.SMS.ToString();
                responseToken.WorkFlowStateEvent = stateEventPermission.WorkFlowStateEvent;
                responseToken.Active             = true;
                responseToken.CreBy   = UserAccount.UserID;
                responseToken.CreDate = DateTime.Now;
                responseToken.UpdBy   = UserAccount.UserID;
                responseToken.UpdDate = DateTime.Now;
                responseToken.UpdPgm  = UserAccount.CurrentProgramCode;

                WorkFlowResponseTokenService.Save(responseToken);
            }



            return(tokenCode);
        }
Example #5
0
        private bool CallWorkFlow(string TokenCode, string approveFlag, string From)
        {
            //1.1 If cannot SignIn , we not need to call workflow

            IWorkFlowResponseTokenQuery WorkFlowResponseTokenQuery = (IWorkFlowResponseTokenQuery)ContextRegistry.GetContext().GetObject("WorkFlowResponseTokenQuery");

            string docNo = "";

            if (UserAccount != null && UserAccount.Authentication)
            {
                try
                {
                    IList <WorkFlowResponseToken> responseTokens = 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();
                        //send sms notify error
                        SCGSMSService.SendSMS09(error, TokenCode, From, true);
                    }
                    else
                    {
                        docNo = token.WorkFlow.Document.DocumentNo;

                        WorkFlowService = (IWorkFlowService)ContextRegistry.GetContext().GetObject("WorkFlowService");

                        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)
                {
                    string error = ex.ValidationErrors.ToString();
                    //send sms notify error
                    SCGSMSService.SendSMS09(error, TokenCode, From, true);
                }
                catch (Exception exm)
                {
                    string error = exm.Message.ToString();
                    //send sms notify error
                    SCGSMSService.SendSMS09(error, TokenCode, From, true);
                }
                finally
                {
                    UserEngine.SignOut(UserAccount.UserID);
                }
            }
            else
            {
                //send sms notify approve comleted user
                SCGSMSService.SendSMS06(TokenCode, UserAccount.UserID, true);
            }
            return(true);
        }
        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);
        }