-
Notifications
You must be signed in to change notification settings - Fork 1
/
DialogWindowCreateFile.xaml.cs
192 lines (152 loc) · 7.81 KB
/
DialogWindowCreateFile.xaml.cs
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
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Win32;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.ComponentModel;
using System.Windows.Markup;
namespace SCADA
{
/// <summary>
/// Логика взаимодействия для DialogWindowCreateFile.xaml
/// </summary>
public partial class DialogWindowCreateFile : Window
{
public DialogWindowCreateFile()
{
InitializeComponent();
}
private void CreatePage(object sender, RoutedEventArgs e)
{
char[] InvalidChars = { '"', '/', '\\', '<', '>', '?', '*', '|', ':' };
if (NamePage.Text.IndexOfAny(InvalidChars) != -1)
{
Border border = new Border();
border.BorderThickness = new Thickness(2);
border.Background = new SolidColorBrush(Colors.White);
border.BorderBrush = new SolidColorBrush(Colors.Red);
TextBlock textBlock = new TextBlock();
textBlock.TextWrapping = TextWrapping.Wrap;
textBlock.Text = "Имя странцы не должно содержать символы: < > | \" / \\ * : ?";
border.Child = textBlock;
Message.Child = border;
Message.IsOpen = true;
e.Handled = true;
return;
}
if (string.IsNullOrWhiteSpace(NamePage.Text))
{
Border border = new Border();
border.BorderThickness = new Thickness(2);
border.Background = new SolidColorBrush(Colors.White);
border.BorderBrush = new SolidColorBrush(Colors.Red);
TextBlock textBlock = new TextBlock();
textBlock.TextWrapping = TextWrapping.Wrap;
textBlock.Text = "Имя страницы не должно содержать только пробелы или быть пустой строкой.";
border.Child = textBlock;
Message.Child = border;
Message.IsOpen = true;
e.Handled = true;
return;
}
if (!NamePage.Text.EndsWith(".pg"))
{
NamePage.Text += ".pg";
}
//Находим индекс имени проекта, для удаления и получения пути проекта
int index = ((MainWindow)((AppWPF)Application.Current).MainWindow).ProjectBin.PathProject.LastIndexOf(((MainWindow)((AppWPF)Application.Current).MainWindow).ProjectBin.ProjectName);
Window MainWindow = ((AppWPF)System.Windows.Application.Current).MainWindow;
PageScada ps = new PageScada();
ps.Name = NamePage.Text;
ps.Path = ((MainWindow)((AppWPF)Application.Current).MainWindow).ProjectBin.PathProject.Remove(index) + "\\" + NamePage.Text;
ps.Attachments = 0;
if (File.Exists(ps.Path))
{
MessageBox.Show("Страница " + ps.Path + " уже существует.", "Ошибка создания страницы", MessageBoxButton.OK, MessageBoxImage.Error);
e.Handled = true;
return;
}
StackPanel panelPage = new StackPanel();
panelPage.Orientation = System.Windows.Controls.Orientation.Horizontal;
Image imageScada = new Image();
imageScada.Source = new BitmapImage(new Uri("Images/Page16.png", UriKind.Relative));
Image imageCut = new Image();
imageCut.Source = new BitmapImage(new Uri("Images/Cut16.png", UriKind.Relative));
Image imageDelete = new Image();
imageDelete.Source = new BitmapImage(new Uri("Images/PageDelete16.png", UriKind.Relative));
Image imageCopy = new Image();
imageCopy.Source = new BitmapImage(new Uri("Images/CopyPage16.png", UriKind.Relative));
MenuItem menuItemCopyPage = new MenuItem();
menuItemCopyPage.IsEnabled = false;
menuItemCopyPage.Style = (Style)Application.Current.FindResource("ControlOnToolBar");
menuItemCopyPage.Header = "Копировать";
menuItemCopyPage.Icon = imageCopy;
menuItemCopyPage.Tag = ps;
menuItemCopyPage.Click += ((MainWindow)MainWindow).CopyItem;
MenuItem menuItemCutPage = new MenuItem();
menuItemCutPage.IsEnabled = false;
menuItemCutPage.Style = (Style)Application.Current.FindResource("ControlOnToolBar");
menuItemCutPage.Header = "Вырезать";
menuItemCutPage.Icon = imageCut;
menuItemCutPage.Tag = ps;
menuItemCutPage.Click += ((MainWindow)MainWindow).CutItem;
MenuItem menuItemDeletePage = new MenuItem();
menuItemDeletePage.Header = "Удалить";
menuItemDeletePage.Icon = imageDelete;
menuItemDeletePage.Tag = ps;
menuItemDeletePage.Click += ((MainWindow)MainWindow).DeleteItem;
ContextMenu contextMenuPage = new ContextMenu();
contextMenuPage.Tag = "PageScada";
contextMenuPage.Items.Add(menuItemCopyPage);
contextMenuPage.Items.Add(menuItemCutPage);
contextMenuPage.Items.Add(menuItemDeletePage);
TreeViewItem ItemPage = new TreeViewItem();
ItemPage.MouseDoubleClick += ((MainWindow)MainWindow).OpenBrowsePage;
ItemPage.Tag = ps;
ItemPage.KeyDown += ((MainWindow)MainWindow).RenamePage;
ItemPage.ContextMenu = contextMenuPage;
ps.TreeItem = ItemPage;
System.Windows.Controls.TextBox tbRenamePage = new System.Windows.Controls.TextBox();
tbRenamePage.KeyDown += ((MainWindow)MainWindow).OkRenamePage;
tbRenamePage.Text = ps.Name;
System.Windows.Controls.Label lNamePage = new System.Windows.Controls.Label();
lNamePage.Content = ps.Name;
lNamePage.Tag = tbRenamePage;
AlphanumComparator a = new AlphanumComparator();
a.Name = (string)lNamePage.Content;
panelPage.Children.Add(imageScada);
panelPage.Children.Add(lNamePage);
panelPage.Tag = a;
ItemPage.Header = panelPage;
((MainWindow)MainWindow).BrowseProject.Items.Add(ItemPage);
Page pg = new Page();
((MainWindow)((AppWPF)Application.Current).MainWindow).ProjectBin.CollectionPageScada.Add(ps.Path, ps);
((AppWPF)System.Windows.Application.Current).CollectionPage.Add(ps.Path, pg);
TabItemPage tabItemPage = new TabItemPage(ps);
using (FileStream fs = File.Create((ps.Path)))
{
XamlWriter.Save(pg, fs);
fs.Close();
}
((MainWindow)MainWindow).BrowseProject.Items.SortDescriptions.Clear();
((MainWindow)MainWindow).BrowseProject.Items.SortDescriptions.Add(new SortDescription("ContextMenu.Tag", ListSortDirection.Ascending));
((MainWindow)MainWindow).BrowseProject.Items.SortDescriptions.Add(new SortDescription("Header.Tag", ListSortDirection.Ascending));
e.Handled = true;
this.Close();
}
}
}