using System; using System.Web.UI; using System.Web.UI.WebControls; using Nexus.Core.Helpers; using Nexus.Web; using PhoneBook.Core; namespace PhoneBook.Web.Controls { /// /// Capture input values to filter a list of directory entries. /// /// public class Finder2 : ViewControl { /// /// Signal update to input filters /// by passing FindArgs with the search critiers. /// /// public event EventHandler Filter_Changed; /// /// Populate the entry finder's own controls. /// /// public void Open() { IViewHelper h = GetHelperFor(App.ENTRY_FIND); ExecuteBind(h); bool ok = (h.IsNominal); if (!ok) Page_Alert = h; } /// /// Provide runtime instance of find Button. /// /// protected Button find; /// /// Handle the Click event of the Find button /// by resetting the filters /// and raising the Filter Changed event /// so that the presentation will list all entries. /// /// Event source /// Runtime parameters /// private void find_Click(object sender, EventArgs e) { if (Filter_Changed == null) return; Filter_Reset(null); IViewHelper helper = Read(App.ENTRY_LIST); Filter_Changed(this, new ViewArgs(helper)); } /// /// Unselect all but the active filter. /// /// The active filter /// private void Filter_Reset(DropDownList except) { // Reset filter controls int exceptIndex = 0; if (except != null) exceptIndex = except.SelectedIndex; foreach (Control c in Controls) { if (IsListControl(c)) { DropDownList x = (DropDownList) c; x.SelectedIndex = 0; } } if (except != null) except.SelectedIndex = exceptIndex; } /// /// Handle the SelectIndexChanged event for any of the filters /// by capturing its settings /// and raising the Filter_Changed event. /// /// Event source /// Runtime parameters /// private void filter_SelectedIndexChanged(object sender, EventArgs e) { IViewHelper helper = Catalog.GetHelperFor(App.ENTRY_LIST); DropDownList list = sender as DropDownList; string id = list.ID; int v = id.LastIndexOf(ListSuffix); string key = id.Substring(0, v); helper.Criteria[key] = list.SelectedValue; Filter_Reset(list); Filter_Changed(this, new ViewArgs(helper)); } private void Page_Load(object sender, EventArgs e) { find.Click += new EventHandler(find_Click); foreach (Control control in Controls) { if (IsListControl(control)) { DropDownList filter = (DropDownList) control; filter.SelectedIndexChanged += new EventHandler(filter_SelectedIndexChanged); filter.AutoPostBack = true; } } } #region Web Form Designer generated code protected override void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.Load += new EventHandler(this.Page_Load); } #endregion } }