Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Diplom Spec.doc
Скачиваний:
0
Добавлен:
01.07.2025
Размер:
4 Мб
Скачать
☆

Додатки

Фрагменти коду програми

Головне меню:

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;

namespace АРМАвтопарк

{

public partial class Form1 : Form

{

public static string PIBShort;

public Form1()

{

InitializeComponent();

toolStripStatusLabel3.Text = "";

timer1.Enabled = true;

timer1.Interval = 1000;

}

private void Form1_Load(object sender, EventArgs e)

{

toolStripStatusLabel2.Text = "Дата: " + System.DateTime.Now.Day+"."+System.DateTime.Now.Month+"."+System.DateTime.Now.Year;

}

private void timer1_Tick(object sender, EventArgs e)

{

toolStripStatusLabel3.Text = "Час: " + DateTime.Now.ToLongTimeString();

}

private void проНасToolStripMenuItem_Click(object sender, EventArgs e)

{

About ab = new About();

ab.ShowDialog();

}

private void диспетчериToolStripMenuItem_Click(object sender, EventArgs e)

{

Disp ds = new Disp();

ds.ShowDialog();

}

private void button1_Click(object sender, EventArgs e)

{

string pasdb;

DBConn db = new DBConn();

db.OpenConnection();

pasdb = db.SelPass(textBox1.Text);

string pasnew = DBConn.GetHashString(textBox2.Text);

db.CloseConnection();

if (pasdb != pasnew)

{

label3.Visible = true;

}

else

{

groupBox1.Visible = false;

menuStrip1.Visible = true;

db.OpenConnection();

string PIB = db.SelPib(textBox1.Text);

db.CloseConnection();

toolStripSplitButton1.Visible = true;

string [] pib = PIB.Split(' ');

PIBShort = pib[0]+" "+ pib[1].Substring(0,1)+"."+pib[2].Substring(0,1)+".";

toolStripStatusLabel1.Text = "Ви ввійшли як: " + PIBShort;

monthCalendar1.Visible = true;

groupBox2.Visible = true;

db.OpenConnection();

db.insertAudit("Користувач увійшов");

db.CloseConnection();

}

}

private void toolStripSplitButton1_ButtonClick(object sender, EventArgs e)

{

DBConn db = new DBConn();

groupBox1.Visible = true;

menuStrip1.Visible = false;

toolStripStatusLabel1.Text = "Ви на виконали вхід. Для продовдення роботи введіть свій логін та пароль";

toolStripSplitButton1.Visible = false;

monthCalendar1.Visible = false;

groupBox2.Visible = false;

db.OpenConnection();

db.insertAudit("Користувач вийшов");

db.CloseConnection();

}

private void журналToolStripMenuItem_Click(object sender, EventArgs e)

{

Journal j = new Journal();

j.ShowDialog();

}

private void водіїToolStripMenuItem_Click(object sender, EventArgs e)

{

Vodij v = new Vodij();

v.ShowDialog();

}

private void паливоToolStripMenuItem_Click(object sender, EventArgs e)

{

Паливо pl = new Паливо();

pl.ShowDialog();

}

private void причепиToolStripMenuItem_Click(object sender, EventArgs e)

{

Prich p = new Prich();

p.ShowDialog();

}

private void автомобіліToolStripMenuItem_Click(object sender, EventArgs e)

{

Auto a = new Auto();

a.ShowDialog();

}

private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)

{

label4.Text = monthCalendar1.SelectionStart.ToString("yyyy.MM.dd");

DBConn db = new DBConn();

db.OpenConnection();

label5.Text = db.StringTasks(label4.Text);

db.CloseConnection();

}

private void monthCalendar1_VisibleChanged(object sender, EventArgs e)

{

label4.Text = monthCalendar1.SelectionStart.ToString("yyyy.MM.dd");

}

private void замовленняToolStripMenuItem_Click(object sender, EventArgs e)

{

zamovlennja z = new zamovlennja();

z.ShowDialog();

}

private void подорожніЛистиToolStripMenuItem_Click(object sender, EventArgs e)

{

Подорожній_лист p = new Подорожній_лист();

p.ShowDialog();

}

private void пробігАвтоЗаПеріодToolStripMenuItem_Click(object sender, EventArgs e)

{

Пробіг_авто_за_період p = new Пробіг_авто_за_період();

p.ShowDialog();

}

private void звітЗамовленьToolStripMenuItem_Click(object sender, EventArgs e)

{

Звіт_замовлень z = new Звіт_замовлень();

z.ShowDialog();

}

private void розхідВодиToolStripMenuItem_Click(object sender, EventArgs e)

{

Розхід_палива f = new Розхід_палива();

f.ShowDialog();

private void подорожніЛистиДиспетчераToolStripMenuItem_Click(object sender, EventArgs e)

{

ПЛ_Диспетчера p = new ПЛ_Диспетчера();

p.ShowDialog();

}

private void інстрекціяКористувачаToolStripMenuItem_Click(object sender, EventArgs e)

{

Інструкція_користувача i = new Інструкція_користувача();

i.ShowDialog();

}

}

}

Форма реєстрації диспетчера

namespace АРМАвтопарк

{

public partial class New_disp : Form

{

public New_disp()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

if (textBox3.Text == textBox4.Text)

{

DBConn db = new DBConn();

db.OpenConnection();

string Pass = DBConn.GetHashString(textBox3.Text);

db.InsertDisp(textBox1.Text, textBox2.Text, Pass);

db.CloseConnection();

Disp us = this.Owner as Disp;

if (us != null)

{

us.Disp_Load(sender, e);

}

Close();

}

else

{

label5.Visible = true;

}

}

}

}

Клас запитів до БД

namespace АРМАвтопарк

{

public class DBConn

{

private SqlConnection connect = null;

public void OpenConnection()

{

connect = new SqlConnection(@"Data Source=DESKTOP-NVFIR3P\SQLEXPRESS;Initial Catalog=ARMAuto;Integrated Security=True");

connect.Open();

}

public void CloseConnection()

{

connect.Close();

}

public void InsertDisp(string PIB, string Login, string Pass)

{

string sql = string.Format("Insert Into Диспетчер" +

"(ПІБ, Логін, Пароль) Values(@PIB, @Login, @Pass)");

using (SqlCommand cmd = new SqlCommand(sql, this.connect))

{

// Добавить параметры

cmd.Parameters.AddWithValue("@PIB", PIB);

cmd.Parameters.AddWithValue("@Login", Login);

cmd.Parameters.AddWithValue("@Pass", Pass);

cmd.ExecuteNonQuery();

}

}

public string SelPass(string Login)

{

string sql = string.Format("Select Пароль FROM Диспетчер WHERE Логін = '"+Login+"'");

string pas;

using (SqlCommand cmd = new SqlCommand(sql, this.connect))

{

pas = Convert.ToString(cmd.ExecuteScalar());

}

return pas;

}

public string SelPib(string Login)

{

string sql = string.Format("Select ПІБ FROM Диспетчер WHERE Логін = '" + Login + "'");

string Pib;

using (SqlCommand cmd = new SqlCommand(sql, this.connect))

{

Pib = Convert.ToString(cmd.ExecuteScalar());

}

return Pib;

}

public static string GetHashString(string s)

{

byte[] bytes = Encoding.Unicode.GetBytes(s);

MD5CryptoServiceProvider CSP =

new MD5CryptoServiceProvider();

byte[] byteHash = CSP.ComputeHash(bytes);

string hash = string.Empty;

foreach (byte b in byteHash)

hash += string.Format("{0:x2}", b);

return hash;

}

public int CountFreeCars(string tip)

{

int count=0;

string sql = string.Format("Select COUNT(Код_авто) FROM Автомобіль WHERE Тип='" + tip + "' AND Стан='Вільний'");

using (SqlCommand cmd = new SqlCommand(sql, this.connect))

{

count = Convert.ToInt32(cmd.ExecuteScalar());

}

return count;

}

public string StringTasks(string dat)

{

string str="";

string sql = string.Format("SELECT Код_замовлення, Замовник FROM Замовлення WHERE CONVERT(varchar(10), Дата_і_час, 102)='"+dat+"'");

using (SqlCommand cmd = new SqlCommand(sql, this.connect))

{

SqlDataReader reader = cmd.ExecuteReader();

if (reader.HasRows)

{

while (reader.Read())

{

str = str + "Замовлення №" + reader[0] + " замовник:"+reader[1]+". ";

}

}

}

return str;

}

public void insertAudit(string Act)

{

string sql = string.Format("Insert Into Журнал" +

"(Користувач, [Дата і час], Дія) Values('"+Form1.PIBShort+"', '"+DateTime.Now+"', @Act)");

using (SqlCommand cmd = new SqlCommand(sql, this.connect))

{

cmd.Parameters.AddWithValue("@Act", Act);

cmd.ExecuteNonQuery();

}

}

public int Kod(string vidpr, string pov)

{

int kod=0;

string sql = string.Format("SELECT Код_листа FROM Подорожній_лист Where Дата_і_час_відправки='" + vidpr + "' AND Дата_і_час_повернення='" + pov + "'");

using (SqlCommand cmd = new SqlCommand(sql, this.connect))

{

kod = Convert.ToInt32(cmd.ExecuteScalar());

}

return kod;

}

}

}

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]