80 lines
3.6 KiB
C#
80 lines
3.6 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 Form4 : Form
|
|
{
|
|
static string connS = "Server=localhost;Port=5432;Database=newdemo26;Username=postgres;Password=Swa2sWA13;";
|
|
public Form4()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void button4_Click(object sender, EventArgs e)
|
|
{
|
|
listBox1.Items.Add(comboBox1.SelectedItem.ToString() + "|" + textBox1.Text);
|
|
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
//INSERT INTO public.""Zakaz""(""Data_Z"", ""Data_P"", ""ID_Punkt"", ""Status_Zakaz"") VALUES(?, ?, ?, ?);
|
|
if (true)
|
|
{
|
|
NpgsqlConnection npgsqlConnection = new NpgsqlConnection(connS);
|
|
npgsqlConnection.Open();
|
|
NpgsqlCommand command = new NpgsqlCommand(@$"INSERT INTO public.""Zakaz""(""Data_Z"", ""Data_P"", ""ID_Punkt"", ""Status_Zakaz"") VALUES('{textBox2.Text}', '{textBox2.Text}', {comboBox3.SelectedIndex + 1}, {comboBox2.SelectedIndex + 1}) RETURNING ""ID_Zakaz"";", npgsqlConnection);
|
|
DataTable dataTable1 = new DataTable();
|
|
dataTable1.Load(command.ExecuteReader());
|
|
int IDZAKAZ = int.Parse(dataTable1.Rows[0].ItemArray[0].ToString());
|
|
npgsqlConnection.Close();
|
|
|
|
int[] ItemID = new int[listBox1.Items.Count];
|
|
int ii = 0;
|
|
foreach (object id in listBox1.Items) {
|
|
|
|
string[] Tovar = id.ToString().Split('|');
|
|
|
|
NpgsqlConnection npgsqlConnections = new NpgsqlConnection(connS);
|
|
npgsqlConnections.Open();
|
|
NpgsqlCommand commands = new NpgsqlCommand(@$"INSERT INTO public.""Sostav""( ""ID_Tovar"", ""Kolichestvo"") VALUES ({Tovar[0]}, {Tovar[1]}) RETURNING ""ID_Sostav"";", npgsqlConnections);
|
|
DataTable dataTable = new DataTable();
|
|
dataTable.Load(commands.ExecuteReader());
|
|
ItemID[ii] = int.Parse(dataTable.Rows[0].ItemArray[0].ToString());
|
|
ii = ii + 1;
|
|
|
|
npgsqlConnections.Close();
|
|
}
|
|
foreach (int jj in ItemID)
|
|
{
|
|
NpgsqlConnection npgsqlConnectionss = new NpgsqlConnection(connS);
|
|
npgsqlConnectionss.Open();
|
|
NpgsqlCommand commandss = new NpgsqlCommand(@$"INSERT INTO public.""ZakazSostav""(""ID_Sostav"", ""ID_Zakaz"") VALUES ( {jj}, {IDZAKAZ});", npgsqlConnectionss);
|
|
|
|
commandss.ExecuteReader();
|
|
}
|
|
|
|
}
|
|
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();*/
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|