winform+dev的前后台分离标准项目
lg
2024-08-27 978d57ea2e89b07508f01f800ee97b36f19adec2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using DevExpress.XtraBars;
using DevExpress.XtraBars.Navigation;
using DevExpress.XtraTab;
using GsDxApp.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Text;
using System.Windows.Forms;
using Gs.DevApp.ToolBox;
 
namespace Gs.DevApp.DevFrm
{
    public partial class FrmMain : DevExpress.XtraBars.FluentDesignSystem.FluentDesignForm
    {
        private static Dictionary<string, XtraTabPage> TabPageDic = new Dictionary<string, XtraTabPage>();
        //private StatusStrip statusStrip;
        //private ToolStripStatusLabel statusLabel;
        public FrmMain()
        {
            InitializeComponent();
            getInit();
        }
 
        private void getInit()
        {
            string filePath = @"D:\GsMes\GsDXApp\GsDxApp\bin\Debug\menu.txt";
            string _strJson = File.ReadAllText(filePath);
            var _obj = new
            {
                rtnCode = 1,
                rtnData = new { list = new[] { new { guid = "", name = "", pah= "", ico = "", list = new[] { new { guid = "", name = "", pah= "", ico = "" } } } } },
                rtnMsg = ""
            };
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmMain));
            _obj = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(_strJson, _obj);
            foreach (dynamic _dy in _obj.rtnData.list)
            {
                AccordionControlElement _grp = this.acrd.AddGroup();
                _grp.ImageOptions.Image = Utility.GetImgFromResource(_dy.ico);
                _grp.Name = Guid.NewGuid().ToString();
                _grp.Style = DevExpress.XtraBars.Navigation.ElementStyle.Group;
                _grp.Text = _dy.name;
                _grp.Click += _grp_Click;
                foreach (dynamic _dy2 in _dy.list)
                {
                    AccordionControlElement _itm = this.acrd.AddItem();
                    _itm.Name = Guid.NewGuid().ToString();
                    _itm.ImageOptions.Image =Utility.GetImgFromResource(_dy2.ico);
                    _itm.Style = DevExpress.XtraBars.Navigation.ElementStyle.Item;
                    _itm.Text = _dy2.name;
                    _itm.Appearance.Normal.Font = new System.Drawing.Font("Tahoma", 10F);
                    _itm.Tag = _dy2.pah;
                    _itm.Click += _grp_Click;
                    _grp.Elements.Add(_itm);
                };
            }
        }
 
        private void _grp_Click(object sender, EventArgs e)
        {
            AccordionControlElement _acd = (AccordionControlElement)sender;
            if (_acd.Elements.Count > 0) return;
            string tabPageName = _acd.Name + "_page";
            string tabText = _acd.Text;
            //string newFormName = "GsDxApp.test.ToolbarForm1";
            string newFormName = _acd.Tag.ToString();
            AddTabpage(tab, tabPageName, tabText, newFormName);
        }
 
        /// <summary>
        /// 新增选项卡页
        /// </summary>
        /// <param name="tabControl">选项卡控件</param>
        /// <param name="tabPageName">当期选项卡页name名称</param>
        /// <param name="tabText">当前选项卡页Text标题</param>
        /// <param name="newFormName">当前选项卡中的新窗体</param>
        public void AddTabpage(XtraTabControl tabControl, string tabPageName, string tabText, string newFormName)
        {
            if (IsTabpageExsit(tabControl, tabPageName))
            {
                return;
            }
            XtraTabPage newPage = new XtraTabPage();
            newPage.Name = tabPageName;
            newPage.Text = tabText;
            newPage.Tooltip = (tabText + ":" + tabPageName);
            newPage.Controls.Add(AddNewForm(newFormName));
            tabControl.TabPages.Add(newPage);
            TabPageDic.Add(tabPageName, newPage);
            tabControl.SelectedTabPage = newPage;
        }
 
        /// <summary>
        /// 移除选项卡页
        /// </summary>
        /// <param name="tabControl"></param>
        /// <param name="tabPageName"></param>
        /// <param name="e"></param>
        public void RemoveTabPage(XtraTabControl tabControl, EventArgs e)
        {
            DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs args = (DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs)e;
            string name = args.Page.Tooltip;
            foreach (XtraTabPage item in tabControl.TabPages)
            {
                if (item.Name == name)
                {
                    tabControl.TabPages.Remove(item);
                    item.Dispose();
                    TabPageDic.Remove(name);
                    return;
                }
            }
        }
 
        /// <summary>
        /// 判断选项卡是否已经存在
        /// </summary>
        /// <param name="tabControl">选项卡控件</param>
        /// <param name="tabPageName">选项卡名称</param>
        /// <returns></returns>
        private bool IsTabpageExsit(XtraTabControl tabControl, string tabPageName)
        {
            foreach (var item in TabPageDic)
            {
                if (item.Key == tabPageName)
                {
                    tabControl.SelectedTabPage = item.Value;
                    return true;
                }
            }
            return false;
        }
 
        /// <summary>
        /// 在选项卡中生成窗体
        /// </summary>
        /// <param name="form">窗体名称</param>
        private Form AddNewForm(string formName)
        {
            Form newForm = (Form)Assembly.GetExecutingAssembly().CreateInstance(formName);
            newForm.FormBorderStyle = FormBorderStyle.None;
            newForm.TopLevel = false;
            //newForm.Parent = ((XtraTabControl)sender).SelectedTabPage;
            newForm.ControlBox = false;
            newForm.Dock = DockStyle.Fill;
            newForm.Visible = true;
            return newForm;
        }
 
       
    }
}