private void btnUpdateRaceResult_Click(object sender, EventArgs e) { if (lstDisplayUpdateView.SelectedIndex >= 0) { if (InputValidation()) { RaceResultsModel updateRecord = (RaceResultsModel)lstDisplayUpdateView.SelectedItem; updateRecord.RaceCourse = cboRaceCourse.Text; updateRecord.RaceDate = DateTime.Parse(dtpRaceDate.Text); updateRecord.Amount = decimal.Parse(txtAmount.Text); updateRecord.Result = cboResult.Text; savedData = dataUpdates.UpdateRecord(updateRecord, raceResultsfile); lstDisplayUpdateView.Items.Clear(); foreach (var item in savedData) { lstDisplayUpdateView.Items.Add(item); } btnAddNewRace.Enabled = true; ResetInputBoxes(); lblDisplay.Text = "record updated"; } else { string message = "Invalid input, please try again"; lblDisplay.Text = message; ResetInputBoxes(); } } else { lblDisplay.Text = "Please select an item to update"; } }
public List <RaceResultsModel> DeleteRecord(RaceResultsModel model, string filename) { //Open the saved file List <RaceResultsModel> results = filename.FullFilePath().OpenSerialisedFile(); results.RemoveAll(x => x.ID == model.ID); results.SaveSerialisedFile(filename); return(results); }
private void btnHigh_Low_Click(object sender, EventArgs e) { lstReportsData.Items.Clear(); RaceResultsModel highestWon = rrm.GetHighestWon(_savedData); RaceResultsModel highestLoss = rrm.GetHighestLoss(_savedData); lstReportsData.Items.Add("The good and the bad..."); lstReportsData.Items.Add($"Best result todate: {highestWon}"); lstReportsData.Items.Add("==========================================="); lstReportsData.Items.Add($"Worst result to date: {highestLoss}"); lstReportsData.Items.Add("==========================================="); }
public List <RaceResultsModel> AddNewRecord(RaceResultsModel model, string filename) { //Open the saved file List <RaceResultsModel> results = filename.FullFilePath().OpenSerialisedFile(); //find the maxId int maxId = results.OrderByDescending(x => x.ID).First().ID + 1; model.ID = maxId; results.Add(model); //Save Serialised file results.SaveSerialisedFile(filename); return(results); }
private void btnAddNewRace_Click(object sender, EventArgs e) { lblDisplay.Text = ""; /*ensuring that the files data has either been imported * or opened before a new entry can be added*/ if (lstDisplayUpdateView.Items.Count != 0) { if (InputValidation()) { RaceResultsModel model = new RaceResultsModel( cboRaceCourse.SelectedItem.ToString(), dtpRaceDate.Text, txtAmount.Text, cboResult.SelectedItem.ToString()); savedData = dataUpdates.AddNewRecord(model, raceResultsfile); string message = "Race details added"; lblDisplay.Visible = true; lblDisplay.Text = message; ResetInputBoxes(); //display data in listbox lstDisplayUpdateView.Items.Clear(); foreach (RaceResultsModel race in savedData) { lstDisplayUpdateView.Items.Add(race); } ResetInputBoxes(); } else { string message = "Invalid input, please try again"; lblDisplay.Text = message; ResetInputBoxes(); } } else { lblDisplay.Text = "Missing saved data, import or open file"; } }
public void btnDelete_Click(object sender, EventArgs e) { if (lstDisplayUpdateView.SelectedIndex >= 0) { RaceResultsModel deleteRecord = (RaceResultsModel)lstDisplayUpdateView.SelectedItem; savedData = dataUpdates.DeleteRecord(deleteRecord, raceResultsfile); lstDisplayUpdateView.Items.Clear(); foreach (RaceResultsModel result in savedData) { lstDisplayUpdateView.Items.Add(result); } lblDisplay.Text = "Record deleted"; ResetInputBoxes(); btnAddNewRace.Enabled = true; } else { lblDisplay.Text = "Please select an item to delete"; } }
private void btnSelectItem_Click(object sender, EventArgs e) { if (lstDisplayUpdateView.SelectedIndex >= 0) { RaceResultsModel updateRecord = (RaceResultsModel)lstDisplayUpdateView.SelectedItem; int selectedIndex = lstDisplayUpdateView.Items.IndexOf(updateRecord); cboRaceCourse.Text = updateRecord.RaceCourse; dtpRaceDate.Value = updateRecord.RaceDate; txtAmount.Text = updateRecord.Amount.ToString(); cboResult.Text = updateRecord.Result; lblDisplay.Text = ""; btnAddNewRace.Enabled = false; btnUpdateRaceResult.Enabled = true; btnDelete.Enabled = true; } else { lblDisplay.Text = "Nothing selected"; } }
//extension method for coverting data into RaceResultsModel format public static List <RaceResultsModel> ConvertOrigData(this List <string> lines) { List <RaceResultsModel> output = new List <RaceResultsModel>(); int lineId = 1; foreach (string line in lines) { string chg1 = line.Replace("(", ""); string chg2 = chg1.Replace(")", ""); string chg3 = chg2.Replace(" ", ""); string[] words = chg3.Split(','); string date = string.Format(words[3] + "/" + words[2] + "/" + words[1]); string amt = words[4].Replace("m", ""); string res; if (words[5] == "true") { res = "Win"; } else { res = "Loss"; } RaceResultsModel resultsModel = new RaceResultsModel(lineId, words[0], date, amt, res) { ID = lineId, RaceCourse = words[0], RaceDate = Convert.ToDateTime(date), Amount = decimal.Parse(amt), Result = res }; lineId = lineId + 1;//incrementing the uniqueId for each line of data. output.Add(resultsModel); } return(output); }