private void InsertIntoDataBase() { FuelRecord data = new FuelRecord() { Liter = (float)numericUpDown1.Value, RefuelingDate = dateTimePicker1.Value, Kilometer = (float)numericUpDown2.Value }; try { FuelRecordModel fuelRecordModel = new FuelRecordModel(); fuelRecordModel.FuelRecord.Add(data); fuelRecordModel.SaveChanges(); MessageBox.Show("儲存成功!"); } catch { MessageBox.Show("發生錯誤!"); } }
public void ViewDetailsExecute(FuelRecord fuelRecord) { var selectedFuelRecord = fuelRecord; //if (SelectedFuelRecord == null) //{ // return; //} int fuelRecordId = selectedFuelRecord.FuelRecordId; NavigateToFuelRecordDetails(fuelRecordId); }
/// <summary> /// Navigates to Edit view /// </summary> /// <param name="fuelRecord"></param> public void EditFuelRecordExecute(FuelRecord fuelRecord) { if (fuelRecord == null) { return; } int fuelRecordId = fuelRecord.FuelRecordId; NavigateToFuelRecordEdit(fuelRecordId); }
public void InsertOrUpdate(FuelRecord fuelRecord) { if (fuelRecord.FuelRecordId == default(int)) { _context.FuelRecords.InsertOnSubmit(fuelRecord); } else if (_context.FuelRecords.Contains(fuelRecord)) { return; } else { _context.FuelRecords.Attach(fuelRecord, true); } }