- Timestamp:
- 05/09/11 22:13:01 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified branches/WebApplication/MVC2/HLWebOKBQueryPlugin/ViewModels/FilterModel.cs ¶
r6163 r6170 15 15 public class FilterModel 16 16 { 17 private List<bool> boolStates;18 17 19 private List<Filter> _filters; 20 21 //public KeyValuePair<int,Filter> ParentFilter { get; set; } 22 public List<Filter> Filters 23 { 24 25 get 26 { 27 QueryServiceClient client = Query.GetClientFactory("okbtester", "okbtester"); 28 return client.GetFilters().ToList<Filter>(); /// => won't work 29 } 30 31 32 } 33 //public Dictionary<int,Filter> SelectedFilters { get; set; } 34 // use an unique id for reach filter "Control" 35 public CombinedFilter Content { get; set; } 18 public static string ComboboxName { get { return "filtersCombobox"; } } 19 public static string ParentIdName { get { return "parentId"; } } 20 public static string ValueTextbox { get { return "valueTextbox"; } } 21 public static string ValueDropDownList { get { return "valueDropDownList"; } } 36 22 37 23 24 /// <summary> 25 /// Constructor 26 /// </summary> 38 27 public FilterModel() 39 28 { … … 44 33 { 45 34 Content = filter; 46 //filter.i 35 } 36 37 /// <summary> 38 /// Get Bool States. 39 /// </summary> 40 public List<Boolean> BoolStates 41 { 42 get 43 { 44 List<Boolean> boolStates = new List<Boolean>(); 45 46 boolStates = new List<Boolean>(); 47 boolStates.Add(true); 48 boolStates.Add(false); 49 50 return boolStates; 51 } 47 52 } 48 53 49 54 50 public List<Boolean> GetBoolStates() 55 /// <summary> 56 /// Available Filters 57 /// </summary> 58 public List<Filter> AvailableFilters 51 59 { 52 if (boolStates == null)60 get 53 61 { 54 boolStates = new List<Boolean>(); 55 boolStates.Add(true); 56 boolStates.Add(false); 62 QueryServiceClient client = Query.GetClientFactory("okbtester", "okbtester"); 63 return client.GetFilters().ToList<Filter>(); 57 64 } 58 return boolStates;59 65 } 60 66 67 68 /// <summary> 69 /// Available Filters without AND and OR. 70 /// </summary> 71 public List<Filter> AvailableFilterForCombobox 72 { 73 get 74 { 75 List<Filter> filters = AvailableFilters; 76 77 filters.Remove(filters.OfType<CombinedFilter>().Where(x => x.Operation == BooleanOperation.Or).FirstOrDefault()); 78 filters.Remove(filters.OfType<CombinedFilter>().Where(x => x.Operation == BooleanOperation.And).FirstOrDefault()); 79 80 return filters; 81 } 82 } 83 84 /// <summary> 85 /// Content 86 /// </summary> 87 public CombinedFilter Content { get; set; } 88 89 90 91 /// <summary> 92 /// Delete a filter with given id. 93 /// </summary> 94 /// <param name="id">filter id</param> 95 internal bool RemoveFilter(Guid id) 96 { 97 bool removed = false; 98 List<Filter> orFilters = Content.Filters.ToList<Filter>(); 99 100 foreach (CombinedFilter f in orFilters) 101 { 102 Filter deleteFilter = f.Filters.Where(x => x.Id == id).FirstOrDefault(); 103 if (deleteFilter != null) 104 { 105 List<Filter> masterFilters = f.Filters.ToList<Filter>(); 106 masterFilters.Remove(deleteFilter); 107 f.Filters = masterFilters.ToArray<Filter>(); 108 removed = true; 109 break; 110 } 111 } 112 113 Content.Filters = orFilters.ToArray<Filter>(); 114 return removed; 115 } 116 117 /// <summary> 118 /// Add a new filters 119 /// </summary> 120 /// <param name="filterTypeName">type name</param> 121 /// <param name="parentId">parent filter id</param> 122 internal void AddFilter(string filterTypeName, Guid parentId) 123 { 124 125 // get selected filter (combobox) 126 Filter filter = AvailableFilters.Where(x => x.FilterTypeName.Equals(filterTypeName)).FirstOrDefault(); 127 128 129 // find the partent filterr 130 List<Filter> orFilters = Content.Filters.ToList<Filter>(); ; 131 CombinedFilter parentFilter = (CombinedFilter)orFilters.Where(e => e.Id.Equals(parentId)).FirstOrDefault(); 132 133 // remove 134 orFilters.Remove(parentFilter); 135 136 List<Filter> filterList = parentFilter.Filters.ToList<Filter>(); 137 138 139 // Add the new filter 140 filterList.Add(filter); 141 //Response.Write("addx:" + filter.Id); 142 143 parentFilter.Filters = filterList.ToArray<Filter>(); 144 145 // Add the current filter (AND) 146 orFilters.Add(parentFilter); 147 148 Content.Filters = orFilters.ToArray<Filter>(); 149 } 150 151 /// <summary> 152 /// Update existing filters with posted value 153 /// </summary> 154 /// <param name="parentId">parent filter id</param> 155 /// <param name="postValues">dictionary with posted values</param> 156 internal void UpdateWithPostValues(Dictionary<Guid, Dictionary<string, string>> postValues) 157 { 158 // Set values for the existing Filters 159 foreach (CombinedFilter cf in Content.Filters) 160 { 161 foreach (Filter f in cf.Filters) 162 { 163 164 Dictionary<string, string> dict = postValues.Where(x => x.Key.Equals(f.Id)).FirstOrDefault().Value; 165 if (dict != null) 166 { 167 foreach (KeyValuePair<string, string> kvp in dict) 168 { 169 if ("StringComparisonFilter".Equals(f.GetType().Name)) 170 { 171 if (kvp.Key.Equals(FilterModel.ValueTextbox)) 172 { 173 ((StringComparisonFilter)f).Value = kvp.Value; 174 } 175 // To this for alle keys 176 177 } 178 else 179 { 180 // To this for all filters 181 } 182 } 183 } 184 } 185 } 186 } 61 187 } 62 188 }
Note: See TracChangeset
for help on using the changeset viewer.