using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Wrox.ConnectionManagement
{
    public class TextBoxChanger : WebPart, IStringForCalendar
    {
        private TextBox myTextBox;
        private string _calendarString = String.Empty;

        [Personalizable()]
        public string CalendarString
        {
            get { return _calendarString; }
            set { _calendarString = value; }
        }

        [ConnectionProvider("Provider for String From TextBox", 
            "TextBoxStringProvider")]
        public IStringForCalendar TextBoxStringProvider()
        {
            return this;
        }

        protected override void CreateChildControls()
        {
            Controls.Clear();
            myTextBox = new TextBox();
            this.Controls.Add(myTextBox);
            Button myButton = new Button();
            myButton.Text = "Zmień pasek tytułowy kalendarza";
            myButton.Click += new EventHandler(this.myButton_Click);
            this.Controls.Add(myButton);
        }

        private void myButton_Click(object sender, EventArgs e)
        {
            if (myTextBox.Text != String.Empty)
            {
                CalendarString = myTextBox.Text;
                myTextBox.Text = String.Empty;
            }
        }
    }
}
