C# Web App Conditional statement that can accept results from a SQL Query
I am working on an older CMS (C#, Visual Studio 2005, .NET 2.0) that splits visibility of an object based on a user's id and that user's relationship to a vendor ID. I currently have a conditional that has worked so far that simply does this:
protected void Page_Load(object sender, EventArgs e)
{
// If the current user is Special Vendor 1, or has a parent Id of Special Vendor 1 then load the "Special Vendor 1" documents
if ((CurrentUser.Vendor.Id == 3) || (CurrentUser.Vendor.ParentVendor.Id == 3) || (CurrentUser.Vendor.ParentVendor.Id == 1) || (CurrentUser.Vendor.Id == 374) || (CurrentUser.Vendor.ParentVendor.Id == 374))
{
hypCatalogAccessLink.NavigateUrl = "documents/SpecialVendor1_Catalog_Access_v3 3_2011_08SV1.pdf";
hypCatalogAccessLink.Text = "Download Special Vendor 1 Catalog Access";
hypCatalogAccessLink.Target = "_blank";
}
// Another Special Vendor (Special Vendor 2)
else if ((CurrentUser.Vendor.Name == "Special Vendor 2") || (CurrentUser.Vendor.ParentVendor.Name == "Special Vendor 2"))
{
hypCatalogAccessLink.NavigateUrl = "documents/SpecialVendor2_Catalog_Access_v3.3_2011_08_SV2.pdf";
hypCatalogAccessLink.Text = "Download Special Vendor 2 Catalog Access";
hypCatalogAccessLink.Target = "_blank";
}
else // Use Generic Vendor Catalog as default
{
hypCatalogAccessLink.NavigateUrl = "documents/Generic_Catalog_Access_v3 3_2011_08.pdf";
hypCatalogAccessLink.Text = "Download Generic Catalog Access";
hypCatalogAccessLink.Target = "_blank";
}
}
What I want to do, now that we have many, many chil开发者_如何学Pythond vendors of Special Vendor 1, is to pull all the child vendors from a stored procedure, which will update results as child vendors are added, in real-time. However, I do not know how to integrate a set of integer results into a conditional statement. My first instinct is to use a foreach in the first condition, but I have no experience doing such things. I can call my stored procedure with EXEC GetAllSV1ChildVendors Which returns a list of 24 vendors that I want to filter out for Special Vendor 1 visibility access. Should I populate an array? Is there a more direct access method to the results of the stored procedure? Any help is great. Thanks!
if you store your list of vendor ids in a List, you could do
if (VendorList.Contains(CurrentUser.Vendor.Id) ...
精彩评论