/// <summary>
        ///Perform Process.
        /// </summary>
        /// <returns>Message (variables are parsed)</returns>
        protected override String DoIt()
        {
            string      msg      = null;
            MWFActivity activity = new MWFActivity(GetCtx(), p_AD_WF_Activity_ID, Get_Trx());

            log.Info("" + activity);

            MUser user = MUser.Get(GetCtx(), GetAD_User_ID());

            //	Abort
            if (p_IsAbort)
            {
                msg = user.GetName() + ": Abort";
                activity.SetTextMsg(msg);
                activity.SetAD_User_ID(GetAD_User_ID());
                activity.SetWFState(StateEngine.STATE_ABORTED);
                //JID_0278 : To mark processing checkbox false.
                // Mohit
                // Date : 22 May 2019
                MTable table = new MTable(GetCtx(), activity.GetAD_Table_ID(), null);
                PO     po    = MTable.GetPO(GetCtx(), table.GetTableName(), activity.GetRecord_ID(), Get_Trx());
                if (po != null && po.Get_ColumnIndex("Processing") >= 0)
                {
                    po.Set_Value("Processing", false);
                    po.Save();
                }
                return(msg);
            }

            //	Change User
            if (p_AD_User_ID != 0 && activity.GetAD_User_ID() != p_AD_User_ID)
            {
                MUser from = MUser.Get(GetCtx(), activity.GetAD_User_ID());
                MUser to   = MUser.Get(GetCtx(), p_AD_User_ID);
                msg = user.GetName() + ": " + from.GetName() + " -> " + to.GetName();
                activity.SetTextMsg(msg);
                activity.SetAD_User_ID(p_AD_User_ID);
            }
            //	Change Responsible
            if (p_AD_WF_Responsible_ID != 0 && activity.GetAD_WF_Responsible_ID() != p_AD_WF_Responsible_ID)
            {
                MWFResponsible from = MWFResponsible.Get(GetCtx(), activity.GetAD_WF_Responsible_ID());
                MWFResponsible to   = MWFResponsible.Get(GetCtx(), p_AD_WF_Responsible_ID);
                String         msg1 = user.GetName() + ": " + from.GetName() + " -> " + to.GetName();
                activity.SetTextMsg(msg1);
                activity.SetAD_WF_Responsible_ID(p_AD_WF_Responsible_ID);
                if (msg == null)
                {
                    msg = msg1;
                }
                else
                {
                    msg += " - " + msg1;
                }
            }
            activity.Save();
            return(msg);
        }
        /// <summary>
        ///Perform Process.
        /// </summary>
        /// <returns>Message (variables are parsed)</returns>
        protected override String DoIt()
        {
            string      msg      = null;
            MWFActivity activity = new MWFActivity(GetCtx(), p_AD_WF_Activity_ID, Get_Trx());

            log.Info("" + activity);

            MUser user = MUser.Get(GetCtx(), GetAD_User_ID());

            //	Abort
            if (p_IsAbort)
            {
                msg = user.GetName() + ": Abort";
                activity.SetTextMsg(msg);
                activity.SetAD_User_ID(GetAD_User_ID());
                activity.SetWFState(StateEngine.STATE_ABORTED);
                return(msg);
            }

            //	Change User
            if (p_AD_User_ID != 0 && activity.GetAD_User_ID() != p_AD_User_ID)
            {
                MUser from = MUser.Get(GetCtx(), activity.GetAD_User_ID());
                MUser to   = MUser.Get(GetCtx(), p_AD_User_ID);
                msg = user.GetName() + ": " + from.GetName() + " -> " + to.GetName();
                activity.SetTextMsg(msg);
                activity.SetAD_User_ID(p_AD_User_ID);
            }
            //	Change Responsible
            if (p_AD_WF_Responsible_ID != 0 && activity.GetAD_WF_Responsible_ID() != p_AD_WF_Responsible_ID)
            {
                MWFResponsible from = MWFResponsible.Get(GetCtx(), activity.GetAD_WF_Responsible_ID());
                MWFResponsible to   = MWFResponsible.Get(GetCtx(), p_AD_WF_Responsible_ID);
                String         msg1 = user.GetName() + ": " + from.GetName() + " -> " + to.GetName();
                activity.SetTextMsg(msg1);
                activity.SetAD_WF_Responsible_ID(p_AD_WF_Responsible_ID);
                if (msg == null)
                {
                    msg = msg1;
                }
                else
                {
                    msg += " - " + msg1;
                }
            }
            activity.Save();
            return(msg);
        }
        /// <summary>
        /// Activity Constructor
        /// </summary>
        /// <param name="activity">activity</param>
        public MWFEventAudit(MWFActivity activity)
            : base(activity.GetCtx(), 0, activity.Get_TrxName())
        {
            SetAD_WF_Process_ID(activity.GetAD_WF_Process_ID());
            SetAD_WF_Node_ID(activity.GetAD_WF_Node_ID());
            SetAD_Table_ID(activity.GetAD_Table_ID());
            SetRecord_ID(activity.GetRecord_ID());
            SetAD_WF_Responsible_ID(activity.GetAD_WF_Responsible_ID());
            SetAD_User_ID(activity.GetAD_User_ID());
            SetWFState(activity.GetWFState());
            SetEventType(EVENTTYPE_ProcessCreated);
            SetElapsedTimeMS(Utility.Env.ZERO);
            MWFNode node = activity.GetNode();

            if (node != null && node.Get_ID() != 0)
            {
                String action = node.GetAction();
                if (MWFNode.ACTION_SetVariable.Equals(action) ||
                    MWFNode.ACTION_UserChoice.Equals(action))
                {
                    SetAttributeName(node.GetAttributeName());
                    //SetOldValue(String.valueOf(activity.getAttributeValue()));
                    SetOldValue(Util.GetValueOfString(activity.GetAttributeValue()));
                    if (MWFNode.ACTION_SetVariable.Equals(action))
                    {
                        SetNewValue(node.GetAttributeValue());
                    }
                }
            }
        }
Beispiel #4
0
        }       //	sendAlerts

        private int SendEmail(MWFActivity activity, String AD_Message, bool toProcess, bool toSupervisor)
        {
            if (m_client == null || m_client.GetAD_Client_ID() != activity.GetAD_Client_ID())
            {
                m_client = MClient.Get(GetCtx(), activity.GetAD_Client_ID());
            }

            MWFProcess process = new MWFProcess(GetCtx(), activity.GetAD_WF_Process_ID(), null);

            String subjectVar = activity.GetNode().GetName();
            String message    = activity.GetTextMsg();

            if (message == null || message.Length == 0)
            {
                message = process.GetTextMsg();
            }
            FileInfo pdf = null;
            PO       po  = activity.GetPO();

            if (po is DocAction)
            {
                message = ((DocAction)po).GetDocumentInfo() + "\n" + message;
                pdf     = ((DocAction)po).CreatePDF();
            }

            //  Inactivity Alert: Workflow Activity {0}
            String subject = Msg.GetMsg(m_client.GetAD_Language(), AD_Message,
                                        new Object[] { subjectVar });

            //	Prevent duplicates
            List <int> list    = new List <int>();
            int        counter = 0;

            //	To Activity Owner
            if (m_client.SendEMail(activity.GetAD_User_ID(), subject, message, pdf))
            {
                counter++;
            }
            list.Add(activity.GetAD_User_ID());

            //	To Process Owner
            if (toProcess &&
                process.GetAD_User_ID() != activity.GetAD_User_ID())
            {
                if (m_client.SendEMail(process.GetAD_User_ID(), subject, message, pdf))
                {
                    counter++;
                }
                list.Add(process.GetAD_User_ID());
            }

            //	To Activity Responsible
            MWFResponsible responsible = MWFResponsible.Get(GetCtx(), activity.GetAD_WF_Responsible_ID());

            counter += sendAlertToResponsible(responsible, list, process, subject, message, pdf);

            //	To Process Responsible
            if (toProcess &&
                process.GetAD_WF_Responsible_ID() != activity.GetAD_WF_Responsible_ID())
            {
                responsible = MWFResponsible.Get(GetCtx(), process.GetAD_WF_Responsible_ID());
                counter    += sendAlertToResponsible(responsible, list, process, subject, message, pdf);
            }

            //	Processor SuperVisor
            if (toSupervisor && m_model.GetSupervisor_ID() != 0 &&
                !list.Contains(m_model.GetSupervisor_ID()))
            {
                if (m_client.SendEMail(m_model.GetSupervisor_ID(), subject, message, pdf))
                {
                    counter++;
                }
                list.Add(m_model.GetSupervisor_ID());
            }

            return(counter);
        }   //  sendAlert
        public string ApproveIt(int nodeID, int activityID, string textMsg, object forward, object answer, Ctx ctx)
        {
            MWFActivity activity      = new MWFActivity(ctx, activityID, null);
            MWFNode     node          = activity.GetNode();
            int         approvalLevel = node.GetApprovalLeval();
            int         AD_User_ID    = ctx.GetAD_User_ID();
            MColumn     column        = node.GetColumn();

            if (forward != null) // Prefer Forward
            {
                int fw = int.Parse(forward.ToString());
                if (fw == AD_User_ID || fw == 0)
                {
                    return("");
                }
                if (!activity.ForwardTo(fw, textMsg, true))
                {
                    return("CannotForward");
                }
            }
            //	User Choice - Answer
            else if (MWFNode.ACTION_UserChoice.Equals(node.GetAction()))
            {
                if (column == null)
                {
                    column = node.GetColumn();
                }
                //	Do we have an answer?
                int    dt    = column.GetAD_Reference_ID();
                String value = null;
                value = answer != null?answer.ToString() : null;

                //if (dt == DisplayType.YesNo || dt == DisplayType.List || dt == DisplayType.TableDir)
                if (!node.IsMultiApproval() &&
                    (dt == DisplayType.YesNo || dt == DisplayType.List || dt == DisplayType.TableDir))
                {
                    if (value == null || value.Length == 0)
                    {
                        return("FillMandatory");
                    }
                    //
                    string res = SetUserChoice(AD_User_ID, value, dt, textMsg, activity, node);
                    if (res != "OK")
                    {
                        return(res);
                    }
                }
                //Genral Attribute Instance
                //else if (column.GetColumnName().ToUpper().Equals("C_GENATTRIBUTESETINSTANCE_ID"))
                //{
                //    if (attrib == null)
                //    {
                //        Dispatcher.BeginInvoke(delegate
                //        {
                //            SetBusy(false);
                //            ShowMessage.Error("FillMandatory", true, Msg.GetMsg(Envs.GetContext(), "Answer", true));
                //            //log.Config("Answer=" + value + " - " + textMsg);
                //            return;
                //        });
                //        return;
                //    }

                //    SetUserChoice(AD_User_ID, attrib.GetAttributeSetInstance().ToString(), 0, textMsg, activity, node);
                //}

                else if (forward == null && node.IsMultiApproval() && approvalLevel > 0 && answer.ToString().Equals("Y"))
                {
                    int eventCount = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT COUNT(WFE.AD_WF_EventAudit_ID) FROM AD_WF_EventAudit WFE
                                                                                INNER JOIN AD_WF_Process WFP ON (WFP.AD_WF_Process_ID=WFE.AD_WF_Process_ID)
                                                                                INNER JOIN AD_WF_Activity WFA ON (WFA.AD_WF_Process_ID=WFP.AD_WF_Process_ID)
                                                                                WHERE WFE.AD_WF_Node_ID=" + node.GetAD_WF_Node_ID() + " AND WFA.AD_WF_Activity_ID=" + activity.GetAD_WF_Activity_ID()));
                    if (eventCount < approvalLevel) //Forward Activity
                    {
                        int superVisiorID = Util.GetValueOfInt(DB.ExecuteScalar("SELECT Supervisor_ID FROM AD_User WHERE IsActive='Y' AND AD_User_ID=" + activity.GetAD_User_ID()));
                        if (superVisiorID == 0)//Approve
                        {
                            //SetUserConfirmation(AD_User_ID, textMsg, activity, node);

                            string res = SetUserChoice(AD_User_ID, value, dt, textMsg, activity, node);
                            if (res != "OK")
                            {
                                return(res);
                            }
                        }
                        else //forward
                        {
                            if (!activity.ForwardTo(superVisiorID, textMsg, true))
                            {
                                //Dispatcher.BeginInvoke(delegate
                                //{
                                //    SetBusy(false);
                                //    ShowMessage.Error("CannotForward", true);
                                //    return;
                                //});
                                return("CannotForward");
                            }
                        }
                    }
                    else //Approve
                    {
                        //SetUserConfirmation(AD_User_ID, textMsg, activity, node);

                        string res = SetUserChoice(AD_User_ID, value, dt, textMsg, activity, node);
                        if (res != "OK")
                        {
                            return(res);
                        }
                    }
                }
                else
                {
                    string res = SetUserChoice(AD_User_ID, value, dt, textMsg, activity, node);
                    if (res != "OK")
                    {
                        return(res);
                    }
                }
            }
            //	User Action
            else
            {
                //   log.Config("Action=" + node.GetAction() + " - " + textMsg);
                //try
                //{
                //    activity.SetUserConfirmation(AD_User_ID, textMsg);
                //}
                //catch (Exception exx)
                //{
                //    Dispatcher.BeginInvoke(delegate
                //            {
                //                SetBusy(false);
                //                log.Log(Level.SEVERE, node.GetName(), exx);
                //                ShowMessage.Error("Error", true, exx.ToString());
                //                return;
                //            });
                //    return;
                //}
                activity.SetUserConfirmation(AD_User_ID, textMsg);
            }

            return("");
        }