121 lines
4.3 KiB
C#
121 lines
4.3 KiB
C#
|
|
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;
|
|||
|
|
|
|||
|
|
namespace auto_repair_shop
|
|||
|
|
{
|
|||
|
|
public partial class Form1 : Form
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
public DataTable data = new DataTable();
|
|||
|
|
|
|||
|
|
public Form1()
|
|||
|
|
{
|
|||
|
|
InitializeComponent();
|
|||
|
|
DataTable dataTable = Dbs.select("SELECT idbid, client, service, price, deadlines FROM bid ");
|
|||
|
|
data = dataTable;
|
|||
|
|
dataGridView1.DataSource = data;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
private void button1_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
{
|
|||
|
|
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "")
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("Заполните все поля!");
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
data = Dbs.select($"INSERT INTO bid (`client`,`service`,`price`, `deadlines` ) VALUES ('{textBox1.Text}','{textBox2.Text}','{textBox3.Text}','{textBox4.Text}');");
|
|||
|
|
data = Dbs.select(@"SELECT idBid,client,service,price, deadlines FROM bid ");
|
|||
|
|
textBox1.Clear();
|
|||
|
|
textBox2.Clear();
|
|||
|
|
textBox3.Clear();
|
|||
|
|
textBox4.Clear();
|
|||
|
|
|
|||
|
|
dataGridView1.DataSource = data;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void button2_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
DialogResult result = MessageBox.Show("удалить безвазвратно?", "Подтвердите действие", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|||
|
|
|
|||
|
|
if (result == DialogResult.Yes)
|
|||
|
|
{
|
|||
|
|
data = Dbs.select($"DELETE FROM bid WHERE idBid = " + dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[0].Value.ToString());
|
|||
|
|
data = Dbs.select($"SELECT idBid, client, service,price, deadlines FROM bid ");
|
|||
|
|
MessageBox.Show("Удаление завершено!", "TsManager");
|
|||
|
|
}
|
|||
|
|
else if (result == DialogResult.No)
|
|||
|
|
{
|
|||
|
|
dataGridView1.DataSource = data;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
dataGridView1.DataSource = data;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
private void button3_Click_1(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
int selectedRowIndex = dataGridView1.CurrentCell.RowIndex;
|
|||
|
|
|
|||
|
|
if (selectedRowIndex < 0)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("Пожалуйста, выберите строку для редактирования.");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
int id = Convert.ToInt32(dataGridView1.Rows[selectedRowIndex].Cells[0].Value);
|
|||
|
|
|
|||
|
|
|
|||
|
|
if (string.IsNullOrWhiteSpace(textBox1.Text) || string.IsNullOrWhiteSpace(textBox2.Text) || string.IsNullOrWhiteSpace(textBox3.Text) || string.IsNullOrWhiteSpace(textBox4.Text))
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("Заполните все поля!");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
DialogResult result = MessageBox.Show("уверены что хотите редактировать?", "Подтвердите действие", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|||
|
|
|
|||
|
|
if (result == DialogResult.Yes)
|
|||
|
|
{
|
|||
|
|
string updateQuery = $"UPDATE bid SET client = '{textBox1.Text}', service = '{textBox2.Text}', price= '{textBox3.Text}', deadlines= '{textBox4.Text}' WHERE idBid = {id};";
|
|||
|
|
Dbs.select(updateQuery);
|
|||
|
|
|
|||
|
|
|
|||
|
|
data = Dbs.select("SELECT idBid, client, service, price, deadlines FROM bid ");
|
|||
|
|
dataGridView1.DataSource = data;
|
|||
|
|
|
|||
|
|
|
|||
|
|
textBox1.Clear();
|
|||
|
|
textBox2.Clear();
|
|||
|
|
textBox3.Clear();
|
|||
|
|
textBox4.Clear();
|
|||
|
|
MessageBox.Show("редактирование завершено!", "TsManager");
|
|||
|
|
}
|
|||
|
|
else if (result == DialogResult.No)
|
|||
|
|
{
|
|||
|
|
dataGridView1.DataSource = data;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|