123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- using ComponentFactory.Krypton.Navigator;
- using ComponentFactory.Krypton.Toolkit;
- using NXWMS.Client.Model.AppModels.Condition.SysSettings;
- using NXWMS.Commons;
- using NXWMS.Services;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace NXWMS
- {
- public partial class MainFormNew : KryptonForm
- {
- public MainFormNew()
- {
- InitializeComponent();
- InitCirclePicBox();
- InitData();
- LoadMainMenuData();
- BasDictionaryUtil.GetAndSetBasDictionary();
- }
- private int _widthLeftRight;
- private void buttonSpecHeaderGroup1_Click(object sender, EventArgs e)
- {
- #region 20210222 孙亚龙新增布局控制
- kryptonSplitContainer1.SuspendLayout();
- if (kryptonHeaderGroup1.HeaderPositionPrimary == VisualOrientation.Top)
- {
- // Make the left panel of the splitter fixed in size
- kryptonSplitContainer1.FixedPanel = FixedPanel.Panel1;
- kryptonSplitContainer1.IsSplitterFixed = true;
- // Remember the current height of the header group
- _widthLeftRight = kryptonHeaderGroup1.Width;
- // We have not changed the orientation of the header yet, so the width of
- // the splitter panel is going to be the height of the collapsed header group
- int newWidth = kryptonHeaderGroup1.PreferredSize.Height;
- // Make the header group fixed just as the new height
- kryptonSplitContainer1.Panel1MinSize = newWidth;
- kryptonSplitContainer1.SplitterDistance = newWidth;
- // Change header to be vertical and button to near edge
- kryptonHeaderGroup1.HeaderPositionPrimary = VisualOrientation.Right;
- buttonSpecHeaderGroup1.Edge = PaletteRelativeEdgeAlign.Near;
- }
- else
- {
- // Make the left panel of the splitter fixed in size
- kryptonSplitContainer1.FixedPanel = FixedPanel.Panel1;
- kryptonSplitContainer1.IsSplitterFixed = true;
- // Put back the minimise size to the original
- kryptonSplitContainer1.Panel1MinSize = _widthLeftRight;
- // Calculate the correct splitter we want to put back
- kryptonSplitContainer1.SplitterDistance = _widthLeftRight;
- // Change header to be horizontal and button to far edge
- kryptonHeaderGroup1.HeaderPositionPrimary = VisualOrientation.Top;
- buttonSpecHeaderGroup1.Edge = PaletteRelativeEdgeAlign.Far;
- }
- kryptonSplitContainer1.ResumeLayout();
- #endregion
- }
- private void InitCirclePicBox()
- {
- System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
- path.AddEllipse(this.picb_UserPhoto.ClientRectangle);
- Region reg = new Region(path);
- this.picb_UserPhoto.Region = reg;
- }
- private void MainFormNew_Load(object sender, EventArgs e)
- {
- this.Text = "WMS";
- }
- /// <summary>
- /// 初始化数据
- /// </summary>
- private void InitData()
- {
- //TODO暂时放所有
- AppConfig.MenuUserGroupList = SysSettingsServices.menuService.GetLevelList(new MenuLevelCondition { }).Data;
- }
- /// <summary>
- /// 树节点双击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void TreeMenuNodeDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
- {
- try
- {
- var menuView = sender as KryptonTreeView;
- var selectedNode = menuView.SelectedNode;
- if (selectedNode == null)
- {
- return;
- }
- //限定打开个数
- if (knavg_MainTabControl.Pages.Count >= AppConfig._MaxFormCount)
- {
- KryptonMessageBox.Show($"当前打开窗体过多,影响系统运行速度\r\n\r\n请关闭其它窗体,在进行打开新菜单窗体!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- var currMenu = AppConfig.MenuUserGroupList.Where(m => m.MenuCode == selectedNode.Name).ToList();
- var objectHandle = Activator.CreateInstance(null, currMenu.FirstOrDefault().MenuURL);
- var frm = (Form)objectHandle.Unwrap();
- AddFrmMenuPage(frm, selectedNode);
- }
- catch (Exception ex)
- {
- KryptonMessageBox.Show($"加载窗体错误!\r\n" + ex.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void AddFrmMenuPage(Form frm, TreeNode treeNode)
- {
- KryptonPage tmpPage = knavg_MainTabControl.Pages.FirstOrDefault(x => x.Name == treeNode.Name);
- if (tmpPage != null)
- {
- knavg_MainTabControl.SelectedPage = tmpPage;
- knavg_MainTabControl.Refresh();
- }
- else
- {
- KryptonPage tmpPage1 = new KryptonPage { Text = treeNode.Text, Name = treeNode.Name };
- ButtonSpecAny bsa = new ButtonSpecAny
- {
- Style = PaletteButtonStyle.FormClose,
- Type = PaletteButtonSpecStyle.FormClose,
- Tag = tmpPage1
- };
- bsa.Click += BtnClose_Click;
- knavg_MainTabControl.Pages.Add(tmpPage1);
- knavg_MainTabControl.SelectedPage = tmpPage1;
- knavg_MainTabControl.SelectedPage.ButtonSpecs.Add(bsa);
- frm.TopLevel = false;
- //frm.WindowState = FormWindowState.Maximized;
- //frm.MinimizeBox = false;
- frm.FormBorderStyle = FormBorderStyle.None;
- frm.Dock = DockStyle.Fill;
- frm.Parent = tmpPage1;
- frm.Show();
- }
- }
- private void BtnClose_Click(object sender, EventArgs e)
- {
- ButtonSpecAny bsa = sender as ButtonSpecAny;
- knavg_MainTabControl.Pages.Remove(bsa.Tag);
- knavg_MainTabControl.SelectedPage = knavg_MainTabControl.Pages[knavg_MainTabControl.Pages.Count - 1];
- }
- private void LoadMainMenuData()
- {
- var mainMenuResult1 = (from x in AppConfig.MenuUserGroupList.Where(x => x.MainMenuPid == -1 && x.MainMenuUsedFlag == 1)
- select new
- { x.MainMenuId, x.MainMenuName, x.MainMenuCode, x.MainMenuOrder, x.MainMenuURL }).Distinct().OrderBy(x => x.MainMenuOrder);
- if (mainMenuResult1.Count() > 0)
- {
- foreach (var item in mainMenuResult1)
- {
- KryptonPage tmpPage1 = new KryptonPage { Text = item.MainMenuName, Name = item.MainMenuCode };
- KryptonTreeView treeMenu = new KryptonTreeView();
- foreach (var itemDetail in (from x in AppConfig.MenuUserGroupList.Where(m => m.MainMenuCode == item.MainMenuCode && m.MenuUsedFlag == 1)
- select new
- { x.MenuCode, x.MenuName, x.MenuId, x.MenuOrder, x.MenuURL }).Distinct().OrderBy(x => x.MenuId))
- {
- treeMenu.Nodes.Add(itemDetail.MenuCode, itemDetail.MenuName);
- }
- treeMenu.ItemStyle = ButtonStyle.Custom2;
- treeMenu.StateCommon.Node.Border.Color1 = Color.Black;
- treeMenu.StateCommon.Node.Border.Color2 = Color.Black;
- treeMenu.OverrideFocus.Node.Back.Color1 = Color.FromArgb(132, 0, 255);
- treeMenu.OverrideFocus.Node.Back.Color2 = Color.FromArgb(132, 0, 255);
- treeMenu.Palette = kryptonPalette2;
- treeMenu.NodeMouseDoubleClick += new TreeNodeMouseClickEventHandler(TreeMenuNodeDoubleClick);
- tmpPage1.Controls.Add(treeMenu);
- treeMenu.Dock = DockStyle.Fill;
- knavg_MainMenu.Pages.Add(tmpPage1);
- }
- KryptonPage tmpPage2 = new KryptonPage(Text = " ", Name = "DefaultPage");
- knavg_MainMenu.Pages.Add(tmpPage2);
- knavg_MainMenu.SelectedPage = tmpPage2;
- }
- }
- private void MainFormNew_FormClosing(object sender, FormClosingEventArgs e)
- {
- Application.Exit();
- }
- }
- }
|