0

我有这个代码但它不工作..它不过滤任何东西..当我生成一些东西时..我不知道为什么..有人可以帮我解决这个问题..??我需要产生一些东西。这是我正在使用的代码:

public DataTable getDocumentsByFilter(string category, string document, string office, string period, DateTime start, DateTime end, string sy, string sem, string searchinfo)
{
    string sql = "SELECT d.*,so.*,sy.*,ua.*,so.SchoolOfficeDescription as [AddresseeName] From Document d, SchoolOffice so, SchoolYear sy, UserAccount ua WHERE d.Addressee = so.SchoolOfficeID AND d.SchoolYearID = sy.SchoolYearID AND d.Status like 'Active' AND ua.UserID = d.UserID";

    if (!(office == "All")) 
    {
        sql = sql + " And  d.Addressee =" + office ;
    }
    else if (office == "All")
    {
        sql = sql + " AND  d.Addressee >= 0 ";
    }

    if (!(document == "All"))
    {
        sql = sql + document + "";
    }
    else
    {
        sql = sql + " AND ( d.docStatus like 'Draft' OR d.docStatus like 'Forwarded' OR d.docStatus like 'Received') ";
    }

    if (!(category == "All"))
        sql = sql + " And d.Category like '" + category+ "'";
    else
    {
        sql = sql + " AND ( d.Category like 'Activity,Item,Service' OR  d.Category like 'Activity' OR  d.Category like 'Item' or  d.Category like 'Service')";
    }

    if (period == "SY")
    {
        sql = sql + " And sy.YearStart like '" + sy + "'";

        if (!(sem == "Please select..."))
        {
            sql = sql + " And sy.Semester like '" + sem + "'";
        }
        else 
        {
            sql = sql + " And (sy.Semester like 'First Semester' OR sy.Semester like 'Summer Term' or sy.Semester like 'Second Semester') ";
        }
    }
    else if (period == "Date")
    {
        sql = sql + " And d.DateCreated between '" + start + "' And '" + end + "'";
    }
    else if (period == "All")
    {
        sql = sql + " AND d.DateCreated  > '1/1/1911 12:00:00 AM' ";
    }

    if (searchinfo != "Enter document details")
    {
        sql = sql + " AND ((ua.FirstName like '%" + searchinfo + "%' OR ua.LastName like '%" + searchinfo + "%') AND ua.UserID = d.UserID)";
    }

    sql = sql + " ORDER BY d.DateCreated DESC";

    return GetDataTable(sql, null);
}
4

0 回答 0