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

Commit 7b7ee93

Browse files
author
Alexander Fuks
committed
Fix default dates bindings
1 parent 1fb5f43 commit 7b7ee93

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

BusinessAccounting/BusinessAccounting/UserControls/CashPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
</Grid.ColumnDefinitions>
101101

102102
<Label Grid.Row="0" Content="Дата" VerticalContentAlignment="Center" HorizontalContentAlignment="Right" />
103-
<DatePicker Grid.Row="0" Grid.Column="1" controls:TextboxHelper.Watermark="Выберите дату" FirstDayOfWeek="Monday" Name="InputDate" SelectedDateFormat="Long" SelectedDate="{Binding DefaultInputDate, Mode=OneWay, TargetNullValue={x:Static system:DateTime.Now}}"/>
103+
<DatePicker Grid.Row="0" Grid.Column="1" controls:TextboxHelper.Watermark="Выберите дату" FirstDayOfWeek="Monday" Name="InputDate" SelectedDateFormat="Long" SelectedDate="{Binding DefaultInputDate, Mode=OneWay}"/>
104104

105105
<Label Grid.Row="1" Grid.Column="0" Content="Сумма" VerticalContentAlignment="Center" HorizontalContentAlignment="Right" />
106106
<TextBox Grid.Row="1" Grid.Column="1" controls:TextboxHelper.Watermark="Введите сумму" controls:TextboxHelper.ClearTextButton="True" Name="InputSum"/>

BusinessAccounting/BusinessAccounting/UserControls/CashPage.xaml.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@
55
using System.Configuration;
66
using System.Data;
77
using System.Threading.Tasks;
8-
using System.Windows;
9-
using System.Windows.Controls;
10-
using System.Windows.Forms;
118
using System.Windows.Input;
129
using System.Windows.Media;
13-
using System.Windows.Threading;
1410
using XDatabase;
1511
using XDatabase.Core;
1612

@@ -25,12 +21,14 @@ public CashPage()
2521
{
2622
InitializeComponent();
2723

24+
InputDate.DataContext = this;
25+
2826
LoadDefaultDate();
2927
LoadHistory();
3028
LoadEmployees();
3129
}
3230

33-
public DateTime DefaultInputDate { get; set; }
31+
public DateTime? DefaultInputDate { get; set; }
3432

3533
public static RoutedCommand SaveRecordCommand = new RoutedCommand();
3634
public static RoutedCommand LoadHistoryCommand = new RoutedCommand();
@@ -83,7 +81,7 @@ private void LoadEmployees()
8381
{
8482
foreach (DataRow r in employeesData.Rows)
8583
{
86-
_employees.Add(new Employee()
84+
_employees.Add(new Employee
8785
{
8886
Id = Convert.ToInt32(r.ItemArray[0]),
8987
FullName = r.ItemArray[1].ToString()
@@ -139,7 +137,7 @@ private void SaveRecord()
139137

140138
if (result)
141139
{
142-
InputDate.SelectedDate = DefaultInputDate != DateTime.MinValue ? DefaultInputDate : (DateTime?)null;
140+
InputDate.SelectedDate = DefaultInputDate;
143141
InputSum.Text = "";
144142
InputComment.Text = "";
145143
ComboEmployee.SelectedIndex = -1;
@@ -192,7 +190,6 @@ private void LoadDefaultDate()
192190
int offset;
193191
if (!int.TryParse(ConfigurationManager.AppSettings["DefaultInputDateOffset"], out offset)) return;
194192
DefaultInputDate = DateTime.Now.Date.AddDays(offset);
195-
InputDate.DataContext = this;
196193
}
197194
#endregion
198195

BusinessAccounting/BusinessAccounting/UserControls/GraphicsPage.xaml.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public GraphicsPage()
2525
LoadDefaultDates();
2626
}
2727

28-
public DateTime DefaultStartDate { get; set; }
29-
public DateTime DefaultEndDate { get; set; }
28+
public DateTime? DefaultStartDate { get; set; }
29+
public DateTime? DefaultEndDate { get; set; }
3030

3131
public static readonly RoutedCommand PrintChartCommand = new RoutedCommand();
3232
public static readonly RoutedCommand SaveChartCommand = new RoutedCommand();
@@ -38,10 +38,14 @@ private void LoadDefaultDates()
3838
{
3939
int startOffset;
4040
int endOffset;
41-
if (!int.TryParse(ConfigurationManager.AppSettings["DefaultStartDateOffset"], out startOffset)) return;
42-
if (!int.TryParse(ConfigurationManager.AppSettings["DefaultEndDateOffset"], out endOffset)) return;
43-
DefaultStartDate = DateTime.Now.Date.AddDays(startOffset);
44-
DefaultEndDate = DateTime.Now.Date.AddDays(endOffset);
41+
if (int.TryParse(ConfigurationManager.AppSettings["DefaultStartDateOffset"], out startOffset))
42+
{
43+
DefaultStartDate = DateTime.Now.Date.AddDays(startOffset);
44+
}
45+
if (int.TryParse(ConfigurationManager.AppSettings["DefaultEndDateOffset"], out endOffset))
46+
{
47+
DefaultEndDate = DateTime.Now.Date.AddDays(endOffset);
48+
}
4549
}
4650

4751
#region Charts

0 commit comments

Comments
 (0)