Exemplo n.º 1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //Validate Input
            if (string.IsNullOrEmpty(QuoteTextToInsert.Text.Trim()))
            {
                lblAddQuoteFeedback.Text = "Quote Text is required before you can save a quote.";
                return;
            }

            //Collect the Quote
            Quote newQuote = new Quote();
            newQuote.Text = QuoteTextToInsert.Text;
            newQuote.CategoriesAsString = CategoryToInsert.Text;
            newQuote.Author = AuthorToInsert.Text;

            //Add the quote to the collection
            QuoteListWrapper wrapper = new QuoteListWrapper();
            wrapper.InsertQuote(newQuote);

            //Tell the user that the update was successful.
            lblAddQuoteFeedback.Text = "Last Quote was successfully added.";

            //Clear the text controls for more quotes to be added
            QuoteTextToInsert.Text = string.Empty;
            CategoryToInsert.Text = string.Empty;
            AuthorToInsert.Text = string.Empty;
        }
Exemplo n.º 2
0
        protected void DeleteButtonInGrid_Click(object sender, EventArgs e)
        {
            Button deleteButton = (Button)sender;
            Trace.Write("About to delete: " + deleteButton.CommandName);

            if (deleteButton == null || string.IsNullOrEmpty(deleteButton.CommandName))
            {
                Response.Write("Unable to delete quote - please reload the page and try again.");
            }

            QuoteListWrapper wrapper = new QuoteListWrapper();
            wrapper.DeleteQuote(deleteButton.CommandName);

            //Refresh the list
            ListView1.DataBind();

            //Refresh the page
            InitializePage();
        }
Exemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            QuoteListWrapper wrapper;

            if (this.Attributes["UseGlobalQuoteList"] != null
                && this.Attributes["UseGlobalQuoteList"].Trim().ToLower() == "true")
            {
                //Do special logic to use the global quote list.
                string guidForGlobalList = ConfigurationManager.AppSettings["GlobalQuoteListId"];
                if (string.IsNullOrEmpty(guidForGlobalList))
                    throw new Exception("ERROR: We expect the following section in your config file: <appSettings><add key='GlobalQuoteListId' value='ed32da6e-da85-477e-9b21-ddf131a532e8'/></appSettings>");

                wrapper = new QuoteListWrapper(guidForGlobalList);
            }
            else
            {
                //This will create the QuoteList based on who is currently logged in right now.
                wrapper = new QuoteListWrapper();
            }

            Quote quote = wrapper.GetRandomQuote();

            if (quote == null)
            {
                lblQuote.Text = "This quote collection does not contain any quotes yet.";
                lblCategories.Text = string.Empty;
                lblAuthor.Text = string.Empty;
            }
            else
            {
                lblQuote.Text = quote.Text;
                lblCategories.Text = quote.CategoriesAsString;
                lblAuthor.Text = quote.Author;
            }

            //THIS DOES NOT WORK - Attempt to get some way to make the enter key page forward through quotes.
            //this.Page.Form.DefaultButton = FindControl("btnNext").UniqueID;
        }
        protected void AddCategoryButton_Click(object sender, EventArgs e)
        {
            ErrorMessages.InnerHtml = string.Empty;

            QuoteListWrapper wrapper = new QuoteListWrapper();
            Quote quote = (Quote)wrapper.GetQuoteById(GetQuoteId());

            if (quote.Categories.Contains(CategoryToAddText.Text))
            {
                ErrorMessages.InnerHtml = "<br>The category you are adding already exists in the list.";
                return;
            }

            //Update our data structure
            quote.Categories.Add(CategoryToAddText.Text);
            wrapper.UpdateQuote(quote);

            //Clear the textbox
            CategoryToAddText.Text = string.Empty;

            //Show the change to the user
            InitializeControl();
        }
        protected void RemoveButton_Click(object sender, EventArgs e)
        {
            Button clicked = (Button)sender;

            if (clicked == null)
                return;

            if (clicked.CommandName == null)
                return;

            QuoteListWrapper wrapper = new QuoteListWrapper();
            Quote quote = (Quote)wrapper.GetQuoteById(GetQuoteId());

            if (quote.Categories.Contains(clicked.CommandName))
            {
                quote.Categories.Remove(clicked.CommandName);
            }

            //update our data structure
            wrapper.UpdateQuote(quote);

            //Show the change to the user
            InitializeControl();
        }
        private void InitializeControl()
        {
            string QuoteId = GetQuoteId();

            QuoteListWrapper wrapper = new QuoteListWrapper();
            IQuote quote = wrapper.GetQuoteById(QuoteId);

            List<CategoryWrapper> catList = new List<CategoryWrapper>();
            foreach (string category in quote.Categories)
            {
                CategoryWrapper wrap = new CategoryWrapper();
                wrap.Text = category;
                catList.Add(wrap);
            }

            ListView1.DataSource = catList;
            ListView1.DataBind();
        }
Exemplo n.º 7
0
        private void InitializePage()
        {
            //See if there is a querystring value
            string searchText = string.Empty;
            if (Request.QueryString["s"] != null)
            {
                searchText = Request.QueryString["s"].Trim();

                //If this is a postback, we might be trying to change the searchText
                //so do not overwrite that value in the Textbox. Otherwise, viewstate
                //will automatically keep our previous value.
                if (!IsPostBack)
                {
                    txtSearch.Text = searchText;
                }
            }
            QuoteListWrapper wrapper = new QuoteListWrapper();
            IList<IQuote> quotes = wrapper.GetQuotes(searchText);
            RecordCount.Text = string.Format("There are {0} quotes.", quotes.Count);

            //Only display the quotes control if we have some quotes.
            bool displayQuotes = (quotes.Count > 0);
            ListView1.Visible = displayQuotes;
            txtSearch.Visible = displayQuotes;
            btnSearch.Visible = displayQuotes;
            DataPager1.Visible = displayQuotes;
        }