-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
159 lines (128 loc) · 6.17 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
using System.Configuration;
using System.Globalization;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using ShopWebApp.Pages;
using ShopWeb.Data;
using Menu = ShopWebApp.Pages.Menu;
using System.Windows.Markup;
using System;
using System.Linq;
using ShopWebApp.Code;
using ShopWeb.Shared;
namespace ShopWebApp
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
SetCulture();
SetConnectionString();
InitializeSettings();
}
void SetCulture()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("ru-RU");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("ru-RU");
LanguageProperty.OverrideMetadata(
typeof(FrameworkElement),
new FrameworkPropertyMetadata
(
XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)
)
);
}
void SetConnectionString()
{
string[] CommandLineArgs = Environment.GetCommandLineArgs();
string GetNextValueInArray(string Command)
{
int serverIndex = Array.IndexOf(CommandLineArgs, Command);
if((serverIndex + 1) < CommandLineArgs.Length)
{
return CommandLineArgs[serverIndex + 1];
}
else
{
return "";
}
}
string serverCommand = CommandLineArgs.FirstOrDefault(s => s == "--server");
string server = serverCommand?.Length > 0 ? GetNextValueInArray(serverCommand) : "";
string databaseCommand = CommandLineArgs.FirstOrDefault(s => s == "--database");
string database = databaseCommand?.Length > 0 ? GetNextValueInArray(databaseCommand) : "";
string passwordCommand = CommandLineArgs.FirstOrDefault(s => s == "--password");
string password = passwordCommand?.Length > 0 ? GetNextValueInArray(passwordCommand) : "";
string userCommand = CommandLineArgs.FirstOrDefault(s => s == "--user");
string user = userCommand?.Length > 0 ? GetNextValueInArray(userCommand) : "";
if (server.Length == 0)
{
server = ConfigurationManager.AppSettings["server"];
}
if(database.Length == 0)
{
database = ConfigurationManager.AppSettings["database"];
}
if (password.Length == 0)
{
password = ConfigurationManager.AppSettings["password"];
}
if (user.Length == 0)
{
user = ConfigurationManager.AppSettings["user"];
}
ShopWebContext.ConnectionString = $"Server={server};Database={database};User Id={user};Password={password};MultipleActiveResultSets=True";
}
void ApplyPage(Page page)
{
frame.Content = page;
Title = page.Title;
}
void Products_Click(object sender, RoutedEventArgs e) => ApplyPage(new Products());
void Categories_Click(object sender, RoutedEventArgs e) => ApplyPage(new Categories());
void Menu_Click(object sender, RoutedEventArgs e) => ApplyPage(new Menu());
void Shops_Click(object sender, RoutedEventArgs e) => ApplyPage(new Shops());
void Adresses_Click(object sender, RoutedEventArgs e) => ApplyPage(new Adresses());
void Sliders_Click(object sender, RoutedEventArgs e) => ApplyPage(new Sliders());
void Orders_Click(object sender, RoutedEventArgs e) => ApplyPage(new Orders());
void OrdersCanceled_Click(object sender, RoutedEventArgs e) => ApplyPage(new OrdersCanceled());
void Users_Click(object sender, RoutedEventArgs e) => ApplyPage(new Users());
void StatisticsByDayPage_Click(object sender, RoutedEventArgs e) => ApplyPage(new StatisticsByDayPage());
void StatisticsByHourPage_Click(object sender, RoutedEventArgs e) => ApplyPage(new StatisticsByHourPage());
void StatisticsByCategoryPage_Click(object sender, RoutedEventArgs e) => ApplyPage(new StatisticsByCategoryPage());
void Messages_Click(object sender, RoutedEventArgs e) => ApplyPage(new Messages());
void DeliveryTime_Click(object sender, RoutedEventArgs e) => ApplyPage(new DeliveryTimes());
void ProductsCollections_Click(object sender, RoutedEventArgs e) => ApplyPage(new ProductsCollections());
void DeliveryPriceTags_Click(object sender, RoutedEventArgs e) => ApplyPage(new DeliveryPriceTags());
void InitializeSettings()
{
CheckMenuItemSetting("ShowProductsInMenuDesktop", Products);
CheckMenuItemSetting("ShowMenuInMenuDesktop", Menu);
CheckMenuItemSetting("ShowCategoriesInMenuDesktop", Categories);
CheckMenuItemSetting("ShowShopsInMenuDesktop", Shops);
CheckMenuItemSetting("ShowAdressesInMenuDesktop", Adresses);
CheckMenuItemSetting("ShowSlidersInMenuDesktop", Sliders);
CheckMenuItemSetting("ShowUsersInMenuDesktop", Users);
CheckMenuItemSetting("ShowReportsInMenuDesktop", Reports);
CheckMenuItemSetting("ShowStatisticsInMenuDesktop", Statistics);
CheckMenuItemSetting("ShowMessagesInMenuDesktop", Messages);
CheckMenuItemSetting("ShowProductsInMenuDesktop", Products);
CheckMenuItemSetting("ShowProductsCollectionsInMenuDesktop", ProductsCollections);
CheckMenuItemSetting("ShowDeliveryPriceTagsInMenuDesktop", DeliveryPriceTags);
CheckMenuItemSetting("ShowDeliveryTimesInMenuDesktop", DeliveryTime);
}
void CheckMenuItemSetting(string Setting, System.Windows.Controls.MenuItem MenuItem)
{
if (int.Parse(SettingsManager.GetValue(Setting)) == 1)
{
MenuItem.Visibility = Visibility.Visible;
}
else
{
MenuItem.Visibility = Visibility.Collapsed;
}
}
}
}