117 lines
5.0 KiB
C#
117 lines
5.0 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 Npgsql;
|
|
|
|
namespace demo25052026
|
|
{
|
|
public partial class Form2 : Form
|
|
{
|
|
static string connS = "Server=localhost;Port=5432;Database=newdemo26;Username=postgres;Password=Swa2sWA13;";
|
|
int ID_pr { get; set; }
|
|
public Form2(int ID)
|
|
{
|
|
InitializeComponent();
|
|
ID_pr = ID;
|
|
if (ID != 0)
|
|
{
|
|
NpgsqlConnection npgsqlConnection = new NpgsqlConnection(connS);
|
|
npgsqlConnection.Open();
|
|
NpgsqlCommand command = new NpgsqlCommand(@$"SELECT ""Naimenov_ID"", ""Tip_ID"", ""Ed_izm"", ""Cena"", ""Postav_ID"", ""Proizv_ID"", ""Skidka"", ""Kolichestvo"", ""Opisanie"", ""Photo"", ""Articul"" FROM public.""Tovar"" WHERE ""ID_Tovar"" = {ID};", npgsqlConnection);
|
|
DataTable data = new DataTable();
|
|
data.Load(command.ExecuteReader());
|
|
comboBox2.SelectedIndex = int.Parse(data.Rows[0].ItemArray[0].ToString()) - 1;
|
|
comboBox1.SelectedIndex = int.Parse(data.Rows[0].ItemArray[1].ToString()) - 1;
|
|
comboBox5.SelectedIndex = 0;
|
|
textBox5.Text = data.Rows[0].ItemArray[3].ToString();
|
|
comboBox4.SelectedIndex = int.Parse(data.Rows[0].ItemArray[4].ToString()) - 1;
|
|
comboBox3.SelectedIndex = int.Parse(data.Rows[0].ItemArray[5].ToString()) - 1;
|
|
|
|
Skidka.Text = data.Rows[0].ItemArray[6].ToString();
|
|
|
|
textBox7.Text = data.Rows[0].ItemArray[7].ToString();
|
|
textBox2.Text = data.Rows[0].ItemArray[8].ToString();
|
|
if (data.Rows[0].ItemArray[9].ToString() != "")
|
|
{
|
|
Photo.Image = Image.FromFile(data.Rows[0].ItemArray[9].ToString());
|
|
PhotoPath = data.Rows[0].ItemArray[9].ToString();
|
|
}
|
|
else
|
|
{
|
|
Photo.Image = Image.FromFile("picture.png");
|
|
}
|
|
|
|
textBox1.Text = data.Rows[0].ItemArray[10].ToString();
|
|
|
|
|
|
npgsqlConnection.Close();
|
|
}
|
|
|
|
}
|
|
|
|
string PhotoPath { get; set; }
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
if (ID_pr == 0)
|
|
{
|
|
NpgsqlConnection npgsqlConnection = new NpgsqlConnection(connS);
|
|
npgsqlConnection.Open();
|
|
NpgsqlCommand command = new NpgsqlCommand(@$"INSERT INTO public.""Tovar""(""Articul"", ""Naimenov_ID"", ""Ed_izm"", ""Cena"", ""Postav_ID"", ""Proizv_ID"", ""Tip_ID"", ""Skidka"", ""Kolichestvo"", ""Opisanie"", ""Photo"") VALUES ('{textBox1.Text}', {comboBox2.SelectedIndex + 1}, '{comboBox5.SelectedItem.ToString()}', {textBox5.Text}, {comboBox4.SelectedIndex + 1}, {comboBox3.SelectedIndex + 1}, {comboBox1.SelectedIndex + 1}, {Skidka.Text}, {textBox7.Text}, {textBox2.Text}, {PhotoPath});", npgsqlConnection);
|
|
command.ExecuteNonQuery();
|
|
|
|
npgsqlConnection.Close();
|
|
}
|
|
else
|
|
{
|
|
NpgsqlConnection npgsqlConnection = new NpgsqlConnection(connS);
|
|
npgsqlConnection.Open();
|
|
NpgsqlCommand command = new NpgsqlCommand(@$"UPDATE public.""Tovar"" SET ""Articul""='{textBox1.Text}', ""Naimenov_ID""={comboBox2.SelectedIndex + 1}, ""Ed_izm""='{comboBox5.SelectedItem.ToString()}', ""Cena""= {textBox5.Text}, ""Postav_ID""={comboBox4.SelectedIndex + 1}, ""Proizv_ID""={comboBox3.SelectedIndex + 1}, ""Tip_ID""={comboBox1.SelectedIndex + 1}, ""Skidka""={Skidka.Text}, ""Kolichestvo""={textBox7.Text}, ""Opisanie""='{textBox2.Text}', ""Photo""= '{PhotoPath}' WHERE ""ID_Tovar""= {ID_pr};", npgsqlConnection);
|
|
command.ExecuteNonQuery();
|
|
|
|
npgsqlConnection.Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void Photo_Click(object sender, EventArgs e)
|
|
{
|
|
OpenFileDialog openFile = new OpenFileDialog();
|
|
if (openFile.ShowDialog() == DialogResult.OK)
|
|
{
|
|
PhotoPath = openFile.FileName;
|
|
Photo.Image = Image.FromFile(PhotoPath);
|
|
}
|
|
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
this.Hide();
|
|
Form1 form = new Form1();
|
|
form.Hide();
|
|
}
|
|
|
|
private void button4_Click(object sender, EventArgs e)
|
|
{
|
|
NpgsqlConnection npgsqlConnection = new NpgsqlConnection(connS);
|
|
npgsqlConnection.Open();
|
|
NpgsqlCommand command = new NpgsqlCommand(@$"DELETE FROM public.""Tovar"" WHERE ""ID_Tovar"" = {ID_pr};", npgsqlConnection);
|
|
command.ExecuteNonQuery();
|
|
|
|
npgsqlConnection.Close();
|
|
}
|
|
}
|
|
}
|