Esempio n. 1
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);
        }
Esempio n. 2
0
        /// <summary>
        /// Starts the process
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="pi">ProcessInfo object</param>
        /// <returns></returns>
        public bool StartProcess(Ctx ctx, ProcessInfo pi, Trx trx)
        {
            //  Preparation
            _pi = pi;
            PrepareCtx(ctx);
            //ctxContext = ctx == null ? Utility.Env.GetCtx() : ctx;

            _trx = trx;
            bool localTrx = _trx == null;

            if (localTrx)
            {
                _trx = Trx.GetTrx("SvrProcess");
            }


            //trx = SqlExec.ExecuteQuery.GerServerTransaction();

            String msg     = null;
            bool   success = true;

            try
            {
                Lock();
                Prepare();
                msg = DoIt();
            }
            catch (Exception e)
            {
                msg = e.Message;
                if (msg == null)
                {
                    msg = e.ToString();
                }
                if (e.Message != null)
                {
                    log.Log(Level.SEVERE, msg);
                }
                else if (VLogMgt.IsLevelFiner())
                {
                    log.Log(Level.WARNING, msg);
                }
                else
                {
                    log.Warning(msg);
                }
                success = false;
            }

            if (localTrx && _trx != null)
            {
                if (success)
                {
                    _trx.Commit();
                }
                else
                {
                    _trx.Rollback();
                }
                _trx.Close();
                _trx = null;
            }

            //	Parse Variables
            msg = Utility.Msg.ParseTranslation(ctx, msg);
            _pi.SetSummary(msg, !success);
            ProcessInfoUtil.SaveLogToDB(_pi);

            Unlock();
            return(success);
        }
Esempio n. 3
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
Esempio n. 4
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
        }
Esempio n. 5
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