Beispiel #1
0
        /// <summary>
        /// Is this a Valid Transition For ..
        /// </summary>
        /// <param name="activity">activity</param>
        /// <returns>true if valid</returns>
        public bool IsValidFor(MWFActivity activity)
        {
            if (IsStdUserWorkflow())
            {
                PO po = activity.GetPO();
                if (po.GetType() == typeof(DocAction) || po.GetType().GetInterface("DocAction") == typeof(DocAction))
                {
                    DocAction da        = (DocAction)po;
                    String    docStatus = da.GetDocStatus();
                    String    docAction = da.GetDocAction();
                    if (!DocActionVariables.ACTION_COMPLETE.Equals(docAction) ||
                        DocActionVariables.STATUS_COMPLETED.Equals(docStatus) ||
                        DocActionVariables.STATUS_WAITINGCONFIRMATION.Equals(docStatus) ||
                        DocActionVariables.STATUS_WAITINGPAYMENT.Equals(docStatus) ||
                        DocActionVariables.STATUS_VOIDED.Equals(docStatus) ||
                        DocActionVariables.STATUS_CLOSED.Equals(docStatus) ||
                        DocActionVariables.STATUS_REVERSED.Equals(docStatus))

                    /*
                    || DocAction.ACTION_Complete.equals(docAction)
                    || DocAction.ACTION_ReActivate.equals(docAction)
                    || DocAction.ACTION_None.equals(docAction)
                    || DocAction.ACTION_Post.equals(docAction)
                    || DocAction.ACTION_Unlock.equals(docAction)
                    || DocAction.ACTION_Invalidate.equals(docAction)	) */
                    {
                        log.Fine("isValidFor =NO= StdUserWF - Status=" + docStatus + " - Action=" + docAction);
                        return(false);
                    }
                }
            }
            //	No Conditions
            if (GetConditions(false).Length == 0)
            {
                log.Fine("#0 " + ToString());
                return(true);
            }
            //	First condition always AND
            bool ok = _conditions[0].Evaluate(activity);

            for (int i = 1; i < _conditions.Length; i++)
            {
                if (_conditions[i].IsOr())
                {
                    ok = ok || _conditions[i].Evaluate(activity);
                }
                else
                {
                    ok = ok && _conditions[i].Evaluate(activity);
                }
            }           //	for all conditions
            log.Fine("isValidFor (" + ok + ") " + ToString());
            return(ok);
        }
        /// <summary>
        /// Evaluate Condition
        /// </summary>
        /// <param name="activity">activity</param>
        /// <returns>true if true</returns>
        public bool Evaluate(MWFActivity activity)
        {
            AD_WF_Activity_ID = activity.GetAD_WF_Activity_ID();
            if (GetAD_Column_ID() == 0)
            {
                //throw new IllegalStateException("No Column defined - " + this);
                throw new Exception("No Column defined - " + this);
            }



            PO po = activity.GetPO();

            if (po == null || po.Get_ID() == 0)
            {
                //throw new IllegalStateException("Could not evaluate " + po + " - " + this);
                throw new Exception("Could not evaluate " + po + " - " + this);
            }
            //
            Object valueObj = po.Get_ValueOfColumn(GetAD_Column_ID());

            if (valueObj == null)
            {
                valueObj = "";
            }
            String value1 = GetValue();

            if (value1 == null)
            {
                value1 = "";
            }



            String value2 = GetValue2();

            if (value2 == null)
            {
                value2 = "";
            }

            // If column is of bool type and user insert y or n in condition, then convert them to true or false to match with value got from PO.
            if (MColumn.Get(GetCtx(), GetAD_Column_ID()).GetAD_Reference_ID().Equals(DisplayType.YesNo))
            {
                if (value1.ToLower().Equals("y"))
                {
                    value1 = "true";
                }
                else if (value1.ToLower().Equals("n"))
                {
                    value1 = "false";
                }

                if (value2.ToLower().Equals("y"))
                {
                    value2 = "true";
                }
                else if (value2.ToLower().Equals("n"))
                {
                    value2 = "false";
                }
            }

            String resultStr = "PO:{" + valueObj + "} " + GetOperation() + " Condition:{" + value1 + "}";

            if (GetOperation().Equals(OPERATION_Sql))
            {
                throw new ArgumentException("SQL Operator not implemented yet: " + resultStr);
            }
            if (GetOperation().Equals(OPERATION_X))
            {
                resultStr += "{" + value2 + "}";
            }

            bool result = false;

            //Lakhwinder
            if (MColumn.Get(GetCtx(), GetAD_Column_ID()).GetColumnName().ToUpper().Equals("C_GENATTRIBUTESETINSTANCE_ID"))
            {
                return(EvaluateAttributeCondition(po));
            }

            //if (valueObj instanceof Number)
            if (valueObj != null && CommonFunctions.IsNumeric(valueObj.ToString()))
            {
                result = CompareNumber(valueObj, value1, value2);
            }
            else
            {
                result = CompareString(valueObj, value1, value2);
            }
            //
            log.Fine(resultStr + " -> " + result + (_numeric ? " (#)" : " ($)"));
            return(result);
        }
Beispiel #3
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 ActivityInfo GetActivityInfo(int activityID, int nodeID, int wfProcessID, Ctx ctx)
        {
            ActivityInfo info = new ActivityInfo();

            try
            {
                MWFNode node = new MWFNode(ctx, nodeID, null);
                info.NodeAction = node.GetAction();
                info.NodeName   = node.GetName();
                if (MWFNode.ACTION_UserChoice.Equals(node.GetAction()))
                {
                    MColumn col = node.GetColumn();
                    info.ColID             = col.GetAD_Column_ID();
                    info.ColReference      = col.GetAD_Reference_ID();
                    info.ColReferenceValue = col.GetAD_Reference_Value_ID();
                    info.ColName           = col.GetColumnName();
                }
                else if (MWFNode.ACTION_UserWindow.Equals(node.GetAction()))
                {
                    info.AD_Window_ID = node.GetAD_Window_ID();
                    MWFActivity activity = new MWFActivity(ctx, activityID, null);
                    info.KeyCol = activity.GetPO().Get_TableName() + "_ID";
                }
                else if (MWFNode.ACTION_UserForm.Equals(node.GetAction()))
                {
                    info.AD_Form_ID = node.GetAD_Form_ID();
                }



                string  sql = @"SELECT node.ad_wf_node_ID,
                                  node.Name AS NodeName,
                                  usr.Name AS UserName,
                                  wfea.wfstate,
                                  wfea.TextMsg
                              FROM ad_wf_eventaudit wfea
                                INNER JOIN Ad_WF_Node node
                                ON (node.Ad_Wf_node_ID=wfea.AD_Wf_Node_id)
                                INNER JOIN AD_User usr
                                ON (usr.Ad_User_ID         =wfea.ad_User_ID)
                              WHERE wfea.AD_WF_Process_ID=" + wfProcessID + @"
                              Order By wfea.ad_wf_eventaudit_id desc";
                DataSet ds  = DB.ExecuteDataset(sql);
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    List <NodeInfo> nodeInfo = new List <NodeInfo>();
                    List <int>      nodes    = new List <int>();
                    NodeInfo        ni       = null;
                    NodeHistory     nh       = null;
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        if (!nodes.Contains(Util.GetValueOfInt(ds.Tables[0].Rows[i]["AD_WF_Node_ID"])))
                        {
                            ni            = new NodeInfo();
                            ni.Name       = Util.GetValueOfString(ds.Tables[0].Rows[i]["NodeName"]);
                            nh            = new NodeHistory();
                            nh.State      = Util.GetValueOfString(ds.Tables[0].Rows[i]["WFState"]);
                            nh.ApprovedBy = Util.GetValueOfString(ds.Tables[0].Rows[i]["UserName"]);
                            ni.History    = new List <NodeHistory>();

                            if (ds.Tables[0].Rows[i]["TextMsg"] == null || ds.Tables[0].Rows[i]["TextMsg"] == DBNull.Value)
                            {
                                nh.TextMsg = string.Empty;
                            }
                            else
                            {
                                nh.TextMsg = ds.Tables[0].Rows[i]["TextMsg"].ToString();
                            }
                            ni.History.Add(nh);
                            nodes.Add(Util.GetValueOfInt(ds.Tables[0].Rows[i]["AD_WF_Node_ID"]));
                            nodeInfo.Add(ni);
                        }
                        else
                        {
                            int index = nodes.IndexOf(Util.GetValueOfInt(ds.Tables[0].Rows[i]["AD_WF_Node_ID"]));
                            nh            = new NodeHistory();
                            nh.State      = Util.GetValueOfString(ds.Tables[0].Rows[i]["WFState"]);
                            nh.ApprovedBy = Util.GetValueOfString(ds.Tables[0].Rows[i]["UserName"]);
                            if (ds.Tables[0].Rows[i]["TextMsg"] == null || ds.Tables[0].Rows[i]["TextMsg"] == DBNull.Value)
                            {
                                nh.TextMsg = string.Empty;
                            }
                            else
                            {
                                nh.TextMsg = ds.Tables[0].Rows[i]["TextMsg"].ToString();
                            }
                            nodeInfo[index].History.Add(nh);
                        }
                    }
                    info.Node = nodeInfo;
                }

                return(info);
            }
            catch
            {
                return(info);
            }
        }