Example #1
0
        /// <summary>
        /// Parse text
        /// </summary>
        /// <param name="text">text</param>
        /// <param name="po">po object</param>
        /// <returns>parsed text</returns>
        public static string Parse(String text, PO po)
        {
            if (po == null || text.IndexOf("@") == -1)
            {
                return(text);
            }

            String        inStr = text;
            String        token;
            StringBuilder outStr = new StringBuilder();

            int i = inStr.IndexOf("@");

            while (i != -1)
            {
                outStr.Append(inStr.Substring(0, i)); // up to @
                inStr = inStr.Substring(i + 1);       ///from first @

                int j = inStr.IndexOf("@");           // next @
                if (j < 0)                            // no second tag
                {
                    inStr = "@" + inStr;
                    break;
                }

                token = inStr.Substring(0, j);
                if (token == "Tenant")
                {
                    int id = po.GetAD_Client_ID();
                    outStr.Append(DB.ExecuteScalar("Select Name FROM AD_Client WHERE AD_Client_ID=" + id));
                }
                else if (token == "Org")
                {
                    int id = po.GetAD_Org_ID();
                    outStr.Append(DB.ExecuteScalar("Select Name FROM AD_ORG WHERE AD_ORG_ID=" + id));
                }
                else if (token == "BPName")
                {
                    if (po.Get_TableName() == "C_BPartner")
                    {
                        outStr.Append(ParseVariable("Name", po));
                    }
                    else
                    {
                        outStr.Append("@" + token + "@");
                    }
                }
                else
                {
                    outStr.Append(ParseVariable(token, po));            // replace context
                }
                inStr = inStr.Substring(j + 1);
                // from second @
                i = inStr.IndexOf("@");
            }

            outStr.Append(inStr);                                               //	add remainder
            return(outStr.ToString());
        }
 /// <summary>
 /// Get AD_Org_ID
 /// </summary>
 /// <returns>org</returns>
 public int GetAD_Org_ID()
 {
     if (_AD_Org_ID <= 0)
     {
         return(_po.GetAD_Org_ID());
     }
     else
     {
         return(_AD_Org_ID);
     }
 }
Example #3
0
        /// <summary>
        /// New Constructor
        /// </summary>
        /// <param name="wf">workflow</param>
        /// <param name="pi">Process Info (Record_ID)</param>
        public MWFProcess(MWorkflow wf, ProcessInfo pi)
            : base(wf.GetCtx(), 0, wf.Get_TrxName())
        {
            if (!Utility.TimeUtil.IsValid(wf.GetValidFrom(), wf.GetValidTo())) // make this class or this function
            {
                //throw new IllegalStateException("Workflow not valid");
                throw new Exception("Workflow not valid");
            }
            _wf = wf;
            _pi = pi;
            SetAD_Client_ID(wf.GetAD_Client_ID());
            SetAD_Workflow_ID(wf.GetAD_Workflow_ID());
            SetPriority(wf.GetPriority());
            base.SetWFState(WFSTATE_NotStarted);

            // vinay bhatt for window id
            SetAD_Window_ID(pi.GetAD_Window_ID());
            //

            //	Document
            SetAD_Table_ID(wf.GetAD_Table_ID());
            SetRecord_ID(pi.GetRecord_ID());
            if (GetPO() == null)
            {
                SetTextMsg("No PO with ID=" + pi.GetRecord_ID());
                base.SetWFState(WFSTATE_Terminated);
            }
            else
            {
                SetTextMsg(GetPO());
            }
            //	Responsible/User
            if (wf.GetAD_WF_Responsible_ID() == 0)
            {
                SetAD_WF_Responsible_ID();
            }
            else
            {
                SetAD_WF_Responsible_ID(wf.GetAD_WF_Responsible_ID());
            }
            SetUser_ID((int)pi.GetAD_User_ID());                //	user starting
            //
            _state = new StateEngine(GetWFState());
            _state.SetCtx(GetCtx());
            SetProcessed(false);
            //	Lock Entity
            GetPO();
            if (_po != null)
            {
                // Set transaction organization on workflow process
                SetAD_Org_ID(_po.GetAD_Org_ID());
                _po.Lock();
            }
        }
 /// <summary>
 /// Create Document Line
 /// </summary>
 /// <param name="po">line persistent object</param>
 /// <param name="doc">header</param>
 public DocLine(PO po, Doc doc)
 {
     log = VLogger.GetVLogger(this.GetType().FullName);
     if (po == null)
     {
         throw new ArgumentException("PO is null");
     }
     _po  = po;
     _doc = doc;
     //
     //  Document Consistency
     if (_po.GetAD_Org_ID() == 0)
     {
         _po.SetAD_Org_ID(_doc.GetAD_Org_ID());
     }
 }
Example #5
0
        /// <summary>
        /// Insert data in Version table against multikey Master table
        /// </summary>
        /// <param name="baseTbl"></param>
        /// <param name="keyCols"></param>
        /// <param name="tblVer"></param>
        /// <returns></returns>
        private string InsertMKVersionData(MTable baseTbl, string[] keyCols, MTable tblVer)
        {
            string retMsg = "";
            // Get data from Master table
            DataSet dsRecs = DB.ExecuteDataset("SELECT * FROM " + baseTbl.GetTableName(), null, _trx);

            // check if there are any records in master table
            if (dsRecs != null && dsRecs.Tables[0].Rows.Count > 0)
            {
                // loop through all records and insert in Version table
                for (int i = 0; i < dsRecs.Tables[0].Rows.Count; i++)
                {
                    // get where Clause for Master table against multiple key columns
                    GetMKWhereClause(dsRecs.Tables[0].Rows[i], keyCols);
                    if (MKWhereClause.Length > 0)
                    {
                        int count = Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(" + tblVer.GetTableName() + "_ID) FROM " + tblVer.GetTableName() + " WHERE " + MKWhereClause.ToString(), null, _trx));
                        if (count > 0)
                        {
                            continue;
                        }
                    }

                    // create PO object of source table (Master table)
                    PO sPO = baseTbl.GetPO(GetCtx(), dsRecs.Tables[0].Rows[i], _trx);
                    // create PO object of destination table (Version table)
                    PO dPO = tblVer.GetPO(GetCtx(), 0, _trx);
                    sPO.CopyTo(dPO);
                    dPO.SetAD_Client_ID(sPO.GetAD_Client_ID());
                    dPO.SetAD_Org_ID(sPO.GetAD_Org_ID());
                    dPO.Set_Value("RecordVersion", "1");
                    dPO.Set_ValueNoCheck("VersionValidFrom", sPO.Get_Value("Created"));
                    dPO.Set_ValueNoCheck("IsVersionApproved", true);
                    dPO.Set_ValueNoCheck("Processed", true);
                    dPO.Set_ValueNoCheck("ProcessedVersion", true);
                    for (int j = 0; j < keyCols.Length; j++)
                    {
                        dPO.Set_ValueNoCheck(keyCols[j], sPO.Get_Value(keyCols[j]));
                    }
                    dPO.Set_Value("Export_ID", null);
                    if (!dPO.Save())
                    {
                        ValueNamePair vnp   = VLogger.RetrieveError();
                        string        error = "";
                        if (vnp != null)
                        {
                            error = vnp.GetName();
                            if (error == "" && vnp.GetValue() != null)
                            {
                                error = vnp.GetValue();
                            }
                        }
                        if (error == "")
                        {
                            error = "Error in saving data in Version table";
                        }
                        return(retMsg);
                    }
                }
            }

            return(retMsg);
        }
Example #6
0
        }   //  sendAlert

        private int sendAlertToResponsible(MWFResponsible responsible, List <int> list, MWFProcess process, String subject, String message, FileInfo pdf)
        {
            int counter = 0;

            if (responsible.IsInvoker())
            {
                ;
            }
            //	Human
            else if (X_AD_WF_Responsible.RESPONSIBLETYPE_Human.Equals(responsible.GetResponsibleType()) &&
                     responsible.GetAD_User_ID() != 0 &&
                     !list.Contains(responsible.GetAD_User_ID()))
            {
                if (m_client.SendEMail(responsible.GetAD_User_ID(), subject, message, pdf))
                {
                    counter++;
                }
                list.Add(responsible.GetAD_User_ID());
            }
            //	Org of the Document
            else if (X_AD_WF_Responsible.RESPONSIBLETYPE_Organization.Equals(responsible.GetResponsibleType()))
            {
                PO document = process.GetPO();
                if (document != null)
                {
                    MOrgInfo org = MOrgInfo.Get(GetCtx(), document.GetAD_Org_ID(), null);
                    if (org.GetSupervisor_ID() != 0 &&
                        !list.Contains(org.GetSupervisor_ID()))
                    {
                        if (m_client.SendEMail(org.GetSupervisor_ID(), subject, message, pdf))
                        {
                            counter++;
                        }
                        list.Add(org.GetSupervisor_ID());
                    }
                }
            }
            //	Role
            else if (X_AD_WF_Responsible.RESPONSIBLETYPE_Role.Equals(responsible.GetResponsibleType()) &&
                     responsible.GetAD_Role_ID() != 0)
            {
                MUserRoles[] userRoles = MUserRoles.GetOfRole(GetCtx(), responsible.GetAD_Role_ID());
                for (int i = 0; i < userRoles.Length; i++)
                {
                    MUserRoles roles = userRoles[i];
                    if (!roles.IsActive())
                    {
                        continue;
                    }
                    int AD_User_ID = roles.GetAD_User_ID();
                    if (!list.Contains(AD_User_ID))
                    {
                        if (m_client.SendEMail(AD_User_ID, subject, message, pdf))
                        {
                            counter++;
                        }
                        list.Add(AD_User_ID);
                    }
                }
            }
            return(counter);
        }       //	sendAlertToResponsible
Example #7
0
 /// <summary>
 /// Get AD_Org_ID
 /// </summary>
 /// <returns>org</returns>
 public int GetAD_Org_ID()
 {
     return(_po.GetAD_Org_ID());
 }
        /// <summary>
        /// Function to update data in Master Table based on the versions saved
        /// </summary>
        /// <param name="dsRec">All Records which need to be updated</param>
        /// <param name="TableName">Version Table Name</param>
        /// <param name="VerTableID">Version Table ID</param>
        /// <returns>True/False based on the Updation of data in parent table</returns>
        private bool UpdateRecords(DataSet dsRec, string TableName, int VerTableID)
        {
            // Get Master table name from Version table
            string BaseTblName = TableName;

            if (TableName.EndsWith("_Ver"))
            {
                BaseTblName = BaseTblName.Substring(0, TableName.Length - 4);
            }
            // Master Table ID from Table name
            int BaseTableID = Util.GetValueOfInt(DB.ExecuteScalar("SELECT AD_Table_ID FROM AD_Table WHERE TableName = '" + BaseTblName + "'"));

            // Get Column information of Master Table
            DataSet dsDBColNames = DB.ExecuteDataset("SELECT ColumnName, AD_Reference_ID, IsUpdateable, IsAlwaysUpdateable FROM AD_Column WHERE AD_Table_ID = " + BaseTableID);

            if (dsDBColNames != null && dsDBColNames.Tables[0].Rows.Count > 0)
            {
                log.Info("Processing for " + TableName + " :: ");

                StringBuilder sqlSB           = new StringBuilder("");
                bool          recordProcessed = false;
                // create object of Master Table
                MTable tbl = new MTable(GetCtx(), BaseTableID, null);
                // create object of Version table
                MTable tblVer = new MTable(GetCtx(), VerTableID, null);

                // check whether master table has Single key
                bool isSingleKey = tbl.IsSingleKey();

                // List of records which were not processed by process in case of any error
                List <string> keys  = new List <string>();
                StringBuilder sbKey = new StringBuilder("");
                // Loop through the records which need to be updated on Master Table
                for (int i = 0; i < dsRec.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = dsRec.Tables[0].Rows[i];
                    sbKey.Clear();
                    PO poDest   = null;
                    PO poSource = tblVer.GetPO(GetCtx(), dr, null);
                    // if table has single key
                    if (isSingleKey)
                    {
                        // Create object of PO Class from TableName and Record ID
                        poDest = MTable.GetPO(GetCtx(), BaseTblName, Util.GetValueOfInt(dr[BaseTblName + "_ID"]), null);
                        sbKey.Append(Util.GetValueOfInt(dr[BaseTblName + "_ID"]));
                    }
                    else
                    {
                        // Create object of PO Class from combination of key columns
                        string[]      keyCols   = tbl.GetKeyColumns();
                        StringBuilder whereCond = new StringBuilder("");
                        for (int w = 0; w < keyCols.Length; w++)
                        {
                            if (w == 0)
                            {
                                if (keyCols[w] != null)
                                {
                                    whereCond.Append(keyCols[w] + " = " + poSource.Get_Value(keyCols[w]));
                                }
                                else
                                {
                                    whereCond.Append(" NVL(" + keyCols[w] + ",0) = 0");
                                }
                            }
                            else
                            {
                                if (keyCols[w] != null)
                                {
                                    whereCond.Append(" AND " + keyCols[w] + " = " + poSource.Get_Value(keyCols[w]));
                                }
                                else
                                {
                                    whereCond.Append(" AND NVL(" + keyCols[w] + ",0) = 0");
                                }
                            }
                        }
                        poDest = tbl.GetPO(GetCtx(), whereCond.ToString(), null);
                        sbKey.Append(whereCond);
                    }

                    // check if there is any error in processing record, then continue and do not process next versions
                    if (keys.Contains(sbKey.ToString()))
                    {
                        continue;
                    }

                    // Check whether Master Table contains "Processing" Column
                    if (poDest.Get_ColumnIndex("Processing") >= 0)
                    {
                        // if "Processing" column found then return, do not update in Master Table,
                        // because transaction might be in approval process
                        if (Util.GetValueOfString(poSource.Get_Value("Processing")) == "Y")
                        {
                            keys.Add(sbKey.ToString());
                            continue;
                        }
                    }

                    // Check whether Master Table contains "Processed" Column
                    if (poDest.Get_ColumnIndex("Processed") >= 0)
                    {
                        if (Util.GetValueOfString(poSource.Get_Value("Processed")) == "Y")
                        {
                            recordProcessed = true;
                        }
                    }

                    // set client and Organization ID from Version table to Master
                    // as copy PO set these ID's as 0
                    poDest.SetAD_Client_ID(poSource.GetAD_Client_ID());
                    poDest.SetAD_Org_ID(poSource.GetAD_Org_ID());

                    StringBuilder sbColName = new StringBuilder("");
                    // Loop through all the columns in Master Table
                    for (int j = 0; j < dsDBColNames.Tables[0].Rows.Count; j++)
                    {
                        sbColName.Clear();
                        // Get Name of Column
                        sbColName.Append(dsDBColNames.Tables[0].Rows[j]["ColumnName"]);

                        // check if column exist in Default columns list, in that case do not update and continue to next column
                        if (defcolNames.Contains(sbColName.ToString()))
                        {
                            continue;
                        }
                        // No need to update Primary key column, continue to next column
                        if (sbColName.ToString().Equals(BaseTblName + "_ID"))
                        {
                            continue;
                        }
                        // if column is of "Yes-No" type i.e. Reference ID is 20 (Fixed) then set True/False
                        if (Util.GetValueOfInt(dsDBColNames.Tables[0].Rows[j]["AD_Reference_ID"]) == 20)
                        {
                            Object val = false;
                            if (poSource.Get_Value(sbColName.ToString()) != null)
                            {
                                val = poSource.Get_Value(sbColName.ToString());
                            }
                            poDest.Set_Value(sbColName.ToString(), val);
                        }
                        else
                        {
                            poDest.Set_ValueNoCheck(sbColName.ToString(), poSource.Get_Value(sbColName.ToString()));
                        }

                        // Check if Master record is Processed and Always Updatable is false then check whether any value updated in such column
                        // if value updated then return false, can't change data in Processed record if it's not Always Updatable
                        if (recordProcessed && Util.GetValueOfString(dsDBColNames.Tables[0].Rows[j]["IsAlwaysUpdateable"]) == "N")
                        {
                            bool upd = poDest.Is_ValueChanged(sbColName.ToString());
                            if (upd)
                            {
                                msg.Append("Can't update  " + sbColName.ToString() + " in " + TableName);
                                log.SaveError("ERROR", "Can not update processed record for column ==>> " + sbColName.ToString());
                                // Add record to the list of unprocessed records
                                keys.Add(sbKey.ToString());
                                continue;
                            }
                        }
                    }

                    // Save Master Record
                    if (!poDest.Save())
                    {
                        // Add record to the list of unprocessed records
                        keys.Add(sbKey.ToString());
                        // Check for Errors
                        ValueNamePair vnp   = VLogger.RetrieveError();
                        string        error = "";
                        if (vnp != null)
                        {
                            error = vnp.GetName();
                            if (error == "" && vnp.GetValue() != null)
                            {
                                error = vnp.GetValue();
                            }
                        }
                        if (error == "")
                        {
                            error = "Error in updating Version";
                        }

                        msg.Append("Save error in " + TableName + " ==>> " + error);
                        log.SaveError("ERROR", error);

                        sqlSB.Clear();

                        sqlSB.Append("UPDATE " + TableName + " SET VersionLog = '" + error + "' WHERE " + TableName + "_ID = " + dr[TableName + "_ID"]);
                        int count = DB.ExecuteQuery(sqlSB.ToString(), null, null);

                        continue;
                    }
                    else
                    {
                        // Update Version table, Set "ProcessedVersion" to "Y", so that it don't consider when process runs next time
                        sqlSB.Clear();
                        // Update against record id in case of Single key, and update Key column in version table as well in case of new record
                        if (isSingleKey)
                        {
                            sqlSB.Append("UPDATE " + TableName + " SET ProcessedVersion = 'Y', " + BaseTblName + "_ID  = " + poDest.Get_ID() + " WHERE " + TableName + "_ID = " + dr[TableName + "_ID"]);
                        }
                        // else
                        else
                        {
                            sqlSB.Append("UPDATE " + TableName + " SET ProcessedVersion = 'Y' WHERE " + TableName + "_ID = " + dr[TableName + "_ID"]);
                        }

                        int count = DB.ExecuteQuery(sqlSB.ToString(), null, null);
                        if (count <= 0)
                        {
                            log.Info(TableName + " not updated ==>> " + sqlSB.ToString());
                        }
                    }
                }
            }
            return(true);
        }