Пример #1
0
    public static ScheduledEvent[] ReadEvents(DateTime dtStart, DateTime dtEnd, int clubID = Club.ClubIDNew, string resourceName = null)
    {
        if (!IsValidCaller(clubID, PrivilegeLevel.ReadOnly))
        {
            return(null);
        }

        Club                  c   = Club.ClubWithID(clubID);
        TimeZoneInfo          tzi = c.TimeZone;
        List <ScheduledEvent> lst = ScheduledEvent.AppointmentsInTimeRange(ScheduledEvent.ToUTC(dtStart, tzi), ScheduledEvent.ToUTC(dtEnd, tzi), resourceName, clubID, tzi);

        // Fix up the owner's name
        lst.ForEach((se) => {
            se.OwnerProfile = c.PrependsScheduleWithOwnerName ? c.Members.FirstOrDefault(cm => cm.UserName.CompareTo(se.OwningUser) == 0) : null;
            se.ReadOnly     = !se.CanEdit(HttpContext.Current.User.Identity.Name, c);
        });
        return(lst.ToArray());
    }
        protected void btnDownloadSchedule_Click(object sender, EventArgs e)
        {
            if (dateDownloadTo.Date.Subtract(dateDownloadFrom.Date).TotalDays < 1)
            {
                lblDownloadErr.Text = Resources.Club.DownloadClubScheduleBadDateRange;
            }
            else
            {
                IEnumerable <ScheduledEvent> rgevents = ScheduledEvent.AppointmentsInTimeRange(dateDownloadFrom.Date, dateDownloadTo.Date, CurrentClub.ID, CurrentClub.TimeZone);
                CurrentClub.MapAircraftAndUsers(rgevents);  // fix up aircraft, usernames
                gvScheduleDownload.DataSource = rgevents;
                gvScheduleDownload.DataBind();

                Response.Clear();
                Response.ContentType = "text/csv";
                // Give it a name that is the brand name, user's name, and date.  Convert spaces to dashes, and then strip out ANYTHING that is not alphanumeric or a dash.
                string szFilename    = String.Format(CultureInfo.InvariantCulture, "{0}-{1}-{2}", Branding.CurrentBrand.AppName, Resources.Club.DownloadClubScheduleFileName, CurrentClub.Name.Replace(" ", "-"));
                string szDisposition = String.Format(CultureInfo.InvariantCulture, "attachment;filename={0}.csv", System.Text.RegularExpressions.Regex.Replace(szFilename, "[^0-9a-zA-Z-]", ""));
                Response.AddHeader("Content-Disposition", szDisposition);
                gvScheduleDownload.ToCSV(Response.OutputStream);
                Response.End();
            }
        }