private void btn_updateInsert_Click(object sender, EventArgs e) { // Collate data List <string> row = new List <string>(); row.Add(text_serialNumber.Text); row.Add(text_name.Text); row.Add(text_model.Text); row.Add(text_year.Text); row.Add(text_make.Text); row.Add(text_baseCost.Text); List <string> primaryKey = new List <string>(); primaryKey.Add(_primaryKey); if (_updateFlag) // If update mode { // TODO UPDATE } else // Add mode { // Add data to database if (_database.WriteData("vehicles", row)) { List <List <string> > formData = _database.FetchData("vehicles"); _row = formData.Count - 1; LoadData(); // Re-enable new button & change to update button. btn_new.Enabled = true; btn_updateInsert.Text = "Update"; _updateFlag = true; // Show success MessageBox.Show("New Vehicle sucessfully added."); } else { // TODO: On write error } } }
private void btn_update_insert_Click(object sender, EventArgs e) { // Collate data List <string> row = new List <string>(); row.Add(text_optId.Text); row.Add(text_optDes.Text); row.Add(text_optCost.Text); List <string> primaryKey = new List <string>(); primaryKey.Add(_primaryKey); if (_updateFlag) // If update mode { if (_database.UpdateData("dealerinstalledoptions", primaryKey, row)) { // Reload data, TODO: Streamline this for performance? List <List <string> > formData = _database.FetchData("dealerinstalledoptions"); text_optId.Text = formData[_row][0]; text_optDes.Text = formData[_row][1]; text_optCost.Text = formData[_row][2]; _primaryKey = formData[_row][0]; // Show success MessageBox.Show("Dealer option succefully updated."); } else { //TODO: on update failure } } else // Add Mode { // Add data to database if (_database.WriteData("dealerinstalledoptions", row)) { // Switch view to newly added data List <List <string> > formData = _database.FetchData("dealerinstalledoptions"); _row = formData.Count - 1; text_optId.Text = formData[_row][0]; text_optDes.Text = formData[_row][1]; text_optCost.Text = formData[_row][2]; _primaryKey = formData[_row][0]; if (_row > 0) // check if there is previous { btn_prev.Enabled = true; } btn_next.Enabled = false; // Re-enable new button & change to update button. btn_new.Enabled = true; btn_update_insert.Text = "Update"; _updateFlag = true; // Show success MessageBox.Show("New Dealer Option sucessfully added."); } else { //TODO: on write failure } } }