protected bool ShouldSendNotification()
        {
            bool shouldSend = false;

            var      entities = new PSsqmEntities();
            TimeSpan timeBetweenNotifications = new TimeSpan(24, 0, 0);
            DateTime lastSentDate;

            SETTINGS stHours = SQMSettings.SelectSettingByCode(entities, "MAIL", "TASK", "HoursBetweenNotifications");

            if (stHours != null)
            {
                if (!string.IsNullOrEmpty(stHours.VALUE))
                {
                    int hours;
                    if (Int32.TryParse(stHours.VALUE, out hours))
                    {
                        timeBetweenNotifications = new TimeSpan(hours, 0, 0);
                    }
                }

                SETTINGS stLastSent = SQMSettings.SelectSettingByCode(entities, "MAIL", "TASK", "NotificationLastSent");

                if (stLastSent != null)
                {
                    if (DateTime.TryParse(stLastSent.VALUE, out lastSentDate))
                    {
                        WriteLine("Last sent date: " + lastSentDate);
                        shouldSend = (DateTime.Now.Subtract(timeBetweenNotifications) > lastSentDate);

                        if (shouldSend == true)
                        {
                            // Set last sent date to now
                            stLastSent.VALUE = DateTime.Now.ToString();
                            SQMSettings.UpdateSettings(entities, stLastSent, "Automated Emailer");
                        }
                    }
                    else
                    {
                        shouldSend = false;
                    }
                }
                else
                {
                    WriteLine("Missing value in SETTINGS table: NotificationLastSent");
                    shouldSend = false;
                }
            }
            else
            {
                WriteLine("Missing value in SETTINGS table: HoursBetweenNotifications");
                shouldSend = false;
            }

            WriteLine("Should send: " + shouldSend);

            return(shouldSend);
        }
Exemplo n.º 2
0
        protected bool SaveSettings(bool updateSetting)
        {
            PSsqmEntities Entities = new PSsqmEntities();
            string        strCode  = selectedCode.SETTING_CD;
            SETTINGS      settings = SQMSettings.SelectSettingByCode(Entities, ddlSettingGroup.SelectedValue.ToString(), ddlSettingFamily.SelectedValue.ToString(), strCode);

            bool success;

            // AW20131106 - need to verify that the SSO_ID and email address are unique in the system
            bool bErrors = false;

            settings.VALUE = tbValue.Text.ToString();
            // update the code
            selectedCode = SQMSettings.UpdateSettings(Entities, settings, SessionManager.UserContext.UserName());
            return(true);
        }