protected void EditOkButton_Clicked(object sender, EventArgs e)
    {
        if (SelectedView == ViewMode.LinkSuggestion)
        {
            int linkSuggestionRef;
            if (this.ViewState["EditLinkSuggestionRef"] is int)
            {
                linkSuggestionRef = (int)this.ViewState["EditLinkSuggestionRef"];
                LinkSuggestion linkSuggestion = LinkSuggestion.GetOne(linkSuggestionRef);
                linkSuggestion.Description = LinkSuggestionDescriptionTextBox.Text;
                linkSuggestion.LinkUrl     = LinkSuggestionUrlTextBox.Text;
                linkSuggestion.CategoryRef = int.Parse(LinkSuggestionCategoryDropdownList.SelectedValue);
                linkSuggestion.Save();

                this.ViewState.Remove("EditLinkSuggestionRef");
            }
        }
        else if (SelectedView == ViewMode.LinkAdministration)
        {
            int linkRef;
            if (this.ViewState["EditLinkRef"] is int)
            {
                linkRef = (int)this.ViewState["EditLinkRef"];
                DateTime linkDate;
                DateTime linkTime;
                int      categoryRef, clicks;
                int?     userRef = null;
                double   rating;

                try
                {
                    linkDate = DateHandler.ParseDateString(LinkDateTextBox.Text);
                    linkTime = DateHandler.ParseTimeString(LinkTimeTextBox.Text);
                    linkDate = linkDate.Add(linkTime.TimeOfDay);

                    categoryRef = int.Parse(LinkCategoryDropdownList.SelectedValue);
                    clicks      = int.Parse(LinkClicksTextBox.Text);
                    rating      = double.Parse(LinkRatingTextBox.Text);
                    userRef     = int.Parse(LinkUserDropDownList.SelectedValue);
                    if (userRef == 0)
                    {
                        userRef = null;
                    }
                }
                catch { return; }

                Link link;
                if (linkRef > 0)
                {
                    link = Link.GetOne(linkRef);
                }
                else
                {
                    link = new Link();
                }
                if (link == null)
                {
                    return;
                }

                link.CategoryRef = categoryRef;
                link.Clicks      = clicks;
                link.LinkDate    = linkDate;
                link.LinkName    = LinkNameTextBox.Text;
                link.LinkUrl     = LinkUrlTextBox.Text;
                link.Rating      = rating;
                link.UserRef     = userRef;

                link.Save();

                this.ViewState.Remove("EditLinkRef");
            }
        }
        EditLinkSuggestionPanel.Visible = false;
        EditLinkPanel.Visible           = false;
        base.HideModalBackground();
    }
    protected void EditButton_Clicked(object sender, EventArgs e)
    {
        CuplexLib.User user = Session["User"] as CuplexLib.User;
        if (SelectedView == ViewMode.LinkSuggestion)
        {
            List <int> linkSuggestionRefList = GetPostCollection("SuggestionCheckBox");
            if (linkSuggestionRefList.Count > 0)
            {
                LinkSuggestion linkSuggestion = LinkSuggestion.GetOne(linkSuggestionRefList[0]);
                if (linkSuggestion == null)
                {
                    return;
                }

                LinkSuggestionDescriptionTextBox.Text = linkSuggestion.Description;
                LinkSuggestionUrlTextBox.Text         = linkSuggestion.LinkUrl;

                LinkSuggestionCategoryDropdownList.DataValueField = "CategoryRef";
                LinkSuggestionCategoryDropdownList.DataTextField  = "CategoryName";
                LinkSuggestionCategoryDropdownList.DataSource     = Category.GetCategoryList();
                LinkSuggestionCategoryDropdownList.DataBind();

                try { LinkSuggestionCategoryDropdownList.SelectedValue = linkSuggestion.CategoryRef.ToString(); }
                catch { }

                this.ViewState["EditLinkSuggestionRef"] = linkSuggestion.LinkSuggestionRef;
                EditLinkSuggestionPanel.Visible         = true;
                base.ShowModalBackground();
            }
        }
        else if (SelectedView == ViewMode.LinkAdministration)
        {
            List <int> selectedLinkRefRefList = GetPostCollection("LinkSelectionCheckBox");
            if (selectedLinkRefRefList.Count > 0)
            {
                Link link = Link.GetOne(selectedLinkRefRefList[0]);
                if (link == null)
                {
                    return;
                }

                LinkDateTextBox.Text = DateHandler.ToDateString(link.LinkDate);
                LinkTimeTextBox.Text = DateHandler.ToTimeString(link.LinkDate);
                LinkNameTextBox.Text = link.LinkName;

                LinkCategoryDropdownList.DataValueField = "CategoryRef";
                LinkCategoryDropdownList.DataTextField  = "CategoryName";
                LinkCategoryDropdownList.DataSource     = Category.GetCategoryList();
                LinkCategoryDropdownList.DataBind();

                try { LinkCategoryDropdownList.SelectedValue = link.CategoryRef.ToString(); }
                catch { }

                LinkUserDropDownList.Items.Clear();
                LinkUserDropDownList.Items.Add(new ListItem("null", "0"));

                if (link.UserRef != user.UserRef)
                {
                    LinkUserDropDownList.Items.Add(new ListItem(user.UserName, user.UserRef.ToString()));
                }

                if (link.UserRef != null)
                {
                    LinkUserDropDownList.Items.Add(new ListItem(link.UserName, link.UserRef.Value.ToString()));
                    LinkUserDropDownList.SelectedValue = link.UserRef.Value.ToString();
                }

                LinkUrlTextBox.Text    = link.LinkUrl;
                LinkClicksTextBox.Text = link.Clicks.ToString();
                LinkRatingTextBox.Text = Math.Round(link.Rating, 2).ToString();

                this.ViewState["EditLinkRef"] = link.LinkRef;
                EditLinkPanel.Visible         = true;
                base.ShowModalBackground();
            }
        }
    }