test/KursovayaDvornikovAM/WarehouseForm.cs

175 lines
5.7 KiB
C#

using MySql.Data.MySqlClient;
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;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using Excel = Microsoft.Office.Interop.Excel;
namespace KursovayaDvornikovAM
{
public partial class WarehouseForm : Form
{
public WarehouseForm()
{
InitializeComponent();
}
private void label3_Click(object sender, EventArgs e)
{
}
private void ReturnButton_Click(object sender, EventArgs e)
{
this.Hide();
MainForm mainForm = new MainForm();
mainForm.Show();
}
private void WarehouseForm_Load(object sender, EventArgs e)
{
DataTable data = DBconnection.Select("SELECT idSklad,Nomer_Sklada,Adress,Opisanie FROM `ISPr24-37_DvornikovAM_Kursovaya`.Sklad ;");
dataGridView1.DataSource = data;
dataGridView1.DataSource = data;
dataGridView1.AllowUserToAddRows = false;
}
private void CloseButton_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void HideButton_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
private void HideButton_MouseEnter(object sender, EventArgs e)
{
HideButton.ForeColor = Color.Red;
}
private void HideButton_MouseLeave(object sender, EventArgs e)
{
HideButton.ForeColor = Color.Black;
}
private void CloseButton_MouseEnter(object sender, EventArgs e)
{
CloseButton.ForeColor = Color.Red;
}
private void CloseButton_MouseLeave(object sender, EventArgs e)
{
CloseButton.ForeColor = Color.Black;
}
Point lastPoint;
private void WarehouseForm_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.Left += e.X - lastPoint.X;
this.Top += e.Y - lastPoint.Y;
}
}
private void WarehouseForm_MouseDown(object sender, MouseEventArgs e)
{
lastPoint = new Point(e.X, e.Y);
}
private void label4_Click(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
//добавление
private void Dobavlenie_Click(object sender, EventArgs e)
{
if ((textBox1.Text == "") || (textBox2.Text == "") || (textBox3.Text == ""))
MessageBox.Show("Заполните все поля");
else
{
DBconnection.Select("insert into Sklad (`Nomer_Sklada`,`Adress`,`Opisanie`) values ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text +"')");
textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = "";
}
}
//редактирование
private void Redactirovanie_Click(object sender, EventArgs e)
{
string id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
if ((textBox1.Text == "") || (textBox2.Text == "") || (textBox3.Text == ""))
MessageBox.Show("Заполните все поля");
else
{
DBconnection.Select("UPDATE Sklad SET Nomer_Sklada='" + textBox1.Text + "',Adress='" + textBox2.Text + "',Opisanie='" + textBox3.Text +"' WHERE idSklad='" + id + "'");
textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = "";
}
}
//удаление
private void Udalenie_Click(object sender, EventArgs e)
{
DataTable data = DBconnection.Select(@"DELETE FROM `ISPr24-37_DvornikovAM_Kursovaya`.Sklad WHERE idSklad='" + dataGridView1.SelectedRows[0].Cells[0].Value.ToString() + "';");
data = DBconnection.Select("SELECT idSklad,Nomer_Sklada,Adress,Opisanie FROM `ISPr24-37_DvornikovAM_Kursovaya`.Sklad;");
dataGridView1.DataSource = data;
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
//Обновление
private void Obnovlenie_Click(object sender, EventArgs e)
{
DataTable data = DBconnection.Select("SELECT idSklad,Nomer_Sklada,Adress,Opisanie FROM `ISPr24-37_DvornikovAM_Kursovaya`.Sklad;");
dataGridView1.DataSource = null;
dataGridView1.DataSource = data;
}
private void Export_Click(object sender, EventArgs e)
{
Excel.Application exApp = new Excel.Application();
exApp.Workbooks.Add();
Excel.Worksheet worksheet = (Excel.Worksheet)exApp.ActiveSheet;
int i, j;
for (i = 0; i <= dataGridView1.RowCount - 1; i++)
{
for (j = 0; j <= dataGridView1.ColumnCount - 1; j++)
{
worksheet.Cells[i + 1, j + 1] = dataGridView1[j, i].Value.ToString();
}
}
exApp.Visible = true;
}
private void Search_TextChanged(object sender, EventArgs e)
{
(dataGridView1.DataSource as DataTable).DefaultView.RowFilter = $"Adress LIKE '%{Search.Text}%'";
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
dataGridView1.DataSource = DBconnection.Select("SELECT Nomer_Sklada,Adress,Opisanie FROM Sklad order by " + comboBox1.SelectedItem);
}
}
}