Beispiel #1
0
        /// <summary>
        /// Отсылает новость по электронной почте.
        /// </summary>
        public void SendNews()
        {
            // Получить список всех пользователей.
            Person[] users = UserList.GetUserList();
            if ((users == null) || (users.Length == 0))
                return;

            // Обработать всех пользователей.
            foreach (Person curUser in users)
            {
                // Пользователь без адреса почты не могут получить рассылку.
                if (string.IsNullOrEmpty(curUser.PrimaryEMail))
                    continue;

                // Не оповещать московских служащих.
                if (curUser.EmployeesUlterSYSMoscow)
                    continue;

                // Разослать уведомления.
                string message = Message;
                message = Regex.Replace(message, "_UserName_", curUser.FullName);
                message = Regex.Replace(message, "_Date_", DateTime.Today.ToLongDateString());

                MailItem item = new MailItem
                                    {
                                        FromAddress = Settings.Default.NewsNotificationFromAddress,
                                        ToAddress = curUser.PrimaryEMail,
                                        Subject = Resources.NewsNotificationSubject + "(" + NewsId + ")",
                                        Body = message,
                                        MessageType = ((int) MailTypes.NewsNotification),
                                        IsHTML = true
                                    };
                item.Save();
            }
        }
Beispiel #2
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);
            }
        }
Beispiel #3
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);
            }
        }
        /// <summary>
        /// Рассылает уведомления об отсутствии рабочих интервалах.
        /// </summary>
        public void DeliverNotification()
        {
            // Не оповещать по праздникам.
            if (CalendarItem.GetHoliday(DateTime.Now))
                return;

            // Получить список всех пользователей.
            Person[] users = UserList.GetEmployeeList();
            if (users == null || users.Length == 0)
                return;

            // Получить список рассылки.
            NotificationList nList = NotificationList.GetNotificationList(NotificationType.NotRegistered);
            Logger.Instance.Info("Getting noting list is success.");

            foreach (Person curUser in users)
            {
                try
                {
                    // Не оповещать не слущажих.
                    // Не оповещать служащих, не имеющих адреса электронной почты.
                    // Не оповещать московских служащих.
                    if (!curUser.IsInRole("Employee")
                        || string.IsNullOrEmpty(curUser.PrimaryEMail)
                        || curUser.EmployeesUlterSYSMoscow)
                        continue;

                    // Получить последнее событие за сегодня.
                    WorkEvent lastEvent = WorkEvent.GetCurrentEventOfDate(curUser.ID.Value, DateTime.Today);

                    if (lastEvent == null)
                    {
                        Logger.Instance.Info("Notice sending to " + curUser.FullName + ".");

                        string message = Message;
                        message = Regex.Replace(message, "_UserName_", curUser.FullName);
                        message = Regex.Replace(message, "_Date_", DateTime.Today.ToLongDateString());

                        MailItem item = new MailItem
                                            {
                                                FromAddress = FromAddress,
                                                ToAddress = curUser.PrimaryEMail,
                                                Subject = Subject,
                                                Body = message,
                                                MessageType = ((int) MailTypes.NRNotification)
                                            };
                        item.Save();

                        if (nList != null)
                        {
                            foreach (string eMail in nList)
                            {
                                Logger.Instance.Info("Notice sending to administrator E-Mail " + eMail + ".");

                                message = MessageAdmin;
                                message = Regex.Replace(message, "_UserName_", curUser.FullName);
                                message = Regex.Replace(message, "_Date_", DateTime.Today.ToLongDateString());

                                MailItem adminItem = new MailItem
                                                         {
                                                             FromAddress = FromAddress,
                                                             ToAddress = eMail,
                                                             Subject =
                                                                 Regex.Replace(SubjectAdmin, "_UserName_", curUser.FullName),
                                                             Body = message,
                                                             MessageType = ((int) MailTypes.NRNotification)
                                                         };
                                adminItem.Save();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.Error("При обработке информации о пользователе " + curUser.FullName + " произошла ошибка.", ex);
                }
            }
        }
Beispiel #5
0
 private void createAndSaveMail(string fromAddress, int messageType, string body)
 {
     var mailItem = new MailItem
     {
         FromAddress = fromAddress,
         ToAddress = Settings.Default.ErrorToAddress,
         Subject = Settings.Default.ErrorSubject,
         MessageType = messageType,
         IsHTML = false,
         Body = body
     };
     mailItem.Save();
 }
        /// <summary>
        /// Закрывает незакрытые рабочие интервалы.
        /// </summary>
        public void CloseWorkIntervals()
        {
            Logger.Instance.Info("Procedure of closing non closed work intervals is started.");

            // Получить список всех пользователей.
            var users = UserList.GetUserList();
            if (users == null || users.Length == 0)
                return;

            // Получить список рассылки.
            var nList = NotificationList.GetNotificationList(NotificationType.CloseEvents);

            Logger.Instance.Info("The list of dispatch is loaded.");

            foreach (var curUser in users)
            {
                try
                {
                    var todayWorkEvent = WorkEvent.GetMainWorkEvent(curUser.ID.Value, DateTime.Today);

                    // Не обрабатывать уже закрытые рабочие интервалы.
                    if (todayWorkEvent == null
                        || todayWorkEvent.EndTime != todayWorkEvent.BeginTime)
                        continue;

                    // Получить последнее событие.
                    var lastEvent = WorkEvent.GetCurrentEventOfDate(curUser.ID.Value, DateTime.Today);
                    if (lastEvent.EventType == WorkEventType.TimeOff
                        || lastEvent.EventType == WorkEventType.LanchTime)
                    {
                        WorkEvent.DeleteEvent(lastEvent.ID);

                        // Закрыть рабочий интервал.
                        todayWorkEvent.EndTime = lastEvent.BeginTime;

                        WorkEvent.UpdateEvent(
                            todayWorkEvent.ID,
                            todayWorkEvent.Name,
                            todayWorkEvent.BeginTime,
                            todayWorkEvent.EndTime,
                            todayWorkEvent.UserID,
                            todayWorkEvent.ProjectID,
                            todayWorkEvent.WorkCategoryID,
                            todayWorkEvent.EventTypeID);

                        Logger.Instance.Info("The work interval for user " + curUser.FullName + " was closed.");
                    }
                    else
                    {
                        // Разослать уведомления.
                        if (!string.IsNullOrEmpty(curUser.PrimaryEMail))
                        {
                            Logger.Instance.Info("Sending notice to user " + curUser.FullName + ".");

                            string message = Message;
                            message = Regex.Replace(message, "_UserName_", curUser.FullName);
                            message = Regex.Replace(message, "_Date_", DateTime.Today.ToLongDateString());

                            var item = new MailItem
                                       	{
                                       		FromAddress = FromAddress,
                                       		ToAddress = curUser.PrimaryEMail,
                                       		Subject = Subject,
                                       		Body = message,
                                       		MessageType = ((int) MailTypes.CENotification)
                                       	};
                            item.Save();
                        }

                        if (nList != null)
                        {
                            foreach (string eMail in nList)
                            {
                                Logger.Instance.Info("Sending notice to administrator E-Mail " + eMail + ".");

                                var message = MessageAdmin;
                                message = Regex.Replace(message, "_UserName_", curUser.FullName);
                                message = Regex.Replace(message, "_Date_", DateTime.Today.ToLongDateString());

                                var adminItem = new MailItem
                                                    {
                                                        FromAddress = FromAddress,
                                                        ToAddress = eMail,
                                                        Subject =
                                                            Regex.Replace(SubjectAdmin, "_UserName_",
                                                                          curUser.FullName),
                                                        Body = message,
                                                        MessageType = ((int) MailTypes.CENotification)
                                                    };
                                adminItem.Save();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.Error("During working with user " + curUser.FullName + " information occured error.", ex);
                }
            }
        }