62,268
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
/// <summary>
///GetProducts 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class GetProducts : System.Web.Services.WebService {
public GetProducts () {
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public string[] GetProductList(string prefixText ,int count)
{
Product p = new Product();
SqlDataAdapter da = p.GetProduct();
DataSet ds = new DataSet();
da.Fill(ds);
int j = 0;
int sum = ds.Tables[0].Rows.Count;
int length = prefixText.Length;
List<string> products = null;
//string[] products = new string[sum];
for (int i = 0; i < sum; i++)
{
string SortID = ds.Tables[0].Rows[i]["SortID"].ToString();
string Name = ds.Tables[0].Rows[i]["Name"].ToString();
string Brand = ds.Tables[0].Rows[i]["Brand"].ToString();
string Type = ds.Tables[0].Rows[i]["Type"].ToString();
if (SortID.Substring(0, length).ToString() == prefixText || SortID.Substring(0, length).ToString().ToLower() == prefixText)
{
try
{
products.Add(SortID);
j++;
if (j > (count-1))
{
break;
}
}
catch (System.Web.Services.Protocols.SoapException err)
{
string strerr = err.Message + err.Detail.InnerText;
}
}
if (Name.Substring(0, length).ToString() == prefixText || Name.Substring(0, length).ToString().ToLower() == prefixText)
{
try
{
products.Add(Name);
j++;
if (j > (count - 1))
{
break;
}
}
catch (System.Web.Services.Protocols.SoapException err)
{
string strerr = err.Message + err.Detail.InnerText;
}
}
if (Brand.Substring(0, length).ToString() == prefixText || Brand.Substring(0, length).ToString().ToLower() == prefixText)
{
try
{
products.Add(Brand);
j++;
if (j > (count - 1))
{
break;
}
}
catch (System.Web.Services.Protocols.SoapException err)
{
string strerr = err.Message + err.Detail.InnerText;
}
}
if (Type.Substring(0, length).ToString() == prefixText || Type.Substring(0, length).ToString().ToLower() == prefixText)
{
try
{
products.Add(Type);
j++;
if (j > (count - 1))
{
break;
}
}
catch (System.Web.Services.Protocols.SoapException err)
{
string strerr = err.Message + err.Detail.InnerText;
}
}
}
string[] product = products.ToArray();
return product;
}
}
if (SortID.Substring(0, length).ToString() == prefixText || SortID.Substring(0, length).ToString().ToLower() == prefixText)
{
try
{
products.Add(SortID);
j++;
if (j > (count-1))
{
break;
}
}
catch (System.Web.Services.Protocols.SoapException err)
{
string strerr = err.Message + err.Detail.InnerText;
}
}
if (Name.Substring(0, length).ToString() == prefixText || Name.Substring(0, length).ToString().ToLower() == prefixText)
{
try
{
products.Add(Name);
j++;
if (j > (count - 1))
{
break;
}
}
catch (System.Web.Services.Protocols.SoapException err)
{
string strerr = err.Message + err.Detail.InnerText;
}
}
if (Brand.Substring(0, length).ToString() == prefixText || Brand.Substring(0, length).ToString().ToLower() == prefixText)
{
try
{
products.Add(Brand);
j++;
if (j > (count - 1))
{
break;
}
}
catch (System.Web.Services.Protocols.SoapException err)
{
string strerr = err.Message + err.Detail.InnerText;
}
}
if (Type.Substring(0, length).ToString() == prefixText || Type.Substring(0, length).ToString().ToLower() == prefixText)
{
try
{
products.Add(Type);
j++;
if (j > (count - 1))
{
break;
}
}
catch (System.Web.Services.Protocols.SoapException err)
{
string strerr = err.Message + err.Detail.InnerText;
}
}