Пример #1
0
        // http://www.dol.govt.nz/er/holidaysandleave/publicholidays/publicholidaydates/ical/public-holidays-all.ics
        // http://www.dol.govt.nz/er/holidaysandleave/publicholidays/publicholidaydates/current.asp

        public static DateTime GetWorkingDay(DateTime date, int holidayRegionID)
        {
            if (_hasCalendarHolidayTable == null)
            {
                _hasCalendarHolidayTable = BewebData.TableExists("CalendarHoliday");
            }
            DateTime nextWorkDate = new DateTime(date.Ticks);
            bool     isHoliday;

            do
            {
                isHoliday = nextWorkDate.DayOfWeek == DayOfWeek.Sunday || nextWorkDate.DayOfWeek == DayOfWeek.Saturday;
                if (_hasCalendarHolidayTable.Value && !isHoliday)
                {
                    Sql sql = new Sql("select * from CalendarHoliday where HolidayDate=", nextWorkDate);
                    if (holidayRegionID > 0)
                    {
                        // return National and Regional Holidays
                        sql.Add("and (HolidayRegionID is null or HolidayRegionID = ", holidayRegionID.SqlizeNumber(), ")");
                    }
                    else if (BewebData.FieldExists("CalendarHoliday", "HolidayRegionID"))
                    {
                        // return Holidays without regions if regions exist (e.g. National Holidays)
                        sql.Add("and HolidayRegionID is null");
                    }
                    isHoliday = sql.RecordExists();
                }
                if (isHoliday)
                {
                    nextWorkDate = nextWorkDate.AddDays(1);
                }
            } while (isHoliday);
            return(nextWorkDate);
        }
Пример #2
0
        private void LogMessage()
        {
#if ActiveRecord
            if (!BewebData.TableExists("MailLog"))
            {
                new Sql("CREATE TABLE [dbo].[MailLog]([MailLogID] [int] IDENTITY(1,1) NOT NULL, [EmailTo] [nvarchar](150) NULL, [EmailSubject] [nvarchar](150) NULL, [Result] [nvarchar](250) NULL, [DateSent] [datetime] NULL, [EmailFrom] [nvarchar](150) NULL, CONSTRAINT [MailLog_PK] PRIMARY KEY NONCLUSTERED ([MailLogID] ASC))").Execute();
            }
            if (!BewebData.FieldExists("MailLog", "DateSent"))
            {
                new Sql("ALTER TABLE [dbo].[MailLog] add  [DateSent] [datetime] NULL").Execute();
            }
            if (!BewebData.FieldExists("MailLog", "EmailTo"))
            {
                new Sql("ALTER TABLE [dbo].[MailLog] add  [EmailTo] [nvarchar](150) NULL").Execute();
            }
            if (!BewebData.FieldExists("MailLog", "EmailFrom"))
            {
                new Sql("ALTER TABLE [dbo].[MailLog] add  [EmailFrom] [nvarchar](150) NULL").Execute();
            }
            if (!BewebData.FieldExists("MailLog", "EmailFromName"))
            {
                new Sql("ALTER TABLE [dbo].[MailLog] add  [EmailFromName] [nvarchar](150) NULL").Execute();
            }
            if (!BewebData.FieldExists("MailLog", "EmailToName"))
            {
                new Sql("ALTER TABLE [dbo].[MailLog] add  [EmailToName] [nvarchar](150) NULL").Execute();
            }
            if (!BewebData.FieldExists("MailLog", "EmailCC"))
            {
                new Sql("ALTER TABLE [dbo].[MailLog] add  [EmailCC] [nvarchar](250) NULL").Execute();
            }
            if (!BewebData.FieldExists("MailLog", "DateViewTracked"))
            {
                new Sql("ALTER TABLE [dbo].[MailLog] add  [DateViewTracked] [datetime] NULL").Execute();
            }
            if (!BewebData.FieldExists("MailLog", "TrackingGUID"))
            {
                new Sql("ALTER TABLE [dbo].[MailLog] add  [TrackingGUID] [nvarchar](50) NULL").Execute();
            }
            if (MailLogFullText)
            {
                if (!BewebData.FieldExists("MailLog", "EmailBodyPlain"))
                {
                    new Sql("ALTER TABLE [dbo].[MailLog] add  [EmailBodyPlain] [nvarchar](max) NULL").Execute();
                }
                if (!BewebData.FieldExists("MailLog", "EmailBodyHtml"))
                {
                    new Sql("ALTER TABLE [dbo].[MailLog] add  [EmailBodyHtml] [nvarchar](max) NULL").Execute();
                }
            }
            var maillog = new ActiveRecord("MailLog", "MailLogID");
            maillog["DateSent"].ValueObject      = DateTime.Now;
            maillog["EmailFromName"].ValueObject = FromName.Left(150);
            maillog["EmailFrom"].ValueObject     = FromAddress.Left(150);
            maillog["EmailToName"].ValueObject   = ToName.Left(150);
            maillog["EmailTo"].ValueObject       = ToAddress.Left(150);
            maillog["EmailSubject"].ValueObject  = Subject.Left(150);
            maillog["EmailCC"].ValueObject       = CC.Left(250);
            maillog["TrackingGUID"].ValueObject  = trackingGuid;

            if (MailLogFullText)
            {
                maillog["EmailBodyPlain"].ValueObject = BodyPlain;
                maillog["EmailBodyHtml"].ValueObject  = BodyHtml;
            }
            maillog["Result"].ValueObject = ErrorResult.Left(250) ?? "OK";
            maillog.Save();
#endif
        }