public string GetWhere() { Entities.Content content = Provider.Content; if (content == null) content = (Entities.Content)Provider.Database.Read(typeof(Entities.Content), 1); Entities.Content category = null; if (content.ClassName == "Category") category = content; else category = content.Category; string where = ""; Hashtable htOperators = new Hashtable(); Hashtable htParams = new Hashtable(); alParams = new Dictionary<string, object>(); foreach (string criteria in this.filter.Split(new string[] { " AND ", " and ", " And " }, StringSplitOptions.RemoveEmptyEntries)) { string[] pair = criteria.Split(new string[] { "like@", "<=@", ">=@", "<>@", "<@", ">@", "=@", "like", "<=", ">=", "<>", "<", ">", "=" }, StringSplitOptions.None); htOperators[pair[0]] = criteria.Substring(pair[0].Length, criteria.Length - pair[0].Length - pair[1].Length); htParams[pair[0]] = pair[1]; } int fieldNo = 0; ArrayList fields = new ArrayList(htParams.Keys); foreach (string field in fields) { FieldOpValue fov = new FieldOpValue(entityName + "." + field, htOperators[field].ToString(), htParams[field].ToString()); #region özel durumlar if (fov.Op.Contains("@")) { fov.Op = fov.Op.Substring(0, fov.Op.Length - 1); if (htParams[field].Equals("Hierarchy")) { int parentCategoryId = category == null ? 1 : category.Id; fov.Value = Provider.GetHierarchyLike(parentCategoryId)+"%"; fov.Column = entityName + "." + "Hierarchy"; } else if (htParams[field].Equals("Category")) { if (category == null) throw new Exception(Provider.GetResource("KategoriTam cannot be used as a parameter because there is no active category")); fov.Value = category.Id; fov.Column = entityName + "." + "CategoryId"; } else if (htParams[field].Equals("Author")) { fov.Value = content.AuthorId; } else if (htParams[field].Equals("Source")) { fov.Value = content.SourceId; } else if (htParams[field].Equals("Content")) { fov.Value = content.Id; } else if (htParams[field].Equals("PreviousContent")) { fov.Value = Provider.PreviousContentId; //Provider.Database.GetInt("select Id from Content where Id<{0} AND CategoryId={1} order by Id desc limit 1", content.Id, content.CategoryId); } else if (htParams[field].Equals("NextContent")) { fov.Value = Provider.NextContentId; //Provider.Database.GetInt("select Id from Content where Id>{0} AND CategoryId={1} order by Id limit 1", content.Id, content.CategoryId); } else if (htParams[field].Equals("Yesterday")) { fov.Value = DateTime.Now.Date.AddDays(-1d); } else if (htParams[field].Equals("LastDay")) { fov.Value = DateTime.Now.Date.AddDays(-2d); } else if (htParams[field].Equals("LastWeek")) { fov.Value = DateTime.Now.Date.AddDays(-1 * 7d); } else if (htParams[field].Equals("LastMonth")) { fov.Value = DateTime.Now.Date.AddMonths(-1); } else throw new Exception(Provider.GetResource("Invalid parameter name")); } #endregion alParams.Add(field, fov.Value); where += (where == "" ? "" : " AND ") + fov.Column + " " + fov.Op + " {" + fieldNo + "}"; fieldNo++; } return where; }
public string GetWhere() { Entities.Content content = Provider.Content; if (content == null) { content = (Entities.Content)Provider.Database.Read(typeof(Entities.Content), 1); } Entities.Content category = null; if (content.ClassName == "Category") { category = content; } else { category = content.Category; } string where = ""; Hashtable htOperators = new Hashtable(); Hashtable htParams = new Hashtable(); alParams = new Dictionary <string, object>(); foreach (string criteria in this.filter.Split(new string[] { " AND ", " and ", " And " }, StringSplitOptions.RemoveEmptyEntries)) { string[] pair = criteria.Split(new string[] { "like@", "<=@", ">=@", "<>@", "<@", ">@", "=@", "like", "<=", ">=", "<>", "<", ">", "=" }, StringSplitOptions.None); htOperators[pair[0]] = criteria.Substring(pair[0].Length, criteria.Length - pair[0].Length - pair[1].Length); htParams[pair[0]] = pair[1]; } int fieldNo = 0; ArrayList fields = new ArrayList(htParams.Keys); foreach (string field in fields) { FieldOpValue fov = new FieldOpValue(entityName + "." + field, htOperators[field].ToString(), htParams[field].ToString()); #region özel durumlar if (fov.Op.Contains("@")) { fov.Op = fov.Op.Substring(0, fov.Op.Length - 1); if (htParams[field].Equals("Hierarchy")) { int parentCategoryId = category == null ? 1 : category.Id; fov.Value = Provider.GetHierarchyLike(parentCategoryId) + "%"; fov.Column = entityName + "." + "Hierarchy"; } else if (htParams[field].Equals("Category")) { if (category == null) { throw new Exception(Provider.GetResource("KategoriTam cannot be used as a parameter because there is no active category")); } fov.Value = category.Id; fov.Column = entityName + "." + "CategoryId"; } else if (htParams[field].Equals("Author")) { fov.Value = content.AuthorId; } else if (htParams[field].Equals("Source")) { fov.Value = content.SourceId; } else if (htParams[field].Equals("Content")) { fov.Value = content.Id; } else if (htParams[field].Equals("PreviousContent")) { fov.Value = Provider.PreviousContentId; //Provider.Database.GetInt("select Id from Content where Id<{0} AND CategoryId={1} order by Id desc limit 1", content.Id, content.CategoryId); } else if (htParams[field].Equals("NextContent")) { fov.Value = Provider.NextContentId; //Provider.Database.GetInt("select Id from Content where Id>{0} AND CategoryId={1} order by Id limit 1", content.Id, content.CategoryId); } else if (htParams[field].Equals("Yesterday")) { fov.Value = DateTime.Now.Date.AddDays(-1d); } else if (htParams[field].Equals("LastDay")) { fov.Value = DateTime.Now.Date.AddDays(-2d); } else if (htParams[field].Equals("LastWeek")) { fov.Value = DateTime.Now.Date.AddDays(-1 * 7d); } else if (htParams[field].Equals("LastMonth")) { fov.Value = DateTime.Now.Date.AddMonths(-1); } else { throw new Exception(Provider.GetResource("Invalid parameter name")); } } #endregion alParams.Add(field, fov.Value); where += (where == "" ? "" : " AND ") + fov.Column + " " + fov.Op + " {" + fieldNo + "}"; fieldNo++; } return(where); }