예제 #1
0
        /// <summary>
        /// Return Account's custom fields
        /// </summary>
        /// <returns></returns>
        public StaffAccount GetAccountDetails()
        {
            try
            {
                Debug("RightNowConnectService - GetAccountDetails() - Entry");

                int    accountId = OutOfOfficeClientAddIn.GlobalContext.AccountId;
                string query     = String.Format(RightNowQueries.GetAccountDetailsQuery, accountId);

                string[] data = GetRNData(OracleRightNowOOOAddInNames.OutOfOfficeAddIn, query);

                string[] accountdetails = data[0].Split('|');

                var staffAccount = new StaffAccount();
                staffAccount.AccountId = accountId;

                //Fetching timezone
                string       windowsTimezone = null;
                TimeZoneInfo timeszone       = null;

                if (!string.IsNullOrEmpty(accountdetails[5]))
                {
                    staffAccount.OooTimezone = accountdetails[5];
                    windowsTimezone          = TimezoneService.GetService().GetWindowsTimezone(accountdetails[5]);
                    timeszone = TimeZoneInfo.FindSystemTimeZoneById(windowsTimezone);
                }

                if (!string.IsNullOrEmpty(accountdetails[0]))
                {
                    //staffAccount.OooStart = TimeZoneInfo.ConvertTime(XmlConvert.ToDateTime(accountdetails[0]), timeszone);
                    DateTime dateTime = XmlConvert.ToDateTime(accountdetails[0], XmlDateTimeSerializationMode.Utc);
                    staffAccount.OooStart = OutOfOfficeClientAddIn.GlobalContext.GetTimeZoneDateTime(staffAccount.OooTimezone, dateTime) ?? DateTime.Now;
                }
                else
                {
                    staffAccount.OooStart = DateTime.Now;
                }

                if (!string.IsNullOrEmpty(accountdetails[1]))
                {
                    //staffAccount.OooEnd = TimeZoneInfo.ConvertTime(XmlConvert.ToDateTime(accountdetails[1]), timeszone);
                    DateTime dateTime = XmlConvert.ToDateTime(accountdetails[1], XmlDateTimeSerializationMode.Utc);
                    staffAccount.OooEnd = OutOfOfficeClientAddIn.GlobalContext.GetTimeZoneDateTime(staffAccount.OooTimezone, dateTime) ?? DateTime.Now;
                }
                else
                {
                    staffAccount.OooEnd = DateTime.Now;
                }

                if (!string.IsNullOrEmpty(accountdetails[2]))
                {
                    staffAccount.OooFlag = (accountdetails[2].Equals("1")) ? true : false;
                }
                if (!string.IsNullOrEmpty(accountdetails[3]))
                {
                    staffAccount.OooMsg = accountdetails[3];
                }
                if (!string.IsNullOrEmpty(accountdetails[4]))
                {
                    staffAccount.OooMsgOption = accountdetails[4];
                }


                return(staffAccount);
            }
            catch (Exception e)
            {
                MessageBox.Show(OOOExceptionMessages.UnexpectedError, Common.Common.ErrorLabel, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Error(e.Message, e.StackTrace);
            }

            Debug("RightNowConnectService - GetAccountDetails() - Exit");
            return(null);
        }
        /// <summary>
        /// Saves date on OK button click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="routedEventArgs"></param>
        public void OkClick(object sender, RoutedEventArgs routedEventArgs)
        {
            logger.Debug("OutOfOfficeControl - OkClick() - Entry");

            var updatedAccount = new StaffAccount();

            updatedAccount.OooFlag     = OutOfOfficeCheckbox.IsChecked.GetValueOrDefault();
            updatedAccount.OooTimezone = (TimezoneDropdown.SelectedValue != null) ? TimezoneDropdown.SelectedValue.ToString() : null;
            DateTime?fromDateTime = null;
            DateTime?toDateTime   = null;

            if (FromDateTime.SelectedDate != null || ToDateTime.SelectedDate != null)
            {
                //Combining date and time to store
                string fromDate = FromDateTime.SelectedDate.GetValueOrDefault().Date.ToString("d");
                string fromTime = FromTimeDropdown.SelectedValue.ToString();

                string toDate = ToDateTime.SelectedDate.GetValueOrDefault().Date.ToString("d");
                string toTime = ToTimeDropdown.SelectedValue.ToString();

                fromDateTime = Convert.ToDateTime(fromDate + " " + fromTime);
                toDateTime   = Convert.ToDateTime(toDate + " " + toTime);

                //Validating if user entered date/time without timezone.
                if ((fromDateTime != default(DateTime) || toDateTime != default(DateTime)) && TimezoneDropdown.SelectedValue == null)
                {
                    System.Windows.Forms.MessageBox.Show(OOOExceptionMessages.TimezoneCannotBeEmpty,
                                                         Common.ErrorLabel, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    TimezoneLabel.Content    = "*" + Common.TimezoneLabel;
                    TimezoneLabel.Foreground = new SolidColorBrush(Colors.Red);
                    return;
                }
                //Validating if user entered From Date/Time is less than To Date/Time.
                if (fromDateTime > toDateTime)
                {
                    System.Windows.Forms.MessageBox.Show(OOOExceptionMessages.FromDateGreaterThanToDate,
                                                         Common.ErrorLabel, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (updatedAccount.OooTimezone != null)
                {
                    string       windowsTimezone = TimezoneService.GetService().GetWindowsTimezone(updatedAccount.OooTimezone);
                    TimeZoneInfo timeszone       = TimeZoneInfo.FindSystemTimeZoneById(windowsTimezone);

                    fromDateTime = TimeZoneInfo.ConvertTimeToUtc((DateTime)fromDateTime, timeszone);
                    toDateTime   = TimeZoneInfo.ConvertTimeToUtc((DateTime)toDateTime, timeszone);
                }
            }

            updatedAccount.OooStart     = fromDateTime;
            updatedAccount.OooEnd       = toDateTime;
            updatedAccount.OooMsgOption = PersonalMsgOptionsDropdown.SelectedValue.ToString();
            updatedAccount.OooMsg       = PersonalMsgOptionsDropdown.SelectedValue.ToString().Equals(PersonalMsgOptions.StandardMessage) ? " " : PersonalMsgTextbox.Text;

            var result = RightNowConnectService.GetService().updateCustomFields(updatedAccount);

            if (result)
            {
                _statusBarControl.statusButton.Text      = (updatedAccount.OooFlag) ? Common.OutOfOfficeLabel : Common.AvailableLabel;
                _statusBarControl.statusButton.ForeColor = (updatedAccount.OooFlag) ? Color.DarkRed : Color.DarkGreen;
            }

            Window.GetWindow(this).Close();

            logger.Debug("OutOfOfficeControl - OkClick() - Exit");
        }