Esempio n. 1
0
    public void dessert_Data_Bound(Object sender, DataListItemEventArgs e)
    {
        // Get Live Meal data
        DataRowView item1 = (DataRowView)e.Item.DataItem;

        object[] dessert_Data = item1.Row.ItemArray;

        // Get the current datalist entry.
        Accordion dessert_Accordion = (Accordion)e.Item.FindControl("dessertAccordion");

        //Find meal labels
        Label name_Label        = (Label)dessert_Accordion.FindControl("dessertNameLabel");
        Label chef_Label        = (Label)dessert_Accordion.FindControl("dessertChefNameLabel");
        Label price_Label       = (Label)dessert_Accordion.FindControl("dessertPriceLabel");
        Label location_Label    = (Label)dessert_Accordion.FindControl("dessertLocationLabel");
        Label time_Label        = (Label)dessert_Accordion.FindControl("dessertTimeLabel");
        Label date_Label        = (Label)dessert_Accordion.FindControl("dessertDateLabel");
        Label description_Label = (Label)dessert_Accordion.FindControl("dessertDescriptionLabel");
        Label spaces_Label      = (Label)dessert_Accordion.FindControl("dessertSpacesLabel");

        //Find dietary icons
        Image meat_Icon      = (Image)dessert_Accordion.FindControl("dessertMeatIcon");
        Image fish_Icon      = (Image)dessert_Accordion.FindControl("dessertFishIcon");
        Image shellfish_Icon = (Image)dessert_Accordion.FindControl("dessertShellfishIcon");
        Image wheat_Icon     = (Image)dessert_Accordion.FindControl("dessertWheatIcon");
        Image nut_Icon       = (Image)dessert_Accordion.FindControl("dessertNutIcon");
        Image dairy_Icon     = (Image)dessert_Accordion.FindControl("dessertDairyIcon");
        Image egg_Icon       = (Image)dessert_Accordion.FindControl("dessertEggIcon");

        //Store mealID
        int meal_ID = (int)dessert_Data[0];

        dessertMealIDField.Value = meal_ID.ToString();

        //Populate meal info
        name_Label.Text = (string)dessert_Data[1];
        chef_Label.Text = (string)dessert_Data[3];
        double price = Convert.ToDouble(dessert_Data[4]);

        price_Label.Text    = price.ToString("c");
        location_Label.Text = (string)dessert_Data[5];
        time_Label.Text     = (string)dessert_Data[6];
        date_Label.Text     = (string)dessert_Data[7];

        //Showing dietary
        if ((Boolean)dessert_Data[8])
        {
            meat_Icon.Visible = true; dessertDietaryPanel.Visible = true;
        }
        else
        {
            meat_Icon.Visible = false;
        }
        if ((Boolean)dessert_Data[9])
        {
            fish_Icon.Visible = true; dessertDietaryPanel.Visible = true;
        }
        else
        {
            fish_Icon.Visible = false;
        }
        if ((Boolean)dessert_Data[10])
        {
            shellfish_Icon.Visible = true; dessertDietaryPanel.Visible = true;
        }
        else
        {
            shellfish_Icon.Visible = false;
        }
        if ((Boolean)dessert_Data[11])
        {
            wheat_Icon.Visible = true; dessertDietaryPanel.Visible = true;
        }
        else
        {
            wheat_Icon.Visible = false;
        }
        if ((Boolean)dessert_Data[12])
        {
            nut_Icon.Visible = true; dessertDietaryPanel.Visible = true;
        }
        else
        {
            nut_Icon.Visible = false;
        }
        if ((Boolean)dessert_Data[13])
        {
            dairy_Icon.Visible = true; dessertDietaryPanel.Visible = true;
        }
        else
        {
            dairy_Icon.Visible = false;
        }
        if ((Boolean)dessert_Data[14])
        {
            egg_Icon.Visible = true; dessertDietaryPanel.Visible = true;
        }
        else
        {
            egg_Icon.Visible = false;
        }

        //Meal spaces
        total_Meal_Spaces = (int)dessert_Data[15];
        taken_Meal_Spaces = (int)dessert_Data[16];
        string meal_Spaces = taken_Meal_Spaces.ToString() + "/" + total_Meal_Spaces.ToString();

        spaces_Label.Text = meal_Spaces;

        //Add description
        description_Label.Text = (string)dessert_Data[17];

        //Check if logged in if not hide button, show text
        if (string.IsNullOrEmpty(User.Identity.GetUserId()))
        {
            dessert_Accordion.FindControl("dessertJoinButton").Visible       = false;
            dessert_Accordion.FindControl("dessertLeaveButton").Visible      = false;
            dessert_Accordion.FindControl("dessertManageButton").Visible     = false;
            dessert_Accordion.FindControl("dessertLoginToJoinLabel").Visible = true;
        }
        else
        {
            //Check if user has hosted meal
            if ((string)dessert_Data[2] == User.Identity.GetUserId())
            {
                dessert_Accordion.FindControl("dessertJoinButton").Visible       = false;
                dessert_Accordion.FindControl("dessertLeaveButton").Visible      = false;
                dessert_Accordion.FindControl("dessertManageButton").Visible     = true;
                dessert_Accordion.FindControl("dessertLoginToJoinLabel").Visible = false;
            }
            else
            {
                //Check if user has already joined meal
                if (meal_Guest_Check(meal_ID.ToString(), User.Identity.GetUserId()))
                {
                    dessert_Accordion.FindControl("dessertJoinButton").Visible       = false;
                    dessert_Accordion.FindControl("dessertLeaveButton").Visible      = true;
                    dessert_Accordion.FindControl("dessertManageButton").Visible     = false;
                    dessert_Accordion.FindControl("dessertLoginToJoinLabel").Visible = false;
                }
                else
                {
                    dessert_Accordion.FindControl("dessertJoinButton").Visible       = true;
                    dessert_Accordion.FindControl("dessertLeaveButton").Visible      = false;
                    dessert_Accordion.FindControl("dessertManageButton").Visible     = false;
                    dessert_Accordion.FindControl("dessertLoginToJoinLabel").Visible = false;
                }
            }
        }
    }