예제 #1
0
        void ddlOrganizations_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (ddlOrganizations.SelectedValue == "0")
                {
                    //get the whole list of users:
                    ddlUsers.DataSource     = UsersListTable;
                    ddlUsers.DataValueField = "UserID";
                    ddlUsers.DataTextField  = "UserName";
                    ddlUsers.DataBind();
                }
                else
                {
                    var selected_org = ddlOrganizations.SelectedItem.Text;
                    var selected     = selected_org.Substring(0, selected_org.IndexOf(":") - 1);

                    //get users related to the selected organization only.
                    //if we already have selected user related to the selected organization,
                    //then select it.
                    var find_selected = false;
                    var selectedUser  = ddlUsers.SelectedValue;
                    if (selected == ((DataRow)UsersListTable.Select("UserID = " + selectedUser)[0])["Organization"].ToString())
                    {
                        find_selected = true;
                    }

                    var col = new ListItemCollection();
                    var it  = new ListItem("", "0");
                    col.Add(it);

                    var drows = UsersListTable.Select("Organization = '" + selected + "'");
                    foreach (var dr in drows)
                    {
                        it = new ListItem(dr["UserName"].ToString(), ((int)dr["UserID"]).ToString());
                        col.Add(it);
                    }

                    ddlUsers.DataSource     = col;
                    ddlUsers.DataValueField = "Value";
                    ddlUsers.DataTextField  = "Text";
                    ddlUsers.DataBind();

                    if (find_selected)
                    {
                        ddlUsers.SelectedValue = selectedUser;
                    }
                }
            }
            catch (Exception ex)
            {
                //erase event OnError:
                if (this.OnError != null)
                {
                    var arg = new OrgUsersErrEventArgs();
                    arg.ErrorMessage = ex.Message;
                    this.OnError(this, arg);
                }
            }
        }
예제 #2
0
        void ddlUsers_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                var selected = ddlUsers.SelectedValue;

                if (selected == "0")
                {
                    //get the whole list of organizations:
                    ddlOrganizations.DataSource     = OrgList;
                    ddlOrganizations.DataValueField = "OrgCode";
                    ddlOrganizations.DataTextField  = "OrganizationDesc";
                    ddlOrganizations.DataBind();
                }
                else
                {
                    //get organizations list according user's organization
                    //only in case if selected organization = "0"
                    //in other case we already have initiated list for organizations:

                    if (ddlOrganizations.SelectedValue == "0")
                    {
                        var userOrg = ((DataRow)UsersListTable.Select("UserID = " + selected)[0])["Organization"].ToString();

                        var col = new ListItemCollection();
                        var it  = new ListItem("", "0");
                        col.Add(it);

                        var orgsList = OrgList.Where(o => o.Organization == userOrg);
                        foreach (var org in orgsList)
                        {
                            it = new ListItem(org.OrganizationDesc, org.Organization);
                            col.Add(it);
                        }

                        ddlOrganizations.DataSource     = col;
                        ddlOrganizations.DataValueField = "Value";
                        ddlOrganizations.DataTextField  = "Text";
                        ddlOrganizations.DataBind();
                    }
                }
            }
            catch (Exception ex)
            {
                //erase event OnError:
                if (this.OnError != null)
                {
                    var arg = new OrgUsersErrEventArgs();
                    arg.ErrorMessage = ex.Message;
                    this.OnError(this, arg);
                }
            }
        }