Delphi 7前瞻:将Delphi作为ASP.NET的脚本语言(下) (转)

Delphi 7前瞻:将Delphi作为ASP.NET的脚本语言(下) (转)[@more@]

更高技术的网页
ASP.NET的一些控件远比HTML控件要更加智能化。其中之一就是日历(Calendar)控件。

以下代码是calendar.aspx中的一部分。代码提供二种方法让控件设置日期:
 浏览日历然后选择日期;
 按照日期格式输入日期,确认选择。这种方法由.NET的Convert类支持。

procedure Button1Click(Sender: System.Object; E:EventArgs);
begin
  Calendar1.VisibleDate := System.Convert.ToDateTime(Edit1.Text);
  Label1.Text := 'Delphi for .NET says you set ' + Calendar1.VisibleDate.ToString('D');
end;


  RM runat="server">
 

 

Delphi for .NET running in ASP.net


 

Please pick a date


    OnSelectionChanged="Calendar1Selected">
 
 
 
 
 
 
 
 


 
 


 


 

 

在日历上选择日期触发OnSelectionChanged事件,调用Delphi的Calendar1Selected()过程。
输入日期,点击"Set data"按钮触发Button1Click事件,调用Delphi的Button1Click()过程。

数据处理
现在通过日历的日期选择来选择显示数据库数据。在这个ASP.NET Delphi网页上,增加一个DataGrid和一个TextBox,前者显示数据库数据,后者输入要显示的数据库域。

<Mailto:%@Import" rel="nofollow">%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.sqlClient"%>

procedure DateSelected(Sender: System.Object; E: EventArgs);
begin
  Label1.Text := ProdName + ' says you picked ' + Calendar1.SelectedDate.ToString('D');
  DataGrid1.Datasource := GetOrders(Calendar1.SelectedDate);
  DataGrid1.DataBind;
end;

procedure Button1Click(Sender: System.Object; E:EventArgs);
begin
  Calendar1.VisibleDate := System.Convert.ToDateTime(Edit1.Text);
  Label1.Text := ProdName + ' says you set ' + Calendar1.VisibleDate.ToString('D');
end;

procedure Button2Click(Sender: System.Object; E:EventArgs);
begin
  DisplayFields.Text := DispFields;
end;

function GetOrders(Date : DateTime) : DataSet;
var
  Adapter : SqlDataAdapter;
begin
  Adapter := SqlDataAdapter.Create(
  'select ' + DisplayFields.Text + ' from Orders '+
  'where OrderDate = ''' + date.ToString('d')+'''',
  'Server=(local);Database=Northwind;Trusted_Connection=yes');
  Result := DataSet.Create;
  Adapter.Fill(Result);
end;


 
 

with a Calendar, DataGrid, & SqlClient in ASP.NET


 

 

Pick a date


    OnSelectionChanged="DateSelected">
 
 
 
 
 
 
 
 


 
 


 

 

Display fields:   text="OrderID, CustomerID, ShipName, ShipCity, ShipCountry" width=500 runat="server"/>
 


 
 
 
 

 


 

每当用户点击日历选择日期时,就触发OnSelectionChanged事件,调用DateSelected()函数
在GetOrders函数中,数据库的连接由命名空间定义的SqlClient实现,数据库是MS SQL 2000的示范库Northwind。SqlDataAdapter将查询结果安装到DataGrid中,显示出数据表格,如附图。

改变域输入框的域名,再点击日历,就得到不同的结果。

这就是日历驱动的数据库查询系统,由Delphi for .NET与ASP.NET共同完成。

结语
本文试图简略说明在ASP.NET中应用Delphi是如何方便。
请记住,本文示例是Delphi 7的预览示例,正式版本的结果也许不完全如此,当然也许就是如此。


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752043/viewspace-992848/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10752043/viewspace-992848/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值