/// <summary> /// Assign New Role to Current User. /// </summary> /// <param name="AD_Role_ID"></param> /// <param name="AD_User_ID"></param> private void CreateNewUserRole(int AD_Role_ID, int AD_User_ID) { MUserRoles role = new MUserRoles(ctx, 0, null); role.SetAD_Org_ID(ctx.GetAD_Org_ID()); role.SetAD_Client_ID(ctx.GetAD_Client_ID()); role.SetAD_User_ID(AD_User_ID); role.SetAD_Role_ID(AD_Role_ID); role.Save(); }
protected void Button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(Name.Value)) { return; } HttpRequest q = Request; string lang = q.QueryString["lang"]; usernotSaved = Msg.GetMsg(lang, "VIS_ErrorSavingUser"); Button1.Enabled = false; int AD_Client_ID = 0; int AD_Org_ID = 0; int inviteID = Convert.ToInt32(SecureEngine.Decrypt(q.QueryString["inviteID"])); String sql = "SELECT * FROM AD_InviteUser WHERE AD_InviteUser_ID=" + inviteID; DataSet dsIUser = DB.ExecuteDataset(sql); if (dsIUser != null && dsIUser.Tables[0].Rows.Count > 0) { AD_Org_ID = Convert.ToInt32(dsIUser.Tables[0].Rows[0]["AD_Org_ID"]); AD_Client_ID = Convert.ToInt32(dsIUser.Tables[0].Rows[0]["AD_Client_ID"]); } sql = "SELECT AD_Role_ID FROM ad_inviteuser_role WHERE AD_InviteUser_ID= " + inviteID; DataSet ds = DB.ExecuteDataset(sql); Ctx ctx = new Ctx(); ctx.SetAD_Client_ID(AD_Client_ID); ctx.SetAD_Org_ID(AD_Org_ID); MUser user = new MUser(ctx, 0, null); user.SetAD_Client_ID(AD_Client_ID); user.SetAD_Org_ID(AD_Org_ID); user.SetIsLoginUser(true); user.SetName(Name.Value); user.SetValue(userIDs.Value); user.SetEMail(email.Value); user.SetPassword(passwords.Value); user.SetMobile(mobile.Value); if (user.Save()) { if (ds != null && ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { MUserRoles uRoles = new MUserRoles(ctx, user.GetAD_User_ID(), Convert.ToInt32(ds.Tables[0].Rows[i]["AD_Role_ID"]), null); uRoles.SetAD_Client_ID(AD_Client_ID); uRoles.SetAD_Org_ID(AD_Org_ID); uRoles.Save(); } } sendMail.Visible = true; Name.Value = ""; userIDs.Value = ""; email.Value = ""; passwords.Value = ""; mobile.Value = ""; } else { Button1.Enabled = true; sendMail.InnerText = usernotSaved; sendMail.Visible = true; } }
} // sendAlert private int sendAlertToResponsible(MWFResponsible responsible, List <int> list, MWFProcess process, String subject, String message, FileInfo pdf) { int counter = 0; if (responsible.IsInvoker()) { ; } // Human else if (X_AD_WF_Responsible.RESPONSIBLETYPE_Human.Equals(responsible.GetResponsibleType()) && responsible.GetAD_User_ID() != 0 && !list.Contains(responsible.GetAD_User_ID())) { if (m_client.SendEMail(responsible.GetAD_User_ID(), subject, message, pdf)) { counter++; } list.Add(responsible.GetAD_User_ID()); } // Org of the Document else if (X_AD_WF_Responsible.RESPONSIBLETYPE_Organization.Equals(responsible.GetResponsibleType())) { PO document = process.GetPO(); if (document != null) { MOrgInfo org = MOrgInfo.Get(GetCtx(), document.GetAD_Org_ID(), null); if (org.GetSupervisor_ID() != 0 && !list.Contains(org.GetSupervisor_ID())) { if (m_client.SendEMail(org.GetSupervisor_ID(), subject, message, pdf)) { counter++; } list.Add(org.GetSupervisor_ID()); } } } // Role else if (X_AD_WF_Responsible.RESPONSIBLETYPE_Role.Equals(responsible.GetResponsibleType()) && responsible.GetAD_Role_ID() != 0) { MUserRoles[] userRoles = MUserRoles.GetOfRole(GetCtx(), responsible.GetAD_Role_ID()); for (int i = 0; i < userRoles.Length; i++) { MUserRoles roles = userRoles[i]; if (!roles.IsActive()) { continue; } int AD_User_ID = roles.GetAD_User_ID(); if (!list.Contains(AD_User_ID)) { if (m_client.SendEMail(AD_User_ID, subject, message, pdf)) { counter++; } list.Add(AD_User_ID); } } } return(counter); } // sendAlertToResponsible
} // doWork /** * Process Alert * @param alert alert * @return true if processed */ private bool ProcessAlert(MAlert alert) { if (!alert.IsValid()) { log.Info("Invalid: " + alert); return(false); } log.Info("" + alert); m_recipients.Clear(); StringBuilder message = new StringBuilder(alert.GetAlertMessage()) .Append(Env.NL); // Context Ctx ctx = alert.GetCtx(); ctx.SetAD_Client_ID(alert.GetAD_Client_ID()); ctx.SetAD_Org_ID(alert.GetAD_Org_ID()); // bool valid = true; bool processed = false; MAlertRule[] rules = alert.GetRules(false); for (int i = 0; i < rules.Length; i++) { if (i > 0) { message.Append(Env.NL).Append("================================").Append(Env.NL); } //Trx trx = null; // assume r/o MAlertRule rule = rules[i]; if (!rule.IsValid()) { log.Config("Invalid: " + rule); continue; } log.Fine("" + rule); // Pre String sql = rule.GetPreProcessing(); if (sql != null && sql.Length > 0) { int no = DB.ExecuteQuery(sql); if (no == -1) { ValueNamePair error = VLogger.RetrieveError(); rule.SetErrorMsg("Pre=" + error.GetName()); m_errors.Append("Pre=" + error.GetName()); rule.SetIsValid(false); rule.Save(); valid = false; break; } } // Pre // The processing ctx.SetAD_Role_ID(0); ctx.SetAD_User_ID(0); sql = rule.GetSql(); if (alert.IsEnforceRoleSecurity() || alert.IsEnforceClientSecurity()) { int AD_Role_ID = alert.GetFirstAD_Role_ID(); if (AD_Role_ID == -1) { AD_Role_ID = alert.GetFirstUserAD_Role_ID(); } if (AD_Role_ID != -1) { String tableName = rule.GetTableName(); bool fullyQualified = MRole.SQL_FULLYQUALIFIED; if (Util.IsEmpty(tableName)) { fullyQualified = MRole.SQL_NOTQUALIFIED; } MRole role = MRole.Get(ctx, AD_Role_ID, 0, false); sql = role.AddAccessSQL(sql, tableName, fullyQualified, MRole.SQL_RO); ctx.SetAD_Role_ID(AD_Role_ID); } if (alert.GetFirstAD_User_ID() != -1) { ctx.SetAD_User_ID(alert.GetFirstAD_User_ID()); } } try { String text = ListSqlSelect(sql); if (text != null && text.Length > 0) { message.Append(text); processed = true; int index = text.IndexOf(":"); if (index > 0 && index < 5) { m_summary.Append(text.Substring(0, index)); } } } catch (Exception e) { rule.SetErrorMsg("Select=" + e.Message); m_errors.Append("Select=" + e.Message); rule.SetIsValid(false); rule.Save(); valid = false; break; } // Post sql = rule.GetPostProcessing(); if (sql != null && sql.Length > 0) { int no = DB.ExecuteQuery(sql); if (no == -1) { ValueNamePair error = VLogger.RetrieveError(); rule.SetErrorMsg("Post=" + error.GetName()); m_errors.Append("Post=" + error.GetName()); rule.SetIsValid(false); rule.Save(); valid = false; break; } } // Post } // for all rules // Update header if error if (!valid) { alert.SetIsValid(false); alert.Save(); return(false); } // Nothing to report if (!processed) { m_summary.Append(alert.GetName()).Append("=No Result - "); return(true); } // Send Message int countRecipient = 0; MAlertRecipient[] recipients = alert.GetRecipients(false); for (int i = 0; i < recipients.Length; i++) { MAlertRecipient recipient = recipients[i]; if (recipient.GetAD_User_ID() >= 0) // System == 0 { if (SendInfo(recipient.GetAD_User_ID(), alert, message.ToString())) { countRecipient++; } } if (recipient.GetAD_Role_ID() >= 0) // SystemAdministrator == 0 { MUserRoles[] urs = MUserRoles.GetOfRole(GetCtx(), recipient.GetAD_Role_ID()); for (int j = 0; j < urs.Length; j++) { MUserRoles ur = urs[j]; if (!ur.IsActive()) { continue; } if (SendInfo(ur.GetAD_User_ID(), alert, message.ToString())) { countRecipient++; } } } } m_summary.Append(alert.GetName()).Append(" (Recipients=").Append(countRecipient).Append(") - "); return(valid); } // processAlert