RadRotator 3 tier programming c#

2 posts, 0 answers
  1. Stardome20
    Stardome20 avatar
    7 posts
    Member since:
    Nov 2012

    Posted 28 Jan 2013 Link to this post

    Data Access Layer
    //Getter and setter method
    public string Url
    {
        get return _url; }
        set { _url = value; }
    }
    public string TargetAudience
    {
        get return _targetAudience; }
        set { _targetAudience = value; }
    }
    public string Image
    {
        get return _image; }
        set { _image = value; }
    }
    public string OnMouseOverText
    {
        get return _onMouseOverText; }
        set { _onMouseOverText = value; }
    }
    public int AdvertisementID
    {
        get return _advertisementID; }
        set { _advertisementID = value; }
    }
    public int Location
    {
        get return _location; }
        set { _location = value; }
    }
    //Constructor
     public AdvertisementDAL(){}
     public AdvertisementDAL(int advertisementID, int location,string image,
        string targetAudience,string url, string onMouseOverText)
    {
        _advertisementID = advertisementID;
        _location = location;
        _image = image;
        _targetAudience = targetAudience;
        _url = url;
        _onMouseOverText = onMouseOverText;
    }
             
    public int updateNoOfClick(DateTime now, int ID)
            {
                string sql = "Select NoOfClick From AdvertisementRecord " +
                    "Where RecordDate = @recordDate AND FK_AdvertisementID = @aID";
                SqlConnection conn = new SqlConnection(_connStr);
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@recordDate", now);
                cmd.Parameters.AddWithValue("@aID", ID);
                conn.Open();
                int noOfClick = int.Parse(cmd.ExecuteScalar().ToString());
                noOfClick++;
                conn.Close();
                string sql1 = "Update AdvertisementRecord SET NoOfClick = @Click "
                "WHERE RecordDate = @Date AND FK_ADvertisementID = @aID";
     
                //SqlConnection conn = new SqlConnection(_connStr);
                SqlCommand cmd1 = new SqlCommand(sql1, conn);
                cmd1.Parameters.AddWithValue("@Click", noOfClick);
                cmd1.Parameters.AddWithValue("@aID", ID);
                cmd1.Parameters.AddWithValue("@Date", now);
                conn.Open();
                int row = 0;
                row = cmd1.ExecuteNonQuery();
                conn.Close();
                return row;
            }
            public AdvertisementDAL selectAdvertisementLocation1(DateTime now, string gender)
            {
                AdvertisementDAL dal = null;
                string sql = "Select * From Advertisement Where @currentDate between StartDate AND EndDate AND TargetAudience = @gender AND Location = 1";
                SqlConnection conn = new SqlConnection(_connStr);
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@currentDate", now);
                cmd.Parameters.AddWithValue("@gender", gender);
                conn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
     
                while (dr.Read())
                {
                    _advertisementID = int.Parse(dr["AdvertisementID"].ToString());
                    _location = int.Parse(dr["Location"].ToString());
                    _image = dr["Image"].ToString();
                    _targetAudience = dr["TargetAudience"].ToString();
                    _url = dr["Url"].ToString();
                    _onMouseOverText = dr["OnMouseOverText"].ToString();
                    dal = new AdvertisementDAL(_advertisementID, _location, _image, _targetAudience,
                        _url, _onMouseOverText);
                }
                conn.Close();
                dr.Close();
                dr.Dispose();
                return dal;
            }
     
    This is my business Logic Layer
    public AdvertisementDAL selectAdLocation1(DateTime now, string gender)
            {
                AdvertisementDAL dal = new AdvertisementDAL();
                return dal.selectAdvertisementLocation1(now, gender);
            }
            public void InsertOrUpdateupdateNoOfClick(DateTime now, int aID)
            {
                AdvertisementDAL dal = new AdvertisementDAL();
                int existDate = dal.checkRecordDateIsExist(now, aID);
                if (existDate == 0)
                {
                    dal.insertAdvertisementRecord(now, aID);
                }
                else if (existDate > 0)
                {
                    dal.updateNoOfClick(now, aID);
                }
            }


    Presentation Layer.
                            <telerik:RadRotator ID="RadRotator1" runat="server">
                                <ItemTemplate>
                                    <asp:ImageButton ID="ImageButton1" runat="server" 
        Height="224px" Width="102px" />
                                </ItemTemplate>
                            </telerik:RadRotator>


    I have a radrotator with a image button control. I wanted the rad rotator look similar like this 
    http://demos.telerik.com/aspnet-ajax/rotator/examples/bannerrotation/defaultcs.aspx
    They will load a lot of advertisement images.  
    when a user click on the specific advertisement, 
    they will update the specific advertisement the no of click.  
    The problem is how do I do it in aspx.cs? at page_load

  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5453 posts

    Posted 31 Jan 2013 Link to this post

    Hello,

    What I can suggest is passing the advertisement ID to the image button as its command argument and use the image button's command event (or click event) to obtain this ID on the server. You can then have a method in your DAL that will increase the click count for the given ad based on its id. You can wrap the rotator in an ASP:UpdatePanel with UpdateMode=Conditional to avoid full postbacks, in order for this to be invisible for the user.


    All the best,
    Marin Bratanov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top