Esempio n. 1
0
    //metoda updajtująca tabelę User_Sport
    protected void Update_User_Sport_Table(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(2000);
        string        userid = Session["userid"].ToString();
        int           selectedSportsNumber = 0;
        List <string> sporty          = Usr.GetSporty(userid);
        CheckBoxList  checkedListBox1 = (CheckBoxList)pnlCustomers.FindControl("cblCustomerList");

        foreach (ListItem li in checkedListBox1.Items)
        {
            if (li.Selected && !sporty.Contains(li.Text))
            {
                try
                {
                    Usr.ExecuteCommandInsert(li.Value, userid);
                    selectedSportsNumber++;
                }
                catch (Exception ex)
                {
                    HttpContext.Current.Trace.Write(ex.Message);
                }
            }
            else if (!li.Selected && sporty.Contains(li.Text))
            {
                try
                {
                    Usr.ExecuteCommandDelete(li.Value, userid);
                }
                catch (Exception ex)
                {
                    HttpContext.Current.Trace.Write(ex.Message);
                }
            }
            else if (li.Selected && sporty.Contains(li.Text))
            {
                selectedSportsNumber++;
            }
        }

        if (selectedSportsNumber == 1)
        {
            divDDL.InnerText = "1 element";
        }
        else if (selectedSportsNumber < 5 && selectedSportsNumber > 0)
        {
            divDDL.InnerText = selectedSportsNumber + " elementy";
        }
        else
        {
            divDDL.InnerText = selectedSportsNumber + " elementów";
        }
    }