Skip to content

Commit

Permalink
add first row to export and use abbreviation from config
Browse files Browse the repository at this point in the history
  • Loading branch information
zefanjajobse committed Jun 18, 2024
1 parent 41c6a0e commit c496f58
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
4 changes: 2 additions & 2 deletions PlanningCenter to OPS/Actions/DrawFormItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private void ComboBoxOnClose(object sender, EventArgs e)
ToolTip.Hide(ComboBox);
}

public void Render(Form f)
public void Render(Form f, Config config)
{
Label.Text = SongInfo.attributes.title;
Label.TooltipText = "test";
Expand All @@ -100,7 +100,7 @@ public void Render(Form f)
{
ComboBox.Items.Add($"et {song.id} - {song.name}");
FoundSongs.Add($"et {song.id} - {song.name}", song);
SongTooltipInfo.Add($"et {song.id} - {song.name}", $"et{song.id}");
SongTooltipInfo.Add($"et {song.id} - {song.name}", $"{config.et_abbreviation}{song.id}");
};
ComboBox.Items.Add("Planning center");
ComboBox.SelectedIndex = 0;
Expand Down
26 changes: 19 additions & 7 deletions PlanningCenter to OPS/Actions/ReadOpsDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ internal class ReadOpsDb
private static string SqlConnectionString = "Data Source=C:\\ProgramData\\Stichting Opwekking\\OPS 8\\songs.search.sqlite";
//private static string SqlConnectionString = "Data Source=C:\\Users\\zjobse\\Downloads\\songs.search.sqlite";

public ReadOpsDb()
public ReadOpsDb(bool add_first_line = false)
{
using (var connection = new SqliteConnection(SqlConnectionString))
{
connection.Open();

var command = connection.CreateCommand();
command.CommandText =
@"
SELECT title
FROM song_index
";
if (add_first_line)
{
command.CommandText = @"SELECT title, first_line FROM song_index";
} else
{
command.CommandText = @"SELECT title FROM song_index";
}
IDictionary<string, List<Song>> song_lists = new Dictionary<string, List<Song>>();
using (var reader = command.ExecuteReader())
{
Expand All @@ -42,7 +44,15 @@ FROM song_index
song_lists.Add(last_item, new List<Structs.Song>());
}
string song_name = string.Join(" ", unparsed_current_song.Skip(1).ToArray().SkipLast(last_item.Length));
song_lists[last_item].Add(new Structs.Song(song_number, song_name));

if (add_first_line) {
string[] unparsed_first_line = reader.GetString(1).Split(' ');
string first_line = string.Join(" ", unparsed_first_line.Skip(1).ToArray().SkipLast(last_item.Length));
song_lists[last_item].Add(new Structs.Song(song_number, song_name, first_line));
} else
{
song_lists[last_item].Add(new Structs.Song(song_number, song_name, ""));
}
}
}
this.books = song_lists;
Expand Down Expand Up @@ -84,10 +94,12 @@ public void Export()
IXLWorksheet worksheet = workbook.Worksheets.Add(entry.Key);
worksheet.Cell(1, 1).Value = "Liednummer";
worksheet.Cell(1, 2).Value = "Titel";
worksheet.Cell(1, 3).Value = "Eerste regel";
for (int i = 1; i < entry.Value.Count; i++)
{
worksheet.Cell(i + 1, 1).Value = entry.Value[i].id;
worksheet.Cell(i + 1, 2).Value = entry.Value[i].name;
worksheet.Cell(i + 1, 3).Value = entry.Value[i].first_line;
}
}

Expand Down
2 changes: 1 addition & 1 deletion PlanningCenter to OPS/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private void button1_Click(object sender, EventArgs e)

private void ReadSongs_Click(object sender, EventArgs e)
{
ReadOpsDb db_reader = new ReadOpsDb();
ReadOpsDb db_reader = new ReadOpsDb(true);
db_reader.Export();
}

Expand Down
2 changes: 1 addition & 1 deletion PlanningCenter to OPS/SelectSongs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private void SelectSongs_Load(object sender, EventArgs e)
{
song_element = new DrawFormItems(this.Config, x, "", "");
}
song_element.Render(this);
song_element.Render(this, this.Config);
this.SongDropdowns.Add(song_element);
} else
{
Expand Down
4 changes: 3 additions & 1 deletion PlanningCenter to OPS/Structs/OpsSongs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ internal class Song
{
public int id { get; set; }
public string name { get; set; }
public string first_line { get; set; }

public Song (int id, string name)
public Song (int id, string name, string first_line)
{
this.id = id;
this.name = name;
this.first_line = first_line;
}
}

Expand Down

0 comments on commit c496f58

Please sign in to comment.