/// <summary> /// event handler when click sell button, update the vehicle table /// </summary> void btnSell_Click(object sender, EventArgs e) { try { _currentRow["OptionsPrice"] = _optionsCharge; _currentRow["SoldBy"] = ((DataRowView)_salesStaffBindingSource.Current).Row["ID"]; _vehicleStockData.Update(); this.Close(); } catch (Exception ex) { // Display an error message AutomotiveManager.ShowMessage("An error occurred while attempting to sell the vehicle.", "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error); AutomotiveManager.recordError(ex); //close the form this.Shown += new EventHandler(frmVehicleSale_Shown); } }
/// <summary> /// the method to save the current insert /// </summary> /// <returns>ture if SuccessfulSaved, false when failed</returns> private bool saveCurrentRecord() { _errorFocus = false; bool isSuccessfulSaved = false; if (this.ValidateChildren()) { try { // When the edit mode of the form is new if (_editType == EditType.New) { // Get a reference to the data table from the bind source object DataTable dataTable = (DataTable)_bindingSource.DataSource; // Add a new row to the data table DataRow row = dataTable.NewRow(); // Define all the columns and values in the row row["StockNumber"] = txtStockNumber.Text.Trim(); row["ManufacturedYear"] = txtYear.Text.Trim(); row["Make"] = txtMake.Text.Trim(); row["Model"] = txtModel.Text.Trim(); row["Mileage"] = txtMileage.Text.Trim(); row["Automatic"] = radAutomatic.Checked; row["Colour"] = txtColour.Text.Trim(); row["BasePrice"] = txtBasePrice.Text.Trim(); // Add the new row to the data table dataTable.Rows.Add(row); } // Update the data set to the data source _vehicleStockData.Update(); isSuccessfulSaved = true; } catch (Exception ex) { // Display an error message AutomotiveManager.ShowMessage("An error occured while saving the contact.", "Save Error", MessageBoxButtons.OK, MessageBoxIcon.Error); AutomotiveManager.recordError(ex); } } return(isSuccessfulSaved); }