jt
2021-06-10 5d0d028456874576560552f5a5c4e8b801786f11
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing.Design;
using System.IO;
using GrapeCity.ActiveReports.Design;
using GrapeCity.ActiveReports.Design.Resources;
using System.ComponentModel.Design;
using GrapeCity.ActiveReports.Design.Toolbox;
using GrapeCity.ActiveReports.PageReportModel;
namespace HH.WMS.Client
{
    public partial class EndUserDesigner : DevComponents.DotNetBar.Metro.MetroForm
    {
        ToolStripDropDownItem _fileMenu;
        private ToolStripMenuItem _exportMenuItem;
        string _reportName;
        IMessageFilter _filter;
        ToolStripMenuItem _toogleFilterMenu;
        public EndUserDesigner()
        {
            InitializeComponent();
            //Set the ToolBox, ReportExplorer and PropertyGrid in the Designer.
            reportDesigner.Toolbox = reportToolbox;//Attaches the toolbox to the report designer
            reportExplorer.ReportDesigner = reportDesigner;//Attaches the report explorer to the report designer
            reportDesigner.LayoutChanged += new LayoutChangedEventHandler(OnLayoutChanged);
            reportDesigner.ReportChanged += OnReportChanged;
            layerList.ReportDesigner = reportDesigner;
            reportDesigner.PropertyGrid = reportPropertyGrid;//Attaches the Property Grid to the report designer
            //Populate the menu.
            groupEditor.ReportDesigner = reportDesigner;
            reportsLibrary.ReportDesigner = reportDesigner;
            ToolStrip toolstrip = reportDesigner.CreateToolStrips(new DesignerToolStrips[]
                {
                    DesignerToolStrips.Menu
                })[0];
            _fileMenu = (ToolStripDropDownItem)toolstrip.Items[0];
            CreateFileMenu(_fileMenu);
            _toogleFilterMenu = new ToolStripMenuItem(Properties.Resources.DisableShortcutsText, null, new EventHandler(ToggleMessageFilter));
            ((ToolStripDropDownItem)toolstrip.Items[2]).DropDownItems.Add(new ToolStripSeparator());
            ((ToolStripDropDownItem)toolstrip.Items[2]).DropDownItems.Add(_toogleFilterMenu);
            AppendToolStrips(0, new ToolStrip[]
                {
                    toolstrip
                });
            AppendToolStrips(1, reportDesigner.CreateToolStrips(new DesignerToolStrips[]
                {
                    DesignerToolStrips.Edit, 
                    DesignerToolStrips.Undo, 
                    DesignerToolStrips.Zoom
                }));
            ToolStrip item = CreateReportToolbar();
            AppendToolStrips(1, new ToolStrip[]
                {
                    item
                });
            AppendToolStrips(2, reportDesigner.CreateToolStrips(new DesignerToolStrips[]
                {
                    DesignerToolStrips.Format, 
                    DesignerToolStrips.Layout
                }));
            LoadTools(reportToolbox, reportDesigner.ReportType);
            RefreshExportEnabled();
            CreateReportExplorer();
            splitContainerMiddle.Panel2Collapsed = reportDesigner.ReportType == DesignerReportType.Section;
            FormClosing += EndUserDesigner_FormClosing;
        }
        private void EndUserDesigner_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = !ConfirmSaveChanges();
        }
        private void OnReportChanged(object sender, EventArgs e)
        {
            SetTitle();
        }
        private void SetTitle()
        {
            Text = string.Format("{0}{1} - {2}", string.IsNullOrEmpty(_reportName)
                                    ? GetDefaultReportName(reportDesigner.ReportType)
                                    : Path.GetFileName(_reportName),
                                 reportDesigner.IsDirty ? Properties.Resources.DirtySign : string.Empty,
                                 Properties.Resources.Title);
        }
        private string GetDefaultReportName(DesignerReportType reportType)
        {
            switch (reportType)
            {
                case DesignerReportType.Section:
                    return Properties.Resources.DefaultReportNameRpx;
                default:
                    return Properties.Resources.DefaultReportNameRdlx;
            }
        }
        private void OnLayoutChanged(object sender, LayoutChangedArgs e)
        {
            if (e.Type == LayoutChangeType.ReportLoad || e.Type == LayoutChangeType.ReportClear)
            {
                reportToolbox.Reorder(reportDesigner);
                reportToolbox.EnsureCategories();
                reportToolbox.Refresh();
                RefreshExportEnabled();
                CreateReportExplorer();
                splitContainerMiddle.Panel2Collapsed = reportDesigner.ReportType == DesignerReportType.Section;
            }
            if (e.Type == LayoutChangeType.ReportClear)
            {
                _reportName = null;
            }
            if (e.Type == LayoutChangeType.ReportLoad)
            {
                if (!string.IsNullOrEmpty(_reportName))
                {
                    //if (GetIsMaster())
                    //{
                    //    _reportName = null;
                    //}
                }
            }
            SetTitle();
        }
        private void RefreshExportEnabled()
        {
            reportDesigner.ActiveTabChanged -= OnEnableExport;
            reportDesigner.ActiveTabChanged += OnEnableExport;
            OnEnableExport(this, EventArgs.Empty);
        }
        private void OnEnableExport(object sender, EventArgs eventArgs)
        {
            if (_exportMenuItem != null)
                _exportMenuItem.Enabled = reportDesigner.ActiveTab == DesignerTab.Preview;
          
        }
        private static void LoadTools(IToolboxService toolbox,  DesignerReportType reportType)
        {
            if (reportType == DesignerReportType.Section)
            {
                //Add Data Providers.
                foreach (Type type in new Type[]
                {
                    typeof (System.Data.DataSet),
                    typeof (System.Data.DataView),
                    typeof (System.Data.OleDb.OleDbConnection),
                    typeof (System.Data.OleDb.OleDbDataAdapter),
                    typeof (System.Data.Odbc.OdbcConnection),
                    typeof (System.Data.Odbc.OdbcDataAdapter),
                    typeof (System.Data.SqlClient.SqlConnection),
                    typeof (System.Data.SqlClient.SqlDataAdapter)
                })
                {
                    toolbox.AddToolboxItem(new ToolboxItem(type), Properties.Resources.ToolBoxData);
                }
            }
        }
        //Adding DropDownItems to the ToolStripDropDownItem.
        private void CreateFileMenu(ToolStripDropDownItem fileMenu)
        {
            fileMenu.DropDownItems.Clear();
            //fileMenu.DropDownItems.Add(new ToolStripMenuItem(Properties.Resources.NewText, Properties.Resources.CmdNewReport, new EventHandler(OnNew), (Keys.Control | Keys.N)));
            //fileMenu.DropDownItems.Add(new ToolStripMenuItem(Properties.Resources.OpenText, Properties.Resources.CmdOpen, new EventHandler(OnOpen), (Keys.Control | Keys.O)));
            
            fileMenu.DropDownItems.Add(new ToolStripMenuItem(Properties.Resources.LoadFromServer, Properties.Resources.CmdOpenFromServer, new EventHandler(OnLoadFromServer)));
            
            fileMenu.DropDownItems.Add(new ToolStripMenuItem(Properties.Resources.SaveText, Properties.Resources.CmdSave, new EventHandler(OnSave), (Keys.Control | Keys.S)));
            fileMenu.DropDownItems.Add(new ToolStripMenuItem(Properties.Resources.SaveAsText, Properties.Resources.CmdSaveAs, new EventHandler(OnSaveAs)));
            
            fileMenu.DropDownItems.Add(new ToolStripMenuItem(Properties.Resources.SaveToServer, Properties.Resources.CmdSaveToServer, new EventHandler(OnSaveToServer)));
            
            _exportMenuItem = new ToolStripMenuItem(Properties.Resources.ExportText, Properties.Resources.export, new EventHandler(OnExport), (Keys.Control | Keys.E));
            _exportMenuItem.Enabled = false;
            fileMenu.DropDownItems.Add(_exportMenuItem);
            fileMenu.DropDownItems.Add(new ToolStripSeparator());
            fileMenu.DropDownItems.Add(new ToolStripMenuItem(Properties.Resources.ExitText, null, new EventHandler(OnExit)));
        }
        private ToolStrip CreateReportToolbar()
        {
            return new ToolStrip(new ToolStripButton[]
            { 
                CreateToolStripButton(Properties.Resources.NewText,Properties.Resources.CmdNewReport,new EventHandler(OnNew),Properties.Resources.NewText),
                CreateToolStripButton(Properties.Resources.OpenText,Properties.Resources.CmdOpen,new EventHandler(OnOpen),Properties.Resources.OpenText),
                CreateToolStripButton(Properties.Resources.SaveText,Properties.Resources.CmdSave,new EventHandler(OnSave),Properties.Resources.SaveText) 
            });
        }
        private bool PerformSave()
        {
            if (string.IsNullOrEmpty(_reportName) || string.IsNullOrEmpty(Path.GetDirectoryName(_reportName)) || !File.Exists(_reportName))
            {
                return PerformSaveAs();
            }
            reportDesigner.SaveReport(new FileInfo(_reportName));
            return true;
        }
        private bool PerformSaveAs()
        {
            using (SaveFileDialog dlg = new SaveFileDialog())
            {
                dlg.Filter = GetSaveFilter(reportDesigner.ReportType, GetIsMaster());
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    _reportName = dlg.FileName;
                    reportDesigner.SaveReport(new FileInfo(dlg.FileName));
                    return true;
                }
            }
            return false;
        }
        private bool GetIsMaster()
        {
            bool isMaster = false;
            if (reportDesigner.ReportType == DesignerReportType.Rdl)
            {
                var report = (Component)reportDesigner.Report;
                var site = report == null ? null : report.Site;
                if (site != null)
                {
                    var host = site.GetService(typeof(IDesignerHost)) as IDesignerHost;
                    if (host != null)
                    {
                        var mcs = host.GetService(typeof(IMasterContentService)) as IMasterContentService;
                        isMaster = mcs != null && mcs.IsMaster;
                    }
                }
            }
            return isMaster;
        }
        private string GetSaveFilter(DesignerReportType type, bool isMaster)
        {
            switch (type)
            {
                case DesignerReportType.Section:
                    return Properties.Resources.SectionReportFilter;
                case DesignerReportType.Page:
                    return Properties.Resources.PageReportFilter;
                case DesignerReportType.Rdl:
                    return isMaster ? Properties.Resources.RDLReportFilterMaster : Properties.Resources.RDLReportFilter;
                default:
                    return Properties.Resources.SectionReportFilter;
            }
        }
        //Click "New" to open a new report.
        private void OnNew(object sender, EventArgs e)
        {
            if (ConfirmSaveChanges())
            {
                reportDesigner.ExecuteAction(DesignerAction.NewReport);
                EnableTabs();
            }
        }
        //Click "Open" to open an existing report.
        private void OnOpen(object sender, EventArgs e)
        {
            if (!ConfirmSaveChanges())
            {
                return;
            }
            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.Filter = Properties.Resources.OpenFileFilter;
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    _reportName = dlg.FileName;
                    reportDesigner.LoadReport(new FileInfo(dlg.FileName));
                    EnableTabs();
                }
            }
        }
        private void OnExport(object sender, EventArgs e)
        {
            ExportForm exportForm = new ExportForm(reportDesigner.ReportType, reportDesigner.Report, reportDesigner.ReportViewer);
            exportForm.ShowDialog();
        }
        //Click "Save" to save a report.
        private void OnSave(object sender, EventArgs e)
        {
            if (PerformSave())
                SetTitle();
        }
        //Click "Save as" to save a report with a name.
        private void OnSaveAs(object sender, EventArgs e)
        {
            if (PerformSaveAs())
                SetTitle();
        }
        private void OnExit(object sender, EventArgs e)
        {
            Close();
        }
        //Checking whether modifications have been made to the report loaded to the designer.
        private bool ConfirmSaveChanges()
        {
            try
            {
                if (reportDesigner.IsDirty)
                {
                    DialogResult dialogresult = MessageBox.Show(Properties.Resources.ReportDirtyMessage, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                    if (dialogresult == DialogResult.Cancel)
                    {
                        return false;
                    }
                    if (dialogresult == DialogResult.Yes)
                    {
                        return PerformSave();
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        private void AppendToolStrips(int row, IList<ToolStrip> toolStrips)
        {
            ToolStripPanel topToolStripPanel = toolStripContainer.TopToolStripPanel;
            int num = toolStrips.Count;
            while (--num >= 0)
            {
                topToolStripPanel.Join(toolStrips[num], row);
            }
        }
        private static ToolStripButton CreateToolStripButton(string text, System.Drawing.Image image, EventHandler handler, string toolTip)
        {
            return new ToolStripButton(text, image, handler)
            {
                DisplayStyle = ToolStripItemDisplayStyle.Image,
                ToolTipText = toolTip,
                DoubleClickEnabled = true
            };
        }
        private void CreateReportExplorer()
        {
            if (reportDesigner.ReportType == DesignerReportType.Section)
            {
                if (explorerPropertyGridContainer.Panel1.Controls.Contains(reportExplorerTabControl))
                {
                    reportExplorerTabControl.TabPages[0].SuspendLayout();
                    explorerPropertyGridContainer.Panel1.SuspendLayout();
                    explorerPropertyGridContainer.Panel1.Controls.Remove(reportExplorerTabControl);
                    explorerPropertyGridContainer.Panel1.Controls.Add(reportExplorer);
                    reportExplorerTabControl.TabPages[0].ResumeLayout();
                    explorerPropertyGridContainer.Panel1.ResumeLayout();
                }
            }
            else if (!explorerPropertyGridContainer.Panel1.Controls.Contains(reportExplorerTabControl))
            {
                reportExplorerTabControl.TabPages[0].SuspendLayout();
                explorerPropertyGridContainer.Panel1.SuspendLayout();
                explorerPropertyGridContainer.Panel1.Controls.Remove(reportExplorer);
                reportExplorerTabControl.TabPages[0].Controls.Add(reportExplorer);
                explorerPropertyGridContainer.Panel1.Controls.Add(reportExplorerTabControl);
                reportExplorerTabControl.TabPages[0].ResumeLayout();
                explorerPropertyGridContainer.Panel1.ResumeLayout();
            }
        }
        private void EnableTabs()
        {
            LoadTools(reportToolbox, reportDesigner.ReportType);
            reportToolbox.Reorder(reportDesigner);
            reportToolbox.EnsureCategories();
            if (reportDesigner.ReportType == DesignerReportType.Section)
            {
                reportToolbox.ChangeVisibilityCategory(Properties.Resources.ToolBoxData, true);
                reportToolbox.EnableCategory(Properties.Resources.ToolBoxData, true);
            }
            reportToolbox.Refresh();
        }
        
        //Click "Save to Server" to save a report to the server.
        private void OnSaveToServer(object sender, EventArgs e)
        {
            reportDesigner.SaveReportToServer();
        }
        //Click "Open from Server" to open a report from the server.
        private void OnLoadFromServer(object sender, EventArgs e)
        {
            var reportname = "";
            if (reportDesigner.LoadReportFromServer(out reportname) == DialogResult.OK)
            {
                _reportName = reportname;
                SetTitle();
            }
        }
        
        private void ToggleMessageFilter(object sender, EventArgs eventArgs)
        {
            if (_filter != null)
            {
                Application.RemoveMessageFilter(_filter);
                _filter = null;
                _toogleFilterMenu.CheckState = CheckState.Unchecked;
                return;
            }
            _filter = new DesignerMessageFilter(reportDesigner);
            Application.AddMessageFilter(_filter);
            _toogleFilterMenu.CheckState = CheckState.Checked;
        }
        private sealed class DesignerMessageFilter : IMessageFilter
        {
            private const int WM_KEYDOWN = 0x100;
            private const int WM_SYSKEYDOWN = 0x104;
            private readonly Designer _designer;
            public DesignerMessageFilter(Designer designer)
            {
                _designer = designer;
            }
            public bool PreFilterMessage(ref Message m)
            {
                if ((m.Msg == WM_KEYDOWN || m.Msg == WM_SYSKEYDOWN) && IsControlMatch(m.HWnd))
                {
                    var keyData = ((Keys)((int)((long)m.WParam))) | ModifierKeys;
                    if ((keyData & Keys.Control) == Keys.Control)
                        return true;
                }
                return false;
            }
            private bool IsControlMatch(IntPtr handle)
            {
                if (handle == _designer.Handle)
                    return true;
                if (_designer.Controls.Count == 0)
                    return false;
                return IsChildControlMatch(handle, _designer.Controls);
            }
            /// <summary>
            /// Loops through the child controls to see if it's a child control that is sending the message.
            /// </summary>
            /// <remarks>The TypedValueEditor has controls made up of child controls so we need to see if the message is coming from a possible child control</remarks>
            private static bool IsChildControlMatch(IntPtr handle, Control.ControlCollection controls)
            {
                foreach (Control child in controls)
                {
                    if (child.Handle == handle)
                        return true;
                    if (child.Controls.Count > 0 && IsChildControlMatch(handle, child.Controls))
                        return true;
                }
                return false;
            }
        }
 
 
        private void EndUserDesigner_Load(object sender, EventArgs e)
        {
            //CommonFunctions.AddARDemoOperation(EventTypes.¿ªÊ¼±¨±í±à¼­, this.CurrentReport.Name);
            //this.OnDesign("test.rdlx");
 
        }
        /// <summary>
        /// ¼ÓÔØ±à¼­
        /// </summary>
        /// <param name="path"></param>
        public void OnDesign(string path)
        {
            try
            {
 
                _reportName = path;//Application.StartupPath+"\\"+path;
                reportDesigner.LoadReport(new FileInfo(path));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}