lg
2024-09-22 c115ac388af5a6928716f0146a75a2a42fb27d8e
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
using DevExpress.XtraBars.Navigation;
using DevExpress.XtraTab;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using Gs.DevApp.ToolBox;
using Newtonsoft.Json;
using Gs.DevApp.Entity;
using Newtonsoft.Json.Linq;
 
namespace Gs.DevApp.DevFrm
{
    public partial class FrmMain : DevExpress.XtraBars.FluentDesignSystem.FluentDesignForm
    {
        private static Dictionary<string, XtraTabPage> TabPageDic = new Dictionary<string, XtraTabPage>();
        public FrmMain()
        {
            InitializeComponent();
            this.Text = System.Configuration.ConfigurationSettings.AppSettings.Get("ProductName").ToString();
            tab.CloseButtonClick += Tab_CloseButtonClick;
            tooLoading.Click += TooLoading_Click;
            barPwd.ItemClick += BarPwd_ItemClick;
            barExit.ItemClick += BarExit_ItemClick;
            this.FormClosing += FrmMain_FormClosing;
            getTree();
        }
 
        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MsgHelper.AskQuestion("确定要退出系统吗?"))
            {
                int i = _userOut();
                if (i > 0)
                {
                    this.FormClosing -= new FormClosingEventHandler(this.FrmMain_FormClosing);
                    Application.Exit();
                }
                else
                    e.Cancel = true;//取消。返回窗体
            }
            else
                e.Cancel = true;//取消。返回窗体
        }
 
        /// <summary>
        /// 退出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BarExit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (MsgHelper.AskQuestion("确定要退出系统吗?"))
            {
                int i = _userOut();
                if (i > 0)
                {
                    this.FormClosing -= new FormClosingEventHandler(this.FrmMain_FormClosing);
                    Application.Exit();
                }
            }
        }
 
        /// <summary>
        /// 设置用户密码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BarPwd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            User.UserSetPwd frm = new User.UserSetPwd(LoginInfoModel.CurrentUser.LoginUserGuid);
            frm.ShowDialog();
        }
 
        /// <summary>
        /// 重新加载系统
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TooLoading_Click(object sender, EventArgs e)
        {
            int i = 100;
            Gs.DevApp.UserControl.ShowDialogForm sdf = new Gs.DevApp.UserControl.ShowDialogForm("提示", "", "请耐心等候,正在操作中!");
            for (int j = 0; j < i; j++)
            {
                sdf.SetCaption("执行进度(" + (j) + "/" + i.ToString() + ")");
            }
            sdf.Close();
            getTree();
        }
        private void getTree()
        {
            toolTime.Text = "登录时间" + LoginInfoModel.CurrentUser.LoginTime;
            var _obj = new
            {
                userGuid = LoginInfoModel.CurrentUser.LoginUserGuid,
                orgGuid = LoginInfoModel.CurrentUser.LoginOrgGuid,
            };
            try
            {
                string strJson = UtilityHelper.HttpPost("", "User/GetUserLoginInfo", JsonConvert.SerializeObject(_obj));
                JObject _job = JObject.Parse(strJson);
                string rtnCode = _job["rtnCode"].ToString();
                if (int.Parse(rtnCode) > 0)
                {
                    this.acrd.Clear();
                    barMsg.Caption = _job["rtnData"]["loginMsg"].ToString();
                    JArray array = new JArray();
                    var d = _job["rtnData"]["list"];
                    foreach (var a in d)
                    {
                        array.Add(a);
                    }
                    System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmMain));
                    DataTable dt = JsonConvert.DeserializeObject<DataTable>(array.ToString());
                    DataRow[] drGrp = dt.Select("upGuid is null");
                    int gdx = 0, idx = 0;
                    foreach (DataRow _dy in drGrp)
                    {
                        AccordionControlElement _grp = this.acrd.AddGroup();
                        _grp.ImageOptions.Image = UtilityHelper.GetImgFromResource(_dy["icon"].ToString(), 1);
                        _grp.Name = _dy["guid"].ToString();
                        _grp.Style = DevExpress.XtraBars.Navigation.ElementStyle.Group;
                        _grp.Text = _dy["name"].ToString();
                        _grp.Tag = _dy["formPath"].ToString();//存路径,类名
                        _grp.Click += _grp_Click;
                        if (gdx == 0)
                            _grp.Expanded = true;
                        DataRow[] drItem = dt.Select("upGuid='" + _dy["guid"].ToString() + "'");
                        foreach (DataRow _dy2 in drItem)
                        {
                            AccordionControlElement _itm = this.acrd.AddItem();
                            _itm.ImageOptions.Image = UtilityHelper.GetImgFromResource(_dy2["icon"].ToString(), 2);
                            _itm.Name = _dy2["guid"].ToString();
                            _itm.Style = DevExpress.XtraBars.Navigation.ElementStyle.Item;
                            _itm.Text = _dy2["name"].ToString();
                            _itm.Appearance.Normal.Font = new System.Drawing.Font("Tahoma", 10F);
                            _itm.Tag = _dy2["formPath"].ToString();//存路径,类名
                            _itm.Click += _grp_Click;
                            _grp.Elements.Add(_itm);
                            if (idx == 0 && tab.TabPages.Count <= 0)
                            {
                                string tabPageName = _itm.Name + "_page";
                                string tabText = _itm.Text;//当前选项卡页Text标题
                                string newFormName = _itm.Tag.ToString();//存路径,类名
                                Image imgIcon = _itm.Image;
                                AddTabpage(tab, tabPageName, tabText, newFormName, imgIcon);
                            }
                            idx++;
                        };
                        gdx++;
                    }
                }
                else
                {
                    ToolBox.MsgHelper.ShowError("提示:初始化失败,请联系管理员!");
                }
            }
            catch (Exception ex)
            {
                ToolBox.MsgHelper.ShowError("提示:" + ex.Message);
            }
        }
        /// <summary>
        /// 左侧菜单点击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        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 = _acd.Tag.ToString();
            Image imgIcon = _acd.Image;
            AddTabpage(tab, tabPageName, tabText, newFormName, imgIcon);
        }
 
        /// <summary>
        /// 关闭选项卡
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Tab_CloseButtonClick(object sender, EventArgs e)
        {
            RemoveTabPage(tab, e);
        }
        /// <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, Image imgIcon)
        {
            if (IsTabpageExsit(tabControl, tabPageName))
            {
                return;
            }
            XtraTabPage newPage = new XtraTabPage();
            newPage.Name = tabPageName;
            newPage.Text = tabText;
            newPage.Tooltip = newPage.Name;
            newPage.Appearance.Header.Font = (tab.Appearance.Font);
            newPage.ImageOptions.Image = imgIcon;
            Form fm = AddNewForm(newFormName);
            if (fm != null)
            {
                newPage.Controls.Add(fm);
                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)
        {
            if (TabPageDic.Count <= 1)
            {
                ToolBox.MsgHelper.Warning("请至少保留一个功能!");
                return;
            }
            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)
        {
            try
            {
                Form newForm = (Form)Assembly.GetExecutingAssembly().CreateInstance(formName);
                if (newForm == null)
                {
                    Gs.DevApp.ToolBox.MsgHelper.ShowError("请检查是否开通了该模块!");
                    return null;
                }
                newForm.FormBorderStyle = FormBorderStyle.None;
                newForm.TopLevel = false;
                newForm.ControlBox = false;
                newForm.Dock = DockStyle.Fill;
                newForm.Visible = true;
                return newForm;
            }
            catch (Exception)
            {
                Gs.DevApp.ToolBox.MsgHelper.ShowError("请检查是否开通了该模块!");
            }
            return null;
        }
 
        private int _userOut()
        {
            var _obj = new
            {
                userGuid = LoginInfoModel.CurrentUser.LoginUserGuid,
            };
            try
            {
                string strJson = UtilityHelper.HttpPost("", "User/UserOut", JsonConvert.SerializeObject(_obj));
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
                if (_rtn.rtnCode > 0)
                    return _rtn.rtnCode;
                ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnData.outMsg);
                return _rtn.rtnCode;
            }
            catch (Exception ex)
            {
                this.DialogResult = DialogResult.Cancel;
                ToolBox.MsgHelper.Warning("提示:" + ex.Message);
                return -1;
            }
        }
    }
}