//take in form inputs and popluate grid content private void dataGrid_climbs_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e) { DataTable dt = climbDb.getDt(); DataRow dr = dt.Rows[e.RowIndex]; routeData route = new routeData(); //exception handling try { //collect information from the form route.attempts = Convert.ToInt32(dr["attempts"]); route.color = dr["color"].ToString(); route.date = Convert.ToDateTime(dr["date"].ToString()); route.grade = dr["grade"].ToString(); route.notes = dr["notes"].ToString(); route.routeDesc = dr["routeDesc"].ToString(); //create new climb singleClimb climb = new singleClimb(); //assign form data to climb climb.assignInfo(route); //create new route RouteInfo routeInfo = new RouteInfo(climb); //show route routeInfo.Show(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
// save the climb on click private void saveClimb_Click(object sender, EventArgs e) { //create a new climb singleClimb climb = new singleClimb(); routeData route; bool saveCheck = false; //Error Handling // Try to parse the attemps value, if it's not a number don't save the climb if (Int32.TryParse(txtBox_attempts.Text, out route.attempts)) { saveCheck = true; } route.color = txtBox_color.Text; route.date = dateTimePicker_addClimb.Value; //if (float.TryParse(txtBox_grade.Text, out route.grade)) { } route.grade = txtBox_grade.Text; route.notes = rTxtBox_notes.Text; route.routeDesc = txtBox_routeDesc.Text; //if save is true save add the climb to the database if (saveCheck) { climb.assignInfo(route); climbDb.addClimbToDb(climb); //create new route info RouteInfo routeInfo = new RouteInfo(climb); routeInfo.Show(); this.Close(); } //if the save is false create error message else { MessageBox.Show("Attempts value needs to be a whole number"); } }