KalkulatorISP-31rrrrr/source/repos/test/Form4.cs
2025-11-11 14:18:33 +04:00

44 lines
1.6 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;
namespace test
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string connect = "server=cfif31.ru;user=ISPr24-37_AnpilogovPV;database=ISPr24-37_AnpilogovPV_ekzam;password=ISPr24-37_AnpilogovPV";
MySqlConnection connection = new MySqlConnection(connect);
{
connection.Open();
var name = textBox1.Text;
int cena;
if (int.TryParse(textBox2.Text, out cena))
{
var add = $"INSERT INTO producti (name, cena) VALUES ('{name}', '{cena}')";
var command = new MySqlCommand(add, connection);
command.ExecuteNonQuery(); MessageBox.Show("Запись успешно создана!", "Успех!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
MessageBox.Show("Пункты ПЛАН и СДЕЛАНО должны иметь числовой формат!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
connection.Close();
}
}
}
}