可以接受SQL查询结果的c# Web应用条件语句

本文关键字:Web 应用 条件 语句 结果 SQL 查询 | 更新日期: 2023-09-27 18:07:11

我正在开发一个较旧的CMS (c#, Visual Studio 2005, . net 2.0),它根据用户id和用户与供应商id的关系拆分对象的可见性。目前,我有一个条件语句,它的作用是:

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";
        }
    }

现在我们有了很多很多Special Vendor 1的子供应商,我想做的是从一个存储过程中拉出所有的子供应商,它将在添加子供应商时实时更新结果。但是,我不知道如何将一组整数结果集成到条件语句中。我的第一反应是在第一个条件下使用foreach,但我没有这样做的经验。来调用存储过程EXEC GetAllSV1ChildVendors它返回一个包含24个供应商的列表,我想过滤掉这些供应商以获得Special Vendor 1的可见性访问。我应该填充一个数组吗?是否有更直接访问存储过程结果的方法?任何帮助都很好。谢谢!

可以接受SQL查询结果的c# Web应用条件语句

如果您将供应商id列表存储在list中,您可以

if (VendorList.Contains(CurrentUser.Vendor.Id) ...