using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Configuration;

/// <summary>
///AutoCompleteDemo1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。 
 [System.Web.Script.Services.ScriptService]
public class AutoCompleteDemo1 : System.Web.Services.WebService {

    public AutoCompleteDemo1 () {

        //如果使用设计的组件，请取消注释以下行 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string[] GetData(string prefixText)
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["constring"].ConnectionString);

        string strsql = "select gid,GoodsName,price from v_tabG_inventory where GoodsName like  '%" + prefixText + "%'and Quantity > 0 and state = 0  ";

        string strnameid;
        SqlCommand cmd = new SqlCommand(strsql, conn);

        List<string> items = new List<string>();

        conn.Open();

        using (SqlDataReader dr = cmd.ExecuteReader())
        {
            while (dr.Read())
            {

                // strnameid = Convert.ToString(dr["GoodsName"]) + "    " + Convert.ToString(dr["goodprice"]) + "元 物品编码" + Convert.ToString(dr["gid"]);
                strnameid = Convert.ToString(dr["GoodsName"]);
                items.Add(strnameid);

            }
        }

        //return new string[] {prefixText+"111",prefixText+"222"};

        conn.Close();
        return items.ToArray();
    }

}
