/// <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
                                                                                  // +" p.P_Date_Time,p.P_Date_Time_To,p.P_Time, p.P_Time_To "
                         + "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";


            //            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,
            //                                      ip.P_Date_Time,
            //                                      ip.P_Date_Time_To,
            //                                      ip.P_Time,
            //                                      ip.P_Time_To ,
            //                                     pp.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_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();
                    //
                    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
Exemplo n.º 2
0
        }   //  setParameterFromDB

        /// <summary>
        /// Set param from db
        /// </summary>
        /// <param name="pi">ProcessInfo object</param>
        public static ProcessInfoParameter[] SetCrystalParameterFromDB(int id)
        {
            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 "                        //	10..12
                         + "FROM AD_CrystalInstance_Para p"
                         + " INNER JOIN AD_CrystalInstance i ON (p.AD_CrystalInstance_ID=i.AD_CrystalInstance_ID) "
                         + "WHERE p.AD_CrystalInstance_ID=@pinstanceid "
                         + "ORDER BY p.SeqNo";
            IDataReader dr = null;

            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@pinstanceid", 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();
                    //	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();
            return(pars);
            //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