ningshuxia
2023-02-24 8c0434431e2c77de997ffbf27e65fdcc7ab915e3
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
using DevExpress.XtraBars;
using DevExpress.XtraBars.Docking;
using DevExpress.XtraBars.Docking2010.Views;
using DevExpress.XtraEditors;
using IStation.DataProvider.temp;
using IStation.WinFormUI;
using IStation.WinFormUI.Project;
using IStation.WinFormUI.Scene;
using IStation.WinFrmUI.Scatl;
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
 
namespace IStation.Client
{
    /// <summary>
    /// 主界面
    /// </summary>
    public partial class MainForm : DevExpress.XtraBars.FluentDesignSystem.FluentDesignForm
    {
        #region  构造函数
        public MainForm()
        {
            InitializeComponent();
            this.IconOptions.Icon = WinFormUI.Properties.Resource.app;
        }
 
        //禁止标题扩展
        protected override bool ExtendNavigationControlToFormTitle
        {
            get { return false; }
        }
 
        //开启界面双缓冲  解决窗体切换闪屏问题
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x02000000;
                return cp;
            }
        }
 
        #endregion
         
 
        NotifyIcon _app = null;
        internal void InitialForm()
        {
            if (this.components == null)
                _app = new System.Windows.Forms.NotifyIcon();
            else
                _app = new System.Windows.Forms.NotifyIcon(this.components);
            _app.Text = "Scatl";
            _app.Visible = true;
            _app.Click += (object sender, EventArgs e) =>
            {
                this.Visible = true;
                this.WindowState = FormWindowState.Maximized;
                _app.Visible = false;
            };
 
            var project = new BLL.Project().QueryById(GlobalParas.ProjectId);
            if (project != null)
            {
                this.barStaticProjectCaption.Caption = project.Name;
            } 
        }
 
        #region Form
 
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                if (XtraMessageBox.Show("是否关闭程序?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
                {
                    e.Cancel = true;
                    return;
                }
                var bll = new BLL.Project();
                var project = bll.QueryById(GlobalParas.ProjectId);
                project.UpdateTime = DateTime.Now;
                bll.Update(project);
            }
        }
 
        #endregion
 
        #region TabbedView
 
        //选中
        private void tabbedView1_DocumentSelected(object sender, DocumentEventArgs e)
        {
            if (e.Document == null)
                return;
            var surfaceGuid = e.Document.Tag as SurfaceGuid;
            if (surfaceGuid == null)
                return; 
        }
 
        //激活
        private void tabbedView1_DocumentActivated(object sender, DevExpress.XtraBars.Docking2010.Views.DocumentEventArgs e)
        {
 
        }
 
        //关闭ing
        private void tabbedView1_DocumentClosing(object sender, DevExpress.XtraBars.Docking2010.Views.DocumentCancelEventArgs e)
        {
 
        }
 
        //关闭
        private void tabbedView1_DocumentClosed(object sender, DevExpress.XtraBars.Docking2010.Views.DocumentEventArgs e)
        {
 
        }
 
        #endregion
 
        #region Page
 
        //是否存在Page
        private bool IsExistPage(SurfaceGuid sguid, bool isActivateDoc)
        {
            if (sguid == null)
                return false;
            if (this.dockManager1.Panels != null && this.dockManager1.Panels.Count > 0)
            {
                foreach (DockPanel panel in this.dockManager1.Panels)
                {
                    if (panel.Tag != null)
                    {
                        if (panel.Tag is SurfaceGuid)
                        {
                            if ((panel.Tag as SurfaceGuid).ToString() == sguid.ToString())
                            {
                                if (isActivateDoc)
                                    panel.Show();
                                return true;
                            }
                        }
                    }
                }
            }
 
            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 SurfaceGuid)
                        {
                            if ((doc.Tag as SurfaceGuid).ToString() == sguid.ToString())
                            {
                                if (isActivateDoc)
                                    this.tabbedView1.Controller.Activate(doc);
                                return true;
                            }
                        }
                    }
                }
            }
 
            return false;
        }
 
        //更新数据
        private void RefreshPageData(SurfaceGuid sguid)
        {
            if (sguid == null)
                return;
            if (this.dockManager1.Panels != null && this.dockManager1.Panels.Count > 0)
            {
                var panel = this.dockManager1.Panels.ToList().Find(x => x.Tag != null && x.Tag is SurfaceGuid && (x.Tag as SurfaceGuid).ToString() == sguid.ToString());
                if (panel != null)
                {
                    if (panel.ControlContainer.Controls.Count > 0)
                    {
                        var page = panel.ControlContainer.Controls[0] as DocumentPage;
                        if (page != null)
                        {
                            page.RefreshDataSource();
                        }
                    }
                    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 SurfaceGuid && (x.Tag as SurfaceGuid).ToString() == sguid.ToString());
                if (doc != null)
                {
                    var page = doc.Control as DocumentPage;
                    if (page != null)
                    {
                        page.RefreshDataSource();
                    }
                    return;
                }
            }
        }
 
        //更新PageTitle
        private void UpdatePageTitle(SurfaceGuid sguid, PageTitle title)
        {
            if (sguid == null || title == null)
                return;
 
            if (this.dockManager1.Panels != null && this.dockManager1.Panels.Count > 0)
            {
                var panel = this.dockManager1.Panels.ToList().Find(x => x.Tag != null && x.Tag is SurfaceGuid && (x.Tag as SurfaceGuid).ToString() == sguid.ToString());
                if (panel != null)
                {
                    panel.Text = title.Caption;
                    panel.ImageOptions.Image = title.HeaderImage;
                    panel.ImageOptions.SvgImage = title.HeaderSvgImage;
                    panel.ImageOptions.SvgImageSize = title.SvgImageSize;
                    if (panel.ControlContainer.Controls.Count > 0)
                    {
                        var page = panel.ControlContainer.Controls[0] as DocumentPage;
                        if (page != null)
                        {
                            page.PageTitle = title;
                        }
                    }
                    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 SurfaceGuid && (x.Tag as SurfaceGuid).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;
                    var page = doc.Control as DocumentPage;
                    if (page != null)
                    {
                        page.PageTitle = title;
                    }
                    return;
                }
            }
        }
 
        //创建Page
        private bool CreatePage(DocumentPage page, SurfaceGuid sguid)
        {
            if (page == null || sguid == null)
                return false;
            page.SurfaceGuid = 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();
            switch (sguid.DockType)
            {
                case eDockType.Dock:
                    {
                        this.dockManager1.BeginUpdate();
                        DockPanel docPnl = null;
                        if (sguid.SubDockType == eSubDockType.Dock_Left)
                            docPnl = this.dockManager1.AddPanel(DockingStyle.Left);
                        else if (sguid.SubDockType == eSubDockType.Dock_Right)
                            docPnl = this.dockManager1.AddPanel(DockingStyle.Right);
 
                        docPnl.Footer = Directory.GetCurrentDirectory();
                        if (page.PageTitle != null)
                        {
                            docPnl.Text = page.PageTitle.Caption;
                            docPnl.ImageOptions.Image = page.PageTitle.HeaderImage;
                            docPnl.ImageOptions.SvgImage = page.PageTitle.HeaderSvgImage;
                            docPnl.ImageOptions.SvgImageSize = page.PageTitle.SvgImageSize;
                        }
                        docPnl.ControlContainer.Controls.Add(page);
                        docPnl.Tag = sguid;
                        this.dockManager1.EndUpdate();
                        docPnl.Show();
                    }
                    break;
                case eDockType.Tab:
                    {
                        this.tabbedView1.BeginUpdate();
                        var doc = this.tabbedView1.AddDocument(page);
                        doc.Footer = Directory.GetCurrentDirectory();
                        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;
                        }
                        doc.Tag = sguid;
                        this.tabbedView1.EndUpdate();
                        this.tabbedView1.Controller.Activate(doc);
                    }
                    break;
                default: break;
            }
            page.InitialDataSource();
            return true;
        }
 
        //关闭Page
        private void ClosePage(SurfaceGuid sguid)
        {
            switch (sguid.DockType)
            {
                case eDockType.Dock:
                    {
                        if (this.dockManager1.Panels != null && this.dockManager1.Panels.Count > 0)
                        {
                            var panel = this.dockManager1.Panels.ToList().Find(x => x.Tag != null && x.Tag is SurfaceGuid && (x.Tag as SurfaceGuid).ToString() == sguid.ToString());
                            if (panel != null)
                            {
                                if (panel.Visibility != DockVisibility.Hidden)
                                    panel.Close();//会触发正在关闭和关闭事件
                                                  //this.dockManager1.RemovePanel(panel);//不会触发正在关闭和关闭事件
                            }
                        }
                    }
                    break;
                case eDockType.Tab:
                    {
                        if (this.tabbedView1.Documents != null && this.tabbedView1.Documents.Count > 0)
                        {
                            var doc = this.tabbedView1.Documents.ToList().Find(x => x.Tag != null && x.Tag is SurfaceGuid && (x.Tag as SurfaceGuid).ToString() == sguid.ToString());
                            if (doc != null)
                            {
                                this.tabbedView1.Controller.Close(doc);//会触发正在关闭和关闭事件
                            }
                        }
                    }
                    break;
                default: break;
            }
        }
 
        //查找page
        private DocumentPage FindPage(SurfaceGuid 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);
                    var page = doc.Control as DocumentPage;
                    if (page != null)
                    {
                        return page;
                    }
                    return null;
                }
            }
            return null;
        }
 
        //重置所有页面
        private void ResetAllPages()
        {
            this.tabbedView1.Controller.CloseAll();
            /*  var project = new BLL.Project().GetById(GlobalParas.ProjectId);
              this.nb标题.Caption = $"Scada分析-{project.Name}";
              var sguid = new SurfaceGuid();
              sguid.DockType = eDockType.Tab;
              sguid.Modular = eModular.System;
              sguid.Function = "最近浏览";
              if (!IsExistPage(sguid, true))
              {
                  var page = new LatelyProjectOverviewPage(sguid);
                  CreatePage(page, sguid);
              }*/
        }
 
 
 
        #endregion
 
        private void accProjectItem_Click(object sender, EventArgs e)
        { 
            var scene = SceneTempCreate.GetScene(GlobalParas.ProjectId);
            var bol= GeneralMonitorDataImportHelper.Import(GlobalParas.ProjectId,scene.Id,scene.DataSourcesMappers);
            if (!bol)
            {
                MessageBox.Show("导入失败!");
            }
            else
            {
                MessageBox.Show("导入成功!");
            }
        }
 
        private void barBtnExportProject_ItemClick(object sender, ItemClickEventArgs e)
        {
            ProjectHelper.OtherSaveProject(GlobalParas.ProjectId);
        }
 
        private void accordionControlElement2_Click(object sender, EventArgs e)
        {
 
        }
    }
}