-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
229 lines (205 loc) · 8.23 KB
/
MainWindow.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
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
using Server_Restart_II;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Timers;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Timer = System.Timers.Timer;
using Server_Restart_Final.DataStorage;
using ServerRestartFinal.Core.IoC;
namespace Server_Restart_Final
{
/// <summary>
/// MainWindow.xaml 的互動邏輯
/// </summary>
public partial class MainWindow : Window
{
public double WindowHeight { get { return Application.Current.MainWindow.Height; } set { Main.Height = value; } }
public ApplicationPage CurrentPage = Global.GlobalSigh.PageType;
public Timer timer1;
public Server _server;
public MainPage _MainPage = new MainPage();
public MainWindow()
{
this.Main = this;
this.DataContext = new WindowsVeiwModles(this);
this.Loaded += MainWindow_Loaded;
this.MouseDown += MainWindow_MouseDown;
this.Closing += MainWindow_Closing;
this.MouseMove += MainWindow_MouseMove;
timer1 = new Timer
{
Enabled=false,
AutoReset=true,
Interval=700,
};
timer1.Elapsed += Timer_Elapsed;
}
private void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
this.Dispatcher.Invoke((Action)(() =>
{
f();
}));
}
public void f()
{
Ellipse_Particle ep = new Ellipse_Particle(_MainPage.DrawCanvas);
ep.Draw();
ep = null;
}
private void MainWindow_MouseMove(object sender, MouseEventArgs e)
{
_MainPage.Out.Text = "" + e.GetPosition(_MainPage.DrawCanvas);
}
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Global.GlobalSigh.ApplicationClosing();
}
public Ellipse cir;
private void MainWindow_MouseDown(object sender, MouseButtonEventArgs e)
{
}
protected override void OnRender(DrawingContext dc)
{
}
public async Task SizeMin()
{
for (int i = 100; i >= 30; i -= 2)
{
await Task.Delay(1);
this.Dispatcher.Invoke((Action)(() =>
{
cir.Height = i;
cir.Width = i;
}));
}
}
public async Task Move_Control(object sender, MouseButtonEventArgs e)
{
Point MousePoint = e.GetPosition(_MainPage.DrawCanvas);
var PosX = (int)(MousePoint.X - (cir.Width / 2));
var PosY = (int)(MousePoint.Y - (cir.Height / 2));
int MainHeight = (int)_MainPage.DrawCanvas.Height;
int MainWidth = (int)_MainPage.DrawCanvas.Width;
var MarginHeight = MainHeight - (PosY + (int)SystemParameters.CaptionHeight + (int)SystemParameters.BorderWidth + 4);
var MarginWidth = MainWidth - (PosX + (int)SystemParameters.BorderWidth);
cir.Margin = new Thickness(PosX, PosY, MarginWidth, MarginHeight);
for (int i = 0; i <= 1000; i++)
{
await Task.Delay(1);
this.Dispatcher.Invoke((Action)(() =>
{
cir.Margin = new Thickness(PosX, PosY - i, MarginWidth, MarginHeight + i);
}));
}
}
Random r = new Random();
public async Task Move_Control()
{
Point MousePoint = new Point(r.Next(0, 500), 500);
var PosX = (int)(MousePoint.X - (cir.Width / 2));
var PosY = (int)(MousePoint.Y - (cir.Height / 2));
int MainHeight = (int)_MainPage.DrawCanvas.Height;
int MainWidth = (int)_MainPage.DrawCanvas.Width;
var MarginHeight = MainHeight - (PosY + (int)SystemParameters.CaptionHeight + (int)SystemParameters.BorderWidth + 4);
var MarginWidth = MainWidth - (PosX + (int)SystemParameters.BorderWidth);
cir.Margin = new Thickness(PosX, PosY, MarginWidth, MarginHeight);
for (int i = 0; i <= 1000; i++)
{
await Task.Delay(1);
this.Dispatcher.Invoke((Action)(() =>
{
cir.Margin = new Thickness(PosX, PosY - i, MarginWidth, MarginHeight + i);
}));
}
}
public void Move_Control(object sender, Point p)
{
Point MousePoint = p;
var PosX = (int)(MousePoint.X - 115 - 50);
var PosY = (int)(MousePoint.Y - 55 - 50);
int MainHeight = (int)_MainPage.DrawCanvas.Height;
int MainWidth = (int)_MainPage.DrawCanvas.Width;
var MarginHeight = MainHeight - (PosY + (int)SystemParameters.CaptionHeight + (int)SystemParameters.BorderWidth + 4);
var MarginWidth = MainWidth - (PosX + (int)SystemParameters.BorderWidth);
cir.Margin = new Thickness(PosX, PosY, MarginWidth, MarginHeight);
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
Global.GlobalSigh.ConnectToSQLServer();
ProcessCheckStatus.data = StorageData.FromXmlFile<Data>(System.Windows.Forms.Application.StartupPath + "\\LocalData.xml");
Global.GlobalSigh.SS.ConnectToServer();
Global.GlobalSigh._client.Connect(ProcessCheckStatus.data.SQLServerLoaction,10127);
ProcessCheckStatus.CheckUserExit.Elapsed += CheckUserExit_Elapsed;
ProcessCheckStatus.CheckUserExit.Enabled = ProcessCheckStatus.data.UserFroceTiming;
SideMenu.Width = 60;
Global.GlobalSigh.lf = this.LoadingFrame;
this.WindowState = WindowState.Normal;
Global.GlobalSigh.sidem = this.SideMenu;
Global.GlobalSigh.sidem.CPMenu = this.SideMenu.CPMenu;
Global.GlobalSigh.sidem.CPMenu = new RelayCommand(Global.GlobalSigh.ChangeSideMenu);
Global.GlobalSigh.fr = this.MainFrame;
Global.GlobalSigh.mw = this;
cir = new Ellipse();
cir.StrokeThickness = 1;
cir.Stroke = Brushes.AliceBlue;
cir.Height = 300;
cir.Width = 300;
Point R = new Point(_MainPage.DrawCanvas.Height / 2, _MainPage.DrawCanvas.Width / 2);
Move_Control(sender, R);
_MainPage.DrawCanvas.Children.Add(cir);
}
private void CheckUserExit_Elapsed(object sender, ElapsedEventArgs e)
{
ProcessCheckStatus.UserControl = false;
}
private async void StartServerBtn_Click(object sender, RoutedEventArgs e)
{
await Task.Run(()=>_server.StartServer());
}
private void Main_SizeChanged(object sender, SizeChangedEventArgs e)
{
Control control = (Control)sender;
this.Dispatcher.Invoke(()=> { ChangeMain(); });
Debug.Write(" Heigh:"+this.Height+" Width:"+this.Width+"\n");
}
public void ChangeMain()
{
Task.Run(() => this.Dispatcher.Invoke(() => {
MainGrid.Height = this.Height;
SideMenu.Height = this.Height;
}));
}
private void Main_MouseMove(object sender, MouseEventArgs e)
{
}
public void MouseMoves()
{
ProcessCheckStatus.CheckUserExit.Enabled = ProcessCheckStatus.data.UserFroceTiming;
if (ProcessCheckStatus.data.UserFroceTiming)
{
ProcessCheckStatus.UserControl = true;
}
}
private void Main_StateChanged(object sender, EventArgs e)
{
Task.Run(() => this.Dispatcher.Invoke(() => {
MainGrid.Height = this.Height;
SideMenu.Height = this.Height;
}));
}
}
}