/// <summary> /// Mass operation button "OK" click. /// </summary> protected void btnOk_Click(object sender, EventArgs e) { // Get where condition depending on mass action selection string where = null; What what = (What)ValidationHelper.GetInteger(drpWhat.SelectedValue, 0); switch (what) { // All items case What.All: where = SqlHelperClass.AddWhereCondition(gridElem.WhereCondition, gridElem.WhereClause); break; // Selected items case What.Selected: where = SqlHelperClass.GetWhereCondition <int>("AccountID", gridElem.SelectedItems, false); break; } Action action = (Action)ValidationHelper.GetInteger(drpAction.SelectedItem.Value, 0); switch (action) { // Action 'Change status' case Action.ChangeStatus: // Get selected status ID from hidden field int statusId = ValidationHelper.GetInteger(hdnIdentifier.Value, -1); // If status ID is 0, the status will be removed if (statusId >= 0) { AccountInfoProvider.UpdateAccountStatus(statusId, where); ShowConfirmation(GetString("om.account.massaction.statuschanged")); } break; // Action 'Add to contact group' case Action.AddToGroup: // Get contact group ID from hidden field int groupId = ValidationHelper.GetInteger(hdnIdentifier.Value, 0); if (groupId > 0) { List <string> accountIds = null; switch (what) { // All items case What.All: // Get selected IDs based on where condition DataSet accounts = AccountInfoProvider.GetAccounts(where, null, 0, "AccountID"); if (!DataHelper.DataSourceIsEmpty(accounts)) { // Get array list with IDs accountIds = DataHelper.GetUniqueValues(accounts.Tables[0], "AccountID", true); } break; // Selected items case What.Selected: // Get selected IDs from UniGrid accountIds = gridElem.SelectedItems; break; } if (accountIds != null) { // Add each selected account to the contact group, skip accounts that are already members of the group foreach (string item in accountIds) { int accountId = ValidationHelper.GetInteger(item, 0); if ((accountId > 0) && (ContactGroupMemberInfoProvider.GetContactGroupMemberInfoByData(groupId, accountId, ContactGroupMemberTypeEnum.Account) == null)) { ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(groupId, accountId, ContactGroupMemberTypeEnum.Account, MemberAddedHowEnum.Account); } } // Get contact group to show result message with its display name ContactGroupInfo group = ContactGroupInfoProvider.GetContactGroupInfo(groupId); if (group != null) { ShowConfirmation(String.Format(GetString("om.account.massaction.addedtogroup"), ResHelper.LocalizeString(group.ContactGroupDisplayName))); } } } break; // Merge click case Action.Merge: DataSet selectedAccounts = AccountHelper.GetAccounListInfos(null, where, null, -1, null); if (!DataHelper.DataSourceIsEmpty(selectedAccounts)) { // Get selected account ID from hidden field int accountID = ValidationHelper.GetInteger(hdnIdentifier.Value, -1); // If account ID is 0 then new contact must be created if (accountID == 0) { int siteID; if (filter.DisplaySiteSelector || filter.DisplayGlobalOrSiteSelector) { siteID = filter.SelectedSiteID; } else { siteID = SiteID; } SetDialogParameters(selectedAccounts, AccountHelper.GetNewAccount(AccountHelper.MERGED, siteID)); } // Selected contact to be merged into else if (accountID > 0) { SetDialogParameters(selectedAccounts, AccountInfoProvider.GetAccountInfo(accountID)); } OpenWindow(); } break; default: return; } // Reload UniGrid gridElem.ClearSelectedItems(); gridElem.ReloadData(); pnlUpdate.Update(); }
/// <summary> /// OnAfterSave event handler. /// </summary> protected void EditForm_OnAfterSave(object sender, EventArgs e) { // Get edited contact group ContactGroupInfo cgi = (ContactGroupInfo)EditForm.EditedObject; if (chkDynamic.Checked) { // Set info for scheduled task task = GetScheduledTask(cgi); // Update scheduled task if (chkSchedule.Checked) { if (!schedulerInterval.CheckOneDayMinimum()) { // If problem occurred while setting schedule interval EditForm.ErrorLabel.Text = GetString("Newsletter_Edit.NoDaySelected"); EditForm.ErrorLabel.Visible = true; EditForm.StopProcessing = true; return; } if (!IsValidDate(SchedulingHelper.DecodeInterval(schedulerInterval.ScheduleInterval).StartTime)) { // Start date is not in valid format EditForm.ErrorLabel.Text = GetString("Newsletter.IncorrectDate"); EditForm.ErrorLabel.Visible = true; EditForm.StopProcessing = true; return; } task.TaskInterval = schedulerInterval.ScheduleInterval; task.TaskNextRunTime = SchedulingHelper.GetNextTime(task.TaskInterval, new DateTime(), new DateTime()); task.TaskEnabled = true; } else { task.TaskInterval = schedulerInterval.ScheduleInterval; task.TaskNextRunTime = TaskInfoProvider.NO_TIME; task.TaskEnabled = false; } TaskInfoProvider.SetTaskInfo(task); cgi.ContactGroupScheduledTaskID = task.TaskID; pnlInfo.Visible = true; InitInfoPanel(cgi, true); } else { if (cgi.ContactGroupScheduledTaskID > 0) { // Store task ID for deletion deleteScheduledTaskId = cgi.ContactGroupScheduledTaskID; } cgi.ContactGroupScheduledTaskID = 0; cgi.ContactGroupStatus = ContactGroupStatusEnum.Unspecified; schedulerInterval.Visible = false; pnlInfo.Visible = false; } // Update contact group ContactGroupInfoProvider.SetContactGroupInfo(cgi); if (deleteScheduledTaskId > 0) { // Delete scheduled task if schedule evaluation was unchecked TaskInfoProvider.DeleteTaskInfo(deleteScheduledTaskId); } InitHeaderActions(false); ((CMSPage)Page).CurrentMaster.HeaderActions.ReloadData(); // Refresh breadcrumbs after data are loaded ScriptHelper.RefreshTabHeader(Page, null); }
/// <summary> /// Loads contact groups of merged contacts into checkboxlist. /// </summary> private void LoadContactGroups() { if (!RequestHelper.IsPostBack()) { StringBuilder idList = new StringBuilder("("); foreach (DataRow dr in mergedAccounts.Tables[0].Rows) { idList.Append(dr["AccountID"] + ","); } // Remove last comma idList.Remove(idList.Length - 1, 1); idList.Append(")"); // Remove site contact groups string addWhere = null; if (parentAccount.AccountSiteID == 0) { addWhere = " AND ContactGroupMemberContactGroupID IN (SELECT ContactGroupID FROM OM_ContactGroup WHERE ContactGroupSiteID IS NULL)"; } string where = "ContactGroupMemberType = 1 AND ContactGroupMemberRelatedID IN " + idList.ToString() + " AND ContactGroupMemberContactGroupID NOT IN (SELECT ContactGroupMemberContactGroupID FROM OM_ContactGroupMember WHERE ContactGroupMemberRelatedID = " + parentAccount.AccountID + " AND ContactGroupMemberType = 1)" + addWhere; // Limit selection of contact groups according to current user's permissions if (!CMSContext.CurrentUser.UserSiteManagerAdmin) { bool readModifySite = ContactGroupHelper.AuthorizedReadContactGroup(parentAccount.AccountSiteID, false) && ContactGroupHelper.AuthorizedModifyContactGroup(parentAccount.AccountSiteID, false); bool readGlobal = ContactGroupHelper.AuthorizedReadContactGroup(UniSelector.US_GLOBAL_RECORD, false) && ContactGroupHelper.AuthorizedModifyContactGroup(UniSelector.US_GLOBAL_RECORD, false); if (!readModifySite && !readGlobal) { tabContactGroups.Visible = false; tabContactGroups.HeaderText = null; } else if (readModifySite && !readGlobal) { where = SqlHelperClass.AddWhereCondition(where, " ContactGroupMemberContactGroupID IN (SELECT ContactGroupID FROM OM_ContactGroup WHERE ContactGroupSiteID = " + CMSContext.CurrentSiteID + ")"); } else if (!readModifySite && readGlobal) { where = SqlHelperClass.AddWhereCondition(where, " ContactGroupMemberContactGroupID IN (SELECT ContactGroupID FROM OM_ContactGroup WHERE ContactGroupSiteID IS NULL)"); } else { where = SqlHelperClass.AddWhereCondition(where, " ContactGroupMemberContactGroupID IN (SELECT ContactGroupID FROM OM_ContactGroup WHERE ContactGroupSiteID IS NULL OR ContactGroupSiteID = " + CMSContext.CurrentSiteID + ")"); } } // Get contact group relations DataSet result = ContactGroupMemberInfoProvider.GetRelationships(where, null, -1, "DISTINCT ContactGroupMemberContactGroupID"); if (!DataHelper.DataSourceIsEmpty(result)) { ListItem contactGroup; ContactGroupInfo cg; foreach (DataRow dr in result.Tables[0].Rows) { contactGroup = new ListItem(); contactGroup.Value = ValidationHelper.GetString(dr["ContactGroupMemberContactGroupID"], "0"); contactGroup.Selected = true; // Fill in checkbox list cg = ContactGroupInfoProvider.GetContactGroupInfo(ValidationHelper.GetInteger(dr["ContactGroupMemberContactGroupID"], 0)); if (cg != null) { contactGroup.Text = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(cg.ContactGroupDisplayName)); chkContactGroups.Items.Add(contactGroup); } } } else { tabContactGroups.Visible = false; tabContactGroups.HeaderText = null; } } }
private IEnumerable <KeyValuePair <string, string> > GetMetricData() { string stringData = null; IEnumerable <KeyValuePair <string, string> > tupleData = null; // Gather data for each row, return special message if data is null switch (MetricCodeName) { // Categories case MetricDataEnum.support_metrics: case MetricDataEnum.support_metrics_system: case MetricDataEnum.support_metrics_environment: case MetricDataEnum.support_metrics_counters: case MetricDataEnum.support_metrics_ecommerce: case MetricDataEnum.support_metrics_tasks: case MetricDataEnum.support_metrics_eventlog: return(null); #region System case MetricDataEnum.support_metrics_system_version: stringData = CMSVersion.GetVersion(true, true, true, true); break; case MetricDataEnum.support_metrics_system_appname: stringData = SettingsHelper.AppSettings["CMSApplicationName"]; break; case MetricDataEnum.support_metrics_system_instancename: stringData = SystemContext.InstanceName; break; case MetricDataEnum.support_metrics_system_physicalpath: stringData = SystemContext.WebApplicationPhysicalPath; break; case MetricDataEnum.support_metrics_system_apppath: stringData = SystemContext.ApplicationPath; break; case MetricDataEnum.support_metrics_system_uiculture: stringData = LocalizationContext.CurrentUICulture.CultureName; break; case MetricDataEnum.support_metrics_system_installtype: stringData = SystemContext.IsWebApplicationProject ? "Web App" : "Web site"; break; case MetricDataEnum.support_metrics_system_portaltemplatepage: stringData = URLHelper.PortalTemplatePage; break; case MetricDataEnum.support_metrics_system_timesinceapprestart: stringData = (DateTime.Now - CMSApplication.ApplicationStart).ToString(@"dd\:hh\:mm\:ss"); break; case MetricDataEnum.support_metrics_system_discoveredassemblies: tupleData = AssemblyDiscoveryHelper.GetAssemblies(true).Select((a, i) => GetKeyValuePair(i, a.FullName)); break; case MetricDataEnum.support_metrics_system_targetframework: HttpRuntimeSection httpRuntime = ConfigurationManager.GetSection("system.web/httpRuntime") as HttpRuntimeSection; stringData = httpRuntime.TargetFramework; break; case MetricDataEnum.support_metrics_system_authmode: AuthenticationSection Authentication = ConfigurationManager.GetSection("system.web/authentication") as AuthenticationSection; stringData = Authentication?.Mode.ToString(); break; case MetricDataEnum.support_metrics_system_sessionmode: SessionStateSection SessionState = ConfigurationManager.GetSection("system.web/sessionState") as SessionStateSection; stringData = SessionState?.Mode.ToString(); break; case MetricDataEnum.support_metrics_system_debugmode: CompilationSection Compilation = ConfigurationManager.GetSection("system.web/compilation") as CompilationSection; stringData = Compilation?.Debug.ToString(); break; case MetricDataEnum.support_metrics_system_runallmanagedmodules: var xmlDoc = new System.Xml.XmlDocument(); xmlDoc.Load(URLHelper.GetPhysicalPath("~/Web.config")); stringData = xmlDoc.SelectSingleNode("/configuration/system.webServer/modules").Attributes["runAllManagedModulesForAllRequests"]?.Value; break; #endregion System #region Environment case MetricDataEnum.support_metrics_environment_trustlevel: AspNetHostingPermissionLevel trustLevel = AspNetHostingPermissionLevel.None; if (!SystemContext.IsWebSite) { trustLevel = AspNetHostingPermissionLevel.Unrestricted; } // Check the trust level by evaluation of levels foreach (AspNetHostingPermissionLevel permissionLevel in new[] { AspNetHostingPermissionLevel.Unrestricted, AspNetHostingPermissionLevel.High, AspNetHostingPermissionLevel.Medium, AspNetHostingPermissionLevel.Low, AspNetHostingPermissionLevel.Minimal }) { try { new AspNetHostingPermission(permissionLevel).Demand(); } catch (SecurityException) { continue; } trustLevel = permissionLevel; break; } stringData = trustLevel.ToString(); break; case MetricDataEnum.support_metrics_environment_iisversion: stringData = MetricServerVariables["SERVER_SOFTWARE"]; break; case MetricDataEnum.support_metrics_environment_https: stringData = MetricServerVariables["HTTPS"]; break; case MetricDataEnum.support_metrics_environment_windowsversion: using (RegistryKey versionKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion")) { var productName = versionKey?.GetValue("ProductName"); var currentBuild = versionKey?.GetValue("CurrentBuild"); var releaseId = versionKey?.GetValue("ReleaseId"); stringData = String.Format("{0}, build {1}, release {2}", productName.ToString(), currentBuild.ToString(), releaseId.ToString()); } break; case MetricDataEnum.support_metrics_environment_netversion: using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\")) { var keyValue = ndpKey?.GetValue("Release"); if (keyValue != null) { var releaseKey = (int)keyValue; if (releaseKey >= 461808) { stringData = "4.7.2 or later"; } else if (releaseKey >= 461308) { stringData = "4.7.1"; } else if (releaseKey >= 460798) { stringData = "4.7"; } else if (releaseKey >= 394802) { stringData = "4.6.2"; } else if (releaseKey >= 394254) { stringData = "4.6.1"; } else if (releaseKey >= 393295) { stringData = "4.6"; } else if (releaseKey >= 379893) { stringData = "4.5.2"; } else if (releaseKey >= 378675) { stringData = "4.5.1"; } else if (releaseKey >= 378389) { stringData = "4.5"; } } } break; case MetricDataEnum.support_metrics_environment_sqlserverversion: var dtm = new TableManager(null); stringData = dtm.DatabaseServerVersion; break; case MetricDataEnum.support_metrics_environment_azure: var azureStats = new Dictionary <string, string>(4) { { "Is a Cloud Service", (SettingsHelper.AppSettings["CMSAzureProject"] == "true").ToString("false") }, { "Is file system on Azure", (SettingsHelper.AppSettings["CMSExternalStorageName"] == "azure").ToString("false") }, { "Azure storage account", SettingsHelper.AppSettings["CMSAzureAccountName"] ?? String.Empty }, { "Azure CDN endpoint", SettingsHelper.AppSettings["CMSAzureCDNEndpoint"] ?? String.Empty } }; tupleData = azureStats.Select(s => GetKeyValuePair(s.Key, s.Value)); break; case MetricDataEnum.support_metrics_environment_amazon: var amazonStats = new Dictionary <string, string>(3) { { "Is file system on Amazon", (SettingsHelper.AppSettings["CMSExternalStorageName"] == "amazon").ToString() }, { "Amazon bucket name", SettingsHelper.AppSettings["CMSAmazonBucketName"] ?? String.Empty }, { "Amazon public access", SettingsHelper.AppSettings["CMSAmazonPublicAccess"] ?? String.Empty }, }; tupleData = amazonStats.Select(s => GetKeyValuePair(s.Key, s.Value)); break; case MetricDataEnum.support_metrics_environment_services: tupleData = ServiceManager.GetServices().Select(s => GetKeyValuePair(s.ServiceName, s.Status)); break; #endregion Environment #region Counters case MetricDataEnum.support_metrics_counters_webfarmservers: stringData = CoreServices.WebFarm.GetEnabledServerNames().Count().ToString(); break; case MetricDataEnum.support_metrics_counters_stagingservers: stringData = ServerInfoProvider.GetServers().GetCount().ToString(); break; case MetricDataEnum.support_metrics_counters_pagemostchildren: CMS.DocumentEngine.TreeProvider tree = new CMS.DocumentEngine.TreeProvider(); var pageWithMostChildren = tree.SelectNodes().OnCurrentSite().Published() .ToDictionary(n => n, n => n.Children.Count) .Aggregate((l, r) => l.Value > r.Value ? l : r); tupleData = new[] { GetKeyValuePair(URLHelper.GetAbsoluteUrl("~" + pageWithMostChildren.Key.NodeAliasPath), pageWithMostChildren.Value) }; break; case MetricDataEnum.support_metrics_counters_modules: stringData = ResourceInfoProvider.GetResources().GetCount().ToString(); break; case MetricDataEnum.support_metrics_counters_medialibraries: stringData = MediaLibraryInfoProvider.GetMediaLibraries().WhereNull("LibraryGroupID").GetCount().ToString(); break; case MetricDataEnum.support_metrics_counters_activities: stringData = ActivityInfoProvider.GetActivities().GetCount().ToString(); break; case MetricDataEnum.support_metrics_counters_contacts: stringData = ContactInfoProvider.GetContacts().GetCount().ToString(); break; case MetricDataEnum.support_metrics_counters_contactgroups: stringData = ContactGroupInfoProvider.GetContactGroups().GetCount().ToString(); break; case MetricDataEnum.support_metrics_counters_omrules: stringData = RuleInfoProvider.GetRules().GetCount().ToString(); break; case MetricDataEnum.support_metrics_counters_products: stringData = SKUInfoProvider.GetSKUs(SiteContext.CurrentSiteID).WhereNull("SKUOptionCategoryID").GetCount().ToString(); break; #endregion Counters #region Tasks case MetricDataEnum.support_metrics_tasks_webfarm: stringData = WebFarmTaskInfoProvider.GetWebFarmTasks() .WhereLessThan("TaskCreated", DateTime.Now.AddDays(-1)) .GetCount().ToString(); break; case MetricDataEnum.support_metrics_tasks_staging: stringData = StagingTaskInfoProvider.GetTasks() .WhereLessThan("TaskTime", DateTime.Now.AddDays(-1)) .GetCount().ToString(); break; case MetricDataEnum.support_metrics_tasks_integration: stringData = IntegrationTaskInfoProvider.GetIntegrationTasks() .WhereLessThan("TaskTime", DateTime.Now.AddDays(-1)) .GetCount().ToString(); break; case MetricDataEnum.support_metrics_tasks_scheduled: stringData = TaskInfoProvider.GetTasks() .WhereTrue("TaskDeleteAfterLastRun") .WhereLessThan("TaskNextRunTime", DateTime.Now.AddDays(-1)) .GetCount().ToString(); break; case MetricDataEnum.support_metrics_tasks_search: stringData = SearchTaskInfoProvider.GetSearchTasks() .WhereLessThan("SearchTaskCreated", DateTime.Now.AddDays(-1)) .GetCount().ToString(); break; case MetricDataEnum.support_metrics_tasks_email: stringData = EmailInfoProvider.GetEmailCount("EmailStatus = 1 AND EmailLastSendResult IS NOT NULL").ToString(); break; #endregion Tasks #region Event log case MetricDataEnum.support_metrics_eventlog_macroerrors: var macroErrors = EventLogProvider.GetEvents() .WhereEquals("Source", "MacroResolver") .WhereGreaterThan("EventTime", DateTime.Now.Subtract(TimeSpan.FromDays(7))) .OrderByDescending("EventTime") .TopN(10); tupleData = macroErrors.Select(e => GetKeyValuePair(String.Format("{0} from {1} at {2} in {3}", e.EventCode, e.Source, e.EventTime, e.EventMachineName), e.EventDescription.Length > CUTOFF ? e.EventDescription.Substring(0, CUTOFF) : e.EventDescription) ); break; case MetricDataEnum.support_metrics_eventlog_stagingerrors: var stagingErrors = EventLogProvider.GetEvents() .WhereEquals("Source", "staging") .WhereIn("EventType", new[] { "E", "W" }) .WhereGreaterThan("EventTime", DateTime.Now.Subtract(TimeSpan.FromDays(7))) .OrderByDescending("EventTime") .TopN(10); tupleData = stagingErrors.Select(e => GetKeyValuePair(String.Format("{0} from {1} at {2} in {3}", e.EventCode, e.Source, e.EventTime, e.EventMachineName), e.EventDescription.Length > CUTOFF ? e.EventDescription.Substring(0, CUTOFF) : e.EventDescription) ); break; case MetricDataEnum.support_metrics_eventlog_searcherrors: var searchErrors = EventLogProvider.GetEvents() .WhereEquals("Source", "search") .WhereIn("EventType", new[] { "E", "W" }) .WhereGreaterThan("EventTime", DateTime.Now.Subtract(TimeSpan.FromDays(7))) .OrderByDescending("EventTime") .TopN(10); tupleData = searchErrors.Select(e => GetKeyValuePair(String.Format("{0} from {1} at {2} in {3}", e.EventCode, e.Source, e.EventTime, e.EventMachineName), e.EventDescription.Length > CUTOFF ? e.EventDescription.Substring(0, CUTOFF) : e.EventDescription) ); break; case MetricDataEnum.support_metrics_eventlog_contenterrors: var contentErrors = EventLogProvider.GetEvents() .WhereEquals("Source", "content") .WhereIn("EventType", new[] { "E", "W" }) .WhereGreaterThan("EventTime", DateTime.Now.Subtract(TimeSpan.FromDays(7))) .OrderByDescending("EventTime") .TopN(10); tupleData = contentErrors.Select(e => GetKeyValuePair(String.Format("{0} from {1} at {2} in {3}", e.EventCode, e.Source, e.EventTime, e.EventMachineName), e.EventDescription.Length > CUTOFF ? e.EventDescription.Substring(0, CUTOFF) : e.EventDescription) ); break; case MetricDataEnum.support_metrics_eventlog_exceptions: var exceptions = EventLogProvider.GetEvents() .WhereEquals("EventCode", "exception") .WhereGreaterThan("EventTime", DateTime.Now.Subtract(TimeSpan.FromDays(7))) .OrderByDescending("EventTime") .TopN(10); tupleData = exceptions.Select(e => GetKeyValuePair(String.Format("{0} from {1} at {2} in {3}", e.EventCode, e.Source, e.EventTime, e.EventMachineName), e.EventDescription.Length > CUTOFF ? e.EventDescription.Substring(0, CUTOFF) : e.EventDescription) ); break; case MetricDataEnum.support_metrics_eventlog_upgrade: EventLogInfo upgrade = EventLogProvider.GetEvents().WhereLike("Source", "upgrade%").FirstOrDefault(); var version = upgrade?.Source.Split(' ')[2]; if (!String.IsNullOrEmpty(version)) { var parameters = new QueryDataParameters { { "@versionnumber", version } }; var events = ConnectionHelper.ExecuteQuery("SupportHelper.CustomMetric.checkupgrade", parameters); tupleData = (from DataRow row in events.Tables[0]?.Rows select row) .Select(r => new EventLogInfo(r)).Select(e => GetKeyValuePair(String.Format("{0} from {1} at {2} in {3}", e.EventCode, e.Source, e.EventTime, e.EventMachineName), e.EventDescription.Length > CUTOFF ? e.EventDescription.Substring(0, CUTOFF) : e.EventDescription) ); } break; #endregion Event log } if (tupleData?.Count() > 0) { return(tupleData); } if (stringData != null) { return(new[] { GetKeyValuePair(0, stringData) }); } return(new[] { GetKeyValuePair(0, ResHelper.GetStringFormat("support.metrics.invalid", MetricDisplayName, MetricCodeName)) }); }
/// <summary> /// Loads contact groups of merged contacts into checkboxlist. /// </summary> private void LoadContactGroups() { if (!RequestHelper.IsPostBack()) { StringBuilder idList = new StringBuilder("("); foreach (DataRow dr in mMergedContacts.Tables[0].Rows) { idList.Append(dr["ContactID"] + ","); } // Remove last comma idList.Remove(idList.Length - 1, 1); idList.Append(")"); // Remove site contact groups for global contact string addWhere = null; if (mParentContact.ContactSiteID == 0) { addWhere = " AND ContactGroupMemberContactGroupID IN (SELECT ContactGroupID FROM OM_ContactGroup WHERE ContactGroupSiteID IS NULL)"; } string where = " ContactGroupMemberType = 0 AND ContactGroupMemberRelatedID IN " + idList + " AND ContactGroupMemberContactGroupID NOT IN (SELECT ContactGroupMemberContactGroupID FROM OM_ContactGroupMember WHERE ContactGroupMemberRelatedID = " + mParentContact.ContactID + " AND ContactGroupMemberType = 0)" + addWhere; // Show only manually added contact groups where = SqlHelper.AddWhereCondition(where, "ContactGroupMemberFromManual = 1"); // Limit selection of contact groups according to current user's permissions if (!MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin)) { bool readModifySite = ContactGroupHelper.AuthorizedReadContactGroup(mParentContact.ContactSiteID, false) && ContactGroupHelper.AuthorizedModifyContactGroup(mParentContact.ContactSiteID, false); bool readModifyGlobal = ContactGroupHelper.AuthorizedReadContactGroup(UniSelector.US_GLOBAL_RECORD, false) && ContactGroupHelper.AuthorizedModifyContactGroup(UniSelector.US_GLOBAL_RECORD, false); if (!readModifySite && !readModifyGlobal) { tabContactGroups.Visible = false; tabContactGroups.HeaderText = null; } else if (readModifySite && !readModifyGlobal) { where = SqlHelper.AddWhereCondition(where, " ContactGroupMemberContactGroupID IN (SELECT ContactGroupID FROM OM_ContactGroup WHERE ContactGroupSiteID = " + SiteContext.CurrentSiteID + ")"); } else if (!readModifySite && readModifyGlobal) { where = SqlHelper.AddWhereCondition(where, " ContactGroupMemberContactGroupID IN (SELECT ContactGroupID FROM OM_ContactGroup WHERE ContactGroupSiteID IS NULL)"); } else { where = SqlHelper.AddWhereCondition(where, " ContactGroupMemberContactGroupID IN (SELECT ContactGroupID FROM OM_ContactGroup WHERE ContactGroupSiteID IS NULL OR ContactGroupSiteID = " + SiteContext.CurrentSiteID + ")"); } } // Get contact group relations DataSet result = ContactGroupMemberInfoProvider.GetRelationships().Where(where).Column("ContactGroupMemberContactGroupID").Distinct(); if (!DataHelper.DataSourceIsEmpty(result)) { ListItem contactGroup; ContactGroupInfo cg; foreach (DataRow dr in result.Tables[0].Rows) { contactGroup = new ListItem(); contactGroup.Value = ValidationHelper.GetString(dr["ContactGroupMemberContactGroupID"], "0"); contactGroup.Selected = true; cg = ContactGroupInfoProvider.GetContactGroupInfo(ValidationHelper.GetInteger(dr["ContactGroupMemberContactGroupID"], 0)); if (cg != null) { contactGroup.Text = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(cg.ContactGroupDisplayName)); chkContactGroups.Items.Add(contactGroup); } } } else { tabContactGroups.Visible = false; tabContactGroups.HeaderText = null; } } }
/// <summary> /// Mass operation button "OK" click. /// </summary> protected void btnOk_Click(object sender, EventArgs e) { string resultMessage = string.Empty; // Get where condition depending on mass action selection string where; List <string> contactIds = null; What what = (What)ValidationHelper.GetInteger(drpWhat.SelectedValue, 0); switch (what) { // All items case What.All: // Get all contacts with scores based on filter condition var contacts = GetContactsWithScore(); if (!DataHelper.DataSourceIsEmpty(contacts)) { // Get array list with IDs contactIds = DataHelper.GetUniqueValues(contacts.Tables[0], "ContactID", true); } break; // Selected items case What.Selected: // Get selected IDs from unigrid contactIds = gridElem.SelectedItems; break; } // Prepare where condition if ((contactIds != null) && (contactIds.Count > 0)) { where = SqlHelper.GetWhereCondition <int>("ContactID", contactIds, false); } else { where = "0=1"; } Action action = (Action)ValidationHelper.GetInteger(drpAction.SelectedItem.Value, 0); switch (action) { // Action 'Change status' case Action.ChangeStatus: // Get selected status ID from hidden field int statusId = ValidationHelper.GetInteger(hdnIdentifier.Value, -1); // If status ID is 0, the status will be removed if (statusId >= 0) { ContactInfoProvider.UpdateContactStatus(statusId, where); resultMessage = GetString("om.contact.massaction.statuschanged"); } break; // Action 'Add to contact group' case Action.AddToGroup: // Get contact group ID from hidden field int groupId = ValidationHelper.GetInteger(hdnIdentifier.Value, 0); if ((groupId > 0) && (contactIds != null)) { // Add each selected contact to the contact group, skip contacts that are already members of the group foreach (string item in contactIds) { int contactId = ValidationHelper.GetInteger(item, 0); if (contactId > 0) { ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(groupId, contactId, ContactGroupMemberTypeEnum.Contact, MemberAddedHowEnum.Manual); } } // Get contact group to show result message with its display name ContactGroupInfo group = ContactGroupInfoProvider.GetContactGroupInfo(groupId); if (group != null) { resultMessage = string.Format(GetString("om.contact.massaction.addedtogroup"), HTMLHelper.HTMLEncode(group.ContactGroupDisplayName)); } } break; default: return; } if (!string.IsNullOrEmpty(resultMessage)) { lblInfo.Text = resultMessage; lblInfo.Visible = true; } // Reload unigrid gridElem.ResetSelection(); gridElem.ReloadData(); pnlUpdate.Update(); }
/// <summary> /// Actions handler. /// </summary> protected void HeaderActions_ActionPerformed(object sender, CommandEventArgs e) { if (ContactGroupHelper.AuthorizedModifyContactGroup(SiteID, true)) { switch (e.CommandName.ToLowerCSafe()) { case "save": if (chkDynamic.Checked) { // Get scheduled interval string scheduleInterval = schedulerInterval.ScheduleInterval; } // Save changes in the contact group if (EditForm.SaveData(null)) { mBtnEvaluate.Visible = chkDynamic.Checked; ScriptHelper.RefreshTabHeader(Page, null); } break; case "evaluate": if (EditForm.EditedObject != null) { ContactGroupInfo cgi = (ContactGroupInfo)EditForm.EditedObject; if (cgi != null) { // Set 'Rebuilding' status cgi.ContactGroupStatus = ContactGroupStatusEnum.Rebuilding; ContactGroupInfoProvider.SetContactGroupInfo(cgi); // Evaluate the membership of the contact group ContactGroupEvaluator evaluator = new ContactGroupEvaluator(); evaluator.ContactGroupID = cgi.ContactGroupID; evaluator.Execute(null); EditForm.InfoLabel.Text = GetString("om.contactgroup.evaluationstarted"); EditForm.InfoLabel.Visible = true; // Get scheduled task and update last run time if (cgi.ContactGroupScheduledTaskID > 0) { task = TaskInfoProvider.GetTaskInfo(cgi.ContactGroupScheduledTaskID); if (task != null) { task.TaskLastRunTime = DateTime.Now; TaskInfoProvider.SetTaskInfo(task); // Initialize interval control schedulerInterval.ScheduleInterval = task.TaskInterval; schedulerInterval.ReloadData(); } } // Display basic info about dynamic contact group InitInfoPanel(cgi, false); } } break; } } }
/// <summary> /// Mass operation button "OK" click. /// </summary> protected void btnOk_Click(object sender, EventArgs e) { // Get where condition depending on mass action selection string where = null; What what = (What)ValidationHelper.GetInteger(drpWhat.SelectedValue, 0); switch (what) { // All items case What.All: where = SqlHelper.AddWhereCondition(gridElem.WhereCondition, gridElem.WhereClause); break; // Selected items case What.Selected: where = SqlHelper.GetWhereCondition <int>("AccountID", gridElem.SelectedItems, false); break; } Action action = (Action)ValidationHelper.GetInteger(drpAction.SelectedItem.Value, 0); switch (action) { // Action 'Change status' case Action.ChangeStatus: { // Get selected status ID from hidden field int statusId = ValidationHelper.GetInteger(hdnIdentifier.Value, -1); // If status ID is 0, the status will be removed if (statusId >= 0) { AccountInfoProvider.UpdateAccountStatus(statusId, where); ShowConfirmation(GetString("om.account.massaction.statuschanged")); } } break; // Action 'Add to contact group' case Action.AddToGroup: { // Get contact group ID from hidden field int groupId = ValidationHelper.GetInteger(hdnIdentifier.Value, 0); if (groupId > 0) { IEnumerable <string> accountIds = null; switch (what) { // All items case What.All: // Get selected IDs based on where condition DataSet accounts = AccountInfoProvider.GetAccounts().Where(where).Column("AccountID"); if (!DataHelper.DataSourceIsEmpty(accounts)) { // Get array list with IDs accountIds = DataHelper.GetUniqueValues(accounts.Tables[0], "AccountID", true); } break; // Selected items case What.Selected: // Get selected IDs from UniGrid accountIds = gridElem.SelectedItems; break; } if (accountIds != null) { // Add each selected account to the contact group, skip accounts that are already members of the group foreach (string item in accountIds) { int accountId = ValidationHelper.GetInteger(item, 0); if ((accountId > 0) && (ContactGroupMemberInfoProvider.GetContactGroupMemberInfoByData(groupId, accountId, ContactGroupMemberTypeEnum.Account) == null)) { ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(groupId, accountId, ContactGroupMemberTypeEnum.Account, MemberAddedHowEnum.Account); } } // Get contact group to show result message with its display name ContactGroupInfo group = ContactGroupInfoProvider.GetContactGroupInfo(groupId); if (group != null) { ShowConfirmation(String.Format(GetString("om.account.massaction.addedtogroup"), ResHelper.LocalizeString(group.ContactGroupDisplayName))); } } } } break; default: return; } // Reload UniGrid gridElem.ResetSelection(); gridElem.ReloadData(); pnlUpdate.Update(); }
/// <summary> /// Mass operation button "OK" click. /// </summary> protected void btnOk_Click(object sender, EventArgs e) { // Get where condition depending on mass action selection string where = null; What what = (What)ValidationHelper.GetInteger(drpWhat.SelectedValue, 0); switch (what) { // All items case What.All: where = SqlHelper.AddWhereCondition(gridElem.WhereCondition, gridElem.WhereClause); break; // Selected items case What.Selected: where = SqlHelper.GetWhereCondition <int>("ContactID", gridElem.SelectedItems, false); break; } Action action = (Action)ValidationHelper.GetInteger(drpAction.SelectedItem.Value, 0); switch (action) { // Action 'Change status' case Action.ChangeStatus: // Get selected status ID from hidden field int statusId = ValidationHelper.GetInteger(hdnIdentifier.Value, -1); // If status ID is 0, the status will be removed if (statusId >= 0) { ContactInfoProvider.UpdateContactStatus(statusId, where); ShowConfirmation(GetString("om.contact.massaction.statuschanged")); } break; // Action 'Add to contact group' case Action.AddToGroup: // Get contact group ID from hidden field int groupId = ValidationHelper.GetInteger(hdnIdentifier.Value, 0); if (groupId > 0) { var contactGroup = ContactGroupInfoProvider.GetContactGroupInfo(groupId); if (contactGroup == null) { RedirectToAccessDenied(GetString("general.invalidparameters")); return; } IEnumerable <string> contactIds = null; switch (what) { // All items case What.All: // Get selected IDs based on where condition DataSet contacts = ContactInfoProvider.GetContacts().Where(where).Column("ContactID"); if (!DataHelper.DataSourceIsEmpty(contacts)) { // Get array list with IDs contactIds = DataHelper.GetUniqueValues(contacts.Tables[0], "ContactID", true); } break; // Selected items case What.Selected: // Get selected IDs from unigrid contactIds = gridElem.SelectedItems; break; } if (contactIds != null) { // Add each selected contact to the contact group, skip contacts that are already members of the group foreach (string item in contactIds) { int contactId = item.ToInteger(0); if (contactId > 0) { ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(groupId, contactId, ContactGroupMemberTypeEnum.Contact, MemberAddedHowEnum.Manual); } } // Show result message with contact group's display name ShowConfirmation(String.Format(GetString("om.contact.massaction.addedtogroup"), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(contactGroup.ContactGroupDisplayName)))); } } break; default: return; } // Reload unigrid gridElem.ResetSelection(); gridElem.ReloadData(); pnlUpdate.Update(); }