Разработка системы рассылки СМС сообщений

Автор работы: Пользователь скрыл имя, 29 Января 2013 в 17:29, курсовая работа

Краткое описание

Целью курсовой работы является автоматизация рассылки SMS сообщений, для ускорения и облегчения работы по оповещению студентов.
Задачей, для достижения данной цели является создание приложения SmsMessenger, которое будет производить автоматизацию рассылки SMS.

Содержание

Введение 2
1. Описание предметной области 3
1.1. Предметная область курсового проекта 3
1.2. Информационно-логическая модель предметной области 3
2. Создание приложения SmsMessenger 6
2.1. Логическое проектирование 6
2.2. Модель данных 7
2.3. Описание представлений и представителей 8
3. Тестирование программы 17
Заключение 25
Список литературы 26
Пиложение А. Задание на курсовой проект 27
Приложение Б. Структура исходных файлов 28
Приложение В. XAML код всех представлений и библиотек ресурсов 30
Приложение Г. Код классов программы. 62

Вложенные файлы: 1 файл

Kursovik.docx

— 6.63 Мб (Скачать файл)

            if (e.LeftButton == MouseButtonState.Pressed)

            {

                Point currentPosition = e.GetPosition(sender as Border);

 

                DataObject d = new DataObject();

                d.SetData("SmsTemplate",(sender as Border).DataContext as SmsTemplate);

                DragDropEffects finalDropEffect = DragDrop.DoDragDrop(sender as Border, d, DragDropEffects.Move);

            }

        }

 

        private void AddTemplateGroupButton_click(object sender, RoutedEventArgs e)

        {

            Presenter.OpenSmsTemplateGroup(new SmsTemplateGroup() {Title = "Новая группа шаблонов"});

        }

 

        private void EditSmsTemplateGroupButton_click(object sender, RoutedEventArgs e)

        {

            Button button = sender as Button;

            if (button != null)

                Presenter.OpenSmsTemplateGroup(button.DataContext as SmsTemplateGroup);

        }

 

        private void DeleteSmsTemplateGroupButton_click(object sender, RoutedEventArgs e)

        {

            if (MessageBox.Show("Удаление группы шаблона SMS."+Environment.NewLine+"Все шаблоны входящие в эту группу будут удалены!", "Уверены?", MessageBoxButton.YesNo, MessageBoxImage.Warning) != MessageBoxResult.Yes)

                return;

            Button button = sender as Button;

            if (button != null)

                Presenter.DeleteSmsTemplateGroup(button.DataContext as SmsTemplateGroup);

        }

 

    }

}

 

CellPhoneValidator.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows.Controls;

using System.Text.RegularExpressions;

 

namespace SmsMessanger.Validators

{

    class CellPhoneValidation : ValidationRule

    {

        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)

        {

            string phone = value.ToString();

 

            if (string.IsNullOrEmpty(phone)) return new ValidationResult(true, null);

           

            for (int i = 0; i < phone.Length; i++)

                if (!char.IsNumber(phone[i])) phone = phone.Remove(i,1);

           

            phone = "+" + phone;

            bool valid = Regex.IsMatch(phone, @"\+7[0-9]{10,10}$");

 

            if (!valid)

                return new ValidationResult(false, "Сотовый телефон должен быть в формате +7xxxxxxxxx");

            else

                return new ValidationResult(true, null);

        }

    }

}

 

 

ErrorsToMessagesConverter.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows.Data;

using System.Windows.Controls;

using System.Collections.ObjectModel;

 

namespace SmsMessanger.Validators

{

    class ErrorsToMessagesConverter : IValueConverter

    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

        {

            StringBuilder sb = new StringBuilder();

 

            var errors = value as ReadOnlyCollection<ValidationError>;

            if (errors != null)

            {

                foreach (var e in errors.Where(e=>e.ErrorContent!=null))

                {

                    sb.AppendLine(e.ErrorContent.ToString());

                }

            }

            return sb.ToString();

        }

 

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

        {

            throw new NotImplementedException();

        }

    }

}

 

 

ErrorsToVisibleConverter.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows.Data;

using System.Windows.Controls;

using System.Collections.ObjectModel;

 

namespace SmsMessanger.Validators

{

    class ErrorsToVisibleConverter : IValueConverter

    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

        {

            var errors = value as ReadOnlyCollection<ValidationError>;

            if (errors == null) return System.Windows.Visibility.Collapsed;

            if (errors.Count == 0) return System.Windows.Visibility.Collapsed;

            return System.Windows.Visibility.Visible;

        }

 

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

        {

            throw new NotImplementedException();

        }

    }

}

 

 

TitlesValidator.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows.Controls;

 

namespace SmsMessanger.Validators

{

    class TitlesValidator : ValidationRule

    {

        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)

        {

            string title = value.ToString();

           

            if (string.IsNullOrEmpty(title))

                return new ValidationResult(false,"Поле обязательно для заполнения");

 

            if (title.Length < 2)

                return new ValidationResult(false, "Длина текста в поле должна быть не менее 2-х символов");

 

            return new ValidationResult(true, null);

        }

    }

}

 

EditConfigView.xaml.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;

using SmsMessanger.Presenters;

 

namespace SmsMessanger.Views

{

    /// <summary>

    /// Interaction logic for EditConfigView.xaml

    /// </summary>

    public partial class EditConfigView : UserControl

    {

        public EditConfigView()

        {

            InitializeComponent();

        }

 

        EditConfigPresenter Presenter { get { return DataContext as EditConfigPresenter; } }

 

 

        private void savebutton_click(object sender, RoutedEventArgs e)

        {

            Presenter.SaveSettings();

        }

    }

}

 

 

EditContactView.xaml.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;

using SmsMessanger.Presenters;

using SmsMessanger.Model;

 

namespace SmsMessanger.Views

{

    /// <summary>

    /// Interaction logic for EditContact.xaml

    /// </summary>

    public partial class EditContactView : UserControl

    {

        public EditContactView()

        {

            InitializeComponent();

        }

 

        public EditContactPresenter Presenter { get { return DataContext as EditContactPresenter; } }

 

        private void choseImageButton_click(object sender, RoutedEventArgs e)

        {

            Presenter.SaveImage();

        }

 

        private void saveButton_Click(object sender, RoutedEventArgs e)

        {

            StringBuilder errors = new StringBuilder();

 

            #region просмотр критических для сохранения полей

            //Сохранять нельзя

            if (Validation.GetHasError(firstName) || Validation.GetHasError(lastName))

            {

                MessageBox.Show("Не коректно заполнено имя/фамилия студента. Сохранение отменено.");

                return;

            }

               

 

            //Можно сохранять

            if (Validation.GetHasError(cellPhone))

                errors.AppendLine("Сотовый телефон указан в неверном формате, и не будет сохранен."+Environment.NewLine);

            #endregion

            if (!string.IsNullOrEmpty(errors.ToString()))

                MessageBox.Show(errors.ToString());

            Presenter.SaveContact();

        }

    }

}

 

 

EditDistributionListView.xaml.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;

using SmsMessanger.Presenters;

using SmsMessanger.Model;

using SmsMessanger.Model.ViewModels;

 

namespace SmsMessanger.Views

{

    /// <summary>

    /// Interaction logic for EditContact.xaml

    /// </summary>

    public partial class EditDistributionListView : UserControl

    {

        public EditDistributionListView()

        {

            InitializeComponent();

        }

 

        public EditDistributionListPresenter Presenter { get { return DataContext as EditDistributionListPresenter; } }

 

        private void SaveButton_click(object sender, RoutedEventArgs e)

        {

            Presenter.SaveDistributionList();

        }

 

       

        private void GroupUnchecked(object sender, RoutedEventArgs e)

        {

            CheckBox checkBox = sender as CheckBox;

            TreeViewItem node =  SmsVisualTreeHelper.FindAncestor<TreeViewItem>(checkBox);

            TreeView tree = SmsVisualTreeHelper.FindAncestor<TreeView>(node);

            TreeViewItem container = tree.ItemContainerGenerator.ContainerFromIndex(2) as TreeViewItem;

        }

 

        private void ContactChecked(object sender, RoutedEventArgs e)

        {

            CheckBox cbox = sender as CheckBox;

 

            TreeViewItem node = SmsVisualTreeHelper.FindAncestor<TreeViewItem>(cbox);

            TreeViewItem mainNode = SmsVisualTreeHelper.FindAncestor<TreeViewItem>(node);

            (mainNode.DataContext as DistributionTreeGroup).IsChecked = true;

        }

 

        private void ContactUnchecked(object sender, RoutedEventArgs e)

        {

            CheckBox cbox = sender as CheckBox;

 

            TreeViewItem node = SmsVisualTreeHelper.FindAncestor<TreeViewItem>(cbox);

            TreeViewItem mainNode = SmsVisualTreeHelper.FindAncestor<TreeViewItem>(node);

 

            foreach (var item in mainNode.Items)

            {

                if ((item as DistributionTreeContact).IsChecked)

                {

                    (mainNode.DataContext as DistributionTreeGroup).IsChecked = true;

                    return;

                }

                (mainNode.DataContext as DistributionTreeGroup).IsChecked = false;

            }

        }

 

        private void checkAllElementsButton_click(object sender, RoutedEventArgs e)

        {

            Button button = sender as Button;

            if (button != null)

            {

                DistributionTreeGroup group = button.DataContext as DistributionTreeGroup;

                bool groupChecked = !group.IsChecked;

                group.IsChecked = groupChecked;

                foreach (var item in group.Contacts)

                {

                    item.IsChecked = groupChecked;

                }

            }

 

            TreeViewItem node = SmsVisualTreeHelper.FindAncestor<TreeViewItem>(button);

            node.IsExpanded = true;

        }

 

 

    }

}

 

 

EditGroupView.xaml.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;

using SmsMessanger.Presenters;

 

namespace SmsMessanger.Views

{

    /// <summary>

    /// Interaction logic for EditGroupView.xaml

    /// </summary>

    public partial class EditGroupView : UserControl

    {

        public EditGroupView()

        {

            InitializeComponent();

        }

 

        public EditGroupPresenter Presenter { get { return DataContext as EditGroupPresenter; } }

 

        private void saveButton_Click(object sender, RoutedEventArgs e)

        {

            Presenter.SaveGroup();

        }

    }

}

 

 

EditSmsTemplateGroupView.xaml.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;

using SmsMessanger.Presenters;

 

namespace SmsMessanger.Views

{

    /// <summary>

    /// Interaction logic for EditSmsTemplateGroup.xaml

    /// </summary>

    public partial class EditSmsTemplateGroupView : UserControl

    {

        public EditSmsTemplateGroupView()

        {

            InitializeComponent();

        }

 

        EditSmsTemplateGroupPresenter Presenter { get { return DataContext as EditSmsTemplateGroupPresenter; } }

 

        private void saveButton_click(object sender, RoutedEventArgs e)

        {

            Presenter.Save();

        }

    }

}

 

 

EditSmsView.xaml.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;

using SmsMessanger.Presenters;

 

namespace SmsMessanger.Views

{

    /// <summary>

    /// Interaction logic for EditGroupView.xaml

    /// </summary>

    public partial class EditSmsView : UserControl

    {

        public EditSmsView()

        {

            InitializeComponent();

        }

 

        public EditSmsTemplatePresenter Presenter { get { return DataContext as EditSmsTemplatePresenter; } }

 

        private void saveButton_Click(object sender, RoutedEventArgs e)

        {

            Presenter.SaveSmsTemplate();

        }

    }

}

 

 

LogView.xaml.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;

using SmsMessanger.Presenters;

using SmsMessanger.Model;

 

namespace SmsMessanger.Views

{

    /// <summary>

    /// Interaction logic for EditContact.xaml

    /// </summary>

    public partial class LogView : UserControl

    {

        public LogView()

        {

            InitializeComponent();

        }

 

        public LogPresenter Presenter { get { return DataContext as LogPresenter; } }

    }

}

 

 

SendSmsByListView.xaml.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;

using SmsMessanger.Presenters;

using SmsMessanger.Model;

using SmsMessanger.Model.ViewModels;

 

namespace SmsMessanger.Views

{

    /// <summary>

    /// Interaction logic for EditContact.xaml

    /// </summary>

    public partial class SendSmsByListView : UserControl

    {

        public SendSmsByListView()

        {

            InitializeComponent();

        }

 

        public SendSmsByListPresenter Presenter { get { return DataContext as SendSmsByListPresenter; } }

 

        private void PrepareSmsButton_click(object sender, RoutedEventArgs e)

        {

            Button button = sender as Button;

            if (button!=null)

            {

                SmsTemplate template = button.DataContext as SmsTemplate;

                SmsMessage.Text = template.Text;

            }

        }

 

        private void SendSMS_button(object sender, RoutedEventArgs e)

        {

            Presenter.SendSmsList();

        }

 

        private void cancelButton_click(object sender, RoutedEventArgs e)

        {

            Presenter.Cancel();

        }

 

        private void saveTemplateButton_click(object sender, RoutedEventArgs e)

        {

            if (templateGroupSelectorPanel.Visibility == System.Windows.Visibility.Visible)

            {

                SmsTemplateGroup templateGroup = templateGroupSelector.SelectedValue as SmsTemplateGroup;

                if (templateGroup == null) return;

                if (string.IsNullOrEmpty(newTemplateTitle.Text)) return;

 

                if (templateGroupSelector.SelectedIndex != -1)

                {

                    Presenter.SaveSmsTemplate(newTemplateTitle.Text, SmsMessage.Text, templateGroup);

                   

                    templateGroupSelector.SelectedIndex = -1;

                    newTemplateTitle.Text = string.Empty;

                    templateGroupSelectorPanel.Visibility = System.Windows.Visibility.Collapsed;

Информация о работе Разработка системы рассылки СМС сообщений