/// <summary>
        /// Perform Process.
        /// </summary>
        /// <returns>Message (variables are parsed)</returns>
        protected override String DoIt()
        {
            MWFProcess process = new MWFProcess(GetCtx(), p_AD_WF_Process_ID, Get_Trx());

            log.Info("doIt - " + process);

            MUser user = MUser.Get(GetCtx(), GetAD_User_ID());

            //	Abort
            if (p_IsAbort)
            {
                msg = user.GetName() + ": Abort";
                process.SetTextMsg(msg);
                process.SetAD_User_ID(GetAD_User_ID());
                process.SetWFState(StateEngine.STATE_ABORTED);

                //JID_0278 : To mark processing checkbox false.
                // Mohit
                // Date : 22 May 2019
                MTable table = new MTable(GetCtx(), process.GetAD_Table_ID(), null);
                PO     po    = MTable.GetPO(GetCtx(), table.GetTableName(), process.GetRecord_ID(), Get_Trx());
                if (po != null && po.Get_ColumnIndex("Processing") >= 0)
                {
                    po.Set_Value("Processing", false);
                    po.Save();
                }
                return(msg);
            }

            //	Change User
            if (p_AD_User_ID != 0 && process.GetAD_User_ID() != p_AD_User_ID)
            {
                MUser from = MUser.Get(GetCtx(), process.GetAD_User_ID());
                MUser to   = MUser.Get(GetCtx(), p_AD_User_ID);
                msg = user.GetName() + ": " + from.GetName() + " -> " + to.GetName();
                process.SetTextMsg(msg);
                process.SetAD_User_ID(p_AD_User_ID);
            }
            //	Change Responsible
            if (p_AD_WF_Responsible_ID != 0 && process.GetAD_WF_Responsible_ID() != p_AD_WF_Responsible_ID)
            {
                MWFResponsible from = MWFResponsible.Get(GetCtx(), process.GetAD_WF_Responsible_ID());
                MWFResponsible to   = MWFResponsible.Get(GetCtx(), p_AD_WF_Responsible_ID);
                String         msg1 = user.GetName() + ": " + from.GetName() + " -> " + to.GetName();
                process.SetTextMsg(msg1);
                process.SetAD_WF_Responsible_ID(p_AD_WF_Responsible_ID);
                if (msg == null)
                {
                    msg = msg1;
                }
                else
                {
                    msg += " - " + msg1;
                }
            }
            process.Save();

            return("OK");
        }
 /**
  *  Set Approved
  *	@param IsApproved approval
  */
 public new void SetIsApproved(Boolean isApproved)
 {
     if (isApproved && !IsApproved())
     {
         int    AD_User_ID = GetCtx().GetAD_User_ID();
         MUser  user       = MUser.Get(GetCtx(), AD_User_ID);
         String Info       = user.GetName()
                             + ": "
                             + Msg.Translate(GetCtx(), "IsApproved")
                             + " - " + DateTime.Now.ToString();
         AddDescription(Info);
     }
     base.SetIsApproved(isApproved);
 }
        }   //  sendAlert

        private bool Escalate(MRequest request)
        {
            //  Get Supervisor
            MUser supervisor    = request.GetSalesRep(); //	self
            int   supervisor_ID = request.GetSalesRep().GetSupervisor_ID();

            if ((supervisor_ID == 0) && (m_model.GetSupervisor_ID() != 0))
            {
                supervisor_ID = m_model.GetSupervisor_ID();
            }
            if ((supervisor_ID != 0) && (supervisor_ID != request.GetAD_User_ID()))
            {
                supervisor = MUser.Get(GetCtx(), supervisor_ID);
            }

            //  Escalated: Request {0} to {1}
            String subject = Msg.GetMsg(m_client.GetAD_Language(), "RequestEscalate",
                                        new String[] { request.GetDocumentNo(), supervisor.GetName() });
            String to = request.GetSalesRep().GetEMail();

            if ((to == null) || (to.Length == 0))
            {
                log.Warning("SalesRep has no EMail - " + request.GetSalesRep());
            }
            else
            {
                m_client.SendEMail(request.GetSalesRep_ID(), subject, request.GetSummary(), request.CreatePDF());
            }

            //	Not the same - send mail to supervisor
            if (request.GetSalesRep_ID() != supervisor.GetAD_User_ID())
            {
                to = supervisor.GetEMail();
                if ((to == null) || (to.Length == 0))
                {
                    log.Warning("Supervisor has no EMail - " + supervisor);
                }
                else
                {
                    m_client.SendEMail(supervisor.GetAD_User_ID(), subject, request.GetSummary(), request.CreatePDF());
                }
            }

            //  ----------------
            request.SetDueType();
            request.SetIsEscalated(true);
            request.SetResult(subject);
            return(request.Save());
        }   //  escalate
        /// <summary>
        ///Perform Process.
        /// </summary>
        /// <returns>Message (variables are parsed)</returns>
        protected override String DoIt()
        {
            string      msg      = null;
            MWFActivity activity = new MWFActivity(GetCtx(), p_AD_WF_Activity_ID, Get_Trx());

            log.Info("" + activity);

            MUser user = MUser.Get(GetCtx(), GetAD_User_ID());

            //	Abort
            if (p_IsAbort)
            {
                msg = user.GetName() + ": Abort";
                activity.SetTextMsg(msg);
                activity.SetAD_User_ID(GetAD_User_ID());
                activity.SetWFState(StateEngine.STATE_ABORTED);
                return(msg);
            }

            //	Change User
            if (p_AD_User_ID != 0 && activity.GetAD_User_ID() != p_AD_User_ID)
            {
                MUser from = MUser.Get(GetCtx(), activity.GetAD_User_ID());
                MUser to   = MUser.Get(GetCtx(), p_AD_User_ID);
                msg = user.GetName() + ": " + from.GetName() + " -> " + to.GetName();
                activity.SetTextMsg(msg);
                activity.SetAD_User_ID(p_AD_User_ID);
            }
            //	Change Responsible
            if (p_AD_WF_Responsible_ID != 0 && activity.GetAD_WF_Responsible_ID() != p_AD_WF_Responsible_ID)
            {
                MWFResponsible from = MWFResponsible.Get(GetCtx(), activity.GetAD_WF_Responsible_ID());
                MWFResponsible to   = MWFResponsible.Get(GetCtx(), p_AD_WF_Responsible_ID);
                String         msg1 = user.GetName() + ": " + from.GetName() + " -> " + to.GetName();
                activity.SetTextMsg(msg1);
                activity.SetAD_WF_Responsible_ID(p_AD_WF_Responsible_ID);
                if (msg == null)
                {
                    msg = msg1;
                }
                else
                {
                    msg += " - " + msg1;
                }
            }
            activity.Save();
            return(msg);
        }
        /// <summary>
        /// Perform Process.
        /// </summary>
        /// <returns>Message (variables are parsed)</returns>
        protected override String DoIt()
        {
            MWFProcess process = new MWFProcess(GetCtx(), p_AD_WF_Process_ID, Get_Trx());

            log.Info("doIt - " + process);

            MUser user = MUser.Get(GetCtx(), GetAD_User_ID());

            //	Abort
            if (p_IsAbort)
            {
                msg = user.GetName() + ": Abort";
                process.SetTextMsg(msg);
                process.SetAD_User_ID(GetAD_User_ID());
                process.SetWFState(StateEngine.STATE_ABORTED);
                return(msg);
            }

            //	Change User
            if (p_AD_User_ID != 0 && process.GetAD_User_ID() != p_AD_User_ID)
            {
                MUser from = MUser.Get(GetCtx(), process.GetAD_User_ID());
                MUser to   = MUser.Get(GetCtx(), p_AD_User_ID);
                msg = user.GetName() + ": " + from.GetName() + " -> " + to.GetName();
                process.SetTextMsg(msg);
                process.SetAD_User_ID(p_AD_User_ID);
            }
            //	Change Responsible
            if (p_AD_WF_Responsible_ID != 0 && process.GetAD_WF_Responsible_ID() != p_AD_WF_Responsible_ID)
            {
                MWFResponsible from = MWFResponsible.Get(GetCtx(), process.GetAD_WF_Responsible_ID());
                MWFResponsible to   = MWFResponsible.Get(GetCtx(), p_AD_WF_Responsible_ID);
                String         msg1 = user.GetName() + ": " + from.GetName() + " -> " + to.GetName();
                process.SetTextMsg(msg1);
                process.SetAD_WF_Responsible_ID(p_AD_WF_Responsible_ID);
                if (msg == null)
                {
                    msg = msg1;
                }
                else
                {
                    msg += " - " + msg1;
                }
            }
            process.Save();

            return("OK");
        }
        /// <summary>
        /// save prefrence into database as well as in server context
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="pref"></param>
        /// <returns></returns>
        public bool SavePrefrence(Ctx ctx, Dictionary <string, object> pref)
        {
            MUserPreference preference = null;
            MUser           user       = MUser.Get(ctx);

            preference = user.GetPreference();
            preference.SetIsAutoCommit(pref["IsAutoCommit"].Equals("Y") ? true : false);
            ctx.SetAutoCommit(pref["IsAutoCommit"].Equals("Y") ? true : false);
            preference.SetIsShowAcct(pref["IsShowAcct"].Equals("Y") ? true : false);
            ctx.SetContext("#ShowAcct", pref["IsShowAcct"].Equals("Y") ? true : false);
            //	Show Trl Tab
            preference.SetIsShowTrl(pref["IsShowTrl"].Equals("Y") ? true : false);
            ctx.SetContext("#ShowTrl", pref["IsShowTrl"].Equals("Y") ? true : false);
            //	Show Advanced Tab
            preference.SetIsShowAdvanced(pref["IsShowAdvanced"].Equals("Y") ? true : false);
            ctx.SetContext("#ShowAdvanced", pref["IsShowAdvanced"].Equals("Y") ? true : false);
            return(preference.Save());
        }
Exemple #7
0
        }       //	processAlert

        /**
         *  Send Email / Notice
         *  @param AD_User_ID user
         *	@param alert alert
         *	@param message message text
         *	@return true if sent (or previously sent)
         */
        private bool SendInfo(int AD_User_ID, MAlert alert, String message)
        {
            if (m_recipients.Contains(AD_User_ID))
            {
                return(false);
            }
            m_recipients.Add(AD_User_ID);
            //
            bool   success          = false;
            MUser  to               = MUser.Get(alert.GetCtx(), AD_User_ID);
            String NotificationType = to.GetNotificationType();

            if (Util.IsEmpty(NotificationType))
            {
                NotificationType = X_AD_User.NOTIFICATIONTYPE_EMail;
            }
            //	Send Mail
            if (X_AD_User.NOTIFICATIONTYPE_EMail.Equals(NotificationType) ||
                X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.Equals(NotificationType))
            {
                success = m_client.SendEMail(AD_User_ID, alert.GetAlertSubject(), message, null);
                if (!success)
                {
                    log.Warning("EMail failed: " + to);
                    NotificationType = X_AD_User.NOTIFICATIONTYPE_Notice;
                }
            }
            //	Send Note
            if (X_AD_User.NOTIFICATIONTYPE_Notice.Equals(NotificationType) ||
                X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.Equals(NotificationType))
            {
                int   AD_Message_ID = 1040;     //	AlertNotice
                MNote note          = new MNote(alert.GetCtx(), AD_Message_ID, AD_User_ID,
                                                X_AD_Alert.Table_ID, alert.GetAD_Alert_ID(),
                                                alert.GetAlertSubject(), message, null);
                success = note.Save();
            }
            return(success);
        }       //	sendInfo
Exemple #8
0
        /// <summary>
        /// Send notice to user
        /// </summary>
        /// <param name="AD_User_ID">Id of user</param>
        /// <param name="NotificationType"> Notification type</param>
        /// <param name="client"> Tenant object</param>
        /// <param name="from"> From user notice</param>
        /// <param name="subject">Subject of notice.</param>
        /// <param name="message">Message to be sent to user</param>
        /// <param name="pdf"> Attachment</param>
        private void SendNoticeNow(int AD_User_ID, String NotificationType,
                                   MClient client, MUser from, String subject, String message, FileInfo pdf)
        {
            MUser to = MUser.Get(GetCtx(), AD_User_ID);

            if (NotificationType == null)
            {
                NotificationType = to.GetNotificationType();
            }
            //	Send Mail
            if (X_AD_User.NOTIFICATIONTYPE_EMail.Equals(NotificationType) ||
                X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.Equals(NotificationType))
            {
                VAdvantage.Model.MMailAttachment1 _mAttachment = new VAdvantage.Model.MMailAttachment1(GetCtx(), 0, null);
                _mAttachment.SetAD_Client_ID(GetCtx().GetAD_Client_ID());
                _mAttachment.SetAD_Org_ID(GetCtx().GetAD_Org_ID());
                _mAttachment.SetAD_Table_ID(MTable.Get_Table_ID(Table_Name));
                _mAttachment.IsActive();
                _mAttachment.SetMailAddress("");
                _mAttachment.SetAttachmentType("M");
                _mAttachment.SetRecord_ID(_req.GetR_Request_ID());
                _mAttachment.SetTextMsg(message);
                _mAttachment.SetTitle(subject);
                _mAttachment.SetMailAddress(to.GetEMail());

                if (from != null && !string.IsNullOrEmpty(from.GetEMail()))
                {
                    _mAttachment.SetMailAddressFrom(from.GetEMail());
                }
                else
                {
                    _mAttachment.SetMailAddressFrom(client.GetRequestEMail());
                }

                _mAttachment.NewRecord();

                if (client.SendEMail(from, to, subject, message.ToString(), pdf))
                {
                    _success++;
                    if (_emailTo.Length > 0)
                    {
                        _emailTo.Append(", ");
                    }
                    _emailTo.Append(to.GetEMail());
                    _mAttachment.SetIsMailSent(true);
                }
                else
                {
                    log.Warning("Failed: " + to);
                    _failure++;
                    NotificationType = X_AD_User.NOTIFICATIONTYPE_Notice;
                    _mAttachment.SetIsMailSent(false);
                }

                _mAttachment.Save();
            }

            //	Send Note
            if (X_AD_User.NOTIFICATIONTYPE_Notice.Equals(NotificationType) ||
                X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.Equals(NotificationType))
            {
                int   AD_Message_ID = 834;
                MNote note          = new MNote(GetCtx(), AD_Message_ID, AD_User_ID,
                                                X_R_Request.Table_ID, _req.GetR_Request_ID(),
                                                subject, message.ToString(), Get_TrxName());
                if (note.Save())
                {
                    _notices++;
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// Prepare notice message.
        /// </summary>
        /// <param name="list">list of the values changed.</param>
        private void prepareNotificMsg(List <String> list)
        {
            if (mailText_ID == 0)
            {
                message = new StringBuilder();
                //		UpdatedBy: Joe
                int   UpdatedBy = GetCtx().GetAD_User_ID();
                MUser from      = MUser.Get(GetCtx(), UpdatedBy);
                if (from != null)
                {
                    message.Append(Msg.Translate(GetCtx(), "UpdatedBy")).Append(": ")
                    .Append(from.GetName());
                }
                //		LastAction/Created: ...
                if (_req.GetDateLastAction() != null)
                {
                    message.Append("\n").Append(Msg.Translate(GetCtx(), "DateLastAction"))
                    .Append(": ").Append(_req.GetDateLastAction());
                }
                else
                {
                    message.Append("\n").Append(Msg.Translate(GetCtx(), "Created"))
                    .Append(": ").Append(_req.GetCreated());
                }
                //	Changes
                for (int i = 0; i < list.Count; i++)
                {
                    X_R_Request req = new X_R_Request(GetCtx(), 0, null);

                    String columnName = (String)list[i];
                    message.Append("\n").Append(Msg.GetElement(GetCtx(), columnName))
                    .Append(": ").Append(_reqAction.getColumnValue(columnName))
                    .Append(" -> ").Append(_req.getColumnValue(columnName));
                }
                //	NextAction
                if (_req.GetDateNextAction() != null)
                {
                    message.Append("\n").Append(Msg.Translate(GetCtx(), "DateNextAction"))
                    .Append(": ").Append(_req.GetDateNextAction());
                }
                message.Append(SEPARATOR)
                .Append(_req.GetSummary());
                if (_req.GetResult() != null)
                {
                    message.Append("\n----------\n").Append(_req.GetResult());
                }
                message.Append(_req.GetMailTrailer(null));
            }
            else
            {
                message = new StringBuilder();

                MMailText text = new MMailText(GetCtx(), mailText_ID, null);
                text.SetPO(_req, true); //Set _Po Current value
                subject += _req.GetDocumentNo() + ": " + text.GetMailHeader();

                message.Append(text.GetMailText(true));
                if (_req.GetDateNextAction() != null)
                {
                    message.Append("\n").Append(Msg.Translate(GetCtx(), "DateNextAction"))
                    .Append(": ").Append(_req.GetDateNextAction());
                }

                // message.Append(GetMailTrailer(null));
            }
        }
Exemple #10
0
        /// <summary>
        /// Send notice to users.
        /// </summary>
        /// <param name="list"> List of columns changed.</param>
        protected void SendNotices(List <String> list)
        {
            bool          isEmailSent = false;
            StringBuilder finalMsg    = new StringBuilder();

            finalMsg.Append(Msg.Translate(GetCtx(), "R_Request_ID") + ": " + _req.GetDocumentNo()).Append("\n").Append(Msg.Translate(GetCtx(), "R_NotificSent"));
            //	Subject
            if (mailText_ID == 0)
            {
                subject = Msg.Translate(GetCtx(), "R_Request_ID")
                          + " " + Msg.GetMsg(GetCtx(), "Updated", true) + ": " + _req.GetDocumentNo() + " (●" + MTable.Get_Table_ID(Table_Name) + "-" + _req.GetR_Request_ID() + "●) " + Msg.GetMsg(GetCtx(), "DoNotChange");
            }
            //	Message

            //		UpdatedBy: Joe
            int   UpdatedBy = GetCtx().GetAD_User_ID();
            MUser from      = MUser.Get(GetCtx(), UpdatedBy);

            FileInfo pdf = CreatePDF();

            log.Finer(message.ToString());

            //	Prepare sending Notice/Mail
            MClient client = MClient.Get(GetCtx(), GetAD_Client_ID());

            //	ReSet from if external
            if (from.GetEMailUser() == null || from.GetEMailUserPW() == null)
            {
                from = null;
            }
            _success = 0;
            _failure = 0;
            _notices = 0;

            /** List of users - aviod duplicates	*/
            List <int> userList = new List <int>();
            String     sql      = "SELECT u.AD_User_ID, u.NotificationType, u.EMail, u.Name, MAX(r.AD_Role_ID) "
                                  + "FROM RV_RequestUpdates_Only ru"
                                  + " INNER JOIN AD_User u ON (ru.AD_User_ID=u.AD_User_ID)"
                                  + " LEFT OUTER JOIN AD_User_Roles r ON (u.AD_User_ID=r.AD_User_ID) "
                                  + "WHERE ru.R_Request_ID= " + _req.GetR_Request_ID()
                                  + " GROUP BY u.AD_User_ID, u.NotificationType, u.EMail, u.Name";

            IDataReader idr = null;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql, null, null);
                while (idr.Read())
                {
                    int    AD_User_ID       = Utility.Util.GetValueOfInt(idr[0]);
                    String NotificationType = Util.GetValueOfString(idr[1]); //idr.GetString(1);
                    if (NotificationType == null)
                    {
                        NotificationType = X_AD_User.NOTIFICATIONTYPE_EMail;
                    }
                    String email = Util.GetValueOfString(idr[2]);// idr.GetString(2);

                    if (String.IsNullOrEmpty(email))
                    {
                        continue;
                    }

                    String Name = Util.GetValueOfString(idr[3]);//idr.GetString(3);
                    //	Role
                    int AD_Role_ID = Utility.Util.GetValueOfInt(idr[4]);
                    if (idr == null)
                    {
                        AD_Role_ID = -1;
                    }

                    //	Don't send mail to oneself
                    //		if (AD_User_ID == UpdatedBy)
                    //			continue;

                    //	No confidential to externals
                    if (AD_Role_ID == -1 &&
                        (_req.GetConfidentialTypeEntry().Equals(X_R_Request.CONFIDENTIALTYPE_Internal) ||
                         _req.GetConfidentialTypeEntry().Equals(X_R_Request.CONFIDENTIALTYPE_PrivateInformation)))
                    {
                        continue;
                    }

                    if (X_AD_User.NOTIFICATIONTYPE_None.Equals(NotificationType))
                    {
                        log.Config("Opt out: " + Name);
                        continue;
                    }
                    if ((X_AD_User.NOTIFICATIONTYPE_EMail.Equals(NotificationType) ||
                         X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.Equals(NotificationType)) &&
                        (email == null || email.Length == 0))
                    {
                        if (AD_Role_ID >= 0)
                        {
                            NotificationType = X_AD_User.NOTIFICATIONTYPE_Notice;
                        }
                        else
                        {
                            log.Config("No EMail: " + Name);
                            continue;
                        }
                    }
                    if (X_AD_User.NOTIFICATIONTYPE_Notice.Equals(NotificationType) &&
                        AD_Role_ID >= 0)
                    {
                        log.Config("No internal User: "******"\n").Append(user.GetName()).Append(".");
                    isEmailSent = true;
                }

                idr.Close();
                // Notification For Role
                List <int> _users = SendRoleNotice();
                for (int i = 0; i < _users.Count; i++)
                {
                    MUser  user             = new MUser(GetCtx(), _users[i], null);
                    int    AD_User_ID       = user.GetAD_User_ID();
                    String NotificationType = user.GetNotificationType(); //idr.GetString(1);
                    if (NotificationType == null)
                    {
                        NotificationType = X_AD_User.NOTIFICATIONTYPE_EMail;
                    }
                    String email = user.GetEMail();// idr.GetString(2);

                    if (String.IsNullOrEmpty(email))
                    {
                        continue;
                    }

                    String Name = user.GetName(); //idr.GetString(3);
                                                  //	Role

                    if (X_AD_User.NOTIFICATIONTYPE_None.Equals(NotificationType))
                    {
                        log.Config("Opt out: " + Name);
                        continue;
                    }

                    //
                    SendNoticeNow(_users[i], NotificationType,
                                  client, from, subject, message.ToString(), pdf);
                    finalMsg.Append("\n").Append(user.GetName()).Append(".");
                    isEmailSent = true;
                }

                if (!isEmailSent)
                {
                    finalMsg.Clear();
                    finalMsg.Append(Msg.Translate(GetCtx(), "R_Request_ID") + ": " + _req.GetDocumentNo()).Append("\n").Append(Msg.Translate(GetCtx(), "R_NoNotificationSent"));
                }

                int   AD_Message_ID = 834;
                MNote note          = new MNote(GetCtx(), AD_Message_ID, GetCtx().GetAD_User_ID(),
                                                X_R_Request.Table_ID, _req.GetR_Request_ID(),
                                                subject, finalMsg.ToString(), Get_TrxName());
                if (note.Save())
                {
                    log.Log(Level.INFO, "ProcessFinished", "");
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                log.Log(Level.SEVERE, sql, e);
            }


            //	New Sales Rep (may happen if sent from beforeSave
            if (!userList.Contains(_req.GetSalesRep_ID()))
            {
                SendNoticeNow(_req.GetSalesRep_ID(), null,
                              client, from, subject, message.ToString(), pdf);
            }
        }
        protected override string DoIt()
        {
            VLogger log = VLogger.GetVLogger(this.GetType().FullName);

            log.Log(Level.SEVERE, "UserPassword Change Log=>" + Convert.ToString(p_AD_User_ID));
            if (p_AD_User_ID == -1)
            {
                p_AD_User_ID = GetAD_User_ID();
            }

            MUser user    = MUser.Get(GetCtx(), p_AD_User_ID);
            MUser current = MUser.Get(GetCtx(), GetAD_User_ID());


            if (!current.IsAdministrator() && p_AD_User_ID != GetAD_User_ID() && user.HasRole())
            {
                throw new ArgumentException("@UserCannotUpdate@");
            }

            // SuperUser and System passwords can only be updated by themselves
            if (user.IsSystemAdministrator() && p_AD_User_ID != GetAD_User_ID())
            {
                throw new ArgumentException("@UserCannotUpdate@");
            }

            log.Log(Level.SEVERE, "UserPassword Change Log Step Check for valid user=>" + Convert.ToString(p_AD_User_ID));
            if (string.IsNullOrEmpty(p_CurrentPassword))
            {
                if (string.IsNullOrEmpty(p_OldPassword))
                {
                    throw new ArgumentException("@OldPasswordMandatory@");
                }
                else if (!p_OldPassword.Equals(user.GetPassword()))
                {
                    if (!SecureEngine.Encrypt(p_OldPassword).Equals(user.GetPassword()))
                    {
                        throw new ArgumentException("@OldPasswordNoMatch@");
                    }
                }
            }

            else if (!p_CurrentPassword.Equals(current.GetPassword()))
            {
                throw new ArgumentException("@OldPasswordNoMatch@");
            }
            log.Log(Level.SEVERE, "UserPassword Change Log Step Password Change=>" + Convert.ToString(p_AD_User_ID));
            String originalPwd = p_NewPassword;

            String sql = "UPDATE AD_User SET Updated=SYSDATE, UpdatedBy=" + GetAD_User_ID();

            if (!string.IsNullOrEmpty(p_NewPassword))
            {
                MColumn column = MColumn.Get(GetCtx(), 417); // Password Column
                if (column.IsEncrypted())
                {
                    p_NewPassword = SecureEngine.Encrypt(p_NewPassword);
                }
                sql += ", Password="******", Email=" + GlobalVariable.TO_STRING(p_NewEMail);
            }
            if (!string.IsNullOrEmpty(p_NewEMailUser))
            {
                sql += ", EmailUser="******", EmailUserPW=" + GlobalVariable.TO_STRING(p_NewEMailUserPW);
            }
            sql += " WHERE AD_User_ID=" + p_AD_User_ID;
            log.Log(Level.SEVERE, "UserPassword Change Log=>" + sql);
            int iRes = DB.ExecuteQuery(sql, null, Get_Trx());

            if (iRes > 0)
            {
                bool error = false;
                //Check for yellowFin user password change if BI user is true..................
                object ModuleId = DB.ExecuteScalar("select ad_moduleinfo_id from ad_moduleinfo where prefix='VA037_' and IsActive = 'Y'"); // is active check by vinay bhatt on 18 oct 2018
                if (ModuleId != null && ModuleId != DBNull.Value)
                {
                    if (user.IsVA037_BIUser())
                    {
                        var  Dll              = Assembly.Load("VA037");
                        var  BIUser           = Dll.GetType("VA037.BIProcess.BIUsers");
                        var  objBIUser        = Activator.CreateInstance(BIUser);
                        var  ChangeBIPassword = BIUser.GetMethod("ChangeBIPassword");
                        bool value            = (bool)ChangeBIPassword.Invoke(objBIUser, new object[] { GetCtx(), GetAD_Client_ID(), Convert.ToString(user.GetVA037_BIUserName()), originalPwd });
                        if (value)
                        {
                            //user.SetPassword(p_NewPassword);
                            error = false;
                            user.SetPassword(originalPwd);
                            //return "OK";
                        }
                        else
                        {
                            error = true;
                            // return "@Error@";
                        }
                    }
                    else
                    {
                        error = false;
                        user.SetPassword(originalPwd);
                        // return "OK";
                    }
                }
                ModuleId = DB.ExecuteScalar("select ad_moduleinfo_id from ad_moduleinfo where prefix='VA039_' and IsActive = 'Y'"); // is active check by vinay bhatt
                if (ModuleId != null && ModuleId != DBNull.Value)
                {
                    MUser obj = new MUser(GetCtx(), p_AD_User_ID, null);
                    if (obj.IsVA039_IsJasperUser() == true)
                    {
                        var      Dll           = Assembly.Load("VA039");
                        var      JasperUser    = Dll.GetType("VA039.Classes.Users");
                        var      objJasperUser = Activator.CreateInstance(JasperUser);
                        var      BICreateUser  = JasperUser.GetMethod("ModifyUserPassword");
                        object[] args          = new object[] { GetCtx(), originalPwd };
                        bool     value         = (bool)BICreateUser.Invoke(objJasperUser, args);
                        if (value)
                        {
                            error = false;
                            user.SetPassword(originalPwd);

                            //return "@Error@";
                        }
                        else
                        {
                            error = true;
                            goto PasswordError;
                            // return "OK";
                        }
                    }
                }
                else
                {
                    error = false;
                    user.SetPassword(originalPwd);
                    // return "OK";
                }
PasswordError:
                if (error)
                {
                    return("@Error@");
                }
                else
                {
                    return("OK");
                }
            }
            else
            {
                return("@Error@");
            }
        }
        public JavaScriptResult Application()
        {
            //var s = Codec.DecryptStringAES();
            StringBuilder sb = new StringBuilder();

            Ctx ctx = Session["ctx"] as Ctx;

            if (ctx.GetSecureKey() == "")
            {
                ctx.SetSecureKey(SecureEngineBridge.GetRandomKey());
            }

            //  ctx.SetApplicationUrl(@Url.Content("~/"));
            ctx.SetIsSSL(Request.Url.Scheme == Uri.UriSchemeHttps);

            //lakhwinder
            string fullUrl = Request.Url.AbsoluteUri.Remove(Request.Url.AbsoluteUri.LastIndexOf('/'));

            //fullUrl = fullUrl.Remove(fullUrl.LastIndexOf('/'));
            //fullUrl = fullUrl.Remove(fullUrl.LastIndexOf('/'));
            fullUrl = fullUrl.Remove(fullUrl.IndexOf("VIS/Resource"));
            ctx.SetApplicationUrl(fullUrl);

            SecureEngine.Encrypt("a");

            CCache <string, string> msgs = Msg.Get().GetMsgMap(ctx.GetAD_Language());

            sb.Append("; var VIS = {");
            sb.Append("Application: {contextUrl:'").Append(@Url.Content("~/")).Append("',").Append(" contextFullUrl:'").Append(fullUrl).Append("',")
            .Append("isMobile:").Append(Request.Browser.IsMobileDevice ? "1" : "0")
            .Append(", isRTL:").Append(ctx.GetIsRightToLeft() ? "1" : "0")
            .Append(", isBasicDB:").Append(ctx.GetIsBasicDB() ? "1" : "0")
            .Append(", isSSL:").Append((Request.Url.Scheme != Uri.UriSchemeHttps ? "0" :"1"))           //TODO
            .Append("},");

            sb.Append("I18N: { }, context: { }");
            sb.Append("};");

            sb.Append("VIS.Consts={");
            /* Table */
            sb.Append("'ACCESSLEVEL_Organization' : '1','ACCESSLEVEL_ClientOnly' : '2','ACCESSLEVEL_ClientPlusOrganization' : '3' ,'ACCESSLEVEL_SystemOnly' : '4'");
            sb.Append(", 'ACCESSLEVEL_SystemPlusClient' : '6','ACCESSLEVEL_All' : '7'");
            sb.Append(", 'ACCESSTYPERULE_Accessing' : 'A', 'ACCESSTYPERULE_Exporting' : 'E' , 'ACCESSTYPERULE_Reporting' : 'R'");
            sb.Append("};");

            /* USER */
            sb.Append(" VIS.MUser = {");
            sb.Append("'isAdministrator':'" + MUser.Get(ctx).IsAdministrator() + "', 'isUserEmployee':'" + MUser.GetIsEmployee(ctx, ctx.GetAD_User_ID()) + "' }; ");

            /* ROLE */
            sb.Append(" VIS.MRole =  {");
            sb.Append(" 'vo' : " + Newtonsoft.Json.JsonConvert.SerializeObject(VIS.Helpers.RoleHelper.GetRole(VAdvantage.Model.MRole.GetDefault(ctx, false))) + " , ");
            sb.Append(" 'SQL_RW' : true, 'SQL_RO' : false, 'SQL_FULLYQUALIFIED' : true, 'SQL_NOTQUALIFIED' : false,'SUPERUSER_USER_ID' : 100, 'SYSTEM_USER_ID' : 0 ");
            sb.Append(", 'PREFERENCETYPE_Client':'C', 'PREFERENCETYPE_None':'N', 'PREFERENCETYPE_Organization':'O', 'PREFERENCETYPE_User':'******'");

            sb.Append(", columnSynonym : { 'AD_User_ID': 'SalesRep_ID','C_ElementValue_ID':'Account_ID'}");
            sb.Append("};");

            /* CTX */
            SetLoginContext(ctx);
            sb.Append(" VIS.context.ctx = ").Append(Newtonsoft.Json.JsonConvert.SerializeObject(ctx.GetMap())).Append("; ");

            /* Message */
            sb.Append(" VIS.I18N.labels = { ");
            if (msgs != null)
            {
                int total = msgs.Keys.Count;
                foreach (var key in msgs.Keys)
                {
                    --total;
                    //if (key.Contains('\n') || key.Contains('\'')
                    //   || key.Contains('\"') || key.StartsWith("SC_") || key.Contains('\r'))
                    //{
                    //    continue;
                    //}
                    //if (msgs.Get(key).ToString().Contains('\n') || msgs.Get(key).ToString().Contains('\'')
                    //    || msgs.Get(key).ToString().Contains('\"') || msgs.Get(key).ToString().Contains('\r'))
                    //{
                    //    continue;
                    //}
                    string msg = (string)msgs.Get(key) ?? "";
                    msg = msg.Replace("\n", " ").Replace("\r", " ").Replace("\"", "'");

                    if (total == 0)
                    {
                        sb.Append("\"").Append(key).Append("\": ").Append("\"").Append(msg).Append("\"");
                    }
                    else
                    {
                        sb.Append("\"").Append(key).Append("\": ").Append("\"").Append(msg).Append("\", ");
                    }
                }
            }
            sb.Append("};");
            // sb.Append(" console.log(VIS.I18N.labels)");
            //return View();
            //System.Web.Optimization.JsMinify d = new System.Web.Optimization.JsMinify();
            //d.Process(


            //Update Login Time

            var r = new ResourceManager(fullUrl, ctx.GetAD_Client_ID());

            r.RunAsync();
            r = null;

            return(JavaScript(sb.ToString()));
        }
Exemple #13
0
        }   //  getWarehouses

        /* HTML5 */

        /// <summary>
        /// Load Preferences into Context for selected client.
        /// <para>
        /// Sets Org info in context and loads relevant field from
        /// - AD_Client/Info,
        /// - C_AcctSchema,
        /// - C_AcctSchema_Elements
        /// - AD_Preference
        /// </para>
        /// Assumes that the context is set for #AD_Client_ID, ##AD_User_ID, #AD_Role_ID
        /// </summary>
        /// <param name="org">org information</param>
        /// <param name="warehouse">optional warehouse information</param>
        /// <param name="timestamp">optional date</param>
        /// <param name="printerName">optional printer info</param>
        /// <returns>AD_Message of error (NoValidAcctInfo) or ""</returns>
        public String LoadPreferences(string date, String printerName)
        {
            if (m_ctx.GetContext("#AD_Client_ID").Length == 0)
            {
                throw new Exception("Missing Context #AD_Client_ID");
            }
            if (m_ctx.GetContext("##AD_User_ID").Length == 0)
            {
                throw new Exception("Missing Context ##AD_User_ID");
            }
            if (m_ctx.GetContext("#AD_Role_ID").Length == 0)
            {
                throw new Exception("Missing Context #AD_Role_ID");
            }

            string dateS = m_ctx.GetContext("#Date");

            DateTime dt    = DateTime.Now;
            long     today = CommonFunctions.CurrentTimeMillis();

            if (DateTime.TryParse(dateS, out dt))
            {
                today = CommonFunctions.CurrentTimeMillis(dt);
            }

            m_ctx.SetContext("#Date", today.ToString());

            //	Load User/Role Infos
            MUser user = MUser.Get(m_ctx, m_ctx.GetAD_User_ID());

            MUserPreference preference = user.GetPreference();
            MRole           role       = MRole.GetDefault(m_ctx);

            //	Optional Printer
            if (printerName == null)
            {
                printerName = "";
            }
            if (printerName.Length == 0 && preference.GetPrinterName() != null)
            {
                printerName = preference.GetPrinterName();
            }
            m_ctx.SetPrinterName(printerName);
            if (preference.GetPrinterName() == null && printerName.Length > 0)
            {
                preference.SetPrinterName(printerName);
            }

            //	Other
            m_ctx.SetAutoCommit(preference.IsAutoCommit());
            m_ctx.SetAutoNew(Ini.IsPropertyBool(Ini.P_A_NEW));
            if (role.IsShowAcct())
            {
                m_ctx.SetContext("#ShowAcct", preference.IsShowAcct());
            }
            else
            {
                m_ctx.SetContext("#ShowAcct", "N");
            }
            m_ctx.SetContext("#ShowTrl", preference.IsShowTrl());
            m_ctx.SetContext("#ShowAdvanced", preference.IsShowAdvanced());

            String retValue     = "";
            int    AD_Client_ID = m_ctx.GetAD_Client_ID();
            //	int AD_Org_ID =  org.getKey();
            //	int AD_User_ID =  Env.getAD_User_ID (m_ctx);
            int AD_Role_ID = m_ctx.GetAD_Role_ID();

            //	Other Settings
            m_ctx.SetContext("#YYYY", "Y");

            //	AccountSchema Info (first)
            String sql = "SELECT a.C_AcctSchema_ID, a.C_Currency_ID, a.HasAlias, c.ISO_Code, c.StdPrecision "
                         + "FROM C_AcctSchema a"
                         + " INNER JOIN AD_ClientInfo ci ON (a.C_AcctSchema_ID=ci.C_AcctSchema1_ID)"
                         + " INNER JOIN C_Currency c ON (a.C_Currency_ID=c.C_Currency_ID) "
                         + "WHERE ci.AD_Client_ID='" + AD_Client_ID + "'";
            IDataReader dr = null;

            try
            {
                int C_AcctSchema_ID = 0;
                dr = DataBase.DB.ExecuteReader(sql);

                if (!dr.Read())
                {
                    //  No Warning for System
                    if (AD_Role_ID != 0)
                    {
                        retValue = "NoValidAcctInfo";
                    }
                }
                else
                {
                    //	Accounting Info
                    C_AcctSchema_ID = Utility.Util.GetValueOfInt(dr[0].ToString());
                    m_ctx.SetContext("$C_AcctSchema_ID", C_AcctSchema_ID);
                    m_ctx.SetContext("$C_Currency_ID", Utility.Util.GetValueOfInt(dr[1].ToString()));
                    m_ctx.SetContext("$HasAlias", dr[2].ToString());
                    m_ctx.SetContext("$CurrencyISO", dr[3].ToString());
                    m_ctx.SetStdPrecision(Utility.Util.GetValueOfInt(dr[4].ToString()));
                }
                dr.Close();

                //	Accounting Elements
                sql = "SELECT ElementType "
                      + "FROM C_AcctSchema_Element "
                      + "WHERE C_AcctSchema_ID='" + C_AcctSchema_ID + "'"
                      + " AND IsActive='Y'";

                dr = DataBase.DB.ExecuteReader(sql);
                while (dr.Read())
                {
                    m_ctx.SetContext("$Element_" + dr["ElementType"].ToString(), "Y");
                }
                dr.Close();


                //	This reads all relevant window neutral defaults
                //	overwriting superseeded ones.  Window specific is read in Maintain
                sql = "SELECT Attribute, Value, AD_Window_ID "
                      + "FROM AD_Preference "
                      + "WHERE AD_Client_ID IN (0, @#AD_Client_ID@)"
                      + " AND AD_Org_ID IN (0, @#AD_Org_ID@)"
                      + " AND (AD_User_ID IS NULL OR AD_User_ID=0 OR AD_User_ID=@##AD_User_ID@)"
                      + " AND IsActive='Y' "
                      + "ORDER BY Attribute, AD_Client_ID, AD_User_ID DESC, AD_Org_ID";
                //	the last one overwrites - System - Client - User - Org - Window
                sql = Utility.Env.ParseContext(m_ctx, 0, sql, false);
                if (sql.Length == 0)
                {
                }
                else
                {
                    dr = DataBase.DB.ExecuteReader(sql);
                    while (dr.Read())
                    {
                        string AD_Window_ID = dr[2].ToString();
                        String at           = "";
                        if (string.IsNullOrEmpty(AD_Window_ID))
                        {
                            at = "P|" + dr[0].ToString();
                        }
                        else
                        {
                            at = "P" + AD_Window_ID + "|" + dr[0].ToString();
                        }
                        String va = dr[1].ToString();
                        m_ctx.SetContext(at, va);
                    }
                    dr.Close();
                }

                //	Default Values
                sql = "SELECT t.TableName, c.ColumnName "
                      + "FROM AD_Column c "
                      + " INNER JOIN AD_Table t ON (c.AD_Table_ID=t.AD_Table_ID) "
                      + "WHERE c.IsKey='Y' AND t.IsActive='Y'"
                      + " AND EXISTS (SELECT * FROM AD_Column cc "
                      + " WHERE ColumnName = 'IsDefault' AND t.AD_Table_ID=cc.AD_Table_ID AND cc.IsActive='Y')";

                dr = DataBase.DB.ExecuteReader(sql);
                while (dr.Read())
                {
                    LoadDefault(dr[0].ToString(), dr[1].ToString());
                }
                dr.Close();
            }
            catch
            {
                if (dr != null)
                {
                    dr.Close();
                }
            }

            //Ini.SaveProperties(Ini.IsClient());
            //	Country
            m_ctx.SetContext("#C_Country_ID", MCountry.GetDefault(m_ctx).GetC_Country_ID());

            m_ctx.SetShowClientOrg(Ini.IsShowClientOrg() ? "Y" : "N");
            m_ctx.SetShowMiniGrid(Ini.GetProperty(Ini.P_Show_Mini_Grid));
            return(retValue);
        }       //	loadPreferences
Exemple #14
0
        }       //	doIt

        /// <summary>
        /// impoert process
        /// </summary>
        /// <param name="imp">import</param>
        /// <returns>true if processed</returns>
        private bool Process(X_I_Contact imp)
        {
            if (imp.GetEMail() == null || imp.GetEMail().Length == 0)
            {
                return(ProcessFail(imp, "No EMail"));
            }

            MUser user = MUser.Get(GetCtx(), imp.GetEMail(), Get_TrxName());

            //	New User
            if (user == null || user.GetAD_User_ID() == 0)
            {
                if (imp.IsEMailBounced())
                {
                    return(ProcessFail(imp, "No User found with email - cannou set Bounced flag"));
                }
                if (imp.GetContactName() == null || imp.GetContactName().Length == 0)
                {
                    return(ProcessFail(imp, "No Name for User/Contact"));
                }

                user = new MUser(GetCtx(), 0, Get_TrxName());
                user.SetName(imp.GetContactName());
                user.SetDescription(imp.GetContactDescription());
                user.SetEMail(imp.GetEMail());
            }
            //	Existing User
            else
            {
                if (imp.IsEMailBounced())
                {
                    user.SetIsEMailBounced(true);
                    user.SetBouncedInfo(imp.GetBouncedInfo());
                }
            }
            if (!user.Save())
            {
                return(ProcessFail(imp, "Cannot save User"));
            }

            //	Create BP
            if (imp.IsCreateBP())
            {
                if (user.GetC_BPartner_ID() == 0)
                {
                    MBPartner bp = new MBPartner(GetCtx(), 0, Get_TrxName());
                    bp.SetName(user.GetName());
                    if (!bp.Save())
                    {
                        return(ProcessFail(imp, "Cannot create BPartner"));
                    }
                    else
                    {
                        user.SetC_BPartner_ID(bp.GetC_BPartner_ID());
                        if (!user.Save())
                        {
                            return(ProcessFail(imp, "Cannot update User"));
                        }
                    }
                }
                imp.SetC_BPartner_ID(user.GetC_BPartner_ID());
            }

            //	Create Lead
            if (imp.IsCreateLead())
            {
                MLead lead = new MLead(GetCtx(), 0, Get_TrxName());
                lead.SetName(imp.GetContactName());
                lead.SetDescription(imp.GetContactDescription());
                lead.SetAD_User_ID(user.GetAD_User_ID());
                lead.SetC_BPartner_ID(user.GetC_BPartner_ID());
                lead.Save();
                imp.SetC_Lead_ID(lead.GetC_Lead_ID());
            }

            //	Interest Area
            if (imp.GetR_InterestArea_ID() != 0 && user != null)
            {
                MContactInterest ci = MContactInterest.Get(GetCtx(),
                                                           imp.GetR_InterestArea_ID(), user.GetAD_User_ID(),
                                                           true, Get_TrxName());
                ci.Save();              //	don't subscribe or re-activate
            }

            imp.SetAD_User_ID(user.GetAD_User_ID());
            imp.SetI_IsImported(true);
            imp.SetI_ErrorMsg(null);
            imp.Save();
            return(true);
        }       //	process
        protected override string DoIt()
        {
            if (p_AD_User_ID == -1)
            {
                p_AD_User_ID = GetAD_User_ID();
            }

            MUser user    = MUser.Get(GetCtx(), p_AD_User_ID);
            MUser current = MUser.Get(GetCtx(), GetAD_User_ID());


            if (!current.IsAdministrator() && p_AD_User_ID != GetAD_User_ID() && user.HasRole())
            {
                throw new ArgumentException("@UserCannotUpdate@");
            }

            // SuperUser and System passwords can only be updated by themselves
            if (user.IsSystemAdministrator() && p_AD_User_ID != GetAD_User_ID())
            {
                throw new ArgumentException("@UserCannotUpdate@");
            }


            if (string.IsNullOrEmpty(p_CurrentPassword))
            {
                if (string.IsNullOrEmpty(p_OldPassword))
                {
                    throw new ArgumentException("@OldPasswordMandatory@");
                }
                else if (!p_OldPassword.Equals(user.GetPassword()))
                {
                    if (!SecureEngineUtility.SecureEngine.Encrypt(p_OldPassword).Equals(user.GetPassword()))
                    {
                        throw new ArgumentException("@OldPasswordNoMatch@");
                    }
                }
            }

            else if (!p_CurrentPassword.Equals(current.GetPassword()))
            {
                throw new ArgumentException("@OldPasswordNoMatch@");
            }

            String originalPwd = p_NewPassword;

            String sql = "UPDATE AD_User SET Updated=SYSDATE, UpdatedBy=" + GetAD_User_ID();

            if (!string.IsNullOrEmpty(p_NewPassword))
            {
                MColumn column = MColumn.Get(GetCtx(), 417); // Password Column
                if (column.IsEncrypted())
                {
                    p_NewPassword = SecureEngineUtility.SecureEngine.Encrypt(p_NewPassword);
                }
                sql += ", Password="******", Email=" + GlobalVariable.TO_STRING(p_NewEMail);
            }
            if (!string.IsNullOrEmpty(p_NewEMailUser))
            {
                sql += ", EmailUser="******", EmailUserPW=" + GlobalVariable.TO_STRING(p_NewEMailUserPW);
            }
            sql += " WHERE AD_User_ID=" + p_AD_User_ID;

            int iRes = DB.ExecuteQuery(sql, null, Get_Trx());

            if (iRes > 0)
            {
                //user.SetPassword(p_NewPassword);
                user.SetPassword(originalPwd);
                return("OK");
            }
            else
            {
                return("@Error@");
            }
        }
        protected override string DoIt()
        {
            VLogger log = VLogger.GetVLogger(this.GetType().FullName);

            log.Log(Level.SEVERE, "UserPassword Change Log=>" + Convert.ToString(p_AD_User_ID));
            if (p_AD_User_ID == -1)
            {
                p_AD_User_ID = GetAD_User_ID();
            }

            MUser user    = MUser.Get(GetCtx(), p_AD_User_ID);
            MUser current = MUser.Get(GetCtx(), GetAD_User_ID());


            if (!current.IsAdministrator() && p_AD_User_ID != GetAD_User_ID() && user.HasRole())
            {
                throw new ArgumentException("@UserCannotUpdate@");
            }

            // SuperUser and System passwords can only be updated by themselves
            if (user.IsSystemAdministrator() && p_AD_User_ID != GetAD_User_ID() && GetAD_User_ID() != 100)
            {
                throw new ArgumentException("@UserCannotUpdate@");
            }

            log.Log(Level.SEVERE, "UserPassword Change Log Step Check for valid user=>" + Convert.ToString(p_AD_User_ID));
            if (string.IsNullOrEmpty(p_CurrentPassword))
            {
                if (string.IsNullOrEmpty(p_OldPassword))
                {
                    throw new ArgumentException("@OldPasswordMandatory@");
                }
                else if (!p_OldPassword.Equals(user.GetPassword()))
                {
                    if (!SecureEngine.Encrypt(p_OldPassword).Equals(user.GetPassword()))
                    {
                        throw new ArgumentException("@OldPasswordNoMatch@");
                    }
                }
            }

            else if (!p_CurrentPassword.Equals(current.GetPassword()))
            {
                throw new ArgumentException("@OldPasswordNoMatch@");
            }

            string validatePwd = Common.Common.ValidatePassword(null, p_NewPassword, p_NewPassword);

            if (validatePwd.Length > 0)
            {
                throw new ArgumentException(Msg.GetMsg(GetCtx(), validatePwd));
            }

            log.Log(Level.SEVERE, "UserPassword Change Log Step Password Change=>" + Convert.ToString(p_AD_User_ID));
            String originalPwd = p_NewPassword;

            String sql = "UPDATE AD_User SET Updated=SYSDATE,FailedloginCount=0, UpdatedBy=" + GetAD_User_ID();

            if (user.GetAD_User_ID() == current.GetAD_User_ID())
            {
                Common.Common.UpdatePasswordAndValidity(p_NewPassword, p_AD_User_ID, GetAD_User_ID(), -1, GetCtx());
            }
            else
            {
                sql += ",  PasswordExpireOn = null";
            }


            if (!string.IsNullOrEmpty(p_NewPassword))
            {
                MColumn column = MColumn.Get(GetCtx(), 417); // Password Column
                if (column.IsEncrypted())
                {
                    p_NewPassword = SecureEngine.Encrypt(p_NewPassword);
                }
                sql += ", Password="******", Email=" + GlobalVariable.TO_STRING(p_NewEMail);
            }
            if (!string.IsNullOrEmpty(p_NewEMailUser))
            {
                sql += ", EmailUser="******", EmailUserPW=" + GlobalVariable.TO_STRING(p_NewEMailUserPW);
            }
            sql += " WHERE AD_User_ID=" + p_AD_User_ID;
            log.Log(Level.SEVERE, "UserPassword Change Log=>" + sql);
            int iRes = DB.ExecuteQuery(sql, null, Get_Trx());

            if (iRes > 0)
            {
                return("@OK@");
            }
            else
            {
                return("@Error@");
            }
        }