/// <summary> /// 將搜尋控制項的值轉換為 SQL Statement /// </summary> /// <param name="sql">PetaPoco SQL</param> /// <param name="SearchItems">用於搜尋的控制項集合</param> /// <param name="plSearch">搜尋區塊控制項</param> /// <param name="ViewState">ViewState</param> public static void ConvertControlToSQL(PetaPoco.Sql sql, IList<SearchItem> SearchItems, Panel plSearch, StateBag ViewState) { foreach (SearchItem item in SearchItems) { if (((Panel)plSearch).FindControl(item.ControlName).GetType() == typeof(CheckBox)) { if ((bool)ViewState[item.ControlName]) { sql.Append(item.SQLStatement, ViewState[item.ControlName]); } } else { if (!string.IsNullOrEmpty(Convert.ToString(ViewState[item.ControlName]))) { sql.Append(item.SQLStatement, ViewState[item.ControlName]); } } } }
private static PetaPoco.Sql BuildWhereCondition(PetaPoco.Sql sql, QueryField queryField) { string format = "[{0}] {1} @0"; if (queryField.Name.Equals(QueryFieldName.DownloadDateTime) || queryField.Name.Equals(QueryFieldName.CompletionDateTime)) { format = "datetime([{0}]) {1} datetime(@0)"; } sql = sql.Append(String.Format(CultureInfo.InvariantCulture, format, ColumnNameOverides.ContainsKey(queryField.Name) ? ColumnNameOverides[queryField.Name] : queryField.Name.ToString(), queryField.Operator), queryField.Value); return sql; }