Пример #1
0
        private void OpenScreen(sp_SYS_GetMenu_Result data)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                if (!IsScreenOpened(data))
                {
                    var uc = GetUserControlFromID(data.ID);
                    if (uc != null)
                    {
                        TabPage tab = new TabPage(data.ID);
                        tab.Name = data.ID;
                        tab.Text = string.Format("{0}: {1}", data.ID, data.MENU_NAME);
                        tab.Tag  = data;
                        uc.Dock  = DockStyle.Fill;
                        tab.Controls.Add(uc);
                        tabControl.TabPages.Add(tab);
                        tabControl.SelectedIndex = tabControl.TabPages.Count - 1;

                        tabControl.Visible = tabControl.TabPages.Count > 0;
                    }
                    else
                    {
                        rMessageBox.ShowWarning(this, string.Format("ไม่พบไฟล์หน้าจอนี้ [{0}]", data.ID), MessageBoxButtons.OK);
                    }
                }
                else
                {
                    foreach (TabPage tabPage in tabControl.TabPages)
                    {
                        if ((tabPage.Tag as sp_SYS_GetMenu_Result) == data)
                        {
                            tabControl.SelectedTab = tabPage;
                        }
                    }
                }
                if (tabControl.SelectedTab != null)
                {
                    this.ActiveControl = tabControl.SelectedTab.Controls[0].Controls[0];
                }
            }
            catch (Exception ex)
            {
                rMessageBox.ShowException(this, ex);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
Пример #2
0
 private bool IsScreenOpened(sp_SYS_GetMenu_Result data)
 {
     try
     {
         foreach (TabPage tab in tabControl.TabPages)
         {
             if (tab.Tag as sp_SYS_GetMenu_Result == data)
             {
                 return(true);
             }
         }
         return(false);
     }
     catch (Exception ex)
     {
         rMessageBox.ShowException(this, ex);
         return(true);
     }
 }
Пример #3
0
        public void CloseTab(sp_SYS_GetMenu_Result data)
        {
            try
            {
                for (int i = 0; i < tabControl.TabCount; i++)
                {
                    if (tabControl.TabPages[i].Tag as sp_SYS_GetMenu_Result == data)
                    {
                        tabControl.TabPages.RemoveAt(i);
                    }
                }

                tabControl.Visible = tabControl.TabPages.Count > 0;
            }
            catch (Exception ex)
            {
                rMessageBox.ShowException(this, ex);
            }
        }
Пример #4
0
        private void LoadMenu()
        {
            List <sp_SYS_GetMenu_Result> menus = vmSys.LoadMenu();

            foreach (var m in menus)
            {
                if (m.PARENT_ID == null)
                {
                    ToolStripMenuItem menu = new ToolStripMenuItem()
                    {
                        Name = m.ID,
                        Text = "&" + m.MENU_NAME,
                        Tag  = m,
                    };
                    menuStrip.Items.Add(menu);
                }
                else
                {
                    if (m.MENU_TYPE == "FORM")
                    {
                        ToolStripItem form = new ToolStripMenuItem()
                        {
                            Name = m.ID,
                            Text = "&" + m.MENU_NAME,
                            Tag  = m,
                        };
                        form.Click += new EventHandler(MenuItem_Click);
                        foreach (ToolStripMenuItem d in menuStrip.Items)
                        {
                            sp_SYS_GetMenu_Result data = d.Tag as sp_SYS_GetMenu_Result;
                            if (d.DropDownItems.Count > 0)
                            {
                                foreach (ToolStripMenuItem d2 in d.DropDownItems)
                                {
                                    sp_SYS_GetMenu_Result data2 = d2.Tag as sp_SYS_GetMenu_Result;
                                    if (data2.ID == m.PARENT_ID)
                                    {
                                        d2.DropDownItems.Add(form);
                                    }
                                }
                            }
                            if (data.ID == m.PARENT_ID)
                            {
                                d.DropDownItems.Add(form);
                            }
                        }
                    }
                    else if (m.MENU_TYPE == "MENU")
                    {
                        ToolStripMenuItem menu = new ToolStripMenuItem()
                        {
                            Name = m.ID,
                            Text = "&" + m.MENU_NAME,
                            Tag  = m,
                        };
                        foreach (ToolStripMenuItem d in menuStrip.Items)
                        {
                            if (((sp_SYS_GetMenu_Result)d.Tag).ID == m.PARENT_ID)
                            {
                                d.DropDownItems.Add(menu);
                            }
                        }
                    }
                }
            }
        }
Пример #5
0
        private void MenuItem_Click(object sender, EventArgs e)
        {
            sp_SYS_GetMenu_Result row = ((ToolStripItem)sender).Tag as sp_SYS_GetMenu_Result;

            this.OpenScreen(row);
        }