我通常尽可能声明我的 DAL 类覆盖搜索方法,如下例所示:
public class clsAsd {
    private AdConn oConn;
    public clsAsd(ref AdConn Connection) {
        oConn = Connection;
    }
    private string sqlSearch(string DocType, string Status, string Aaa) {
        return
            "    AND x.tp_doc = '" + DocType + "'\r\n" +
            "    AND x.co_status IN (" + Status + ")\r\n" +
            "    AND x.aaa = '" + Aaa + "'\r\n";
    }
    public List<clsQwe> search(string DocType, string Status, string Aaa, bool IncDel) {
        return search(sqlSearch(DocType, Status, Aaa), IncDel);
    }
    private string sqlSearch(string DocType, string Status, string Aaa, string Bbb) {
        string sSQL = sqlSearch(DocType, Status, Aaa) + (Bbb != "" ? "    AND x.bbb = '" + Bbb + "'\r\n" : "");
        return sSQL;
    }
    public List<clsQwe> search(string DocType, string Status, string Aaa, string Bbb, bool IncDel) {
        return search(sqlSearch(DocType, Status, Aaa, Bbb), IncDel);
    }
    private List<clsQwe> search(string Where, bool IncDel) {
        string sSQL;
        sSQL = "SELECT\r\n";
        sSQL += "    b.aaa, c.bbb, x.*\r\n";
        sSQL += "FROM asd x, qwe b, zxc c\r\n";
        sSQL += "WHERE x.www = b.www\r\n";
        sSQL += "    AND x.zzz = c.zzz\r\n";
        sSQL += Where;
        if (!IncDel) sSQL += "    AND x.del IS NULL\r\n";
        sSQL += "ORDER BY x.www";
        // Connection + Run SQL
        // List to get results
        List<clsQwe> lstRet = new List<clsQwe>();
        // Row to add in list
        clsQwe oX;
        while (oReader.Read()) {
            oX = new clsQwe();
            // Add all data
            lstRet.Add(oX);
        }
        // Return data
        return lstRet;
    }
}
我的问题是:这是一个好习惯吗?
我应该为每个不同的搜索使用一种方法?例子:
public class clsAsd {
    private AdConn oConn;
    public clsAsd(ref AdConn Connection) { oConn = Connection; }
    public List<clsQwe> search1(string DocType, string Status, string Aaa, bool IncDel) { }
    public List<clsQwe> search2(string DocType, string Status, string Aaa, string Bbb, bool IncDel) { }
    public List<clsQwe> search3(string DocType, string Status, string Aaa, string Bbb, string Ccc, bool IncDel) { }
    private List<clsQwe> search(string Where, bool IncDel) { }
}
我怎样才能提高这门课?
我正在考虑只实现一种接收类(clsQwe)作为参数的搜索方法。我检查这个类的每个属性并根据填充的属性创建 where 子句。
这种做法有意思吗?
谢谢你。