当管理员单击开始统计按钮时将触发Calculate_Click事件其代码如程序所示
程序 ST_TurnOverStatModuleascxcs
…
private void Calculate_Click(object sender SystemEventArgs e)
{
dg_TurnOverListCurrentPageIndex=;
//从文件WebConfig中读取连接字符串
string ST_sqldb =
ConfigurationSettingsAppSettings[ConnectionString];
//连接ST_GinShopManage数据库
SqlConnection ST_Conn = new SqlConnection (ST_sqldb)
//定义SQL语句
String ST_selsql=select hST_BeginTimehST_EndTime
hST_RoomIdcST_NamehST_CNamehST_CIdent
ityIdhST_CPhonehST_TotalPrice+
from ST_History hST_RoomsInfo rST_RoomCategory c where
rST_RoomId=hST_RoomId and rST_RCategoryId=cST_RCategoryId;
//获取选择的时间
string datefrom=YearFromListSelectedItemValueToString()
++MouthFromListSelectedItemValueToString()
++DayFromListSelectedItemValueToString()
dateto=YearToListSelectedItem
stringValueToString()
++MouthToListSelectedItemValueToString()
++DayToListSelectedItemValueToString()
ST_selsqlST_selsql=ST_selsql+ and hST_BeginTime between
+datefrom+and+dateto+;
//获取选择的方式
if(RCategoryNameListSelectedIndex!=)
{
ST_selsqlST_selsql=ST_selsql+ and
cST_RCategoryId=+RCategoryNameListSelectedIndex+;
}
//创建SqlDataAdapter对象调用ST_selsql
SqlDataAdapter ST_myadapter = new SqlDataAdapter
(ST_selsqlST_Conn)
//创建并填充DataSet
DataSet ds = new DataSet ()
ST_myadapterFill (ds)
dg_TurnOverListDataSource =ds;
dg_TurnOverListDataBind ()
//计算营业额
double SumPrice=;
for(int i=;i<dg_TurnOverListRowsCount;i++){
DataRow dr=dsTables[]Rows[i];
SumPriceSumPrice=SumPrice+ConvertToDouble(
dr[ST_TotalPrice]ToString())}
TurnOverLabelText=SumPriceToString()
//关闭ST_Conn
ST_ConnClose ()
private void ShowAll_Click(object sender SystemEventArgs e)
{
Show_TurnOverList()
}
…
【代码说明】上述代码将页面中的各个控件的值作为条件加入到SQL语句然后进行查询再将数据显示出来此外还统计了营业额即对dg_TurnOverList中的金额列的值进行求和将其值用TurnOverLabel的Text属性显示出来
注意GridView的每一行都是一个DataRow类
返回目录ASPNET项目开发指南
编辑推荐
ASPNET MVC 框架揭秘
ASPNET开发宝典
ASP NET开发培训视频教程
[] []