Файл: Технико-экономическая характеристика предметной области и предприятия.pdf

ВУЗ: Не указан

Категория: Курсовая работа

Дисциплина: Не указана

Добавлен: 17.06.2023

Просмотров: 124

Скачиваний: 2

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

{

get { return name_otdel; }

set { name_otdel = value; }

}

string data;

public string Data

{

get { return data; }

set { data = value; }

}

string prichina;

public string Prichina

{

get { return prichina; }

set { prichina = value; }

}

}

}

Приложение Б

Доступ к БД

using System;

using System.Collections.Generic;

using System.Data;

using System.Data.OleDb;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace Nag

{

internal class BD

{

private OleDbConnection connection;

private OleDbCommand command;

private void ConnectTo()

{

connection = new OleDbConnection(@"provider=Microsoft.Jet.OLEDB.4.0; data source=BD.mdb");

command = connection.CreateCommand();

}

public BD()

{

ConnectTo();

}

//otdel

public void Inser_otdel(otdel zad)

{

try

{

command.CommandText = "INSERT INTO otdel (Name) VALUES('" + zad.Name + "')";

command.CommandType = CommandType.Text;

connection.Open();

command.ExecuteNonQuery();

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

public void Update_otdel(otdel st, otdel now)

{

try

{

command.CommandText = "UPDATE otdel SET Name = '" + now.Name + "' WHERE ID =" + st.Id;

command.CommandType = CommandType.Text;

connection.Open();

command.ExecuteNonQuery();

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

public List<otdel> Fill_otdel()

{

List<otdel> spisok = new List<otdel>();

try

{

command.CommandText = "SELECT * FROM otdel";

command.CommandType = CommandType.Text;

connection.Open();

OleDbDataReader reader = command.ExecuteReader();

while (reader.Read())

{

otdel zad = new otdel();

zad.Id = Convert.ToInt32(reader["Id"].ToString());

zad.Name = reader["Name"].ToString();

spisok.Add(zad);

}

return spisok;

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null)

{

connection.Close();

}

}

}

public void Delete(string Id, string tab) //Удаление!!!!!!!!!!!!!!!!!!!!

{

try

{

command.CommandText = "DELETE FROM " + tab + " WHERE ID= " + Id;

command.CommandType = CommandType.Text;

connection.Open();

command.ExecuteNonQuery();

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

public List<otdel> Fill_otdel_Id(String tab)

{

List<otdel> spisok = new List<otdel>();

try

{

command.CommandText = "SELECT * FROM otdel WHERE Id = " + tab;

command.CommandType = CommandType.Text;

connection.Open();

OleDbDataReader reader = command.ExecuteReader();

while (reader.Read())

{

otdel zad = new otdel();

zad.Id = Convert.ToInt32(reader["Id"].ToString());

zad.Name = reader["Name"].ToString();

spisok.Add(zad);

}

return spisok;

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

public List<otdel> Fill_otdel_Name(String tab)

{

List<otdel> spisok = new List<otdel>();

try

{

command.CommandText = "SELECT * FROM otdel WHERE Name = " + tab;

command.CommandType = CommandType.Text;

connection.Open();

OleDbDataReader reader = command.ExecuteReader();

while (reader.Read())

{

otdel zad = new otdel();

zad.Id = Convert.ToInt32(reader["Id"].ToString());


zad.Name = reader["Name"].ToString();

spisok.Add(zad);

}

return spisok;

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

public otdel Get_otdel_Id(String tab)

{

otdel zad = new otdel();

try

{

command.CommandText = "SELECT * FROM otdel WHERE Id = " + tab;

command.CommandType = CommandType.Text;

connection.Open();

OleDbDataReader reader = command.ExecuteReader();

while (reader.Read())

{

zad.Id = Convert.ToInt32(reader["Id"].ToString());

zad.Name = reader["Name"].ToString();

}

return zad;

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

public otdel Get_otdel_Name(String tab)

{

otdel zad = new otdel();

try

{

command.CommandText = "SELECT * FROM otdel WHERE Name = '" + tab + "'";

command.CommandType = CommandType.Text;

connection.Open();

OleDbDataReader reader = command.ExecuteReader();

while (reader.Read())

{

zad.Id = Convert.ToInt32(reader["Id"].ToString());

zad.Name = reader["Name"].ToString();

}

return zad;

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

// admin

public void Inser_admin(admin zad)

{

try

{

command.CommandText = "INSERT INTO admin (Name,Tel,Adres) VALUES('" + zad.Name + "', '" + zad.Tel + "', '" + zad.Adres + "')";

command.CommandType = CommandType.Text;

connection.Open();

command.ExecuteNonQuery();

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

public List<admin> Fill_admin()

{

List<admin> spisok = new List<admin>();

try

{

command.CommandText = "SELECT * FROM admin";

command.CommandType = CommandType.Text;

connection.Open();

OleDbDataReader reader = command.ExecuteReader();

while (reader.Read())

{

admin zad = new admin();

zad.Id = Convert.ToInt32(reader["Id"].ToString());

zad.Name = reader["Name"].ToString();

zad.Tel =reader["Tel"].ToString();

zad.Adres = reader["Adres"].ToString();

spisok.Add(zad);

}

return spisok;

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null)

{

connection.Close();

}

}

}

public admin Get_admin_name(String id)

{

admin zad = new admin();

try

{

command.CommandText = "SELECT * FROM admin WHERE Name = '" + id + "'";

command.CommandType = CommandType.Text;

connection.Open();

OleDbDataReader reader = command.ExecuteReader();

while (reader.Read())

{

zad.Id = Convert.ToInt32(reader["Id"].ToString());

zad.Name = reader["Name"].ToString();

zad.Tel = reader["Tel"].ToString();

zad.Adres = reader["Adres"].ToString();

}

return zad;

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

public List<admin> Fill_admin_name(String tab)

{

List<admin> spisok = new List<admin>();

try

{

command.CommandText = "SELECT * FROM admin WHERE Name = '" + tab + " '";

command.CommandType = CommandType.Text;

connection.Open();

OleDbDataReader reader = command.ExecuteReader();

while (reader.Read())

{

admin zad = new admin();

zad.Id = Convert.ToInt32(reader["Id"].ToString());

zad.Name = reader["Name"].ToString();

zad.Tel = reader["Tel"].ToString();

zad.Adres = reader["Adres"].ToString();

spisok.Add(zad);

}

return spisok;

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

public void Update_admin(admin st, admin now)

{


try

{

command.CommandText = "UPDATE admin SET Name = '" + now.Name + "',Tel ='" + now.Tel + "',Adres ='" + now.Adres + "' WHERE ID =" + st.Id;

command.CommandType = CommandType.Text;

connection.Open();

command.ExecuteNonQuery();

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

public admin Get_admin_id(String id)

{

admin zad = new admin();

try

{

command.CommandText = "SELECT * FROM admin WHERE Id = " + id;

command.CommandType = CommandType.Text;

connection.Open();

OleDbDataReader reader = command.ExecuteReader();

while (reader.Read())

{

zad.Id = Convert.ToInt32(reader["Id"].ToString());

zad.Name = reader["Name"].ToString();

zad.Tel = reader["Tel"].ToString();

zad.Adres = reader["Adres"].ToString();

}

return zad;

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

//Klient

public void Inser_klient(klient zad)

{

try

{

command.CommandText = "INSERT INTO Klient (Name,Tel,Adres) VALUES('" + zad.Name + "', '" + zad.Tel + "', '" + zad.Adres + "')";

command.CommandType = CommandType.Text;

connection.Open();

command.ExecuteNonQuery();

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

public List<klient> Fill_klient()

{

List<klient> spisok = new List<klient>();

try

{

command.CommandText = "SELECT * FROM Klient";

command.CommandType = CommandType.Text;

connection.Open();

OleDbDataReader reader = command.ExecuteReader();

while (reader.Read())

{

klient zad = new klient();

zad.Id = Convert.ToInt32(reader["Id"].ToString());

zad.Name = reader["Name"].ToString();

zad.Tel = reader["Tel"].ToString();

zad.Adres = reader["Adres"].ToString();

spisok.Add(zad);

}

return spisok;

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null)

{

connection.Close();

}

}

}

public klient Get_klient_name(String id)

{

klient zad = new klient();

try

{

command.CommandText = "SELECT * FROM Klient WHERE Name = '" + id + "'";

command.CommandType = CommandType.Text;

connection.Open();

OleDbDataReader reader = command.ExecuteReader();

while (reader.Read())

{

zad.Id = Convert.ToInt32(reader["Id"].ToString());

zad.Name = reader["Name"].ToString();

zad.Tel = reader["Tel"].ToString();

zad.Adres = reader["Adres"].ToString();

}

return zad;

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

public List<klient> Fill_klient_name(String tab)

{

List<klient> spisok = new List<klient>();

try

{

command.CommandText = "SELECT * FROM Klient WHERE Name = '" + tab + " '";

command.CommandType = CommandType.Text;

connection.Open();

OleDbDataReader reader = command.ExecuteReader();

while (reader.Read())

{

klient zad = new klient();

zad.Id = Convert.ToInt32(reader["Id"].ToString());

zad.Name = reader["Name"].ToString();

zad.Tel = reader["Tel"].ToString();

zad.Adres = reader["Adres"].ToString();

spisok.Add(zad);

}

return spisok;

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

public void Update_klient(klient st, klient now)

{

try

{

command.CommandText = "UPDATE Klient SET Name = '" + now.Name + "',Tel ='" + now.Tel + "',Adres ='" + now.Adres + "' WHERE ID =" + st.Id;

command.CommandType = CommandType.Text;

connection.Open();

command.ExecuteNonQuery();

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }


}

}

public klient Get_klient_id(String id)

{

klient zad = new klient();

try

{

command.CommandText = "SELECT * FROM Klient WHERE Id = " + id;

command.CommandType = CommandType.Text;

connection.Open();

OleDbDataReader reader = command.ExecuteReader();

while (reader.Read())

{

zad.Id = Convert.ToInt32(reader["Id"].ToString());

zad.Name = reader["Name"].ToString();

zad.Tel = reader["Tel"].ToString();

zad.Adres = reader["Adres"].ToString();

}

return zad;

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

//zaavka

public void Inser_zaavka(zaavka zad)

{

try

{

command.CommandText = "INSERT INTO zaavka (Id_admin,Id_klient,Id_otdel,Data,Prichina) VALUES('" + zad.Id_admin + "', '" + zad.Id_klient + "', '" + zad.Id_otdel + "', '" + zad.Data + "', '" + zad.Prichina + "')";

command.CommandType = CommandType.Text;

connection.Open();

command.ExecuteNonQuery();

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

public void Update_zaavka(zaavka st,zaavka now)

{

try

{

command.CommandText = "UPDATE zaavka SET Id_admin = '" + now.Id_admin + "',Id_klient ='" + now.Id_klient + "',Id_otdel ='" + now.Id_otdel + "',Data ='" + now.Data + "',Prichina ='" + now.Prichina+"' WHERE ID =" + st.Id;

command.CommandType = CommandType.Text;

connection.Open();

command.ExecuteNonQuery();

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

public List<zaavka> Fill_zaavka()

{

List<zaavka> spisok = new List<zaavka>();

try

{

command.CommandText = "SELECT * FROM zaavka";

command.CommandType = CommandType.Text;

connection.Open();

OleDbDataReader reader = command.ExecuteReader();

while (reader.Read())

{

zaavka zad = new zaavka();

zad.Id = Convert.ToInt32(reader["Id"].ToString());

zad.Id_admin = Convert.ToInt32(reader["Id_admin"].ToString());

zad.Id_klient = Convert.ToInt32(reader["Id_klient"].ToString());

zad.Id_otdel = Convert.ToInt32(reader["Id_otdel"].ToString());

zad.Data= reader["Data"].ToString();

zad.Prichina= reader["Prichina"].ToString();

spisok.Add(zad);

}

return spisok;

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null)

{

connection.Close();

}

}

}

public List<zaavka> Fill_zaavka_idadmin(String tab)

{

List<zaavka> spisok = new List<zaavka>();

try

{

command.CommandText = "SELECT * FROM zaavka WHERE Id_admin = " + tab;

command.CommandType = CommandType.Text;

connection.Open();

OleDbDataReader reader = command.ExecuteReader();

while (reader.Read())

{

zaavka zad = new zaavka();

zad.Id = Convert.ToInt32(reader["Id"].ToString());

zad.Id_admin = Convert.ToInt32(reader["Id_admin"].ToString());

zad.Id_klient = Convert.ToInt32(reader["Id_klient"].ToString());

zad.Id_otdel = Convert.ToInt32(reader["Id_otdel"].ToString());

zad.Data = reader["Data"].ToString();

zad.Prichina = reader["Prichina"].ToString();

spisok.Add(zad);

}

return spisok;

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

public List<zaavka> Fill_zaavka_idklient(String tab)

{

List<zaavka> spisok = new List<zaavka>();

try

{

command.CommandText = "SELECT * FROM zaavka WHERE Id_klient = " + tab;

command.CommandType = CommandType.Text;

connection.Open();

OleDbDataReader reader = command.ExecuteReader();

while (reader.Read())

{

zaavka zad = new zaavka();

zad.Id = Convert.ToInt32(reader["Id"].ToString());

zad.Id_admin = Convert.ToInt32(reader["Id_admin"].ToString());


zad.Id_klient = Convert.ToInt32(reader["Id_klient"].ToString());

zad.Id_otdel = Convert.ToInt32(reader["Id_otdel"].ToString());

zad.Data = reader["Data"].ToString();

zad.Prichina = reader["Prichina"].ToString();

spisok.Add(zad);

}

return spisok;

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

public List<zaavka> Fill_zaavka_id_otdel(String tab)

{

List<zaavka> spisok = new List<zaavka>();

try

{

command.CommandText = "SELECT * FROM zaavka WHERE Id_otdel = " + tab;

command.CommandType = CommandType.Text;

connection.Open();

OleDbDataReader reader = command.ExecuteReader();

while (reader.Read())

{

zaavka zad = new zaavka();

zad.Id = Convert.ToInt32(reader["Id"].ToString());

zad.Id_admin = Convert.ToInt32(reader["Id_admin"].ToString());

zad.Id_klient = Convert.ToInt32(reader["Id_klient"].ToString());

zad.Id_otdel = Convert.ToInt32(reader["Id_otdel"].ToString());

zad.Data = reader["Data"].ToString();

zad.Prichina = reader["Prichina"].ToString();

spisok.Add(zad);

}

return spisok;

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

public zaavka Get_zaavka_idadmin(String tab)

{

zaavka zad = new zaavka();

try

{

command.CommandText = "SELECT * FROM zaavka WHERE Id_admin = " + tab;

command.CommandType = CommandType.Text;

connection.Open();

OleDbDataReader reader = command.ExecuteReader();

while (reader.Read())

{

zad.Id = Convert.ToInt32(reader["Id"].ToString());

zad.Id_admin = Convert.ToInt32(reader["Id_admin"].ToString());

zad.Id_klient = Convert.ToInt32(reader["Id_klient"].ToString());

zad.Id_otdel = Convert.ToInt32(reader["Id_otdel"].ToString());

zad.Data = reader["Data"].ToString();

zad.Prichina = reader["Prichina"].ToString();

}

return zad;

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

public zaavka Get_zaavka_idklient(String tab)

{

zaavka zad = new zaavka();

try

{

command.CommandText = "SELECT * FROM zaavka WHERE Id_klient = " + tab;

command.CommandType = CommandType.Text;

connection.Open();

OleDbDataReader reader = command.ExecuteReader();

while (reader.Read())

{

zad.Id = Convert.ToInt32(reader["Id"].ToString());

zad.Id_admin = Convert.ToInt32(reader["Id_admin"].ToString());

zad.Id_klient = Convert.ToInt32(reader["Id_klient"].ToString());

zad.Id_otdel = Convert.ToInt32(reader["Id_otdel"].ToString());

zad.Data = reader["Data"].ToString();

zad.Prichina = reader["Prichina"].ToString();

}

return zad;

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

public zaavka Get_zaavka_id_otdel(String tab)

{

zaavka zad = new zaavka();

try

{

command.CommandText = "SELECT * FROM zaavka WHERE Id_otdel = " + tab;

command.CommandType = CommandType.Text;

connection.Open();

OleDbDataReader reader = command.ExecuteReader();

while (reader.Read())

{

zad.Id = Convert.ToInt32(reader["Id"].ToString());

zad.Id_admin = Convert.ToInt32(reader["Id_admin"].ToString());

zad.Id_klient = Convert.ToInt32(reader["Id_klient"].ToString());

zad.Id_otdel = Convert.ToInt32(reader["Id_otdel"].ToString());

zad.Data = reader["Data"].ToString();

zad.Prichina = reader["Prichina"].ToString();

}

return zad;

}

catch (Exception)

{

throw;

}

finally

{

if (connection != null) { connection.Close(); }

}

}

public List<zaavka> Fill_zaavka_data(String tab)

{

List<zaavka> spisok = new List<zaavka>();

try

{

command.CommandText = "SELECT * FROM zaavka WHERE Data = '" + tab+"'";

command.CommandType = CommandType.Text;