public static void SaveTransaction(TicketTransaction ticketTransaction) { string path = Path.Combine(assemblyPath, @"Transactions.csv"); //Create colum header first time if (File.Exists(path) == false) { File.AppendAllText(path, @"Datum;Biljett typ; Pris; Antal" + Environment.NewLine, System.Text.Encoding.GetEncoding(1252)); } File.AppendAllText(path, ticketTransaction + Environment.NewLine, System.Text.Encoding.GetEncoding(1252)); }
private void SaveTransaction(bool refund) { var items = TicketsListView.Items; foreach (ListViewItem item in items) { //Don't save zero tickets for a tickettype if (item.SubItems[2].Text != "0") { var ticketTransaction = new TicketTransaction(); ticketTransaction.TicketType = item.Tag as TicketType; ticketTransaction.TransactionType = refund; if (Int32.TryParse(item.SubItems[2].Text, out int numberOfTickets)) { ticketTransaction.NumberOfTickets = numberOfTickets; } if (refund) { numberOfTicketsSold -= numberOfTickets; } else { numberOfTicketsSold += numberOfTickets; } ticketTransaction.TransactionDate = DateTime.Now.Date; FileHandler.SaveTransaction(ticketTransaction); } } ClearListView(); }