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

Автор работы: Пользователь скрыл имя, 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 Мб (Скачать файл)

        public void DeleteGroup(Group group)

        {

            if (group != null)

            {

                _store.Remove(group);

                Serialize();

            }

        }

    }

}

 

 

LogEventRepository.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

 

namespace SmsMessanger.Model

{

    public class LogEventRepository

    {

        private List<LogEvent> _store;

        private string logFile { get { return "log.txt"; } }

 

        public LogEventRepository()

        {

            _store = new List<LogEvent>();

        }

       

        public void LoadLog()

        {

            if (File.Exists(logFile))

                using (FileStream stream = new FileStream(logFile, FileMode.Open))

                {

                    TextReader tr = new StreamReader(stream);

                    string line = null;

                    while (!string.IsNullOrEmpty(line = tr.ReadLine()))

                    {

                        string[] vars = line.Split('|');

                        LogEvent logevent = new LogEvent

                        {

                            MiniImage = vars[0],

                            Date = DateTime.Parse(vars[1]),

                            Text = vars[2],

                            Id = Guid.NewGuid(),

                        };

                        _store.Add(logevent);

                    }

                }

        }

 

        public List<LogEvent> FindAll()

        {

            _store.Clear();

            LoadLog();

            return new List<LogEvent>(_store);

        }

    }

}

 

 

RepositoryBase.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

using System.Runtime.Serialization.Formatters.Binary;

 

namespace SmsMessanger.Model

{

    public class RepositoryBase<T>

    {

        protected List<T> _store;

        private string _stateFile;

 

        public RepositoryBase(string stateFile)

        {

            _stateFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, stateFile);

            Deserialize();

        }

 

        protected void Deserialize()

        {

            if (File.Exists(_stateFile))

                using (FileStream stream = File.Open(_stateFile, FileMode.Open))

                {

                    BinaryFormatter formater = new BinaryFormatter();

                    _store = (List<T>)formater.Deserialize(stream);

                }

            else

                _store = new List<T>();

        }

        protected void Serialize()

        {

            using (FileStream stream = File.Open(_stateFile, FileMode.OpenOrCreate))

            {

                BinaryFormatter formatter = new BinaryFormatter();

                formatter.Serialize(stream, _store);

            }

 

        }

    }

}

 

 

SendSmsReportRepository.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace SmsMessanger.Model

{

    public class SendSmsReportRepository:RepositoryBase<SendSmsReport>

    {

        public SendSmsReportRepository()

            : base("SmsReports.source")

        {

        }

 

        public List<SendSmsReport> FindAll()

        {

            return new List<SendSmsReport>(_store);

        }

 

        public SendSmsReport GetReport(Guid id)

        {

            return _store.FirstOrDefault(g=>g.Id==id);

        }

 

        public void SaveReport(SendSmsReport smsReport)

        {

            if (smsReport.Id == Guid.Empty)

                smsReport.Id = Guid.NewGuid();

            if (!_store.Contains(smsReport))

                _store.Add(smsReport);

            Serialize();

        }

 

        public void DeleteReport(SendSmsReport report)

        {

            if (report != null)

            {

                _store.Remove(report);

                Serialize();

            }

        }

    }

}

 

 

SmsTemplateGroupRepository.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace SmsMessanger.Model

{

    class SmsTemplateGroupRepository:RepositoryBase<SmsTemplateGroup>

    {

        public SmsTemplateGroupRepository()

            : base("TemplateGroups.source")

        {

            //Установка родительских групп для каждого шаблона СМС

            foreach (SmsTemplateGroup group in _store)

                foreach (SmsTemplate template in group.SmsTemplates)

                    template.ParentGroup = group;

        }

 

        public SmsTemplate GetTemplate(Guid templateId)

        {

            SmsTemplate template;

            foreach(var g in _store)

            {

                var tpl = g.SmsTemplates.FirstOrDefault(t => t.Id == templateId);

                if (tpl != null)

                    return tpl;

            }

            return null;

        }

 

        public List<SmsTemplateGroup> FindAll()

        {

            return new List<SmsTemplateGroup>(_store);

        }

 

        public void SaveSmsTemplate(SmsTemplate template)

        {

            if (template.Id == Guid.Empty)

            {

                template.Id = Guid.NewGuid();

                template.ParentGroup.SmsTemplates.Add(template);

            }

            SaveSmsTemplateGroup(template.ParentGroup);

        }

 

        public void SaveSmsTemplateGroup(SmsTemplateGroup group)

        {

            if (group.Id == Guid.Empty)

                group.Id = Guid.NewGuid();

            if (!_store.Contains(group))

                _store.Add(group);

            Serialize();

        }

 

        public void DeleteSmsTemplate(SmsTemplate template)

        {

            template.ParentGroup.SmsTemplates.Remove(template);

            Serialize();

        }

 

        public void DeleteSmsTemplateGroup(SmsTemplateGroup templateGroup)

        {

            _store.Remove(templateGroup);

            Serialize();

        }

 

    }

}

 

 

TemplateRepository.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace SmsMessanger.Model

{

    class TemplateRepository:RepositoryBase<SmsTemplate>

    {

        public TemplateRepository()

            : base("Templates.source")

        {

        }

 

        public List<SmsTemplate> FindAll()

        {

            return new List<SmsTemplate>(_store);

        }

    }

}

 

VMDistributionTreeEdit.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace SmsMessanger.Model.ViewModels

{

    public class VMDistributionTreeEdit:Notifer

    {

        private List<DistributionTreeGroup> _groups;

        public List<DistributionTreeGroup> Groups

        {

            get { return _groups; }

            set

            {

                _groups = value;

                OnPropertyChanged("Groups");

            }

        }

 

 

        public void SetupGroups(List<Group> groups)

        {

            foreach (var item in groups)

            {

                AddGroup(item);

            }

        }

        public void AddGroup(Group group)

        {

            DistributionTreeGroup newGroup = new DistributionTreeGroup();

            newGroup.Title = group.Title;

            newGroup.Id = group.Id;

            newGroup.IsChecked = false;

            if (group.Contacts!=null)

                foreach(var item in group.Contacts)

                    newGroup.Contacts.Add(new DistributionTreeContact

                    {

                        Id = item.Id,

                        IsChecked = false,

                        Fio = item.Fio,

                        Photo = item.Photo,

                        CellPhone = item.CellPhone

                    });

 

            Groups.Add(newGroup);

        }

 

        public VMDistributionTreeEdit()

        {

            Groups = new List<DistributionTreeGroup>();

        }

 

        public void CheckedAll()

        {

            foreach (var group in Groups)

            {

                group.IsChecked = true;

                foreach (var contact in group.Contacts)

                {

                    contact.IsChecked = true;

                }

            }

        }

    }

 

    public class DistributionTreeGroup : Notifer

    {

        private Guid _id;

        private string _title;

        private bool _isChecked;

        private List<DistributionTreeContact> _contacts;

 

 

        public string Title

        {

            get { return _title; }

            set

            {

                _title = value;

                OnPropertyChanged("Title");

            }

        }

        public bool IsChecked

        {

            get { return _isChecked; }

            set

            {

                _isChecked = value;

                OnPropertyChanged("IsChecked");

            }

        }

        public Guid Id

        {

            get { return _id; }

            set

            {

                _id = value;

                OnPropertyChanged("Id");

            }

        }

        public List<DistributionTreeContact> Contacts

        {

            get { return _contacts; }

            set

            {

                _contacts = value;

                OnPropertyChanged("Contacts");

            }

        }

 

        public DistributionTreeGroup()

        {

            Contacts = new List<DistributionTreeContact>();

        }

    }

 

    public class DistributionTreeContact : Notifer

    {

        private Guid _id;

        private string _fio;

        private bool _isChecked;

        private string _photo;

        private string _cellPhone;

 

        public string Fio

        {

            get { return _fio; }

            set

            {

                _fio = value;

                OnPropertyChanged("Title");

            }

        }

        public bool IsChecked

        {

            get { return _isChecked; }

            set

            {

                _isChecked = value;

                OnPropertyChanged("IsChecked");

            }

        }

        public Guid Id

        {

            get { return _id; }

            set

            {

                _id = value;

                OnPropertyChanged("Id");

            }

        }

        public string Photo

        {

            get { return _photo; }

            set

            {

                _photo = value;

                OnPropertyChanged("Photo");

            }

        }

        public string CellPhone

        {

            get { return _cellPhone; }

            set

            {

                _cellPhone = value;

                OnPropertyChanged("CellPhone");

            }

        }

    }

}

 

 

VMSmsSend.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace SmsMessanger.Model.ViewModels

{

    class VMSmsSend:Notifer

    {

        private List<DistributionTreeGroup> _groups;

        private List<SmsTemplate> _smsTemplates;

        private SmsTemplate _currentTemplate;

 

 

        public List<DistributionTreeGroup> Groups

        {

            get { return _groups; }

            set

            {

                _groups = value;

                OnPropertyChanged("Groups");

            }

        }

        public SmsTemplate CurrentTemplate

        {

            get { return _currentTemplate; }

            set

            {

                _currentTemplate = value;

                OnPropertyChanged("CurrentTemplate");

            }

        }

        public List<SmsTemplate> SmsTemplates

        {

            get { return _smsTemplates; }

            set

            {

                _smsTemplates = value;

                OnPropertyChanged("SmsTemplates");

            }

        }

 

        public void SetupGroups(List<Group> groups)

        {

            foreach (var item in groups)

            {

                AddGroup(item);

            }

        }

        public void AddGroup(Group group)

        {

            DistributionTreeGroup newGroup = new DistributionTreeGroup();

            newGroup.Title = group.Title;

            newGroup.Id = group.Id;

            newGroup.IsChecked = false;

 

            foreach (var item in group.Contacts)

                newGroup.Contacts.Add(new DistributionTreeContact

                {

                    Id = item.Id,

                    IsChecked = false,

                    Fio = item.Fio,

                    Photo = item.Photo

                });

 

            Groups.Add(newGroup);

        }

 

        public VMSmsSend(DistributionList distributionList,List<SmsTemplate> avalableTemplates, SmsTemplate smsTemplate)

        {

            CurrentTemplate = smsTemplate;

            SetupGroups(distributionList.Groups);

            SmsTemplates = avalableTemplates;

        }

    }

}

 

Contact.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

 

namespace SmsMessanger.Model

{

    [Serializable]

    public class Contact:Notifer

    {

        private Guid _id;

        private string _firstName;

        private string _lastName;

        private string _number;

        private string _cellPhone;

        private string _homePhone;

        private string _address;

        private string _photo;

        private Guid _groupId;

        private DateTime? _birthDay;

 

        [NonSerialized]

        private Group _group;

        [NonSerialized]

        private bool _checked;

 

 

        public Guid Id

        {

            get { return _id; }

            set

            {

                _id = value;

                OnPropertyChanged("Id");

            }

 

        }       

        public string FirstName

        {

            get { return _firstName; }

            set

            {

                _firstName = value;

                OnPropertyChanged("FirstName");

                OnPropertyChanged("Fio");

            }

 

        }

        public string LastName

        {

            get { return _lastName; }

            set

            {

                _lastName = value;

                OnPropertyChanged("LastName");

                OnPropertyChanged("Fio");

            }

 

        }

        public string Fio

        {

            get

            {

                if (string.IsNullOrEmpty(FirstName) && string.IsNullOrEmpty(LastName))

                    return "Новый студент";

                return string.Format("{0} {1}",FirstName,LastName);

            }

        }

        public string Number

        {

            get { return _number; }

            set

            {

                _number = value;

                OnPropertyChanged("Number");

            }

 

        }

        public string CellPhone

        {

            get { return _cellPhone; }

            set

            {

                _cellPhone = value;

                OnPropertyChanged("CellPhone");

            }

 

        }

        public string HomePhone

        {

            get { return _homePhone; }

            set

            {

                _homePhone = value;

                OnPropertyChanged("HomePhone");

            }

 

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