using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
using EF.BLL;
using EF.DAL;
namespace EF.APP
{
/// <summary>
/// SearchTeachingClass 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
[System.Web.Script.Services.ScriptService]
public class SearchTeachingClassService : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
/// <summary>
/// 主要是这个方法就是查询数据变为一个字符数组。
/// </summary>
/// <param name="q"></param>
/// <returns></returns>
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string[] GetData(string q)
{
var s = q.Split('#')[0].ToUpper();
var semesterID = Convert.ToInt32(q.Split('#')[1]);
var data = new List<string>();
var db = new EFSystemDataEntities();
using (var teachingClassBll = new TeachingClassBll(db))
{
var query =
teachingClassBll.Filter(
c =>(c.SemesterID==semesterID)&&(c.ClassCode.Contains(s) || c.ClassName.Contains(s) || c.ClassNamePY.Contains(s))).Take(20);
foreach (var teachingClass in query)
{
data.Add(string.Format("{0}#{1}", teachingClass.ClassName, teachingClass.ID));
}
}
return data.ToArray();
}
}