分配的用户只能看到分配的数据(管理面板)

Assigned users to see only assigned data (Admin Panel)

我有一个场景,我有不同类型的角色,例如 超级管理员 = 0

管理员 = 1

用户数 = 2

我想要的是,

有一个下拉列表,其中包含多个组织名称,每个组织名称都与管理员和用户相关。

现在,当任何用户或管理员登录到面板时,他应该只能查看与他相关的组织名称,并且在只读模式下也是如此属性。

我已经创建了 table,现在我可以根据 SuperAdmin 的要求在下拉列表中看到所有组织。

我创建了两个 table,一个用于 User,第二个用于 CompanyName,并在它们之间建立了关系。现在我想要的是

用户登录时的查询他应该只能在下拉列表中查看与他相关的组织名称

嗨,

我有一个场景,我有不同类型的角色,例如超级管理员、管理员和用户。

我想要的是,

有一个下拉列表,其中包含多个组织名称,每个组织名称都与管理员和用户相关。

现在,当任何用户或管理员登录到面板时,他应该只能查看与他相关的组织名称,并且在只读模式下也是如此属性。

我已经创建了 table,现在我可以根据 SuperAdmin 的要求在下拉列表中看到所有组织。

我创建了两个 table,一个用于 User,第二个用于 CompanyName,并在它们之间建立了关系。现在我想要的是

用户登录时的查询他应该只能在下拉列表中查看与他相关的组织名称

我的下拉列表代码是

private void BindDropdownlist()
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultCSRConnection"].ConnectionString);
        SqlCommand cmd = new SqlCommand("Select * from tbl_ngoname", conn);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);



        ddlngonameselect.DataValueField = ds.Tables[0].Columns["Id"].ToString();
        ddlngonameselect.DataTextField = ds.Tables[0].Columns["ngo_name"].ToString();
        ddlngonameselect.DataSource = ds.Tables[0];
        ddlngonameselect.DataBind();
        ddlngonameselect.Items.Insert(0, new ListItem("--Show All--", "0"));

    }

另请参阅每个用户的用户类型。

cmd.Parameters.AddWithValue("@password", md5(txtPassword.Text));
        cmd.Parameters.AddWithValue("@active", 1);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
        if (dt != null && dt.Rows.Count > 0)
        {
            if (dt.Rows[0]["usertype"].ToString() == "0") //SuperAdmin
            {
                Session["UserType"] = "0";
                Session["User"] = dt.Rows[0]["username"].ToString();
                Response.Redirect("csrdashboards.aspx");
            }
            else if (dt.Rows[0]["usertype"].ToString() == "1") // Admin
            {
                Session["UserType"] = "1";
                Session["User"] = dt.Rows[0]["username"].ToString();
                Response.Redirect("csrdashboards.aspx");
            }
            else if (dt.Rows[0]["usertype"].ToString() == "2") // User
            {
                Session["UserType"] = "2";
                Session["User"] = dt.Rows[0]["username"].ToString();
                Response.Redirect("csrdashboards.aspx");
            }
        }

请帮忙

经过研究调试,终于有了自己的答案。

我来了:-

private void BindDropdownlist()
    {
        try
        {
            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultCSRConnection"].ConnectionString))
            {
                tempUsertype = Convert.ToString(Session["UserType"]);
                if (tempUsertype != string.Empty)
                {
                    conn.Open();
                    using (SqlCommand cmd = new SqlCommand((tempUsertype == "0" ? "Select * from tbl_ngoname" : "Select * from tbl_ngoname where id in (Select NgoId from tbl_User where username=@username)"), conn))
                    {
                        cmd.Parameters.AddWithValue("@username", Convert.ToString(Session["User"]));
                        SqlDataAdapter da = new SqlDataAdapter(cmd);
                        DataSet ds = new DataSet();
                        da.Fill(ds);
                        ddlngonameselect.DataValueField = ds.Tables[0].Columns["Id"].ToString();
                        ddlngonameselect.DataTextField = ds.Tables[0].Columns["ngo_name"].ToString();
                        ddlngonameselect.DataSource = ds.Tables[0];
                        ddlngonameselect.SelectedIndex = 0;

                        if (Session["UserType"] == "1" || Session["UserType"] == "2")
                        {
                            ddlngonameselect.Enabled = false;
                        }
                        else
                        {
                            ddlngonameselect.Items.Insert(0, new ListItem() { Text = "--Select NGO--", Value = "0" });
                            ddlngonameselect.Enabled = true;
                        }

                        ddlngonameselect.DataBind();
                    }
                }
                else
                {
                    Response.Write("Some error");
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }

    }

我试过了,对我有用:)