Exemplo n.º 1
0
        public void UpdateSettings(Guid userId, UserSettings settings)
        {
            var currentUserId = detail.ServiceClient.OrganizationServiceProxy.CallerId;
            detail.ServiceClient.OrganizationServiceProxy.CallerId = userId;

            var records = detail.ServiceClient.OrganizationServiceProxy.RetrieveMultiple(new QueryByAttribute("usersettings")
            {
                Attributes = { "systemuserid" },
                Values = { userId },
            });

            var record = records.Entities.First();

            if (settings.AdvancedFindStartupMode >= 1)
                record["advancedfindstartupmode"] = settings.AdvancedFindStartupMode;
            if (settings.AutoCreateContactOnPromote >= 0)
                record["autocreatecontactonpromote"] = settings.AutoCreateContactOnPromote;
            if (settings.DefaultCalendarView >= 0)
                record["defaultcalendarview"] = settings.DefaultCalendarView;
            if (settings.HomePageArea.Length > 0 && settings.HomePageArea != "No change")
                record["homepagearea"] = settings.HomePageArea;
            if (settings.HomePageSubArea.Length > 0 && settings.HomePageSubArea != "No change")
                record["homepagesubarea"] = settings.HomePageSubArea;
            if (settings.IncomingEmailFilteringMethod >= 0)
                record["incomingemailfilteringmethod"] = new OptionSetValue(settings.IncomingEmailFilteringMethod);
            if (settings.PagingLimit.HasValue)
                record["paginglimit"] = settings.PagingLimit.Value;
            if (settings.TimeZoneCode >= 0)
                record["timezonecode"] = settings.TimeZoneCode;
            if (settings.WorkdayStartTime.Length > 0 && settings.WorkdayStartTime != "No change")
                record["workdaystarttime"] = settings.WorkdayStartTime;
            if (settings.WorkdayStopTime.Length > 0 && settings.WorkdayStopTime != "No change")
                record["workdaystoptime"] = settings.WorkdayStopTime;
            if (settings.ReportScriptErrors >= 1)
                record["reportscripterrors"] = new OptionSetValue(settings.ReportScriptErrors);
            if (settings.IsSendAsAllowed.HasValue)
                record["issendasallowed"] = settings.IsSendAsAllowed.Value;
            if (settings.UiLanguage.HasValue)
                record["uilanguageid"] = settings.UiLanguage.Value;
            if (settings.HelpLanguage.HasValue)
                record["helplanguageid"] = settings.HelpLanguage.Value;
            if (settings.Currency != null)
                record["transactioncurrencyid"] = settings.Currency;
            if (settings.StartupPaneEnabled.HasValue)
                record["getstartedpanecontentenabled"] = settings.StartupPaneEnabled.Value;
            if (settings.UseCrmFormForAppointment.HasValue)
                record["usecrmformforappointment"] = settings.UseCrmFormForAppointment.Value;
            if (settings.UseCrmFormForContact.HasValue)
                record["usecrmformforcontact"] = settings.UseCrmFormForContact.Value;
            if (settings.UseCrmFormForEmail.HasValue)
                record["usecrmformforemail"] = settings.UseCrmFormForEmail.Value;
            if (settings.UseCrmFormForTask.HasValue)
                record["usecrmformfortask"] = settings.UseCrmFormForTask.Value;

            service.Update(record);

            detail.ServiceClient.OrganizationServiceProxy.CallerId = currentUserId;
        }
Exemplo n.º 2
0
        private void tsbUpdateUserSettings_Click(object sender, EventArgs e)
        {
            if (userSelector1.SelectedItems.Count == 0)
            {
                MessageBox.Show(this, "No user has been selected!", "Warning", MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);
                return;
            }

            #region Initialisation des données à mettre à jour

            var setting = new UserSettings
            {
                AdvancedFindStartupMode = cbbAdvancedFindMode.SelectedIndex,
                AutoCreateContactOnPromote = cbbCreateRecords.SelectedIndex - 1,
                DefaultCalendarView = cbbCalendar.SelectedIndex - 1,
                IncomingEmailFilteringMethod = cbbTrackMessages.SelectedIndex - 1,
                ReportScriptErrors = cbbReportScriptErrors.SelectedIndex,
                HomePageArea = cbbSiteMapArea.SelectedItem.ToString(),
                HomePageSubArea = cbbSiteMapSubArea.SelectedItem.ToString(),
                UsersToUpdate = userSelector1.SelectedItems,
            };

            if (cbbSendAsAllowed.SelectedIndex != 0)
            {
                setting.IsSendAsAllowed = cbbSendAsAllowed.SelectedIndex == 2;
            }

            if (cbbPagingLimit.SelectedIndex != 0)
            {
                setting.PagingLimit = int.Parse(cbbPagingLimit.SelectedItem.ToString());
            }

            if (cbbTimeZones.SelectedIndex != 0)
            {
                setting.TimeZoneCode = ((AppCode.TimeZone)cbbTimeZones.SelectedItem).Code;
            }

            if (cbbWorkStartTime.SelectedIndex != 0 || cbbWorkStartTime.SelectedText != null)
            {
                setting.WorkdayStartTime = cbbWorkStartTime.SelectedItem.ToString();
                if (cbbWorkStartTime.SelectedIndex == 0)
                {
                    setting.WorkdayStartTime = cbbWorkStartTime.SelectedText;
                }
            }

            if (cbbWorkStopTime.SelectedIndex != 0 || cbbWorkStopTime.SelectedText != null)
            {
                setting.WorkdayStopTime = cbbWorkStopTime.SelectedItem.ToString();
                if (cbbWorkStopTime.SelectedIndex == 0)
                {
                    setting.WorkdayStopTime = cbbWorkStopTime.SelectedText;
                }
            }

            if (cbbHelpLanguage.SelectedIndex != 0)
            {
                setting.HelpLanguage = ((Language)cbbHelpLanguage.SelectedItem).Lcid;
            }

            if (cbbUiLanguage.SelectedIndex != 0)
            {
                setting.UiLanguage = ((Language)cbbUiLanguage.SelectedItem).Lcid;
            }

            if (cbbCurrencies.SelectedIndex != 0)
            {
                setting.Currency = ((Currency)cbbCurrencies.SelectedItem).CurrencyReference;
            }

            if (cbbStartupPane.SelectedIndex != 0)
            {
                setting.StartupPaneEnabled = cbbStartupPane.SelectedIndex == 2;
            }

            if (cbbUseCrmFormAppt.SelectedIndex != 0)
            {
                setting.UseCrmFormForAppointment = cbbUseCrmFormAppt.SelectedIndex == 2;
            }

            if (cbbUseCrmFormContact.SelectedIndex != 0)
            {
                setting.UseCrmFormForContact = cbbUseCrmFormContact.SelectedIndex == 2;
            }

            if (cbbUseCrmFormEmail.SelectedIndex != 0)
            {
                setting.UseCrmFormForEmail = cbbUseCrmFormEmail.SelectedIndex == 2;
            }

            if (cbbUseCrmFormTask.SelectedIndex != 0)
            {
                setting.UseCrmFormForTask = cbbUseCrmFormTask.SelectedIndex == 2;
            }

            #endregion Initialisation des données à mettre à jour

            WorkAsync(new WorkAsyncInfo
            {
                Message = "Initializing update...",
                AsyncArgument = setting,
                Work = (bw, evt) =>
                {
                    var settingArg = (UserSettings)evt.Argument;
                    var ush = new UserSettingsHelper(Service, ConnectionDetail);

                    foreach (var user in settingArg.UsersToUpdate)
                    {
                        bw.ReportProgress(0, "Updating settings for user " + user.GetAttributeValue<string>("fullname"));
                        ush.UpdateSettings(user.Id, setting);
                    }
                },
                PostWorkCallBack = evt =>
                {
                    if (evt.Error != null)
                    {
                        MessageBox.Show(this, "An error occured: " + evt.Error.Message, "Error", MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                },
                ProgressChanged = evt => { SetWorkingMessage(evt.UserState.ToString()); }
            });
        }
Exemplo n.º 3
0
        public void UpdateSettings(Guid userId, UserSettings settings)
        {
            var currentUserId = ((OrganizationServiceProxy)(((OrganizationService)service).InnerService)).CallerId;

            var records = service.RetrieveMultiple(new QueryByAttribute("usersettings")
            {
                Attributes = { "systemuserid" },
                Values     = { userId },
            });

            var record = records.Entities.First();

            if (settings.AdvancedFindStartupMode >= 1)
            {
                record["advancedfindstartupmode"] = settings.AdvancedFindStartupMode;
            }
            if (settings.AutoCreateContactOnPromote >= 0)
            {
                record["autocreatecontactonpromote"] = settings.AutoCreateContactOnPromote;
            }
            if (settings.DefaultCalendarView >= 0)
            {
                record["defaultcalendarview"] = settings.DefaultCalendarView;
            }
            if (settings.HomePageArea.Length > 0 && settings.HomePageArea != "No change")
            {
                record["homepagearea"] = settings.HomePageArea;
            }
            if (settings.HomePageSubArea.Length > 0 && settings.HomePageSubArea != "No change")
            {
                record["homepagesubarea"] = settings.HomePageSubArea;
            }
            if (settings.IncomingEmailFilteringMethod >= 0)
            {
                record["incomingemailfilteringmethod"] = new OptionSetValue(settings.IncomingEmailFilteringMethod);
            }
            if (settings.PagingLimit.HasValue)
            {
                record["paginglimit"] = settings.PagingLimit.Value;
            }
            if (settings.TimeZoneCode >= 0)
            {
                record["timezonecode"] = settings.TimeZoneCode;
            }
            if (settings.WorkdayStartTime.Length > 0 && settings.WorkdayStartTime != "No change")
            {
                record["workdaystarttime"] = settings.WorkdayStartTime;
            }
            if (settings.WorkdayStopTime.Length > 0 && settings.WorkdayStopTime != "No change")
            {
                record["workdaystoptime"] = settings.WorkdayStopTime;
            }
            if (settings.ReportScriptErrors >= 1)
            {
                record["reportscripterrors"] = new OptionSetValue(settings.ReportScriptErrors);
            }
            if (settings.IsSendAsAllowed.HasValue)
            {
                record["issendasallowed"] = settings.IsSendAsAllowed.Value;
            }
            if (settings.UiLanguage.HasValue)
            {
                record["uilanguageid"] = settings.UiLanguage.Value;
            }
            if (settings.HelpLanguage.HasValue)
            {
                record["helplanguageid"] = settings.HelpLanguage.Value;
            }
            if (settings.Currency != null)
            {
                record["transactioncurrencyid"] = settings.Currency;
            }
            if (settings.StartupPaneEnabled.HasValue)
            {
                record["getstartedpanecontentenabled"] = settings.StartupPaneEnabled.Value;
            }
            if (settings.UseCrmFormForAppointment.HasValue)
            {
                record["usecrmformforappointment"] = settings.UseCrmFormForAppointment.Value;
            }
            if (settings.UseCrmFormForContact.HasValue)
            {
                record["usecrmformforcontact"] = settings.UseCrmFormForContact.Value;
            }
            if (settings.UseCrmFormForEmail.HasValue)
            {
                record["usecrmformforemail"] = settings.UseCrmFormForEmail.Value;
            }
            if (settings.UseCrmFormForTask.HasValue)
            {
                record["usecrmformfortask"] = settings.UseCrmFormForTask.Value;
            }

            service.Update(record);

            ((OrganizationServiceProxy)(((OrganizationService)service).InnerService)).CallerId = currentUserId;
        }