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;
using System.Xml;

namespace garment_factory
{
    public partial class fZakazchik : Form
    {
        public fZakazchik()
        {
            InitializeComponent();
        }
        void FillListZakaz()
        {
            SqlConnection con = new SqlConnection(Properties.Settings.Default.Fabrika2024ConnectionString);
            dgvZakaz.Rows.Clear();
            string Query = $@"SELECT  Izdelie.Name_izd, Tkani.Nazvanie, Furnitura.namefur, Furnitura.countfur, Orders.CountIzdel
FROM     Orders INNER JOIN
                  Furnitura ON Orders.id_furnitur = Furnitura.idfur INNER JOIN
                  Izdelie ON Orders.id_izdelie = Izdelie.id_izdelie INNER JOIN
                  Tkani ON Orders.id_tkani = Tkani.Id_Tkani INNER JOIN
                  Users ON Orders.id_zakaz = Users.id_User
where Users.Id_user = {LblIdUser.Text}";
            con.Open();
            SqlCommand cmd = new SqlCommand(Query, con);
            SqlDataReader Rez = cmd.ExecuteReader();
            while (Rez.Read())
            {
                dgvZakaz.Rows.Add(Rez["Name_izd"], Rez["Nazvanie"], Rez["namefur"], Rez["countfur"], Rez["CountIzdel"]);
            }
            con.Close();
        }
        private void fZakazchik_Load(object sender, EventArgs e)
        {
            // TODO: данная строка кода позволяет загрузить данные в таблицу "fabrika2024DataSet.Users". При необходимости она может быть перемещена или удалена.
            this.usersTableAdapter.Fill(this.fabrika2024DataSet.Users);
            FillListZakaz();
            string id = id_userTextBox.Text;
            SqlConnection con = new SqlConnection(Properties.Settings.Default.Fabrika2024ConnectionString);
            con.Open();
            string t1 = string.Format($@"select * from Users where id_user = {id}");
            SqlCommand query = new SqlCommand(t1, con);
            // выполнить запрос
            SqlDataReader rdr = query.ExecuteReader();
            while (rdr.Read())
            {
                FIO.Text = rdr["Surname"].ToString()+" "+ rdr["Name"].ToString()+" "+  rdr["Otch"].ToString();          
            }
            con.Close();
        }

        private void BtnProfile_Click(object sender, EventArgs e)
        {
            fProfil frm = new fProfil();
            frm.BsUsers.Filter = this.BsUsers.Filter;
            if (frm.ShowDialog() == DialogResult.OK)
            {
                this.usersTableAdapter.Fill(this.fabrika2024DataSet.Users);
            }
        }

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

        private void BtnAddZakaz_Click(object sender, EventArgs e)
        {
            fAddZakaz frm = new fAddZakaz();
            frm.IdZakazchik = LblIdUser.Text;
            frm.ShowDialog();

            FillListZakaz();
        }
    }
}
