Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Самая последния курсовая (таблицы).docx
Скачиваний:
2
Добавлен:
01.05.2025
Размер:
659 Кб
Скачать
☆

Приложение а

Диаграммы uml

Рисунок 1– Диаграмма вариантов использования

Рисунок 2 – Диаграмма последовательности

Рисунок 3- Диаграмма деятельности

Рисунок 4 - Диаграмма состояний

Рисунок 5 – Диаграмма развертывания

ПРИЛОЖЕНИЕ Б

Скрипт создания базы данных

CREATE TABLE Абоненты

(

НомерТелефона integer NOT NULL ,

ФИО varchar(20) NULL ,

Адрес varchar(20) NULL ,

ДатаПодключения varchar(20) NULL

)

go

ALTER TABLE Абоненты

ADD CONSTRAINT XPKАбоненты PRIMARY KEY CLUSTERED (НомерТелефона ASC)

go

CREATE TABLE Обслуживание

(

ID integer NOT NULL ,

НомерТелефона integer NULL ,

Дата varchar(20) NULL ,

Время integer NULL ,

Тариф integer NULL ,

Стоимость integer NULL

)

go

ALTER TABLE Обслуживание

ADD CONSTRAINT XPKОбслуживаниеРазговоров PRIMARY KEY CLUSTERED (ID ASC)

go

CREATE TABLE Услуги

(

КодУслуги integer NOT NULL ,

Наименование varchar(20) NULL ,

Стоимость integer NULL ,

Дата char(18) NULL ,

НомерТелефона integer NULL

)

go

ALTER TABLE Услуги

ADD CONSTRAINT XPKУслуги PRIMARY KEY CLUSTERED (КодУслуги ASC)

go

ALTER TABLE Обслуживание

ADD CONSTRAINT R_16 FOREIGN KEY (НомерТелефона) REFERENCES Абоненты(НомерТелефона)

ON DELETE NO ACTION

ON UPDATE NO ACTION

go

ALTER TABLE Услуги

ADD CONSTRAINT R_17 FOREIGN KEY (НомерТелефона) REFERENCES Абоненты(НомерТелефона)

ON DELETE NO ACTION

ON UPDATE NO ACTION

go

Приложение в листинг

Клиентское приложение

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Net;

using System.Net.Sockets;

namespace Client

{

public partial class Clients : Form

{

public Clients()

{

InitializeComponent();

}

private void Clients_Load(object sender, EventArgs e)

{

string msg = "Select * From Жильцы";

richTextBox1.Text = SendMessageFromSocket(11000, msg);

}

static string SendMessageFromSocket(int port, string message)

{

// Буфер для входящих данных

byte[] bytes = new byte[1024];

// Соединяемся с удаленным устройством

// Устанавливаем удаленную точку для сокета

IPHostEntry ipHost = Dns.GetHostEntry("localhost");

IPAddress ipAddr = ipHost.AddressList[0];

IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, port);

Socket sender = new Socket(ipAddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

// Соединяем сокет с удаленной точкой

sender.Connect(ipEndPoint);

byte[] msg = Encoding.UTF8.GetBytes(message);

// Отправляем данные через сокет

int bytesSent = sender.Send(msg);

// Получаем ответ от сервера

int bytesRec = sender.Receive(bytes);

//Console.WriteLine(Encoding.UTF8.GetString(bytes, 0, bytesRec));

// Освобождаем сокет

sender.Shutdown(SocketShutdown.Both);

sender.Close();

return Encoding.UTF8.GetString(bytes, 0, bytesRec);

}

private void button1_Click(object sender, EventArgs e)

{

this.Close();

}

private void button2_Click(object sender, EventArgs e)

{

string msg = "INSERT INTO Жильцы (НомерТелефона,ФИО,Адрес, ДатаПодключения) VALUES (" +

textBox1.Text + ",'" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "')";

MessageBox.Show(SendMessageFromSocket(11000, msg),

"Результат ", MessageBoxButtons.OK);

this.Close();

}

private void button3_Click(object sender, EventArgs e)

{

string msg = "Delete From Жильцы Where НомерТелефона=" +

textBox1.Text ;

MessageBox.Show(SendMessageFromSocket(11000, msg),

"Результат ", MessageBoxButtons.OK);

this.Close();

}

}

}

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Net;

using System.Net.Sockets;

namespace Client

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

}

private void просмотрКлиентовToolStripMenuItem_Click(object sender, EventArgs e)

{

Clients form1 = new Clients();

form1.ShowDialog();

}

private void просмотрТоваровToolStripMenuItem_Click(object sender, EventArgs e)

{

}

private void просмотрСотрудниковToolStripMenuItem_Click(object sender, EventArgs e)

{

}

private void добавитьНовогоКлиентаToolStripMenuItem_Click(object sender, EventArgs e)

{

ServiceView form1 = new ServiceView();

form1.ShowDialog();

}

private void удалитьКлиентаToolStripMenuItem_Click(object sender, EventArgs e)

{

}

private void выходToolStripMenuItem_Click(object sender, EventArgs e)

{

this.Close();

string msg = "TheEnd";

SendMessageFromSocket(11000, msg);

}

private void поискДанныхToolStripMenuItem_Click(object sender, EventArgs e)

{

}

private void принятьНаУчетToolStripMenuItem1_Click(object sender, EventArgs e)

{

Priem form1 = new Priem();

form1.ShowDialog();

}

private void просмортОтчетаToolStripMenuItem_Click(object sender, EventArgs e)

{

}

private void pictureBox1_Click(object sender, EventArgs e)

{

}

private void оПрограммеToolStripMenuItem_Click(object sender, EventArgs e)

{

}

static void SendMessageFromSocket(int port, string message)

{

// Буфер для входящих данных

byte[] bytes = new byte[1024];

// Соединяемся с удаленным устройством

// Устанавливаем удаленную точку для сокета

IPHostEntry ipHost = Dns.GetHostEntry("localhost");

IPAddress ipAddr = ipHost.AddressList[0];

IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, port);

Socket sender = new Socket(ipAddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

// Соединяем сокет с удаленной точкой

sender.Connect(ipEndPoint);

byte[] msg = Encoding.UTF8.GetBytes(message);

// Отправляем данные через сокет

int bytesSent = sender.Send(msg);

sender.Shutdown(SocketShutdown.Both);

sender.Close();

}

private void поискToolStripMenuItem1_Click(object sender, EventArgs e)

{

Poisk form1 = new Poisk();

form1.ShowDialog();

}

private void отчетToolStripMenuItem_Click(object sender, EventArgs e)

{

Report form1 = new Report();

form1.ShowDialog();

}

private void поискToolStripMenuItem_Click(object sender, EventArgs e)

{

AboutBox1 form1 = new AboutBox1();

form1.ShowDialog();

}

}

}

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Net;

using System.Net.Sockets;

namespace Client

{

public partial class Poisk : Form

{

public Poisk()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

string msg = "Select * From View2 WHERE ФИО='" + textBox1.Text + "'";

richTextBox1.Text = SendMessageFromSocket(11000, msg);

}

static string SendMessageFromSocket(int port, string message)

{

// Буфер для входящих данных

byte[] bytes = new byte[1024];

// Соединяемся с удаленным устройством

// Устанавливаем удаленную точку для сокета

IPHostEntry ipHost = Dns.GetHostEntry("localhost");

IPAddress ipAddr = ipHost.AddressList[0];

IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, port);

Socket sender = new Socket(ipAddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

// Соединяем сокет с удаленной точкой

sender.Connect(ipEndPoint);

byte[] msg = Encoding.UTF8.GetBytes(message);

// Отправляем данные через сокет

int bytesSent = sender.Send(msg);

// Получаем ответ от сервера

int bytesRec = sender.Receive(bytes);

//Console.WriteLine(Encoding.UTF8.GetString(bytes, 0, bytesRec));

// Освобождаем сокет

sender.Shutdown(SocketShutdown.Both);

sender.Close();

return Encoding.UTF8.GetString(bytes, 0, bytesRec);

}

private void button2_Click(object sender, EventArgs e)

{

this.Close();

}

}

}

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Net;

using System.Net.Sockets;

namespace Client

{

public partial class Priem : Form

{

public Priem()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

string msg = "INSERT INTO Обслуживание (ID,НомерТелефона,Дата, Время) VALUES ( "+

textBox1.Text + ", " + textBox2.Text + ",' " +textBox4.Text + "',' " +textBox5.Text + "' )" ;

MessageBox.Show(SendMessageFromSocket(11000, msg),

"Результат ", MessageBoxButtons.OK);

this.Close();

}

static string SendMessageFromSocket(int port, string message)

{

// Буфер для входящих данных

byte[] bytes = new byte[1024];

// Соединяемся с удаленным устройством

// Устанавливаем удаленную точку для сокета

IPHostEntry ipHost = Dns.GetHostEntry("localhost");

IPAddress ipAddr = ipHost.AddressList[0];

IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, port);

Socket sender = new Socket(ipAddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

// Соединяем сокет с удаленной точкой

sender.Connect(ipEndPoint);

byte[] msg = Encoding.UTF8.GetBytes(message);

// Отправляем данные через сокет

int bytesSent = sender.Send(msg);

// Получаем ответ от сервера

int bytesRec = sender.Receive(bytes);

//Console.WriteLine(Encoding.UTF8.GetString(bytes, 0, bytesRec));

// Освобождаем сокет

sender.Shutdown(SocketShutdown.Both);

sender.Close();

return Encoding.UTF8.GetString(bytes, 0, bytesRec);

}

}

}

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Net;

using System.Net.Sockets;

namespace Client

{

public partial class Report : Form

{

public Report()

{

InitializeComponent();

}

private void Report_Load(object sender, EventArgs e)

{

string msg = "Select * From View1";

richTextBox1.Text = SendMessageFromSocket(11000, msg);

}

static string SendMessageFromSocket(int port, string message)

{

// Буфер для входящих данных

byte[] bytes = new byte[1024];

// Соединяемся с удаленным устройством

// Устанавливаем удаленную точку для сокета

IPHostEntry ipHost = Dns.GetHostEntry("localhost");

IPAddress ipAddr = ipHost.AddressList[0];

IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, port);

Socket sender = new Socket(ipAddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

// Соединяем сокет с удаленной точкой

sender.Connect(ipEndPoint);

byte[] msg = Encoding.UTF8.GetBytes(message);

// Отправляем данные через сокет

int bytesSent = sender.Send(msg);

// Получаем ответ от сервера

int bytesRec = sender.Receive(bytes);

//Console.WriteLine(Encoding.UTF8.GetString(bytes, 0, bytesRec));

// Освобождаем сокет

sender.Shutdown(SocketShutdown.Both);

sender.Close();

return Encoding.UTF8.GetString(bytes, 0, bytesRec);

}

private void button1_Click(object sender, EventArgs e)

{

this.Close();

}

}

}

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Net;

using System.Net.Sockets;

namespace Client

{

public partial class ServiceView : Form

{

public ServiceView()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

this.Close();

}

private void TovatView_Load(object sender, EventArgs e)

{

string msg = "Select * From Услуги";

richTextBox1.Text= SendMessageFromSocket(11000, msg);

}

static string SendMessageFromSocket(int port, string message)

{

// Буфер для входящих данных

byte[] bytes = new byte[1024];

// Соединяемся с удаленным устройством

// Устанавливаем удаленную точку для сокета

IPHostEntry ipHost = Dns.GetHostEntry("localhost");

IPAddress ipAddr = ipHost.AddressList[0];

IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, port);

Socket sender = new Socket(ipAddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

// Соединяем сокет с удаленной точкой

sender.Connect(ipEndPoint);

byte[] msg = Encoding.UTF8.GetBytes(message);

// Отправляем данные через сокет

int bytesSent = sender.Send(msg);

// Получаем ответ от сервера

int bytesRec = sender.Receive(bytes);

//Console.WriteLine(Encoding.UTF8.GetString(bytes, 0, bytesRec));

// Освобождаем сокет

sender.Shutdown(SocketShutdown.Both);

sender.Close();

return Encoding.UTF8.GetString(bytes, 0, bytesRec);

}

private void button2_Click(object sender, EventArgs e)

{

string msg = "INSERT INTO Услуги (КодУслуги,Наименование,Стоимость, Дата, НомерТелефона) VALUES (" +

textBox1.Text + ",'" + textBox2.Text + "'," + textBox3.Text + ",'" + textBox4.Text + "'," + textBox5.Text + ")";

MessageBox.Show(SendMessageFromSocket(11000, msg),

"Результат ", MessageBoxButtons.OK);

this.Close();

}

private void button3_Click(object sender, EventArgs e)

{

string msg = "Delete FROM Услуги WHERE КодУслуги=" + textBox1.Text;

MessageBox.Show(SendMessageFromSocket(11000, msg),

"Результат ", MessageBoxButtons.OK);

this.Close();

}

}

}

Приложение-сервер

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Net;

using System.Net.Sockets;

using System.Data.SqlClient;

namespace Server

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

// Устанавливаем для сокета локальную конечную точку

IPHostEntry ipHost = Dns.GetHostEntry("localhost");

IPAddress ipAddr = ipHost.AddressList[0];

IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, 11000);

// Создаем сокет Tcp/Ip

Socket sListener = new Socket(ipAddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

// Назначаем сокет локальной конечной точке и слушаем входящие сокеты

try

{

sListener.Bind(ipEndPoint);

sListener.Listen(10);

MessageBox.Show("Ожидаем соединение через порт " + ipEndPoint,

"Уведомление о соединении", MessageBoxButtons.OK);

// Начинаем слушать соединения

while (true)

{

//

// Программа приостанавливается, ожидая входящее соединение

Socket handler = sListener.Accept();

string data = null;

// Мы дождались клиента, пытающегося с нами соединиться

byte[] bytes = new byte[1024];

int bytesRec = handler.Receive(bytes);

data += Encoding.UTF8.GetString(bytes, 0, bytesRec);

// Показываем данные на консоли

// ответ сервера

string reply;

reply = ToDatabase(data);

byte[] msg3 = Encoding.UTF8.GetBytes(reply);

handler.Send(msg3);

if (data.IndexOf("<TheEnd>") > -1)

{

MessageBox.Show("Сервер завершил соединение с клиентом.",

"Уведомление о завершении операции", MessageBoxButtons.OK);

Console.WriteLine();

break;

}

}

}

catch (Exception ex)

{

MessageBox.Show(ex.ToString(),

"Ошибка", MessageBoxButtons.OK);

}

finally

{

Console.ReadLine();

}

}

static string ToDatabase(string sqlStatement)

{

string result = string.Empty;

using (SqlConnection connection = new SqlConnection("Data Source=ULIA-PK;Initial Catalog=ATS;Integrated Security=True"))

{

SqlCommand cmd = new SqlCommand(sqlStatement, connection);

connection.Open();

SqlDataReader reader = cmd.ExecuteReader();

try

{

while (reader.Read())

{

for (int i = 0; i < reader.FieldCount; ++i)

result = result + reader[i] + " ; ";

result = result + "\n";

}

}

finally

{

reader.Close();

}

}

if (result == "")

return "Запрос успешно выполнен";

else return result;

}

private void Form1_Load(object sender, EventArgs e)

{

// Устанавливаем для сокета локальную конечную точку

IPHostEntry ipHost = Dns.GetHostEntry("localhost");

IPAddress ipAddr = ipHost.AddressList[0];

IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, 11000);

// Создаем сокет Tcp/Ip

Socket sListener = new Socket(ipAddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

// Назначаем сокет локальной конечной точке и слушаем входящие сокеты

try

{

sListener.Bind(ipEndPoint);

sListener.Listen(10);

MessageBox.Show("Ожидаем соединение через порт " + ipEndPoint,

"Уведомление о соединении", MessageBoxButtons.OK);

// Начинаем слушать соединения

while (true)

{

//

// Программа приостанавливается, ожидая входящее соединение

Socket handler = sListener.Accept();

string data = null;

// Мы дождались клиента, пытающегося с нами соединиться

byte[] bytes = new byte[1024];

int bytesRec = handler.Receive(bytes);

data += Encoding.UTF8.GetString(bytes, 0, bytesRec);

if (data=="TheEnd")

{

MessageBox.Show("Сервер завершил соединение с клиентом.",

"Уведомление о завершении операции", MessageBoxButtons.OK);

this.Close();

// break;

}

// ответ сервера

string reply;

reply = ToDatabase(data);

byte[] msg3 = Encoding.UTF8.GetBytes(reply);

handler.Send(msg3);

}

}

catch (Exception ex)

{

MessageBox.Show(ex.ToString(),

"Ошибка", MessageBoxButtons.OK);

}

finally

{

Console.ReadLine();

}

}

}

}

48