各位大侠,小弟最近才接触三层架构,遇到个疑问。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 + "'";
}
{
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语句了?
逻辑层 处理业务逻辑
数据层 数据访问操作