Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.

Commit 350a985

Browse files
authored
Merge pull request #3 from kungfux/feature_XDatabase
Switch to XDatabase and configurable connection
2 parents a1721bf + 9b1bde1 commit 350a985

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1191
-10218
lines changed
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
55
</startup>
6-
</configuration>
6+
<connectionStrings>
7+
<!--<add name="SQLiteConnection" connectionString="Data Source=ba.sqlite;Version=3;UTF8Encoding=True;foreign keys=true;FailIfMissing=true;" providerName="System.Data.Sqlite" />-->
8+
</connectionStrings>
9+
</configuration>

BusinessAccounting/BusinessAccounting/App.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<Application x:Class="BusinessAccounting.App"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
StartupUri="MainWindow.xaml">
4+
StartupUri="MainWindow.xaml"
5+
Startup="App_OnStartup">
56
<Application.Resources>
67
<ResourceDictionary>
78
<ResourceDictionary.MergedDictionaries>
Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,40 @@
1-
using System.Windows;
2-
using Xclass.Database;
1+
using System;
2+
using System.Configuration;
3+
using System.Reflection;
4+
using System.Windows;
5+
using XDatabase;
36

47
namespace BusinessAccounting
58
{
69
/// <summary>
710
/// Interaction logic for App.xaml
811
/// </summary>
9-
public partial class App : Application
12+
public partial class App
1013
{
11-
public static SQLite3Query sqlite = new SQLite3Query();
14+
public static readonly XQuerySqlite Sqlite = new XQuerySqlite();
15+
16+
private void App_OnStartup(object sender, StartupEventArgs e)
17+
{
18+
var connectionString = $@"Data Source={Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\{Assembly.GetExecutingAssembly().GetName().Name}\ba.sqlite;" +
19+
"Version=3;UTF8Encoding=True;foreign keys=true;FailIfMissing=true;";
20+
21+
try
22+
{
23+
connectionString = ConfigurationManager.ConnectionStrings["SqliteConnection"].ConnectionString;
24+
}
25+
catch (NullReferenceException)
26+
{
27+
}
28+
29+
if (Sqlite.TestConnection(connectionString))
30+
{
31+
Sqlite.ConnectionString = connectionString;
32+
}
33+
else
34+
{
35+
MessageBox.Show($"Не удалось установить соединение с базой данных.{Environment.NewLine}Детали: {Sqlite.LastErrorMessage}", "Проблемка");
36+
Current.Shutdown();
37+
}
38+
}
1239
}
1340
}

BusinessAccounting/BusinessAccounting/BusinessAccounting.csproj

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -8,11 +8,14 @@
88
<OutputType>WinExe</OutputType>
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>BusinessAccounting</RootNamespace>
11-
<AssemblyName>BusinessAccounting</AssemblyName>
12-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
11+
<AssemblyName>Business Accounting</AssemblyName>
12+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
1515
<WarningLevel>4</WarningLevel>
16+
<TargetFrameworkProfile />
17+
<NuGetPackageImportStamp>
18+
</NuGetPackageImportStamp>
1619
</PropertyGroup>
1720
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1821
<PlatformTarget>x86</PlatformTarget>
@@ -45,13 +48,16 @@
4548
<Reference Include="MahApps.Metro">
4649
<HintPath>..\packages\MahApps.Metro.0.14.0.0\lib\net45\MahApps.Metro.dll</HintPath>
4750
</Reference>
48-
<Reference Include="MySql.Data">
49-
<HintPath>..\packages\Xclass\Xclass.Database\MySql.Data.dll</HintPath>
51+
<Reference Include="MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
52+
<HintPath>..\packages\MySql.Data.6.9.9\lib\net45\MySql.Data.dll</HintPath>
53+
<Private>True</Private>
5054
</Reference>
5155
<Reference Include="System" />
56+
<Reference Include="System.Configuration" />
5257
<Reference Include="System.Data" />
53-
<Reference Include="System.Data.SQLite">
54-
<HintPath>..\packages\Xclass\Xclass.Database\System.Data.SQLite.dll</HintPath>
58+
<Reference Include="System.Data.SQLite, Version=1.0.104.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
59+
<HintPath>..\packages\System.Data.SQLite.Core.1.0.104.0\lib\net46\System.Data.SQLite.dll</HintPath>
60+
<Private>True</Private>
5561
</Reference>
5662
<Reference Include="System.Drawing" />
5763
<Reference Include="Microsoft.CSharp" />
@@ -68,9 +74,9 @@
6874
<Reference Include="PresentationCore" />
6975
<Reference Include="PresentationFramework" />
7076
<Reference Include="WindowsFormsIntegration" />
71-
<Reference Include="Xclass.Database, Version=1.0.0.0, Culture=neutral, processorArchitecture=x86">
72-
<SpecificVersion>False</SpecificVersion>
73-
<HintPath>..\packages\Xclass\Xclass.Database\Xclass.Database.dll</HintPath>
77+
<Reference Include="XDatabase, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
78+
<HintPath>..\packages\XDatabase.2.0.0\lib\XDatabase.dll</HintPath>
79+
<Private>True</Private>
7480
</Reference>
7581
</ItemGroup>
7682
<ItemGroup>
@@ -125,7 +131,9 @@
125131
<AppDesigner Include="Properties\" />
126132
</ItemGroup>
127133
<ItemGroup>
128-
<None Include="App.config" />
134+
<None Include="App.config">
135+
<SubType>Designer</SubType>
136+
</None>
129137
</ItemGroup>
130138
<ItemGroup>
131139
<Resource Include="Resources\favicon.ico" />
@@ -145,6 +153,13 @@
145153
<Resource Include="Resources\image_noimage.png" />
146154
</ItemGroup>
147155
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
156+
<Import Project="..\packages\System.Data.SQLite.Core.1.0.104.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.104.0\build\net46\System.Data.SQLite.Core.targets')" />
157+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
158+
<PropertyGroup>
159+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
160+
</PropertyGroup>
161+
<Error Condition="!Exists('..\packages\System.Data.SQLite.Core.1.0.104.0\build\net46\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.104.0\build\net46\System.Data.SQLite.Core.targets'))" />
162+
</Target>
148163
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
149164
Other similar extension points exist, see Microsoft.Common.targets.
150165
<Target Name="BeforeBuild">

BusinessAccounting/BusinessAccounting/MainWindow.xaml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<Controls:MetroWindow
1+
<controls:MetroWindow
22
x:Class="BusinessAccounting.MainWindow"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5-
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
5+
xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
66
Title="Business Accounting"
77
TitleCaps="False"
88
Height="450"
@@ -14,13 +14,19 @@
1414
Icon="pack://application:,,,/Resources/favicon.ico"
1515
SaveWindowPosition="True">
1616

17-
<Controls:MetroWindow.Resources>
17+
<controls:MetroWindow.Resources>
1818
<Image x:Key="ImageMenu" Source="pack://application:,,,/Resources/image_menu.png" />
1919
<Image x:Key="ImageCash" Source="pack://application:,,,/Resources/image_cash.png" />
2020
<Image x:Key="ImageMan" Source="pack://application:,,,/Resources/image_man.png" />
2121
<Image x:Key="ImageGraph" Source="pack://application:,,,/Resources/image_graph.png" />
22-
</Controls:MetroWindow.Resources>
22+
</controls:MetroWindow.Resources>
2323

24+
<controls:MetroWindow.RightWindowCommands>
25+
<controls:WindowCommands>
26+
<Button Name="OpenDbFolder" Content="Открыть папку с БД" Click="OpenDbFolder_OnClick"/>
27+
</controls:WindowCommands>
28+
</controls:MetroWindow.RightWindowCommands>
29+
2430
<!-- this grid contain menu button -->
2531
<Grid>
2632
<Grid.Triggers>
@@ -121,4 +127,4 @@
121127
x:Name="ButtonMenu"
122128
Click="ButtonMenu_Click"/>
123129
</Grid>
124-
</Controls:MetroWindow>
130+
</controls:MetroWindow>

BusinessAccounting/BusinessAccounting/MainWindow.xaml.cs

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
using System;
2+
using System.Diagnostics;
3+
using System.IO;
4+
using System.Reflection;
25
using System.Windows;
36
using System.Windows.Controls;
7+
using System.Windows.Media;
48
using MahApps.Metro.Controls;
59
using System.Windows.Media.Animation;
610
using MahApps.Metro.Controls.Dialogs;
@@ -10,7 +14,7 @@ namespace BusinessAccounting
1014
/// <summary>
1115
/// Interaction logic for MainWindow.xaml
1216
/// </summary>
13-
public partial class MainWindow : MetroWindow
17+
public partial class MainWindow
1418
{
1519
public MainWindow()
1620
{
@@ -49,15 +53,17 @@ private void OpenCloseMenu()
4953
{
5054
GridMenu.Visibility = Visibility.Visible;
5155
}
52-
DoubleAnimation animation = new DoubleAnimation();
53-
animation.From = GridMenu.Opacity > 0 ? 1 : 0;
54-
animation.To = GridMenu.Opacity > 0 ? 0 : 1;
55-
animation.Duration = new Duration(TimeSpan.FromSeconds(0.5));
56+
DoubleAnimation animation = new DoubleAnimation
57+
{
58+
From = GridMenu.Opacity > 0 ? 1 : 0,
59+
To = GridMenu.Opacity > 0 ? 0 : 1,
60+
Duration = new Duration(TimeSpan.FromSeconds(0.5))
61+
};
5662
animation.Completed += animation_Completed;
5763
GridMenu.BeginAnimation(OpacityProperty, animation);
5864
}
5965

60-
void animation_Completed(object sender, EventArgs e)
66+
private void animation_Completed(object sender, EventArgs e)
6167
{
6268
// hide objects if they are not visible already
6369
// to avoid clicks
@@ -73,24 +79,48 @@ private void LoadPage(UserControl pPage)
7379
UserControlGrid.Children.Add(pPage);
7480
}
7581

76-
private bool WindowDisplayed = false;
82+
private bool _windowDisplayed;
7783

7884
protected override void OnContentRendered(EventArgs e)
7985
{
8086
base.OnContentRendered(e);
8187

82-
if (WindowDisplayed)
88+
if (_windowDisplayed)
8389
return;
8490

85-
WindowDisplayed = true;
86-
87-
if (!App.sqlite.TestConnection("Data Source=ba.sqlite;Version=3;UTF8Encoding=True;foreign keys=true;FailIfMissing=true", true, false))
88-
{
89-
this.ShowMessageAsync("Проблемка", "Не удалось установить соединение с базой данных.", MessageDialogStyle.Affirmative);
90-
}
91+
_windowDisplayed = true;
9192

9293
// open default page
9394
LoadPage(new UserControls.CashPage());
9495
}
96+
97+
private void ShowMessage(string text)
98+
{
99+
for (var visual = this as Visual; visual != null; visual = VisualTreeHelper.GetParent(visual) as Visual)
100+
if (visual is MetroWindow)
101+
{
102+
((MetroWindow)visual).ShowMessageAsync("Проблемка", text + Environment.NewLine + App.Sqlite.LastErrorMessage);
103+
}
104+
}
105+
106+
private void OpenDbFolder_OnClick(object sender, RoutedEventArgs e)
107+
{
108+
string dbPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\{Assembly.GetExecutingAssembly().GetName().Name}";
109+
110+
try
111+
{
112+
if (!Directory.Exists(dbPath))
113+
{
114+
ShowMessage($"Папка по адресу {dbPath} не найдена.");
115+
return;
116+
}
117+
118+
Process.Start("explorer", $@"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\{Assembly.GetExecutingAssembly().GetName().Name}");
119+
}
120+
catch (Exception)
121+
{
122+
// ignored
123+
}
124+
}
95125
}
96126
}

BusinessAccounting/BusinessAccounting/Properties/AssemblyInfo.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
[assembly: AssemblyTitle("Business Accounting")]
1111
[assembly: AssemblyDescription("")]
1212
[assembly: AssemblyConfiguration("")]
13-
[assembly: AssemblyCompany("Fuks Alexander")]
13+
[assembly: AssemblyCompany("Alexander Fuks")]
1414
[assembly: AssemblyProduct("Business Accounting")]
15-
[assembly: AssemblyCopyright("Copyright © Fuks Alexander 2014")]
15+
[assembly: AssemblyCopyright("Copyright © Alexander Fuks 2014-2017")]
1616
[assembly: AssemblyTrademark("")]
1717
[assembly: AssemblyCulture("")]
1818

@@ -51,5 +51,5 @@
5151
// You can specify all the values or you can default the Build and Revision Numbers
5252
// by using the '*' as shown below:
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("1.1.0.0")]
55-
[assembly: AssemblyFileVersion("1.1.0.0")]
54+
[assembly: AssemblyVersion("1.2.0.0")]
55+
[assembly: AssemblyFileVersion("1.2.0.0")]

0 commit comments

Comments
 (0)