-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
74 lines (63 loc) · 1.87 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
using System;
using System.ComponentModel;
using System.Windows;
namespace SatelliteDataScripter
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private MainWindowModel Model { get; set; }
public MainWindow()
{
InitializeComponent();
if (!DesignerProperties.GetIsInDesignMode(this))
{
DataContext = Model = new MainWindowModel();
Model.OptionsChanged += MainWindowModel_OnOptionsChanged;
}
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
ConnectionsComboBox.Focus();
}
private void MainWindowModel_OnOptionsChanged(object sender, RoutedEventArgs e)
{
UpdateScript(true);
}
private void GenerateButton_Click(object sender, RoutedEventArgs e)
{
UpdateScript(false);
}
private void UpdateScript(bool silent)
{
if (Model.SelectedTable != null)
{
ScriptTextBox.Text = GenerateScript(silent);
ScriptTextBox.SelectAll();
}
else
{
ScriptTextBox.Text = string.Empty;
}
}
private string GenerateScript(bool silent)
{
try
{
var script = Model.SelectedTable.ScriptData();
Clipboard.SetText(script);
return script;
}
catch (Exception exception)
{
if (!silent)
{
MessageBox.Show(this, exception.Message, exception.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error);
}
return string.Empty;
}
}
}
}