コード例 #1
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
        }