void saveButton_Click(object sender, EventArgs e) { categoryId = Int32.Parse(idHidden.Value); String name = nameBox.Text.Trim(); if (name == String.Empty) { ErrorMessage = "Name cannot be blank"; return; } CategoryTableAdapter categoryAdapter = new CategoryTableAdapter(); if (categoryId > 0) { category = categoryAdapter.GetCategory(categoryId)[0]; category.Name = name; categoryAdapter.Update(category); parentCategoryId = category.ParentCategoryId; } else if (isNew == true && isSubCategory == false && Request.QueryString["parent_id"] == "NEW") { categoryAdapter.Insert(StationId, null, name, -1); } else { parentCategoryId = Int32.Parse(parentIdHidden.Value); // SeqNo of -1 will assign it the next highest SeqNo for the category categoryAdapter.Insert(StationId, parentCategoryId, name, -1); } InfoMessage = "Category Updated"; if (parentCategoryId > 0) { Response.Redirect("~/admin/CategoryEdit.aspx?id=" + parentCategoryId); } else { Response.Redirect("~/admin/CategoryList.aspx"); } }
protected override void OnPreInit(EventArgs e) { int categoryId = GetValueFromQueryString("category_id"); if (categoryId > 0) { CategoryTableAdapter categoryAdapter = new CategoryTableAdapter(); DollarSaverDB.CategoryDataTable categories = categoryAdapter.GetCategory(categoryId); if (categories.Count == 1) { category = categories[0]; } } base.OnPreInit(e); }
protected void Page_Load(object sender, EventArgs e) { saveButton.Click += new EventHandler(saveButton_Click); cancelButton.Click += new EventHandler(cancelButton_Click); deleteButton.Click += new EventHandler(deleteButton_Click); deleteButton.Attributes["onclick"] = "javascript: return confirm('Are you sure want to delete this item?');"; subCategoryGrid.RowCommand += new GridViewCommandEventHandler(subCategoryGrid_RowCommand); categoryId = GetIdFromQueryString(); CategoryTableAdapter categoryAdapter = new CategoryTableAdapter(); if (categoryId != 0) { DollarSaverDB.CategoryDataTable categories = categoryAdapter.GetCategory(categoryId); if (categories.Rows.Count != 1) { Response.Redirect("~/admin/CategoryList.aspx"); } category = categories[0]; if (category.StationId != StationId) { Response.Redirect("~/admin/CategoryList.aspx"); } if (!category.IsParentCategoryIdNull()) { parentCategoryId = category.ParentCategoryId; parentCategory = categoryAdapter.GetCategory(parentCategoryId)[0]; } } else { parentCategoryId = GetParentIdFromQueryString(); DollarSaverDB.CategoryDataTable parentCategories = categoryAdapter.GetCategory(parentCategoryId); if (parentCategories.Rows.Count != 1) { Response.Redirect("~/admin/CategoryList.aspx"); } parentCategory = parentCategories[0]; if (parentCategory.StationId != StationId) { Response.Redirect("~/admin/CategoryList.aspx"); } isNew = true; } if (isNew || !category.IsParentCategoryIdNull()) { isSubCategory = true; } }
private void BindSubCategories(int parentCategoryId) { CategoryTableAdapter categoryAdapter = new CategoryTableAdapter(); DollarSaverDB.CategoryRow category = categoryAdapter.GetCategory(parentCategoryId)[0]; if (category.SubCategories.Count > 0) { subCategory1Holder.Visible = true; subCategoryList1.DataSource = category.SubCategories.Rows; subCategoryList1.DataTextField = "Name"; subCategoryList1.DataValueField = "CategoryId"; subCategoryList1.DataBind(); subCategoryList1.Items.Insert(0, new ListItem("", "0")); if (advertiser != null && advertiser.SubCategories.Count > 0 && subCategoryList1.Items.FindByValue(advertiser.SubCategories[0].CategoryId.ToString()) != null) { subCategoryList1.SelectedValue = advertiser.SubCategories[0].CategoryId.ToString(); } else { subCategoryList1.SelectedValue = "0"; } } else { subCategory1Holder.Visible = false; } if (category.SubCategories.Count > 1) { subCategory2Holder.Visible = true; subCategoryList2.DataSource = category.SubCategories.Rows; subCategoryList2.DataTextField = "Name"; subCategoryList2.DataValueField = "CategoryId"; subCategoryList2.DataBind(); subCategoryList2.Items.Insert(0, new ListItem("", "0")); if (advertiser != null && advertiser.SubCategories.Count > 1 && subCategoryList2.Items.FindByValue(advertiser.SubCategories[1].CategoryId.ToString()) != null) { subCategoryList2.SelectedValue = advertiser.SubCategories[1].CategoryId.ToString(); } else { subCategoryList2.SelectedValue = "0"; } } else { subCategory2Holder.Visible = false; } if (category.SubCategories.Count > 2) { subCategory3Holder.Visible = true; subCategoryList3.DataSource = category.SubCategories.Rows; subCategoryList3.DataTextField = "Name"; subCategoryList3.DataValueField = "CategoryId"; subCategoryList3.DataBind(); subCategoryList3.Items.Insert(0, new ListItem("", "0")); if (advertiser != null && advertiser.SubCategories.Count > 2 && subCategoryList3.Items.FindByValue(advertiser.SubCategories[2].CategoryId.ToString()) != null) { subCategoryList3.SelectedValue = advertiser.SubCategories[2].CategoryId.ToString(); } else { subCategoryList3.SelectedValue = "0"; } } else { subCategory3Holder.Visible = false; } }
protected void Page_Load(object sender, EventArgs e) { List <MenuItem> categoryMenu = new List <MenuItem>(); advertiserGrid.RowDataBound += new GridViewRowEventHandler(advertiserGrid_RowDataBound); MenuItem allAdvertisers = new MenuItem("View All", "0", null, "/admin/AdvertiserList.aspx"); categoryMenu.Add(allAdvertisers); bool inactive = Globals.ConvertToBool(Request.QueryString["inactive"]); String inactiveLinkAppender = String.Empty; if (inactive) { inactiveLinkAppender = "&inactive=1"; } foreach (DollarSaverDB.CategoryRow category in Station.PrimaryCategories) { MenuItem item = new MenuItem(category.Name, category.CategoryId.ToString(), null, "/admin/AdvertiserList.aspx?id=" + category.CategoryId + inactiveLinkAppender); categoryMenu.Add(item); } categoryMenuRepeater.DataSource = categoryMenu; categoryMenuRepeater.DataBind(); int categoryId = GetIdFromQueryString(); DollarSaverDB.AdvertiserDataTable advertisers; if (categoryId > 0) { CategoryTableAdapter categoryAdapter = new CategoryTableAdapter(); DollarSaverDB.CategoryDataTable categories = categoryAdapter.GetCategory(categoryId); if (categories.Count != 1) { Response.Redirect("~/admin/AdvertiserList.aspx"); } DollarSaverDB.CategoryRow category = categories[0]; if (category.StationId != StationId) { Response.Redirect("~/admin/AdvertiserList.aspx"); } if (inactive) { advertisers = category.InactiveAdvertisers; } else { advertisers = category.ActiveAdvertisers; } } else { if (inactive) { advertisers = Station.InactiveAdvertisers; } else { advertisers = Station.ActiveAdvertisers; } } if (advertisers.Count > 0) { advertiserHolder.Visible = true; noAdvertiserHolder.Visible = false; advertiserGrid.DataSource = advertisers.Rows; advertiserGrid.DataBind(); } else { advertiserHolder.Visible = false; noAdvertiserHolder.Visible = true; } if (inactive) { activeLinkHolder.Visible = true; inactiveLinkHolder.Visible = false; headerCell.Text = "Inactive Advertisers"; } else { activeLinkHolder.Visible = false; inactiveLinkHolder.Visible = true; } if (CurrentUser.Role == AdminRole.Root || CurrentUser.Role == AdminRole.Admin) { categoryHolder.Visible = true; } else { categoryHolder.Visible = false; } }