Пример #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            FoundersTableAdapter foundersAdpt = new FoundersTableAdapter();
            this.ddFounders.AppendDataBoundItems = true;
            this.ddFounders.Items.Add("");
            this.ddFounders.DataSource     = foundersAdpt.GetData().OrderBy(n => n.FirstName);
            this.ddFounders.DataTextField  = "FullName";
            this.ddFounders.DataValueField = "FounderID";
            this.ddFounders.DataBind();

            try
            {
                if (Request["Founder"] != null)
                {
                    this.ddFounders.Items.FindByValue(Request["Founder"]).Selected = true;
                }
            }
            catch
            {
                //do nothing
            }
        }
    }
    protected void btnAddFounder_Click(object sender, EventArgs e)
    {
        int id = 0;

        try
        {
            FoundersTableAdapter foundersAdpt = new FoundersTableAdapter();

            string firstName, lastName, middleName, suffix;
            firstName  = txtFirstName.Text.Trim();
            middleName = txtMiddleName.Text.Trim() == "" ? null : txtMiddleName.Text.Trim();
            lastName   = txtLastName.Text.Trim();
            suffix     = txtSuffix.Text.Trim() == "" ? null : txtSuffix.Text.Trim();

            //query the addition against the database and confirm if the
            if (foundersAdpt.GetData().Count(
                    row =>
                    row.FirstName == firstName &&
                    row.LastName == lastName &&
                    middleName == (row.IsMiddleNameNull() ? null : row.MiddleName) &&
                    suffix == (row.IsSuffixNull() ? null : row.Suffix)) != 0)
            {
                throw new ApplicationException("The Founder that you attempted to enter already exists.");
            }

            //insert the new record
            foundersAdpt.InsertQuick(firstName, middleName, lastName, suffix);

            //get the new identity
            id = (int)foundersAdpt.GetIdentity();

            //kick the user to the add quote page
            Response.Redirect("add-quote.aspx?Founder=" + id.ToString());
        }
        catch (Exception ex)
        {
            this.ShowError(ex);
            txtFirstName.Text  = "";
            txtLastName.Text   = "";
            txtMiddleName.Text = "";
            txtSuffix.Text     = "";
        }
    }
Пример #3
0
    private void LoadSingleQuote(int quoteId)
    {
        CoreDataObjects.QuotesViewRow r;

        if (quoteId == 0)
        {
            //load the quote of the day
            r = (CoreDataObjects.QuotesViewRow)quotesAdpt.GetQuoteOfTheDay().Rows[0];
        }
        else
        {
            //get quote that is requested
            r = (CoreDataObjects.QuotesViewRow)quotesAdpt.GetByQuoteID(quoteId).Rows[0];
        }

        //setup page meta data title
        Page.Title = string.Format("{0} Quote #{1}", r.FullName, r.QuoteID);

        //change meta title on the quote of the day request
        if (_qotd)
        {
            Page.AddMetaInfo(OpenGraphMetaTags.Title, string.Format("Quote of the Day: {0} Quote #{1}", r.FullName, r.QuoteID));
        }
        else
        {
            Page.AddMetaInfo(OpenGraphMetaTags.Title, string.Format("{0} Quote #{1}", r.FullName, r.QuoteID));
        }

        Page.AddMetaInfo(OpenGraphMetaTags.Type, "article");
        Page.AddMetaInfo(OpenGraphMetaTags.Site_Name, "WhatWouldTheFoundersDo.org");
        Page.AddMetaInfo(OpenGraphMetaTags.URL, string.Format("http://www.whatwouldthefoundersdo.org/showquote.aspx?q={0}", r.QuoteID));
        Page.AddMetaInfo(OpenGraphMetaTags.Description, string.Format("{0}", r.QuoteText));

        LoadFounderData(r.FounderID);

        try
        {
            if (Request.QueryString["Edit"] != null)
            {
                if (Authenticator.GetUser().Role == ContributorRoles.Admin)
                {
                    if (!IsPostBack)
                    {
                        FoundersTableAdapter foundersAdpt = new FoundersTableAdapter();
                        this.ddFounders.DataSource     = foundersAdpt.GetData().OrderBy(n => n.FirstName);
                        this.ddFounders.DataTextField  = "FullName";
                        this.ddFounders.DataValueField = "FounderID";
                        this.ddFounders.DataBind();
                    }


                    //show the quote in a text box
                    QuoteText.Text     = r.QuoteText;
                    QuoteText.Width    = 580;
                    QuoteText.Rows     = (r.QuoteText.Length / 118) + 1;
                    QuoteText.CssClass = "transparent";
                    QuoteText.ToolTip  = "Click to modify.";
                    QuoteText.Attributes.Add("onclick", "this.className = 'selected';");
                    QuoteText.Attributes.Add("onblur", "this.className = 'transparent';");

                    ddFounders.ClearSelection();
                    //ddFounders.SelectedValue = r.FounderID.ToString();
                    ddFounders.Items.FindByValue(r.FounderID.ToString()).Attributes.Add("selected", "true");

                    PanelAdmin.Visible = true;
                    QuoteId.Value      = r.QuoteID.ToString();
                }
            }
            else
            {
                QuoteHelper.LoadQuote(PanelQuote, "", r.QuoteText, 0, r.ReferenceInfo, r.Keywords, false);
            }
        }
        catch
        {
            QuoteHelper.LoadQuote(PanelQuote, "", r.QuoteText, 0, r.ReferenceInfo, r.Keywords, false);
        }
    }