void loadEvents()
    {
        EventFilter filter = new EventFilter();

        filter.Keyword = txtKeyword.Text.Trim();
        filter.UserIds = ddlUsers.SelectedValue;
        filter.MainType = ddlMainType.SelectedValue;
        if (ddlCompalted.SelectedValue != "") filter.Completed = Convert.ToBoolean(ddlCompalted.SelectedValue);
        filter.Type = int.Parse(ddlEventType.SelectedValue);
        filter.DateFrom = txtDateFrom.Text;
        filter.DateTo = txtDateTo.Text;
        filter.SortBy = ddlSortBy.SelectedValue;
        filter.RecordsPerPage = recordsPerPage;

        //set current page
        int currentPage = 1;
        if (Request.QueryString["paged"] != null && Request.QueryString["paged"].IsNumeric())
            currentPage = int.Parse(Request.QueryString["paged"]);
        filter.CurrentPage = currentPage;

        //retrieve events
        IEnumerable<Event> events = new Events().GetEvents(filter);

        //data bind
        rptEvents.DataSource = events;
        rptEvents.DataBind();

        if (events.Count() > 0)
        {
            pager1.recordsPerPage = recordsPerPage;
            pager1.totalRecords = events.First().RecordCount;

            div_events.Visible = true;
            div_noresults.Visible = false;
        }
        else
        {
            div_events.Visible = false;
            div_noresults.Visible = true;
        }
    }
Example #2
0
        /// <summary>
        /// This function returns the events
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public IEnumerable<Event> GetEvents(EventFilter filter)
        {
            //         public string MainType { get; set; }
            //public string Keyword { get; set; }
            //public bool? Completed { get; set; }


            var events = new List<Event>();
            // setup the parameters
            SqlParameter[] parameters = {
                           new SqlParameter("@RecordsPerPage", filter.RecordsPerPage ),
                           new SqlParameter("@PageNo", filter.CurrentPage),
	                       new SqlParameter("@DateFrom", string.IsNullOrEmpty(filter.DateFrom) ? "" : new Utils().GetValidDate(filter.DateFrom) ),
	                       new SqlParameter("@DateTo ",  string.IsNullOrEmpty(filter.DateTo) ? ""  : new Utils().GetValidDate(filter.DateTo)  ),
                           new SqlParameter("@UserIds", string.IsNullOrEmpty(filter.UserIds) ? "" : filter.UserIds.Trim().TrimEnd(Convert.ToChar(","))), 
                           new SqlParameter("@AllDay", filter.AllDay ),
                           new SqlParameter("@SortBy", filter.SortBy),
                           new SqlParameter("@ClientId", filter.ClientId),
                           new SqlParameter("@VacancyId", filter.VacancyId) , 
                           new SqlParameter("@CreatedBy", filter.CreatedBy),
                           new SqlParameter("@Type", filter.Type) ,
                           new SqlParameter("@MainType", filter.MainType) ,
                           new SqlParameter("@Keyword", filter.Keyword) ,
                           new SqlParameter("@Completed", filter.Completed) 

            };
            // setup the connection
            var conn = new Sql_DataAccess(_connString);
            var ds = conn.GetDataSetFromSP("RetrieveEvents", parameters);
            // iterate and return clients
            if (ds != null && ds.Tables.Count > 0)
            {
                events = (from DataRow dr in ds.Tables[0].Rows
                          select new Event
                          {
                              EventId = (int)dr["EventId"],
                              MainType = (dr["MainType"] ?? "").ToString(),
                              Title = (dr["Title"] ?? "").ToString(),
                              Location = (dr["Location"] ?? "").ToString(),
                              Description = (dr["Description"] ?? "").ToString(),
                              StartDate = new Utils().GetUkDate((DateTime)dr["StartDate"]),
                              EndDate = new Utils().GetUkDate((DateTime)dr["EndDate"]),
                              StartTime = ((DateTime)dr["StartDate"]).ToString("HH:mm"),
                              EndTime = ((DateTime)dr["EndDate"]).ToString("HH:mm"),
                              IsDayEvent = (bool)dr["AllDayEvent"],
                              UserId = (int)dr["UserId"],
                              Username = (dr["Username"] ?? "").ToString(),
                              CreatedBy = (int)(dr["CreatedBy"]),
                              CreatedDate = (DateTime)(dr["CreatedDate"]),
                              RecurrenceId = (int)(dr["RecurrenceId"]),
                              Completed = (bool)dr["Completed"],
                              Locked = ((bool)dr["Locked"]),
                              EventType = new EventType { EventTypeId = (int)dr["EventTypeId"], EventTypeText = (dr["EventType"] ?? "").ToString() },
                              Vacancy = (int)dr["VacancyId"] > 0 ? (new EventTag { id = (int)dr["VacancyId"], name = (dr["JobTitle"] ?? "").ToString() }) : null,
                              Client = (int)dr["ClientId"] > 0 ? (new EventTag { id = (int)dr["ClientId"], name = (dr["Client"] ?? "").ToString() }) : null,
                              ClientContact = (int)dr["ClientContactId"] > 0 ? (new EventTag { id = (int)dr["ClientContactId"], name = (dr["ClientContactName"] ?? "").ToString() }) : null,
                              RecordCount = (int)dr["RECORDCOUNT"]
                          }).ToList();
            }
            return events;
        }