2021-07-15 16:58:51 +05:00
|
|
|
|
using Diplom_B.DB;
|
|
|
|
|
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 Diplom_B
|
|
|
|
|
{
|
|
|
|
|
public partial class IzdForm : Form
|
|
|
|
|
{
|
|
|
|
|
public IzdForm()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
errorLable.Visible = false;
|
2021-07-15 23:13:18 +05:00
|
|
|
|
idLable.Text = "";
|
2021-07-15 16:58:51 +05:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (var db = new MainDB()){
|
2021-07-15 23:13:18 +05:00
|
|
|
|
var res = WorkDB.ListIzdelie();
|
2021-07-15 16:58:51 +05:00
|
|
|
|
UpdateTable(res);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
ShowError();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void createButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!double.TryParse(cenaBox.Text, out double cena))
|
|
|
|
|
{
|
|
|
|
|
ShowError("Ошибка цены.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!int.TryParse(otdRazBox.Text, out int otdRaz))
|
|
|
|
|
{
|
|
|
|
|
ShowError("Ошибка отдела-разработчика.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
var r = new Izdelie()
|
|
|
|
|
{
|
|
|
|
|
Name = nameBox.Text,
|
|
|
|
|
DecNum = decBox.Text,
|
|
|
|
|
Shifr = shifrBox.Text,
|
|
|
|
|
Litera = literaBox.Text,
|
|
|
|
|
Cena = cena,
|
|
|
|
|
OtdelRazrab = otdRaz,
|
|
|
|
|
Ved = vedBox.Text,
|
|
|
|
|
GlavKonstr = glavKonstrBox.Text
|
|
|
|
|
};
|
2021-07-15 23:13:18 +05:00
|
|
|
|
WorkDB.AddIzdelie(r);
|
|
|
|
|
UpdateTable(WorkDB.ListIzdelie());
|
2021-07-15 16:58:51 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ShowError(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void UpdateTable(Izdelie[] arr)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
var r = dataGridView1.Rows;
|
|
|
|
|
while (r.Count > 0)
|
|
|
|
|
r.Remove(r[0]);
|
|
|
|
|
var c = dataGridView1.Columns;
|
|
|
|
|
while (c.Count > 0)
|
|
|
|
|
c.Remove(c[0]);
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
var c = dataGridView1.Columns;
|
|
|
|
|
c.Add("Id", "№");
|
2021-07-15 23:13:18 +05:00
|
|
|
|
c["Id"].Width = 40;
|
|
|
|
|
c.Add("Name", "Наим.");
|
|
|
|
|
c["Name"].Width = 60;
|
|
|
|
|
c.Add("DecNum", "Дец. №");
|
|
|
|
|
c["DecNum"].Width = 120;
|
2021-07-15 16:58:51 +05:00
|
|
|
|
c.Add("Shifr", "Шифр");
|
2021-07-15 23:13:18 +05:00
|
|
|
|
c["Shifr"].Width = 80;
|
2021-07-15 16:58:51 +05:00
|
|
|
|
c.Add("Litera", "Литера");
|
2021-07-15 23:13:18 +05:00
|
|
|
|
c["Litera"].Width = 50;
|
2021-07-15 16:58:51 +05:00
|
|
|
|
c.Add("Cena", "Цена");
|
2021-07-15 23:13:18 +05:00
|
|
|
|
c["Cena"].Width = 70;
|
2021-07-15 16:58:51 +05:00
|
|
|
|
c.Add("OtdelRazrab", "Отдел");
|
2021-07-15 23:13:18 +05:00
|
|
|
|
c["OtdelRazrab"].Width = 40;
|
|
|
|
|
c.Add("Ved", "Вед.");
|
|
|
|
|
c.Add("GlavKonstr", "Глав. констр.");
|
2021-07-15 16:58:51 +05:00
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
var r = dataGridView1.Rows;
|
|
|
|
|
foreach(var izd in arr)
|
|
|
|
|
r.Add(new object[] {
|
|
|
|
|
izd.Id,
|
|
|
|
|
izd.Name,
|
|
|
|
|
izd.DecNum,
|
|
|
|
|
izd.Shifr,
|
|
|
|
|
izd.Litera,
|
2021-07-15 23:13:18 +05:00
|
|
|
|
izd.Cena.ToString("F2") + " Р",
|
2021-07-15 16:58:51 +05:00
|
|
|
|
izd.OtdelRazrab,
|
|
|
|
|
izd.Ved,
|
|
|
|
|
izd.GlavKonstr
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-07-15 23:13:18 +05:00
|
|
|
|
if (dataGridView1.Rows.Count > 0)
|
|
|
|
|
dataGridView1.Rows[0].Selected = true;
|
|
|
|
|
dataGridView1_CurrentCellChanged(this, new EventArgs());
|
2021-07-15 16:58:51 +05:00
|
|
|
|
}
|
2021-07-15 23:13:18 +05:00
|
|
|
|
|
|
|
|
|
private Task errDrop;
|
2021-07-15 16:58:51 +05:00
|
|
|
|
private void ShowError(string msg = null)
|
|
|
|
|
{
|
|
|
|
|
errorLable.Text = string.IsNullOrEmpty(msg) ? "Неизвестная ошибка." : msg;
|
|
|
|
|
errorLable.Visible = true;
|
2021-07-15 23:13:18 +05:00
|
|
|
|
errDrop = new Task(() =>
|
|
|
|
|
{
|
|
|
|
|
var fd = errDrop.Id;
|
|
|
|
|
Task.Delay(5000).Wait();
|
|
|
|
|
if (errDrop.Id == fd)
|
|
|
|
|
if (InvokeRequired) Invoke((Action)(() => { errorLable.Visible = false; }));
|
|
|
|
|
else errorLable.Visible = false;
|
|
|
|
|
});
|
|
|
|
|
errDrop.Start();
|
2021-07-15 16:58:51 +05:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-15 23:13:18 +05:00
|
|
|
|
private void dataGridView1_CurrentCellChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ClearBoxes();
|
|
|
|
|
if (dataGridView1.SelectedRows.Count != 1)
|
|
|
|
|
return;
|
|
|
|
|
{
|
|
|
|
|
var izd = WorkDB.GetIzdelie((int)dataGridView1.SelectedRows[0].Cells[0].Value);
|
|
|
|
|
if (izd == null)
|
|
|
|
|
return;
|
|
|
|
|
idLable.Text = izd.Id.ToString();
|
|
|
|
|
nameBox.Text = izd.Name;
|
|
|
|
|
decBox.Text = izd.DecNum;
|
|
|
|
|
shifrBox.Text = izd.Shifr;
|
|
|
|
|
literaBox.Text = izd.Litera;
|
|
|
|
|
cenaBox.Text = izd.Cena.ToString();
|
|
|
|
|
otdRazBox.Text = izd.OtdelRazrab.ToString();
|
|
|
|
|
vedBox.Text = izd.Ved;
|
|
|
|
|
glavKonstrBox.Text = izd.GlavKonstr;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-15 16:58:51 +05:00
|
|
|
|
|
2021-07-15 23:13:18 +05:00
|
|
|
|
private void clearButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ClearBoxes();
|
|
|
|
|
}
|
|
|
|
|
private void ClearBoxes()
|
|
|
|
|
{
|
|
|
|
|
idLable.Text = "";
|
|
|
|
|
nameBox.Text = "";
|
|
|
|
|
decBox.Text = "";
|
|
|
|
|
shifrBox.Text = "";
|
|
|
|
|
literaBox.Text = "";
|
|
|
|
|
cenaBox.Text = "";
|
|
|
|
|
otdRazBox.Text = "";
|
|
|
|
|
vedBox.Text = "";
|
|
|
|
|
glavKonstrBox.Text = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Task filterDrop;
|
|
|
|
|
private void searchBox_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
filterDrop = new Task(() =>
|
|
|
|
|
{
|
|
|
|
|
var fd = filterDrop.Id;
|
|
|
|
|
Task.Delay(1000).Wait();
|
|
|
|
|
if (filterDrop.Id == fd)
|
|
|
|
|
if (InvokeRequired) Invoke((Action)(() => { UpdateTable(WorkDB.ListIzdelie(searchBox.Text)); }));
|
|
|
|
|
else UpdateTable(WorkDB.ListIzdelie(searchBox.Text));
|
2021-07-15 16:58:51 +05:00
|
|
|
|
|
2021-07-15 23:13:18 +05:00
|
|
|
|
});
|
|
|
|
|
filterDrop.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void resetSearchButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
searchBox.Text = "";
|
|
|
|
|
filterDrop = new Task(() => { return; });
|
|
|
|
|
UpdateTable(WorkDB.ListIzdelie());
|
|
|
|
|
}
|
2021-07-15 16:58:51 +05:00
|
|
|
|
}
|
|
|
|
|
}
|