2 commit
This commit is contained in:
parent
62b431186d
commit
c90de05288
@ -5,6 +5,8 @@ VisualStudioVersion = 17.9.34622.214
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Forms", "Forms\Forms.csproj", "{4B046F4C-2C21-4CEE-BAB2-11507D0AB05B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "database", "database\database.csproj", "{E071440F-0DFB-418C-B4B7-6D862CC36F93}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -15,6 +17,10 @@ Global
|
||||
{4B046F4C-2C21-4CEE-BAB2-11507D0AB05B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4B046F4C-2C21-4CEE-BAB2-11507D0AB05B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4B046F4C-2C21-4CEE-BAB2-11507D0AB05B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E071440F-0DFB-418C-B4B7-6D862CC36F93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E071440F-0DFB-418C-B4B7-6D862CC36F93}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E071440F-0DFB-418C-B4B7-6D862CC36F93}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E071440F-0DFB-418C-B4B7-6D862CC36F93}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
39
ComputerFirm/Forms/Form1.Designer.cs
generated
39
ComputerFirm/Forms/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
||||
namespace Forms
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Text = "Form1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace Forms
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
191
ComputerFirm/Forms/FormClient.Designer.cs
generated
Normal file
191
ComputerFirm/Forms/FormClient.Designer.cs
generated
Normal file
@ -0,0 +1,191 @@
|
||||
namespace Forms
|
||||
{
|
||||
partial class FormClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
buttonDelete = new Button();
|
||||
buttonUpdate = new Button();
|
||||
buttonCreate = new Button();
|
||||
textBoxEmail = new TextBox();
|
||||
textBoxSurname = new TextBox();
|
||||
textBoxName = new TextBox();
|
||||
label5 = new Label();
|
||||
label4 = new Label();
|
||||
label2 = new Label();
|
||||
label1 = new Label();
|
||||
dataGridView = new DataGridView();
|
||||
textBoxPhone = new TextBox();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonDelete
|
||||
//
|
||||
buttonDelete.Location = new Point(688, 214);
|
||||
buttonDelete.Name = "buttonDelete";
|
||||
buttonDelete.Size = new Size(75, 23);
|
||||
buttonDelete.TabIndex = 28;
|
||||
buttonDelete.Text = "delete";
|
||||
buttonDelete.UseVisualStyleBackColor = true;
|
||||
buttonDelete.Click += buttonDelete_Click;
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
buttonUpdate.Location = new Point(688, 185);
|
||||
buttonUpdate.Name = "buttonUpdate";
|
||||
buttonUpdate.Size = new Size(75, 23);
|
||||
buttonUpdate.TabIndex = 27;
|
||||
buttonUpdate.Text = "update";
|
||||
buttonUpdate.UseVisualStyleBackColor = true;
|
||||
buttonUpdate.Click += buttonUpdate_Click;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Location = new Point(688, 156);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(75, 23);
|
||||
buttonCreate.TabIndex = 26;
|
||||
buttonCreate.Text = "create";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += buttonCreate_Click;
|
||||
//
|
||||
// textBoxEmail
|
||||
//
|
||||
textBoxEmail.Location = new Point(688, 98);
|
||||
textBoxEmail.Name = "textBoxEmail";
|
||||
textBoxEmail.Size = new Size(100, 23);
|
||||
textBoxEmail.TabIndex = 24;
|
||||
//
|
||||
// textBoxSurname
|
||||
//
|
||||
textBoxSurname.Location = new Point(688, 40);
|
||||
textBoxSurname.Name = "textBoxSurname";
|
||||
textBoxSurname.Size = new Size(100, 23);
|
||||
textBoxSurname.TabIndex = 22;
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
textBoxName.Location = new Point(688, 11);
|
||||
textBoxName.Name = "textBoxName";
|
||||
textBoxName.Size = new Size(100, 23);
|
||||
textBoxName.TabIndex = 21;
|
||||
//
|
||||
// label5
|
||||
//
|
||||
label5.AutoSize = true;
|
||||
label5.Location = new Point(622, 106);
|
||||
label5.Name = "label5";
|
||||
label5.Size = new Size(36, 15);
|
||||
label5.TabIndex = 20;
|
||||
label5.Text = "Email";
|
||||
//
|
||||
// label4
|
||||
//
|
||||
label4.AutoSize = true;
|
||||
label4.Location = new Point(622, 77);
|
||||
label4.Name = "label4";
|
||||
label4.Size = new Size(41, 15);
|
||||
label4.TabIndex = 19;
|
||||
label4.Text = "Phone";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(622, 43);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(54, 15);
|
||||
label2.TabIndex = 17;
|
||||
label2.Text = "Surname";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(622, 14);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(39, 15);
|
||||
label1.TabIndex = 16;
|
||||
label1.Text = "Name";
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.AllowUserToAddRows = false;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Location = new Point(13, 14);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowTemplate.Height = 25;
|
||||
dataGridView.Size = new Size(603, 426);
|
||||
dataGridView.TabIndex = 15;
|
||||
dataGridView.CellClick += dataGridView_CellClick;
|
||||
//
|
||||
// textBoxPhone
|
||||
//
|
||||
textBoxPhone.Location = new Point(688, 69);
|
||||
textBoxPhone.Name = "textBoxPhone";
|
||||
textBoxPhone.Size = new Size(100, 23);
|
||||
textBoxPhone.TabIndex = 29;
|
||||
//
|
||||
// FormClient
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(textBoxPhone);
|
||||
Controls.Add(buttonDelete);
|
||||
Controls.Add(buttonUpdate);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(textBoxEmail);
|
||||
Controls.Add(textBoxSurname);
|
||||
Controls.Add(textBoxName);
|
||||
Controls.Add(label5);
|
||||
Controls.Add(label4);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(dataGridView);
|
||||
Name = "FormClient";
|
||||
Text = "FormClient";
|
||||
Load += FormClient_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonDelete;
|
||||
private Button buttonUpdate;
|
||||
private Button buttonCreate;
|
||||
private TextBox textBoxEmail;
|
||||
private TextBox textBoxSurname;
|
||||
private TextBox textBoxName;
|
||||
private TextBox textBoxPhone;
|
||||
private Label label5;
|
||||
private Label label4;
|
||||
private Label label2;
|
||||
private Label label1;
|
||||
private DataGridView dataGridView;
|
||||
}
|
||||
}
|
119
ComputerFirm/Forms/FormClient.cs
Normal file
119
ComputerFirm/Forms/FormClient.cs
Normal file
@ -0,0 +1,119 @@
|
||||
using database;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Forms
|
||||
{
|
||||
public partial class FormClient : Form
|
||||
{
|
||||
private Abstractions bd;
|
||||
public FormClient(Abstractions _bd)
|
||||
{
|
||||
InitializeComponent();
|
||||
bd = _bd;
|
||||
}
|
||||
private void loadData()
|
||||
{
|
||||
// Получаем список клиентов
|
||||
List<Client> clients = bd.GetClients();
|
||||
|
||||
// Очищаем dataGridView перед заполнением новыми данными
|
||||
dataGridView.Rows.Clear();
|
||||
|
||||
// Предварительно определяем столбцы, если это не было сделано ранее
|
||||
if (dataGridView.ColumnCount == 0)
|
||||
{
|
||||
dataGridView.Columns.Add("Id", "ID");
|
||||
dataGridView.Columns.Add("Name", "Name");
|
||||
dataGridView.Columns.Add("Surname", "Surname");
|
||||
dataGridView.Columns.Add("Phone", "Phone");
|
||||
dataGridView.Columns.Add("Email", "Email");
|
||||
}
|
||||
|
||||
// Заполняем dataGridView данными из списка клиентов
|
||||
foreach (Client client in clients)
|
||||
{
|
||||
dataGridView.Rows.Add(client.Id, client.Name, client.Surname, client.Phone, client.Email);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Создание новой записи клиента
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Client newClient = new Client
|
||||
{
|
||||
Name = textBoxName.Text,
|
||||
Surname = textBoxSurname.Text,
|
||||
Phone = textBoxPhone.Text,
|
||||
Email = textBoxEmail.Text
|
||||
};
|
||||
|
||||
bd.AddClient(newClient);
|
||||
// Обновляем отображение данных
|
||||
loadData();
|
||||
}
|
||||
|
||||
// Обновление выбранной записи клиента
|
||||
private void buttonUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow row = dataGridView.SelectedRows[0];
|
||||
int clientId = Convert.ToInt32(row.Cells["Id"].Value);
|
||||
|
||||
Client updatedClient = new Client
|
||||
{
|
||||
Id = clientId,
|
||||
Name = textBoxName.Text,
|
||||
Surname = textBoxSurname.Text,
|
||||
Phone = textBoxPhone.Text,
|
||||
Email = textBoxEmail.Text
|
||||
};
|
||||
|
||||
bd.UpdateClient(updatedClient);
|
||||
// Обновляем отображение данных
|
||||
loadData();
|
||||
}
|
||||
}
|
||||
|
||||
// Удаление выбранной записи клиента
|
||||
private void buttonDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow row = dataGridView.SelectedRows[0];
|
||||
int clientId = Convert.ToInt32(row.Cells["Id"].Value);
|
||||
|
||||
bd.DeleteClient(clientId);
|
||||
// Обновляем отображение данных
|
||||
loadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void FormClient_Load(object sender, EventArgs e)
|
||||
{
|
||||
loadData();
|
||||
}
|
||||
|
||||
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
if (e.RowIndex >= 0)
|
||||
{
|
||||
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
|
||||
|
||||
textBoxName.Text = row.Cells["Name"].Value.ToString();
|
||||
textBoxSurname.Text = row.Cells["Surname"].Value.ToString();
|
||||
textBoxPhone.Text = row.Cells["Phone"].Value.ToString();
|
||||
textBoxEmail.Text = row.Cells["Email"].Value.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
|
||||
Example:
|
||||
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
@ -26,36 +26,36 @@
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
196
ComputerFirm/Forms/FormComponent.Designer.cs
generated
Normal file
196
ComputerFirm/Forms/FormComponent.Designer.cs
generated
Normal file
@ -0,0 +1,196 @@
|
||||
namespace Forms
|
||||
{
|
||||
partial class FormComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
buttonDelete = new Button();
|
||||
buttonUpdate = new Button();
|
||||
buttonCreate = new Button();
|
||||
textBoxTitle = new TextBox();
|
||||
label4 = new Label();
|
||||
label3 = new Label();
|
||||
label2 = new Label();
|
||||
label1 = new Label();
|
||||
dataGridView = new DataGridView();
|
||||
textBoxCountSklad = new TextBox();
|
||||
textBoxPrice = new TextBox();
|
||||
textBoxManufacturer = new TextBox();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonDelete
|
||||
//
|
||||
buttonDelete.Location = new Point(688, 214);
|
||||
buttonDelete.Name = "buttonDelete";
|
||||
buttonDelete.Size = new Size(75, 23);
|
||||
buttonDelete.TabIndex = 28;
|
||||
buttonDelete.Text = "delete";
|
||||
buttonDelete.UseVisualStyleBackColor = true;
|
||||
buttonDelete.Click += buttonDelete_Click;
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
buttonUpdate.Location = new Point(688, 185);
|
||||
buttonUpdate.Name = "buttonUpdate";
|
||||
buttonUpdate.Size = new Size(75, 23);
|
||||
buttonUpdate.TabIndex = 27;
|
||||
buttonUpdate.Text = "update";
|
||||
buttonUpdate.UseVisualStyleBackColor = true;
|
||||
buttonUpdate.Click += buttonUpdate_Click;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Location = new Point(688, 156);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(75, 23);
|
||||
buttonCreate.TabIndex = 26;
|
||||
buttonCreate.Text = "create";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += buttonCreate_Click;
|
||||
//
|
||||
// textBoxTitle
|
||||
//
|
||||
textBoxTitle.Location = new Point(688, 11);
|
||||
textBoxTitle.Name = "textBoxTitle";
|
||||
textBoxTitle.Size = new Size(100, 23);
|
||||
textBoxTitle.TabIndex = 21;
|
||||
//
|
||||
// label4
|
||||
//
|
||||
label4.AutoSize = true;
|
||||
label4.Location = new Point(598, 101);
|
||||
label4.Name = "label4";
|
||||
label4.Size = new Size(79, 15);
|
||||
label4.TabIndex = 19;
|
||||
label4.Text = "Manufacturer";
|
||||
//
|
||||
// label3
|
||||
//
|
||||
label3.AutoSize = true;
|
||||
label3.Location = new Point(598, 72);
|
||||
label3.Name = "label3";
|
||||
label3.Size = new Size(33, 15);
|
||||
label3.TabIndex = 18;
|
||||
label3.Text = "Price";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(598, 43);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(68, 15);
|
||||
label2.TabIndex = 17;
|
||||
label2.Text = "CountSklad";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(598, 14);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(29, 15);
|
||||
label1.TabIndex = 16;
|
||||
label1.Text = "Title";
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.AllowUserToAddRows = false;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Location = new Point(13, 14);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowTemplate.Height = 25;
|
||||
dataGridView.Size = new Size(579, 426);
|
||||
dataGridView.TabIndex = 15;
|
||||
dataGridView.CellClick += dataGridView_CellClick;
|
||||
//
|
||||
// textBoxCountSklad
|
||||
//
|
||||
textBoxCountSklad.Location = new Point(688, 40);
|
||||
textBoxCountSklad.Name = "textBoxCountSklad";
|
||||
textBoxCountSklad.Size = new Size(100, 23);
|
||||
textBoxCountSklad.TabIndex = 29;
|
||||
//
|
||||
// textBoxPrice
|
||||
//
|
||||
textBoxPrice.Location = new Point(688, 69);
|
||||
textBoxPrice.Name = "textBoxPrice";
|
||||
textBoxPrice.Size = new Size(100, 23);
|
||||
textBoxPrice.TabIndex = 30;
|
||||
//
|
||||
// textBoxManufacturer
|
||||
//
|
||||
textBoxManufacturer.Location = new Point(688, 98);
|
||||
textBoxManufacturer.Name = "textBoxManufacturer";
|
||||
textBoxManufacturer.Size = new Size(100, 23);
|
||||
textBoxManufacturer.TabIndex = 31;
|
||||
//
|
||||
// FormComponent
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(textBoxManufacturer);
|
||||
Controls.Add(textBoxPrice);
|
||||
Controls.Add(textBoxCountSklad);
|
||||
Controls.Add(buttonDelete);
|
||||
Controls.Add(buttonUpdate);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(textBoxTitle);
|
||||
Controls.Add(label4);
|
||||
Controls.Add(label3);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(dataGridView);
|
||||
Name = "FormComponent";
|
||||
Text = "FormComponent";
|
||||
Load += FormComponent_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonDelete;
|
||||
private Button buttonUpdate;
|
||||
private Button buttonCreate;
|
||||
private ComboBox comboBoxBodyType;
|
||||
private TextBox textBoxSeats;
|
||||
private TextBox textBoxYear;
|
||||
private TextBox textBoxModel;
|
||||
private TextBox textBoxTitle;
|
||||
private Label label5;
|
||||
private Label label4;
|
||||
private Label label3;
|
||||
private Label label2;
|
||||
private Label label1;
|
||||
private DataGridView dataGridView;
|
||||
private TextBox textBoxCountSklad;
|
||||
private TextBox textBoxPrice;
|
||||
private TextBox textBoxManufacturer;
|
||||
}
|
||||
}
|
133
ComputerFirm/Forms/FormComponent.cs
Normal file
133
ComputerFirm/Forms/FormComponent.cs
Normal file
@ -0,0 +1,133 @@
|
||||
using database;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Forms
|
||||
{
|
||||
public partial class FormComponent : Form
|
||||
{
|
||||
private Abstractions bd;
|
||||
public FormComponent(Abstractions _bd)
|
||||
{
|
||||
InitializeComponent();
|
||||
bd = _bd;
|
||||
}
|
||||
private void loadData()
|
||||
{
|
||||
// Получаем список компонентов
|
||||
List<Component> components = bd.GetComponents();
|
||||
|
||||
// Очищаем dataGridView перед заполнением новыми данными
|
||||
dataGridView.Rows.Clear();
|
||||
|
||||
// Предварительно определяем столбцы, если это не было сделано ранее
|
||||
if (dataGridView.ColumnCount == 0)
|
||||
{
|
||||
dataGridView.Columns.Add("Id", "ID");
|
||||
dataGridView.Columns.Add("Title", "Title");
|
||||
dataGridView.Columns.Add("CountSklad", "CountSklad");
|
||||
dataGridView.Columns.Add("Price", "Price");
|
||||
dataGridView.Columns.Add("Manufacturer", "Manufacturer");
|
||||
}
|
||||
|
||||
// Заполняем dataGridView данными из списка компонентов
|
||||
foreach (Component component in components)
|
||||
{
|
||||
dataGridView.Rows.Add(component.Id, component.Title, component.CountSklad, component.Price, component.Manufacturer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Создаем новый объект Component и заполняем его данными из текстовых полей
|
||||
Component newComponent = new Component
|
||||
{
|
||||
Title = textBoxTitle.Text,
|
||||
CountSklad = textBoxCountSklad.Text,
|
||||
Price = double.Parse(textBoxPrice.Text),
|
||||
Manufacturer = textBoxManufacturer.Text
|
||||
};
|
||||
|
||||
// Вызываем метод добавления нового компонента в базу данных
|
||||
bd.AddComponent(newComponent);
|
||||
|
||||
// Перезагружаем данные в dataGridView
|
||||
loadData();
|
||||
}
|
||||
|
||||
private void buttonUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
// Получаем выбранный компонент из dataGridView
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int componentId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
// Создаем объект Component с обновленными данными из текстовых полей
|
||||
Component updatedComponent = new Component
|
||||
{
|
||||
Id = componentId,
|
||||
Title = textBoxTitle.Text,
|
||||
CountSklad = textBoxCountSklad.Text,
|
||||
Price = double.Parse(textBoxPrice.Text),
|
||||
Manufacturer = textBoxManufacturer.Text
|
||||
};
|
||||
|
||||
// Вызываем метод обновления компонента в базе данных
|
||||
bd.UpdateComponent(updatedComponent);
|
||||
|
||||
// Перезагружаем данные в dataGridView
|
||||
loadData();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Please select a branch to update.");
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
// Получаем выбранный компонент из dataGridView
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int componentId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
// Вызываем метод удаления компонентa из базы данных
|
||||
bd.DeleteComponent(componentId);
|
||||
|
||||
// Перезагружаем данные в dataGridView
|
||||
loadData();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Please select a branch to delete.");
|
||||
}
|
||||
}
|
||||
|
||||
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
if (e.RowIndex >= 0)
|
||||
{
|
||||
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
|
||||
|
||||
textBoxTitle.Text = row.Cells["Title"].Value.ToString();
|
||||
textBoxCountSklad.Text = row.Cells["CountSklad"].Value.ToString();
|
||||
textBoxPrice.Text = row.Cells["Price"].Value.ToString();
|
||||
textBoxManufacturer.Text = row.Cells["Manufacturer"].Value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private void FormComponent_Load(object sender, EventArgs e)
|
||||
{
|
||||
loadData();
|
||||
}
|
||||
}
|
||||
}
|
120
ComputerFirm/Forms/FormComponent.resx
Normal file
120
ComputerFirm/Forms/FormComponent.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
215
ComputerFirm/Forms/FormDevice.Designer.cs
generated
Normal file
215
ComputerFirm/Forms/FormDevice.Designer.cs
generated
Normal file
@ -0,0 +1,215 @@
|
||||
namespace Forms
|
||||
{
|
||||
partial class FormDevice
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
buttonDelete = new Button();
|
||||
buttonUpdate = new Button();
|
||||
buttonCreate = new Button();
|
||||
comboBoxClientId = new ComboBox();
|
||||
textBoxTypeDevice = new TextBox();
|
||||
textBoxModel = new TextBox();
|
||||
label4 = new Label();
|
||||
label3 = new Label();
|
||||
label2 = new Label();
|
||||
label1 = new Label();
|
||||
dataGridView = new DataGridView();
|
||||
comboBoxOrderId = new ComboBox();
|
||||
textBoxSerialNumber = new TextBox();
|
||||
label5 = new Label();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonDelete
|
||||
//
|
||||
buttonDelete.Location = new Point(688, 269);
|
||||
buttonDelete.Name = "buttonDelete";
|
||||
buttonDelete.Size = new Size(75, 23);
|
||||
buttonDelete.TabIndex = 28;
|
||||
buttonDelete.Text = "delete";
|
||||
buttonDelete.UseVisualStyleBackColor = true;
|
||||
buttonDelete.Click += buttonDelete_Click;
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
buttonUpdate.Location = new Point(688, 240);
|
||||
buttonUpdate.Name = "buttonUpdate";
|
||||
buttonUpdate.Size = new Size(75, 23);
|
||||
buttonUpdate.TabIndex = 27;
|
||||
buttonUpdate.Text = "update";
|
||||
buttonUpdate.UseVisualStyleBackColor = true;
|
||||
buttonUpdate.Click += buttonUpdate_Click;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Location = new Point(688, 211);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(75, 23);
|
||||
buttonCreate.TabIndex = 26;
|
||||
buttonCreate.Text = "create";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += buttonCreate_Click;
|
||||
//
|
||||
// comboBoxClientId
|
||||
//
|
||||
comboBoxClientId.FormattingEnabled = true;
|
||||
comboBoxClientId.Location = new Point(688, 127);
|
||||
comboBoxClientId.Name = "comboBoxClientId";
|
||||
comboBoxClientId.Size = new Size(100, 23);
|
||||
comboBoxClientId.TabIndex = 25;
|
||||
//
|
||||
// textBoxTypeDevice
|
||||
//
|
||||
textBoxTypeDevice.Location = new Point(688, 36);
|
||||
textBoxTypeDevice.Name = "textBoxTypeDevice";
|
||||
textBoxTypeDevice.Size = new Size(100, 23);
|
||||
textBoxTypeDevice.TabIndex = 23;
|
||||
//
|
||||
// textBoxModel
|
||||
//
|
||||
textBoxModel.Location = new Point(688, 65);
|
||||
textBoxModel.Name = "textBoxModel";
|
||||
textBoxModel.Size = new Size(100, 23);
|
||||
textBoxModel.TabIndex = 21;
|
||||
//
|
||||
// label4
|
||||
//
|
||||
label4.AutoSize = true;
|
||||
label4.Location = new Point(622, 68);
|
||||
label4.Name = "label4";
|
||||
label4.Size = new Size(41, 15);
|
||||
label4.TabIndex = 19;
|
||||
label4.Text = "Model";
|
||||
//
|
||||
// label3
|
||||
//
|
||||
label3.AutoSize = true;
|
||||
label3.Location = new Point(622, 39);
|
||||
label3.Name = "label3";
|
||||
label3.Size = new Size(66, 15);
|
||||
label3.TabIndex = 18;
|
||||
label3.Text = "TypeDevice";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(622, 159);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(47, 15);
|
||||
label2.TabIndex = 17;
|
||||
label2.Text = "OrderId";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(622, 130);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(48, 15);
|
||||
label1.TabIndex = 16;
|
||||
label1.Text = "ClientId";
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.AllowUserToAddRows = false;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Location = new Point(13, 14);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowTemplate.Height = 25;
|
||||
dataGridView.Size = new Size(603, 426);
|
||||
dataGridView.TabIndex = 15;
|
||||
dataGridView.CellClick += dataGridView_CellClick;
|
||||
//
|
||||
// comboBoxOrderId
|
||||
//
|
||||
comboBoxOrderId.FormattingEnabled = true;
|
||||
comboBoxOrderId.Location = new Point(688, 156);
|
||||
comboBoxOrderId.Name = "comboBoxOrderId";
|
||||
comboBoxOrderId.Size = new Size(100, 23);
|
||||
comboBoxOrderId.TabIndex = 29;
|
||||
//
|
||||
// textBoxSerialNumber
|
||||
//
|
||||
textBoxSerialNumber.Location = new Point(688, 94);
|
||||
textBoxSerialNumber.Name = "textBoxSerialNumber";
|
||||
textBoxSerialNumber.Size = new Size(100, 23);
|
||||
textBoxSerialNumber.TabIndex = 31;
|
||||
//
|
||||
// label5
|
||||
//
|
||||
label5.AutoSize = true;
|
||||
label5.Location = new Point(622, 97);
|
||||
label5.Name = "label5";
|
||||
label5.Size = new Size(62, 15);
|
||||
label5.TabIndex = 30;
|
||||
label5.Text = "SerialNum";
|
||||
//
|
||||
// FormDevice
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(textBoxSerialNumber);
|
||||
Controls.Add(label5);
|
||||
Controls.Add(comboBoxOrderId);
|
||||
Controls.Add(buttonDelete);
|
||||
Controls.Add(buttonUpdate);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(comboBoxClientId);
|
||||
Controls.Add(textBoxTypeDevice);
|
||||
Controls.Add(textBoxModel);
|
||||
Controls.Add(label4);
|
||||
Controls.Add(label3);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(dataGridView);
|
||||
Name = "FormDevice";
|
||||
Text = "FormDevice";
|
||||
Load += FormDevice_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonDelete;
|
||||
private Button buttonUpdate;
|
||||
private Button buttonCreate;
|
||||
private ComboBox comboBoxClientId;
|
||||
private TextBox textBoxTypeDevice;
|
||||
private TextBox textBoxModel;
|
||||
private Label label4;
|
||||
private Label label3;
|
||||
private Label label2;
|
||||
private Label label1;
|
||||
private DataGridView dataGridView;
|
||||
private ComboBox comboBoxOrderId;
|
||||
private TextBox textBoxSerialNumber;
|
||||
private Label label5;
|
||||
}
|
||||
}
|
160
ComputerFirm/Forms/FormDevice.cs
Normal file
160
ComputerFirm/Forms/FormDevice.cs
Normal file
@ -0,0 +1,160 @@
|
||||
using database;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Forms
|
||||
{
|
||||
public partial class FormDevice : Form
|
||||
{
|
||||
private Abstractions bd;
|
||||
public FormDevice(Abstractions _bd)
|
||||
{
|
||||
InitializeComponent();
|
||||
bd = _bd;
|
||||
}
|
||||
private void loadData()
|
||||
{
|
||||
// Получаем список девайсов
|
||||
List<Device> devices = bd.GetDevices();
|
||||
|
||||
// Очищаем dataGridView перед заполнением новыми данными
|
||||
dataGridView.Rows.Clear();
|
||||
|
||||
// Предварительно определяем столбцы, если это не было сделано ранее
|
||||
if (dataGridView.ColumnCount == 0)
|
||||
{
|
||||
dataGridView.Columns.Add("Id", "ID");
|
||||
dataGridView.Columns.Add("TypeDevice", "TypeDevice");
|
||||
dataGridView.Columns.Add("Model", "Model");
|
||||
dataGridView.Columns.Add("SerialNumber", "SerialNumber");
|
||||
dataGridView.Columns.Add("ClientId", "ClientId");
|
||||
dataGridView.Columns["ClientId"].Visible = false;
|
||||
dataGridView.Columns.Add("Client", "Client");
|
||||
dataGridView.Columns.Add("OrderId", "OrderId");
|
||||
dataGridView.Columns["OrderId"].Visible = false;
|
||||
dataGridView.Columns.Add("Order", "Order");
|
||||
}
|
||||
|
||||
// Заполняем dataGridView данными из списка девайсов
|
||||
foreach (Device device in devices)
|
||||
{
|
||||
dataGridView.Rows.Add(device.Id,
|
||||
device.TypeDevice, device.Model, device.SerialNumber,
|
||||
device.ClientId,
|
||||
bd.GetClientById(device.ClientId).Name,
|
||||
device.OrderId,
|
||||
bd.GetOrderById(device.OrderId).EndCost);
|
||||
}
|
||||
|
||||
}
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Создаем новый объект Device и заполняем его данными из текстовых полей и комбо-боксов
|
||||
Device newDevice = new Device
|
||||
{
|
||||
TypeDevice = textBoxTypeDevice.Text,
|
||||
Model = textBoxModel.Text,
|
||||
SerialNumber = textBoxSerialNumber.Text,
|
||||
ClientId = ((Client)comboBoxClientId.SelectedItem).Id,
|
||||
OrderId = ((Order)comboBoxOrderId.SelectedItem).Id
|
||||
};
|
||||
|
||||
// Вызываем метод добавления нового девайса в базу данных
|
||||
bd.AddDevice(newDevice);
|
||||
|
||||
// Обновляем dataGridView
|
||||
loadData();
|
||||
}
|
||||
|
||||
private void buttonUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
// Получаем индекс выбранной строки
|
||||
int rowIndex = dataGridView.CurrentCell.RowIndex;
|
||||
|
||||
// Получаем ID редактируемого автомобиля из выбранной строки dataGridView
|
||||
int deviceId = (int)dataGridView.Rows[rowIndex].Cells["Id"].Value;
|
||||
|
||||
// Создаем объект Device и заполняем его данными из текстовых полей и комбо-боксов
|
||||
Device updatedDevice = new Device
|
||||
{
|
||||
Id = deviceId,
|
||||
TypeDevice = textBoxTypeDevice.Text,
|
||||
Model = textBoxModel.Text,
|
||||
SerialNumber = textBoxSerialNumber.Text,
|
||||
ClientId = ((Client)comboBoxClientId.SelectedItem).Id,
|
||||
OrderId = ((Order)comboBoxOrderId.SelectedItem).Id
|
||||
};
|
||||
|
||||
// Вызываем метод обновления девайса в базе данных
|
||||
bd.UpdateDevice(updatedDevice);
|
||||
|
||||
// Обновляем dataGridView
|
||||
loadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
// Получаем индекс выбранной строки
|
||||
int rowIndex = dataGridView.CurrentCell.RowIndex;
|
||||
|
||||
// Получаем ID удаляемого девайса из выбранной строки dataGridView
|
||||
int deviceId = (int)dataGridView.Rows[rowIndex].Cells["Id"].Value;
|
||||
|
||||
// Вызываем метод удаления девайса из базы данных
|
||||
bd.DeleteDevice(deviceId);
|
||||
|
||||
// Обновляем dataGridView
|
||||
loadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
if (e.RowIndex >= 0)
|
||||
{
|
||||
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
|
||||
|
||||
// Заполняем текстовые поля данными из выбранной строки
|
||||
textBoxTypeDevice.Text = row.Cells["TypeDevice"].Value.ToString();
|
||||
textBoxModel.Text = row.Cells["Model"].Value.ToString();
|
||||
textBoxSerialNumber.Text = row.Cells["SerialNumber"].Value.ToString();
|
||||
|
||||
// Получаем значения для комбо-боксов из выбранной строки
|
||||
int clientId = Convert.ToInt32(row.Cells["ClientId"].Value);
|
||||
int orderId = Convert.ToInt32(row.Cells["OrderId"].Value);
|
||||
|
||||
// Устанавливаем выбранные значения в комбо-боксы
|
||||
comboBoxClientId.SelectedValue = clientId;
|
||||
comboBoxOrderId.SelectedValue = orderId;
|
||||
}
|
||||
}
|
||||
|
||||
private void FormDevice_Load(object sender, EventArgs e)
|
||||
{
|
||||
// Заполнение comboBoxClientId данными из БД
|
||||
comboBoxClientId.DataSource = bd.GetClients();
|
||||
comboBoxClientId.DisplayMember = "Name";
|
||||
comboBoxClientId.ValueMember = "Id";
|
||||
|
||||
// Заполнение comboBoxOrderId данными из БД
|
||||
comboBoxOrderId.DataSource = bd.GetOrders();
|
||||
comboBoxOrderId.DisplayMember = "Title";
|
||||
comboBoxOrderId.ValueMember = "Id";
|
||||
|
||||
// Загрузка данных в dataGridView
|
||||
loadData();
|
||||
}
|
||||
}
|
||||
}
|
120
ComputerFirm/Forms/FormDevice.resx
Normal file
120
ComputerFirm/Forms/FormDevice.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
235
ComputerFirm/Forms/FormEmployees.Designer.cs
generated
Normal file
235
ComputerFirm/Forms/FormEmployees.Designer.cs
generated
Normal file
@ -0,0 +1,235 @@
|
||||
namespace Forms
|
||||
{
|
||||
partial class FormEmployees
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
dataGridView = new DataGridView();
|
||||
textBoxName = new TextBox();
|
||||
textBoxSurnName = new TextBox();
|
||||
textBoxPosition = new TextBox();
|
||||
textBoxTimeWork = new TextBox();
|
||||
textBoxSeniority = new TextBox();
|
||||
textBoxCostPerHour = new TextBox();
|
||||
label1 = new Label();
|
||||
label2 = new Label();
|
||||
label3 = new Label();
|
||||
label4 = new Label();
|
||||
label5 = new Label();
|
||||
label6 = new Label();
|
||||
buttonDelete = new Button();
|
||||
buttonUpdate = new Button();
|
||||
buttonCreate = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.AllowUserToAddRows = false;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Location = new Point(12, 12);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowTemplate.Height = 25;
|
||||
dataGridView.Size = new Size(603, 426);
|
||||
dataGridView.TabIndex = 1;
|
||||
dataGridView.CellClick += dataGridView_CellClick;
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
textBoxName.Location = new Point(688, 12);
|
||||
textBoxName.Name = "textBoxName";
|
||||
textBoxName.Size = new Size(100, 23);
|
||||
textBoxName.TabIndex = 2;
|
||||
//
|
||||
// textBoxSurnName
|
||||
//
|
||||
textBoxSurnName.Location = new Point(688, 53);
|
||||
textBoxSurnName.Name = "textBoxSurnName";
|
||||
textBoxSurnName.Size = new Size(100, 23);
|
||||
textBoxSurnName.TabIndex = 3;
|
||||
//
|
||||
// textBoxPosition
|
||||
//
|
||||
textBoxPosition.Location = new Point(688, 96);
|
||||
textBoxPosition.Name = "textBoxPosition";
|
||||
textBoxPosition.Size = new Size(100, 23);
|
||||
textBoxPosition.TabIndex = 4;
|
||||
//
|
||||
// textBoxTimeWork
|
||||
//
|
||||
textBoxTimeWork.Location = new Point(688, 136);
|
||||
textBoxTimeWork.Name = "textBoxTimeWork";
|
||||
textBoxTimeWork.Size = new Size(100, 23);
|
||||
textBoxTimeWork.TabIndex = 5;
|
||||
//
|
||||
// textBoxSeniority
|
||||
//
|
||||
textBoxSeniority.Location = new Point(688, 182);
|
||||
textBoxSeniority.Name = "textBoxSeniority";
|
||||
textBoxSeniority.Size = new Size(100, 23);
|
||||
textBoxSeniority.TabIndex = 6;
|
||||
//
|
||||
// textBoxCostPerHour
|
||||
//
|
||||
textBoxCostPerHour.Location = new Point(688, 252);
|
||||
textBoxCostPerHour.Name = "textBoxCostPerHour";
|
||||
textBoxCostPerHour.Size = new Size(100, 23);
|
||||
textBoxCostPerHour.TabIndex = 7;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(621, 20);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(39, 15);
|
||||
label1.TabIndex = 8;
|
||||
label1.Text = "Name";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(621, 61);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(56, 15);
|
||||
label2.TabIndex = 9;
|
||||
label2.Text = "SurName";
|
||||
//
|
||||
// label3
|
||||
//
|
||||
label3.AutoSize = true;
|
||||
label3.Location = new Point(621, 104);
|
||||
label3.Name = "label3";
|
||||
label3.Size = new Size(50, 15);
|
||||
label3.TabIndex = 10;
|
||||
label3.Text = "Position";
|
||||
//
|
||||
// label4
|
||||
//
|
||||
label4.AutoSize = true;
|
||||
label4.Location = new Point(621, 144);
|
||||
label4.Name = "label4";
|
||||
label4.Size = new Size(61, 15);
|
||||
label4.TabIndex = 11;
|
||||
label4.Text = "TimeWork";
|
||||
//
|
||||
// label5
|
||||
//
|
||||
label5.AutoSize = true;
|
||||
label5.Location = new Point(621, 190);
|
||||
label5.Name = "label5";
|
||||
label5.Size = new Size(53, 15);
|
||||
label5.TabIndex = 12;
|
||||
label5.Text = "Seniority";
|
||||
//
|
||||
// label6
|
||||
//
|
||||
label6.AutoSize = true;
|
||||
label6.Location = new Point(621, 234);
|
||||
label6.Name = "label6";
|
||||
label6.Size = new Size(75, 15);
|
||||
label6.TabIndex = 13;
|
||||
label6.Text = "CostPerHour";
|
||||
//
|
||||
// buttonDelete
|
||||
//
|
||||
buttonDelete.Location = new Point(713, 347);
|
||||
buttonDelete.Name = "buttonDelete";
|
||||
buttonDelete.Size = new Size(75, 23);
|
||||
buttonDelete.TabIndex = 17;
|
||||
buttonDelete.Text = "delete";
|
||||
buttonDelete.UseVisualStyleBackColor = true;
|
||||
buttonDelete.Click += buttonDelete_Click;
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
buttonUpdate.Location = new Point(713, 318);
|
||||
buttonUpdate.Name = "buttonUpdate";
|
||||
buttonUpdate.Size = new Size(75, 23);
|
||||
buttonUpdate.TabIndex = 16;
|
||||
buttonUpdate.Text = "update";
|
||||
buttonUpdate.UseVisualStyleBackColor = true;
|
||||
buttonUpdate.Click += buttonUpdate_Click;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Location = new Point(713, 289);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(75, 23);
|
||||
buttonCreate.TabIndex = 15;
|
||||
buttonCreate.Text = "create";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += buttonCreate_Click;
|
||||
//
|
||||
// FormEmployees
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(buttonDelete);
|
||||
Controls.Add(buttonUpdate);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(label6);
|
||||
Controls.Add(label5);
|
||||
Controls.Add(label4);
|
||||
Controls.Add(label3);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(textBoxCostPerHour);
|
||||
Controls.Add(textBoxSeniority);
|
||||
Controls.Add(textBoxTimeWork);
|
||||
Controls.Add(textBoxPosition);
|
||||
Controls.Add(textBoxSurnName);
|
||||
Controls.Add(textBoxName);
|
||||
Controls.Add(dataGridView);
|
||||
Name = "FormEmployees";
|
||||
Text = "FormEmployees";
|
||||
Load += FormEmployees_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private TextBox textBoxName;
|
||||
private TextBox textBoxSurnName;
|
||||
private TextBox textBoxPosition;
|
||||
private TextBox textBoxTimeWork;
|
||||
private TextBox textBoxSeniority;
|
||||
private TextBox textBoxCostPerHour;
|
||||
private Label label1;
|
||||
private Label label2;
|
||||
private Label label3;
|
||||
private Label label4;
|
||||
private Label label5;
|
||||
private Label label6;
|
||||
private Button buttonDelete;
|
||||
private Button buttonUpdate;
|
||||
private Button buttonCreate;
|
||||
}
|
||||
}
|
129
ComputerFirm/Forms/FormEmployees.cs
Normal file
129
ComputerFirm/Forms/FormEmployees.cs
Normal file
@ -0,0 +1,129 @@
|
||||
using database;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Forms
|
||||
{
|
||||
public partial class FormEmployees : Form
|
||||
{
|
||||
private Abstractions bd;
|
||||
public FormEmployees(Abstractions _bd)
|
||||
{
|
||||
InitializeComponent();
|
||||
bd = _bd;
|
||||
}
|
||||
|
||||
private void loadData()
|
||||
{
|
||||
// Получаем список сотрудников
|
||||
List<Employee> employees = bd.GetEmployees();
|
||||
|
||||
// Очищаем dataGridView перед заполнением новыми данными
|
||||
dataGridView.Rows.Clear();
|
||||
|
||||
// Предварительно определяем столбцы, если это не было сделано ранее
|
||||
if (dataGridView.ColumnCount == 0)
|
||||
{
|
||||
dataGridView.Columns.Add("Id", "ID");
|
||||
dataGridView.Columns.Add("Name", "Name");
|
||||
dataGridView.Columns.Add("Surname", "Surname");
|
||||
dataGridView.Columns.Add("Position", "Position");
|
||||
dataGridView.Columns.Add("Timework", "Timework");
|
||||
dataGridView.Columns.Add("Seniority", "Seniority");
|
||||
dataGridView.Columns.Add("CostPerHour", "CostPerHour");
|
||||
}
|
||||
|
||||
// Заполняем dataGridView данными из списка сотрудников
|
||||
foreach (Employee employee in employees)
|
||||
{
|
||||
dataGridView.Rows.Add(employee.Id, employee.Name, employee.Surname, employee.Position, employee.Timework, employee.Seniority, employee.CostPerHour);
|
||||
}
|
||||
}
|
||||
|
||||
// Создание новой записи сотрудника
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Employee newEmployee = new Employee
|
||||
{
|
||||
Name = textBoxName.Text,
|
||||
Surname = textBoxSurnName.Text,
|
||||
Position = textBoxPosition.Text,
|
||||
Timework = textBoxTimeWork.Text,
|
||||
Seniority = textBoxSeniority.Text,
|
||||
CostPerHour = decimal.Parse(textBoxCostPerHour.Text)
|
||||
};
|
||||
|
||||
bd.AddEmployee(newEmployee);
|
||||
// Обновляем отображение данных
|
||||
loadData();
|
||||
// Очищаем текстовые поля после добавления сотрудника
|
||||
}
|
||||
|
||||
// Обновление выбранной записи сотрудника
|
||||
private void buttonUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow row = dataGridView.SelectedRows[0];
|
||||
int employeeId = Convert.ToInt32(row.Cells["Id"].Value);
|
||||
|
||||
Employee updatedEmployee = new Employee
|
||||
{
|
||||
Id = employeeId,
|
||||
Name = textBoxName.Text,
|
||||
Surname = textBoxSurnName.Text,
|
||||
Position = textBoxPosition.Text,
|
||||
Timework = textBoxTimeWork.Text,
|
||||
Seniority = textBoxSeniority.Text,
|
||||
CostPerHour = decimal.Parse(textBoxCostPerHour.Text)
|
||||
};
|
||||
|
||||
bd.UpdateEmployee(updatedEmployee);
|
||||
// Обновляем отображение данных
|
||||
loadData();
|
||||
}
|
||||
}
|
||||
|
||||
// Удаление выбранной записи сотрудника
|
||||
private void buttonDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow row = dataGridView.SelectedRows[0];
|
||||
int employeeId = Convert.ToInt32(row.Cells["Id"].Value);
|
||||
|
||||
bd.DeleteEmployee(employeeId);
|
||||
// Обновляем отображение данных
|
||||
loadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void FormEmployees_Load(object sender, EventArgs e)
|
||||
{
|
||||
loadData();
|
||||
}
|
||||
|
||||
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
if (e.RowIndex >= 0)
|
||||
{
|
||||
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
|
||||
|
||||
textBoxName.Text = row.Cells["Name"].Value.ToString();
|
||||
textBoxSurnName.Text = row.Cells["Surname"].Value.ToString();
|
||||
textBoxPosition.Text = row.Cells["Position"].Value.ToString();
|
||||
textBoxTimeWork.Text = row.Cells["Timework"].Value.ToString();
|
||||
textBoxSeniority.Text = row.Cells["Seniority"].Value.ToString();
|
||||
textBoxCostPerHour.Text = row.Cells["CostPerHour"].Value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
120
ComputerFirm/Forms/FormEmployees.resx
Normal file
120
ComputerFirm/Forms/FormEmployees.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
198
ComputerFirm/Forms/FormMain.Designer.cs
generated
Normal file
198
ComputerFirm/Forms/FormMain.Designer.cs
generated
Normal file
@ -0,0 +1,198 @@
|
||||
namespace Forms
|
||||
{
|
||||
partial class FormMain
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
menuStrip1 = new MenuStrip();
|
||||
tablesToolStripMenuItem = new ToolStripMenuItem();
|
||||
deviceToolStripMenuItem = new ToolStripMenuItem();
|
||||
componentToolStripMenuItem = new ToolStripMenuItem();
|
||||
employeesToolStripMenuItem = new ToolStripMenuItem();
|
||||
clientToolStripMenuItem = new ToolStripMenuItem();
|
||||
orderToolStripMenuItem = new ToolStripMenuItem();
|
||||
serviceToolStripMenuItem = new ToolStripMenuItem();
|
||||
buttonTest = new Button();
|
||||
textBoxTest = new TextBox();
|
||||
textBoxTest2 = new TextBox();
|
||||
buttonTest2 = new Button();
|
||||
textBoxTest3 = new TextBox();
|
||||
buttonTest3 = new Button();
|
||||
menuStrip1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
menuStrip1.Items.AddRange(new ToolStripItem[] { tablesToolStripMenuItem });
|
||||
menuStrip1.Location = new Point(0, 0);
|
||||
menuStrip1.Name = "menuStrip1";
|
||||
menuStrip1.Size = new Size(435, 24);
|
||||
menuStrip1.TabIndex = 0;
|
||||
menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
// tablesToolStripMenuItem
|
||||
//
|
||||
tablesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { deviceToolStripMenuItem, componentToolStripMenuItem, employeesToolStripMenuItem, clientToolStripMenuItem, orderToolStripMenuItem, serviceToolStripMenuItem });
|
||||
tablesToolStripMenuItem.Name = "tablesToolStripMenuItem";
|
||||
tablesToolStripMenuItem.Size = new Size(50, 20);
|
||||
tablesToolStripMenuItem.Text = "tables";
|
||||
//
|
||||
// deviceToolStripMenuItem
|
||||
//
|
||||
deviceToolStripMenuItem.Name = "deviceToolStripMenuItem";
|
||||
deviceToolStripMenuItem.Size = new Size(136, 22);
|
||||
deviceToolStripMenuItem.Text = "device";
|
||||
deviceToolStripMenuItem.Click += deviceToolStripMenuItem_Click;
|
||||
//
|
||||
// componentToolStripMenuItem
|
||||
//
|
||||
componentToolStripMenuItem.Name = "componentToolStripMenuItem";
|
||||
componentToolStripMenuItem.Size = new Size(136, 22);
|
||||
componentToolStripMenuItem.Text = "component";
|
||||
componentToolStripMenuItem.Click += componentToolStripMenuItem_Click;
|
||||
//
|
||||
// employeesToolStripMenuItem
|
||||
//
|
||||
employeesToolStripMenuItem.Name = "employeesToolStripMenuItem";
|
||||
employeesToolStripMenuItem.Size = new Size(136, 22);
|
||||
employeesToolStripMenuItem.Text = "employees";
|
||||
employeesToolStripMenuItem.Click += employeesToolStripMenuItem_Click;
|
||||
//
|
||||
// clientToolStripMenuItem
|
||||
//
|
||||
clientToolStripMenuItem.Name = "clientToolStripMenuItem";
|
||||
clientToolStripMenuItem.Size = new Size(136, 22);
|
||||
clientToolStripMenuItem.Text = "client";
|
||||
clientToolStripMenuItem.Click += clientToolStripMenuItem_Click;
|
||||
//
|
||||
// orderToolStripMenuItem
|
||||
//
|
||||
orderToolStripMenuItem.Name = "orderToolStripMenuItem";
|
||||
orderToolStripMenuItem.Size = new Size(136, 22);
|
||||
orderToolStripMenuItem.Text = "order";
|
||||
orderToolStripMenuItem.Click += orderToolStripMenuItem_Click;
|
||||
//
|
||||
// serviceToolStripMenuItem
|
||||
//
|
||||
serviceToolStripMenuItem.Name = "serviceToolStripMenuItem";
|
||||
serviceToolStripMenuItem.Size = new Size(136, 22);
|
||||
serviceToolStripMenuItem.Text = "service";
|
||||
serviceToolStripMenuItem.Click += serviceToolStripMenuItem_Click;
|
||||
//
|
||||
// buttonTest
|
||||
//
|
||||
buttonTest.Location = new Point(75, 11);
|
||||
buttonTest.Name = "buttonTest";
|
||||
buttonTest.Size = new Size(75, 23);
|
||||
buttonTest.TabIndex = 1;
|
||||
buttonTest.Text = "buttonTest";
|
||||
buttonTest.UseVisualStyleBackColor = true;
|
||||
buttonTest.Click += buttonTest_Click;
|
||||
//
|
||||
// textBoxTest
|
||||
//
|
||||
textBoxTest.Location = new Point(172, 12);
|
||||
textBoxTest.Multiline = true;
|
||||
textBoxTest.Name = "textBoxTest";
|
||||
textBoxTest.Size = new Size(251, 75);
|
||||
textBoxTest.TabIndex = 2;
|
||||
//
|
||||
// textBoxTest2
|
||||
//
|
||||
textBoxTest2.Location = new Point(172, 93);
|
||||
textBoxTest2.Multiline = true;
|
||||
textBoxTest2.Name = "textBoxTest2";
|
||||
textBoxTest2.Size = new Size(251, 75);
|
||||
textBoxTest2.TabIndex = 4;
|
||||
//
|
||||
// buttonTest2
|
||||
//
|
||||
buttonTest2.Location = new Point(75, 92);
|
||||
buttonTest2.Name = "buttonTest2";
|
||||
buttonTest2.Size = new Size(85, 23);
|
||||
buttonTest2.TabIndex = 3;
|
||||
buttonTest2.Text = "buttonTest2";
|
||||
buttonTest2.UseVisualStyleBackColor = true;
|
||||
buttonTest2.Click += buttonTest2_Click;
|
||||
//
|
||||
// textBoxTest3
|
||||
//
|
||||
textBoxTest3.Location = new Point(172, 174);
|
||||
textBoxTest3.Multiline = true;
|
||||
textBoxTest3.Name = "textBoxTest3";
|
||||
textBoxTest3.Size = new Size(251, 75);
|
||||
textBoxTest3.TabIndex = 6;
|
||||
//
|
||||
// buttonTest3
|
||||
//
|
||||
buttonTest3.Location = new Point(75, 173);
|
||||
buttonTest3.Name = "buttonTest3";
|
||||
buttonTest3.Size = new Size(85, 23);
|
||||
buttonTest3.TabIndex = 5;
|
||||
buttonTest3.Text = "buttonTest3";
|
||||
buttonTest3.UseVisualStyleBackColor = true;
|
||||
buttonTest3.Click += buttonTest3_Click;
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(435, 266);
|
||||
Controls.Add(textBoxTest3);
|
||||
Controls.Add(buttonTest3);
|
||||
Controls.Add(textBoxTest2);
|
||||
Controls.Add(buttonTest2);
|
||||
Controls.Add(textBoxTest);
|
||||
Controls.Add(buttonTest);
|
||||
Controls.Add(menuStrip1);
|
||||
MainMenuStrip = menuStrip1;
|
||||
Name = "FormMain";
|
||||
Text = "FormMain";
|
||||
menuStrip1.ResumeLayout(false);
|
||||
menuStrip1.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private MenuStrip menuStrip1;
|
||||
private ToolStripMenuItem tablesToolStripMenuItem;
|
||||
private ToolStripMenuItem deviceToolStripMenuItem;
|
||||
private ToolStripMenuItem componentToolStripMenuItem;
|
||||
private ToolStripMenuItem employeesToolStripMenuItem;
|
||||
private ToolStripMenuItem clientToolStripMenuItem;
|
||||
private ToolStripMenuItem orderToolStripMenuItem;
|
||||
private Button buttonTest;
|
||||
private TextBox textBoxTest;
|
||||
private ToolStripMenuItem serviceToolStripMenuItem;
|
||||
private TextBox textBoxTest2;
|
||||
private Button buttonTest2;
|
||||
private TextBox textBoxTest3;
|
||||
private Button buttonTest3;
|
||||
}
|
||||
}
|
153
ComputerFirm/Forms/FormMain.cs
Normal file
153
ComputerFirm/Forms/FormMain.cs
Normal file
@ -0,0 +1,153 @@
|
||||
using database;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
|
||||
|
||||
namespace Forms
|
||||
{
|
||||
public partial class FormMain : Form
|
||||
{
|
||||
|
||||
public FormMain()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void deviceToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormDevice));
|
||||
if (service is FormDevice form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void componentToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
|
||||
if (service is FormComponent form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void employeesToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormEmployees));
|
||||
if (service is FormEmployees form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void clientToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormClient));
|
||||
if (service is FormClient form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void orderToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormOrder));
|
||||
if (service is FormOrder form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void serviceToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormService));
|
||||
if (service is FormService form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonTest_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(Abstractions));
|
||||
if (service is Abstractions bd)
|
||||
{
|
||||
// Замените "GetClients" на метод вашего класса, который выполняет запрос к сущности
|
||||
DateTime startTime = DateTime.Now;
|
||||
var result = bd.GetClients(); // Выполняем запрос к сущности
|
||||
DateTime endTime = DateTime.Now;
|
||||
|
||||
// Выводим время выполнения запроса в консоль
|
||||
textBoxTest.Text = $"Время выполнения запроса: {(endTime - startTime).TotalMilliseconds} миллисекунд";
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonTest2_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(Abstractions));
|
||||
if (service is Abstractions bd)
|
||||
{
|
||||
DateTime startTime = DateTime.Now;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
Employee employee = new Employee
|
||||
{
|
||||
Name = "Сотрудник " + i,
|
||||
Surname = "Фамилия " + i,
|
||||
Position = "Должность " + i,
|
||||
Timework = "Время работы " + i,
|
||||
Seniority = "Стаж " + i,
|
||||
CostPerHour = i * 10
|
||||
};
|
||||
bd.AddEmployee(employee);
|
||||
}
|
||||
DateTime endTime = DateTime.Now;
|
||||
|
||||
textBoxTest2.Text = $"Добавление 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд";
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonTest3_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(Abstractions));
|
||||
if (service is Abstractions bd)
|
||||
{
|
||||
DateTime startTime = DateTime.Now;
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
var employee = bd.GetEmployees();
|
||||
int id = employee.Last().Id;
|
||||
bd.DeleteEmployee(id);
|
||||
}
|
||||
DateTime endTime = DateTime.Now;
|
||||
|
||||
textBoxTest3.Text = $"Удаление 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд";
|
||||
}
|
||||
}
|
||||
/*
|
||||
private Abstractions bd = new Implementation();
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
List<Branch> branches = bd.GetBranches();
|
||||
|
||||
// Очищаем dataGridView1 перед заполнением новыми данными
|
||||
dataGridView1.Rows.Clear();
|
||||
|
||||
// Предварительно определяем столбцы, если это не было сделано ранее
|
||||
if (dataGridView1.ColumnCount == 0)
|
||||
{
|
||||
dataGridView1.Columns.Add("Id", "ID");
|
||||
dataGridView1.Columns.Add("Name", "Name");
|
||||
dataGridView1.Columns.Add("Address", "Address");
|
||||
dataGridView1.Columns.Add("Phone", "Phone");
|
||||
dataGridView1.Columns.Add("WorkingHours", "Working Hours");
|
||||
}
|
||||
|
||||
// Заполняем dataGridView1 данными из списка branches
|
||||
foreach (Branch branch in branches)
|
||||
{
|
||||
dataGridView1.Rows.Add(branch.Id, branch.Name, branch.Address, branch.Phone, branch.WorkingHours);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
123
ComputerFirm/Forms/FormMain.resx
Normal file
123
ComputerFirm/Forms/FormMain.resx
Normal file
@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
238
ComputerFirm/Forms/FormOrder.Designer.cs
generated
Normal file
238
ComputerFirm/Forms/FormOrder.Designer.cs
generated
Normal file
@ -0,0 +1,238 @@
|
||||
namespace Forms
|
||||
{
|
||||
partial class FormOrder
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
buttonDelete = new Button();
|
||||
buttonUpdate = new Button();
|
||||
buttonCreate = new Button();
|
||||
comboBoxComponent = new ComboBox();
|
||||
textBoxCost = new TextBox();
|
||||
textBoxStartDate = new TextBox();
|
||||
textBoxEndDate = new TextBox();
|
||||
label5 = new Label();
|
||||
label4 = new Label();
|
||||
label3 = new Label();
|
||||
label2 = new Label();
|
||||
label1 = new Label();
|
||||
dataGridView = new DataGridView();
|
||||
comboBoxClient = new ComboBox();
|
||||
comboBoxService = new ComboBox();
|
||||
label6 = new Label();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonDelete
|
||||
//
|
||||
buttonDelete.Location = new Point(688, 244);
|
||||
buttonDelete.Name = "buttonDelete";
|
||||
buttonDelete.Size = new Size(75, 23);
|
||||
buttonDelete.TabIndex = 28;
|
||||
buttonDelete.Text = "delete";
|
||||
buttonDelete.UseVisualStyleBackColor = true;
|
||||
buttonDelete.Click += buttonDelete_Click;
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
buttonUpdate.Location = new Point(688, 215);
|
||||
buttonUpdate.Name = "buttonUpdate";
|
||||
buttonUpdate.Size = new Size(75, 23);
|
||||
buttonUpdate.TabIndex = 27;
|
||||
buttonUpdate.Text = "update";
|
||||
buttonUpdate.UseVisualStyleBackColor = true;
|
||||
buttonUpdate.Click += buttonUpdate_Click;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Location = new Point(688, 186);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(75, 23);
|
||||
buttonCreate.TabIndex = 26;
|
||||
buttonCreate.Text = "create";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += buttonCreate_Click;
|
||||
//
|
||||
// comboBoxComponent
|
||||
//
|
||||
comboBoxComponent.FormattingEnabled = true;
|
||||
comboBoxComponent.Location = new Point(688, 11);
|
||||
comboBoxComponent.Name = "comboBoxComponent";
|
||||
comboBoxComponent.Size = new Size(270, 23);
|
||||
comboBoxComponent.TabIndex = 25;
|
||||
//
|
||||
// textBoxCost
|
||||
//
|
||||
textBoxCost.Location = new Point(688, 157);
|
||||
textBoxCost.Name = "textBoxCost";
|
||||
textBoxCost.Size = new Size(270, 23);
|
||||
textBoxCost.TabIndex = 24;
|
||||
//
|
||||
// textBoxStartDate
|
||||
//
|
||||
textBoxStartDate.Location = new Point(688, 99);
|
||||
textBoxStartDate.Name = "textBoxStartDate";
|
||||
textBoxStartDate.Size = new Size(270, 23);
|
||||
textBoxStartDate.TabIndex = 23;
|
||||
//
|
||||
// textBoxEndDate
|
||||
//
|
||||
textBoxEndDate.Location = new Point(688, 128);
|
||||
textBoxEndDate.Name = "textBoxEndDate";
|
||||
textBoxEndDate.Size = new Size(270, 23);
|
||||
textBoxEndDate.TabIndex = 21;
|
||||
//
|
||||
// label5
|
||||
//
|
||||
label5.AutoSize = true;
|
||||
label5.Location = new Point(622, 160);
|
||||
label5.Name = "label5";
|
||||
label5.Size = new Size(31, 15);
|
||||
label5.TabIndex = 20;
|
||||
label5.Text = "Cost";
|
||||
//
|
||||
// label4
|
||||
//
|
||||
label4.AutoSize = true;
|
||||
label4.Location = new Point(622, 131);
|
||||
label4.Name = "label4";
|
||||
label4.Size = new Size(53, 15);
|
||||
label4.TabIndex = 19;
|
||||
label4.Text = "End date";
|
||||
//
|
||||
// label3
|
||||
//
|
||||
label3.AutoSize = true;
|
||||
label3.Location = new Point(622, 102);
|
||||
label3.Name = "label3";
|
||||
label3.Size = new Size(57, 15);
|
||||
label3.TabIndex = 18;
|
||||
label3.Text = "Start date";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(622, 43);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(38, 15);
|
||||
label2.TabIndex = 17;
|
||||
label2.Text = "Client";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(622, 14);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(71, 15);
|
||||
label1.TabIndex = 16;
|
||||
label1.Text = "Component";
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.AllowUserToAddRows = false;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Location = new Point(13, 14);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowTemplate.Height = 25;
|
||||
dataGridView.Size = new Size(603, 426);
|
||||
dataGridView.TabIndex = 15;
|
||||
dataGridView.CellClick += dataGridView_CellClick;
|
||||
//
|
||||
// comboBoxClient
|
||||
//
|
||||
comboBoxClient.FormattingEnabled = true;
|
||||
comboBoxClient.Location = new Point(688, 40);
|
||||
comboBoxClient.Name = "comboBoxClient";
|
||||
comboBoxClient.Size = new Size(270, 23);
|
||||
comboBoxClient.TabIndex = 29;
|
||||
//
|
||||
// comboBoxService
|
||||
//
|
||||
comboBoxService.FormattingEnabled = true;
|
||||
comboBoxService.Location = new Point(688, 70);
|
||||
comboBoxService.Name = "comboBoxService";
|
||||
comboBoxService.Size = new Size(270, 23);
|
||||
comboBoxService.TabIndex = 31;
|
||||
//
|
||||
// label6
|
||||
//
|
||||
label6.AutoSize = true;
|
||||
label6.Location = new Point(622, 73);
|
||||
label6.Name = "label6";
|
||||
label6.Size = new Size(44, 15);
|
||||
label6.TabIndex = 30;
|
||||
label6.Text = "Service";
|
||||
//
|
||||
// FormOrder
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(970, 450);
|
||||
Controls.Add(comboBoxService);
|
||||
Controls.Add(label6);
|
||||
Controls.Add(comboBoxClient);
|
||||
Controls.Add(buttonDelete);
|
||||
Controls.Add(buttonUpdate);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(comboBoxComponent);
|
||||
Controls.Add(textBoxCost);
|
||||
Controls.Add(textBoxStartDate);
|
||||
Controls.Add(textBoxEndDate);
|
||||
Controls.Add(label5);
|
||||
Controls.Add(label4);
|
||||
Controls.Add(label3);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(dataGridView);
|
||||
Name = "FormOrder";
|
||||
Text = "FormOrder";
|
||||
Load += FormOrder_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonDelete;
|
||||
private Button buttonUpdate;
|
||||
private Button buttonCreate;
|
||||
private ComboBox comboBoxComponent;
|
||||
private TextBox textBoxCost;
|
||||
private TextBox textBoxStartDate;
|
||||
private TextBox textBoxEndDate;
|
||||
private Label label5;
|
||||
private Label label4;
|
||||
private Label label3;
|
||||
private Label label2;
|
||||
private Label label1;
|
||||
private DataGridView dataGridView;
|
||||
private ComboBox comboBoxClient;
|
||||
private ComboBox comboBoxService;
|
||||
private Label label6;
|
||||
}
|
||||
}
|
201
ComputerFirm/Forms/FormOrder.cs
Normal file
201
ComputerFirm/Forms/FormOrder.cs
Normal file
@ -0,0 +1,201 @@
|
||||
using database;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Forms
|
||||
{
|
||||
public partial class FormOrder : Form
|
||||
{
|
||||
private Abstractions bd;
|
||||
public FormOrder(Abstractions _bd)
|
||||
{
|
||||
InitializeComponent();
|
||||
bd = _bd;
|
||||
}
|
||||
private void loadData()
|
||||
{
|
||||
// Получаем список заказов
|
||||
List<Order> orders = bd.GetOrders();
|
||||
|
||||
// Очищаем dataGridView перед заполнением новыми данными
|
||||
dataGridView.Rows.Clear();
|
||||
|
||||
// Предварительно определяем столбцы, если это не было сделано ранее
|
||||
if (dataGridView.ColumnCount == 0)
|
||||
{
|
||||
dataGridView.Columns.Add("Id", "ID");
|
||||
dataGridView.Columns.Add("ComponentId", "ComponentId");
|
||||
dataGridView.Columns["ComponentId"].Visible = false;
|
||||
dataGridView.Columns.Add("Component", "Component");
|
||||
dataGridView.Columns.Add("ClientId", "ClientId");
|
||||
dataGridView.Columns["ClientId"].Visible = false;
|
||||
dataGridView.Columns.Add("Client", "Client");
|
||||
dataGridView.Columns.Add("ServiceId", "ServiceId");
|
||||
dataGridView.Columns["ServiceId"].Visible = false;
|
||||
dataGridView.Columns.Add("Service", "Service");
|
||||
dataGridView.Columns.Add("DateStart", "Start Date");
|
||||
dataGridView.Columns.Add("EndDate", "End Date");
|
||||
dataGridView.Columns.Add("EndCost", "EndCost");
|
||||
}
|
||||
|
||||
// Заполняем dataGridView данными из списка заказов
|
||||
foreach (Order order in orders)
|
||||
{
|
||||
dataGridView.Rows.Add(order.Id,
|
||||
order.ComponentId,
|
||||
bd.GetComponentById(order.ComponentId).Title + " " + bd.GetComponentById(order.ComponentId).Manufacturer,
|
||||
order.ClientId,
|
||||
bd.GetClientById(order.ClientId).Name + " " + bd.GetClientById(order.ClientId).Surname,
|
||||
order.ServiceId,
|
||||
bd.GetServiceById(order.ServiceId).Title,
|
||||
order.DateStart, order.DateEnd, order.EndCost);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Создаем новый объект Order и заполняем его данными из текстовых полей и комбо-боксов
|
||||
Order newOrder = new Order
|
||||
{
|
||||
ComponentId = ((Component)comboBoxComponent.SelectedItem).Id,
|
||||
ClientId = ((Client)comboBoxClient.SelectedItem).Id,
|
||||
ServiceId = ((Service)comboBoxService.SelectedItem).Id,
|
||||
EndCost = decimal.Parse(textBoxCost.Text),
|
||||
DateStart = textBoxStartDate.Text,
|
||||
DateEnd = textBoxEndDate.Text
|
||||
};
|
||||
|
||||
// Вызываем метод добавления нового заказа в базу данных
|
||||
bd.AddOrder(newOrder);
|
||||
|
||||
// Обновляем dataGridView
|
||||
loadData();
|
||||
}
|
||||
|
||||
private void buttonUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
// Получаем индекс выбранной строки
|
||||
int rowIndex = dataGridView.CurrentCell.RowIndex;
|
||||
|
||||
// Получаем ID редактируемого заказа из выбранной строки dataGridView
|
||||
int orderId = (int)dataGridView.Rows[rowIndex].Cells["Id"].Value;
|
||||
|
||||
// Создаем объект Order и заполняем его данными из текстовых полей и комбо-боксов
|
||||
Order updatedOrder = new Order
|
||||
{
|
||||
Id = orderId,
|
||||
EndCost = decimal.Parse(textBoxCost.Text),
|
||||
DateStart = textBoxStartDate.Text,
|
||||
DateEnd = textBoxEndDate.Text,
|
||||
ComponentId = ((Component)comboBoxComponent.SelectedItem).Id,
|
||||
ClientId = ((Client)comboBoxClient.SelectedItem).Id,
|
||||
ServiceId = ((Service)comboBoxService.SelectedItem).Id
|
||||
};
|
||||
|
||||
// Вызываем метод обновления заказа в базе данных
|
||||
bd.UpdateOrder(updatedOrder);
|
||||
|
||||
// Обновляем dataGridView
|
||||
loadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
// Получаем индекс выбранной строки
|
||||
int rowIndex = dataGridView.CurrentCell.RowIndex;
|
||||
|
||||
// Получаем ID удаляемого заказа из выбранной строки dataGridView
|
||||
int orderId = (int)dataGridView.Rows[rowIndex].Cells["Id"].Value;
|
||||
|
||||
// Вызываем метод удаления заказа из базы данных
|
||||
bd.DeleteOrder(orderId);
|
||||
|
||||
// Обновляем dataGridView
|
||||
loadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
if (e.RowIndex >= 0)
|
||||
{
|
||||
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
|
||||
|
||||
// Заполняем текстовые поля данными из выбранной строки
|
||||
textBoxCost.Text = row.Cells["EndCost"].Value.ToString();
|
||||
textBoxStartDate.Text = row.Cells["DateStart"].Value.ToString();
|
||||
textBoxEndDate.Text = row.Cells["EndDate"].Value.ToString();
|
||||
|
||||
// Получаем значения для комбо-боксов из выбранной строки
|
||||
int componentId = Convert.ToInt32(row.Cells["ComponentId"].Value);
|
||||
int clientId = Convert.ToInt32(row.Cells["ClientId"].Value);
|
||||
int serviceId = Convert.ToInt32(row.Cells["ServiceId"].Value);
|
||||
|
||||
// Заполняем комбо-боксы данными из БД
|
||||
//comboBoxComponent.DataSource = bd.GetComponents()
|
||||
// .Select(x => new helpCombobox()
|
||||
// {
|
||||
// Text = x.Title + " " + x.Manufacturer,
|
||||
// Id = x.Id
|
||||
// })
|
||||
// .ToList();
|
||||
//comboBoxComponent.DisplayMember = "Text";
|
||||
//comboBoxComponent.ValueMember = "Id";
|
||||
//comboBoxComponent.SelectedValue = componentId;
|
||||
|
||||
//comboBoxClient.DataSource = bd.GetClients()
|
||||
// .Select(x => new helpCombobox()
|
||||
// {
|
||||
// Text = x.Name + " " + x.Surname,
|
||||
// Id = x.Id
|
||||
// }).ToList();
|
||||
//comboBoxClient.DisplayMember = "Text";
|
||||
//comboBoxClient.ValueMember = "Id";
|
||||
//comboBoxClient.SelectedValue = clientId;
|
||||
|
||||
//comboBoxService.DataSource = bd.GetServices()
|
||||
// .Select(x => new helpCombobox()
|
||||
// {
|
||||
// Text = x.Title,
|
||||
// Id = x.Id
|
||||
// }).ToList();
|
||||
//comboBoxService.DisplayMember = "Text";
|
||||
//comboBoxService.ValueMember = "Id";
|
||||
//comboBoxService.SelectedValue = serviceId; // Здесь должно быть serviceId, а не clientId
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void FormOrder_Load(object sender, EventArgs e)
|
||||
{
|
||||
// Заполнение comboBoxClientId данными из БД
|
||||
comboBoxComponent.DataSource = bd.GetComponents();
|
||||
comboBoxComponent.DisplayMember = "Name";
|
||||
comboBoxComponent.ValueMember = "Id";
|
||||
|
||||
// Заполнение comboBoxOrderId данными из БД
|
||||
comboBoxClient.DataSource = bd.GetClients();
|
||||
comboBoxClient.DisplayMember = "Title";
|
||||
comboBoxClient.ValueMember = "Id";
|
||||
|
||||
// Заполнение comboBoxOrderId данными из БД
|
||||
comboBoxService.DataSource = bd.GetServices();
|
||||
comboBoxService.DisplayMember = "Title";
|
||||
comboBoxService.ValueMember = "Id";
|
||||
|
||||
loadData();
|
||||
}
|
||||
}
|
||||
}
|
120
ComputerFirm/Forms/FormOrder.resx
Normal file
120
ComputerFirm/Forms/FormOrder.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
170
ComputerFirm/Forms/FormService.Designer.cs
generated
Normal file
170
ComputerFirm/Forms/FormService.Designer.cs
generated
Normal file
@ -0,0 +1,170 @@
|
||||
namespace Forms
|
||||
{
|
||||
partial class FormService
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
dataGridView = new DataGridView();
|
||||
label1 = new Label();
|
||||
label2 = new Label();
|
||||
label4 = new Label();
|
||||
textBoxTitle = new TextBox();
|
||||
textBoxCost = new TextBox();
|
||||
comboBoxEmployeesId = new ComboBox();
|
||||
buttonCreate = new Button();
|
||||
buttonUpdate = new Button();
|
||||
buttonDelete = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.AllowUserToAddRows = false;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Location = new Point(12, 12);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowTemplate.Height = 25;
|
||||
dataGridView.Size = new Size(603, 426);
|
||||
dataGridView.TabIndex = 0;
|
||||
dataGridView.CellClick += dataGridView_CellClick;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(621, 12);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(29, 15);
|
||||
label1.TabIndex = 1;
|
||||
label1.Text = "Title";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(621, 41);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(31, 15);
|
||||
label2.TabIndex = 2;
|
||||
label2.Text = "Cost";
|
||||
//
|
||||
// label4
|
||||
//
|
||||
label4.AutoSize = true;
|
||||
label4.Location = new Point(618, 70);
|
||||
label4.Name = "label4";
|
||||
label4.Size = new Size(64, 15);
|
||||
label4.TabIndex = 4;
|
||||
label4.Text = "Employees";
|
||||
//
|
||||
// textBoxTitle
|
||||
//
|
||||
textBoxTitle.Location = new Point(687, 9);
|
||||
textBoxTitle.Name = "textBoxTitle";
|
||||
textBoxTitle.Size = new Size(100, 23);
|
||||
textBoxTitle.TabIndex = 6;
|
||||
//
|
||||
// textBoxCost
|
||||
//
|
||||
textBoxCost.Location = new Point(687, 38);
|
||||
textBoxCost.Name = "textBoxCost";
|
||||
textBoxCost.Size = new Size(100, 23);
|
||||
textBoxCost.TabIndex = 7;
|
||||
//
|
||||
// comboBoxEmployeesId
|
||||
//
|
||||
comboBoxEmployeesId.FormattingEnabled = true;
|
||||
comboBoxEmployeesId.Location = new Point(688, 67);
|
||||
comboBoxEmployeesId.Name = "comboBoxEmployeesId";
|
||||
comboBoxEmployeesId.Size = new Size(100, 23);
|
||||
comboBoxEmployeesId.TabIndex = 11;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Location = new Point(687, 154);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(75, 23);
|
||||
buttonCreate.TabIndex = 12;
|
||||
buttonCreate.Text = "create";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += buttonCreate_Click;
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
buttonUpdate.Location = new Point(687, 183);
|
||||
buttonUpdate.Name = "buttonUpdate";
|
||||
buttonUpdate.Size = new Size(75, 23);
|
||||
buttonUpdate.TabIndex = 13;
|
||||
buttonUpdate.Text = "update";
|
||||
buttonUpdate.UseVisualStyleBackColor = true;
|
||||
buttonUpdate.Click += buttonUpdate_Click;
|
||||
//
|
||||
// buttonDelete
|
||||
//
|
||||
buttonDelete.Location = new Point(687, 212);
|
||||
buttonDelete.Name = "buttonDelete";
|
||||
buttonDelete.Size = new Size(75, 23);
|
||||
buttonDelete.TabIndex = 14;
|
||||
buttonDelete.Text = "delete";
|
||||
buttonDelete.UseVisualStyleBackColor = true;
|
||||
buttonDelete.Click += buttonDelete_Click;
|
||||
//
|
||||
// FormService
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(buttonDelete);
|
||||
Controls.Add(buttonUpdate);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(comboBoxEmployeesId);
|
||||
Controls.Add(textBoxCost);
|
||||
Controls.Add(textBoxTitle);
|
||||
Controls.Add(label4);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(dataGridView);
|
||||
Name = "FormService";
|
||||
Text = "FormService";
|
||||
Load += FormService_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private Label label1;
|
||||
private Label label2;
|
||||
private Label label4;
|
||||
private TextBox textBoxTitle;
|
||||
private TextBox textBoxCost;
|
||||
private ComboBox comboBoxEmployeesId;
|
||||
private Button buttonCreate;
|
||||
private Button buttonUpdate;
|
||||
private Button buttonDelete;
|
||||
}
|
||||
}
|
117
ComputerFirm/Forms/FormService.cs
Normal file
117
ComputerFirm/Forms/FormService.cs
Normal file
@ -0,0 +1,117 @@
|
||||
using database;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Forms
|
||||
{
|
||||
public partial class FormService : Form
|
||||
{
|
||||
private Abstractions bd;
|
||||
public FormService(Abstractions _bd)
|
||||
{
|
||||
InitializeComponent();
|
||||
bd = _bd;
|
||||
}
|
||||
|
||||
private void loadData()
|
||||
{
|
||||
List<Service> services = bd.GetServices();
|
||||
|
||||
// Очищаем dataGridView перед заполнением новыми данными
|
||||
dataGridView.Rows.Clear();
|
||||
|
||||
// Предварительно определяем столбцы, если это не было сделано ранее
|
||||
if (dataGridView.ColumnCount == 0)
|
||||
{
|
||||
dataGridView.Columns.Add("Id", "ID");
|
||||
dataGridView.Columns.Add("Title", "Title");
|
||||
dataGridView.Columns.Add("Cost", "Cost");
|
||||
dataGridView.Columns.Add("EmployeesId", "EmployeesId");
|
||||
dataGridView.Columns["EmployeesId"].Visible = false;
|
||||
dataGridView.Columns.Add("Employees", "Employees");
|
||||
}
|
||||
|
||||
// Заполняем dataGridView данными из списка услуг
|
||||
foreach (Service service in services)
|
||||
{
|
||||
dataGridView.Rows.Add(service.Id, service.Title, service.Cost, service.EmployeesId, bd.GetEmployeeById(service.EmployeesId).Id);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Создаем новый объект Service с данными из текстовых полей и комбо-бокса
|
||||
Service newService = new Service
|
||||
{
|
||||
Title = textBoxTitle.Text,
|
||||
Cost = decimal.Parse(textBoxCost.Text),
|
||||
EmployeesId = ((Employee)comboBoxEmployeesId.SelectedItem).Id,
|
||||
};
|
||||
|
||||
// Добавляем новую услугу в базу данных
|
||||
bd.AddService(newService);
|
||||
|
||||
// Перезагружаем данные в таблицу
|
||||
loadData();
|
||||
}
|
||||
|
||||
private void buttonUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Получаем Id выбранной строки
|
||||
int selectedRowId = (int)dataGridView.SelectedRows[0].Cells["Id"].Value;
|
||||
|
||||
// Создаем объект Service с обновленными данными из текстовых полей и комбо-бокса
|
||||
Service updatedService = new Service
|
||||
{
|
||||
Id = selectedRowId,
|
||||
Title = textBoxTitle.Text,
|
||||
Cost = decimal.Parse(textBoxCost.Text),
|
||||
EmployeesId = ((Employee)comboBoxEmployeesId.SelectedItem).Id,
|
||||
};
|
||||
|
||||
// Обновляем услуги в базе данных
|
||||
bd.UpdateService(updatedService);
|
||||
|
||||
// Перезагружаем данные в таблицу
|
||||
loadData();
|
||||
}
|
||||
|
||||
private void buttonDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Получаем Id выбранной строки
|
||||
int selectedRowId = (int)dataGridView.SelectedRows[0].Cells["Id"].Value;
|
||||
|
||||
// Удаляем услуги из базы данных
|
||||
bd.DeleteService(selectedRowId);
|
||||
|
||||
// Перезагружаем данные в таблицу
|
||||
loadData();
|
||||
}
|
||||
|
||||
|
||||
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
if (e.RowIndex >= 0)
|
||||
{
|
||||
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
|
||||
|
||||
// Заполняем текстовые поля данными из выбранной строки
|
||||
textBoxTitle.Text = row.Cells["Title"].Value.ToString();
|
||||
textBoxCost.Text = row.Cells["Cost"].Value.ToString();
|
||||
|
||||
// Получаем значение сотрудника из выбранной строки
|
||||
int employeeId = Convert.ToInt32(row.Cells["EmployeesId"].Value);
|
||||
|
||||
// Выбираем сотрудника с данным employeeId в комбо-боксе
|
||||
comboBoxEmployeesId.SelectedValue = employeeId;
|
||||
}
|
||||
}
|
||||
private void FormService_Load(object sender, EventArgs e)
|
||||
{
|
||||
// Заполнение comboBoxClientId данными из БД
|
||||
comboBoxEmployeesId.DataSource = bd.GetEmployees();
|
||||
comboBoxEmployeesId.DisplayMember = "Name";
|
||||
comboBoxEmployeesId.ValueMember = "Id";
|
||||
loadData();
|
||||
}
|
||||
}
|
||||
}
|
120
ComputerFirm/Forms/FormService.resx
Normal file
120
ComputerFirm/Forms/FormService.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -8,4 +8,12 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\database\database.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,7 +1,12 @@
|
||||
using database;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Forms
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
@ -11,7 +16,21 @@ namespace Forms
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||
}
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddTransient<Abstractions, Implementation>();
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormComponent>();
|
||||
services.AddTransient<FormDevice>();
|
||||
services.AddTransient<FormService>();
|
||||
services.AddTransient<FormClient>();
|
||||
services.AddTransient<FormOrder>();
|
||||
services.AddTransient<FormEmployees>();
|
||||
}
|
||||
}
|
||||
}
|
53
ComputerFirm/database/Abstractions.cs
Normal file
53
ComputerFirm/database/Abstractions.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace database
|
||||
{
|
||||
public abstract class Abstractions
|
||||
{
|
||||
|
||||
// CDUD операции для каждой сущности
|
||||
|
||||
// Device
|
||||
public abstract void AddDevice(Device device);
|
||||
public abstract List<Device> GetDevices();
|
||||
public abstract Device GetDeviceById(int id);
|
||||
public abstract void UpdateDevice(Device device);
|
||||
public abstract void DeleteDevice(int id);
|
||||
|
||||
// Employees
|
||||
public abstract void AddEmployee(Employee employee);
|
||||
public abstract List<Employee> GetEmployees();
|
||||
public abstract Employee GetEmployeeById(int id);
|
||||
public abstract void UpdateEmployee(Employee employee);
|
||||
public abstract void DeleteEmployee(int id);
|
||||
|
||||
// Client
|
||||
public abstract void AddClient(Client client);
|
||||
public abstract Client GetClientById(int id);
|
||||
public abstract List<Client> GetClients();
|
||||
public abstract void UpdateClient(Client client);
|
||||
public abstract void DeleteClient(int id);
|
||||
|
||||
// Orders
|
||||
public abstract void AddOrder(Order order);
|
||||
public abstract Order GetOrderById(int id);
|
||||
public abstract List<Order> GetOrders();
|
||||
public abstract void UpdateOrder(Order order);
|
||||
public abstract void DeleteOrder(int id);
|
||||
|
||||
// Service
|
||||
public abstract void AddService(Service service);
|
||||
public abstract Service GetServiceById(int id);
|
||||
public abstract List<Service> GetServices();
|
||||
public abstract void UpdateService(Service service);
|
||||
public abstract void DeleteService(int id);
|
||||
|
||||
// Components
|
||||
public abstract void AddComponent(Component component);
|
||||
public abstract Component GetComponentById(int id);
|
||||
public abstract List<Component> GetComponents();
|
||||
public abstract void UpdateComponent(Component component);
|
||||
public abstract void DeleteComponent(int id);
|
||||
|
||||
}
|
||||
}
|
475
ComputerFirm/database/Implementation.cs
Normal file
475
ComputerFirm/database/Implementation.cs
Normal file
@ -0,0 +1,475 @@
|
||||
using Npgsql;
|
||||
using System.Data;
|
||||
|
||||
namespace database
|
||||
{
|
||||
public class Implementation : Abstractions
|
||||
{
|
||||
private NpgsqlConnection GetConnection()
|
||||
{
|
||||
return new NpgsqlConnection("Host=localhost;Username=postgres;Password=1234;Database=Computerfirmbd;");
|
||||
}
|
||||
|
||||
// CDUD операции для каждой сущности
|
||||
|
||||
// Device
|
||||
public override void AddDevice(Device device)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("INSERT INTO device (typedevice, model, serialnumber, clientid, orderid) VALUES (@TypeDevice, @Model, @SerialNumber, @ClientId, @OrderId)", conn);
|
||||
cmd.Parameters.AddWithValue("@TypeDevice", device.TypeDevice);
|
||||
cmd.Parameters.AddWithValue("@Model", device.Model);
|
||||
cmd.Parameters.AddWithValue("@SerialNumber", device.SerialNumber);
|
||||
cmd.Parameters.AddWithValue("@ClientId", device.ClientId);
|
||||
cmd.Parameters.AddWithValue("@OrderId", device.OrderId);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public override List<Device> GetDevices()
|
||||
{
|
||||
var devices = new List<Device>();
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("SELECT * FROM device", conn);
|
||||
using var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
devices.Add(new Device
|
||||
{
|
||||
Id = reader.GetInt32(0),
|
||||
TypeDevice = reader.GetString(1),
|
||||
Model = reader.GetString(2),
|
||||
SerialNumber = reader.GetString(3),
|
||||
ClientId = reader.GetInt32(4),
|
||||
OrderId = reader.GetInt32(5),
|
||||
});
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
public override Device GetDeviceById(int id)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand($"SELECT * FROM device WHERE id = {id}", conn);
|
||||
using var reader = cmd.ExecuteReader();
|
||||
if (reader.Read())
|
||||
{
|
||||
return new Device
|
||||
{
|
||||
Id = reader.GetInt32(0),
|
||||
TypeDevice = reader.GetString(1),
|
||||
Model = reader.GetString(2),
|
||||
SerialNumber = reader.GetString(3),
|
||||
ClientId = reader.GetInt32(4),
|
||||
OrderId = reader.GetInt32(5),
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void UpdateDevice(Device device)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("UPDATE device SET typedevice = @TypeDevice, model = @Model, serialnumber = @SerialNumber, clientid = @ClientId, orderid = @OrderId WHERE id = @Id", conn);
|
||||
cmd.Parameters.AddWithValue("@TypeDevice", device.TypeDevice);
|
||||
cmd.Parameters.AddWithValue("@Model", device.Model);
|
||||
cmd.Parameters.AddWithValue("@SerialNumber", device.SerialNumber);
|
||||
cmd.Parameters.AddWithValue("@ClientId", device.ClientId);
|
||||
cmd.Parameters.AddWithValue("@OrderId", device.OrderId);
|
||||
cmd.Parameters.AddWithValue("@Id", device.Id);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public override void DeleteDevice(int id)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand($"DELETE FROM device WHERE id = {id}", conn);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
//Employee
|
||||
|
||||
public override void AddEmployee(Employee employee)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("INSERT INTO employee (name, surname, position, timework, seniority, costperhour) VALUES (@Name, @Surname, @Position, @Timework, @Seniority, @CostPerHour)");
|
||||
cmd.Parameters.AddWithValue("@Name", employee.Name);
|
||||
cmd.Parameters.AddWithValue("@Surname", employee.Surname);
|
||||
cmd.Parameters.AddWithValue("@Position", employee.Position);
|
||||
cmd.Parameters.AddWithValue("@Timework", employee.Timework);
|
||||
cmd.Parameters.AddWithValue("@Seniority", employee.Seniority);
|
||||
cmd.Parameters.AddWithValue("@CostPerHour", employee.CostPerHour);
|
||||
cmd.Connection = conn;
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public override List<Employee> GetEmployees()
|
||||
{
|
||||
var employee = new List<Employee>();
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("SELECT * FROM employee", conn);
|
||||
using var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
employee.Add(new Employee()
|
||||
{
|
||||
Id = reader.GetInt32(0),
|
||||
Name = reader.GetString(1),
|
||||
Surname = reader.GetString(2),
|
||||
Position = reader.GetString(3),
|
||||
Timework = reader.GetString(4),
|
||||
Seniority = reader.GetString(5),
|
||||
CostPerHour = reader.GetDecimal(6)
|
||||
});
|
||||
}
|
||||
return employee;
|
||||
}
|
||||
|
||||
public override Employee GetEmployeeById(int id)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand($"SELECT * FROM employee WHERE id = {id}", conn);
|
||||
using var reader = cmd.ExecuteReader();
|
||||
if (reader.Read())
|
||||
{
|
||||
return new Employee
|
||||
{
|
||||
Id = reader.GetInt32(0),
|
||||
Name = reader.GetString(1),
|
||||
Surname = reader.GetString(2),
|
||||
Position = reader.GetString(3),
|
||||
Timework = reader.GetString(4),
|
||||
Seniority = reader.GetString(5),
|
||||
CostPerHour = reader.GetDecimal(6)
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void UpdateEmployee(Employee employee)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open(); // добавил открытие соединения
|
||||
using var cmd = new NpgsqlCommand("UPDATE employee SET name = @Name, surname = @Surname, position = @Position, timework = @Timework, seniority = @Seniority, costperhour = @CostPerHour WHERE id = @Id", conn);
|
||||
cmd.Parameters.AddWithValue("@Name", employee.Name);
|
||||
cmd.Parameters.AddWithValue("@Surname", employee.Surname);
|
||||
cmd.Parameters.AddWithValue("@Position", employee.Position);
|
||||
cmd.Parameters.AddWithValue("@Timework", employee.Timework);
|
||||
cmd.Parameters.AddWithValue("@Seniority", employee.Seniority);
|
||||
cmd.Parameters.AddWithValue("@CostPerHour", employee.CostPerHour);
|
||||
cmd.Parameters.AddWithValue("@Id", employee.Id);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public override void DeleteEmployee(int id)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand($"DELETE FROM employee WHERE id = {id}", conn);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
// Client
|
||||
public override void AddClient(Client client)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("INSERT INTO client (name, surname, email, phone) VALUES (@Name, @Surname, @Email, @Phone)", conn);
|
||||
cmd.Parameters.AddWithValue("@Name", client.Name);
|
||||
cmd.Parameters.AddWithValue("@Surname", client.Surname);
|
||||
cmd.Parameters.AddWithValue("@Email", client.Email);
|
||||
cmd.Parameters.AddWithValue("@Phone", client.Phone);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public override List<Client> GetClients()
|
||||
{
|
||||
var client = new List<Client>();
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("SELECT * FROM client", conn);
|
||||
using var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
client.Add(new Client
|
||||
{
|
||||
Id = reader.GetInt32(0),
|
||||
Name = reader.GetString(1),
|
||||
Surname = reader.GetString(2),
|
||||
Email = reader.GetString(3),
|
||||
Phone = reader.GetString(4),
|
||||
});
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
public override Client GetClientById(int id)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand($"SELECT * FROM client WHERE id = {id}", conn);
|
||||
using var reader = cmd.ExecuteReader();
|
||||
if (reader.Read())
|
||||
{
|
||||
return new Client
|
||||
{
|
||||
Id = reader.GetInt32(0),
|
||||
Name = reader.GetString(1),
|
||||
Surname = reader.GetString(2),
|
||||
Email = reader.GetString(3),
|
||||
Phone = reader.GetString(4)
|
||||
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void UpdateClient(Client client)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand($"UPDATE client SET name = '{client.Name}', surname = '{client.Surname}', email = '{client.Email}', phone = '{client.Phone}' WHERE id = {client.Id}", conn);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public override void DeleteClient(int id)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand($"DELETE FROM client WHERE id = {id}", conn);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
// Order
|
||||
public override void AddOrder(Order order)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("INSERT INTO orders (datestart, dateend, endcost, clientid, componentid, serviceid) VALUES (@DateStart, @DateEnd, @EndCost, @ClientId, @ComponentId, @ServiceId)", conn);
|
||||
cmd.Parameters.AddWithValue("@DateStart", order.DateStart);
|
||||
cmd.Parameters.AddWithValue("@DateEnd", order.DateEnd);
|
||||
cmd.Parameters.AddWithValue("@EndCost", order.EndCost);
|
||||
cmd.Parameters.AddWithValue("@ClientId", order.ClientId);
|
||||
cmd.Parameters.AddWithValue("@ComponentId", order.ComponentId);
|
||||
cmd.Parameters.AddWithValue("@ServiceId", order.ServiceId);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public override List<Order> GetOrders()
|
||||
{
|
||||
var orders = new List<Order>();
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("SELECT * FROM orders", conn);
|
||||
using var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
orders.Add(new Order
|
||||
{
|
||||
Id = reader.GetInt32(0),
|
||||
DateStart = reader.GetString(1),
|
||||
DateEnd = reader.GetString(2),
|
||||
EndCost = reader.GetDecimal(3),
|
||||
ClientId = reader.GetInt32(4),
|
||||
ComponentId = reader.GetInt32(5),
|
||||
ServiceId = reader.GetInt32(6),
|
||||
});
|
||||
}
|
||||
return orders;
|
||||
}
|
||||
|
||||
public override Order GetOrderById(int id)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand($"SELECT * FROM orders WHERE id = {id}", conn);
|
||||
using var reader = cmd.ExecuteReader();
|
||||
if (reader.Read())
|
||||
{
|
||||
return new Order
|
||||
{
|
||||
Id = reader.GetInt32(0),
|
||||
DateStart = reader.GetString(1),
|
||||
DateEnd = reader.GetString(2),
|
||||
EndCost = reader.GetDecimal(3),
|
||||
ClientId = reader.GetInt32(4),
|
||||
ComponentId = reader.GetInt32(5),
|
||||
ServiceId = reader.GetInt32(6),
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void UpdateOrder(Order order)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("UPDATE orders SET datestart = @DateStart, dateend = @DateEnd, endcost = @EndCost, clientid = @ClientId, componentid = @ComponentId, serviceid = @ServiceId WHERE id = @Id", conn);
|
||||
cmd.Parameters.AddWithValue("@DateStart", order.DateStart);
|
||||
cmd.Parameters.AddWithValue("@DateEnd", order.DateEnd);
|
||||
cmd.Parameters.AddWithValue("@EndCost", order.EndCost);
|
||||
cmd.Parameters.AddWithValue("@ClientId", order.ClientId);
|
||||
cmd.Parameters.AddWithValue("@ComponentId", order.ComponentId);
|
||||
cmd.Parameters.AddWithValue("@ServiceId", order.ServiceId);
|
||||
cmd.Parameters.AddWithValue("@Id", order.Id);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public override void DeleteOrder(int id)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand($"DELETE FROM orders WHERE id = {id}", conn);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
// Service
|
||||
public override void AddService(Service service)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("INSERT INTO service (title, cost, employeesid) VALUES (@Title, @Cost, @EmployeesId)", conn);
|
||||
cmd.Parameters.AddWithValue("@Title", service.Title);
|
||||
cmd.Parameters.AddWithValue("@Cost", service.Cost);
|
||||
cmd.Parameters.AddWithValue("@EmployeesId", service.EmployeesId);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public override List<Service> GetServices()
|
||||
{
|
||||
var services = new List<Service>();
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("SELECT * FROM service", conn);
|
||||
using var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
services.Add(new Service
|
||||
{
|
||||
Id = reader.GetInt32(0),
|
||||
Title = reader.GetString(1),
|
||||
Cost = reader.GetDecimal(2),
|
||||
EmployeesId = reader.GetInt32(3),
|
||||
});
|
||||
}
|
||||
return services;
|
||||
}
|
||||
|
||||
public override Service GetServiceById(int id)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand($"SELECT * FROM service WHERE id = {id}", conn);
|
||||
using var reader = cmd.ExecuteReader();
|
||||
if (reader.Read())
|
||||
{
|
||||
return new Service
|
||||
{
|
||||
Id = reader.GetInt32(0),
|
||||
Title = reader.GetString(1),
|
||||
Cost = reader.GetDecimal(2),
|
||||
EmployeesId = reader.GetInt32(3),
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public override void UpdateService(Service service)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("UPDATE service SET title = @Title, cost = @Cost, employeesid = @EmployeesId WHERE id = @Id", conn);
|
||||
cmd.Parameters.AddWithValue("@Title", service.Title);
|
||||
cmd.Parameters.AddWithValue("@Cost", service.Cost);
|
||||
cmd.Parameters.AddWithValue("@EmployeesId", service.EmployeesId);
|
||||
cmd.Parameters.AddWithValue("@Id", service.Id);
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override void DeleteService(int id)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand($"DELETE FROM service WHERE id = {id}", conn);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
// Component
|
||||
public override void AddComponent(Component component)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("INSERT INTO component (title, countsklad, manufacturer, price) VALUES (@Title, @CountSklad, @Manufacturer, @Price)", conn);
|
||||
cmd.Parameters.AddWithValue("@Title", component.Title);
|
||||
cmd.Parameters.AddWithValue("@CountSklad", component.CountSklad);
|
||||
cmd.Parameters.AddWithValue("@Manufacturer", component.Manufacturer);
|
||||
cmd.Parameters.AddWithValue("@Price", component.Price);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public override List<Component> GetComponents()
|
||||
{
|
||||
var components = new List<Component>();
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("SELECT * FROM component", conn);
|
||||
using var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
components.Add(new Component
|
||||
{
|
||||
Id = reader.GetInt32(0),
|
||||
Title = reader.GetString(1),
|
||||
CountSklad = reader.GetString(2),
|
||||
Manufacturer = reader.GetString(3),
|
||||
Price = reader.GetDouble(4)
|
||||
});
|
||||
}
|
||||
return components;
|
||||
}
|
||||
|
||||
public override Component GetComponentById(int id)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand($"SELECT * FROM component WHERE id = {id}", conn);
|
||||
using var reader = cmd.ExecuteReader();
|
||||
if (reader.Read())
|
||||
{
|
||||
return new Component
|
||||
{
|
||||
Id = reader.GetInt32(0),
|
||||
Title = reader.GetString(1),
|
||||
CountSklad = reader.GetString(2),
|
||||
Manufacturer = reader.GetString(3),
|
||||
Price = reader.GetDouble(4)
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void UpdateComponent(Component component)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand($"UPDATE component SET title = '{component.Title}', countsklad = '{component.CountSklad}', manufacturer = '{component.Manufacturer}', price = '{component.Price}' WHERE id = {component.Id}", conn);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public override void DeleteComponent(int id)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand($"DELETE FROM component WHERE id = {id}", conn);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
13
ComputerFirm/database/database.csproj
Normal file
13
ComputerFirm/database/database.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Npgsql" Version="8.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
62
ComputerFirm/database/models.cs
Normal file
62
ComputerFirm/database/models.cs
Normal file
@ -0,0 +1,62 @@
|
||||
namespace database
|
||||
{
|
||||
// Определение моделей данных
|
||||
|
||||
public class Device
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string TypeDevice { get; set; }
|
||||
public string Model { get; set; }
|
||||
public string SerialNumber { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
public int OrderId { get; set; }
|
||||
}
|
||||
|
||||
public class Employee
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Surname { get; set; }
|
||||
public string Position { get; set; }
|
||||
public string Timework { get; set; }
|
||||
public string Seniority { get; set; }
|
||||
public decimal CostPerHour { get; set; }
|
||||
}
|
||||
|
||||
public class Client
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Surname { get; set; }
|
||||
public string Phone { get; set; }
|
||||
public string Email { get; set; }
|
||||
}
|
||||
|
||||
public class Order
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int ComponentId { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
public int ServiceId { get; set; }
|
||||
public String DateStart { get; set; }
|
||||
public String DateEnd { get; set; }
|
||||
public decimal EndCost { get; set; }
|
||||
}
|
||||
|
||||
public class Service
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
public decimal Cost { get; set; }
|
||||
public int EmployeesId { get; set; }
|
||||
}
|
||||
|
||||
public class Component
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string CountSklad { get; set; }
|
||||
public double Price { get; set; }
|
||||
public string Manufacturer { get; set; }
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user