/// <summary>
        /// Start Next Activity
        /// </summary>
        /// <param name="last">last activity</param>
        /// <param name="activities">all activities</param>
        /// <returns>true if there is a next activity</returns>
        private bool StartNext(MWFActivity last, MWFActivity[] activities)
        {
            log.Config("Last=" + last);
            //	transitions from the last processed node
            MWFNodeNext[] transitions = GetWorkflow().GetNodeNexts(last.GetAD_WF_Node_ID(), last.GetAD_Client_ID());
            if (transitions == null || transitions.Length == 0)
            {
                log.Config("none");
                return(false);   //	done
            }

            //	We need to wait for last activity
            if (MWFNode.JOINELEMENT_AND.Equals(last.GetNode().GetJoinElement()))
            {
                //	get previous nodes
                //	check if all have closed activities
                //	return false for all but the last
            }
            //	eliminate from active processed
            //last.SetProcessed(true);
            last.Set_ValueNoCheck("Processed", true);
            last.Save();

            //	Start next activity
            String split = last.GetNode().GetSplitElement();

            for (int i = 0; i < transitions.Length; i++)
            {
                //	Is this a valid transition?
                if (!transitions[i].IsValidFor(last))
                {
                    continue;
                }

                //	Start new Activity
                MWFActivity activity = new MWFActivity(this, transitions[i].GetAD_WF_Next_ID());
                // set Last Activity ID property in current WF Activity
                activity.SetLastActivity(last.GetAD_WF_Activity_ID());
                // new Thread(activity).Start();
                //thred = new Thread(new ThreadStart(activity.Run));
                //thred.CurrentCulture = Utility.Env.GetLanguage(Utility.Env.GetContext()).GetCulture(Utility.Env.GetLoginLanguage(Utility.Env.GetContext()).GetAD_Language());
                //thred.CurrentUICulture = Utility.Env.GetLanguage(Utility.Env.GetContext()).GetCulture(Utility.Env.GetLoginLanguage(Utility.Env.GetContext()).GetAD_Language());
                activity.Run();
                // thred.Start();

                //	only the first valid if XOR
                if (MWFNode.SPLITELEMENT_XOR.Equals(split))
                {
                    return(true);
                }
            }   //	for all transitions
            return(true);
        }
        /// <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);
        }
Esempio n. 3
0
        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("");
        }