using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Швейная_фабрика
{
    public partial class FormZakazchik : Form
    {
        public FormZakazchik()
        {
            InitializeComponent();
        }
        SqlConnection Con = new SqlConnection("Data Source=213.155.192.79,3002;Initial Catalog=СlothesFactoryLG;Persist Security Info=True;User ID=u21lebed;Password=hgm8");
        void FillOrders()
        {
            DgvOrders.Rows.Clear();
            string txtQuery = $@"SELECT        Izdelie.name_izd as Izd, Users.Surname, Tkan.Title AS Cloth, Furnitura.namefur, Orders.CountFur, Orders.CountIzd
FROM            Tkan INNER JOIN
                         Orders ON Tkan.id_Tkan = Orders.id_tkan INNER JOIN
                         Furnitura ON Orders.id_fur = Furnitura.id_fur INNER JOIN
                         Izdelie ON Orders.id_izd = Izdelie.id_izd INNER JOIN
                         Users ON Orders.id_men = Users.id_User
where Users.Role = 2 and Orders.id_zak = {FormMain.IDUser}";
            Con.Open();
            SqlCommand query = new SqlCommand(txtQuery, Con);
            SqlDataReader res = query.ExecuteReader();
            int i = 0;
            while (res.Read())
            {
                DgvOrders.Rows.Add();
                DgvOrders.Rows[i].Cells[0].Value = res["Izd"].ToString();
                DgvOrders.Rows[i].Cells[1].Value = (res["Surname"].ToString());
                DgvOrders.Rows[i].Cells[2].Value = (res["Cloth"].ToString());
                DgvOrders.Rows[i].Cells[3].Value = (res["namefur"].ToString());
                DgvOrders.Rows[i].Cells[4].Value = (res["CountFur"].ToString());
                DgvOrders.Rows[i].Cells[5].Value = (res["CountIzd"].ToString());
                i++;
            }
            Con.Close();
        }

        private void FormZakazchik_Load(object sender, EventArgs e)
        {
            // TODO: данная строка кода позволяет загрузить данные в таблицу "сlothesFactoryLGDataSet.Users". При необходимости она может быть перемещена или удалена.
            this.usersTableAdapter.Fill(this.сlothesFactoryLGDataSet.Users);
            FillOrders();

        }

        private void BtnProfile_Click(object sender, EventArgs e)
        {
            FormProfil frm = new FormProfil();
            frm.BsUsers.Filter = BsUsers.Filter;
            frm.ShowDialog();
        }

        private void BtnLev_Click(object sender, EventArgs e)
        {
            FormLeven frm = new FormLeven();
            frm.ShowDialog();
        }

        private void BtnAddZakaz_Click(object sender, EventArgs e)
        {
            FormAddZak frm = new FormAddZak();
            frm.BsUsers.Filter = BsUsers.Filter;
            frm.ShowDialog();
            FillOrders();
        }
    }
}
