1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| using System.Web.Script.Services;
using AjaxControlToolkit;
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data.SqlClient;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
public class ListesAuthentification : System.Web.Services.WebService
{
public CascadingDropDownNameValue[] GetSites(string knownCategoryValues, string category)
{
SqlConnection conn = new SqlConnection(@"data source=JF\PRO; initial catalog=BaseExemples; integrated security=true");
conn.Open();
SqlCommand comm = new SqlCommand("SELECT Code,Libellé FROM Site", conn);
SqlDataReader dr = comm.ExecuteReader();
List<CascadingDropDownNameValue> l = new List<CascadingDropDownNameValue>();
while (dr.Read())
{
l.Add(new CascadingDropDownNameValue(dr["Libellé"].ToString(), dr["Code"].ToString()));
}
conn.Close();
return l.ToArray();
}
[WebMethod]
public CascadingDropDownNameValue[] GetNoms(string knownCategoryValues, string category)
{
int Code;
CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
if (!kv.ContainsKey("Sites") || !Int32.TryParse(kv["Sites"], out Code))
{
throw new ArgumentException("Pas de site");
};
SqlConnection conn = new SqlConnection(@"data source=JF\PRODOQ; initial catalog=BaseExemples; integrated security=true");
conn.Open();
SqlCommand comm = new SqlCommand("SELECT Code,Nom,Prénom FROM Site,AuthProdoq WHERE Code=@Code AND Site.code=AuthProdoq.Code", conn);
comm.Parameters.AddWithValue("@Code", Code);
SqlDataReader dr = comm.ExecuteReader();
List<CascadingDropDownNameValue> l = new List<CascadingDropDownNameValue>();
while (dr.Read())
{
l.Add(new CascadingDropDownNameValue(dr["Nom"].ToString() + " " + dr["Prénom"].ToString(), dr["Code"].ToString()));
}
conn.Close();
return l.ToArray();
}
}//Fin de la classe |
Partager