Ekz_LEDNEV/Form1.cs
2026-05-15 11:49:45 +04:00

80 lines
2.5 KiB
C#

using MySql.Data.MySqlClient;
using System.Data;
namespace ekz_lednev
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// Çàãðóçêà ôîðìî÷êè è çàïîëíåíèå äàííûõ â äàòàãðèäâüþ
private void Form1_Load(object sender, EventArgs e)
{
DB dB = DB.GetInstance();
DataTable dt = new DataTable();
MySqlDataAdapter adp = new MySqlDataAdapter();
MySqlCommand cmd = new MySqlCommand($@"
SELECT b.`id`, b.`name`, bt.`name` AS `material_type_id`, b.`price_one`, b.`quantity_real`, b.`quantity_plan`, b.`quantity_pack`, bu.`name` AS `unit_id`
FROM `Material` b
LEFT JOIN `material_type` bt ON bt.`id`=b.`material_type_id`
LEFT JOIN `unit` bu ON bu.`id`=b.`unit_id`
", dB.GetConnection());
adp.SelectCommand = cmd;
adp.Fill(dt);
dataGridView1.DataSource = dt;
}
// Êíîïêà óäàëåíèÿ
private void button3_Click(object sender, EventArgs e)
{
DataGridViewRow dtRow = dataGridView1.SelectedRows[0];
int id = Convert.ToInt32(dtRow.Cells["id"].Value);
DB dB = DB.GetInstance();
MySqlCommand cmd = new MySqlCommand($"DELETE FROM `pozorisp_lednev_ekz`.`Material` WHERE (`id` = '{id}');", dB.GetConnection());
cmd.ExecuteNonQuery();
MessageBox.Show("Óäàëåíî!");
Application.Restart();
}
// Êíîïêà äîáàâëåíèå
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.Show();
}
// Êíîïêà ðåäàêòèðîâàíèÿ
private void button2_Click(object sender, EventArgs e)
{
Form3 form3 = new Form3();
form3.Show();
}
// Ïîäñêàçêà
private void button5_Click(object sender, EventArgs e)
{
MessageBox.Show("Äàííàÿ ñòðàíèöà âûâîäèò ñïèñîê òîâàðîâ, ïðè âàøåì æåëàíèè ñäåëàòü ÷òî-ëèáî ñ ýòèì ñïèñêîì, âîñïîëüçóéòåñü êíîïêàìè" +
" Äîï. Èíôî - òàáëèöà ñ äîï. èíôîðìàöèåé");
}
private void button6_Click(object sender, EventArgs e)
{
Form4 form4 = new Form4();
form4.Show();
}
private void button4_Click(object sender, EventArgs e)
{
Form5 form5 = new Form5();
form5.Show();
}
}
}