复制代码 代码如下:
public class returnresult
{
public int curindex { get; set; }
public datatable idxlist { get; set; }
}
//测试数据库连接
[webmethod(description = "!!!测试数据库连接,链接字符串在web.config中")]
public bool conectdb()
{
strcon = configurationsettings.appsettings["sqlconduke"];
conn = new sqlconnection(strcon);
try
{
conn.open();
return true;
}
catch (exception)
{
return false;
}
finally
{
conn.close();
}
}
复制代码 代码如下:
[webmethod(description = "根据 照片名 获得详细数据(datatable),strtb,eg:panview;strimgname,eg:20131019072740-0000150")]
public datatable getinfobyimgname(string strtb, string strimgname)
{
bool ifcon = conectdb();
if (ifcon)
{
string sql_bfcar = "select * from dbo." strtb " where imagename like '%" strimgname "%'";
da = new sqldataadapter(sql_bfcar, conn);
myds = new dataset();
da.fill(myds);
return myds.tables[0];
}
else
{
return null;
}
}
[webmethod(description = "根据 照片名 获得所在link的所有数据(returnresult),strtb,eg:panview;strimgname,eg:20131019072740-0000150")]
public returnresult getlinkdtbyimgname(string strtb, string strimgname)
{
returnresult returnresult = new returnresult();
bool ifcon = conectdb();
if (ifcon)
{
returnresult.curindex = convert.toint32(getinfobyimgname(strtb, strimgname).rows[0][0]);
string strlinkguid = getinfobyimgname(strtb, strimgname).rows[0][1].tostring();
string sql_bfcar = "select * from dbo." strtb " where linkguid like '%" strlinkguid "%'";
da = new sqldataadapter(sql_bfcar, conn);
myds = new dataset();
da.fill(myds);
returnresult.idxlist = myds.tables[0];
return returnresult;
}
else
{
return null;
}
}
flex代码:
复制代码 代码如下:
xmlns:mx="library://ns.adobe.com/flex/mx" minwidth="955" minheight="600" creationcomplete="application1_creationcompletehandler(event)">
import mx.collections.arraycollection;
import mx.controls.alert;
import mx.events.flexevent;
import mx.rpc.events.faultevent;
import mx.rpc.events.resultevent;
public var arr:arraycollection=new arraycollection();
public var aaa:string=new string();
protected function webservice1_faulthandler(event:faultevent):void
{
alert.show(event.fault.tostring());
}
protected function getlinkdtbyimgnamehandler(event:resultevent):void
{
// aaa=this.myweb.getlinkdtbyimgname.lastresult.curindex;
// arr=this.myweb.getlinkdtbyimgname.lastresult.idxlist.tables.table.rows;
aaa=event.result.curindex;
arr=event.result.idxlist.tables.table.rows;
alert.show(aaa " " arr.length.tostring());
}
protected function application1_creationcompletehandler(event:flexevent):void
{
myweb.getlinkdtbyimgname("panview","20131019072740-0000150");
}
]]>