示例#1
0
        /// <summary>
        /// Отсылает пользовательскую статистику.
        /// </summary>
        /// <param name="curUser">Пользователь, которому отсылается статистика.</param>
        /// <param name="delivery">Описание рассылки.</param>
        private void SendUserStatistics(Person curUser, UserDelivery delivery)
        {
            if (curUser == null
                || curUser.ID == null
                || delivery == null)
                return;

            try
            {
                // Отослать статистику за неделю.
                DateTime end = DateTime.Today.AddDays(-1);
                DateTime begin = DateClass.WeekBegin(end);

                if (begin.Month < end.Month)
                    begin = new DateTime(end.Year, end.Month, 1, 0, 0, 0);

                MailItem item = new MailItem
                                    {
                                        FromAddress = FromAddress,
                                        ToAddress = curUser.PrimaryEMail,
                                        Subject = String.Format(Subject, curUser.FullName, begin, end),
                                        MessageType = ((int) MailTypes.UserStatistics)
                                    };

                // Узнать пользователя, чья статистика должна быть послана.
                Person statUser = curUser;
                if (delivery.StatisticsUserID != null)
                {
                    statUser = new Person();
                    if (!statUser.Load(delivery.StatisticsUserID.Value))
                        statUser = curUser;
                }

                PeriodUserStatistics stat = PeriodUserStatistics.GetUserStatistics(statUser, begin, end);
                switch (delivery.DeliveryPresentation)
                {
                    case DeliveryPresentation.XML:
                        item.IsHTML = false;
                        item.Body = stat.GetXMLPresentation();
                        break;

                    case DeliveryPresentation.HTML:
                        item.IsHTML = true;
                        item.Body = stat.GetHTMLPresentation();
                        break;
                }
                item.Save();

                // Отослать статистику за месяц.
                if (DateTime.Today.Day == 1)
                {
                    begin = new DateTime(end.Year, end.Month, 1, 0, 0, 0);
                    item.Subject = String.Format(Subject, curUser.FullName, begin, end);

                    stat = PeriodUserStatistics.GetUserStatistics(curUser, begin, end);
                    switch (delivery.DeliveryPresentation)
                    {
                        case DeliveryPresentation.XML:
                            item.IsHTML = false;
                            item.Body = stat.GetXMLPresentation();
                            break;

                        case DeliveryPresentation.HTML:
                            item.IsHTML = true;
                            item.Body = stat.GetHTMLPresentation();
                            break;
                    }

                    item.ID = null;
                    item.Save();
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Error("Can't send user " + curUser.FullName + " statistcs.", ex);
            }
        }
示例#2
0
        /// <summary>
        /// Отсылает офисную статистику.
        /// </summary>
        /// <param name="curUser">Пользователь, которому отсылается статистика.</param>
        /// <param name="delivery">Описание рассылки.</param>
        private void SendOfficeStatistics(Person curUser, UserDelivery delivery)
        {
            if (curUser == null
                || curUser.ID == null
                || delivery == null)
                return;

            try
            {
                // Отослать статистику за неделю.
                DateTime end = DateTime.Today.AddDays(-1);
                DateTime begin = DateClass.WeekBegin(end);

                if (begin.Month < end.Month)
                    begin = new DateTime(end.Year, end.Month, 1, 0, 0, 0);

                MailItem item = new MailItem
                                    {
                                        FromAddress = FromAddress,
                                        ToAddress = curUser.PrimaryEMail,
                                        Subject = String.Format(SubjectAdmin, begin, end),
                                        MessageType = ((int) MailTypes.OfficeStatistics)
                                    };

                PeriodOfficeStatistics stat = PeriodOfficeStatistics.GetOfficeStatistics(begin, end);
                switch (delivery.DeliveryPresentation)
                {
                    case DeliveryPresentation.XML:
                        item.IsHTML = false;
                        item.Body = stat.GetXMLPresentation();
                        break;

                    case DeliveryPresentation.HTML:
                        item.IsHTML = true;
                        item.Body = stat.GetHTMLPresentation();
                        break;
                }
                item.Save();

                // Отослать статистику за месяц.
                if (DateTime.Today.Day == 1)
                {
                    begin = new DateTime(end.Year, end.Month, 1, 0, 0, 0);
                    item.Subject = String.Format(SubjectAdmin, begin, end);

                    stat = PeriodOfficeStatistics.GetOfficeStatistics(begin, end);
                    switch (delivery.DeliveryPresentation)
                    {
                        case DeliveryPresentation.XML:
                            item.IsHTML = false;
                            item.Body = stat.GetXMLPresentation();
                            break;

                        case DeliveryPresentation.HTML:
                            item.IsHTML = true;
                            item.Body = stat.GetHTMLPresentation();
                            break;
                    }

                    item.ID = null;
                    item.Save();
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Error("Can't send user " + curUser.FullName + " office statistics.", ex);
            }
        }