第一部分:数据库通过存储过程读取数据,通过datatable接受,前台通过asp:repeater.DataSource()和binding()绑定数据

  /// <summary>
/// 分店详情及点评信息
/// </summary>
/// <param name="cityName"></param>
/// <param name="startDate"></param>
/// <param name="endDate"></param>
/// <returns></returns>
public override DataTable BranchListSearchAndReview(string cityName, string startDate, string endDate)
{
DataTable dt = new DataTable("BranchListSearchAndReview");
DataColumn ID = new DataColumn("ID", typeof(int));
DataColumn Name = new DataColumn("Name", typeof(string));
DataColumn CityName = new DataColumn("CityName", typeof(string));
DataColumn Address = new DataColumn("Address", typeof(string));
DataColumn Content = new DataColumn("Content", typeof(string));
DataColumn adjustmentprice = new DataColumn("adjustmentprice", typeof(string));
DataColumn Regional = new DataColumn("Regional", typeof(string));
DataColumn SumBranchReview = new DataColumn("SumBranchReview", typeof(string));
DataColumn ScoreAvg = new DataColumn("ScoreAvg", typeof(string));
DataColumn Cover = new DataColumn("Cover", typeof(string));
DataColumn Longitude = new DataColumn("Longitude", typeof(string));
DataColumn Latitude = new DataColumn("Latitude", typeof(string));
DataColumn PriceSection = new DataColumn("PriceSection",typeof(string));
DataColumn Phone = new DataColumn("Phone",typeof(string));
DataColumn Mobile = new DataColumn("Mobile",typeof(string));
dt.Columns.Add(ID);
dt.Columns.Add(Name);
dt.Columns.Add(CityName);
dt.Columns.Add(Address);
dt.Columns.Add(Content);
dt.Columns.Add(adjustmentprice);
dt.Columns.Add(Regional);
dt.Columns.Add(SumBranchReview);
dt.Columns.Add(ScoreAvg);
dt.Columns.Add(Cover);
dt.Columns.Add(Longitude);
dt.Columns.Add(Latitude);
dt.Columns.Add(PriceSection);
dt.Columns.Add(Phone);
dt.Columns.Add(Mobile);
using (SqlConnection conn = SqlHelper.getConnection())
{
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "sb_branch_search";
cmd.Parameters.Add("@CityName", SqlDbType.NVarChar, ).Value = cityName;
cmd.Parameters.Add("@StartDate", SqlDbType.NVarChar, ).Value = startDate;
cmd.Parameters.Add("@EndDate", SqlDbType.NVarChar, ).Value = endDate;
conn.Open();
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
DataRow dr = dt.NewRow();
dr["ID"] = Convert.ToInt32(sdr["ID"]);
dr["Name"] = sdr["Name"].ToString();
dr["CityName"] = sdr["CityName"].ToString();
dr["Address"] = sdr["Address"].ToString();
if (!string.IsNullOrEmpty(sdr["content"].ToString()))
{
dr["Content"] = sdr["Content"].ToString().Length > ? sdr["Content"].ToString().Substring(, )+"..." : sdr["Content"].ToString();
}
else
{
dr["Content"] = "试过才知道真好!";
}
dr["adjustmentprice"] = sdr["adjustmentprice"].ToString();
dr["Regional"] = sdr["Regional"].ToString();
if (!string.IsNullOrEmpty(sdr["SumBranchReview"].ToString()))
{
dr["SumBranchReview"] = sdr["SumBranchReview"].ToString();
}
else
{
dr["SumBranchReview"] = "";
} if (sdr["ScoreAvg"] != DBNull.Value)
{
dr["ScoreAvg"] = sdr["ScoreAvg"].ToString();
}
else
{
dr["ScoreAvg"] = "";
} //对价格分区域判断 0-300:A ;300-450:B;450-600:C;600+:D 如果有变化要在这里改
//赵坤 20160318
Convert.ToInt32(dr["adjustmentprice"].ToString());
if ( < Convert.ToInt32(dr["adjustmentprice"].ToString()) && Convert.ToInt32(dr["adjustmentprice"].ToString()) <= )
{
dr["PriceSection"] = "A";
}
else if ( < Convert.ToInt32(dr["adjustmentprice"].ToString()) && Convert.ToInt32(dr["adjustmentprice"].ToString()) <= )
{
dr["PriceSection"] = "B";
}
else if ( < Convert.ToInt32(dr["adjustmentprice"].ToString()) && Convert.ToInt32(dr["adjustmentprice"].ToString()) <= )
{
dr["PriceSection"] = "C";
}
else
{
dr["PriceSection"] = "D";
}
dr["Cover"] = sdr["Cover"].ToString();
dr["Longitude"] = sdr["Longitude"].ToString();
dr["Latitude"] = sdr["Latitude"].ToString();
dr["Mobile"] = sdr["Mobile"].ToString();
dr["Phone"] = sdr["Phone"].ToString();
dt.Rows.Add(dr);
}
}
return dt;
}

Dal

   /// <summary>
/// 分店信息
/// </summary>
private void LoadingBranchList()
{
ToolManager.GetParam<string>("cityName", ref cityName);
ToolManager.GetParam<string>("startDate", ref startDate);
ToolManager.GetParam<string>("endDate", ref endDate);
if (ToolManager.CheckParam("StartDate"))
{
if (Convert.ToDateTime(ToolManager.GetParam("StartDate")) >= Convert.ToDateTime(today))
{
startDate = Convert.ToDateTime(ToolManager.GetParam("StartDate")).ToString("yyyy-MM-dd");
}
else
{ }
}
if (ToolManager.CheckParam("EndDate"))
{
if (Convert.ToDateTime(startDate) >= Convert.ToDateTime(ToolManager.GetParam("EndDate")))
{
endDate =Convert.ToDateTime( startDate).AddDays().ToString();
}
else
{
endDate = Convert.ToDateTime(ToolManager.GetParam("EndDate")).ToString("yyyy-MM-dd");
}
}
string cityNameTrue = cityName;
if (cityName == "输入城市名字")
{
cityNameTrue = "";
}
// List<CBranch> branchs= BranchManager.BranchListSearch(cityNameTrue, startDate, endDate);
DataTable dt = BranchManager.BranchListSearchAndReview(cityNameTrue, startDate, endDate);
rptBranch.DataSource = dt;
rptBranch.DataBind();
}

web

第二部分:数据库通过存储过程读取数据,通过dataset接受,前天通过datetable处理后,binding()

  private void LoadBranch()
{
//店名、地址信息、价格(最低价格)、图片信息、房间概述(分店介绍、路线图)、
ToolManager.GetParam<int>("branchID", ref branchID);
ToolManager.GetParam<string>("startDate", ref startDate);
ToolManager.GetParam<string>("endDate", ref endDate);
cb = BranchManager.GetBranch(branchID);
if (cb.ID == )
{
//如果没有传递参数或者参数为总部,则调回首页
Response.Redirect("/default.aspx");
}
else
{
DataTable dt = new DataTable();
List<CRoomPicture> pis = new List<CRoomPicture>();
DataSet ds = BranchManager.GetBranchDetailInfo(branchID);
if (ds.Tables.Count > )
{
dt = ds.Tables[];
if (dt==null||dt.Rows.Count==)
{
Response.Redirect("/default.aspx");
}
else
{
BranchName = dt.Rows[]["BranchName"].ToString();
BranchNameShort = dt.Rows[]["BranchNameShort"].ToString();
Address = dt.Rows[]["Address"].ToString();
Introduction = dt.Rows[]["Introduction"].ToString().Trim();
Traffic = dt.Rows[]["Traffic"].ToString().Trim();
MapAddress = dt.Rows[]["MapAddress"].ToString();
string[] trafficc = Traffic.Split('|');//交通
for (int i = ; i < trafficc.Length; i++)
{
strTrafficcMap = strTrafficcMap + "<li>" + trafficc[i] + "</li>";
}
adjustmentprice = dt.Rows[]["adjustmentprice"].ToString();
ScoreAvg = dt.Rows[]["ScoreAvg"].ToString();
Latitude = dt.Rows[]["Latitude"].ToString();
Longitude = dt.Rows[]["Longitude"].ToString();
CityName = dt.Rows[]["CityName"].ToString();
Phone = dt.Rows[]["Phone"].ToString();
//pics = ds.Tables[1];
DataTable dt1 = new DataTable();
dt1 = ds.Tables[];
//for (int i = 0; i < ds.Tables[1].Rows.Count; i++)
//{
// //数据库中必须有八个
// if (i>8)
// {
// break;
// }
// //CRoomPicture cs = new CRoomPicture();
// //cs.ID = (int)dt1.Rows[i]["ID"];
// //cs.RoomID = (int)dt1.Rows[i]["RoomID"];
// //cs.MasterPath = dt1.Rows[i]["MasterPath"].ToString().Replace("~", "");
// //cs.ThumbnailsUrl = dt1.Rows[i]["ThumbnailsUrl"].ToString();
// //cs.AttachmentUrl = dt1.Rows[i]["AttachmentUrl"].ToString();
// //cs.Description = dt1.Rows[i]["Description"].ToString();
// //pis.Add(cs);
//}
pis = (List<CRoomPicture>)ConvertToModel(dt1);
} }
ImgRepeater.DataSource = pis;
ImgRepeater.DataBind();
}
}

web

  //获取detail页面详情
public override DataSet GetBranchDetailInfo(int branchId)
{
DataSet ds=new DataSet ();
List<CRoomPicture> pics = new List<CRoomPicture>();
using (SqlConnection conn=SqlHelper.getConnection())
{
SqlParameter param = new SqlParameter("@BranchID", branchId);
ds = SqlHelper.ExecuteDataset(conn, CommandType.StoredProcedure, "sb_branch_img_Booking_review", param);
conn.Close();
}
return ds;
}

Dal

存储过程

存储过程一:实用技术包括inner join 、cast round sum count float 组合取保留两位小数的平均数

 USE [ttrj]
GO
/****** Object: StoredProcedure [dbo].[sb_branch_search] Script Date: 04/18/2016 09:57:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[sb_branch_search]
@CityName nvarchar(),
@StartDate nvarchar(),
@EndDate nvarchar()
as
begin
set nocount on
declare @where nvarchar()
declare @sql nvarchar()
set @where='where 1=1 and h.isvalid=1'
if @CityName <> ''
set @where=@where+' and c.Name='''+@CityName+''''
if @StartDate <> ''
set @where=@where+' and e.date>='''+@StartDate+''''
if @EndDate <> ''
set @where=@where+' and e.date<'''+@EndDate+''''
set @sql='select h.id,max(b.id) as branchID,avg(h.MemberPrice+e.adjustmentprice) as adjustmentprice from branch b left join dbo.HouseUnit h on b.id=h.branchID left join T_city c on b.cityID=c.id left join Ebooking e
on b.id=e.branchID '+@where+' and b.id<> group by b.id,h.id order by b.id'
declare @TempIds Table
(
Id int,
branchID int,
adjustmentprice float,
Pos int identity(,)
)
insert into @TempIds
exec(@sql)
if @CityName <> ''
begin
insert into @TempIds
select isnull(h.id,),b.ID,isnull(h.memberPrice,) from Branch b left join HouseUnit h on b.id=h.branchID left join T_city c on b.cityID=c.id where b.isApproved= and b.ID<> and h.isvalid= and c.Name=convert(nvarchar(),@CityName) and isnull(h.id,) not in (select id from @TempIds)
end
else
begin
insert into @TempIds
select isnull(h.id,),b.ID,isnull(h.memberPrice,) from Branch b left join HouseUnit h on b.id=h.branchID where b.isApproved= and b.ID<> and h.isvalid= and isnull(h.id,) not in (select id from @TempIds)
end
--开始 对返回结果重新编辑,减少b表中返回数据,增加了一个试图的(分店点评总数、均分、最后评价),赵坤,
select b.*,
isnull(a.adjustmentprice,) as adjustmentprice,c.[Name] as cityName,r.Content,r.SumBranchReview,r.ScoreAvg
from branch b inner join T_City c
on b.cityID=c.ID inner join dbo.Vi_GetBranch_ReviewInfo r on b.ID=r.BranchID,(select branchID,min(adjustmentprice) adjustmentprice from @TempIds group by branchID) a
where b.id=a.branchid and b.isapproved= and b.foregroundShow= order by b.SysOrder desc
--结束 对返回结果重新编辑
end

存储过程(一)

 SELECT     br.ReviewID, br.BranchID, br.ScoreAvg, br.SumBranchReview, tr.[Content]
FROM dbo.T_Review AS tr INNER JOIN
(SELECT MAX(r.ID) AS ReviewID, b.BranchID, COUNT(r.ID) AS SumBranchReview,
ISNULL(CAST(ROUND((SUM(r.CleanScore + r.ComfortScore + r.ServiceScore + r.SleepScore + r.InternetScore + r.InAndOutScore + r.EquipmentScore + r.ChannelServiceScore)
* 1.0) / (COUNT(r.ID) * ), ) AS float), ) AS ScoreAvg
FROM dbo.T_Review AS r INNER JOIN
dbo.T_Bill AS b ON r.BillID = b.ID
WHERE (r.ReviewType = '') OR
(r.ReviewType = '')
GROUP BY b.BranchID) AS br ON tr.ID = br.ReviewID

试图(一)

存储过程二:inner join

 USE [ttrj]
GO
/****** Object: StoredProcedure [dbo].[sb_branch_img_Booking_review] Script Date: 04/18/2016 10:01:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <赵坤,,Name>
-- Create date: <--,,>
-- Description: <查询detail页面中详细信息、图片信息、预定信息、>
-- =============================================
ALTER PROCEDURE [dbo].[sb_branch_img_Booking_review]
@BranchID int
AS
BEGIN
--详细信息
select brr.*,brs.ScoreAvg from (SELECT d.ID,d.CityName,d.BranchName,d.Phone,d.BranchNameShort,d.MapAddress,d.Address,d.Introduction,d.Traffic,f.adjustmentprice,d.Longitude,d.Latitude from
(select br.ID,ci.name as CityName,ci.name+'天天如家'+br.Name as BranchName,br.Name as BranchNameShort,br.Phone,br.MapAddress,br.Address,br.Introduction,br.Traffic,br.Longitude,br.Latitude
from branch br inner join T_city ci on br.cityid=ci.id where br.id=@BranchID ) d
,( select top avg(h.MemberPrice+e.adjustmentprice) as adjustmentprice,max(h.branchID) as branchID
from dbo.HouseUnit h left join Ebooking e on h.branchID=e.branchID where h.branchID=@BranchID and h.isvalid= group by h.id order by adjustmentprice asc)
f where d.ID=f.BranchID) brr ,( SELECT b.BranchID,ISNULL(CAST(ROUND(SUM(r.CompositeScore) * 1.0 / COUNT(r.ID), ) AS float), ) AS ScoreAvg
FROM dbo.T_Review AS r LEFT OUTER JOIN dbo.T_Bill AS b ON r.BillID = b.ID
WHERE (r.ReviewType = '') OR(r.ReviewType = '')
GROUP BY b.BranchID) brs where brs.BranchId=brr.ID
--图片
select top r.ID,r.RoomID,MasterPath=replace(r.MasterPath,'~',''),r.ThumbnailsUrl,r.AttachmentUrl,r.Description from T_RoomPicture r inner join HouseUnit h on r.RoomID=h.id where h.BranchID=@BranchID END

存储过程(二)

datatable dateset 载体传递数据、存储过程的更多相关文章

  1. WCF分布式开发步步为赢(8):使用数据集(DataSet)、数据表(DataTable)、集合(Collection)传递数据

    数据集(DataSet).数据表(DataTable).集合(Collection)概念是.NET FrameWork里提供数据类型,在应用程序编程过程中会经常使用其来作为数据的载体,属于ADO.NE ...

  2. 将list<对象>转换成DataTable,把DataTable转换成参数传入存储过程实现批量插入数据

    领导让在存储过程中批量添加数据,找出效率最高的,我看到后台代码后,发现可以将list<对象>转换成DataTable,把DataTable转换成参数传入存储过程实现批量插入数据,知道还有其 ...

  3. SQLserver2008如何把表格变量传递到存储过程中

    在Microsoft SQL Server 2008中,你可以实现把表格变量传递到存储过程中,如果变量可以被声明,那么它就可以被传递.下面我们来具体介绍如何把表格变量(包括内含的数据)传递到存储过程和 ...

  4. 【ASP.NET MVC】View与Controller之间传递数据

    1   概述 本篇文章主要从操作上简要分析Controller<=>View之间相互传值,关于页面之间传值,如果感兴趣,可参考我另外一篇文章ASP.NET 页面之间传值的几种方式 . Co ...

  5. 【ASP.NET MVC系列】浅谈ASP.NET MVC 视图与控制器传递数据

    ASP.NET MVC系列文章 [01]浅谈Google Chrome浏览器(理论篇) [02]浅谈Google Chrome浏览器(操作篇)(上) [03]浅谈Google Chrome浏览器(操作 ...

  6. Android中Service通信(一)——启动Service并传递数据

    启动Service并传递数据的小实例(通过外界与服务进行通信): 1.activity_main.xml: <EditText android:layout_width="match_ ...

  7. angular input标签只能单向传递数据的问题

    angularjs input标签只能单向传递数据的问题 <ion-view title = "{{roomName}}" style = "height:90%; ...

  8. activity与fragment之间传递数据

    总结:无论是activity给fragment传递数据,还是fragment给activity传递数据,都把activity和fragment都当做一个普通的对象,调用它的方法,传递参数. 1.Fra ...

  9. android跟服务器使用json传递数据

    最近在做项目,使用了json传递数据,把服务器对象转换成json字符串返回,android使用gson包解析json字符串变成对象. 1.服务器代码编写,我这边是在servlet里面 Peron pe ...

随机推荐

  1. UML图示与代码对照

    本文转载:http://www.cnblogs.com/iamlilinfeng/archive/2012/08/29/2662740.html 一.类继承 1 public class Father ...

  2. Selenium 中使用方法小结

    --> 文本框 中填写 文本信息 basePage.getTXTPortfolio().sendKeys("文本信息"); --> 点击某个 文本框/下拉列表 中的 指 ...

  3. PHP+MySQL多语句执行<转自wooyun>

    发起这个帖子,估计就很多人看到题目就表示不屑了.一直以来PHP+MySQL环境下,无论是写程序或者是注入攻击,是无法多语句执行的,这么广为人知的常识,没理由会有人不知道.可权威就是用来被挑战的,常识也 ...

  4. PostgreSQL中如何查询在当前的哪个数据库中

    [pgsql@localhost bin]$ ./psql -d tester psql () Type "help" for help. tester=# select curr ...

  5. HTML输出 一 控制列背景颜色

    #将需要读取的域名和端口列表保存在名为ports01.txt.ports02的文件中,文件与脚本位于相同目录下$CurrentPath = $MyInvocation.MyCommand.Path.s ...

  6. socket.io+angular.js+express.js做个聊天应用(一)

    node,express开发环境等安装如果已经搞好了. justhacker@justhacker-ThinkPad-Edge-E440:~/projects/nodejs$ express -e c ...

  7. httpclient发送request请求时设置header和timeout

    package com.xxx.xxx.common; import java.io.BufferedReader; import java.io.InputStreamReader; import ...

  8. GLSL实现简单硬件Anisotrop Lighting 【转】

    http://blog.csdn.net/a3070173/archive/2008/11/13/3294660.aspx 各向异性光照往往用于处理一些具有各向异性表面的物体,如:光盘的盘面.为避免在 ...

  9. delphi TTreeView组件遍历磁盘目录

    TTreeView组件遍历磁盘目录 实例说明 TTreeView组件是一个以分枝结构或者说树状结构显示数据的组件,以该组件显示数据具有较好的等级关系和逻辑层次,并且易于操作.在组件中显示的数据结构与系 ...

  10. Logistic回归总结

    原文:http://blog.csdn.net/dongtingzhizi/article/details/15962797  Logistic回归总结 作者:洞庭之子 微博:洞庭之子-Bing (2 ...