56 lines
1.8 KiB
C#
56 lines
1.8 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;
|
|||
|
|
|
|||
|
|
namespace KursovayaDvornikovAM
|
|||
|
|
{
|
|||
|
|
public partial class Add : Form
|
|||
|
|
{
|
|||
|
|
public Add()
|
|||
|
|
{
|
|||
|
|
InitializeComponent();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void button1_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
string connect = "server=cfif31.ru;user=ISPr24-37_DvornikovAM;database=ISPr24-37_DvornikovAM_Kursovaya;password=ISPr24-37_DvornikovAM";
|
|||
|
|
|
|||
|
|
MySqlConnection connection = new MySqlConnection(connect);
|
|||
|
|
{
|
|||
|
|
connection.Open();
|
|||
|
|
|
|||
|
|
|
|||
|
|
var Nazvanie = textBox1.Text;
|
|||
|
|
var Kategoria = textBox2.Text;
|
|||
|
|
int Cena;
|
|||
|
|
var Opisanie = textBox4.Text;
|
|||
|
|
int Sklad;
|
|||
|
|
|
|||
|
|
if (int.TryParse(textBox3.Text, out Cena) && int.TryParse(textBox5.Text, out Sklad))
|
|||
|
|
{
|
|||
|
|
var add = $"INSERT INTO Tovar (Nazvanie, Kategoria, Cena, Opisanie, Sklad) VALUES ('{Nazvanie}', '{Kategoria}', {Cena}, '{Opisanie}', {Sklad})";
|
|||
|
|
|
|||
|
|
var command = new MySqlCommand(add, connection);
|
|||
|
|
command.ExecuteNonQuery();
|
|||
|
|
|
|||
|
|
MessageBox.Show("Запись успешно создана!", "Успех!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("Пункты ЦЕНА и СКЛАД должны иметь числовой формат!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
connection.Close();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|