demomethods.cs

来自「ajax是未来之星」· CS 代码 · 共 110 行

CS
110
字号
// *******************************************************************************************
//
// Ajax.NET Professional - The free AJAX implementation for the Microsoft.NET Framework
//
// Copyright (C) 2005 Michael Schwarz, info@schwarz-interactive.de
//
// *******************************************************************************************
using System;

namespace AjaxProSample.NamespaceTest.Demo
{
	/// <summary>
	/// Summary description for DemoMethods.
	/// </summary>
	public class DemoMethods
	{
		[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
		public void Test5(string s)
		{
			System.Web.HttpContext.Current.Session["example"] = s;
		}

		[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.Read)]
		public string Test6()
		{
			if(System.Web.HttpContext.Current.Session["example"] != null)
				return (string)System.Web.HttpContext.Current.Session["example"].ToString();

			return "First set the value...";
		}

		[AjaxPro.AjaxMethod]
		public DateTime GetServerTime()
		{
			return DateTime.Now;
		}

		[AjaxPro.AjaxMethod]
		public DateTime PutServerTime(DateTime d)
		{
			return d;
		}

		[AjaxPro.AjaxMethod]
		public string GetDateStringOnServer(DateTime d)
		{
			return d.ToString();
		}

		[AjaxPro.AjaxMethod]
		public string PutTwoServerTimes(DateTime d1, DateTime d2)
		{
			return d1.ToString() + "\r\n" + d2.ToString();
		}

		[AjaxPro.AjaxMethod]
		public IPerson GetPerson(int id)
		{
			if(id == 1)
			{
				IPerson b = new IPerson();

				b.FirstName = "Tanja";
				b.FamilyName = "Schwarz";
				b.Age = 25;
				b.Gender = GenderType.Female;

				return b;
			}

			IBoss p = new IBoss();

			p.FirstName = "Michael";
			p.FamilyName = "Mustermann";
			p.Age = 28;
			p.Company = "My Company GmbH Co.KG";
			p.Gender = GenderType.Male;

			return p;
		}

		[AjaxPro.AjaxMethod]
		public bool IsBoss(IPerson p)
		{
			return p.GetType() == typeof(IBoss);
		}
	}

	[AjaxPro.AjaxClass]
	public class IPerson
	{
		public string FirstName;
		public string FamilyName;
		public int Age = 0;
		public GenderType Gender = GenderType.Unknown;
	}

	public class IBoss : IPerson
	{
		public string Company;
	}

	public enum GenderType
	{
		Male,
		Female,
		Unknown
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?