IHttpHandler 在SharePoint中的应用

1. 一个文件名为VCChartHandler.ashx,其文件代码为:

<%@ WebHandler Language="C#"  Class="VCSharePoint.BL.VCHandler,VCSharePoint, 
Version=1.0.0.0, Culture=neutral, PublicKeyToken=0134fd28ed40d3b2"%>

 2. 另一个类为VCHandler.cs的文件,其后台代码为:

using System;

using System.Data;

using System.Collections.Generic;

using System.Text;

using System.Web;





namespace VCSharePoint.BL

{

  public class VCHandler:IHttpHandler

    {

        #region IHttpHandler Members



        public bool IsReusable

        {

            get { return false; }

        }

        public void ProcessRequest(HttpContext context)

        {  



            context.Response.Clear();

            string yearValue = context.Request["Year"] == null ? DateTime.Today.Year.ToString() : context.Request["Year"].ToString();

            string monthValue = context.Request["Month"] == null ? UNITS.GetCurrMonth : context.Request["Month"].ToString();

            string data = string.Empty;

            data = JSONConverter.GetJSONData(GetRankingTable(yearValue, monthValue));

            context.Response.ContentType = "application/json";

            context.Response.ContentEncoding = Encoding.UTF8;

            if (data.Length == 0)

                data = "{\"NoResult\": \"this is no result\"}";   

             context.Response.Write(data);

        }

        private DataTable GetRankingTable(string yearValue,string monthValue)

        {

            BL.BLCalculate BlCinstance = new BLCalculate(yearValue, monthValue);

            return BlCinstance.GetDataCalc();

        }



        #endregion

    }

}



 

 3.  有一个显示文件网页文件为VC Ranking Chart.aspx, 其后台代码为:其引用了一个jQuery库

<%@ Page language="C#" MasterPageFile="~masterurl/default.master"    Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" meta:progid="SharePoint.WebPartPage.Document" %>

<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %> <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Register TagPrefix="QueryControl" TagName="QueryControls" src="~/_controltemplates/QueryControls.ascx"%>

<asp:Content ID="Content1" ContentPlaceHolderId="PlaceHolderPageTitle" runat="server">

	Volunteer Challenge Result

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderId="PlaceHolderPageImage" runat="server"><IMG SRC="/_layouts/images/blank.gif" width=1 height=1 alt=""></asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderId="PlaceHolderPageTitleInTitleArea" runat="server">

	<WebPartPages:WebPartZone runat="server" Title="loc:TitleBar" ID="TitleBar" AllowLayoutChange="false" AllowPersonalization="false"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone>

</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderId="PlaceHolderTitleBreadcrumb" runat="server"/>

<asp:Content ID="Content5" ContentPlaceHolderId="PlaceHolderTitleAreaClass" runat="server">

<style type="text/css">

TD.ms-titleareaframe, .ms-pagetitleareaframe {

	height: 10px;

}

Div.ms-titleareaframe {

	height: 100%;

}

.ms-pagetitleareaframe table {

	background: none;

	height: 10px;

}

</style>

</asp:Content>

<asp:Content ID="Content6" ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">	

    <!-- JS Module-->

    <script type="text/javascript" src="/_layouts/VCCharts/jquery-1.5.2.min.js"> </script>

    <script type="text/javascript" src="/_layouts/VCCharts/highcharts.js"> </script>

    <script type="text/javascript" src="/_layouts/VCCharts/exporting.js"></script>

     <!-- End JS Module-->

     

     <script  type="text/javascript">

    $(function(){                    

       InitalQuery();

       MonthChangeBind(); 

    });

	  

	  function InitalQuery()

	  {

	      var year = $("select[id$='ddlYears']").val();

	      var month = $("select[id$='ddlMonths']").val();

	      var relUrl = $("input[id$='relWebURL']").val();

	      var currentD=new Date();

	      var currentY=currentD.getFullYear();

	      

	      if(currentY==year)

	       $("#reminder").css("display","block");

	      else

	          $("#reminder").css("display","none");



	      generateCharts(relUrl,year,month);

	      

	  }

	  function MonthChangeBind()

	  {

	     $("select[id$='ddlMonths']").change(function()

	     {

	        InitalQuery();

	     });

	  }

	  

	  function generateCharts(webUrl,curYear,curMonth){

      	 $.ajax({

      	        url: webUrl+"/_layouts/VCCharts/VCChartHandler.ashx", 	

      	        type: "POST",

                data: {Year: curYear, Month: curMonth},

                beforeSend: loading,

                success: function(json) {

                    $.each(json,function(key,data){                    

                     if(key =="NoResult")

                     {

                        $("#container").html("<span style='color:red;margin-top:100px; margin-left:200px'>" + data +"</span>");

                     }

                     else

                     {

			                var jsonData=[];

			                var jsonCategories=[];

				            $.each(data,function (key1,data1){	

	                	 	     jsonCategories.push(data1.OfficeName);

	               		         jsonData.push(data1.Ranking);

        	          

	             	        });

    	             	    

	                        //----------Draw Chart----

				            var chart;

				            chart = new Highcharts.Chart({

				            chart: {

					            renderTo: 'container',

					            defaultSeriesType: 'bar'

				            },

				            title: {

						            text: 'Office Ranking for the Volunteer Challenge'

					            },

				            xAxis: {

					            //categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas','Dalles','New York']

					            categories: jsonCategories

				            },

				            yAxis: {

					            min: 0,

					            title: {

						            text: ''

					            }

				            },

				            legend: {

					            backgroundColor: '#FFFFFF',

					            reversed: true

				            },

				            tooltip: {

					            formatter: function() {

						            return ''+

							             this.series.name +': '+ this.y +'';

					            }

				            },

				            plotOptions: {

					            series: {

						            stacking: 'normal'

					            }

				            },

			                    series: [{

			                    name: 'Ranking',

					            //data: [5, 3, 4, 7, 2,3,0.5]

					            data: jsonData

				            }]

			            });    				

			            //--------------End Draw---------------//

			       }

		      });   

             },

		error: function(res) { 

			

			 $("#container").html("<div style='color:red'>There are errors:  "+res+",   Please contact system administrator <div>");

		

		},

		complete: function() {  }

         });

        } 



      //loading function.

	function loading() {

	    $("#container").html("<div style=\"margin-top:100px; margin-left:300px\"><img src='/CSRS/_layouts/images/ewr133.gif' /> </br>loading...</div>");

	} 

	

     </script>     

	<META Name="CollaborationServer" Content="SharePoint Team Web Site">

	<script type="text/javascript">

	var navBarHelpOverrideKey = "wssmain";

	</script>

</asp:Content>

<asp:Content ID="Content7" ContentPlaceHolderId="PlaceHolderSearchArea" runat="server">

	<SharePoint:DelegateControl ID="DelegateControl1" runat="server"

		ControlId="SmallSearchInputBox"/>

</asp:Content>

<asp:Content ID="Content8" ContentPlaceHolderId="PlaceHolderLeftActions" runat="server">

</asp:Content>

<asp:Content ID="Content9" ContentPlaceHolderId="PlaceHolderPageDescription" runat="server"/>

<asp:Content ID="Content10" ContentPlaceHolderId="PlaceHolderBodyAreaClass" runat="server">

<style type="text/css">

.ms-bodyareaframe {

	padding: 0px;

}



</style>

</asp:Content>

<asp:Content ID="Content11" ContentPlaceHolderId="PlaceHolderMain" runat="server">

	<table cellspacing="0" border="0" width="100%">

	  <tr>

	   <td class="ms-pagebreadcrumb" >

		<asp:SiteMapPath SiteMapProvider="SPContentMapProvider" id="ContentMap" SkipLinkText="" NodeStyle-CssClass="ms-sitemapdirectional" runat="server"/>

	   </td>

	  </tr>

	  <tr>

	   <td class="ms-webpartpagedescription">

		<SharePoint:ProjectProperty ID="ProjectProperty1" Property="Description" runat="server"/></td>

	  </tr>

	  <tr>

		<td>

		 <table width="100%" cellpadding=0 cellspacing=0 style="padding: 5px 10px 10px 10px;">

		  <tr>

		    <td colspan="2">

		        <QueryControl:QueryControls id="sQueryControl" runat="server"/>

		    </td>

    	  </tr> 

		  <tr>

		    <td colspan="2">

		        <div id="container" style="margin-top: 20px; margin-left: 20px; width: 700px; height: 600px;">

	            </div>

	            <div id="reminder" style=" color:Red;  font-size:12px; text-align:center;">Note: Current Month will  not be included in Total Ranking.</div>

		    </td>

		    </tr> 

		  <tr>

		    <td valign="top" width="100%">

			   <WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly" ID="Right" Title="loc:Right"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone>

			    

		   </td>

		   <td> </td>

		  </tr>

		 </table>

		</td>

	  </tr>

	</table>

	<input  type="hidden" id="ymTempValue" />

</asp:Content>

 

 

 

你可能感兴趣的:(SharePoint)