using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Text; using System.Collections.Generic; public partial class Admin_Controls_SelectorCategories : WebBlockUserControl { public int SelectorID { get { return (ViewState["SelectorID"] == null ? 0 : (int)ViewState["SelectorID"]); } set { ViewState["SelectorID"] = value; } } private void BindPageOne() { DataTable dt = Database.Categories_GetBySelectorID(SelectorID); gvCategories.DataSource = dt; gvCategories.DataBind(); } #region Item Database Functions private void BindPageTwo(bool FullSearch) { DataTable dt; if (FullSearch) { string srchCanonicalName; if (txtSearchCanonicalName.Text.Length > 0) srchCanonicalName = "%" + txtSearchCanonicalName.Text + "%"; else srchCanonicalName = "%"; dt = Database.Categories_Search(srchCanonicalName); } else { dt = Database.Categories_GetAll(); } gvCategoryDatabase.DataSource = dt; gvCategoryDatabase.DataBind(); } protected void btnSearch_Click(object sender, EventArgs e) { if (txtSearchCanonicalName.Text.Length == 0 && ddlSearchUseCategoryLanding.SelectedValue != "-1") { BindPageTwo(false); } else { BindPageTwo(true); } } protected void btnAdd_Click(object sender, EventArgs e) { foreach (GridViewRow gvr in gvCategoryDatabase.Rows) { if (gvr.RowType == DataControlRowType.DataRow) { CheckBox cb = (CheckBox)gvr.Cells[0].Controls[1]; if (cb.Checked) { int CategoryID = (int)gvCategoryDatabase.DataKeys[gvr.RowIndex].Value; DataRow dr = Database.CategorySelectorMap_Get(SelectorID, CategoryID); if (dr == null) Database.CategorySelectorMap_Add(SelectorID, CategoryID); } } } Menu1.Items[0].Selected = true; mvContent.ActiveViewIndex = 0; BindPageOne(); } protected void btnRemoveSelected_Click(object sender, EventArgs e) { foreach (GridViewRow gvr in gvCategories.Rows) { if (gvr.RowType == DataControlRowType.DataRow) { CheckBox cb = (CheckBox)gvr.Cells[0].Controls[1]; if (cb.Checked) { int CategoryID = (int)gvCategories.DataKeys[gvr.RowIndex].Value; Database.CategorySelectorMap_Delete(CategoryID, SelectorID); } } } BindPageOne(); } #endregion #region Page-Wide functions public void BindData() { if (mvContent.ActiveViewIndex == 0) BindPageOne(); else if (mvContent.ActiveViewIndex == 1) BindPageTwo(false); } protected void Menu1_MenuItemClick(object sender, MenuEventArgs e) { mvContent.ActiveViewIndex = Int32.Parse(e.Item.Value); if (mvContent.ActiveViewIndex == 0) BindPageOne(); else if (mvContent.ActiveViewIndex == 1) BindPageTwo(false); } #endregion }