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

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

                        </ItemsPanelTemplate>

                    </Setter.Value>

                </Setter>

            </Trigger>

        </Style.Triggers>

    </Style>

</ResourceDictionary>

 

TransparentButton.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

                   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

 

    <Style x:Key="ButtonFocusVisual">

        <Setter Property="Control.Template">

            <Setter.Value>

                <ControlTemplate>

                    <Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>

                </ControlTemplate>

            </Setter.Value>

        </Setter>

    </Style>

    <!-- Resource dictionary entries should be defined here. -->

    <LinearGradientBrush x:Key="ButtonNormalBackground" EndPoint="0,1" StartPoint="0,0">

        <GradientStop Color="#F3F3F3" Offset="0"/>

        <GradientStop Color="#EBEBEB" Offset="0.5"/>

        <GradientStop Color="#DDDDDD" Offset="0.5"/>

        <GradientStop Color="#CDCDCD" Offset="1"/>

    </LinearGradientBrush>

    <SolidColorBrush x:Key="ButtonNormalBorder" Color="#FF707070"/>

    <Style x:Key="TransparentButton" TargetType="{x:Type Button}">

        <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>

        <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>

        <Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>

        <Setter Property="BorderThickness" Value="1"/>

        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>

        <Setter Property="HorizontalContentAlignment" Value="Center"/>

        <Setter Property="VerticalContentAlignment" Value="Center"/>

        <Setter Property="Padding" Value="1"/>

        <Setter Property="Cursor" Value="Hand"/>

        <Setter Property="Template">

            <Setter.Value>

                <ControlTemplate TargetType="{x:Type Button}">

                    <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>

                    <ControlTemplate.Triggers>

                        <Trigger Property="IsKeyboardFocused" Value="true"/>

                        <Trigger Property="ToggleButton.IsChecked" Value="true"/>

                        <Trigger Property="IsEnabled" Value="false">

                            <Setter Property="Foreground" Value="#ADADAD"/>

                        </Trigger>

                    </ControlTemplate.Triggers>

                </ControlTemplate>

            </Setter.Value>

        </Setter>

    </Style>

 

</ResourceDictionary>

Приложение Г. Код классов программы.

App

using System;

using System.Collections.Generic;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Windows;

 

namespace SmsMessanger

{

    /// <summary>

    /// Interaction logic for App.xaml

    /// </summary>

    public partial class App : Application

    {

    }

}

 

 

Shell

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

{

    /// <summary>

    /// Interaction logic for MainWindow.xaml

    /// </summary>

    ///

 

   

 

    public partial class Shell : Window

    {

        private System.Windows.Forms.NotifyIcon notifyIcon;

 

        public System.Windows.Forms.NotifyIcon NotifyIcon

        {

            get { return notifyIcon; }

        }

 

        public Shell()

        {

            InitializeComponent();

 

            #region Установка иконки в трее

            notifyIcon = new System.Windows.Forms.NotifyIcon();

           

            //notifyIcon.BalloonTipTitle = "SMS Messenger";

            //notifyIcon.BalloonTipText = "SMS";

 

            notifyIcon.Text = "Sms Messenger";

            notifyIcon.Icon = new System.Drawing.Icon(@"icon.ico");

            notifyIcon.DoubleClick += (o, arg) =>

                {

                    Show();

                    WindowState = System.Windows.WindowState.Normal;

                };

 

            if (notifyIcon != null)

                notifyIcon.Visible = true;

            #endregion

 

            DataContext = new ApplicationPresenter(this);

        }

 

        public void RemoveTab(TabItem tabItem)

        {

            tabs.Items.Remove(tabItem);

        }

 

        public void RemoveAllTabs()

        {

            tabs.Items.Clear();

        }

 

        public void AddTab<T>(PresenterBase<T> presenter)

        {

            TabItem newTab = null;

            foreach(TabItem existingTab in tabs.Items)

                if (existingTab.DataContext.Equals(presenter))

                {

                    tabs.Items.Remove(existingTab);

                    newTab = existingTab;

                    break;

                }

            if(newTab==null)

            {

                newTab = new TabItem();

                Binding headerBinding = new Binding(presenter.TabHeaderPath);

                BindingOperations.SetBinding(

                    newTab,

                    TabItem.HeaderProperty,

                    headerBinding

                    );

                newTab.DataContext = presenter;

                newTab.Content = presenter.View;

            }

 

            #region Контекстное меню шапки

            ContextMenu tabMenu = new System.Windows.Controls.ContextMenu();

           

            MenuItem item = new MenuItem(){Header="Закрыть"};

            item.Click+=(o,arg)=>

                {

                    RemoveTab(newTab);

                };

            tabMenu.Items.Add(item);

            item = new MenuItem() { Header = "Закрыть все" };

            item.Click += (o, arg) =>

            {

                RemoveAllTabs();

            };

            tabMenu.Items.Add(item);

 

 

            newTab.ContextMenu = tabMenu;

            #endregion

 

            tabs.Items.Insert(0, newTab);

            newTab.Focus();

        }

 

        public void RemoveTab<T>(PresenterBase<T> presenter)

        {

            foreach(TabItem existingTab in tabs.Items)

                if (existingTab.DataContext.Equals(presenter))

                {

                    tabs.Items.Remove(existingTab);

                    break;

                }

        }

 

        private void app_closed(object sender, EventArgs e)

        {

            Loger.Write("Приложение закрыто", LogImages.Exit);

        }

 

        private void Window_StateChanged(object sender, EventArgs e)

        {

            if (WindowState == System.Windows.WindowState.Minimized)

            {

                Hide();

               

                if (notifyIcon != null)

                    notifyIcon.ShowBalloonTip(2000);

            }

        }

    }

}

Notifer.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.ComponentModel;

 

namespace SmsMessanger

{

    [Serializable]

    public abstract class Notifer : INotifyPropertyChanged

    {

        [field: NonSerialized]

        public event PropertyChangedEventHandler PropertyChanged;

 

        protected virtual void OnPropertyChanged(string propertyName)

        {

            if (PropertyChanged != null)

            {

                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

            }

        }

    }

}

 

Config.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Configuration;

using System.Xml.Linq;

 

namespace SmsMessanger

{

    public static class Configurator

    {

        public static string GetSetting(string settingName)

        {

            XDocument doc = XDocument.Load("Config.xml");

            XElement root = doc.Element("root");

            XElement element = root.Element(settingName);

            if (element == null) return null;

            else return element.Attribute("value").Value;

        }

        public static void SetSetting(string settingName,string value)

        {

            XDocument doc = XDocument.Load("Config.xml");

            XElement root = doc.Element("root");

            XElement element = root.Element(settingName);

            if (element != null)

                element.SetAttributeValue("value", value);

            doc.Save("Config.xml");

        }

 

        public static string SmscLogin

        {

            get { return GetSetting("SmscLogin"); }

            set { SetSetting("SmscLogin",value); }

        }

        public static string SmscPassword

        {

            get { return GetSetting("SmscPassword"); }

            set { SetSetting("SmscPassword",value); }

        }

        public static bool CombatMode

        {

            get { return bool.Parse(GetSetting("CombatMode")); }

            set { SetSetting("CombatMode",value.ToString()); }

        }

    }

}

 

 

Enums.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace SmsMessanger

{

    public enum LogImages

    {

        Normal = 0,

        Exit = 1,

        Save = 2,

        Warning = 3,

        Error = 4

    }

}

 

 

Loger.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

 

namespace SmsMessanger

{

    public static class Loger

    {

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

 

        private static string currentImage = "0";

 

        public static void Write(string text)

        {

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

            {

                TextWriter tw = new StreamWriter(stream);

                tw.WriteLine(string.Format("{0}|{1}|{2}",currentImage, DateTime.Now,text));

                tw.Close();

            }

        }

        public static void Write(string text,LogImages image)

        {

 

            currentImage = Enum.Format(typeof(LogImages), image, "d");

            Write(text);

        }

 

       

    }

}

 

 

Loger.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Windows.Media;

 

namespace SmsMessanger

{

    public static class SmsVisualTreeHelper

    {

        public static T FindAncestor<T>(DependencyObject dependencyObject)

        where T : class

        {

            DependencyObject target = dependencyObject;

            do

            {

                target = VisualTreeHelper.GetParent(target);

            }

            while (target != null && !(target is T));

            return target as T;

        }

    }

}

 

ContactRepository.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 ContactRepository:RepositoryBase<Contact>

    {

        public ContactRepository(GroupRepository groupRepository):base("Contacts.source")

        {

            //Связываем контакты и группы

            foreach (Contact contact in _store)

            {

                contact.Group = groupRepository.GetGroup(contact.GroupId);

                if (contact.Group == null) continue;

                if (contact.Group.Contacts == null) contact.Group.Contacts = new List<Contact>();

                contact.Group.Contacts.Add(contact);

            }

        }

 

        public Contact GetContact(Guid id)

        {

            return _store.First(c => c.Id == id);

        }

 

        public void DeleteContact(Contact contact)

        {

            if (contact != null)

                _store.Remove(contact);

            Serialize();

        }

 

        public void SaveContact(Contact contact)

        {

            if (contact.Id == Guid.Empty)

                contact.Id = Guid.NewGuid();

            if (!_store.Contains(contact))

                _store.Add(contact);

            Serialize();

        }

 

        public List<Contact> FindAll()

        {

            return new List<Contact>(_store);

        }

 

        public List<Contact> FindById(Guid[] Ids)

        {

            return (from c in _store where Ids.Contains(c.Id) select c).ToList();

        }

 

        public void ClearChecked()

        {

            foreach (var item in _store)

            {

                item.Checked = false;

                if (item.Group!=null)

                    item.Group.Checked = false;

            }

        }

    }  

}

 

 

DistributionListRepository.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace SmsMessanger.Model

{

    class DistributionListRepository:RepositoryBase<DistributionList>

    {

 

        private ContactRepository _contactRepository;

       

        public DistributionListRepository(ContactRepository contactRepository)

            : base("DistributionList.source")

        {

 

            _contactRepository = contactRepository;

 

            RebuildTree();

        }

 

        public List<DistributionList> FindAll()

        {

            return new List<DistributionList>(_store);

        }

        public Group GetDistributionList(Guid id)

        {

            return null;

            //return _store.FirstOrDefaultx(g=>g.Id==id);

        }

        public void SaveDistributionList(DistributionList list)

        {

            if (list.Id == Guid.Empty)

                list.Id = Guid.NewGuid();

            if (!_store.Contains(list))

                _store.Add(list);

            Serialize();

        }

        public void DeleteDestributionList(DistributionList list)

        {

            if (list != null)

            {

                _store.Remove(list);

                Serialize();

            }

        }

 

        public void RebuildTree()

        {

            foreach (var dList in _store)

            {

                dList.Contacts = (from c in _contactRepository.FindAll() where dList.ContactsId.Contains(c.Id) select c).ToList();

                dList.Groups = DistributionList.BuildGroupsByContacts(dList.Contacts);

            }

        }

    }

}

 

 

DistributionListRepository.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace SmsMessanger.Model

{

    public class GroupRepository:RepositoryBase<Group>

    {

        public GroupRepository():base("Groups.source")

        {

            //SaveGroup(new Group(){ Title = "Group-1"});

        }

       

        public List<Group> FindAll()

        {

            return new List<Group>(_store);

        }

 

        public Group GetGroup(Guid id)

        {

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

        }

 

        public void SaveGroup(Group group)

        {

            if (group.Id == Guid.Empty)

                group.Id = Guid.NewGuid();

            if (!_store.Contains(group))

                _store.Add(group);

            Serialize();

        }

 

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