Skip to content

Commit

Permalink
împort bookings improved
Browse files Browse the repository at this point in the history
- added third column mapping from CSV to booking text
- allowed to cut off parts from a mapped text in the CSV
  • Loading branch information
nylssoft committed Apr 26, 2018
1 parent cfb98f9 commit 1bf4671
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 67 deletions.
50 changes: 34 additions & 16 deletions Bank/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,16 @@ private void Init(SQLiteConnection con)
" datecolumn INTEGER NOT NULL," +
" text1column INTEGER NOT NULL," +
" text2column INTEGER NOT NULL," +
" text3column INTEGER NOT NULL," +
" amountcolumn INTEGER NOT NULL," +
" dateformat TEXT NOT NULL," +
" currencylanguage TEXT NOT NULL," +
" text1start TEXT NOT NULL," +
" text2start TEXT NOT NULL);";
" text1end TEXT NOT NULL," +
" text2start TEXT NOT NULL," +
" text2end TEXT NOT NULL," +
" text3start TEXT NOT NULL," +
" text3end TEXT NOT NULL);";
cmd.ExecuteNonQuery();
}
}
Expand Down Expand Up @@ -200,8 +205,9 @@ public ImportSetting GetImportSetting(Account account)
{
cmd.CommandText =
"SELECT rowid, encoding, separator, datecolumn, text1column,"+
" text2column, amountcolumn, dateformat, currencylanguage,"+
" text1start, text2start FROM importsetting WHERE accountid=@p1";
" text2column, text3column, amountcolumn, dateformat, currencylanguage,"+
" text1start, text1end, text2start, text2end, text3start, text3end" +
" FROM importsetting WHERE accountid=@p1";
cmd.Parameters.Add(new SQLiteParameter("@p1", account.Id));
using (var reader = cmd.ExecuteReader())
{
Expand All @@ -216,11 +222,16 @@ public ImportSetting GetImportSetting(Account account)
DateColumn = (int)reader.GetInt64(3),
Text1Column = (int)reader.GetInt64(4),
Text2Column = (int)reader.GetInt64(5),
AmountColumn = (int)reader.GetInt64(6),
DateFormat = reader.GetString(7),
CurrencyLanguage = reader.GetString(8),
Text1Start = reader.GetString(9),
Text2Start = reader.GetString(10)
Text3Column = (int)reader.GetInt64(6),
AmountColumn = (int)reader.GetInt64(7),
DateFormat = reader.GetString(8),
CurrencyLanguage = reader.GetString(9),
Text1Start = reader.GetString(10),
Text1End = reader.GetString(11),
Text2Start = reader.GetString(12),
Text2End = reader.GetString(13),
Text3Start = reader.GetString(14),
Text3End = reader.GetString(15)
};
}
}
Expand All @@ -236,7 +247,7 @@ public ImportSetting GetImportSetting(Account account)
using (var cmd = new SQLiteCommand(con))
{
cmd.CommandText = "INSERT INTO importsetting VALUES " +
"(@p1,'ISO-8859-1',';',-1,-1,-1,-1,@p2,@p3,'','')";
"(@p1,'ISO-8859-1',';',-1,-1,-1,-1,-1,@p2,@p3,'','','','','','')";
cmd.Parameters.Add(new SQLiteParameter("@p1", account.Id));
cmd.Parameters.Add(new SQLiteParameter("@p2", dateFormat));
cmd.Parameters.Add(new SQLiteParameter("@p3", currencyLanguage));
Expand All @@ -257,19 +268,26 @@ public void UpdateImportSetting(ImportSetting importSetting)
{
cmd.CommandText = "UPDATE importsetting SET"+
" encoding=@p2, separator=@p3, datecolumn=@p4," +
" text1column=@p5, text2column=@p6, amountcolumn=@p7, dateformat=@p8," +
" currencylanguage=@p9, text1start=@p10, text2start=@p11 WHERE accountid=@p1";
" text1column=@p5, text2column=@p6, text3column=@p7, amountcolumn=@p8, dateformat=@p9," +
" currencylanguage=@p10, text1start=@p11, text1end=@p12," +
" text2start=@p13, text2end=@p14, text3start=@p15, text3end=@p16" +
" WHERE accountid=@p1";
cmd.Parameters.Add(new SQLiteParameter("@p1", importSetting.Account.Id));
cmd.Parameters.Add(new SQLiteParameter("@p2", importSetting.Encoding));
cmd.Parameters.Add(new SQLiteParameter("@p3", importSetting.Separator));
cmd.Parameters.Add(new SQLiteParameter("@p4", importSetting.DateColumn));
cmd.Parameters.Add(new SQLiteParameter("@p5", importSetting.Text1Column));
cmd.Parameters.Add(new SQLiteParameter("@p6", importSetting.Text2Column));
cmd.Parameters.Add(new SQLiteParameter("@p7", importSetting.AmountColumn));
cmd.Parameters.Add(new SQLiteParameter("@p8", importSetting.DateFormat));
cmd.Parameters.Add(new SQLiteParameter("@p9", importSetting.CurrencyLanguage));
cmd.Parameters.Add(new SQLiteParameter("@p10", importSetting.Text1Start));
cmd.Parameters.Add(new SQLiteParameter("@p11", importSetting.Text2Start));
cmd.Parameters.Add(new SQLiteParameter("@p7", importSetting.Text3Column));
cmd.Parameters.Add(new SQLiteParameter("@p8", importSetting.AmountColumn));
cmd.Parameters.Add(new SQLiteParameter("@p9", importSetting.DateFormat));
cmd.Parameters.Add(new SQLiteParameter("@p10", importSetting.CurrencyLanguage));
cmd.Parameters.Add(new SQLiteParameter("@p11", importSetting.Text1Start));
cmd.Parameters.Add(new SQLiteParameter("@p12", importSetting.Text1End));
cmd.Parameters.Add(new SQLiteParameter("@p13", importSetting.Text2Start));
cmd.Parameters.Add(new SQLiteParameter("@p14", importSetting.Text2End));
cmd.Parameters.Add(new SQLiteParameter("@p15", importSetting.Text3Start));
cmd.Parameters.Add(new SQLiteParameter("@p16", importSetting.Text3End));
cmd.ExecuteNonQuery();
}
}
Expand Down
10 changes: 10 additions & 0 deletions Bank/ImportSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class ImportSetting

public int Text2Column { get; set; } = -1;

public int Text3Column { get; set; } = -1;

public int AmountColumn { get; set; } = -1;

public string DateFormat { get; set; } = "dd.MM.yyyy";
Expand All @@ -41,6 +43,14 @@ public class ImportSetting

public string Text1Start { get; set; } = "";

public string Text1End { get; set; } = "";

public string Text2Start { get; set; } = "";

public string Text2End { get; set; } = "";

public string Text3Start { get; set; } = "";

public string Text3End { get; set; } = "";
}
}
25 changes: 19 additions & 6 deletions Bank/ImportWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,42 @@
<RowDefinition Height="30" />
<RowDefinition Height="30" />
<RowDefinition Height="30" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="250"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Content="{x:Static props:Resources.LABEL_MAP_COLUMN_DATE}" Target="{Binding ElementName=comboBoxColumnDate}"/>
<ComboBox Grid.Row="0" x:Name="comboBoxColumnDate" Grid.Column="1" Height="23" SelectionChanged="Page2SelectionChanged"/>
<Label Grid.Row="0" Grid.Column="2" Content="{x:Static props:Resources.LABEL_DATE_FORMAT}" Target="{Binding ElementName=textBoxDateFormat}"/>
<TextBox Grid.Row="0" Grid.Column="3" Height="23" Text="dd.MM.yyyy" Width="80" HorizontalAlignment="Left" MaxLength="10" x:Name="textBoxDateFormat" LostFocus="Page2TextBox_LostFocus"/>
<Label Grid.Row="1" Grid.Column="0" Content="{x:Static props:Resources.LABEL_MAP_COLUMN_TEXT_1}" Target="{Binding ElementName=comboBoxColumnText1}"/>
<ComboBox Grid.Row="1" x:Name="comboBoxColumnText1" Grid.Column="1" Height="23" SelectionChanged="Page2SelectionChanged"/>
<Label Grid.Row="1" Grid.Column="2" Content="{x:Static props:Resources.LABEL_TEXT_1_STARTS_AFTER}" Target="{Binding ElementName=textBoxText1Start}"/>
<Label Grid.Row="1" Grid.Column="2" Content="{x:Static props:Resources.LABEL_STARTS_AFTER}" Target="{Binding ElementName=textBoxText1Start}"/>
<TextBox Grid.Row="1" Grid.Column="3" Height="23" x:Name="textBoxText1Start" MaxLength="100" LostFocus="Page2TextBox_LostFocus"/>
<Label Grid.Row="1" Grid.Column="4" Content="{x:Static props:Resources.LABEL_ENDS_BEFORE}" Target="{Binding ElementName=textBoxText1Start}"/>
<TextBox Grid.Row="1" Grid.Column="5" Height="23" x:Name="textBoxText1End" MaxLength="100" LostFocus="Page2TextBox_LostFocus"/>
<Label Grid.Row="2" Grid.Column="0" Content="{x:Static props:Resources.LABEL_MAP_COLUMN_TEXT_2}" Target="{Binding ElementName=comboBoxColumnText2}"/>
<ComboBox Grid.Row="2" x:Name="comboBoxColumnText2" Grid.Column="1" Height="23" SelectionChanged="Page2SelectionChanged"/>
<Label Grid.Row="2" Grid.Column="2" Content="{x:Static props:Resources.LABEL_TEXT_2_STARTS_AFTER}" Target="{Binding ElementName=textBoxText2Start}"/>
<Label Grid.Row="2" Grid.Column="2" Content="{x:Static props:Resources.LABEL_STARTS_AFTER}" Target="{Binding ElementName=textBoxText2Start}"/>
<TextBox Grid.Row="2" Grid.Column="3" Height="23" x:Name="textBoxText2Start" MaxLength="100" LostFocus="Page2TextBox_LostFocus"/>
<Label Grid.Row="3" Grid.Column="0" Content="{x:Static props:Resources.LABEL_MAP_COLUMN_AMOUNT}" Target="{Binding ElementName=comboBoxColumnAmount}"/>
<ComboBox Grid.Row="3" x:Name="comboBoxColumnAmount" Grid.Column="1" Height="23" SelectionChanged="Page2SelectionChanged"/>
<Label Grid.Row="3" Grid.Column="2" Content="{x:Static props:Resources.LABEL_CURRENCY_LANGUAGE}" Target="{Binding ElementName=textBoxLanguage}"/>
<TextBox Grid.Row="3" Grid.Column="3" Height="21" Text="de" Width="30" HorizontalAlignment="Left" MaxLength="2" x:Name="textBoxLanguage" LostFocus="Page2TextBox_LostFocus"/>
<Label Grid.Row="2" Grid.Column="4" Content="{x:Static props:Resources.LABEL_ENDS_BEFORE}" Target="{Binding ElementName=textBoxText2Start}"/>
<TextBox Grid.Row="2" Grid.Column="5" Height="23" x:Name="textBoxText2End" MaxLength="100" LostFocus="Page2TextBox_LostFocus"/>
<Label Grid.Row="3" Grid.Column="0" Content="{x:Static props:Resources.LABEL_MAP_COLUMN_TEXT_3}" Target="{Binding ElementName=comboBoxColumnText2}"/>
<ComboBox Grid.Row="3" x:Name="comboBoxColumnText3" Grid.Column="1" Height="23" SelectionChanged="Page2SelectionChanged"/>
<Label Grid.Row="3" Grid.Column="2" Content="{x:Static props:Resources.LABEL_STARTS_AFTER}" Target="{Binding ElementName=textBoxText2Start}"/>
<TextBox Grid.Row="3" Grid.Column="3" Height="23" x:Name="textBoxText3Start" MaxLength="100" LostFocus="Page2TextBox_LostFocus"/>
<Label Grid.Row="3" Grid.Column="4" Content="{x:Static props:Resources.LABEL_ENDS_BEFORE}" Target="{Binding ElementName=textBoxText2Start}"/>
<TextBox Grid.Row="3" Grid.Column="5" Height="23" x:Name="textBoxText3End" MaxLength="100" LostFocus="Page2TextBox_LostFocus"/>
<Label Grid.Row="4" Grid.Column="0" Content="{x:Static props:Resources.LABEL_MAP_COLUMN_AMOUNT}" Target="{Binding ElementName=comboBoxColumnAmount}"/>
<ComboBox Grid.Row="4" x:Name="comboBoxColumnAmount" Grid.Column="1" Height="23" SelectionChanged="Page2SelectionChanged"/>
<Label Grid.Row="4" Grid.Column="2" Content="{x:Static props:Resources.LABEL_CURRENCY_LANGUAGE}" Target="{Binding ElementName=textBoxLanguage}"/>
<TextBox Grid.Row="4" Grid.Column="3" Height="21" Text="de" Width="30" HorizontalAlignment="Left" MaxLength="2" x:Name="textBoxLanguage" LostFocus="Page2TextBox_LostFocus"/>
</Grid>
</Grid>
<Grid Grid.Row="0" x:Name="gridWizard3" Visibility="Hidden">
Expand Down
64 changes: 52 additions & 12 deletions Bank/ImportWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ public ImportWindow(Window owner, string title, string csvFile, ImportSetting se
textBoxDateFormat.Text = Setting.DateFormat;
textBoxSeparator.Text = Setting.Separator;
textBoxText1Start.Text = Setting.Text1Start;
textBoxText1End.Text = Setting.Text1End;
textBoxText2Start.Text = Setting.Text2Start;
textBoxText2End.Text = Setting.Text2End;
textBoxText3Start.Text = Setting.Text3Start;
textBoxText3End.Text = Setting.Text3End;
ReadLines();
ShowPage();
}
Expand Down Expand Up @@ -132,6 +136,8 @@ private bool InitColumnMapping()
comboBoxColumnText1.Items.Clear();
comboBoxColumnText2.Items.Clear();
comboBoxColumnText2.Items.Add(string.Empty);
comboBoxColumnText3.Items.Clear();
comboBoxColumnText3.Items.Add(string.Empty);
comboBoxColumnAmount.Items.Clear();
result.Clear();
int idx = listViewImport.SelectedIndex;
Expand All @@ -152,6 +158,7 @@ private bool InitColumnMapping()
comboBoxColumnDate.Items.Add(new ComboBoxItem() { Content = s, Tag = gridrow });
comboBoxColumnText1.Items.Add(new ComboBoxItem() { Content = s, Tag = gridrow });
comboBoxColumnText2.Items.Add(new ComboBoxItem() { Content = s, Tag = gridrow });
comboBoxColumnText3.Items.Add(new ComboBoxItem() { Content = s, Tag = gridrow });
comboBoxColumnAmount.Items.Add(new ComboBoxItem() { Content = s, Tag = gridrow });
gridrow++;
}
Expand All @@ -167,6 +174,10 @@ private bool InitColumnMapping()
{
comboBoxColumnText2.SelectedIndex = Setting.Text2Column;
}
if (Setting.Text3Column >= 0 && Setting.Text3Column < cols.Length)
{
comboBoxColumnText3.SelectedIndex = Setting.Text3Column;
}
if (Setting.AmountColumn >= 0 && Setting.AmountColumn < cols.Length)
{
comboBoxColumnAmount.SelectedIndex = Setting.AmountColumn;
Expand All @@ -190,6 +201,7 @@ private bool InitPreview()
var itemdate = comboBoxColumnDate.SelectedItem as ComboBoxItem;
var itemtext1 = comboBoxColumnText1.SelectedItem as ComboBoxItem;
var itemtext2 = comboBoxColumnText2.SelectedItem as ComboBoxItem;
var itemtext3 = comboBoxColumnText3.SelectedItem as ComboBoxItem;
var itemamount = comboBoxColumnAmount.SelectedItem as ComboBoxItem;
if (itemdate != null && itemtext1 != null && itemamount != null)
{
Expand All @@ -199,6 +211,11 @@ private bool InitPreview()
{
idxtext2 = itemtext2.Tag as int?;
}
int? idxtext3 = null;
if (itemtext3 != null)
{
idxtext3 = itemtext3.Tag as int?;
}
var idxtext1 = itemtext1.Tag as int?;
var idxamount = itemamount.Tag as int?;
result.Clear();
Expand All @@ -208,32 +225,29 @@ private bool InitPreview()
var cols = Split(str, delim);
var dt = DateTime.ParseExact(cols[idxdate.Value], textBoxDateFormat.Text, CultureInfo.InvariantCulture);
long currency = (long)(Decimal.Parse(cols[idxamount.Value], NumberStyles.Currency, ci) * 100);

var b = new ImportBooking()
{
Date = dt,
Amount = currency,
Text = cols[idxtext1.Value].Trim(),
AmountString = CurrencyConverter.ConvertToCurrencyString(currency),
DateString = $"{dt:d}"
};
if (textBoxText1Start.Text.Length > 0)
b.Text = Cut(cols[idxtext1.Value].Trim(), textBoxText1Start.Text.Trim(), textBoxText1End.Text.Trim());
if (idxtext2.HasValue)
{
var idx1 = b.Text.IndexOf(textBoxText1Start.Text);
if (idx1 >= 0)
var text2 = Cut(cols[idxtext2.Value].Trim(), textBoxText2Start.Text.Trim(), textBoxText2End.Text.Trim());
if (text2.Length > 0)
{
b.Text = b.Text.Substring(idx1 + textBoxText1Start.Text.Length).Trim();
b.Text += $", {text2}";
}
}
if (idxtext2.HasValue)
if (idxtext3.HasValue)
{
var text2 = cols[idxtext2.Value].Trim();
var idx2 = text2.IndexOf(textBoxText2Start.Text);
if (idx2 >= 0)
var text3 = Cut(cols[idxtext3.Value].Trim(), textBoxText3Start.Text.Trim(), textBoxText3End.Text.Trim());
if (text3.Length > 0)
{
text2 = text2.Substring(idx2 + textBoxText2Start.Text.Length).Trim();
b.Text += $", {text3}";
}
b.Text += $" {text2}";
}
result.Add(b);
}
Expand All @@ -255,6 +269,27 @@ private bool InitPreview()
return true;
}

private string Cut(string txt, string startpat, string endpat)
{
if (startpat.Length > 0)
{
var idx = txt.IndexOf(startpat);
if (idx >= 0)
{
txt = txt.Substring(idx + startpat.Length).Trim();
}
}
if (endpat.Length > 0)
{
var idx = txt.IndexOf(endpat);
if (idx >= 0)
{
txt = txt.Substring(0, idx).Trim();
}
}
return txt;
}

private void Page1SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (init) return;
Expand Down Expand Up @@ -351,9 +386,14 @@ private void ButtonFinish_Click(object sender, RoutedEventArgs e)
Setting.DateColumn = comboBoxColumnDate.SelectedIndex;
Setting.Text1Column = comboBoxColumnText1.SelectedIndex;
Setting.Text2Column = comboBoxColumnText2.SelectedIndex;
Setting.Text3Column = comboBoxColumnText3.SelectedIndex;
Setting.AmountColumn = comboBoxColumnAmount.SelectedIndex;
Setting.Text1Start = textBoxText1Start.Text;
Setting.Text1End = textBoxText1End.Text;
Setting.Text2Start = textBoxText2Start.Text;
Setting.Text2End = textBoxText2End.Text;
Setting.Text3Start = textBoxText3Start.Text;
Setting.Text3End = textBoxText3End.Text;
DialogResult = true;
Close();
}
Expand Down
Loading

0 comments on commit 1bf4671

Please sign in to comment.