学习资料搜集--从后台取数据填充下拉框
数据层
1
public DataSet GetAllQuoter()
2
{
3
StringBuilder commandText = new StringBuilder("SELECT distinct ReportMain.FromName FROM ReportMain ");
4
DataSet ds = new DataSet();
5
SqlConnection Conn = null;
6
try
7
{
8
if (Connection==null)
9
{
10
Conn = new SqlConnection(strConn);
11
Conn.Open();
12
}
13
else
14
Conn = (SqlConnection)Connection;
15
SqlCommand DSCmd = new SqlCommand(commandText.ToString(),Conn);
16
if (Transaction!=null)
17
DSCmd.Transaction = (SqlTransaction)Transaction;
18
19
SqlDataAdapter DBAdopter = new System.Data.SqlClient.SqlDataAdapter(DSCmd);
20
DBAdopter.Fill(ds);
21
}
22
catch (Exception e)
23
{
24
throw new Exception(e.Message);
25
}
26
finally
27
{
28
if (Conn!=null&&Connection==null) Conn.Close();
29
}
30
return ds;
31
}
32
33
public DataSet GetAllQuoter()2
{3
StringBuilder commandText = new StringBuilder("SELECT distinct ReportMain.FromName FROM ReportMain ");4
DataSet ds = new DataSet();5
SqlConnection Conn = null;6
try7
{8
if (Connection==null)9
{10
Conn = new SqlConnection(strConn);11
Conn.Open();12
}13
else14
Conn = (SqlConnection)Connection;15
SqlCommand DSCmd = new SqlCommand(commandText.ToString(),Conn);16
if (Transaction!=null)17
DSCmd.Transaction = (SqlTransaction)Transaction;18

19
SqlDataAdapter DBAdopter = new System.Data.SqlClient.SqlDataAdapter(DSCmd);20
DBAdopter.Fill(ds);21
}22
catch (Exception e)23
{24
throw new Exception(e.Message);25
}26
finally27
{28
if (Conn!=null&&Connection==null) Conn.Close();29
}30
return ds;31
}32

33

BPO
1
/// <summary>
2
/// 取得所有的报价人
3
/// </summary>
4
/// <returns></returns>
5
[WebMethod(EnableSession = true)]
6
public string GetAllQuoters()
7
{
8
DBLayer.ReportMain report = new ReportMain();
9
DataSet ds = report.GetAllQuoter();
10
DataTable dt = ds.Tables[0];
11
string str = "|";
12
foreach(DataRow dr in dt.Rows)
13
{
14
str = str + dr[0].ToString()+"|";
15
}
16
str = str.Substring(0,str.Length-1);
17
return str;
18
}
19
/// <summary>2
/// 取得所有的报价人3
/// </summary>4
/// <returns></returns>5
[WebMethod(EnableSession = true)]6
public string GetAllQuoters()7
{8
DBLayer.ReportMain report = new ReportMain();9
DataSet ds = report.GetAllQuoter();10
DataTable dt = ds.Tables[0];11
string str = "|";12
foreach(DataRow dr in dt.Rows)13
{14
str = str + dr[0].ToString()+"|";15
}16
str = str.Substring(0,str.Length-1);17
return str;18
}19

前端HTC
1
function CallGetAllQuoters()
2
{
3
this.ServiceHandle=eval(ServiceID);
4
if(ServiceHandle!=null)
5
{
6
ServiceHandle.useService(theBPOName+".asmx?WSDL",theBPOName+"Service");
7
var srv=eval("ServiceHandle."+theBPOName+"Service");
8
ObjectGetAllQuotersTask.CallID=srv.callService("GetAllQuoters");
9
}
10
}
11
12
function DoResultGetAllQuoters()
13
{
14
this.DoResult = function(result)
15
{
16
if(result.error==false)
17
{
18
var piArray = result.value.split("|");
19
for(var i=0;i<piArray.length;i++)
20
{
21
e = document.createElement("OPTION")
22
e.text = piArray[i];
23
e.value = piArray[i];
24
Form1.FromNameEdit0.add(e);
25
}
26
27
}
28
}
29
}
function CallGetAllQuoters()2
{3
this.ServiceHandle=eval(ServiceID);4
if(ServiceHandle!=null)5
{6
ServiceHandle.useService(theBPOName+".asmx?WSDL",theBPOName+"Service");7
var srv=eval("ServiceHandle."+theBPOName+"Service");8
ObjectGetAllQuotersTask.CallID=srv.callService("GetAllQuoters");9
}10
}11

12
function DoResultGetAllQuoters()13
{14
this.DoResult = function(result)15
{16
if(result.error==false)17
{18
var piArray = result.value.split("|");19
for(var i=0;i<piArray.length;i++)20
{21
e = document.createElement("OPTION")22
e.text = piArray[i];23
e.value = piArray[i];24
Form1.FromNameEdit0.add(e);25
}26

27
}28
}29
}


浙公网安备 33010602011771号