public IEnumerable < string > Validate() { if (OdometerReading <= 0) yield return "The odometer value must be greater than zero." ; if (DistanceDriven <= 0) yield return "The odometer value must be greater than the previous value." ; if (FuelQuantity <= 0) yield return "The fuel quantity must be greater than zero." ; if (PricePerFuelUnit <= 0) yield return "The fuel price must be greater than zero." ; } * This source code was highlighted with Source Code Highlighter .
public IEnumerable < string > Validate() { if (OdometerReading <= 0) yield return "The odometer value must be greater than zero." ; if (DistanceDriven <= 0) yield return "The odometer value must be greater than the previous value." ; if (FuelQuantity <= 0) yield return "The fuel quantity must be greater than zero." ; if (PricePerFuelUnit <= 0) yield return "The fuel price must be greater than zero." ; } * This source code was highlighted with Source Code Highlighter .
public IEnumerable < string > Validate() { if (OdometerReading <= 0) yield return "The odometer value must be greater than zero." ; if (DistanceDriven <= 0) yield return "The odometer value must be greater than the previous value." ; if (FuelQuantity <= 0) yield return "The fuel quantity must be greater than zero." ; if (PricePerFuelUnit <= 0) yield return "The fuel price must be greater than zero." ; } * This source code was highlighted with Source Code Highlighter .
public IEnumerable < string > Validate() { if (OdometerReading <= 0) yield return "The odometer value must be greater than zero." ; if (DistanceDriven <= 0) yield return "The odometer value must be greater than the previous value." ; if (FuelQuantity <= 0) yield return "The fuel quantity must be greater than zero." ; if (PricePerFuelUnit <= 0) yield return "The fuel price must be greater than zero." ; } * This source code was highlighted with Source Code Highlighter .
public IEnumerable < string > Validate() { if (OdometerReading <= 0) yield return "The odometer value must be greater than zero." ; if (DistanceDriven <= 0) yield return "The odometer value must be greater than the previous value." ; if (FuelQuantity <= 0) yield return "The fuel quantity must be greater than zero." ; if (PricePerFuelUnit <= 0) yield return "The fuel price must be greater than zero." ; } * This source code was highlighted with Source Code Highlighter .
public IEnumerable < string > Validate() { if (OdometerReading <= 0) yield return "The odometer value must be greater than zero." ; if (DistanceDriven <= 0) yield return "The odometer value must be greater than the previous value." ; if (FuelQuantity <= 0) yield return "The fuel quantity must be greater than zero." ; if (PricePerFuelUnit <= 0) yield return "The fuel price must be greater than zero." ; } * This source code was highlighted with Source Code Highlighter .
public IEnumerable < string > Validate() { if (OdometerReading <= 0) yield return "The odometer value must be greater than zero." ; if (DistanceDriven <= 0) yield return "The odometer value must be greater than the previous value." ; if (FuelQuantity <= 0) yield return "The fuel quantity must be greater than zero." ; if (PricePerFuelUnit <= 0) yield return "The fuel price must be greater than zero." ; } * This source code was highlighted with Source Code Highlighter .
public IEnumerable < string > Validate() { if (OdometerReading <= 0) yield return "The odometer value must be greater than zero." ; if (DistanceDriven <= 0) yield return "The odometer value must be greater than the previous value." ; if (FuelQuantity <= 0) yield return "The fuel quantity must be greater than zero." ; if (PricePerFuelUnit <= 0) yield return "The fuel price must be greater than zero." ; } * This source code was highlighted with Source Code Highlighter .
public IEnumerable < string > Validate() { if (OdometerReading <= 0) yield return "The odometer value must be greater than zero." ; if (DistanceDriven <= 0) yield return "The odometer value must be greater than the previous value." ; if (FuelQuantity <= 0) yield return "The fuel quantity must be greater than zero." ; if (PricePerFuelUnit <= 0) yield return "The fuel price must be greater than zero." ; } * This source code was highlighted with Source Code Highlighter .
public IEnumerable < string > Validate() { if (OdometerReading <= 0) yield return "The odometer value must be greater than zero." ; if (DistanceDriven <= 0) yield return "The odometer value must be greater than the previous value." ; if (FuelQuantity <= 0) yield return "The fuel quantity must be greater than zero." ; if (PricePerFuelUnit <= 0) yield return "The fuel price must be greater than zero." ; } * This source code was highlighted with Source Code Highlighter .
public IEnumerable < string > Validate() { if (OdometerReading <= 0) yield return "The odometer value must be greater than zero." ; if (DistanceDriven <= 0) yield return "The odometer value must be greater than the previous value." ; if (FuelQuantity <= 0) yield return "The fuel quantity must be greater than zero." ; if (PricePerFuelUnit <= 0) yield return "The fuel price must be greater than zero." ; } * This source code was highlighted with Source Code Highlighter .
public IEnumerable < string > Validate() { if (OdometerReading <= 0) yield return "The odometer value must be greater than zero." ; if (DistanceDriven <= 0) yield return "The odometer value must be greater than the previous value." ; if (FuelQuantity <= 0) yield return "The fuel quantity must be greater than zero." ; if (PricePerFuelUnit <= 0) yield return "The fuel price must be greater than zero." ; } * This source code was highlighted with Source Code Highlighter .
public IEnumerable < string > Validate() { if (OdometerReading <= 0) yield return "The odometer value must be greater than zero." ; if (DistanceDriven <= 0) yield return "The odometer value must be greater than the previous value." ; if (FuelQuantity <= 0) yield return "The fuel quantity must be greater than zero." ; if (PricePerFuelUnit <= 0) yield return "The fuel price must be greater than zero." ; } * This source code was highlighted with Source Code Highlighter .
* This source code was highlighted with Source Code Highlighter .
- public static SaveResult SaveFillup (Fillup fillup, Action errorCallback)
- {
- var lastReading =
- Car.FillupHistory.Count> 0?
- Car.FillupHistory.First (). OdometerReading:
- Car.InitialOdometerReading;
- fillup.DistanceDriven = fillup.OdometerReading - lastReading;
- var saveResult = new SaveResult ();
- var validationResults = fillup.Validate ();
- if (validationResults.Count ()> 0)
- {
- saveResult.SaveSuccessful = false ;
- saveResult.ErrorMessages = validationResults;
- }
- else
- {
- Car.FillupHistory.Insert (0, fillup);
- saveResult.SaveSuccessful = true ;
- SaveCar ( delegate {
- saveResult.SaveSuccessful = false ;
- errorCallback (); });
- }
- return saveResult;
- }
* This source code was highlighted with Source Code Highlighter .
- private void SaveButton_Click ( object sender, EventArgs e)
- {
- CommitTextBoxes ();
- SaveResult result = CarDataStore.SaveFillup (currentFillup,
- delegate {
- MessageBox.Show ( "There is not enough space for your phone to" +
- "save your fill-up data. Free space and try again." ,
- "Warning" , MessageBoxButton.OK);
- });
- if (result.SaveSuccessful)
- {
- Microsoft.Phone.Shell.PhoneApplicationService.Current
- .State [ "FillupSaved" ] = true ;
- cacheChanges = false ;
- NavigationService.GoBack ();
- }
- else
- {
- string errorMessages = String .Join (
- Environment.NewLine + Environment.NewLine,
- result.ErrorMessages.ToArray ());
- if (! String .IsNullOrEmpty (errorMessages))
- {
- MessageBox.Show (errorMessages,
- "Warning: Invalid Values" , MessageBoxButton.OK);
- }
- }
- }
* This source code was highlighted with Source Code Highlighter .
- protected override void OnBackKeyPress (
- System.ComponentModel.CancelEventArgs e)
- {
- base .OnBackKeyPress (e);
- // If there are no changes, do nothing.
- if (! hasUnsavedChanges) return ;
- var result = MessageBox.Show ( "You are about to discard your" +
- "changes. Continue?" , "Warning" , MessageBoxButton.OKCancel);
- if (result == MessageBoxResult.OK)
- {
- // Normal navigation; there's no need to handle tombstoning,
- // so set the flag and the current cache.
- cacheChanges = false ;
- this .State.Remove (CURRENT_FILLUP_KEY);
- }
- else
- {
- // Cancel backward navigation.
- e.Cancel = true ;
- }
- }
Source: https://habr.com/ru/post/118461/
All Articles