Example #1
0
        public bool IsBannerActive(BannerInfo objBanner)
        {
            bool blnValid = true;

            if (Null.IsNull(objBanner.StartDate) == false && DateTime.Now < objBanner.StartDate)
            {
                blnValid = false;
            }
            if (blnValid)
            {
                switch (objBanner.Criteria)
                {
                case 0:     //AND = cancel the banner when the Impressions expire
                    if (objBanner.Impressions < objBanner.Views && objBanner.Impressions != 0)
                    {
                        blnValid = false;
                    }
                    break;

                case 1:     //OR = cancel the banner if either the EndDate OR Impressions expire
                    if ((objBanner.Impressions < objBanner.Views && objBanner.Impressions != 0) || (DateTime.Now > objBanner.EndDate && Null.IsNull(objBanner.EndDate) == false))
                    {
                        blnValid = false;
                    }
                    break;
                }
            }
            return(blnValid);
        }
Example #2
0
 public void UpdateBanner(BannerInfo objBannerInfo)
 {
     DataProvider.Instance().UpdateBanner(objBannerInfo.BannerId,
                                          objBannerInfo.BannerName,
                                          objBannerInfo.ImageFile,
                                          objBannerInfo.URL,
                                          objBannerInfo.Impressions,
                                          objBannerInfo.CPM,
                                          objBannerInfo.StartDate,
                                          objBannerInfo.EndDate,
                                          objBannerInfo.CreatedByUser,
                                          objBannerInfo.BannerTypeId,
                                          objBannerInfo.Description,
                                          objBannerInfo.GroupName,
                                          objBannerInfo.Criteria,
                                          objBannerInfo.Width,
                                          objBannerInfo.Height);
     ClearBannerCache();
 }
        public void UpdateBanner(BannerInfo objBannerInfo)
        {
            DataProvider.Instance().UpdateBanner(objBannerInfo.BannerId, objBannerInfo.BannerName, objBannerInfo.ImageFile, objBannerInfo.URL, objBannerInfo.Impressions, objBannerInfo.CPM, objBannerInfo.StartDate, objBannerInfo.EndDate, objBannerInfo.CreatedByUser, objBannerInfo.BannerTypeId, objBannerInfo.Description, objBannerInfo.GroupName, objBannerInfo.Criteria, objBannerInfo.Width, objBannerInfo.Height);

            ClearBannerCache();
        }
Example #4
0
        protected void Page_Load( Object sender, EventArgs e )
        {
            // public attributes
            if( BannerTypeId == "" )
            {
                BannerTypeId = "1"; // banner
            }
            if( BannerCount == "" )
            {
                BannerCount = "1";
            }

            if( PortalSettings.BannerAdvertising != 0 )
            {
                int intPortalId;
                if( PortalSettings.BannerAdvertising == 1 )
                {
                    intPortalId = PortalSettings.PortalId; // portal
                }
                else
                {
                    intPortalId = Null.NullInteger; // host
                }

                // load banners
                BannerController objBanners = new BannerController();
                ArrayList arrBanners = objBanners.LoadBanners(intPortalId, Null.NullInteger, Int32.Parse(BannerTypeId), GroupName, Int32.Parse(BannerCount));

                if( arrBanners.Count == 0 )
                {
                    if( BannerTypeId == "1" )
                    {
                        // add default banner if none found
                        BannerInfo objBanner = new BannerInfo();
                        objBanner.BannerId = - 1;
                        objBanner.ImageFile = Globals.ApplicationPath + "/images/banner.gif";
                        objBanner.URL = Globals.GetDomainName(Request);
                        objBanner.BannerName = Localization.GetString( "Banner", Localization.GetResourceFile( this, MyFileName ) );
                        arrBanners.Add( objBanner );
                    }
                }
                
                // bind to datalist
                lstBanners.DataSource = arrBanners;
                lstBanners.DataBind();

                // set banner display characteristics
                if( lstBanners.Items.Count != 0 )
                {
                    // container attributes
                    lstBanners.RepeatLayout = RepeatLayout.Table;
                    if( !String.IsNullOrEmpty(Width) )
                    {
                        lstBanners.Width = Unit.Parse( Width + "px" );
                    }
                    if( lstBanners.Items.Count == 1 )
                    {
                        lstBanners.CellPadding = 0;
                        lstBanners.CellSpacing = 0;
                    }
                    else
                    {
                        lstBanners.CellPadding = 4;
                        lstBanners.CellSpacing = 0;
                    }

                    if( !String.IsNullOrEmpty(Orientation) )
                    {
                        switch( Orientation )
                        {
                            case "H":

                                lstBanners.RepeatDirection = RepeatDirection.Horizontal;
                                break;
                            case "V":

                                lstBanners.RepeatDirection = RepeatDirection.Vertical;
                                break;
                        }
                    }
                    else
                    {
                        lstBanners.RepeatDirection = RepeatDirection.Vertical;
                    }

                    if( !String.IsNullOrEmpty(BorderWidth) )
                    {
                        lstBanners.ItemStyle.BorderWidth = Unit.Parse( BorderWidth + "px" );
                    }
                    if( !String.IsNullOrEmpty(BorderColor) )
                    {
                        ColorConverter objColorConverter = new ColorConverter();
                        lstBanners.ItemStyle.BorderColor = (Color)objColorConverter.ConvertFrom( BorderColor );
                    }

                    // item attributes
                    lstBanners.ItemStyle.VerticalAlign = VerticalAlign.Middle;
                    if( !String.IsNullOrEmpty(RowHeight) )
                    {
                        lstBanners.ItemStyle.Height = Unit.Parse( RowHeight + "px" );
                    }
                    if( !String.IsNullOrEmpty(ColWidth) )
                    {
                        lstBanners.ItemStyle.Width = Unit.Parse( ColWidth + "px" );
                    }
                }
                else
                {
                    lstBanners.Visible = false;
                }
            }
            else
            {
                lstBanners.Visible = false;
            }
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// cmdUpdate_Click runs when the Update Button is clicked
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// 	[cnurse]	9/21/2004	Updated to reflect design changes for Help, 508 support
        ///                       and localisation
        /// </history>
        /// -----------------------------------------------------------------------------
        protected void OnUpdateClick(object sender, EventArgs e)
        {
            try
            {
                //Only Update if the Entered Data is val
                if (Page.IsValid)
                {
                    if (!cmdCopy.Visible)
                    {
                        BannerId = -1;
                    }
                    DateTime StartDate = Null.NullDate;
                    if (!String.IsNullOrEmpty(txtStartDate.Text))
                    {
                        StartDate = Convert.ToDateTime(txtStartDate.Text);
                    }
                    DateTime EndDate = Null.NullDate;
                    if (!String.IsNullOrEmpty(txtEndDate.Text))
                    {
                        EndDate = Convert.ToDateTime(txtEndDate.Text);
                    }

                    //Create an instance of the Banner DB component
                    var objBanner = new BannerInfo();
                    objBanner.BannerId = BannerId;
                    objBanner.VendorId = VendorId;
                    objBanner.BannerName = txtBannerName.Text;
                    objBanner.BannerTypeId = Convert.ToInt32(cboBannerType.SelectedItem.Value);
                    objBanner.GroupName = DNNTxtBannerGroup.Text;
                    objBanner.ImageFile = ctlImage.Url;
                    if (!String.IsNullOrEmpty(txtWidth.Text))
                    {
                        objBanner.Width = int.Parse(txtWidth.Text);
                    }
                    else
                    {
                        objBanner.Width = 0;
                    }
                    if (!String.IsNullOrEmpty(txtHeight.Text))
                    {
                        objBanner.Height = int.Parse(txtHeight.Text);
                    }
                    else
                    {
                        objBanner.Height = 0;
                    }
                    objBanner.Description = txtDescription.Text;
                    objBanner.URL = ctlURL.Url;
                    objBanner.Impressions = int.Parse(txtImpressions.Text);
                    objBanner.CPM = double.Parse(txtCPM.Text);
                    objBanner.StartDate = StartDate;
                    objBanner.EndDate = EndDate;
                    objBanner.Criteria = int.Parse(optCriteria.SelectedItem.Value);
                    objBanner.CreatedByUser = UserInfo.UserID.ToString();

                    var objBanners = new BannerController();
                    if (BannerId == Null.NullInteger)
                    {
                        //Add the banner within the Banners table
                        objBanners.AddBanner(objBanner);
                    }
                    else
                    {
                        //Update the banner within the Banners table
                        objBanners.UpdateBanner(objBanner);
                    }

                    //Redirect back to the portal home page
                    Response.Redirect(EditUrl("VendorId", VendorId.ToString()), true);
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Example #6
0
        public ArrayList LoadBanners(int PortalId, int ModuleId, int BannerTypeId, string GroupName, int Banners)
        {
            if (GroupName == null)
            {
                GroupName = Null.NullString;
            }

            //set cache key
            string cacheKey = string.Format(DataCache.BannersCacheKey, PortalId, BannerTypeId, GroupName);

            //get list of active banners
            var bannersList = CBO.GetCachedObject <List <BannerInfo> >(new CacheItemArgs(cacheKey, DataCache.BannersCacheTimeOut, DataCache.BannersCachePriority, PortalId, BannerTypeId, GroupName),
                                                                       LoadBannersCallback);

            //create return collection
            var arReturnBanners = new ArrayList(Banners);

            if (bannersList.Count > 0)
            {
                if (Banners > bannersList.Count)
                {
                    Banners = bannersList.Count;
                }

                //set Random start index based on the list of banners
                int intIndex = new Random().Next(0, bannersList.Count);
                //set counter
                int intCounter = 1;

                while (intCounter <= bannersList.Count && arReturnBanners.Count != Banners)
                {
                    //manage the rotation for the circular collection
                    intIndex += 1;
                    if (intIndex > (bannersList.Count - 1))
                    {
                        intIndex = 0;
                    }

                    //get the banner object
                    BannerInfo objBanner = bannersList[intIndex];

                    //add to return collection
                    arReturnBanners.Add(objBanner);

                    //update banner attributes
                    objBanner.Views += 1;
                    if (Null.IsNull(objBanner.StartDate))
                    {
                        objBanner.StartDate = DateTime.Now;
                    }
                    if (Null.IsNull(objBanner.EndDate) && objBanner.Views >= objBanner.Impressions && objBanner.Impressions != 0)
                    {
                        objBanner.EndDate = DateTime.Now;
                    }
                    DataProvider.Instance().UpdateBannerViews(objBanner.BannerId, objBanner.StartDate, objBanner.EndDate);

                    //expire cached collection of banners if a banner is no longer active
                    if (!IsBannerActive(objBanner))
                    {
                        DataCache.RemoveCache(cacheKey);
                    }
                    intCounter += 1;
                }
            }
            return(arReturnBanners);
        }
		public bool IsBannerActive(BannerInfo objBanner)
        {
            bool blnValid = true;

            if (Null.IsNull(objBanner.StartDate) == false && DateTime.Now < objBanner.StartDate)
            {
                blnValid = false;
            }
            if (blnValid)
            {
                switch (objBanner.Criteria)
                {
                    case 0: //AND = cancel the banner when the Impressions expire
                        if (objBanner.Impressions < objBanner.Views && objBanner.Impressions != 0)
                        {
                            blnValid = false;
                        }
                        break;
                    case 1: //OR = cancel the banner if either the EndDate OR Impressions expire
                        if ((objBanner.Impressions < objBanner.Views && objBanner.Impressions != 0) || (DateTime.Now > objBanner.EndDate && Null.IsNull(objBanner.EndDate) == false))
                        {
                            blnValid = false;
                        }
                        break;
                }
            }
            return blnValid;
        }
Example #8
0
        public ArrayList LoadBanners(int PortalId, int ModuleId, int BannerTypeId, string GroupName, int Banners)
        {
            ArrayList returnValue;

            ArrayList arrBanners;

            if (GroupName == null)
            {
                GroupName = Null.NullString;
            }

            // cache key
            string strCacheKey = "Banners:" + PortalId + ":" + BannerTypeId + ":" + GroupName + ":";

            // get banners
            arrBanners = (ArrayList)DataCache.GetCache(strCacheKey + "ArrayList");
            if (arrBanners == null)
            {
                arrBanners = CBO.FillCollection(DataProvider.Instance().FindBanners(PortalId, BannerTypeId, GroupName), typeof(BannerInfo));
                DataCache.SetCache(strCacheKey + "ArrayList", arrBanners);
            }

            // create return collection
            returnValue = new ArrayList(Banners);

            if (arrBanners.Count > 0)
            {
                if (Banners > arrBanners.Count)
                {
                    Banners = arrBanners.Count;
                }

                // get last index for rotation
                int    intLastBannerIndex = 0;
                object objLastBannerIndex = DataCache.GetCache(strCacheKey + "LastIndex");
                if (objLastBannerIndex != null)
                {
                    intLastBannerIndex = Convert.ToInt32(objLastBannerIndex);
                }

                int intCounter = 1;
                while (intCounter <= arrBanners.Count && returnValue.Count != Banners)
                {
                    // manage the rotation
                    intLastBannerIndex++;
                    if (intLastBannerIndex > (arrBanners.Count - 1))
                    {
                        intLastBannerIndex = 0;
                    }

                    // get the banner object
                    BannerInfo objBanner = (BannerInfo)arrBanners[intLastBannerIndex];

                    // check criteria
                    bool blnValid = true;
                    if (Null.IsNull(objBanner.StartDate) == false && DateTime.Now < objBanner.StartDate)
                    {
                        blnValid = false;
                    }
                    if (blnValid)
                    {
                        switch (objBanner.Criteria)
                        {
                        case 0:     // AND = cancel the banner when the Impressions expire

                            if (objBanner.Impressions < objBanner.Views && objBanner.Impressions != 0)
                            {
                                blnValid = false;
                            }
                            break;

                        case 1:     // OR = cancel the banner if either the EndDate OR Impressions expire

                            if ((objBanner.Impressions < objBanner.Views && objBanner.Impressions != 0) || (DateTime.Now > objBanner.EndDate && Null.IsNull(objBanner.EndDate) == false))
                            {
                                blnValid = false;
                            }
                            break;
                        }
                    }

                    // add to return collection
                    if (blnValid)
                    {
                        returnValue.Add(objBanner);

                        // update banner ( these values are persisted to the cache )
                        objBanner.Views++;
                        if (Null.IsNull(objBanner.StartDate))
                        {
                            objBanner.StartDate = DateTime.Now;
                        }
                        if (Null.IsNull(objBanner.EndDate) && objBanner.Views >= objBanner.Impressions && objBanner.Impressions != 0)
                        {
                            objBanner.EndDate = DateTime.Now;
                        }
                        // update database
                        DataProvider.Instance().UpdateBannerViews(objBanner.BannerId, objBanner.StartDate, objBanner.EndDate);
                    }

                    intCounter++;
                }

                // save last index for rotation
                DataCache.SetCache(strCacheKey + "LastIndex", intLastBannerIndex);
            }

            return(returnValue);
        }