Добавьте файлы проекта.
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
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 Npgsql;
|
||||
|
||||
namespace demo26052026
|
||||
{
|
||||
public partial class Form2 : Form
|
||||
{
|
||||
int IDs { get; set; }
|
||||
static string ConnString = "Server=localhost;Port=5432;Database=newdemo262;Username=postgres;Password=Swa2sWA13;";
|
||||
public Form2(int ID)
|
||||
{
|
||||
IDs = ID;
|
||||
InitializeComponent();
|
||||
if (ID != 0)
|
||||
{
|
||||
NpgsqlConnection npgsqlConnection = new NpgsqlConnection(ConnString);
|
||||
npgsqlConnection.Open();
|
||||
NpgsqlCommand npgsqlCommand = new NpgsqlCommand(@$"SELECT ""Articul"", ""Naim_ID"", ""Ed_izm"", ""Cena"", ""Postav_ID"", ""Proizvod_ID"", ""Kategory_ID"", ""Skidka"", ""Kolichestvo"", ""Opisanie"", ""Photo"", ""ID_Tovar"" FROM public.""Tovar"" WHERE ""ID_Tovar"" = {ID};", npgsqlConnection);
|
||||
DataTable dataTable = new DataTable();
|
||||
dataTable.Load(npgsqlCommand.ExecuteReader());
|
||||
|
||||
|
||||
comboBox1.SelectedIndex = int.Parse(dataTable.Rows[0].ItemArray[1].ToString()) - 1;
|
||||
comboBox2.SelectedIndex = int.Parse(dataTable.Rows[0].ItemArray[6].ToString()) - 1;
|
||||
textBox1.Text = dataTable.Rows[0].ItemArray[0].ToString();
|
||||
|
||||
textBox2.Text = dataTable.Rows[0].ItemArray[9].ToString();
|
||||
comboBox3.SelectedIndex = int.Parse(dataTable.Rows[0].ItemArray[5].ToString()) - 1;
|
||||
comboBox4.SelectedIndex = int.Parse(dataTable.Rows[0].ItemArray[4].ToString()) - 1;
|
||||
|
||||
textBox3.Text = dataTable.Rows[0].ItemArray[3].ToString();
|
||||
comboBox5.SelectedIndex = 0;
|
||||
|
||||
textBox4.Text = dataTable.Rows[0].ItemArray[8].ToString();
|
||||
textBox5.Text = dataTable.Rows[0].ItemArray[7].ToString();
|
||||
|
||||
if (dataTable.Rows[0].ItemArray[10].ToString() != "")
|
||||
{
|
||||
pictureBox1.Image = Image.FromFile(dataTable.Rows[0].ItemArray[10].ToString());
|
||||
PhotoPath = dataTable.Rows[0].ItemArray[10].ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
pictureBox1.Image = Image.FromFile("picture.png");
|
||||
}
|
||||
|
||||
|
||||
npgsqlConnection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
string PhotoPath = "picture.png";
|
||||
private void pictureBox1_Click(object sender, EventArgs e)
|
||||
{
|
||||
OpenFileDialog openFileDialog = new OpenFileDialog();
|
||||
if(openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
PhotoPath = openFileDialog.FileName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void button3_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.Hide();
|
||||
Form1 form1 = new Form1();
|
||||
form1.ShowDialog();
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (IDs == 0)
|
||||
{
|
||||
NpgsqlConnection npgsqlConnection = new NpgsqlConnection(ConnString);
|
||||
npgsqlConnection.Open();
|
||||
NpgsqlCommand npgsqlCommand = new NpgsqlCommand(@$"INSERT INTO public.""Tovar""(""Articul"", ""Naim_ID"", ""Ed_izm"", ""Cena"", ""Postav_ID"", ""Proizvod_ID"", ""Kategory_ID"", ""Skidka"", ""Kolichestvo"", ""Opisanie"", ""Photo"") VALUES ('{textBox1.Text}', {comboBox2.SelectedIndex + 1}, '{comboBox5.SelectedItem.ToString()}', {textBox3.Text}, {comboBox4.SelectedIndex + 1}, {comboBox3.SelectedIndex + 1}, {comboBox1.SelectedIndex + 1}, {textBox5.Text}, {textBox4.Text}, {textBox2.Text}, {PhotoPath});", npgsqlConnection);
|
||||
npgsqlCommand.ExecuteNonQuery();
|
||||
npgsqlConnection.Close();
|
||||
MessageBox.Show("Запись успешно внесенна");
|
||||
}
|
||||
else
|
||||
{
|
||||
NpgsqlConnection npgsqlConnection = new NpgsqlConnection(ConnString);
|
||||
npgsqlConnection.Open();
|
||||
NpgsqlCommand npgsqlCommand = new NpgsqlCommand(@$"UPDATE public.""Tovar"" SET ""Articul""='{textBox1.Text}', ""Naim_ID""={comboBox2.SelectedIndex + 1}, ""Ed_izm""='{comboBox5.SelectedItem.ToString()}', ""Cena""= {textBox3.Text}, ""Postav_ID""={comboBox4.SelectedIndex + 1}, ""Proizvod_ID""={comboBox3.SelectedIndex + 1}, ""Kategory_ID""={comboBox1.SelectedIndex + 1}, ""Skidka""={textBox5.Text}, ""Kolichestvo""={textBox4.Text}, ""Opisanie""={textBox2.Text}, ""Photo""={PhotoPath} WHERE ""ID_Tovar""= {IDs};", npgsqlConnection);
|
||||
npgsqlCommand.ExecuteNonQuery();
|
||||
npgsqlConnection.Close();
|
||||
MessageBox.Show("Запись успешно измененна");
|
||||
}
|
||||
}
|
||||
|
||||
private void button2_Click(object sender, EventArgs e)
|
||||
{
|
||||
NpgsqlConnection npgsqlConnection = new NpgsqlConnection(ConnString);
|
||||
npgsqlConnection.Open();
|
||||
NpgsqlCommand npgsqlCommand = new NpgsqlCommand(@$"DELETE FROM public.""Tovar"" WHERE ""ID_Tovar"" = {IDs};", npgsqlConnection);
|
||||
npgsqlCommand.ExecuteNonQuery();
|
||||
npgsqlConnection.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user