Skip to content

Commit

Permalink
1. Move AppSettings to Domain project
Browse files Browse the repository at this point in the history
2. Save BusinessRules to AppSettings
3. Fix error on checking item change
4. Show business rules in appsetting window
5. Change app update checking to background mode
  • Loading branch information
gh0stter committed Mar 8, 2017
1 parent 2e24e17 commit 63e1fef
Show file tree
Hide file tree
Showing 41 changed files with 295 additions and 94 deletions.
9 changes: 5 additions & 4 deletions ACMC Library System/ACMC Library System.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<Install>true</Install>
<InstallFrom>Web</InstallFrom>
<UpdateEnabled>true</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateMode>Background</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
Expand All @@ -35,7 +35,7 @@
<ProductName>ACMC Library System</ProductName>
<PublisherName>William Liu</PublisherName>
<SuiteName>ACMC Library System</SuiteName>
<ApplicationRevision>16</ApplicationRevision>
<ApplicationRevision>18</ApplicationRevision>
<ApplicationVersion>1.1.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<CreateDesktopShortcut>true</CreateDesktopShortcut>
Expand Down Expand Up @@ -158,7 +158,6 @@
<Compile Include="DbModels\item_status.cs" />
<Compile Include="DbModels\LibraryDb.cs" />
<Compile Include="DbModels\patron.cs" />
<Compile Include="Entities\AppSettings.cs" />
<Compile Include="Supports\Array.Extension.cs" />
<Compile Include="Supports\Cache.cs" />
<Compile Include="Supports\Converters.cs" />
Expand Down Expand Up @@ -321,7 +320,9 @@
<Name>DomainModels</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="Entities\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>RD /Q /S %25USERPROFILE%25\AppData\Local\L00P</PreBuildEvent>
Expand Down
22 changes: 22 additions & 0 deletions ACMC Library System/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ACMC_Library_System.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ACMC_Library_System.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
Expand Down Expand Up @@ -48,4 +51,23 @@
</setting>
</ACMC_Library_System.Properties.Settings>
</userSettings>
<applicationSettings>
<ACMC_Library_System.Properties.Settings>
<setting name="RenewPeriodInDay" serializeAs="String">
<value>14</value>
</setting>
<setting name="FinesPerWeek" serializeAs="String">
<value>0.5</value>
</setting>
<setting name="LibMemberId" serializeAs="String">
<value>19</value>
</setting>
<setting name="LibMemberBarcode" serializeAs="String">
<value>M000001</value>
</setting>
<setting name="DefaultQuotaPerMember" serializeAs="String">
<value>2</value>
</setting>
</ACMC_Library_System.Properties.Settings>
</applicationSettings>
</configuration>
33 changes: 22 additions & 11 deletions ACMC Library System/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Windows;
using DomainModels.DataModel;
using Microsoft.Shell;

namespace ACMC_Library_System
Expand All @@ -19,10 +20,10 @@ public bool SignalExternalCommandLineArgs(IList<string> args)
{
// Handle command line arguments of second instance
// Bring window to foreground
//if (this.MainWindow.WindowState == WindowState.Minimized)
//{
// this.MainWindow.WindowState = WindowState.Normal;
//}
if (MainWindow.WindowState == WindowState.Minimized)
{
MainWindow.WindowState = WindowState.Normal;
}
MainWindow.Activate();
return true;
}
Expand All @@ -32,15 +33,25 @@ public bool SignalExternalCommandLineArgs(IList<string> args)
[STAThread]
public static void Main()
{
if (SingleInstance<App>.InitializeAsFirstInstance(Unique))
if (!SingleInstance<App>.InitializeAsFirstInstance(Unique))
{
var application = new App();
application.InitializeComponent();
application.Run();

// Allow single instance code to perform cleanup operations
SingleInstance<App>.Cleanup();
return;
}
var application = new App();

//ini business rules
var appSettings = ACMC_Library_System.Properties.Settings.Default;
BusinessRules.RenewPeriodInDay = appSettings.RenewPeriodInDay;
BusinessRules.DefaultQuotaPerMember = appSettings.DefaultQuotaPerMember;
BusinessRules.FinesPerWeek = appSettings.FinesPerWeek;
BusinessRules.LibMemberBarcode = appSettings.LibMemberBarcode;
BusinessRules.LibMemberId = appSettings.LibMemberId;

application.InitializeComponent();
application.Run();

// Allow single instance code to perform cleanup operations
SingleInstance<App>.Cleanup();
}
}
}
4 changes: 2 additions & 2 deletions ACMC Library System/DbModels/patron.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System.Linq;
using DomainModels.DataModel;
using ACMC_Library_System.Supports;

namespace ACMC_Library_System.DbModels
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;

[Table("patron")]
public partial class patron
Expand Down Expand Up @@ -81,7 +81,7 @@ public patron()

//following properties will not be in the database
[NotMapped]
public bool AllowToDelete => id != BusinessRules.MainMemberId && barcode != BusinessRules.MainMemberBarcode;
public bool AllowToDelete => id != BusinessRules.LibMemberId && barcode != BusinessRules.LibMemberBarcode;

[NotMapped]
public string DisplayNameCh => surname_ch == null ? firstnames_ch : $"{surname_ch} {firstnames_ch}";
Expand Down
45 changes: 45 additions & 0 deletions ACMC Library System/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions ACMC Library System/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,20 @@
<Setting Name="ConnectionString" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="RenewPeriodInDay" Type="System.Int32" Scope="Application">
<Value Profile="(Default)">14</Value>
</Setting>
<Setting Name="FinesPerWeek" Type="System.Double" Scope="Application">
<Value Profile="(Default)">0.5</Value>
</Setting>
<Setting Name="LibMemberId" Type="System.Int32" Scope="Application">
<Value Profile="(Default)">19</Value>
</Setting>
<Setting Name="LibMemberBarcode" Type="System.String" Scope="Application">
<Value Profile="(Default)">M000001</Value>
</Setting>
<Setting Name="DefaultQuotaPerMember" Type="System.Int32" Scope="Application">
<Value Profile="(Default)">2</Value>
</Setting>
</Settings>
</SettingsFile>
49 changes: 35 additions & 14 deletions ACMC Library System/UI/AppSettingWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
mc:Ignorable="d"
Title="App Settings"
Height="430" Width="525"
Height="535" Width="525"
ResizeMode="NoResize"
ShowInTaskbar="False"
WindowStartupLocation="CenterScreen">
Expand Down Expand Up @@ -62,57 +62,78 @@
<TextBox x:Name="TbSqlServer" Text="{Binding SqlServer}"
controls:ControlsHelper.MouseOverBorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"
metro:ControlsHelper.FocusBorderBrush="#55acee"
HorizontalAlignment="Left" Height="23" Margin="144,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="340"/>
HorizontalAlignment="Left" Height="23" Margin="144,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="334"/>

<Label Content="Authentication Type: " HorizontalAlignment="Left" Margin="10,40,0,0" VerticalAlignment="Top"/>
<ComboBox x:Name="CbAuthType" HorizontalAlignment="Left" Height="23"
Margin="144,39,0,0" VerticalAlignment="Top" Width="340"
Margin="144,39,0,0" VerticalAlignment="Top" Width="334"
SelectedIndex="0"
ItemsSource="{Binding SqlAuthType}"
SelectedValuePath="Key"
DisplayMemberPath="Value"
SelectionChanged="TbAuthType_SelectionChanged"/>

<Label Content="User Name: " HorizontalAlignment="Left" Margin="10,71,0,0" VerticalAlignment="Top"/>
<Label Content="User Name: " HorizontalAlignment="Left" Margin="10,71,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="TbUser" Text="{Binding UserName}"
IsEnabled="False"
metro:ControlsHelper.MouseOverBorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"
metro:ControlsHelper.FocusBorderBrush="#55acee"
HorizontalAlignment="Left" Height="23" Margin="144,70,0,0"
TextWrapping="Wrap" VerticalAlignment="Top" Width="340"/>
TextWrapping="Wrap" VerticalAlignment="Top" Width="334"/>

<Label Content="Password: " HorizontalAlignment="Left" Margin="10,101,0,0" VerticalAlignment="Top"/>
<PasswordBox x:Name="TbPassword" IsEnabled="False"
metro:ControlsHelper.MouseOverBorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"
metro:ControlsHelper.FocusBorderBrush="#55acee"
HorizontalAlignment="Left" Height="23" Margin="144,101,0,0" VerticalAlignment="Top" Width="340"/>
HorizontalAlignment="Left" Height="23" Margin="144,101,0,0" VerticalAlignment="Top" Width="334"/>

<Label Content="Catalog: " HorizontalAlignment="Left" Margin="10,133,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="TbCatalog" Text="{Binding Catalog}"
metro:ControlsHelper.MouseOverBorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"
metro:ControlsHelper.FocusBorderBrush="#55acee"
HorizontalAlignment="Left" Height="23"
Margin="144,132,0,0" VerticalAlignment="Top" Width="340"/>
Margin="144,132,0,0" VerticalAlignment="Top" Width="334"/>

<Button x:Name="BtnTest" Content="Test Connection"
HorizontalAlignment="Left" Margin="377,163,0,0" VerticalAlignment="Top" Width="107"
HorizontalAlignment="Left" Margin="371,163,0,0" VerticalAlignment="Top" Width="107"
Click="BtnTest_Click" Height="35"/>
</Grid>
</GroupBox>
<GroupBox x:Name="Update" Header="General Setting" HorizontalAlignment="Left" Margin="10,260,0,0" VerticalAlignment="Top" Height="76" Width="500">
<GroupBox x:Name="Business" Header="Business Rules" HorizontalAlignment="Left" Margin="10,255,0,0" VerticalAlignment="Top" Height="140" Width="500">
<Grid>
<Label Content="Default Renew Period (Day): " HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="TbRenewPeriodInDay" Text="{Binding RenewPeriodInDay}"
controls:ControlsHelper.MouseOverBorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"
metro:ControlsHelper.FocusBorderBrush="#55acee"
HorizontalAlignment="Left" Height="23" Margin="190,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="288" IsEnabled="False"/>

<Label Content="Fines Per Week ($): " HorizontalAlignment="Left" Margin="10,42,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="TbFinesPerWeek" Text="{Binding FinesPerWeek}"
controls:ControlsHelper.MouseOverBorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"
metro:ControlsHelper.FocusBorderBrush="#55acee"
HorizontalAlignment="Left" Height="23" Margin="190,41,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="288" IsEnabled="False"/>

<Label Content="Default Quota Per Member: " HorizontalAlignment="Left" Margin="10,72,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="TbDefaultQuotaPerMember" Text="{Binding DefaultQuotaPerMember}"
controls:ControlsHelper.MouseOverBorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"
metro:ControlsHelper.FocusBorderBrush="#55acee"
HorizontalAlignment="Left" Height="23" Margin="190,71,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="288" IsEnabled="False"/>
</Grid>
</GroupBox>
<GroupBox x:Name="Database" Header="Database Settings" HorizontalAlignment="Left" Margin="10,400,0,0" VerticalAlignment="Top" Height="60" Width="500">
<Grid>
<CheckBox x:Name="CbAutoBackUp"
Margin="10,10,0,0"
Margin="10,0,0,0"
IsChecked="{Binding AutoBackDb}"
HorizontalAlignment="Left"
VerticalAlignment="Top">Bakup database automatically.</CheckBox>
</Grid>
</GroupBox>

<TextBlock Foreground="#8899A6" FontSize="10" HorizontalAlignment="Left" VerticalAlignment="Bottom" Height="12" Width="42" Margin="10,0,0,10">Version :</TextBlock>
<TextBlock Foreground="#8899A6" FontSize="10" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="52,0,0,10" Height="12" Width="50" Text="{Binding AppVersion, Mode=OneTime}" />
<Button x:Name="BtnSave" Content="Save" HorizontalAlignment="Left" Margin="305,353,0,0" VerticalAlignment="Top" Click="BtnSave_Click" Height="35" Width="100" IsDefault="True"/>
<Button x:Name="BtnCancel" Content="Cancel" HorizontalAlignment="Left" Margin="410,353,0,0" VerticalAlignment="Top" Click="BtnCancel_Click" Height="35" Width="100"/>

<Button x:Name="BtnSave" Content="Save" HorizontalAlignment="Left" Margin="305,465,0,0" VerticalAlignment="Top" Click="BtnSave_Click" Height="35" Width="100" IsDefault="True"/>
<Button x:Name="BtnCancel" Content="Cancel" HorizontalAlignment="Left" Margin="410,465,0,0" VerticalAlignment="Top" Click="BtnCancel_Click" Height="35" Width="100"/>
</Grid>
</metro:MetroWindow>
8 changes: 7 additions & 1 deletion ACMC Library System/UI/AppSettingWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using ACMC_Library_System.Entities;
using ACMC_Library_System.Properties;
using ACMC_Library_System.Supports;
using DomainModels.DataModel;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;
using NLog;
Expand Down Expand Up @@ -111,6 +111,12 @@ public string AppVersion
}
}

public int RenewPeriodInDay => BusinessRules.RenewPeriodInDay;

public int DefaultQuotaPerMember => BusinessRules.DefaultQuotaPerMember;

public double FinesPerWeek => BusinessRules.FinesPerWeek;

#endregion

public AppSettingWindow()
Expand Down
2 changes: 0 additions & 2 deletions ACMC Library System/UI/BootStrap.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows;
using System.Configuration;
using System.Deployment.Application;
using System.Linq;
using ACMC_Library_System.DbModels;
using NLog;
using ACMC_Library_System.Entities;
using ACMC_Library_System.Supports;

namespace ACMC_Library_System.UI
Expand Down
5 changes: 2 additions & 3 deletions ACMC Library System/UI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@
</Rectangle>
<Rectangle Margin="478,7,0,0" Stroke="#FFC9C1C1" HorizontalAlignment="Left"
VerticalAlignment="Top" Width="1" Height="20" />
<Rectangle x:Name="IconMemberEditMode" Width="20" Height="20" Margin="484,7,0,0"
<Rectangle x:Name="IconMemberEditMode" Width="21" Height="21" Margin="484,7,0,0"
ToolTip="Edit Member" VerticalAlignment="Top" HorizontalAlignment="Left"
MouseLeftButtonUp="MemberEditModeIconClick"
Style="{StaticResource FunctionIconStyle}"
Expand Down Expand Up @@ -717,7 +717,7 @@
<TextBox x:Name="TbMemberBarcode" Height="25" Margin="1030,45,0,0" VerticalAlignment="Top"
metro:ControlsHelper.FocusBorderBrush="#55acee"
Text="{Binding SelectedMember.barcode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsEnabled="{Binding IsMemberEditMode, Mode=OneWay}"
IsReadOnly="{Binding IsMemberEditMode, Mode=OneWay, Converter={StaticResource InvertBool}}"
HorizontalAlignment="Left" Width="150" />
<TextBox x:Name="TbFirstNameCh" Height="25" Margin="745,80,0,0" VerticalAlignment="Top"
metro:ControlsHelper.FocusBorderBrush="#55acee"
Expand Down Expand Up @@ -1021,7 +1021,6 @@
Height="25" Margin="790,45,0,0"
Text="{Binding SelectedItem.barcode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsReadOnly="{Binding IsAddingNewItem, Mode=OneWay, Converter={StaticResource InvertBool}}"
IsEnabled="{Binding IsItemEditMode, Mode=OneWay}"
VerticalAlignment="Top" HorizontalAlignment="Left" Width="150" />
<TextBox x:Name="TbItemCode"
metro:ControlsHelper.FocusBorderBrush="#55acee"
Expand Down
Loading

0 comments on commit 63e1fef

Please sign in to comment.