Skip to content

Commit

Permalink
Refactor using ViewModel and add today check box
Browse files Browse the repository at this point in the history
  • Loading branch information
woin2ee committed Jul 18, 2024
1 parent 7be745e commit ccc594c
Show file tree
Hide file tree
Showing 6 changed files with 406 additions and 119 deletions.
60 changes: 47 additions & 13 deletions MemoGenerator/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,70 @@
</StackPanel>
</StackPanel>

<StackPanel Margin="0,-10,0,0" Orientation="Vertical">
<StackPanel x:Name="paymentProofStackPanel" Margin="0,-10,0,0" Orientation="Vertical">
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
<TextBlock Margin="10,0,0,0" VerticalAlignment="Center" FontWeight="Bold" Text="결제 증빙" />
<RadioButtons x:Name="paymentProofTypeRadioButton" Margin="40,0,0,0" MaxColumns="2" SelectedIndex="0" SelectionChanged="updatePaymentProofMethodComponent">
<RadioButtons x:Name="paymentProofTypeRadioButton" Margin="40,0,0,0" MaxColumns="2"
SelectedIndex="{Binding SelectedPaymentProofTypeIndex, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
SelectionChanged="updatePaymentProofMethodComponent">
<RadioButton Margin="0,0,-46,0" Padding="6">계산서</RadioButton>
<RadioButton Margin="0,0,-46,0" Padding="6">카드</RadioButton>
</RadioButtons>
</StackPanel>
<StackPanel Padding="10" HorizontalAlignment="Center" VerticalAlignment="Top" Background="#F6F6F6" BorderBrush="DarkGray"
BorderThickness="1" CornerRadius="10" Orientation="Vertical">
<StackPanel x:Name="invoicePanel">
<TextBox x:Name="invoiceDateTextBox" Width="110" Margin="4" HorizontalAlignment="Left" Header="발행일자"
PlaceholderForeground="LightGray" PlaceholderText="0619" TextChanged="updatePaymentProofMethodComponent" />
<TextBlock x:Name="invoiceDateErrorTextBox" Margin="4" FontSize="11" Foreground="Red" Text="발행일자 오류" />
<StackPanel VerticalAlignment="Center" Orientation="Horizontal">
<TextBox x:Name="invoiceDateTextBox" Width="110" Margin="4" HorizontalAlignment="Left" Header="발행일자"
IsEnabled="{Binding EnableInvoice}"
PlaceholderForeground="LightGray" PlaceholderText="0619"
Text="{Binding InvoiceInfo.Date, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
TextChanged="updatePaymentProofMethodComponent" />
<CheckBox x:Name="invoiceDateTodayCheckbox" Margin="8,26,0,0" Click="updatePaymentProofMethodComponent" Content="금일"
IsChecked="{Binding InvoiceInfo.IsToday, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
IsEnabled="{Binding EnableInvoice}" />
</StackPanel>
<TextBlock x:Name="invoiceDateErrorTextBox" Margin="4" FontSize="11" Foreground="Red" Text="발행일자 오류"
Visibility="{Binding InvoiceInfo.IsVisibleDateError}" />
<StackPanel Padding="0,10,0,10" Orientation="Vertical">
<CheckBox x:Name="taxInvoiceCheckBox" Click="updatePaymentProofMethodComponent" Content="계산서" />
<RadioButtons x:Name="invoiceTypeRadioButtons" Margin="10,-2,-10,0" MaxColumns="2" SelectedIndex="0" SelectionChanged="updatePaymentProofMethodComponent">
<CheckBox x:Name="taxInvoiceCheckBox" Click="updatePaymentProofMethodComponent" Content="계산서"
IsChecked="{Binding InvoiceInfo.IncludesInvoice, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
IsEnabled="{Binding EnableInvoice}" />
<RadioButtons x:Name="invoiceTypeRadioButtons" Margin="10,-2,-10,0"
IsEnabled="{Binding EnableInvoiceTypeRadioButtons}"
MaxColumns="2"
SelectedIndex="{Binding InvoiceInfo.SelectedInvoiceTypeIndex, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
SelectionChanged="updatePaymentProofMethodComponent">
<x:String>세금계산서</x:String>
<x:String>면세계산서</x:String>
</RadioButtons>
</StackPanel>
<CheckBox x:Name="transactionStatementCheckBox" Click="updatePaymentProofMethodComponent" Content="거래명세서" />
<TextBlock Margin="10" FontWeight="Bold" Text="사업자" />
<CheckBox x:Name="companyCheckBox" Click="updatePaymentProofMethodComponent" Content="대미기프트" />
<CheckBox x:Name="transactionStatementCheckBox" Click="updatePaymentProofMethodComponent" Content="거래명세서"
IsChecked="{Binding InvoiceInfo.IncludesTransactionSpecification, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
IsEnabled="{Binding EnableInvoice}" />
<TextBlock Margin="10" FontWeight="Bold"
Foreground="{Binding InvoiceHeaderColor}"
Text="사업자" />
<ComboBox x:Name="companyCheckBox"
IsEnabled="{Binding EnableInvoice}"
SelectedIndex="{Binding InvoiceInfo.SelectedBusinessIndex, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
SelectionChanged="updatePaymentProofMethodComponent">
<ComboBoxItem>미지정</ComboBoxItem>
<ComboBoxItem>일이삼사</ComboBoxItem>
<ComboBoxItem>대미기프트</ComboBoxItem>
</ComboBox>
</StackPanel>
<Frame Height="2" Margin="0,12,0,0" Background="DarkGray" />
<StackPanel x:Name="cardPanel">
<RadioButtons x:Name="cardRadioButtons" Margin="0,4,0,0" MaxColumns="1" SelectedIndex="0" SelectionChanged="updatePaymentProofMethodComponent">
<x:String>비씨카드 결제</x:String>
<x:String>나이스페이 결제</x:String>
<RadioButtons x:Name="cardRadioButtons" Margin="0,4,0,0"
IsEnabled="{Binding EnableCard}"
MaxColumns="1"
SelectedIndex="{Binding CardInfo.SelectedCardTypeIndex, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
SelectionChanged="updatePaymentProofMethodComponent">
<RadioButtons.Items>
<x:String>비씨카드 결제</x:String>
<x:String>나이스페이 결제</x:String>
</RadioButtons.Items>
</RadioButtons>
</StackPanel>
</StackPanel>
Expand Down
110 changes: 4 additions & 106 deletions MemoGenerator/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using MemoGenerator.Model.MemoGenerating;
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
Expand Down Expand Up @@ -36,6 +37,7 @@ public sealed partial class MainWindow : Window
private string emailComponent = "";

private TaxCalculatingModel taxCalculatingModel = new TaxCalculatingModel();
private PaymentProofModel paymentProofModel = new PaymentProofModel();

public MainWindow()
{
Expand Down Expand Up @@ -65,6 +67,7 @@ public MainWindow()
this.AppWindow.SetIcon("C:\\Users\\y\\Desktop\\Visual Studio\\Projects\\MemoGenerator\\MemoGenerator\\Assets\\default-icon.ico");

taxCalculatorPanel.DataContext = taxCalculatingModel;
paymentProofStackPanel.DataContext = paymentProofModel;

disableDeductionGroup();
}
Expand Down Expand Up @@ -151,115 +154,10 @@ private void updatePaymentProofMethodComponent(object sender, RoutedEventArgs e)
// 함께사는 세상 옵션 추가
// 분할 발행 기능

List<Control> invoicePanelControls = new List<Control>();
List<Control> cardPanelControls = new List<Control>();

retrieveAllChildControls(invoicePanel, invoicePanelControls);
retrieveAllChildControls(cardPanel, cardPanelControls);

switch (paymentProofTypeRadioButton.SelectedIndex)
{
case 0:
foreach (var control in invoicePanelControls) { control.IsEnabled = true; }
foreach (var control in cardPanelControls) { control.IsEnabled = false; }
updatePaymentProofMethodComponentForInvoice();
break;
case 1:
foreach (var control in invoicePanelControls) { control.IsEnabled = false; }
foreach (var control in cardPanelControls) { control.IsEnabled = true; }
updatePaymentProofMethodComponentForCard();
break;
}

paymentProofMethodComponent = paymentProofModel.memoComponent;
updateMemoTextBlock();
}

private void updatePaymentProofMethodComponentForInvoice()
{
invoiceDateErrorTextBox.Visibility = Visibility.Collapsed;
List<String> elements = new List<string>();

if (DateTime.TryParseExact(invoiceDateTextBox.Text, "MMdd", null, System.Globalization.DateTimeStyles.None, out var date))
{
elements.Add($"{date.ToString("MM'/'dd")}일자");
}
else if (!String.IsNullOrEmpty(invoiceDateTextBox.Text))
{
invoiceDateErrorTextBox.Visibility = Visibility.Visible;
}

if (companyCheckBox.IsChecked == true)
{
elements.Add("대미");
}

if (taxInvoiceCheckBox.IsChecked == true && transactionStatementCheckBox.IsChecked == true)
{
invoiceTypeRadioButtons.IsEnabled = true;
switch (invoiceTypeRadioButtons.SelectedIndex)
{
case 0:
elements.Add("세금계산서/명세서");
break;
case 1:
elements.Add("면세계산서/명세서");
break;
}
}
else if (taxInvoiceCheckBox.IsChecked == true)
{
invoiceTypeRadioButtons.IsEnabled = true;
switch (invoiceTypeRadioButtons.SelectedIndex)
{
case 0:
elements.Add("세금계산서");
break;
case 1:
elements.Add("면세계산서");
break;
}
}
else if (transactionStatementCheckBox.IsChecked == true)
{
invoiceTypeRadioButtons.IsEnabled = false;
elements.Add("명세서");
}
else
{
invoiceTypeRadioButtons.IsEnabled = false;
elements.Clear();
}

if (elements.Count > 0)
{
elements.Add("발행");
}

paymentProofMethodComponent = String.Join(" ", elements);
}

private void updatePaymentProofMethodComponentForCard()
{
List<String> elements = new List<string>();

switch (cardRadioButtons.SelectedIndex)
{
case 0:
elements.Add("비씨카드");
break;
case 1:
elements.Add("나이스페이");
break;
}

if (elements.Count > 0)
{
elements.Add("결제");
}

paymentProofMethodComponent = String.Join(" ", elements);
}

private void updateDocumentsDeliveryRouteComponent(object sender, RoutedEventArgs e)
{
List<String> elements = new List<string>();
Expand Down
33 changes: 33 additions & 0 deletions MemoGenerator/Model/BusinessInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MemoGenerator.Model
{
#nullable enable

class BusinessInfo
{
internal BusinessInfo(string name, string? memoText)
{
this.name = name;
this.memoText = memoText;
}

string name;
internal string? memoText;

internal static List<BusinessInfo> defaults()
{
return new List<BusinessInfo>(new BusinessInfo[] {
new BusinessInfo("미지정", null),
new BusinessInfo("일이삼사", null),
new BusinessInfo("대미기프트", "대미"),
});
}
}

#nullable disable
}
24 changes: 24 additions & 0 deletions MemoGenerator/Model/GlobalSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MemoGenerator.Model
{
class GlobalSettings
{
private static readonly Lazy<GlobalSettings> lazyInstance = new Lazy<GlobalSettings>(() => new GlobalSettings());

public static GlobalSettings Instance
{
get => lazyInstance.Value;
}

private GlobalSettings() {
businessInfos = BusinessInfo.defaults();
}

internal List<BusinessInfo> businessInfos;
}
}
Loading

0 comments on commit ccc594c

Please sign in to comment.