/// <summary>
 /// User ID
 /// </summary>
 /// <returns>return user id</returns>
 protected int GetAD_User_ID()
 {
     if (_pi.GetAD_User_ID() == null || _pi.GetAD_Client_ID() == null)
     {
         String      sql = "SELECT AD_User_ID, AD_Client_ID FROM AD_PInstance WHERE AD_PInstance_ID=@instanceid";
         IDataReader dr  = null;
         try
         {
             SqlParameter[] param = new SqlParameter[1];
             param[0] = new SqlParameter("@instanceid", _pi.GetAD_PInstance_ID());
             dr       = SqlExec.ExecuteQuery.ExecuteReader(sql, param);
             while (dr.Read())
             {
                 _pi.SetAD_User_ID(Utility.Util.GetValueOfInt(dr[0].ToString()));
                 _pi.SetAD_Client_ID(Utility.Util.GetValueOfInt(dr[1].ToString()));
             }
             dr.Close();
         }
         catch (SqlException e)
         {
             if (dr != null)
             {
                 dr.Close();
             }
             log.Log(Level.SEVERE, e.Message);
         }
     }
     if (_pi.GetAD_User_ID() == 0)
     {
         return(0);
     }
     return((int)_pi.GetAD_User_ID());
 }
예제 #2
0
        //public JsonResult SaveChangePassword(int AD_User_ID, string currentPws, string newPws)
        //{
        //    if (Session["Ctx"] != null)
        //    {
        //        var ctx = Session["ctx"] as Ctx;
        //        UserPreferenceModel obj = new UserPreferenceModel();
        //        var val = obj.SaveChangePassword(ctx, AD_User_ID, currentPws, newPws);
        //        return Json(new { result = val }, JsonRequestBehavior.AllowGet);
        //    }
        //    return Json(new { result = "ok" }, JsonRequestBehavior.AllowGet);
        //}
        /// <summary>
        /// Change login user password
        /// </summary>
        /// <param name="AD_User_ID"></param>
        /// <param name="currentPws"></param>
        /// <param name="newPws"></param>
        /// <returns></returns>
        public JsonResult SaveChangePassword(int AD_User_ID, string currentPws, string newPws)
        {
            string message = string.Empty;

            if (Session["Ctx"] != null)
            {
                String msg = "";
                var    ctx = Session["ctx"] as Ctx;

                var AD_Process_ID = Util.GetValueOfInt(DB.ExecuteScalar("SELECT AD_PROCESS_ID  FROM AD_PROCESS WHERE NAME = 'Reset Your Password'", null, null)); // Get Reset Your Password process id
                // Prepare Process
                MPInstance instance = new MPInstance(ctx, AD_Process_ID, 0);                                                                                      // create object of MPInstance
                if (!instance.Save())
                {
                    msg = Msg.GetMsg(ctx, "ProcessNoInstance");
                    return(Json(new { result = msg }, JsonRequestBehavior.AllowGet));
                }
                VAdvantage.ProcessEngine.ProcessInfo pi = new VAdvantage.ProcessEngine.ProcessInfo("ChangePassword", AD_Process_ID);
                pi.SetAD_PInstance_ID(instance.GetAD_PInstance_ID());
                pi.SetAD_User_ID(AD_User_ID);
                pi.SetAD_Client_ID(ctx.GetAD_Client_ID());
                // Add Parameter - CurrentPassword
                MPInstancePara para = new MPInstancePara(instance, 10);

                para.setParameter("CurrentPassword", currentPws);
                if (!para.Save())
                {
                    msg = "No Selection Parameter added";   //  not translated
                    // msg = Msg.GetMsg(ctx, "ProcessNoInstance");
                    return(Json(new { result = msg }, JsonRequestBehavior.AllowGet));
                }
                // Add Parameter - NewPassword
                para = new MPInstancePara(instance, 20);
                para.setParameter("NewPassword", newPws);
                if (!para.Save())
                {
                    msg = "No DocAction Parameter added";   //  not translated
                    // msg = Msg.GetMsg(ctx, "ProcessNoInstance");
                    return(Json(new { result = msg }, JsonRequestBehavior.AllowGet));
                }
                para = new MPInstancePara(instance, 30);
                para.setParameter("AD_User_ID", AD_User_ID);
                if (!para.Save())
                {
                    msg = "No DocAction Parameter added";  //  not translated
                    //msg = Msg.GetMsg(ctx, "ProcessNoInstance");
                    return(Json(new { result = msg }, JsonRequestBehavior.AllowGet));
                }
                ASyncProcess _parent = null;
                // Execute Process
                ProcessCtl worker = new ProcessCtl(ctx, _parent, pi, null);

                worker.Run();     //  complete tasks in unlockUI / generateInvoice_complete
                message = pi.GetSummary();
            }
            return(Json(new { result = message }, JsonRequestBehavior.AllowGet));
            //return Json(new { result = "ok" }, JsonRequestBehavior.AllowGet);
        }
예제 #3
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