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 szemelyilap : System.Web.UI.Page
{
    protected int cegID = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.User.Identity.IsAuthenticated)
        {
            Response.Redirect("kezdolap.aspx");
        }

            System.Collections.Generic.List<db.termekLista> termekLista = new System.Collections.Generic.List<db.termekLista>();
            string UserName = Page.User.Identity.Name;
            db.adatbazisMuveletek.UserNameToCegID(UserName, out cegID);
            kontaktListaz();
            btnUjkontakt.Attributes.Add("onclick", "return false");
            btnUjkontakt.OnClientClick = "window.open('ujkontakt.aspx?ujkontakt','orderWindow" + DateTime.Now.Millisecond.ToString() + "','location=0,status=0,scrollbars=1,width=600,height=350');";
            
    }

  

    protected void kontaktListaz()
    {
        div1.Controls.Clear();
        System.Collections.Generic.List<db.kontakt> kontaktLista = new System.Collections.Generic.List<db.kontakt>();
        db.adatbazisMuveletek.kontaktLekerdez(cegID, out kontaktLista);
        string beosztMegnev;
       

        for (int i = 0; i < kontaktLista.Count; i++)
        {
            db.adatbazisMuveletek.beosztNevToIdLekerdez(kontaktLista[i].beosztasID, out beosztMegnev);
            Label nev = new Label();
            nev.Text = kontaktLista[i].nev;
            nev.Font.Bold = true;
            nev.ID = "lblNev"+i.ToString();

            Label beosztas = new Label();
            beosztas.Text = beosztMegnev;
            beosztas.Font.Bold = true;
            beosztas.ID = "lblBeosztas"+i.ToString();

            Label email = new Label();
            email.Text = kontaktLista[i].email;
            email.Font.Bold = true;
            email.ID = "lblMail"+i.ToString();

            Label tel = new Label();
            tel.Text = kontaktLista[i].telefon;
            tel.Font.Bold = true;
            tel.ID = "lblTel" + i.ToString();

            ImageButton imgBtnModosit = new ImageButton();
            imgBtnModosit.ID = "imgModosit_" + kontaktLista[i].kontaktID.ToString();
            imgBtnModosit.ImageUrl = "~/img/modosit.gif";
            imgBtnModosit.Click += new ImageClickEventHandler(imgBtnModosit_Click);

            ImageButton imgBtnTorol = new ImageButton();
            imgBtnTorol.ID = kontaktLista[i].kontaktID.ToString();
            imgBtnTorol.ImageUrl = "~/img/torol.gif";
            imgBtnTorol.Click += new ImageClickEventHandler(imgBtnTorol_Click);

            Panel pnl = new Panel();
            pnl.ID = "panel0" + i.ToString();
            pnl.BackColor = System.Drawing.Color.Lavender;
            Panel panelh = new Panel();
            panelh.ID = "panelh" + i.ToString();

            Table table = new Table();
            table.Width = System.Web.UI.WebControls.Unit.Pixel(820);
            table.BorderStyle = BorderStyle.None;
            TableRow tRow = new TableRow();
            TableCell tCell1 = new TableCell();
            TableCell tCell2 = new TableCell();
            TableCell tCell3 = new TableCell();
            TableCell tCell4 = new TableCell();
            TableCell tCell5 = new TableCell();
            TableCell tCell6 = new TableCell();

            tCell1.Width = System.Web.UI.WebControls.Unit.Pixel(230);
            tCell2.Width = System.Web.UI.WebControls.Unit.Pixel(155);
            tCell3.Width = System.Web.UI.WebControls.Unit.Pixel(155);
            tCell4.Width = System.Web.UI.WebControls.Unit.Pixel(125);
            tCell5.Width = System.Web.UI.WebControls.Unit.Pixel(70);
            tCell5.Width = System.Web.UI.WebControls.Unit.Pixel(70);

            tCell1.Controls.Add(nev);
            tRow.Controls.Add(tCell1);
            tCell2.Controls.Add(beosztas);
            tRow.Controls.Add(tCell2);
            tCell3.Controls.Add(email);
            tRow.Controls.Add(tCell3);
            tCell4.Controls.Add(tel);
            tRow.Controls.Add(tCell4);
            tCell5.Controls.Add(imgBtnModosit);
            tRow.Controls.Add(tCell5);
            tCell6.Controls.Add(imgBtnTorol);
            tRow.Controls.Add(tCell6);
            table.Controls.Add(tRow);
            pnl.Controls.Add(table);
            div1.Controls.Add(pnl);
                      
        }
    }
    protected void btnUjkontakt_Click(object sender, EventArgs e)
    {
        
    }

    protected void imgBtnModosit_Click(object sender, EventArgs e)
    {
        ImageButton imgBtnModosit = (ImageButton)(sender);
        
        string[] kontakID = imgBtnModosit.ID.ToString().Split(new Char[] { '_' });
        Response.Redirect("kontaktModosit.aspx?kontaktmodosit="+kontakID[1]);
        
    }

    protected void imgBtnTorol_Click(object sender, EventArgs e)
    {
        ImageButton imgbtn = (ImageButton)(sender);
        db.adatbazisMuveletek.kontaktDelete(Convert.ToInt32(imgbtn.ID));
        kontaktListaz();
       
    }
}
