142 lines
6.7 KiB
C#
142 lines
6.7 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 Form1 : Form
|
|
{
|
|
static string connS = "Server=localhost;Port=5432;Database=newdemo26;Username=postgres;Password=Swa2sWA13;";
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
|
|
NpgsqlConnection npgsqlConnection = new NpgsqlConnection(connS);
|
|
npgsqlConnection.Open();
|
|
NpgsqlCommand command = new NpgsqlCommand(@$"SELECT (SELECT ""Imia"" FROM public.""Naimenov"" WHERE ""Naimenov"".""ID_Naimenov"" = ""Tovar"".""Naimenov_ID""), (SELECT ""Imia"" FROM public.""Tip"" WHERE ""Tip"".""ID_Tip"" = ""Tovar"".""Tip_ID""), ""Ed_izm"", ""Cena"", (SELECT ""Imia"" FROM public.""Postav"" WHERE ""Postav"".""ID_Postav"" = ""Tovar"".""Postav_ID""), (SELECT ""Imia"" FROM public.""Proizv"" WHERE ""Proizv"".""ID_Proizv"" = ""Proizv_ID""), ""Skidka"", ""Kolichestvo"", ""Opisanie"", ""Photo"", ""ID_Tovar"" FROM public.""Tovar"";", npgsqlConnection);
|
|
DataTable data = new DataTable();
|
|
data.Load(command.ExecuteReader());
|
|
|
|
for (int i = 0; i < data.Rows.Count; i++)
|
|
{
|
|
UCTovar uCTovar = new UCTovar(this);
|
|
uCTovar.textBox1.Text = data.Rows[i].ItemArray[0].ToString();
|
|
uCTovar.textBox1.Text = uCTovar.textBox1.Text + " | " + data.Rows[i].ItemArray[1].ToString();
|
|
|
|
uCTovar.textBox2.Text = data.Rows[i].ItemArray[8].ToString();
|
|
uCTovar.textBox3.Text = data.Rows[i].ItemArray[4].ToString();
|
|
uCTovar.textBox4.Text = data.Rows[i].ItemArray[5].ToString();
|
|
uCTovar.textBox5.Text = data.Rows[i].ItemArray[3].ToString();
|
|
uCTovar.textBox6.Text = data.Rows[i].ItemArray[2].ToString();
|
|
uCTovar.textBox7.Text = data.Rows[i].ItemArray[7].ToString();
|
|
|
|
uCTovar.Skidka.Text = data.Rows[i].ItemArray[6].ToString();
|
|
if (data.Rows[i].ItemArray[9].ToString() != "") uCTovar.Photo.Image = Image.FromFile(data.Rows[i].ItemArray[9].ToString());
|
|
else uCTovar.Photo.Image = Image.FromFile("picture.png");
|
|
uCTovar.Name = data.Rows[i].ItemArray[10].ToString();
|
|
flowLayoutPanel1.Controls.Add(uCTovar);
|
|
}
|
|
|
|
npgsqlConnection.Close();
|
|
|
|
}
|
|
|
|
private void textBox1_TextChanged(object sender, EventArgs e)
|
|
{
|
|
AllPoisk(comboBox2.SelectedIndex, comboBox1.SelectedIndex);
|
|
}
|
|
|
|
public void AllPoisk(int sort, int filtr)
|
|
{
|
|
flowLayoutPanel1.Controls.Clear();
|
|
|
|
NpgsqlConnection npgsqlConnection = new NpgsqlConnection(connS);
|
|
npgsqlConnection.Open();
|
|
string dob = "";
|
|
if(sort == 0)
|
|
{
|
|
dob = $@"ORDER BY ""Skidka"" ASC";
|
|
}
|
|
else if (sort == 1)
|
|
{
|
|
dob = $@"ORDER BY ""Skidka"" DESC";
|
|
}
|
|
|
|
string dob2 = "";
|
|
if(filtr == 1)
|
|
{
|
|
dob2 = $@" AND (SELECT ""Imia"" FROM public.""Postav"" WHERE ""Postav"".""ID_Postav"" = ""Tovar"".""Postav_ID"") = 'Kari'";
|
|
|
|
}
|
|
else if (filtr == 2)
|
|
{
|
|
dob2 = $@" AND (SELECT ""Imia"" FROM public.""Postav"" WHERE ""Postav"".""ID_Postav"" = ""Tovar"".""Postav_ID"") = 'Обувь для вас'";
|
|
}
|
|
|
|
NpgsqlCommand command = new NpgsqlCommand(@$"SELECT (SELECT ""Imia"" FROM public.""Naimenov"" WHERE ""Naimenov"".""ID_Naimenov"" = ""Tovar"".""Naimenov_ID""), (SELECT ""Imia"" FROM public.""Tip"" WHERE ""Tip"".""ID_Tip"" = ""Tovar"".""Tip_ID""), ""Ed_izm"", ""Cena"", (SELECT ""Imia"" FROM public.""Postav"" WHERE ""Postav"".""ID_Postav"" = ""Tovar"".""Postav_ID""), (SELECT ""Imia"" FROM public.""Proizv"" WHERE ""Proizv"".""ID_Proizv"" = ""Proizv_ID""), ""Skidka"", ""Kolichestvo"", ""Opisanie"", ""Photo"", ""ID_Tovar"" FROM public.""Tovar"" WHERE (SELECT ""Imia"" FROM public.""Naimenov"" WHERE ""Naimenov"".""ID_Naimenov"" = ""Tovar"".""Naimenov_ID"") || (SELECT ""Imia"" FROM public.""Tip"" WHERE ""Tip"".""ID_Tip"" = ""Tovar"".""Tip_ID"") || ""Ed_izm"" || ""Cena"" || (SELECT ""Imia"" FROM public.""Postav"" WHERE ""Postav"".""ID_Postav"" = ""Tovar"".""Postav_ID"") || (SELECT ""Imia"" FROM public.""Proizv"" WHERE ""Proizv"".""ID_Proizv"" = ""Proizv_ID"") || ""Skidka"" ||""Kolichestvo"" || ""Opisanie"" || ""Photo"" ILIKE '%{textBox1.Text}%' " + dob2 + dob, npgsqlConnection);
|
|
DataTable data = new DataTable();
|
|
data.Load(command.ExecuteReader());
|
|
|
|
for (int i = 0; i < data.Rows.Count; i++)
|
|
{
|
|
UCTovar uCTovar = new UCTovar(this);
|
|
uCTovar.textBox1.Text = data.Rows[i].ItemArray[0].ToString();
|
|
uCTovar.textBox1.Text = uCTovar.textBox1.Text + " | " + data.Rows[i].ItemArray[1].ToString();
|
|
|
|
uCTovar.textBox2.Text = data.Rows[i].ItemArray[8].ToString();
|
|
uCTovar.textBox3.Text = data.Rows[i].ItemArray[4].ToString();
|
|
uCTovar.textBox4.Text = data.Rows[i].ItemArray[5].ToString();
|
|
uCTovar.textBox5.Text = data.Rows[i].ItemArray[3].ToString();
|
|
uCTovar.textBox6.Text = data.Rows[i].ItemArray[2].ToString();
|
|
uCTovar.textBox7.Text = data.Rows[i].ItemArray[7].ToString();
|
|
|
|
uCTovar.Skidka.Text = data.Rows[i].ItemArray[6].ToString();
|
|
if (data.Rows[i].ItemArray[9].ToString() != "") uCTovar.Photo.Image = Image.FromFile(data.Rows[i].ItemArray[9].ToString());
|
|
else uCTovar.Photo.Image = Image.FromFile("picture.png");
|
|
uCTovar.Name = data.Rows[i].ItemArray[10].ToString();
|
|
flowLayoutPanel1.Controls.Add(uCTovar);
|
|
}
|
|
|
|
npgsqlConnection.Close();
|
|
}
|
|
|
|
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
AllPoisk(comboBox2.SelectedIndex, comboBox1.SelectedIndex);
|
|
|
|
|
|
|
|
}
|
|
|
|
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
AllPoisk(comboBox2.SelectedIndex, comboBox1.SelectedIndex);
|
|
|
|
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
this.Hide();
|
|
Form2 form2 = new Form2(0);
|
|
form2.ShowDialog();
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
this.Hide();
|
|
Form3 form = new Form3();
|
|
form.ShowDialog();
|
|
}
|
|
}
|
|
}
|