// The Page_Load event handler on this User Control is used to
        // obtain a DataReader of banner information from the Banners
        // table, and then databind the results to a templated DataList
        // server control.  It uses the DotNetNuke.BannerDB()
        // data component to encapsulate all data functionality.
        protected void Page_Load( Object sender, EventArgs e )
        {
            try
            {
                if( ! Page.IsPostBack )
                {
                    // Obtain banner information from the Banners table and bind to the list control
                    BannerTypeController objBannerTypes = new BannerTypeController();

                    cboType.DataSource = objBannerTypes.GetBannerTypes();
                    cboType.DataBind();
                    cboType.Items.Insert( 0, new ListItem( Localization.GetString( "AllTypes", LocalResourceFile ), "-1" ) );

                    if( ModuleId > 0 )
                    {
                        // Get settings from the database
                        Hashtable settings = PortalSettings.GetModuleSettings( ModuleId );

                        if( optSource.Items.FindByValue( Convert.ToString( settings["bannersource"] ) ) != null )
                        {
                            optSource.Items.FindByValue( Convert.ToString( settings["bannersource"] ) ).Selected = true;
                        }
                        else
                        {
                            optSource.Items.FindByValue( "L" ).Selected = true;
                        }
                        if( cboType.Items.FindByValue( Convert.ToString( settings["bannertype"] ) ) != null )
                        {
                            cboType.Items.FindByValue( Convert.ToString( settings["bannertype"] ) ).Selected = true;
                        }
                        DNNTxtBannerGroup.Text = Convert.ToString(Settings["bannergroup"]);
                        if( optOrientation.Items.FindByValue( Convert.ToString( settings["orientation"] ) ) != null )
                        {
                            optOrientation.Items.FindByValue( Convert.ToString( settings["orientation"] ) ).Selected = true;
                        }
                        else
                        {
                            optOrientation.Items.FindByValue( "V" ).Selected = true;
                        }
                        if( Convert.ToString( settings["bannercount"] ) != "" )
                        {
                            txtCount.Text = Convert.ToString( settings["bannercount"] );
                        }
                        else
                        {
                            txtCount.Text = "1";
                        }
                        if( Convert.ToString( settings["border"] ) != "" )
                        {
                            txtBorder.Text = Convert.ToString( settings["border"] );
                        }
                        else
                        {
                            txtBorder.Text = "0";
                        }
                        if( Convert.ToString( settings["padding"] ) != "" )
                        {
                            txtPadding.Text = Convert.ToString( settings["padding"] );
                        }
                        else
                        {
                            txtPadding.Text = "4";
                        }
                        txtBorderColor.Text = Convert.ToString( settings["bordercolor"] );
                        txtRowHeight.Text = Convert.ToString( settings["rowheight"] );
                        txtColWidth.Text = Convert.ToString( settings["colwidth"] );
                    }
                }
            }
            catch( Exception exc ) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException( this, exc );
            }
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Page_Load runs when the control is loaded
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// 	[cnurse]	9/21/2004	Updated to reflect design changes for Help, 508 support
        ///                       and localisation
        /// </history>
        /// -----------------------------------------------------------------------------
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            cmdCancel.Click += OnCancelClick;
            cmdCopy.Click += OnCopyClick;
            cmdDelete.Click += OnDeleteClick;
            cmdEmail.Click += OnEmailClick;
            cmdUpdate.Click += OnUpdateClick;
            DNNTxtBannerGroup.PopulateOnDemand += PopulateBannersOnDemand;

            try
            {
                if ((Request.QueryString["VendorId"] != null))
                {
                    VendorId = Int32.Parse(Request.QueryString["VendorId"]);
                }
                if ((Request.QueryString["BannerId"] != null))
                {
                    BannerId = Int32.Parse(Request.QueryString["BannerId"]);
                }

                //this needs to execute always to the client script code is registred in InvokePopupCal
                cmdStartCalendar.NavigateUrl = Calendar.InvokePopupCal(txtStartDate);
                cmdEndCalendar.NavigateUrl = Calendar.InvokePopupCal(txtEndDate);

                if (Page.IsPostBack == false)
                {
                    ctlImage.FileFilter = Globals.glbImageFileTypes;
                    ClientAPI.AddButtonConfirm(cmdDelete, Localization.GetString("DeleteItem"));

                    var objBannerTypes = new BannerTypeController();
                    //Get the banner types from the database
                    cboBannerType.DataSource = objBannerTypes.GetBannerTypes();
                    cboBannerType.DataBind();

                    var objBanners = new BannerController();
                    if (BannerId != Null.NullInteger)
                    {
                        //Obtain a single row of banner information
                        BannerInfo objBanner = objBanners.GetBanner(BannerId);
                        if (objBanner != null)
                        {
                            txtBannerName.Text = objBanner.BannerName;
                            cboBannerType.Items.FindByValue(objBanner.BannerTypeId.ToString()).Selected = true;
                            DNNTxtBannerGroup.Text = objBanner.GroupName;
                            ctlImage.Url = objBanner.ImageFile;
                            if (objBanner.Width != 0)
                            {
                                txtWidth.Text = objBanner.Width.ToString();
                            }
                            if (objBanner.Height != 0)
                            {
                                txtHeight.Text = objBanner.Height.ToString();
                            }
                            txtDescription.Text = objBanner.Description;
                            if (!String.IsNullOrEmpty(objBanner.URL))
                            {
                                ctlURL.Url = objBanner.URL;
                            }
                            txtImpressions.Text = objBanner.Impressions.ToString();
                            txtCPM.Text = objBanner.CPM.ToString();
                            if (!Null.IsNull(objBanner.StartDate))
                            {
                                txtStartDate.Text = objBanner.StartDate.ToShortDateString();
                            }
                            if (!Null.IsNull(objBanner.EndDate))
                            {
                                txtEndDate.Text = objBanner.EndDate.ToShortDateString();
                            }
                            optCriteria.Items.FindByValue(objBanner.Criteria.ToString()).Selected = true;

                            ctlAudit.CreatedByUser = objBanner.CreatedByUser;
                            ctlAudit.CreatedDate = objBanner.CreatedDate.ToString();

                            var arrBanners = new ArrayList();

                            arrBanners.Add(objBanner);
                            bannersRow.Visible = true;
                            lstBanners.DataSource = arrBanners;
                            lstBanners.DataBind();
                        }
                        else //security violation attempt to access item not related to this Module
                        {
                            Response.Redirect(EditUrl("VendorId", VendorId.ToString()), true);
                        }
                    }
                    else
                    {
                        txtImpressions.Text = "0";
                        txtCPM.Text = "0";
                        optCriteria.Items.FindByValue("1").Selected = true;
                        cmdDelete.Visible = false;
                        cmdCopy.Visible = false;
                        cmdEmail.Visible = false;
                        ctlAudit.Visible = false;
                    }
                }
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
        /// <summary>
		/// The Page_Load event handler on this User Control is used to
        /// obtain a DataReader of banner information from the Banners
        /// table, and then databind the results to a templated DataList
        /// server control.  It uses the DotNetNuke.BannerDB()
        /// data component to encapsulate all data functionality.
		/// </summary>
		protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            cmdUpdate.Click += cmdUpdate_Click;
            cmdCancel.Click += cmdCancel_Click;
            DNNTxtBannerGroup.PopulateOnDemand += DNNTxtBannerGroup_PopulateOnDemand;

            try
            {
                if (!Page.IsPostBack)
                {
					//Obtain banner information from the Banners table and bind to the list control
                    var objBannerTypes = new BannerTypeController();

                    cboType.DataSource = objBannerTypes.GetBannerTypes();
                    cboType.DataBind();
                    cboType.Items.Insert(0, new ListItem(Localization.GetString("AllTypes", LocalResourceFile), "-1"));

                    if (ModuleId > 0)
                    {
                        //Get settings from the database
                        Hashtable settings = new ModuleController().GetModuleSettings(ModuleId);

                        if (optSource.Items.FindByValue(Convert.ToString(settings["bannersource"])) != null)
                        {
                            optSource.Items.FindByValue(Convert.ToString(settings["bannersource"])).Selected = true;
                        }
                        else
                        {
                            optSource.Items.FindByValue("L").Selected = true;
                        }
                        if (cboType.Items.FindByValue(Convert.ToString(settings["bannertype"])) != null)
                        {
                            cboType.Items.FindByValue(Convert.ToString(settings["bannertype"])).Selected = true;
                        }
                        if (!String.IsNullOrEmpty(Convert.ToString(settings["bannergroup"])))
                        {
                            DNNTxtBannerGroup.Text = Convert.ToString(settings["bannergroup"]);
                        }
                        if (optOrientation.Items.FindByValue(Convert.ToString(settings["orientation"])) != null)
                        {
                            optOrientation.Items.FindByValue(Convert.ToString(settings["orientation"])).Selected = true;
                        }
                        else
                        {
                            optOrientation.Items.FindByValue("V").Selected = true;
                        }
                        if (!String.IsNullOrEmpty(Convert.ToString(settings["bannercount"])))
                        {
                            txtCount.Text = Convert.ToString(settings["bannercount"]);
                        }
                        else
                        {
                            txtCount.Text = "1";
                        }
                        if (!String.IsNullOrEmpty(Convert.ToString(settings["border"])))
                        {
                            txtBorder.Text = Convert.ToString(settings["border"]);
                        }
                        else
                        {
                            txtBorder.Text = "0";
                        }
                        if (!String.IsNullOrEmpty(Convert.ToString(settings["padding"])))
                        {
                            txtPadding.Text = Convert.ToString(settings["padding"]);
                        }
                        else
                        {
                            txtPadding.Text = "4";
                        }
                        txtBorderColor.Text = Convert.ToString(settings["bordercolor"]);
                        txtRowHeight.Text = Convert.ToString(settings["rowheight"]);
                        txtColWidth.Text = Convert.ToString(settings["colwidth"]);
                        txtBannerClickThroughURL.Text = Convert.ToString(settings["bannerclickthroughurl"]);
                    }
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }