各位大侠,小弟最近才接触三层架构,遇到个疑问。BLL: public D_BL.BLCollection GetAllBL(M_BL1 bl1)
{
return new D_BL().GetAllBL(bl1);
}DAL:public BLCollection GetAllBL(M_BL1 bl1)
{
BLCollection bls = new BLCollection();
string sql = "Select t.pnl_id,t.prod_nbr,t.cust_nbr,t.bl_log_mach,t.work_ctr,t.bl_factory,t.reason,t.position,t.attribute,t.user_id,to_char(t.key_date,'yyyy-MM-dd hh24:mi:ss') as key_date From bl_bad t"; sql += " Where fac_id='"+bl1.fac_id+"'";
if (bl1.date1 != "")
{
sql += " and to_char(key_date,'yyyy-MM-dd')>='" + bl1.date1 + "'";
}
if (bl1.date2 != "")
{
sql += " and to_char(key_date,'yyyy-MM-dd')<='" + bl1.date2 + "'";
}
if (bl1.cust_nbr != "")
{
sql += " and cust_nbr='" + bl1.cust_nbr + "'";
}
OracleDataReader dr = null;
try
{
dr = Get_DataReader(sql);
while (dr.Read())
{
bls.Add(PopuplateBL(dr));
}
}
catch (OracleException ex)
{
throw new Exception(ex.Message);
}
finally
{
if (dr != null && !dr.IsClosed)
{
dr.Close();
}
conn.Close();
}
return bls;
}我在写SQL语句的时候,把这些判断逻辑写到了DAL,如果想写进BLL层怎么写呢。
if (bl1.date1 != "")
{
sql += " and to_char(key_date,'yyyy-MM-dd')>='" + bl1.date1 + "'";
}
if (bl1.date2 != "")
{
sql += " and to_char(key_date,'yyyy-MM-dd')<='" + bl1.date2 + "'";
}
if (bl1.cust_nbr != "")
{
sql += " and cust_nbr='" + bl1.cust_nbr + "'";
}
{
return new D_BL().GetAllBL(bl1);
}DAL:public BLCollection GetAllBL(M_BL1 bl1)
{
BLCollection bls = new BLCollection();
string sql = "Select t.pnl_id,t.prod_nbr,t.cust_nbr,t.bl_log_mach,t.work_ctr,t.bl_factory,t.reason,t.position,t.attribute,t.user_id,to_char(t.key_date,'yyyy-MM-dd hh24:mi:ss') as key_date From bl_bad t"; sql += " Where fac_id='"+bl1.fac_id+"'";
if (bl1.date1 != "")
{
sql += " and to_char(key_date,'yyyy-MM-dd')>='" + bl1.date1 + "'";
}
if (bl1.date2 != "")
{
sql += " and to_char(key_date,'yyyy-MM-dd')<='" + bl1.date2 + "'";
}
if (bl1.cust_nbr != "")
{
sql += " and cust_nbr='" + bl1.cust_nbr + "'";
}
OracleDataReader dr = null;
try
{
dr = Get_DataReader(sql);
while (dr.Read())
{
bls.Add(PopuplateBL(dr));
}
}
catch (OracleException ex)
{
throw new Exception(ex.Message);
}
finally
{
if (dr != null && !dr.IsClosed)
{
dr.Close();
}
conn.Close();
}
return bls;
}我在写SQL语句的时候,把这些判断逻辑写到了DAL,如果想写进BLL层怎么写呢。
if (bl1.date1 != "")
{
sql += " and to_char(key_date,'yyyy-MM-dd')>='" + bl1.date1 + "'";
}
if (bl1.date2 != "")
{
sql += " and to_char(key_date,'yyyy-MM-dd')<='" + bl1.date2 + "'";
}
if (bl1.cust_nbr != "")
{
sql += " and cust_nbr='" + bl1.cust_nbr + "'";
}
解决方案 »
- 代码加亮插件,分享!
- JavaScript如何判断文本框里的数值大小
- 如何跳过验证控件关闭当前窗口?
- 再次提问,如何不用HTMLINPUT而根据客户端文件名字符串上传文件,比如用ACTIVEX
- 高手进~~~~奇怪问题!
- 请问哪位高手知道,网上比较好的ASP留言板,基本功能具备就可以,不用太复杂,式样简洁的?
- 转成codebehind时出错(VB.NET)Type 'OleDbCommand' is not defined.
- AjaxPro postback时候的问题
- 如何将<转成<
- 请问在html页面中如何可以插入一个asp.net的文件
- 后台代码执行完成后,页面卡顿5秒左右怎么回事呢?
- 由于cookie中的session
{
string sqlWhere="
sqlWhere Where fac_id='"+bl1.fac_id+"'";
if (bl1.date1 != "")
{
sqlWhere += " and to_char(key_date,'yyyy-MM-dd')>='" + bl1.date1 + "'";
}
if (bl1.date2 != "")
{
sqlWhere += " and to_char(key_date,'yyyy-MM-dd')<='" + bl1.date2 + "'";
}
if (bl1.cust_nbr != "")
{
sqlWhere += " and cust_nbr='" + bl1.cust_nbr + "'";
}
"
return new D_BL().GetAllBL(bl1);
}DAL:public BLCollection GetAllBL(M_BL1 bl1,string sqlWhere)
{
BLCollection bls = new BLCollection();
string sql = "Select t.pnl_id,t.prod_nbr,t.cust_nbr,t.bl_log_mach,t.work_ctr,t.bl_factory,t.reason,t.position,t.attribute,t.user_id,to_char(t.key_date,'yyyy-MM-dd hh24:mi:ss') as key_date From bl_bad t";
sql+=sqlwhere;
OracleDataReader dr = null;
try
{
dr = Get_DataReader(sql);
while (dr.Read())
{
bls.Add(PopuplateBL(dr));
}
}
catch (OracleException ex)
{
throw new Exception(ex.Message);
}
finally
{
if (dr != null && !dr.IsClosed)
{
dr.Close();
}
conn.Close();
}
return bls;
}
这种情况是不是只能在DAL判定SQL语句了?
逻辑层 处理业务逻辑
数据层 数据访问操作