-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddDataBase.xaml.cs
More file actions
66 lines (62 loc) · 2.02 KB
/
AddDataBase.xaml.cs
File metadata and controls
66 lines (62 loc) · 2.02 KB
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
using System.Windows;
namespace TheGUIAndSQLApp
{
/// <summary>
/// Логика взаимодействия для AddDataBase.xaml
/// </summary>
public partial class AddDataBase
{
private string connectString;
public AddDataBase(string cS)
{
InitializeComponent();
connectString = cS;
}
private void MetroWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if(App.Current.MainWindow != null)
{
App.Current.MainWindow.IsEnabled = true;
App.Current.MainWindow.Activate();
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
string comboSelectedValue = charSet.SelectedItem.ToString().Replace("System.Windows.Controls.ComboBoxItem: ", "");
string charSetS = getCharSet(comboSelectedValue);
string createStr = "CREATE DATABASE `";
createStr += this.DBName.Text + "` ";
if(comboSelectedValue != "binary")
{
createStr += "DEFAULT CHARACTER SET " + charSetS + " COLLATE " + comboSelectedValue;
}
else
{
createStr += "DEFAULT CHARACTER SET binary";
}
MySqlLib.MySqlData.MySqlExecute.MyResult result =
MySqlLib.MySqlData.MySqlExecute.SqlNoneQuery(createStr, connectString);
if (result.HasError == false)
{
MainWindow wnd = (MainWindow)App.Current.MainWindow;
wnd.SelectDataBases();
this.Close();
}
else
{
MessageBox.Show(result.ErrorText);
}
}
private string getCharSet(string cSV)
{
if(cSV.IndexOf('_') != -1)
{
return cSV.Substring(0, cSV.IndexOf('_'));
}
else
{
return "binary";
}
}
}
}