-
Notifications
You must be signed in to change notification settings - Fork 1
/
ComboBoxPropertiesProvider.cs
130 lines (121 loc) · 4.69 KB
/
ComboBoxPropertiesProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using DevExpress.Web;
using DevExpress.Web.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
namespace E4425.Models
{
public class ComboBoxPropertiesProvider : IDisposable
{
static ComboBoxPropertiesProvider current;
public static ComboBoxPropertiesProvider Current
{
get
{
if (current == null)
current = new ComboBoxPropertiesProvider();
return current;
}
}
public int EditableCountryID
{
get
{
string rawCountryId = HttpContext.Current.Request["CountryId"];
return string.IsNullOrEmpty(rawCountryId) ? -1 : int.Parse(rawCountryId);
}
}
MVCxColumnComboBoxProperties cityComboBoxProperties;
public MVCxColumnComboBoxProperties CityComboBoxProperties
{
get
{
if (cityComboBoxProperties == null)
cityComboBoxProperties = CreateCityComboBox();
return cityComboBoxProperties;
}
}
MVCxColumnComboBoxProperties countryComboBoxProperties;
public MVCxColumnComboBoxProperties CountryComboBoxProperties
{
get
{
if (countryComboBoxProperties == null)
countryComboBoxProperties = CreateCountryComboBox();
return countryComboBoxProperties;
}
}
WorldCitiesEntities worldCities;
protected WorldCitiesEntities WorldCities
{
get
{
if (worldCities == null)
worldCities = new WorldCitiesEntities();
return worldCities;
}
}
protected MVCxColumnComboBoxProperties CreateCountryComboBox()
{
MVCxColumnComboBoxProperties cs = new MVCxColumnComboBoxProperties();
cs.CallbackRouteValues = new { Controller = "Home", Action = "ComboBoxCountryPartial" };
cs.Width = Unit.Percentage(100);
cs.TextField = "CountryName";
cs.ValueField = "CountryId";
cs.ValueType = typeof(int);
cs.IncrementalFilteringDelay = 1000;
cs.IncrementalFilteringMode = IncrementalFilteringMode.Contains;
cs.FilterMinLength = 2;
cs.CallbackPageSize = 20;
cs.ClientSideEvents.SelectedIndexChanged = "CountriesCombo_SelectedIndexChanged";
cs.BindList(WorldCities.Countries.ToList());
return cs;
}
protected MVCxColumnComboBoxProperties CreateCityComboBox()
{
MVCxColumnComboBoxProperties cs = new MVCxColumnComboBoxProperties();
cs.CallbackRouteValues = new { Controller = "Home", Action = "ComboBoxCityPartial" };
cs.Width = Unit.Percentage(100);
cs.CallbackPageSize = 20;
cs.TextField = "CityName";
cs.ValueField = "CityId";
cs.ValueType = typeof(int);
cs.IncrementalFilteringDelay = 1000;
cs.IncrementalFilteringMode = IncrementalFilteringMode.Contains;
cs.FilterMinLength = 2;
cs.BindList(OnItemsRequestedByFilterCondition, OnItemRequestedByValue);
cs.ClientSideEvents.BeginCallback = "CitiesCombo_BeginCallback";
cs.ClientSideEvents.EndCallback = "CitiesCombo_EndCallback";
return cs;
}
protected object OnItemRequestedByValue(ListEditItemRequestedByValueEventArgs e)
{
int id;
if (e.Value == null || !int.TryParse(e.Value.ToString(), out id))
return null;
var query = WorldCities.Cities.Where(city => city.CityId == id);
return query.ToList();
}
protected object OnItemsRequestedByFilterCondition(ListEditItemsRequestedByFilterConditionEventArgs e)
{
IQueryable<City> query;
var skip = e.BeginIndex;
var take = e.EndIndex - e.BeginIndex + 1;
if (EditableCountryID > -1)
query = WorldCities.Cities.Where(city => city.CityName.Contains(e.Filter) && city.Country.CountryId == EditableCountryID).OrderBy(city => city.CityId);
else
query = WorldCities.Cities.Where(city => city.CityName.Contains(e.Filter)).OrderBy(city => city.CityId);
query = query.Skip(skip).Take(take);
return query.ToList();
}
#region IDisposable Members
public void Dispose()
{
if (this.worldCities != null)
worldCities.Dispose();
}
#endregion
}
}