天道酬勤,厚德载物

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::


Events_Calendar.aspx

<%@ Page Language="C#" MasterPageFile="~/Default.master" Title="Untitled Page" Trace="false" %>

<%@ Register TagPrefix="Club" Namespace="ClubSite" %>
<%@ Register TagPrefix="Club" TagName="LoginBanner" Src="LoginBanner.ascx" %>
<%@ Register TagPrefix="ec" Namespace="ControlSample" Assembly="EventCalendar" %>

<script runat="server"> 
    protected 
void Page_Load(object sender, System.EventArgs e)
    
{
        bool isAdmin 
= User.IsInRole("Administrators");
        panel1.Visible 
= isAdmin;
        panel2.Visible 
= isAdmin;
    }

</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    
<div id="body">
        
<Club:LoginBanner ID="LoginBanner1" runat="server" />
        
<div class="fullwidth">
            
<h2>
                Events
</h2>
            
<br />
            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh
            euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad
            minim veniam, quis nostrud exercitation ulliam corper.
            
<div class="dashedline">
            
</div>
            
<href="Events_list.aspx">List view</a> &nbsp; &nbsp; <href="Locations_list.aspx">
                Locations List
</a>
        
</div>
        
<asp:Panel ID="panel1" runat="server" CssClass="fullwidth">
            
<div class="actionbuttons">
                
<Club:RolloverLink ID="Addbtn" runat="server" Text="Add New Event" NavigateURL="Events_edit.aspx?Action=New" />
            
</div>
        
</asp:Panel>
        
<div class="eventmonth">
            
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>"
                SelectCommand
="SELECT [id], [starttime], [title], [description] FROM [Events]"></asp:SqlDataSource>
            
<ec:EventCalendar runat="server" ID="eventscalendar" DataSourceID="sqldatasource1"
                BorderWidth
="0" DayField="starttime" ShowTitle="true" CssClass="eventmonthtable">
                
<DayHeaderStyle CssClass="caldays" />
                
<DayStyle CssClass="calcurrentmonth" />
                
<TodayDayStyle CssClass="calcurrentday" />
                
<WeekendDayStyle CssClass="calweekend" />
                
<OtherMonthDayStyle CssClass="calothermonth" />
                
<DayNumberStyle CssClass="dayNumber" />
                
<HeaderTemplate>
                    
<table width="100%">
                        
<tr align="center">
                            
<td>
                                
<asp:LinkButton ID="PrevMonth" runat="server" Text='<%# "&laquo; " + Container.PrevMonth.ToString("MMMM yyyy") %>'
                                    CommandName="PrevMonth" />
                            
</td>
                            
<td>
                                
<h3>
                                    
<asp:Label ID="label2" runat="server" Text='<%# Container.CurrentMonth.ToString("MMMM yyyy") %>' /></h3>
                            
</td>
                            
<td>
                                
<asp:LinkButton ID="NextMonth" runat="server" Text='<%# Container.NextMonth.ToString("MMMM yyyy") + " &raquo;" %>'
                                    CommandName="NextMonth" />
                            
</td>
                        
</tr>
                    
</table>
                    
<div class="dashedline">
                    
</div>
                
</HeaderTemplate>
                
<DayEventTemplate>
                    
<div style="padding: 3px;">
                        
<asp:HyperLink ID="HyperLink1" runat="server" Text='<%#Eval("title") %>' NavigateUrl='<%"Events_view.aspx?Eventid=" + Convert.ToString(Eval("ID"))%>'
                            ToolTip='
<%# SharedRoutines.truncate((string)Eval("description")) %>' /></div>
                
</DayEventTemplate>
            
</ec:EventCalendar>
        
</div>
        
<asp:Panel ID="panel2" runat="server" CssClass="fullwidth">
            
<div class="actionbuttons">
                
<Club:RolloverLink ID="GreenRolloverLink1" runat="server" Text="Add New Event"
                    NavigateURL
="Events_edit.aspx?Action=New" />
            
</div>
        
</asp:panel>
    
</div>
</asp:Content>

2.Events_List.aspx

<%@ Page Language="C#" MasterPageFile="~/Default.master" Title="Untitled Page" %>

<%@ Register TagPrefix="Club" Namespace="ClubSite" %>
<%@ Register TagPrefix="Club" TagName="LoginBanner" Src="LoginBanner.ascx" %>
<%@ Register TagPrefix="Club" TagName="ImageThumbnail" Src="ImageThumbnail.ascx" %>

<script runat="server">

    protected 
void SqlDataSource1_Selected(object sender, System.Web.UI.WebControls.SqlDataSourceStatusEventArgs e)
    
{
        
int pages;
        pages 
= (int) e.Command.Parameters["@pageCount"].Value;
        pn1.Count 
= pages;
        pn2.Count 
= pages;
    }


    protected 
void SqlDataSource2_Selected(object sender, System.Web.UI.WebControls.SqlDataSourceStatusEventArgs e)
    
{
        
int pages;
        pages 
= (int) e.Command.Parameters["@pageCount"].Value;
        pn3.Count 
= pages;
        pn4.Count 
= pages;
    }


    protected 
void pn1_SelectedPageChanged(object sender, System.EventArgs e)
    
{
        pn2.SelectedPage 
= pn1.SelectedPage;
    }


    protected 
void pn2_SelectedPageChanged(object sender, System.EventArgs e)
    
{
        pn1.SelectedPage 
= pn2.SelectedPage;
    }


    protected 
void pn3_SelectedPageChanged(object sender, System.EventArgs e)
    
{
        pn4.SelectedPage 
= pn3.SelectedPage;
    }


    protected 
void pn4_SelectedPageChanged(object sender, System.EventArgs e)
    
{
        pn3.SelectedPage 
= pn4.SelectedPage;
    }

    private bool IsAdmin;

    protected 
void Page_Load(object sender, System.EventArgs e)
    
{
        IsAdmin 
= User.IsInRole("Administrators");
        panel1.Visible 
= IsAdmin;
    }

</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    
<div id="body">
        
<Club:LoginBanner ID="LoginBanner1" runat="server" />
        
<!--
        
        Left column
        
        
-->
        
<div id="columnleft">
            
<name="content_start" id="content_start"></a>
            
<div class="leftblock">
                
<h2>
                    Events
</h2>
                
<p>
                    Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh
                    euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad
                    minim veniam, quis nostrud exercitation ulliam corper suscipit lobortis nisl ut
                    aliquip ex ea commodo consequat. Duis autem veleum iriure dolor in hendrerit in
                    vulputate velit esse molestie consequat, vel willum lunombro dolore eu feugiat nulla
                    facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent
                    luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
</p>
            
</div>
        
</div>
        
<!--
        
        Right column
        
        
-->
        
<div id="columnright">
            
<div class="rightblock">
                
<asp:Panel ID="panel1" runat="server" CssClass="actionbuttons">
                    
<Club:RolloverLink ID="AddBtn" runat="server" Text="Add new event" NavigateURL="Events_Edit.aspx?Action=New" />
                
</asp:Panel>
                
<href="Events_calendar.aspx">Month view</a> &nbsp; &nbsp; <href="Locations_list.aspx">
                    Locations List
</a>
            
</div>
            
<div class="rightblock">
                
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>"
                    SelectCommand
="PagedUpcommingEventList" SelectCommandType="StoredProcedure" OnSelected="SqlDataSource1_Selected">
                    
<SelectParameters>
                        
<asp:ControlParameter Name="pageNum" ControlID="pn1" PropertyName="SelectedPage" />
                        
<asp:Parameter DefaultValue="5" Name="pageSize" Type="Int32" />
                        
<asp:Parameter Name="pageCount" Direction="ReturnValue" Type="Int32" />
                    
</SelectParameters>
                
</asp:SqlDataSource>
                
<h2>
                    Upcomming events
</h2>
                
<div class="dashedline">
                
</div>
                
<div class="newscrumbs">
                    Page:
                    
<Club:PageNumberer ID="pn1" runat="server" SelectedPage="1" DisplayedPages="7" OnSelectedPageChanged="pn1_SelectedPageChanged"
                        CssClass
="PageNumbers" />
                
</div>
                
<div class="dashedline">
                
</div>
                
<!-- begin news item -->
                
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
                    
<ItemTemplate>
                        
<div class="listitem">
                            
<div class="thumbnail">
                                
<href='<%# "Events_view.aspx?Eventid=" + Convert.ToString(Eval("ID"))%>'>
                                    
<Club:ImageThumbnail ID="ImageThumbnail1" runat="server" PhotoID='<%# Eval("photo") %>'
                                        NoPhotoImg="images/calendar.jpg" />
                                
</a>
                            
</div>
                            
<asp:Panel ID="panel2" runat="server" CssClass="editbuttons" Visible='<%#IsAdmin %>'>
                                
<Club:RolloverLink ID="EditBtn" runat="server" Text="Edit" NavigateURL='<%# "Events_Edit.aspx?Action=Edit&id=" + Convert.ToString(Eval("id")) %>' />
                                
<Club:RolloverLink ID="RemoveBtn" runat="server" Text="Remove" NavigateURL='<%# "Events_Edit.aspx?Action=Remove&id=" + Convert.ToString(Eval("id")) %>' />
                            
</asp:Panel>
                            
<h3>
                                
<asp:Label ID="itemdateLabel" runat="server" Text='<%# Eval("starttime","{0:d}") %>' />
                                
&nbsp;&nbsp;&nbsp;&nbsp; <href='<%# "Events_view.aspx?Eventid=" + Convert.ToString( Eval("ID"))%>'>
                                    
<asp:Label ID="titleLabel" runat="server" Text='<%# Eval("title") %>' />
                                
</a>
                            
</h3>
                            
<p>
                                
<asp:Label ID="descriptionLabel" runat="server" Text='<%# SharedRoutines.truncate((string)Eval("description")) %>' />
                                
<href='<%# "Events_view.aspx?Eventid=" + Convert.ToString( Eval("ID"))%>'>read more &raquo;</a></p>
                            
<div class="clearlist">
                            
</div>
                        
</div>
                    
</ItemTemplate>
                
</asp:Repeater>
                
<div class="dashedline">
                
</div>
                
<div class="newscrumbs">
                    Page:
                    
<Club:PageNumberer ID="pn2" runat="server" SelectedPage="1" DisplayedPages="7" CssClass="PageNumbers"
                        OnSelectedPageChanged
="pn2_SelectedPageChanged" />
                
</div>
            
</div>
            
<div class="rightblock">
                
<h2>
                    Recent events
</h2>
                
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>"
                    SelectCommand
="PagedRecentEventList" SelectCommandType="StoredProcedure" OnSelected="SqlDataSource2_Selected">
                    
<SelectParameters>
                        
<asp:ControlParameter Name="pageNum" ControlID="pn3" PropertyName="SelectedPage" />
                        
<asp:Parameter DefaultValue="5" Name="pageSize" Type="Int32" />
                        
<asp:Parameter Name="pageCount" Direction="ReturnValue" Type="Int32" />
                    
</SelectParameters>
                
</asp:SqlDataSource>
                
<div class="dashedline">
                
</div>
                
<div class="newscrumbs">
                    Page:
                    
<Club:PageNumberer ID="pn3" runat="server" SelectedPage="1" DisplayedPages="7" CssClass="PageNumbers"
                        OnSelectedPageChanged
="pn3_SelectedPageChanged" />
                
</div>
                
<div class="dashedline">
                
</div>
                
<!-- begin news item -->
                
<asp:Repeater ID="Repeater2" runat="server" DataSourceID="SqlDataSource2">
                    
<ItemTemplate>
                        
<div class="listitem">
                            
<div class="thumbnail">
                                
<href='<%# "Events_view.aspx?Eventid=" + Convert.ToString( Eval("ID"))%>'>
                                    
<Club:ImageThumbnail ID="ImageThumbnail1" runat="server" PhotoID='<%# Eval("photo")%>'
                                        NoPhotoImg="images/calendar.jpg" />
                                
</a>
                            
</div>
                            
<asp:Panel ID="panel1" runat="server" CssClass="editbuttons" Visible='<%#IsAdmin %>'>
                                
<Club:RolloverLink ID="EditBtn" runat="server" Text="Edit" NavigateURL='<%# "Events_Edit.aspx?Action=Edit&id=" + Convert.ToString(Eval("id")) %>' />
                                
<Club:RolloverLink ID="RemoveBtn" runat="server" Text="Remove" NavigateURL='<%# "Events_Edit.aspx?Action=Remove&id=" + Convert.ToString(Eval("id")) %>' />
                            
</asp:Panel>
                            
<h3>
                                
<asp:Label ID="itemdateLabel" runat="server" Text='<%# Eval("starttime","{0:d}") %>' />
                                
&nbsp;&nbsp;&nbsp;&nbsp; <href='<%# "Events_view.aspx?Eventid=" + Convert.ToString( Eval("ID"))%>'>
                                    
<asp:Label ID="titleLabel" runat="server" Text='<%# Eval("title") %>' />
                                
</a>
                            
</h3>
                            
<p>
                                
<asp:Label ID="descriptionLabel" runat="server" Text='<%# SharedRoutines.truncate((string)Eval("description")) %>' />
                                
<href='<%# "Events_view.aspx?Eventid=" + Convert.ToString( Eval("ID"))%>'>read more &raquo;</a></p>
                            
<div class="clearlist">
                            
</div>
                        
</div>
                    
</ItemTemplate>
                
</asp:Repeater>
                
<div class="dashedline">
                
</div>
                
<div class="newscrumbs">
                    Page:
                    
<Club:PageNumberer ID="pn4" runat="server" SelectedPage="1" DisplayedPages="7" CssClass="PageNumbers"
                        OnSelectedPageChanged
="pn4_SelectedPageChanged" />
                
</div>
            
</div>
        
</div>
        
<div class="clear2column">
        
</div>
    
</div>
</asp:Content>

3.Events_View.aspx

<%@ Page Language="C#" MasterPageFile="~/Default.master" Title="Untitled Page" %>

<%@ Register TagPrefix="Club" Namespace="ClubSite" %>
<%@ Register TagPrefix="Club" TagName="LoginBanner" Src="LoginBanner.ascx" %>
<%@ Register TagPrefix="Club" TagName="ImageThumbnail" Src="ImageThumbnail.ascx" %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">

    private 
int nextEventID;
    private 
int prevEventID;
    const 
int INVALIDID = -1;

    protected 
void Page_Load(object sender, System.EventArgs e)
    
{
        SqlDataSource1.SelectParameters[
"id"].DefaultValue = System.Convert.ToString(EventID);
    }


    protected 
void NextButton_Click(object sender, System.EventArgs e)
    
{
        InitValsFromSql(EventID);
        
if (nextEventID != INVALIDID)
        
{
            prevEventID 
= EventID;
            EventID 
= nextEventID;
            SqlDataSource1.SelectParameters[
"id"].DefaultValue = System.Convert.ToString(nextEventID);
        }

        ToggleLinks();
    }


    protected 
void PrevButton_Click(object sender, System.EventArgs e)
    
{
        InitValsFromSql(EventID);
        
if (prevEventID != INVALIDID)
        
{
            nextEventID 
= EventID;
            EventID 
= prevEventID;
            SqlDataSource1.SelectParameters[
"id"].DefaultValue = System.Convert.ToString(prevEventID);
        }

        ToggleLinks();
    }


    
void ToggleLinks()
    
{
        LinkButton1.Enabled 
= (nextEventID != INVALIDID);
        LinkButton3.Enabled 
= (nextEventID != INVALIDID);
        LinkButton2.Enabled 
= (prevEventID != INVALIDID);
        LinkButton4.Enabled 
= (prevEventID != INVALIDID);
    }


    
int EventID
    
{
        get
        
{
            
int m_EventID;
            object id 
= ViewState["EventID"];
            
if (id != null)
            
{
                m_EventID 
= (int)id;
            }

            
else
            
{
                id 
= Request.QueryString["EventID"];
                
if (id != null)
                
{
                    m_EventID 
= System.Convert.ToInt32(id);
                }

                
else
                
{
                    m_EventID 
= 1;
                }

                ViewState[
"EventID"= m_EventID;
            }

            
return m_EventID;
        }

        set
        
{
            ViewState[
"EventID"= value;
        }

    }


    
void InitValsFromSql(int EventID)
    
{
        
try
        
{
            SqlConnection connection 
= new SqlConnection(ConfigurationManager.ConnectionStrings["ClubSiteDB"].ConnectionString);
            SqlCommand command 
= new SqlCommand("dbo.NextPrevEvent", connection);
            
            SqlParameter param0 
= new SqlParameter("@id", EventID);
            SqlParameter param1 
= new SqlParameter("@previd", INVALIDID);
            SqlParameter param2 
= new SqlParameter("@nextid", INVALIDID);
            
            param1.Direction 
= ParameterDirection.InputOutput;
            param2.Direction 
= ParameterDirection.InputOutput;
            
            command.Parameters.Add(param0);
            command.Parameters.Add(param1);
            command.Parameters.Add(param2);
            
            command.CommandType 
= CommandType.StoredProcedure;
            connection.Open();
            command.ExecuteNonQuery();
            
            
if (param1.Value != null && param1.Value != DBNull.Value)
            
{
                prevEventID 
= (int) param1.Value;
            }

            
else
            
{
                prevEventID 
= INVALIDID;
            }

            
            
if (param2.Value != null && param2.Value != DBNull.Value)
            
{
                nextEventID 
= (int) param2.Value;
            }

            
else
            
{
                nextEventID 
= INVALIDID;
            }

            connection.Close();
        }

        
catch
        
{
            prevEventID 
= INVALIDID;
            nextEventID 
= INVALIDID;
        }

    }


    protected 
void FormView1_DataBound(object sender, System.EventArgs e)
    
{
        DataRowView view 
= (DataRowView)(FormView1.DataItem);
        object o 
= view["staticURL"];
        
if (o != null && o!= DBNull.Value)
        
{
            string staticurl 
= (string)o;
            
if (staticurl != "")
            
{
                Response.Redirect(staticurl);
            }

        }

    }


    string ShowLocationLink(object locationname, object id)
    
{
        
if (id != null && id!= DBNull.Value)
        
{
            
return "At <a href='Locations_view.aspx?LocationID=" + Convert.ToString(id) + "'>" + (string)locationname + "</a><br/>";
        }

        
else
        
{
            
return "";
        }

    }


    string ShowDuration(object starttime, object endtime)
    
{
        DateTime starttimeDT 
= (DateTime)starttime;
        
if (endtime != null && endtime!= DBNull.Value)
        
{
           DateTime endtimeDT 
= (DateTime)endtime;
            
if (starttimeDT.Date == endtimeDT.Date)
            
{
                
if (starttimeDT == endtimeDT)
                
{
                    
return starttimeDT.ToString("h:mm tt");
                }

                
else
                
{
                    
return starttimeDT.ToString("h:mm tt"+ " - " + endtimeDT.ToString("h:mm tt");
                }

            }

            
else
            
{
                
return "thru " + endtimeDT.ToString("M/d/yy");
            }

        }

        
else
        
{
            
return starttimeDT.ToString("h:mm tt");
        }

    }

    
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    
<div id="body">
        
<Club:LoginBanner ID="LoginBanner1" runat="server" />
        
<!--
        
        Left column
        
        
-->
        
<div id="columnleft">
            
<name="content_start" id="content_start"></a>
            
<div class="leftblock">
                
<h2>
                    Events
</h2>
                
<p>
                    Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh
                    euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad
                    minim veniam, quis nostrud exercitation ulliam corper suscipit lobortis nisl ut
                    aliquip ex ea commodo consequat. Duis autem veleum iriure dolor in hendrerit in
                    vulputate velit esse molestie consequat, vel willum lunombro dolore eu feugiat nulla
                    facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent
                    luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
</p>
            
</div>
        
</div>
        
<!--
        
        Right column
        
        
-->
        
<div id="columnright">
            
<div class="rightblock">
                
<href="Events_calendar.aspx">month view</a> <href="Events_list.aspx">list view</a></div>
            
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>"
                SelectCommand
="SELECT dbo.Events.id, dbo.Events.starttime, dbo.events.endtime, dbo.Events.title, dbo.Events.description, dbo.Events.staticURL, dbo.Events.photo, dbo.Events.Album,  dbo.Events.location, dbo.Locations.title AS locationname FROM  dbo.Events LEFT OUTER JOIN dbo.Locations ON dbo.Events.location = dbo.Locations.id where Events.id=@id">
                
<SelectParameters>
                    
<asp:Parameter Type="Int32" DefaultValue="1" Name="id"></asp:Parameter>
                
</SelectParameters>
            
</asp:SqlDataSource>
            
<div class="rightblock">
                
<div class="nextlink">
                    
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="NextButton_Click">next event &raquo;</asp:LinkButton>
                
</div>
                
<asp:LinkButton ID="LinkButton2" runat="server" OnClick="PrevButton_Click">&laquo; previous event</asp:LinkButton>
                
<div class="dashedline">
                
</div>
                
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="id"
                    AllowPaging
="false" Width="100%">
                    
<ItemTemplate>
                        
<h2>
                            
<asp:Label Text='<%# Eval("title") %>' runat="server" ID="titleLabel" />
                        
</h2>
                        
<div class="itemdetails">
                            
<br />
                            location:
                            
<h3>
                                
<asp:Label ID="locationLabel" runat="server" Text='<%# ShowLocationLink(Eval("locationname"),Eval("location")) %>' />
                            
</h3>
                            
<p>
                                
<asp:Label Text='<%# Eval("starttime","{0:D}") %>' runat="server" ID="itemdateLabel" />
                                
<br />
                                
<asp:Label Text='<%# ShowDuration(Eval("starttime"),Eval("endtime")) %>' runat="server"
                                    ID="Label1" />
                            
</p>
                        
</div>
                        
<div class="downloadevent">
                            
<href="#">
                                
<img src="images/icon_download_event.gif" alt="Download this event to your personal calendar"
                                    width
="15" height="26" /></a><href='<%# "events_download.ashx?EventID=" + Convert.ToString(Eval("id")) %>'>Add
                                        this event to your personal calendar
</a></div>
                        
<Club:ImageThumbnail ID="thumb1" runat="server" ImageSize="Large" PhotoID='<%# Eval("photo") %>' />
                        
<p>
                            
<asp:Label Text='<%# Eval("description") %>' runat="server" ID="descriptionLabel" />
                        
</p>
                        
<asp:Panel ID="panel1" runat="server" CssClass="actionbuttons" Visible='<%#User.IsInRole("Administrators") %>'>
                            
<Club:RolloverLink ID="EditBtn" runat="server" Text="Edit" NavigateURL='<%# "Events_edit.aspx?id=" + Convert.ToString(Eval("id")) %>' />
                        
</asp:Panel>
                    
</ItemTemplate>
                
</asp:FormView>
                
<div class="dashedline">
                
</div>
                
<div class="nextlink">
                    
<asp:LinkButton ID="LinkButton3" runat="server" OnClick="NextButton_Click">next event &raquo;</asp:LinkButton>
                
</div>
                
<asp:LinkButton ID="LinkButton4" runat="server" OnClick="PrevButton_Click">&laquo; previous event</asp:LinkButton>
            
</div>
        
</div>
        
<div class="clear2column">
        
</div>
    
</div>
</asp:Content>

4.Events_Download.ashx

<%@ WebHandler Language="C#" Class="DownloadEvent" %>

using System;
using System.Web; 
using System.Data.SqlClient;
using System.Data;
using System.Text;
using System.IO;

public class DownloadEvent : IHttpHandler 

 
const int BUFFERSIZE = 1024;

    
public bool IsReusable
    
{
        
get
        
{
            
return true;
        }

    }
 

 
public void ProcessRequest(HttpContext context) 
 

   HttpResponse response 
= context.Response; 
   HttpRequest request 
= context.Request; 
   response.BufferOutput 
= true
   response.ContentType 
= "text/calendar"
   response.Cache.SetCacheability(HttpCacheability.NoCache); 
   
int EventID = Convert.ToInt32(request.QueryString["EventID"]); 
   Uri viewurl 
= new Uri(context.Request.Url, "Events_view.aspx?Eventid=" + EventID); 
   writeCalEntry(EventID, response.Output, viewurl.ToString()); 
   response.End(); 
 }


    
public void writeCalEntry(int EventID, TextWriter output, string url)
    
{
        SqlConnection connection 
= new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ClubSiteDB"].ConnectionString);

        
string qry = "SELECT Events.starttime, Events.endtime, Events.title, Events.description, Events.staticURL, Locations.title AS LocName, Locations.directions, ";
        qry 
+= "Locations.description AS locDesc, Locations.address ";
        qry 
+= "FROM Locations RIGHT OUTER JOIN ";
        qry 
+= "Events ON Locations.id = Events.location ";
        qry 
+= "WHERE (Events.id = @id)";

        SqlCommand command 
= new SqlCommand(qry, connection);
        SqlParameter param0 
= new SqlParameter("@id", SqlDbType.Int);
        param0.Value 
= EventID;
        command.Parameters.Add(param0);

        connection.Open();
        DataTable dt 
= new DataTable();
        dt.Load(command.ExecuteReader());
        
if (dt.Rows.Count > 0)
        
{
            DataRow dr 
= dt.Rows[0];

            System.DateTime starttime, endtime;
            
string title, description, location;

            StringBuilder sb 
= new StringBuilder();
            
object o;
            
            starttime 
= (DateTime)dr["starttime"];
            
if (dr["endtime"!= DBNull.Value)
            
{
                endtime 
= (DateTime)dr["endtime"];
            }

            
else
            
{
                endtime 
= starttime;
            }

            
            
if (dr["title"!= DBNull.Value)
            
{
                title 
= (string)(dr["title"]);
            }

            
else
            
{
                title 
= "An untitled clubsite event";
            }

           
            o 
= dr["description"];
            
if (o != DBNull.Value && (string)o != "")
            
{
                sb.AppendLine((
string)o);
            }

            sb.AppendLine();
            
            sb.Append(
"Event URL: ");
            o 
= dr["staticURL"];
            
if (o != DBNull.Value && (string)o != "")
            
{
                sb.AppendLine((
string)o);
            }

            
else
            
{
                sb.AppendLine(url);
            }

            
            o 
= dr["locName"];
            
if (o != DBNull.Value && (string)o != "")
            
{
                location 
= (string) o;
                sb.AppendLine();
                sb.Append(
"Event location: ");
                sb.AppendLine(location);
            }

            
else
            
{
                location 
= null;
            }

            
            o 
= dr["locDesc"];
            
if (o != DBNull.Value && (string)o != "")
            
{
                sb.AppendLine();
                sb.AppendLine(
"Location description:");
                sb.AppendLine((
string)o);
            }

            
            o 
= dr["Address"];
            
if (o != DBNull.Value && (string)o != "")
            
{
                sb.AppendLine();
                sb.AppendLine(
"Location Address:");
                sb.AppendLine((
string)o);
            }

            
            o 
= dr["directions"];
            
if (o != DBNull.Value && (string)o != "")
            
{
                sb.AppendLine();
                sb.AppendLine(
"Location Directions:");
                sb.AppendLine((
string) o);
            }

            
            UnicodeEncoding uc 
= new UnicodeEncoding();
            description 
= sb.ToString();
            output.WriteLine(
"BEGIN:VCALENDAR");
            output.WriteLine(
"VERSION:2.0");
            output.WriteLine(
"PRODID:" + url);
            output.WriteLine(
"METHOD:PUBLISH");
            output.WriteLine(
"BEGIN:VEVENT");
            output.WriteLine(
"UID:" + Guid.NewGuid().ToString());
            output.WriteLine(
"DTSTAMP:" + DateTime.Now.ToUniversalTime().ToString("yyyyMMddTHHmmss"+ "Z");
            output.WriteLine(
"CATEGORIES:APPOINTMENT;PERSONAL");
            output.WriteLine(EncodeProperty(
"DESCRIPTION;ENCODING=QUOTED-PRINTABLE:", description));
            output.WriteLine(
"DTEND:" + endtime.ToUniversalTime().ToString("yyyyMMddTHHmmss"+ "Z");
            
if (!(location == null))
            
{
                output.WriteLine(EncodeProperty(
"LOCATION;ENCODING=QUOTED-PRINTABLE:", location));
            }

            output.WriteLine(
"PRIORITY:0");
            output.WriteLine(
"DTSTART:" + starttime.ToUniversalTime().ToString("yyyyMMddTHHmmss"+ "Z");
            output.WriteLine(
"STATUS:NEEDS ACTION");
            output.WriteLine(EncodeProperty(
"SUMMARY;ENCODING=QUOTED-PRINTABLE:", title));
            output.WriteLine(
"URL:" + url);
            output.WriteLine(
"END:VEVENT");
            output.WriteLine(
"END:VCALENDAR");
        }

        connection.Close();
    }


 
string EncodeProperty(string key, string value) 
 

   StringBuilder sb 
= new StringBuilder(); 
   sb.Append(key); 
   sb.Append(value); 
   sb.Replace(
";""\\;", key.Length, sb.Length - key.Length); 
   sb.Replace(
"\r\n""=0D=0A"); 
   
int offset = 76
   
while (offset < sb.Length) 
     
int pos = sb.ToString(offset - 510).IndexOf("=0D=0A"); 
     
if (pos == -1
       sb.Insert(offset 
- 5 + pos, "=" + "\r\n"); 
       offset 
+= 79 - 5 + pos; 
     }
 else 
       sb.Insert(offset, 
"=" + "\r\n"); 
       offset 
+= 79
     }
 
   }
 
   
return sb.ToString(); 
 }
 

}


5.

posted on 2006-09-07 22:45  cobbles  阅读(374)  评论(0编辑  收藏  举报