MainFormNew.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. using ComponentFactory.Krypton.Navigator;
  2. using ComponentFactory.Krypton.Toolkit;
  3. using NXWMS.Client.Model.AppModels.Condition.SysSettings;
  4. using NXWMS.Commons;
  5. using NXWMS.Services;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Windows.Forms;
  14. namespace NXWMS
  15. {
  16. public partial class MainFormNew : KryptonForm
  17. {
  18. public MainFormNew()
  19. {
  20. InitializeComponent();
  21. InitCirclePicBox();
  22. InitData();
  23. LoadMainMenuData();
  24. BasDictionaryUtil.GetAndSetBasDictionary();
  25. }
  26. private int _widthLeftRight;
  27. private void buttonSpecHeaderGroup1_Click(object sender, EventArgs e)
  28. {
  29. #region 20210222 孙亚龙新增布局控制
  30. kryptonSplitContainer1.SuspendLayout();
  31. if (kryptonHeaderGroup1.HeaderPositionPrimary == VisualOrientation.Top)
  32. {
  33. // Make the left panel of the splitter fixed in size
  34. kryptonSplitContainer1.FixedPanel = FixedPanel.Panel1;
  35. kryptonSplitContainer1.IsSplitterFixed = true;
  36. // Remember the current height of the header group
  37. _widthLeftRight = kryptonHeaderGroup1.Width;
  38. // We have not changed the orientation of the header yet, so the width of
  39. // the splitter panel is going to be the height of the collapsed header group
  40. int newWidth = kryptonHeaderGroup1.PreferredSize.Height;
  41. // Make the header group fixed just as the new height
  42. kryptonSplitContainer1.Panel1MinSize = newWidth;
  43. kryptonSplitContainer1.SplitterDistance = newWidth;
  44. // Change header to be vertical and button to near edge
  45. kryptonHeaderGroup1.HeaderPositionPrimary = VisualOrientation.Right;
  46. buttonSpecHeaderGroup1.Edge = PaletteRelativeEdgeAlign.Near;
  47. }
  48. else
  49. {
  50. // Make the left panel of the splitter fixed in size
  51. kryptonSplitContainer1.FixedPanel = FixedPanel.Panel1;
  52. kryptonSplitContainer1.IsSplitterFixed = true;
  53. // Put back the minimise size to the original
  54. kryptonSplitContainer1.Panel1MinSize = _widthLeftRight;
  55. // Calculate the correct splitter we want to put back
  56. kryptonSplitContainer1.SplitterDistance = _widthLeftRight;
  57. // Change header to be horizontal and button to far edge
  58. kryptonHeaderGroup1.HeaderPositionPrimary = VisualOrientation.Top;
  59. buttonSpecHeaderGroup1.Edge = PaletteRelativeEdgeAlign.Far;
  60. }
  61. kryptonSplitContainer1.ResumeLayout();
  62. #endregion
  63. }
  64. private void InitCirclePicBox()
  65. {
  66. System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
  67. path.AddEllipse(this.picb_UserPhoto.ClientRectangle);
  68. Region reg = new Region(path);
  69. this.picb_UserPhoto.Region = reg;
  70. }
  71. private void MainFormNew_Load(object sender, EventArgs e)
  72. {
  73. this.Text = "WMS";
  74. }
  75. /// <summary>
  76. /// 初始化数据
  77. /// </summary>
  78. private void InitData()
  79. {
  80. //TODO暂时放所有
  81. AppConfig.MenuUserGroupList = SysSettingsServices.menuService.GetLevelList(new MenuLevelCondition { }).Data;
  82. }
  83. /// <summary>
  84. /// 树节点双击事件
  85. /// </summary>
  86. /// <param name="sender"></param>
  87. /// <param name="e"></param>
  88. private void TreeMenuNodeDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
  89. {
  90. try
  91. {
  92. var menuView = sender as KryptonTreeView;
  93. var selectedNode = menuView.SelectedNode;
  94. if (selectedNode == null)
  95. {
  96. return;
  97. }
  98. //限定打开个数
  99. if (knavg_MainTabControl.Pages.Count >= AppConfig._MaxFormCount)
  100. {
  101. KryptonMessageBox.Show($"当前打开窗体过多,影响系统运行速度\r\n\r\n请关闭其它窗体,在进行打开新菜单窗体!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  102. return;
  103. }
  104. var currMenu = AppConfig.MenuUserGroupList.Where(m => m.MenuCode == selectedNode.Name).ToList();
  105. var objectHandle = Activator.CreateInstance(null, currMenu.FirstOrDefault().MenuURL);
  106. var frm = (Form)objectHandle.Unwrap();
  107. AddFrmMenuPage(frm, selectedNode);
  108. }
  109. catch (Exception ex)
  110. {
  111. KryptonMessageBox.Show($"加载窗体错误!\r\n" + ex.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
  112. }
  113. }
  114. private void AddFrmMenuPage(Form frm, TreeNode treeNode)
  115. {
  116. KryptonPage tmpPage = knavg_MainTabControl.Pages.FirstOrDefault(x => x.Name == treeNode.Name);
  117. if (tmpPage != null)
  118. {
  119. knavg_MainTabControl.SelectedPage = tmpPage;
  120. knavg_MainTabControl.Refresh();
  121. }
  122. else
  123. {
  124. KryptonPage tmpPage1 = new KryptonPage { Text = treeNode.Text, Name = treeNode.Name };
  125. ButtonSpecAny bsa = new ButtonSpecAny
  126. {
  127. Style = PaletteButtonStyle.FormClose,
  128. Type = PaletteButtonSpecStyle.FormClose,
  129. Tag = tmpPage1
  130. };
  131. bsa.Click += BtnClose_Click;
  132. knavg_MainTabControl.Pages.Add(tmpPage1);
  133. knavg_MainTabControl.SelectedPage = tmpPage1;
  134. knavg_MainTabControl.SelectedPage.ButtonSpecs.Add(bsa);
  135. frm.TopLevel = false;
  136. //frm.WindowState = FormWindowState.Maximized;
  137. //frm.MinimizeBox = false;
  138. frm.FormBorderStyle = FormBorderStyle.None;
  139. frm.Dock = DockStyle.Fill;
  140. frm.Parent = tmpPage1;
  141. frm.Show();
  142. }
  143. }
  144. private void BtnClose_Click(object sender, EventArgs e)
  145. {
  146. ButtonSpecAny bsa = sender as ButtonSpecAny;
  147. knavg_MainTabControl.Pages.Remove(bsa.Tag);
  148. knavg_MainTabControl.SelectedPage = knavg_MainTabControl.Pages[knavg_MainTabControl.Pages.Count - 1];
  149. }
  150. private void LoadMainMenuData()
  151. {
  152. var mainMenuResult1 = (from x in AppConfig.MenuUserGroupList.Where(x => x.MainMenuPid == -1 && x.MainMenuUsedFlag == 1)
  153. select new
  154. { x.MainMenuId, x.MainMenuName, x.MainMenuCode, x.MainMenuOrder, x.MainMenuURL }).Distinct().OrderBy(x => x.MainMenuOrder);
  155. if (mainMenuResult1.Count() > 0)
  156. {
  157. foreach (var item in mainMenuResult1)
  158. {
  159. KryptonPage tmpPage1 = new KryptonPage { Text = item.MainMenuName, Name = item.MainMenuCode };
  160. KryptonTreeView treeMenu = new KryptonTreeView();
  161. foreach (var itemDetail in (from x in AppConfig.MenuUserGroupList.Where(m => m.MainMenuCode == item.MainMenuCode && m.MenuUsedFlag == 1)
  162. select new
  163. { x.MenuCode, x.MenuName, x.MenuId, x.MenuOrder, x.MenuURL }).Distinct().OrderBy(x => x.MenuId))
  164. {
  165. treeMenu.Nodes.Add(itemDetail.MenuCode, itemDetail.MenuName);
  166. }
  167. treeMenu.ItemStyle = ButtonStyle.Custom2;
  168. treeMenu.StateCommon.Node.Border.Color1 = Color.Black;
  169. treeMenu.StateCommon.Node.Border.Color2 = Color.Black;
  170. treeMenu.OverrideFocus.Node.Back.Color1 = Color.FromArgb(132, 0, 255);
  171. treeMenu.OverrideFocus.Node.Back.Color2 = Color.FromArgb(132, 0, 255);
  172. treeMenu.Palette = kryptonPalette2;
  173. treeMenu.NodeMouseDoubleClick += new TreeNodeMouseClickEventHandler(TreeMenuNodeDoubleClick);
  174. tmpPage1.Controls.Add(treeMenu);
  175. treeMenu.Dock = DockStyle.Fill;
  176. knavg_MainMenu.Pages.Add(tmpPage1);
  177. }
  178. KryptonPage tmpPage2 = new KryptonPage(Text = " ", Name = "DefaultPage");
  179. knavg_MainMenu.Pages.Add(tmpPage2);
  180. knavg_MainMenu.SelectedPage = tmpPage2;
  181. }
  182. }
  183. private void MainFormNew_FormClosing(object sender, FormClosingEventArgs e)
  184. {
  185. Application.Exit();
  186. }
  187. }
  188. }