예제 #1
0
        }   //  setParameterFromDB

        public static void SetLogFromDB(ProcessInfo pi)
        {
            String sql = "SELECT Log_ID, P_ID, P_Date, P_Number, P_Msg "
                         + "FROM AD_PInstance_Log "
                         + "WHERE AD_PInstance_ID=@instanceid "
                         + "ORDER BY Log_ID";
            IDataReader dr = null;

            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@instanceid", pi.GetAD_PInstance_ID());
                dr       = DataBase.DB.ExecuteReader(sql, param);

                int?ival;
                while (dr.Read())
                {
                    if (dr[1].ToString() == "")
                    {
                        ival = null;
                    }
                    else
                    {
                        ival = (int?)Utility.Util.GetValueOfInt(dr[1]);
                    }
                    pi.AddLog(Utility.Util.GetValueOfInt(dr[0]), ival, Utility.Util.GetValueOfDateTime(dr[2]), Utility.Util.GetValueOfDecimal(dr[3]), dr[4].ToString());
                }
                dr.Close();
            }
            catch (Exception e)
            {
                if (dr != null)
                {
                    dr.Close();
                }
                _log.Log(Level.SEVERE, "setLogFromDB", e);
            }
        }
예제 #2
0
        public Dictionary <string, object> Process(ProcessInfo pi, Ctx ctx, out byte[] report, out string reportFilePath)
        {
            reportFilePath = null;

            _ctx   = ctx;
            _pi    = pi;
            report = null;

            MPInstance instance = null;

            if (_pi.GetAD_PInstance_ID() < 1)
            {
                try
                {
                    instance = new MPInstance(ctx, _pi.GetAD_Process_ID(), _pi.GetRecord_ID());
                }
                catch (Exception e)
                {
                    _pi.SetSummary(e.Message);
                    _pi.SetError(true);
                    return(_pi.ToList());
                }

                if (!instance.Save())
                {
                    _pi.SetSummary(Msg.GetMsg(ctx, "ProcessNoInstance", true));
                    _pi.SetError(true);
                    return(_pi.ToList());
                }

                _pi.SetAD_PInstance_ID(instance.Get_ID());
            }



            String procedureName      = "";
            int    AD_ReportView_ID   = 0;
            int    AD_ReportFormat_ID = 0;
            int    AD_Workflow_ID     = 0;
            bool   IsReport           = false;

            bool IsDirectPrint = false;

            bool IsCrystalReport = false;

            String sql = "SELECT p.Name, p.procedureName,p.Classname, p.AD_Process_ID,"                                        //	1..4
                         + " p.IsReport,p.IsDirectPrint,p.AD_ReportView_ID,p.AD_Workflow_ID,"                                  //	5..8
                         + " CASE WHEN COALESCE(p.Statistic_Count,0)=0 THEN 0 ELSE p.Statistic_Seconds/p.Statistic_Count END," //9
                         + " p.IsServerProcess, "                                                                              //10
                         + " p.IsCrystalReport, "                                                                              // crystal  11...12
                         + " p.AD_ReportFormat_ID "                                                                            //12
                         + " FROM AD_Process p"
                         + " INNER JOIN AD_PInstance i ON (p.AD_Process_ID=i.AD_Process_ID) "
                         + " WHERE p.IsActive='Y'"
                         + " AND i.AD_PInstance_ID=@pinstanceid";

            IDataReader dr = null;

            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@pinstanceid", _pi.GetAD_PInstance_ID());
                dr       = SqlExec.ExecuteQuery.ExecuteReader(sql, param);
                while (dr.Read())
                {
                    _pi.SetTitle(dr[0].ToString());
                    //if (m_waiting != null)
                    //    m_waiting.setTitle(_pi.getTitle());
                    procedureName = dr[1].ToString();

                    _pi.SetClassName(dr[2].ToString());

                    _pi.SetAD_Process_ID(Utility.Util.GetValueOfInt(dr[3].ToString()));
                    //	Report
                    if ("Y".Equals(dr[4].ToString()))
                    {
                        IsReport           = true;
                        IsCrystalReport    = "Y".Equals(dr[10].ToString());
                        AD_ReportFormat_ID = dr[11].ToString() == "" ? 0 : Utility.Util.GetValueOfInt(dr[11].ToString());
                        //later
                    }
                    AD_ReportView_ID = dr[6].ToString() == "" ? 0 : Utility.Util.GetValueOfInt(dr[6].ToString());
                    AD_Workflow_ID   = dr[7].ToString() == "" ? 0 : Utility.Util.GetValueOfInt(dr[7].ToString());
                    //
                    //_IsServerProcess = "Y".Equals(dr[9].ToString());
                }
                dr.Close();
            }
            catch (Exception ex)
            {
                if (dr != null)
                {
                    dr.Close();
                }
                _pi.SetSummary(Msg.GetMsg(ctx, "ProcessNoProcedure") + " " + ex.Message, true);
                Unlock();
            }

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

            if (AD_Workflow_ID > 0)
            {
                StartWorkflow(AD_Workflow_ID);

                //Updated by raghu to open reports from work flow

                byte[] repByt = null;
                re = ReportCtl.Report;
                if (re != null)
                {
                    int reportTable_ID = 0;
                    if (re is IReportView)
                    {
                        IReportView irv = re as IReportView;
                        reportTable_ID = irv.GetPrintFormat().GetAD_Table_ID();
                        irv.GetView();
                        _pi.Set_AD_PrintFormat_Table_ID(irv.GetPrintFormat().GetAD_Table_ID());
                    }
                    _pi.SetSummary("Report", re != null);
                    Unlock();
                    if (re != null)
                    {
                        reportFilePath = re.GetReportFilePath(true, out repByt);
                    }
                }
                else
                {
                    repByt = null;
                }
                report = repByt;
                return(_pi.ToList());
            }

            if (_pi.GetClassName() != null)
            {
                if (!StartProcess())
                {
                    report = null;
                    return(_pi.ToList());
                }

                if (!IsReport && procedureName.Length == 0)
                {
                    report = null;
                    return(_pi.ToList());
                }
            }
            report = null;
            if (IsReport)
            {
                if (procedureName.Length > 0)
                {
                    if (!StartDBProcess(procedureName))
                    {
                    }
                }


                if (AD_ReportFormat_ID > 0)             // For Report Formats
                {
                    _pi.SetIsReportFormat(true);
                    int totalRecords = 0;
                    re = VAdvantage.ReportFormat.ReportFormatEngine.Get(_ctx, _pi, out totalRecords, IsArabicReportFromOutside);
                    Unlock();
                    _pi.SetSummary("Report", re != null);
                    _pi.SetTotalRecords(totalRecords);
                    if (re != null)
                    {
                        //isRCReport = true;
                        if (GetIsPrintCsv())
                        {
                            string s = "";
                            reportFilePath = re.GetCsvReportFilePath(s);
                        }
                        else
                        {
                            report         = re.GetReportBytes();
                            reportFilePath = re.GetReportFilePath(true, out report);
                        }
                        ReportString = re.GetReportString();
                    }
                }


                else if (!IsCrystalReport)
                {
                    //start report code
                    //	Start Report	-----------------------------------------------
                    re = ReportCtl.Start(_ctx, _pi, IsDirectPrint);
                    ReportEngine_N _rep = (ReportEngine_N)re;
                    //null check Implemented by raghu 22-May-2015
                    if (_rep != null)
                    {
                        reportTable_ID = _rep.GetPrintFormat().GetAD_Table_ID();
                        _rep.GetView();

                        _pi.Set_AD_PrintFormat_Table_ID(_rep.GetPrintFormat().GetAD_Table_ID());
                        _pi.Set_AD_PrintFormat_ID(_rep.GetPrintFormat().GetAD_PrintFormat_ID());
                        _pi.SetSummary("Report", re != null);
                        Unlock();
                        if (GetIsPrintFormat() && re != null && !GetIsPrintCsv())
                        {
                            reportFilePath = re.GetReportFilePath(true, out report);
                        }
                        else if (GetIsPrintCsv() && re != null)
                        {
                            report = _rep.CreateCSV(_ctx);
                            string filePath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "TempDownload";

                            if (!Directory.Exists(filePath))
                            {
                                Directory.CreateDirectory(filePath);
                            }

                            filePath = filePath + "\\temp_" + CommonFunctions.CurrentTimeMillis() + ".csv";
                            File.WriteAllBytes(filePath, report);
                            reportFilePath = filePath.Substring(filePath.IndexOf("TempDownload"));
                        }
                        else
                        {
                            rptHtml = _rep.GetRptHtml().ToString();
                        }
                        report = _rep.CreatePDF();
                    }
                }
                else
                {
                    _pi.SetIsCrystal(true);
                    string errorMsg        = null;
                    CrystalReportEngine en = null;
                    try
                    {
                        en = new CrystalReportEngine(_ctx, _pi);

                        reportFilePath = en.GetReportFilePath(true, out report);// .GenerateCrystalReport();
                    }
                    catch (Exception err)
                    {
                        errorMsg = err.Message;
                    }

                    _pi.SetSummary(errorMsg ?? "Done", errorMsg != null);
                }
            }
            else
            {
                if (!StartDBProcess(procedureName))
                {
                    _pi.SetSummary("procedure ERROR");
                    return(_pi.ToList());
                }
                ProcessInfoUtil.SetSummaryFromDB(_pi);
            }

            return(_pi.ToList());
        }
예제 #3
0
        public void Run()
        {
            log.Fine("AD_PInstance_ID=" + _pi.GetAD_PInstance_ID() + ", Record_ID=" + _pi.GetRecord_ID());
            Lock();

            //	Get Process Information: Name, Procedure Name, ClassName, IsReport, IsDirectPrint
            String procedureName    = "";
            int    AD_ReportView_ID = 0;
            int    AD_Workflow_ID   = 0;
            bool   IsReport         = false;
            bool   IsDirectPrint    = false;
            //
            String sql = "SELECT p.Name, p.procedureName,p.Classname, p.AD_Process_ID,"         //	1..4
                         + " p.IsReport,p.IsDirectPrint,p.AD_ReportView_ID,p.AD_Workflow_ID,"   //	5..8
                         + " CASE WHEN COALESCE(p.Statistic_Count,0)=0 THEN 0 ELSE p.Statistic_Seconds/p.Statistic_Count END,"
                         + " p.IsServerProcess "
                         + "FROM AD_Process p"
                         + " INNER JOIN AD_PInstance i ON (p.AD_Process_ID=i.AD_Process_ID) "
                         + "WHERE p.IsActive='Y'"
                         + " AND i.AD_PInstance_ID=@pinstanceid";

            if (!Utility.Env.IsBaseLanguage(_ctx, "AD_Process"))                            //   GlobalVariable.IsBaseLanguage())
            {
                sql = "SELECT t.Name, p.procedureName,p.Classname, p.AD_Process_ID,"        //	1..4
                      + " p.IsReport, p.IsDirectPrint,p.AD_ReportView_ID,p.AD_Workflow_ID," //	5..8
                      + " CASE WHEN COALESCE(p.Statistic_Count,0)=0 THEN 0 ELSE p.Statistic_Seconds/p.Statistic_Count END CASE,"
                      + " p.IsServerProcess "
                      + "FROM AD_Process p"
                      + " INNER JOIN AD_PInstance i ON (p.AD_Process_ID=i.AD_Process_ID) "
                      + " INNER JOIN AD_Process_Trl t ON (p.AD_Process_ID=t.AD_Process_ID"
                      + " AND t.AD_Language='" + Utility.Env.GetAD_Language(_ctx) + "') "
                      + "WHERE p.IsActive='Y'"
                      + " AND i.AD_PInstance_ID=@pinstanceid";
            }
            //
            IDataReader dr = null;

            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@pinstanceid", _pi.GetAD_PInstance_ID());
                dr       = SqlExec.ExecuteQuery.ExecuteReader(sql, param);
                while (dr.Read())
                {
                    _pi.SetTitle(dr[0].ToString());
                    //if (m_waiting != null)
                    //    m_waiting.setTitle(_pi.getTitle());
                    procedureName = dr[1].ToString();

                    _pi.SetClassName(dr[2].ToString());

                    _pi.SetAD_Process_ID(Utility.Util.GetValueOfInt(dr[3].ToString()));
                    //	Report
                    if ("Y".Equals(dr[4].ToString()))
                    {
                        IsReport = true;
                        if ("Y".Equals(dr[5].ToString()) && !Ini.IsPropertyBool(Ini.P_PRINTPREVIEW))
                        {
                            IsDirectPrint = true;
                        }
                    }
                    AD_ReportView_ID = dr[6].ToString() == "" ? 0 : Utility.Util.GetValueOfInt(dr[6].ToString());
                    AD_Workflow_ID   = dr[7].ToString() == "" ? 0 : Utility.Util.GetValueOfInt(dr[7].ToString());
                    //
                    _IsServerProcess = "Y".Equals(dr[9].ToString());
                }
                dr.Close();
            }
            catch (SqlException ex)
            {
                if (dr != null)
                {
                    dr.Close();
                }
                _pi.SetSummary(Msg.GetMsg(_ctx, "ProcessNoProcedure") + " " + ex.Message, true);
                Unlock();
                log.Log(Level.SEVERE, "run", ex);
                return;
            }
            finally
            {
                if (dr != null)
                {
                    dr.Close();
                }
            }

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

            if (AD_Workflow_ID > 0)
            {
                StartWorkflow(AD_Workflow_ID);
                re = ReportCtl.Report;

                Unlock();
                return;
            }

            if (_pi.GetClassName() != null)
            {
                if (!StartProcess())
                {
                    Unlock();
                    return;
                }

                if (!IsReport && procedureName.Length == 0)
                {
                    Unlock();
                    return;
                }

                if (IsReport && AD_ReportView_ID == 0)
                {
                    Unlock();
                    return;
                }
            }

            //  If not a report, we need a prodedure name
            if (!IsReport && procedureName.Length == 0)
            {
                _pi.SetSummary(Msg.GetMsg(_ctx, "ProcessNoProcedure", true));
                Unlock();
                return;
            }

            if (IsReport)
            {
                if (procedureName.Length > 0)
                {
                    if (!StartDBProcess(procedureName))
                    {
                        Unlock();
                        return;
                    }
                }

                //start report code
                //	Start Report	-----------------------------------------------
                re = ReportCtl.Start(_ctx, _pi, IsDirectPrint);

                _pi.SetSummary("Report", re != null);
                Unlock();
                if (re != null && IsDirectPrint)
                {
                    re = null;
                    //ve =  new Viewer(re);
                    //new ReportDialog(re);
                }
            }
            else
            {
                if (!StartDBProcess(procedureName))
                {
                    Unlock();
                    return;
                }

                ProcessInfoUtil.SetSummaryFromDB(_pi);
                Unlock();
            }
        }
 protected int GetAD_PInstance_ID()
 {
     return(_pi.GetAD_PInstance_ID());
 }
예제 #5
0
        /// <summary>
        /// Sets the summary from database
        /// </summary>
        /// <param name="pi">ProcessInfo object</param>
        public static void SetSummaryFromDB(ProcessInfo pi)
        {
            int sleepTime = 2000;   //	2 secomds
            int noRetry   = 5;      //  10 seconds total
            //
            String sql = "SELECT Result, ErrorMsg FROM AD_PInstance "
                         + "WHERE AD_PInstance_ID=@instanceid"
                         + " AND Result IS NOT NULL";
            IDataReader dr = null;

            try
            {
                SqlParameter[] param = new SqlParameter[1];
                for (int noTry = 0; noTry < noRetry; noTry++)
                {
                    param[0] = new SqlParameter("@instanceid", pi.GetAD_PInstance_ID());
                    dr       = DataBase.DB.ExecuteReader(sql, param, null);
                    while (dr.Read())
                    {
                        //	we have a result
                        int i = Utility.Util.GetValueOfInt(dr[0].ToString());
                        if (i == 1)
                        {
                            pi.SetSummary(Msg.GetMsg(Env.GetContext(), "Success", true));
                        }
                        else
                        {
                            pi.SetSummary(Msg.GetMsg(Env.GetContext(), "Failure", true));
                        }

                        String Message = dr[1].ToString();
                        dr.Close();
                        //
                        if (Message != null)
                        {
                            if (Message != "")
                            {
                                pi.AddSummary("  (" + Utility.Msg.ParseTranslation(Utility.Env.GetContext(), Message) + ")");
                            }
                        }
                        return;
                    }

                    dr.Close();
                    //	sleep
                    try
                    {
                        Thread.Sleep(sleepTime);
                    }
                    catch (Exception ie)
                    {
                        if (dr != null)
                        {
                            dr.Close();
                        }
                        _log.Log(Level.SEVERE, "Sleep Thread", ie);
                    }
                }
            }
            catch (SqlException e)
            {
                if (dr != null)
                {
                    dr.Close();
                }
                _log.Log(Level.SEVERE, sql, e);
                pi.SetSummary(e.Message, true);
                return;
            }
            pi.SetSummary(Msg.GetMsg(Env.GetContext(), "Timeout", true));
        }       //	setSummaryFromDB
예제 #6
0
        public static void SaveLogToDB(ProcessInfo pi)
        {
            Context p_ctx = Env.GetContext();

            //System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
            //System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
            System.Threading.Thread.CurrentThread.CurrentCulture   = Env.GetLanguage(p_ctx).GetCulture(Env.GetBaseAD_Language());
            System.Threading.Thread.CurrentThread.CurrentUICulture = Env.GetLanguage(p_ctx).GetCulture(Env.GetBaseAD_Language());
            ProcessInfoLog[] logs = pi.GetLogs();
            if (logs == null || logs.Length == 0)
            {
                _log.Fine("No Log");
                return;
            }
            if (pi.GetAD_PInstance_ID() == 0)
            {
                _log.Log(Level.WARNING, "AD_PInstance_ID==0");
                return;
            }
            for (int i = 0; i < logs.Length; i++)
            {
                StringBuilder sql = new StringBuilder("INSERT INTO AD_PInstance_Log "
                                                      + "(AD_PInstance_ID, Log_ID, P_Date, P_ID, P_Number, P_Msg)"
                                                      + " VALUES (");
                sql.Append(pi.GetAD_PInstance_ID()).Append(",")
                .Append(logs[i].GetLog_ID()).Append(",");
                if (logs[i].GetP_Date() == null)
                {
                    sql.Append("NULL");
                }
                else
                {
                    sql.Append(GlobalVariable.TO_DATE(logs[i].GetP_Date(), false));
                }
                sql.Append(",");
                if (logs[i].GetP_ID() == 0)
                {
                    sql.Append("NULL");
                }
                else
                {
                    sql.Append(logs[i].GetP_ID());
                }
                sql.Append(",");
                if (logs[i].GetP_Number() == null)
                {
                    sql.Append("NULL");
                }
                else
                {
                    sql.Append(logs[i].GetP_Number());
                }
                sql.Append(",");
                if (logs[i].GetP_Msg() == null)
                {
                    sql.Append("NULL)");
                }
                else
                {
                    sql.Append(GlobalVariable.TO_STRING(logs[i].GetP_Msg(), 2000)).Append(")");
                }

                SqlExec.ExecuteQuery.ExecuteNonQuery(sql.ToString());
            }
            //System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-DE");
            //System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de-DE");
            System.Threading.Thread.CurrentThread.CurrentCulture   = Utility.Env.GetLanguage(Utility.Env.GetContext()).GetCulture(Env.GetLoginLanguage(p_ctx).GetAD_Language());
            System.Threading.Thread.CurrentThread.CurrentUICulture = Utility.Env.GetLanguage(Utility.Env.GetContext()).GetCulture(Env.GetLoginLanguage(p_ctx).GetAD_Language());
            pi.SetLogList(null);        //	otherwise log entries are twice
        }
예제 #7
0
        }       //	setSummaryFromDB

        /// <summary>
        /// Set param from db
        /// </summary>
        /// <param name="pi">ProcessInfo object</param>
        public static void SetParameterFromDB(ProcessInfo pi)
        {
            List <ProcessInfoParameter> list = new List <ProcessInfoParameter>();
            String sql = "SELECT p.ParameterName,"                                //  1
                         + " p.P_String,p.P_String_To, p.P_Number,p.P_Number_To," //  2/3 4/5
                         + " p.P_Date,p.P_Date_To, p.Info,p.Info_To, "            //  6/7 8/9
                         + " i.AD_Client_ID, i.AD_Org_ID, i.AD_User_ID "          //	10..12
                         + "FROM AD_PInstance_Para p"
                         + " INNER JOIN AD_PInstance i ON (p.AD_PInstance_ID=i.AD_PInstance_ID) "
                         + "WHERE p.AD_PInstance_ID=@pinstanceid "
                         + "ORDER BY p.SeqNo";
            IDataReader dr = null;

            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@pinstanceid", pi.GetAD_PInstance_ID());
                //param[0] = new SqlParameter("@pinstanceid", 1000296);

                dr = DataBase.DB.ExecuteReader(sql, param, null);
                while (dr.Read())
                {
                    String ParameterName = dr[0].ToString();
                    //	String
                    Object Parameter    = dr[1].ToString();
                    Object Parameter_To = dr[2].ToString();

                    Parameter    = Parameter.ToString() == "" ? null  : Parameter;
                    Parameter_To = Parameter_To.ToString() == "" ? null : Parameter_To;

                    //	Big Decimal
                    if ((Parameter == null && Parameter_To == null) || (Parameter.Equals("") && Parameter_To.Equals("")))
                    {
                        if (!(string.IsNullOrEmpty(dr[3].ToString())))
                        {
                            Parameter = Utility.Util.GetValueOfDecimal(dr[3]);
                        }
                        if (!(string.IsNullOrEmpty(dr[3].ToString())))
                        {
                            Parameter_To = Utility.Util.GetValueOfDecimal(dr[4]);
                        }
                    }
                    //	Timestamp
                    if ((Parameter == null && Parameter_To == null) || (Parameter.Equals("") && Parameter_To.Equals("")))
                    {
                        if (!(dr[5] == DBNull.Value))
                        {
                            Parameter = DateTime.Parse(dr[5].ToString());
                        }
                        if (!(dr[6] == DBNull.Value))
                        {
                            Parameter_To = DateTime.Parse(dr[6].ToString());
                        }
                    }
                    //	Info
                    String Info    = dr[7].ToString();
                    String Info_To = dr[8].ToString();
                    //
                    list.Add(new ProcessInfoParameter(ParameterName, Parameter, Parameter_To, Info, Info_To));
                    //
                    if (pi.GetAD_Client_ID() == null)
                    {
                        pi.SetAD_Client_ID(int.Parse(dr[9].ToString()));
                    }
                    if (pi.GetAD_User_ID() == null)
                    {
                        pi.SetAD_User_ID(int.Parse(dr[11].ToString()));
                    }
                }
                dr.Close();
            }
            catch (Exception e)
            {
                if (dr != null)
                {
                    dr.Close();
                }
                _log.Severe(e.ToString());
            }
            finally
            {
                if (dr != null)
                {
                    dr.Close();
                }
            }
            //
            ProcessInfoParameter[] pars = new ProcessInfoParameter[list.Count()];
            pars = list.ToArray();
            pi.SetParameter(pars);
        }   //  setParameterFromDB
        }       //	setSummaryFromDB

        /// <summary>
        /// Set param from db
        /// </summary>
        /// <param name="pi">ProcessInfo object</param>
        public static void SetParameterFromDB(ProcessInfo pi, Ctx ctx)
        {
            List <ProcessInfoParameter> list = new List <ProcessInfoParameter>();

            String sql = @"SELECT ip.ParameterName,
                                      ip.P_String,
                                      ip.P_String_To,
                                      ip.P_Number,
                                      ip.P_Number_To,
                                      ip.P_Date,
                                      ip.P_Date_To,
                                      ip.Info,
                                      ip.Info_To,
                                      i.AD_Client_ID,
                                      i.AD_Org_ID,
                                      i.AD_User_ID,
                                      NVL(PP.LOADRECURSIVEDATA,'N') as LOADRECURSIVEDATA,
                                     nvl(pp.ShowChildOfSelected,'N') as ShowChildOfSelected,nvl(pp.AD_Reference_ID,0) as AD_Reference_ID
                                    FROM AD_PInstance_Para ip JOIN AD_PInstance i ON (ip.AD_PINstance_ID=i.AD_PINstance_ID)
                                   Left Outer JOIN AD_Process_Para pp
                                        ON (pp.AD_Process_Para_ID=ip.AD_Process_Para_ID
                                        AND pp.AD_Process_ID=i.AD_Process_ID)
                                    WHERE ip.AD_PInstance_ID =@pinstanceid";

            IDataReader dr = null;

            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@pinstanceid", pi.GetAD_PInstance_ID());
                //param[0] = new SqlParameter("@pinstanceid", 1000296);

                dr = DataBase.DB.ExecuteReader(sql, param, null);
                while (dr.Read())
                {
                    String ParameterName = dr[0].ToString();
                    //	String
                    Object Parameter    = dr[1].ToString();
                    Object Parameter_To = dr[2].ToString();

                    Parameter    = Parameter.ToString() == "" ? null : Parameter;
                    Parameter_To = Parameter_To.ToString() == "" ? null : Parameter_To;

                    //int displayType = 0;
                    //if (dr[16] != null && dr[16] != DBNull.Value)
                    //{
                    //    displayType = Util.GetValueOfInt(dr[16]);
                    //}

                    //	Big Decimal
                    if ((Parameter == null && Parameter_To == null) || (Parameter.Equals("") && Parameter_To.Equals("")))
                    {
                        if (!(string.IsNullOrEmpty(dr[3].ToString())))
                        {
                            Parameter = Utility.Util.GetValueOfDecimal(dr[3]);
                        }
                        if (!(string.IsNullOrEmpty(dr[3].ToString())))
                        {
                            Parameter_To = Utility.Util.GetValueOfDecimal(dr[4]);
                        }
                    }
                    //	Timestamp
                    if ((Parameter == null && Parameter_To == null) || (Parameter.Equals("") && Parameter_To.Equals("")))
                    {
                        //if (displayType == 0)
                        //{
                        //    if (!(dr[5] == DBNull.Value))
                        //    {
                        //        Parameter = DateTime.Parse(dr[5].ToString());
                        //    }
                        //    if (!(dr[6] == DBNull.Value))
                        //    {
                        //        Parameter_To = DateTime.Parse(dr[6].ToString());
                        //    }
                        //}
                        //else
                        //{
                        //if (displayType == DisplayType.Date)
                        //{
                        if (dr[5] != null && dr[5] != DBNull.Value)
                        {
                            Parameter = DateTime.Parse(dr[5].ToString());
                        }
                        if (dr[6] != null && dr[6] != DBNull.Value)
                        {
                            Parameter_To = DateTime.Parse(dr[6].ToString());
                        }
                        //}
                        //else if (displayType == DisplayType.DateTime)
                        //{
                        //if (dr[12] != null && dr[12] != DBNull.Value)
                        //{
                        //    Parameter = DateTime.Parse(dr[12].ToString());
                        //}
                        //if (dr[13] != null && dr[13] != DBNull.Value)
                        //{
                        //    Parameter_To = DateTime.Parse(dr[13].ToString());
                        //}
                        ////}
                        ////else if (displayType == DisplayType.Time)
                        ////{
                        //if (dr[14] != null && dr[14] != DBNull.Value)
                        //{
                        //    Parameter = DateTime.Parse(dr[14].ToString());
                        //}
                        //if (dr[15] != null && dr[15] != DBNull.Value)
                        //{
                        //    Parameter_To = DateTime.Parse(dr[15].ToString());
                        //}
                        //}
                        //}
                    }
                    //	Info
                    String Info    = dr[7].ToString();
                    String Info_To = dr[8].ToString();



                    if (dr[12].ToString().Equals("Y") && ((DisplayType.IsID(Utility.Util.GetValueOfInt(dr[14])) || DisplayType.MultiKey == Utility.Util.GetValueOfInt(dr[14]))))
                    {
                        string result    = Parameter.ToString();
                        string recResult = GetRecursiveParameterValue(ctx, ParameterName, result.ToString(), ref result, dr[13].ToString().Equals("Y"));
                        if (!string.IsNullOrEmpty(recResult))
                        {
                            Info = Info + ", " + recResult;
                        }
                        Parameter = result;


                        if (Parameter_To != null && Parameter_To.ToString().Length > 0)
                        {
                            result    = Parameter_To.ToString();
                            recResult = GetRecursiveParameterValue(ctx, ParameterName, result.ToString(), ref result, dr[13].ToString().Equals("Y"));
                            if (!string.IsNullOrEmpty(recResult))
                            {
                                Info_To = Info_To + ", " + recResult;
                            }
                            Parameter_To = result;
                        }
                    }

                    if (Parameter_To != null && Parameter_To.ToString().EndsWith(","))
                    {
                        Parameter_To = Parameter_To.ToString().Substring(0, Parameter_To.ToString().Length - 1);
                    }

                    if (Parameter != null && Parameter.ToString().EndsWith(","))
                    {
                        Parameter = Parameter.ToString().Substring(0, Parameter.ToString().Length - 1);
                    }


                    //
                    list.Add(new ProcessInfoParameter(ParameterName, Parameter, Parameter_To, Info, Info_To));
                    //
                    if (pi.GetAD_Client_ID() == null)
                    {
                        pi.SetAD_Client_ID(int.Parse(dr[9].ToString()));
                    }
                    if (pi.GetAD_User_ID() == null)
                    {
                        pi.SetAD_User_ID(int.Parse(dr[11].ToString()));
                    }
                }
                dr.Close();
            }
            catch (Exception e)
            {
                if (dr != null)
                {
                    dr.Close();
                }
                _log.Severe(e.ToString());
            }
            finally
            {
                if (dr != null)
                {
                    dr.Close();
                }
            }
            //
            ProcessInfoParameter[] pars = new ProcessInfoParameter[list.Count()];
            pars = list.ToArray();
            pi.SetParameter(pars);
        }   //  setParameterFromDB