yangyin
2024-08-07 398f41e433b11af8eeedf31299a78c9be13c18c5
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
using DevExpress.XtraBars.Docking2010.Views;
using DevExpress.XtraBars.Navigation;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraEditors;
using HStation.WinFrmUI;
using HStation.WinFrmUI.Auth;
using HStation.WinFrmUI.Auth.Core._01_Role;
using HStation.WinFrmUI.Basic;
using HStation.WinFrmUI.Organize;
using HStation.WinFrmUI.Organize.Core._02_Employee;
using HStation.WinFrmUI.Organize.Core._05_ControlCenter;
using HStation.WinFrmUI.Organize.Core._06_MyCenter;
using HStation.WinFrmUI.Xhs.PumpProduct;
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
 
namespace HStation.Desktop
{
    public partial class GuideMain : RibbonForm
    {
        public GuideMain()
        {
            InitializeComponent();
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            //this.IconOptions.Icon = WinFrmUI.Properties.Resources.App;
            //this.nbMain.ImageOptions.Image = WinFrmUI.Properties.Resources.App.ToBitmap();
            _app = new System.Windows.Forms.NotifyIcon(this.components);
            _app.Text = this.Text;
            _app.Visible = true;
            //_app.Icon = WinFrmUI.Properties.Resources.App;
            //_app.Click += (object sender, EventArgs e) =>
            //{
            //    this.Visible = true;
            //    this.WindowState = FormWindowState.Maximized;
            //    _app.Visible = false;
            //};
 
            //var guid = new SurfaceGuid()
            //{
            //    Function = "地图总览",
            //    Modular = eModular.Model
            //};
            //if (!IsExistPage(guid, true))
            //{
            //    var overview = new MapMgr();
            //    overview.PageTitle.Caption = guid.Function;
            //    overview.SurfaceGuid = guid;
            //    CreatePage(overview, guid);
            //}
            this.FormClosed += (sender, e) =>
            {
                System.Diagnostics.Process.GetCurrentProcess().Kill();
            };
        }
 
        // 开启界面双缓冲 解决窗体切换闪屏问题
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x02000000;
                return cp;
            }
        }
 
        //icon
        private readonly NotifyIcon _app = null;
 
        #region TileNavPane
 
        private void tileNavPane_ElementClick(object sender, NavElementEventArgs e)
        {
            var tagObj = e.Element.Tag;
            if (tagObj == null || !(tagObj is string))
                return;
            var tag = tagObj.ToString();
 
            var hitInfo = this.tileNavPane.CalcHitInfo(MousePosition);
            var buttonInfo = hitInfo.ButtonInfo;
            if (buttonInfo == null)
                return;
            var width = buttonInfo.Location.X;
            var height = buttonInfo.Bounds.Y + buttonInfo.Bounds.Height;
            var point = new Point(width, height);
            switch (tag)
            {
                case "MapOverview":
                    {
                    }
                    break;
 
                case "SystemConfig":
                    {
                        popSystemConfig.MinWidth = buttonInfo.Bounds.Width;
                        popSystemConfig.ShowPopup(point);
                    }
                    break;
 
                case "SystemOrganize":
                    {
                        popSystemOrganize.MinWidth = buttonInfo.Bounds.Width;
                        popSystemOrganize.ShowPopup(point);
                    }
                    break;
 
                case "SystemAuthority":
                    {
                        popSystemAuthority.MinWidth = buttonInfo.Bounds.Width;
                        popSystemAuthority.ShowPopup(point);
                    }
                    break;
 
                case "Minimize":
                    {
                        this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
                    }
                    break;
 
                case "Close":
                    {
                        this.Close();
                    }
                    break;
 
                default:
                    {
                        XtraMessageBox.Show($"未知功能:{tag}");
                    }
                    break;
            }
        }
 
        /// <summary>
        /// 设置NvaButton按钮背景
        /// </summary>
        /// <param name="tag"></param>
        public void SetNvaButtonAppearance(string tag)
        {
            foreach (var btn in this.tileNavPane.Buttons)
            {
                if (btn is DevExpress.XtraBars.Navigation.NavButton nb)
                {
                    if (nb.Tag != null && nb.Tag.ToString() == tag)
                    {
                        nb.Appearance.BackColor = Color.SteelBlue;
                        nb.Appearance.ForeColor = Color.White;
                    }
                    else
                    {
                        nb.Appearance.BackColor = Color.White;
                        nb.Appearance.ForeColor = Color.Black;
                    }
                }
            }
        }
 
        #endregion TileNavPane
 
        //用水器具
        private void barBtnWaterUtensil_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
        }
 
        /// <summary>
        /// 项目管理
        /// </summary>
        private void barBtnProject_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var guid = new PageGuid()
            {
                Function = "项目管理",
                Modular = ""
            };
            if (!IsExistPage(guid, true))
            {
                /*     var page = new XhsProjectMainPanel();
                     page.PageTitle.Caption = guid.Function;
                     page.PageGuid = guid;
                     CreatePage(page, guid);*/
            }
        }
 
        /// <summary>
        /// 泵管理
        /// </summary>
        private void barBtnPumpManage_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var guid = new PageGuid()
            {
                Function = "泵管理",
                Modular = ""
            };
            if (!IsExistPage(guid, true))
            {
                var page = new PumpProductMainPanel();
                page.PageTitle.Caption = guid.Function;
                page.PageGuid = guid;
                CreatePage(page, guid);
            }
        }
 
        /// <summary>
        /// 类型管理
        /// </summary>
        private void barButtonTypeManage_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var guid = new PageGuid()
            {
                Function = "类型管理",
                Modular = ""
            };
            if (!IsExistPage(guid, true))
            {
                var page = new SysTypeManageMainPanel();
                page.PageTitle.Caption = guid.Function;
                page.PageGuid = guid;
                CreatePage(page, guid);
            }
        }
 
        /// <summary>
        /// 分类管理
        /// </summary>
        private void BtnCatlogManage_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var guid = new PageGuid()
            {
                Function = "分类管理",
                Modular = ""
            };
            if (!IsExistPage(guid, true))
            {
                var page = new SysCatalogManageMainPanel();
                page.PageTitle.Caption = guid.Function;
                page.PageGuid = guid;
                CreatePage(page, guid);
            }
        }
 
        /// <summary>
        /// 属性管理
        /// </summary>
        private void BtnPropManage_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var guid = new PageGuid()
            {
                Function = "属性管理",
                Modular = ""
            };
            if (!IsExistPage(guid, true))
            {
                var page = new SysPropManageMainPanel();
                page.PageTitle.Caption = guid.Function;
                page.PageGuid = guid;
                CreatePage(page, guid);
            }
        }
 
        //角色管理
        private void BarBtnRoleManage_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var guid = new PageGuid()
            {
                Function = "角色管理",
                Modular = ""
            };
            if (!IsExistPage(guid, true))
            {
                var page = new RoleMainMgrPanel();
                page.PageTitle.Caption = guid.Function;
                page.PageGuid = guid;
                CreatePage(page, guid);
            }
        }
 
        /// <summary>
        /// 分区管理
        /// </summary>
        private void barBtnPart_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
        }
 
        /// <summary>
        /// 系统类型
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barBtnSystemType_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
        }
 
        /// <summary>
        /// 设施管理
        /// </summary>
        private void barBtnFacilities_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
        }
 
        /// <summary>
        /// 建筑物
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barBtnBuilding_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
        }
 
        /// <summary>
        /// 建筑类型
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barBtnBuildingType_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
        }
 
        /// <summary>
        /// 厂家管理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barBtnSupplier_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
        }
 
        /// <summary>
        /// 用户管理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barBtnUser_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var guid = new PageGuid()
            {
                Function = "用户管理",
                Modular = ""
            };
            if (!IsExistPage(guid, true))
            {
                var page = new EmployeeMgrMainPanel();
                page.PageTitle.Caption = guid.Function;
                page.PageGuid = guid;
                CreatePage(page, guid);
            }
        }
 
        /// <summary>
        /// 权限管理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barBtnAuthority_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
        }
 
        /// <summary>
        /// 日志管理
        /// </summary>
        private void barBtnSystemLog_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
        }
 
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barBtnWaterEquivalent_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
        }
 
        //是否存在Page
        private bool IsExistPage(PageGuid sguid, bool isActivateDoc)
        {
            if (sguid == null)
                return false;
 
            if (this.tabbedView1.Documents != null && this.tabbedView1.Documents.Count > 0)
            {
                foreach (BaseDocument doc in this.tabbedView1.Documents)
                {
                    if (doc.Tag != null)
                    {
                        if (doc.Tag is PageGuid)
                        {
                            if ((doc.Tag as PageGuid).ToString() == sguid.ToString())
                            {
                                if (isActivateDoc)
                                    this.tabbedView1.Controller.Activate(doc);
                                return true;
                            }
                        }
                    }
                }
            }
 
            return false;
        }
 
        //更新数据
        private void RefreshPageData(PageGuid sguid)
        {
            if (sguid == null)
                return;
 
            if (this.tabbedView1.Documents != null && this.tabbedView1.Documents.Count > 0)
            {
                var doc = this.tabbedView1.Documents.ToList().Find(x => x.Tag != null && x.Tag is PageGuid && (x.Tag as PageGuid).ToString() == sguid.ToString());
                if (doc != null)
                {
                    if (doc.Control is DocumentPage page)
                    {
                        page.RefreshData();
                    }
                    return;
                }
            }
        }
 
        //更新PageTitle
        private void UpdatePageTitle(PageGuid sguid, PageTitle title)
        {
            if (sguid == null || title == null)
                return;
 
            if (this.tabbedView1.Documents != null && this.tabbedView1.Documents.Count > 0)
            {
                var doc = this.tabbedView1.Documents.ToList().Find(x => x.Tag != null && x.Tag is PageGuid && (x.Tag as PageGuid).ToString() == sguid.ToString());
                if (doc != null)
                {
                    doc.Caption = title.Caption;
                    doc.ImageOptions.Image = title.HeaderImage;
                    doc.ImageOptions.SvgImage = title.HeaderSvgImage;
                    doc.ImageOptions.SvgImageSize = title.SvgImageSize;
                    if (doc.Control is DocumentPage page)
                    {
                        page.PageTitle = title;
                    }
                    return;
                }
            }
        }
 
        //创建Page
        private bool CreatePage(DocumentPage page, PageGuid sguid)
        {
            if (page == null || sguid == null)
                return false;
            page.PageGuid = sguid;
            page.Dock = DockStyle.Fill;
            page.IsExistPageEvent += IsExistPage;
            page.CreatePageEvent += CreatePage;
            page.RefreshPageDataEvent += RefreshPageData;
            page.UpdatePageTitleEvent += UpdatePageTitle;
            page.ClosePageEvent += ClosePage;
            page.ResetAllPagesEvent += ResetAllPages;
            page.RegistEvents();
 
            this.tabbedView1.BeginUpdate();
            var doc = this.tabbedView1.AddDocument(page);
            doc.Footer = Directory.GetCurrentDirectory();
            doc.Properties.AllowClose = page.AllowClose() ? DevExpress.Utils.DefaultBoolean.True : DevExpress.Utils.DefaultBoolean.False;
            if (page.PageTitle != null)
            {
                doc.Caption = page.PageTitle.Caption;
                doc.ImageOptions.Image = page.PageTitle.HeaderImage;
                doc.ImageOptions.SvgImage = page.PageTitle.HeaderSvgImage;
                doc.ImageOptions.SvgImageSize = page.PageTitle.SvgImageSize;
            }
            else
            {
                doc.Caption = page.PageGuid?.Function;
            }
            doc.Tag = sguid;
            this.tabbedView1.EndUpdate();
            this.tabbedView1.Controller.Activate(doc);
            this.tabbedView1.ActivateDocument(doc.Control);
 
            page.InitialDataSource();
            return true;
        }
 
        //关闭Page
        private void ClosePage(PageGuid sguid)
        {
            if (this.tabbedView1.Documents != null && this.tabbedView1.Documents.Count > 0)
            {
                var doc = this.tabbedView1.Documents.ToList().Find(x => x.Tag != null && x.Tag is PageGuid && (x.Tag as PageGuid).ToString() == sguid.ToString());
                if (doc != null)
                {
                    var page = doc.Control as DocumentPage;
                    this.tabbedView1.Controller.Close(doc);//会触发正在关闭和关闭事件
                }
            }
        }
 
        //查找page
        private DocumentPage FindPage(PageGuid sguid, bool isActiveDoc)
        {
            if (sguid == null)
                return default;
            var sguid_msg = sguid.ToString();
 
            if (this.tabbedView1.Documents != null && this.tabbedView1.Documents.Count > 0)
            {
                var doc = this.tabbedView1.Documents.ToList().Find(x => x.Tag != null && x.Tag.ToString() == sguid_msg);
                if (doc != null)
                {
                    if (isActiveDoc)
                        this.tabbedView1.Controller.Activate(doc);
                    if (doc.Control is DocumentPage page)
                    {
                        return page;
                    }
                    return null;
                }
            }
            return null;
        }
 
        //重置所有页面
        private void ResetAllPages()
        {
            this.tabbedView1.Controller.CloseAll();
        }
 
        private void GuideMain_Load(object sender, EventArgs e)
        {
            var guid = new PageGuid()
            {
                Function = "项目总览",
                Modular = ""
            };
            if (!IsExistPage(guid, true))
            {
                var page = new HomeXhsProjectPage();
                page.PageTitle.Caption = guid.Function;
                page.PageGuid = guid;
                CreatePage(page, guid);
            }
        }
    }
}