private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { Refueling newRefueling = new Refueling(); DataManager dataManager = new DataManager(); //Get user input newRefueling.date = date.Date.DateTime; /* * if (!HelperFunctions.convertStringToDouble(amount.Text, ref newRefueling.amount)) * { * //Error * } * * if (!HelperFunctions.convertStringToDouble(tbCosts.Text, ref newRefueling.costs)) * { * //Error * } * * if (!HelperFunctions.convertStringToDouble(tbDistance.Text, ref newRefueling.drivenDistance)) * { * //Error * } */ newRefueling.isCompleteFilled = Convert.ToBoolean(completeFilled.IsChecked); dataManager.updateRefueling(newRefueling); result = EditRefuelingResult.edit; }
/// <summary> /// Inserts new refueling to database /// </summary> /// <param name="newRefuling"></param> public void addRefueling(Refueling newRefuling) { using (var dbConn = new SQLiteConnection(App.DB_PATH)) { dbConn.RunInTransaction(() => { dbConn.Insert(newRefuling); }); } }
public static bool isComplete(Refueling refueling) { if (refueling.amount == 0) { return(false); } if (refueling.drivenDistance == 0) { return(false); } //All needed attributes are set return(true); }
/// <summary> /// Adds refueling to database /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { Refueling refueling = new Refueling(); DataManager dataManager = new DataManager(); double temp = 0.0; //Get user input refueling.date = date.Date.DateTime; if (!HelperFunctions.convertStringToDouble(amount.Text, ref temp)) { //Error } refueling.amount = temp; if (!HelperFunctions.convertStringToDouble(tbCosts.Text, ref temp)) { //Error } refueling.costs = temp; if (!HelperFunctions.convertStringToDouble(tbDistance.Text, ref temp)) { //Error } refueling.drivenDistance = temp; refueling.isCompleteFilled = Convert.ToBoolean(completeFilled.IsChecked); refueling.calculateLiterPer100Kilometer(); ////Add new refueling to refueling list //(App.Current as App).dataManager.addRefuling(refueling); ////Save new refueling list //(App.Current as App).dataManager.saveRefuelings(); dataManager.addRefueling(refueling); result = AddFuelResult.AddFuel; }
/// <summary> /// Updates the refueling /// </summary> /// <param name="refuling"></param> public void updateRefueling(Refueling refuling) { using (var dbConn = new SQLiteConnection(App.DB_PATH)) { var existingRefueling = dbConn.Query <Refueling>("select * from Refueling where Id =" + refuling.Id).FirstOrDefault(); if (existingRefueling != null) { //TO DO: change existingRefueling.date = refuling.date; existingRefueling.amount = refuling.amount; existingRefueling.costs = refuling.costs; existingRefueling.drivenDistance = refuling.drivenDistance; existingRefueling.isCompleteFilled = refuling.isCompleteFilled; dbConn.RunInTransaction(() => { dbConn.Update(existingRefueling); }); } } }
public CdEditRefueling(Refueling oldRefueling) { this.InitializeComponent(); this.oldRefueling = oldRefueling; }