using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class ujeszkoz1 : System.Web.UI.Page
{
    public int kat1ID = 0;
    public int kat2ID = 0;
    public int kat3ID = 0;
    public int kat4ID = 0;
    //protected int termek_ID;
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {

            dropDownListFeltoltes(1);
            dropDownListFeltoltes(2);
            dropDownListFeltoltes(3);
            dropDownListFeltoltes(4);
            if (Request.QueryString.Count > 0)
            {
                TextBox1.Text = Request.QueryString["cikkszam"].ToString();
            }
        }

    }
    public void dropDownListFeltoltes(int ddlSzam)
    {
        switch (ddlSzam)
        {
            case 1: DropDownList1.Items.Clear(); DropDownList1.Items.Add("Válassz...."); break;
            case 2: DropDownList2.Items.Clear(); DropDownList2.Items.Add("Válassz...."); break;
            case 3: DropDownList3.Items.Clear(); DropDownList3.Items.Add("Válassz...."); break;
            case 4: DropDownList4.Items.Clear(); DropDownList4.Items.Add("Válassz...."); break;
        }


        System.Collections.Generic.List<db.kategoriaElemek> katElemek = new System.Collections.Generic.List<db.kategoriaElemek>();
        db.adatbazisMuveletek.kategoriaLekerdezes(ddlSzam, out katElemek);
        for (int i = 0; i < katElemek.Count; i++)
        {
            switch (ddlSzam)
            {
                case 1: DropDownList1.Items.Add(katElemek[i].kategoriaElem); break;
                case 2: DropDownList2.Items.Add(katElemek[i].kategoriaElem); break;
                case 3: DropDownList3.Items.Add(katElemek[i].kategoriaElem); break;
                case 4: DropDownList4.Items.Add(katElemek[i].kategoriaElem); break;
            }
        }
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        TextBox10.Visible = true;
        TextBox10.Text = "";
        DropDownList1.Visible = false;
        Button7.Visible = true;
        Button3.Visible = false;


    }
    protected void TextBox10_TextChanged(object sender, EventArgs e)
    {

    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        TextBox11.Visible = true;
        TextBox11.Text = "";
        DropDownList2.Visible = false;
        Button8.Visible = true;
        Button4.Visible = false;

    }
    protected void Button5_Click(object sender, EventArgs e)
    {
        TextBox12.Visible = true;
        TextBox12.Text = "";
        DropDownList3.Visible = false;
        Button9.Visible = true;
        Button5.Visible = false;
    }
    protected void Button6_Click(object sender, EventArgs e)
    {
        TextBox13.Visible = true;
        TextBox13.Text = "";
        DropDownList4.Visible = false;
        Button10.Visible = true;
        Button6.Visible = false;
    }
    protected void TextBox13_TextChanged(object sender, EventArgs e)
    {

    }
    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Label11.Visible = false;
        Label12.Visible = false;
        Label15.Visible = false;
        Label16.Visible = false;
        Label17.Visible = false;

        int errorCount = 0;

        if (!kategoriaVizsgalat1()) errorCount++;
        if (!kategoriaVizsgalat2()) errorCount++;
        if (!kategoriaVizsgalat3()) errorCount++;
        if (!kategoriaVizsgalat4()) errorCount++;

        if (!cikkszamVizsgalat()) errorCount++;

        if (errorCount == 0)
        {
            if (TextBox10.Visible)
            {
                db.adatbazisMuveletek.katFelvitel(1, TextBox10.Text);
                db.adatbazisMuveletek.catIdLekerdez(1, TextBox10.Text, out kat1ID);
            }
            if (TextBox11.Visible)
            {
                db.adatbazisMuveletek.katFelvitel(2, TextBox11.Text);
                db.adatbazisMuveletek.catIdLekerdez(2, TextBox11.Text, out kat2ID);
            }

            if (TextBox12.Visible)
            {
                db.adatbazisMuveletek.katFelvitel(3, TextBox12.Text);
                db.adatbazisMuveletek.catIdLekerdez(3, TextBox12.Text, out kat3ID);
            }

            if (TextBox13.Visible)
            {
                db.adatbazisMuveletek.katFelvitel(4, TextBox13.Text);
                db.adatbazisMuveletek.catIdLekerdez(4, TextBox13.Text, out kat4ID);
            }

            if (!db.adatbazisMuveletek.ujCikkFelvitel(TextBox1.Text, TextBox3.Text, TextBox4.Text, FileUpload1.FileName, kat1ID, kat2ID, kat3ID, kat4ID))
                Label10.Text = "NEM JÓÓÓÓÓÓÓÓÓÓÓÓÓ";
        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        TextBox10.Visible = false;
        DropDownList1.Visible = true;
        Button7.Visible = false;
        Button3.Visible = true;

    }
    protected void Button7_Click(object sender, EventArgs e)
    {
        TextBox10.Visible = false;
        TextBox10.Text = "a";
        DropDownList1.Visible = true;
        Button7.Visible = false;
        Button3.Visible = true;

    }
    protected void Button8_Click(object sender, EventArgs e)
    {
        TextBox11.Visible = false;
        TextBox11.Text = "a";
        DropDownList2.Visible = true;
        Button8.Visible = false;
        Button4.Visible = true;

    }
    protected void Button9_Click(object sender, EventArgs e)
    {
        TextBox12.Visible = false;
        TextBox12.Text = "a";
        DropDownList3.Visible = true;
        Button9.Visible = false;
        Button5.Visible = true;
    }
    protected void Button10_Click(object sender, EventArgs e)
    {
        TextBox13.Visible = false;
        TextBox13.Text = "a";
        DropDownList4.Visible = true;
        Button10.Visible = false;
        Button6.Visible = true;

    }
    protected bool kategoriaVizsgalat1()
    {
        int errorCount = 0;

        switch (DropDownList1.Visible)
        {
            case true: db.adatbazisMuveletek.katNameToKatID(1, DropDownList1.SelectedValue, out kat1ID); break;
            case false: db.adatbazisMuveletek.catIdLekerdez(1, TextBox10.Text, out kat1ID);
                if (kat1ID != 0)
                {
                    Label11.Visible = true;
                    errorCount++;
                }
                break;

        }
        if (errorCount > 0) { return false; } else { return true; }

    }
    protected bool kategoriaVizsgalat2()
    {
        int errorCount = 0;
        switch (DropDownList2.Visible)
        {
            case true: db.adatbazisMuveletek.katNameToKatID(2, DropDownList2.SelectedValue, out kat2ID); break;
            case false: db.adatbazisMuveletek.catIdLekerdez(2, TextBox11.Text, out kat2ID);
                if (kat2ID != 0)
                {
                    Label12.Visible = true;
                    errorCount++;
                }
                break;
        }
        if (errorCount > 0) { return false; } else { return true; }

    }
    protected bool kategoriaVizsgalat3()
    {
        int errorCount = 0;
        switch (DropDownList3.Visible)
        {
            case true: db.adatbazisMuveletek.katNameToKatID(3, DropDownList3.SelectedValue, out kat3ID); break;
            case false: db.adatbazisMuveletek.catIdLekerdez(3, TextBox12.Text, out kat3ID);
                if (kat3ID != 0)
                {
                    Label15.Visible = true;
                    errorCount++;
                }
                break;
        }
        if (errorCount > 0) { return false; } else { return true; }
    }
    protected bool kategoriaVizsgalat4()
    {
        int errorCount = 0;
        switch (DropDownList4.Visible)
        {
            case true: db.adatbazisMuveletek.katNameToKatID(4, DropDownList4.SelectedValue, out kat4ID); break;
            case false: db.adatbazisMuveletek.catIdLekerdez(4, TextBox13.Text, out kat4ID);
                if (kat4ID != 0)
                {
                    Label16.Visible = true;
                    errorCount++;
                }
                break;
        }
        if (errorCount > 0) { return false; } else { return true; }
    }
    protected bool cikkszamVizsgalat()
    {
        int errorCount = 0;
        int Count = 0;
        db.adatbazisMuveletek.cikkszamLekerdezes(TextBox1.Text, out Count);
        if (Count > 0)
        {
            Label17.Visible = true;
            errorCount++;
        }
        if (errorCount > 0) { return false; } else { return true; }
    }
    protected void btnUjTermek_Click(object sender, EventArgs e)
    {
        Label7.Visible = true;
        Label1.Visible = true;
        Label3.Visible = true;
        Label4.Visible = true;
        Label5.Visible = true;
        Label8.Visible = true;
        Label9.Visible = true;
        Label10.Visible = true;
        TextBox1.Visible = true;
        TextBox3.Visible = true;
        TextBox4.Visible = true;
        DropDownList1.Visible = true;
        DropDownList2.Visible = true;
        DropDownList3.Visible = true;
        DropDownList4.Visible = true;
        btnUjTermek.Visible = false;
        Button3.Visible = true;
        Button4.Visible = true;
        Button5.Visible = true;
        Button6.Visible = true;
        Button1.Visible = true;
        Button2.Visible = true;
        btnModositMent.Visible = false;
        btnModositas.Visible = true;
        FileUpload1.Visible = true;

    }
    protected void btnModositas_Click(object sender, EventArgs e)
    {
        lblTermekModosit.Visible = true;
        txtTermekModosit.Visible = true;
        Label7.Visible = false;
        Label1.Visible = false;
        Label3.Visible = false;
        Label4.Visible = false;
        Label5.Visible = false;
        Label8.Visible = false;
        Label9.Visible = false;
        Label10.Visible = false;
        TextBox1.Visible = false;
        TextBox3.Visible = false;
        TextBox4.Visible = false;
        DropDownList1.Visible = false;
        DropDownList2.Visible = false;
        DropDownList3.Visible = false;
        DropDownList4.Visible = false;
        btnUjTermek.Visible = false;
        Button3.Visible = false;
        Button4.Visible = false;
        Button5.Visible = false;
        Button6.Visible = false;
        Button1.Visible = false;
        Button2.Visible = false;
        btnModositMent.Visible = false;
        btnModositas.Visible = false;
        FileUpload1.Visible = false;
        

    }
    protected void txtTermekModosit_TextChanged(object sender, EventArgs e)
    {

        //db.termekLista2 termekLista = new db.termekLista2();
        db.termekLista2 termekLista2 = new db.termekLista2();
        TextBox1.Text = txtTermekModosit.Text;
        db.adatbazisMuveletek.cikkszamTotermekLekerdezes(txtTermekModosit.Text.ToString(), out termekLista2);

        int kat1ID = termekLista2.kat1ID;
        int kat2ID = termekLista2.kat2ID;
        int kat3ID = termekLista2.kat3ID;
        int kat4ID = termekLista2.kat4ID;

        string kat1Nev;
        string kat2Nev;
        string kat3Nev;
        string kat4Nev;

        //termek_ID = termekLista2.termekID;

        db.adatbazisMuveletek.katIDToKatName(1, kat1ID, out kat1Nev);
        db.adatbazisMuveletek.katIDToKatName(2, kat2ID, out kat2Nev);
        db.adatbazisMuveletek.katIDToKatName(3, kat3ID, out kat3Nev);
        db.adatbazisMuveletek.katIDToKatName(4, kat4ID, out kat4Nev);

        txtTermekModosit.Visible = false;
        lblTermekModosit.Visible = false;
        TextBox3.Text = termekLista2.megnevezes;
        TextBox4.Text = termekLista2.termekleiras;
        DropDownList1.SelectedValue = kat1Nev;
        DropDownList2.SelectedValue = kat2Nev;
        DropDownList3.SelectedValue = kat3Nev;
        DropDownList4.SelectedValue = kat4Nev;

        Label7.Visible = true;
        Label1.Visible = true;
        Label3.Visible = true;
        Label4.Visible = true;
        Label5.Visible = true;
        Label8.Visible = true;
        Label9.Visible = true;
        Label10.Visible = true;
        TextBox1.Visible = true;
        TextBox3.Visible = true;
        TextBox4.Visible = true;
        DropDownList1.Visible = true;
        DropDownList2.Visible = true;
        DropDownList3.Visible = true;
        DropDownList4.Visible = true;
        btnUjTermek.Visible = true;
        btnModositas.Visible = false;
        Button3.Visible = true;
        Button4.Visible = true;
        Button5.Visible = true;
        Button6.Visible = true;
        Button1.Visible = false;
        Button2.Visible = false;
        btnModositMent.Visible = true;

    }
    protected void btnModositMent_Click(object sender, EventArgs e)
    {
        Label11.Visible = false;
        Label12.Visible = false;
        Label15.Visible = false;
        Label16.Visible = false;
        Label17.Visible = false;

        int errorCount = 0;

        if (!kategoriaVizsgalat1()) errorCount++;
        if (!kategoriaVizsgalat2()) errorCount++;
        if (!kategoriaVizsgalat3()) errorCount++;
        if (!kategoriaVizsgalat4()) errorCount++;

        //if (!cikkszamVizsgalat()) errorCount++;

        if (errorCount == 0)
        {
            if (TextBox10.Visible)
            {
                db.adatbazisMuveletek.katFelvitel(1, TextBox10.Text);
                db.adatbazisMuveletek.catIdLekerdez(1, TextBox10.Text, out kat1ID);
            }
            if (TextBox11.Visible)
            {
                db.adatbazisMuveletek.katFelvitel(2, TextBox11.Text);
                db.adatbazisMuveletek.catIdLekerdez(2, TextBox11.Text, out kat2ID);
            }

            if (TextBox12.Visible)
            {
                db.adatbazisMuveletek.katFelvitel(3, TextBox12.Text);
                db.adatbazisMuveletek.catIdLekerdez(3, TextBox12.Text, out kat3ID);
            }

            if (TextBox13.Visible)
            {
                db.adatbazisMuveletek.katFelvitel(4, TextBox13.Text);
                db.adatbazisMuveletek.catIdLekerdez(4, TextBox13.Text, out kat4ID);
            }
            db.termekLista2 termekLista2 = new db.termekLista2();
            db.adatbazisMuveletek.cikkszamTotermekLekerdezes(txtTermekModosit.Text.ToString(), out termekLista2);
            int termek_ID = termekLista2.termekID;
            if (!db.adatbazisMuveletek.termekUpdate(termek_ID, TextBox1.Text, TextBox3.Text, TextBox4.Text, FileUpload1.FileName, kat1ID, kat2ID, kat3ID, kat4ID))
                Label10.Text = "NEM JÓÓÓÓÓÓÓÓÓÓÓÓÓ";
        }
    }
}
