private void PopulateUserMenu()
        {
            AppMenuBLL appMenu = new AppMenuBLL();

            try
            {
                DataTable dtUserMenu = appMenu.GetUserMenuData(userIdLabel.Text.Trim(), menuForAppDropDownList.SelectedValue.Trim(), menuTypeDropDownList.SelectedValue.Trim());
                DataTable dtAllMenu = appMenu.GetAllMenusForMappingUserMenu(menuForAppDropDownList.SelectedValue.Trim(), menuTypeDropDownList.SelectedValue.Trim());
                DataRow dr = null;

                //for (int i = 0; i < dtUserMenu.Rows.Count; i++)
                //{
                //    if (dtUserMenu.Rows[i]["IsDisplay"].ToString() == "False")
                //    {
                //        dtUserMenu.Rows.RemoveAt(i);
                //        i--;
                //    }
                //}

                for (int i = 0; i < dtUserMenu.Rows.Count; i++)
                {
                    for (int j = 0; j < dtAllMenu.Rows.Count; j++)
                    {
                        if (dtUserMenu.Rows[i]["ParentMenuId"].ToString() == dtAllMenu.Rows[j]["MenuId"].ToString())
                        {
                            dr = dtUserMenu.NewRow();

                            dr["MenuId"] = dtAllMenu.Rows[j]["MenuId"].ToString();
                            dr["MenuName"] = dtAllMenu.Rows[j]["MenuName"].ToString();
                            dr["ToolTipDescription"] = dtAllMenu.Rows[j]["ToolTipDescription"].ToString();
                            dr["ParentMenuId"] = dtAllMenu.Rows[j]["ParentMenuId"].ToString();
                            dr["URL"] = dtAllMenu.Rows[j]["URL"].ToString();
                            dr["MenuSorting"] = dtAllMenu.Rows[j]["MenuSorting"].ToString();
                            dr["DisplayName"] = dtAllMenu.Rows[j]["DisplayName"].ToString();
                            dr["ImageURL"] = dtAllMenu.Rows[j]["ImageURL"].ToString();
                            dr["MenuTarget"] = dtAllMenu.Rows[j]["MenuTarget"].ToString();

                            dtUserMenu.Rows.Add(dr);
                        }
                    }
                }

                /////////////////////////////to convert column data type////////////////////////////////
                DataTable dtCloned = dtUserMenu.Clone();
                dtCloned.Columns["MenuSorting"].DataType = typeof(Int32);
                foreach (DataRow row in dtUserMenu.Rows)
                {
                    dtCloned.ImportRow(row);
                }

                dtUserMenu = dtUserMenu.DefaultView.ToTable(true, "MenuId", "MenuName", "ToolTipDescription", "ParentMenuId", "URL", "MenuSorting", "DisplayName", "MenuTarget", "ImageURL");
                dtUserMenu.DefaultView.Sort = "MenuSorting";
                dtUserMenu = dtUserMenu.DefaultView.ToTable();

                /////////////////////////////to sort by column(s)///////////////////////////////////////
                if (dtUserMenu.Rows.Count > 0)
                {
                    DataView dv = dtUserMenu.DefaultView;
                    dv.Sort = "MenuSorting";
                    dtUserMenu = dv.ToTable();
                }

                if (dtUserMenu.Rows.Count > 0)
                {
                    testAllMenu.Items.Clear();
                    AddTopMenuItems(dtUserMenu);
                }
                else
                {
                    msgbox.Visible = true; msgTitleLabel.Text = "User Menu Not Found!!!"; msgDetailLabel.Text = "";
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                if (ex.InnerException != null) { message += " --> " + ex.InnerException.Message; }
                MyAlertBox("ErrorAlert(\"" + ex.GetType() + "\", \"" + message + "\", \"\");");
            }
            finally
            {
                appMenu = null;
            }
        }
Exemple #2
0
        private void PopulateUserMenu(string menufor)
        {
            string path = HttpContext.Current.Request.Url.AbsolutePath;
            AppMenuBLL appMenu = new AppMenuBLL();
            string appmenufor = "";
            try
            {
                if ((string)LumexSessionManager.Get("isMenu") == "N")
                {
                    if (menufor == "inv")
                    {
                        appmenufor = "Inventory";
                    }
                    else if (menufor == "acc")
                    {
                        appmenufor = "Accounts";
                    }
                    else if (menufor == "stn")
                    {
                        appmenufor = "Settings";
                    }
                    DataTable dtUserMenu = appMenu.GetUserMenuData(LumexSessionManager.Get("ActiveUserId").ToString(), appmenufor, "Sideber");
                    DataTable dtAllMenu = appMenu.GetAllMenusForMappingUserMenu(appmenufor, "Sideber");
                    DataRow dr = null;

                    if (path == "/Default.aspx")
                    {
                        path = "Done";
                    }
                    else
                    {
                        for (int i = 0; i < dtUserMenu.Rows.Count; i++)
                        {
                            if (path == dtUserMenu.Rows[i]["URL"].ToString())
                            {
                                path = "Done";
                                break;
                            }
                        }
                    }
                    if (path != "Done")
                    {
                        // LumexSessionManager.RemoveAll();
                        //Response.Redirect("~/Page404.aspx", false);
                        Response.Redirect("~/Default.aspx", false);
                    }
                    else
                    {
                        for (int i = 0; i < dtUserMenu.Rows.Count; i++)
                        {
                            if (dtUserMenu.Rows[i]["IsDisplay"].ToString() == "False")
                            {
                                dtUserMenu.Rows.RemoveAt(i);
                                i--;
                            }
                        }

                        for (int i = 0; i < dtUserMenu.Rows.Count; i++)
                        {
                            for (int j = 0; j < dtAllMenu.Rows.Count; j++)
                            {
                                if (dtUserMenu.Rows[i]["ParentMenuId"].ToString() == dtAllMenu.Rows[j]["MenuId"].ToString())
                                {
                                    dr = dtUserMenu.NewRow();

                                    dr["MenuId"] = dtAllMenu.Rows[j]["MenuId"].ToString();
                                    dr["MenuName"] = dtAllMenu.Rows[j]["MenuName"].ToString();
                                    dr["ToolTipDescription"] = dtAllMenu.Rows[j]["ToolTipDescription"].ToString();
                                    dr["ParentMenuId"] = dtAllMenu.Rows[j]["ParentMenuId"].ToString();
                                    dr["URL"] = dtAllMenu.Rows[j]["URL"].ToString();
                                    dr["MenuSorting"] = dtAllMenu.Rows[j]["MenuSorting"].ToString();
                                    dr["DisplayName"] = dtAllMenu.Rows[j]["DisplayName"].ToString();
                                    dr["ImageURL"] = dtAllMenu.Rows[j]["ImageURL"].ToString();
                                    dr["MenuTarget"] = dtAllMenu.Rows[j]["MenuTarget"].ToString();
                                    dr["IsDisplay"] = dtAllMenu.Rows[j]["IsDisplay"].ToString();

                                    dtUserMenu.Rows.Add(dr);
                                }
                            }
                        }

                        ///////////////////////////////to convert column data type////////////////////////////////
                        //DataTable dtCloned = dtUserMenu.Clone();
                        //dtCloned.Columns["UserMenuSorting"].DataType = typeof(Int32);
                        //foreach (DataRow row in dtUserMenu.Rows)
                        //{
                        //    dtCloned.ImportRow(row);
                        //}

                        dtUserMenu = dtUserMenu.DefaultView.ToTable(true, "MenuId", "MenuName", "ToolTipDescription", "ParentMenuId", "URL", "MenuSorting", "DisplayName", "MenuTarget", "ImageURL", "IsDisplay");
                        dtUserMenu.DefaultView.Sort = "MenuSorting";
                        dtUserMenu = dtUserMenu.DefaultView.ToTable();
                        usermenu = dtUserMenu;
                        ///////////////////////////////to sort by column(s)///////////////////////////////////////
                        //if (dtUserMenu.Rows.Count > 0)
                        //{
                        //    DataView dv = dtUserMenu.DefaultView;
                        //    dv.Sort = "UserMenuSorting";
                        //    dtUserMenu = dv.ToTable();
                        //}

                        //   mainMenu.Items.Clear();
                        getParentMenulist(dtUserMenu);
                        ParentLevelMenuRepeater.DataSource = ParentLevelMenuItems;
                        ParentLevelMenuRepeater.DataBind();
                        //if (menufor == "inv")
                        //{
                        //    LumexSessionManager.Add("menuinv", dtUserMenu);
                        //}
                        //else if (menufor == "acc")
                        //{
                        //    LumexSessionManager.Add("menuacc", dtUserMenu);
                        //}
                        //else if (menufor == "stn")
                        //{
                        //    LumexSessionManager.Add("menustn", dtUserMenu);
                        //}

                    }
                }
                else if ((string)LumexSessionManager.Get("isMenu") == "Y")
                {
                    //usermenu = new DataTable();
                    //usermenu = (DataTable)LumexSessionManager.Get("Menudata");
                    if (path == "/Default.aspx")
                    {
                        path = "Done";
                    }
                    else
                    {
                        for (int i = 0; i < usermenu.Rows.Count; i++)
                        {
                            if (path == usermenu.Rows[i]["URL"].ToString())
                            {
                                path = "Done";
                                break;
                            }
                        }
                    }



                    if (path != "Done")
                    {
                        LumexSessionManager.RemoveAll();
                        Response.Redirect("~/Default.aspx", false);
                    }
                    getParentMenulist(usermenu);
                    ParentLevelMenuRepeater.DataSource = ParentLevelMenuItems;
                    ParentLevelMenuRepeater.DataBind();
                }
            }
            catch (Exception ex)
            {
                //  msgboxApp.Visible = true; msgTitleLabelApp.Text = "Exception!!!"; msgDetailLabelApp.Text = ex.Message;
            }
            finally
            {
                appMenu = null;
            }
        }