protected void ScheduleGridView_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Select") { int index = Convert.ToInt32(e.CommandArgument); var controller = new RacingController(); var schedule = controller.Schedules_List(Calendar1.SelectedDate); var roster = controller.Roster_List(schedule[index].RaceID); var raceId = roster[0].RaceID.ToString(); RosterDataSource.SelectParameters.Clear(); RosterDataSource.SelectParameters.Add(new Parameter("raceId", TypeCode.Int32, raceId)); RosterDataSource.DataBind(); Close_Results(); RecordRaceTimes.Visible = true; GridView1.EditIndex = -1; GridView1.Visible = true; } }
protected void SaveButton_Command(object sender, CommandEventArgs e) { string error = string.Empty; var controller = new RacingController(); HiddenField raceId = null; foreach (GridViewRow row in GridView1.Rows) { raceId = (HiddenField)row.FindControl("RaceID"); } DropDownList memberDropDown = (DropDownList)GridView1.FooterRow.FindControl("MemberDropDown"); DropDownList feeDropDown = (DropDownList)GridView1.FooterRow.FindControl("FeeDropDown"); DropDownList carDropDown = (DropDownList)GridView1.FooterRow.FindControl("SerialDropDown"); decimal raceFee; if (feeDropDown.SelectedIndex == 1) { TextBox feeTextBox = (TextBox)GridView1.FooterRow.FindControl("FeeTextBox"); raceFee = int.Parse(feeTextBox.Text); } else if (feeDropDown.SelectedIndex == 0) { raceFee = 0; } else { raceFee = decimal.Parse(feeDropDown.SelectedItem.Text); } RosterViewModel roster = new RosterViewModel() { MemberID = int.Parse(memberDropDown.SelectedValue), CarID = int.Parse(carDropDown.SelectedValue), RaceID = int.Parse(raceId.Value), RaceFee = raceFee }; var racerCount = controller.Racer_Count(roster); InvoiceViewModel invoice = null; if (memberDropDown.SelectedIndex == 0) { error = error + " You must select a member when adding a new racer."; } if (raceFee == 0) { error = error + " You must enter a race fee in order to add a new racer."; } if (racerCount.Current > racerCount.Max) { error = error + " Race is already full. Cannot register additional racers."; } if (error.Trim().Length == 0) { try { invoice = controller.Add_Racer(roster, User.Identity.Name); } catch (Exception ex) { MessageUserControl1.ShowInfo(ex.Message, "Unable to save racer"); } var updateSchedule = controller.Schedules_List(Calendar1.SelectedDate); RosterDataSource.SelectParameters.Clear(); RosterDataSource.SelectParameters.Add(new Parameter("raceId", TypeCode.Int32, raceId.Value)); RosterDataSource.DataBind(); ScheduleGridView.DataSource = updateSchedule; ScheduleGridView.DataBind(); MessageUserControl1.ShowInfo("Success", ($"Racer Added to roster. Invoice #{invoice.InvoiceID} created by {User.Identity.Name}. Subtotal - {invoice.Subtotal:C2}, GST - {invoice.GST:C2}, Total - {invoice.Total:C2}")); } else { MessageUserControl1.ShowInfo("Failure", error); } CloseFooter(); }