public void FinishRequest() { FishingRecord record; // validate fields try { // date and time CommonPresenterStuff.ValidateDateEarlierThanNow(_view.DateTimeStart, "start date and time"); CommonPresenterStuff.ValidateCronologicalDates(_view.DateTimeStart, _view.DateTimeEnd, "start date and time", "end date and time"); // location name CommonPresenterStuff.ValidateFieldNotEmpty(_view.Location, "location"); // nature events CommonPresenterStuff.ValidateFieldNotEmpty(_view.Wind, "wind"); CommonPresenterStuff.ValidateFieldNotEmpty(_view.MoonPhase, "moon phase"); CommonPresenterStuff.ValidateFieldNotEmpty(_view.Tide, "tide"); } catch (Exception e) { _view.ShowErrorMessage(e.Message); return; } // if fish catch or sale is empty, warn user if (_fishCatch.GetCaughtFish().Count == 0) { if (!_view.WarnUser(CommonPresenterStuff.WarnFieldEmptyMessage("fish catch"))) { return; } } if (_fishCatch.GetSoldFish().Count == 0) { if (!_view.WarnUser(CommonPresenterStuff.WarnFieldEmptyMessage("fish sale"))) { return; } } // try create record Winds wind = CommonPresenterStuff.GetWindEnum(_view.Wind); MoonPhases moonPhase = CommonPresenterStuff.GetMoonPhaseEnum(_view.MoonPhase); Tides tide = CommonPresenterStuff.GetTideEnum(_view.Tide); try { record = FishingRecordFactory.CreateFishingRecord(_view.DateTimeStart, _view.DateTimeEnd, _view.Location, wind, moonPhase, tide, _fishCatch); } catch (Exception) { _view.ShowErrorMessage(CommonPresenterStuff.ErrorMessage()); return; } Finish(record); }
public PresenterFishingRecordEdit(IViewFishingRecord inView, int inRecordIndex) : base(inView) { _recordIndex = inRecordIndex; FishingRecord record = FishingRecordRepository.GetInstance().GetRecord(inRecordIndex); _fishCatch = record.FishCatch; // set record details on view _view.DateTimeStart = record.DateTimeInterval.Start; _view.DateTimeEnd = record.DateTimeInterval.End; _view.Location = record.Location.Name; _view.Wind = CommonPresenterStuff.GetWindStrings()[(int)record.NatureContex.Wind]; _view.MoonPhase = CommonPresenterStuff.GetMoonPhaseStrings()[(int)record.NatureContex.MoonPhase]; _view.Tide = CommonPresenterStuff.GetTideStrings()[(int)record.NatureContex.Tide]; foreach (string fish in record.FishCatch.GetCaughtFish()) { _view.AddFishCatch(fish, record.FishCatch.GetCaughtFishMass(fish)); } foreach (string fish in record.FishCatch.GetSoldFish()) { _view.AddFishSale(fish, record.FishCatch.GetSoldFishMass(fish), record.FishCatch.GetSoldFishPrice(fish)); } _view.SetFinishButtonText("Save changes"); }
public override void Finish(FishingRecord record) { // try adding record try { FishingRecordRepository.GetInstance().AddRecord(record); } catch (FishingRecordAlreadyExistsException) { _view.ShowErrorMessage("Fishing record already exists!"); return; } catch (FishingRecordsInCollisionException) { _view.ShowErrorMessage(_fishingRecordsInCollisionError); return; } catch (Exception) { _view.ShowErrorMessage(CommonPresenterStuff.ErrorMessage()); return; } NotifyObservers(new Object()); _view.ShowMessage("Fishing record added."); _view.End(); }
public PresenterFishingRecord(IViewFishingRecord inView) { _view = inView; // fill view with data _view.Locations = LocationRepository.GetInstance().GetLocationNames(); _view.Winds = CommonPresenterStuff.GetWindStrings(); _view.MoonPhases = CommonPresenterStuff.GetMoonPhaseStrings(); _view.Tides = CommonPresenterStuff.GetTideStrings(); }
public void AddFishSaleRequest() { double mass, price; // validate fields try { // fish name CommonPresenterStuff.ValidateFieldNotEmpty(_view.FishName, "fish"); // sold mass CommonPresenterStuff.ValidateFieldNotEmpty(_view.Mass, "mass"); mass = CommonPresenterStuff.ValidateDoubleString(_view.Mass, "mass"); CommonPresenterStuff.ValidateDoubleGreaterThan(mass, 0.0, "mass"); // sale price CommonPresenterStuff.ValidateFieldNotEmpty(_view.Price, "price"); price = CommonPresenterStuff.ValidateDoubleString(_view.Price, "price"); CommonPresenterStuff.ValidateDoubleGreaterThan(price, 0.0, "price"); } catch (Exception e) { _view.ShowErrorMessage(e.Message); return; } // try adding fish sale try { Object fishSale = new object[] { _view.FishName, mass, price }; NotifyObservers(fishSale); } catch (FishSaleAlreadyAddedException) { _view.ShowErrorMessage("Fish sale has already been added"); return; } catch (FishNotCaughtException) { _view.ShowErrorMessage("Fish must first be caught!"); return; } catch (SaleMassGreaterThanCaughtMassException) { _view.ShowErrorMessage("Sale mass must be less or equal than caught mass!"); return; } catch (Exception) { _view.ShowErrorMessage(CommonPresenterStuff.ErrorMessage()); } _view.End(); }
public void FinishRequest(string inName, string inLatitude, string inLongitude, string inDepth, string inComment) { Location location; double latitude, longitude, depth; // validate fields try { // location name CommonPresenterStuff.ValidateFieldNotEmpty(_view.LocationName, "name"); // latitude CommonPresenterStuff.ValidateFieldNotEmpty(_view.Latitude, "latitude"); latitude = CommonPresenterStuff.ValidateDoubleString(_view.Latitude, "latitude"); CommonPresenterStuff.ValidateDoubleInRange(latitude, -90.0, 90.0, "latitude"); // longitude CommonPresenterStuff.ValidateFieldNotEmpty(_view.Longitude, "longitude"); longitude = CommonPresenterStuff.ValidateDoubleString(_view.Longitude, "longitude"); CommonPresenterStuff.ValidateDoubleInRange(longitude, -180.0, 180.0, "longitude"); // depth CommonPresenterStuff.ValidateFieldNotEmpty(_view.Depth, "depth"); depth = CommonPresenterStuff.ValidateDoubleString(_view.Depth, "depth"); CommonPresenterStuff.ValidateDoubleGreaterThan(depth, 0.0, "depth"); } catch (Exception e) { _view.ShowErrorMessage(e.Message); return; } // if comment is empty, warn user if (_view.Comment == "") { if (!_view.WarnUser(CommonPresenterStuff.WarnFieldEmptyMessage("comment"))) { return; } } // try creating location try { location = LocationFactory.CreateLocation(inName, latitude, longitude, depth, inComment); } catch (Exception) { _view.ShowErrorMessage(CommonPresenterStuff.ErrorMessage()); return; } Finish(location); }
private List <string> GenerateFishReport(double totalValue, Dictionary <string, double> valuePerItemDict, double totalTimeInHours, string valueName, string valueUnitName) { List <String> report = new List <string>(); string valueNameCap = CommonPresenterStuff.CapitalizeFirstLetter(valueName); // sort items by value descending var valuePerItem = from fishMassPair in valuePerItemDict orderby fishMassPair.Value descending select fishMassPair; // generate report report.Add("Total " + valueName + ": " + totalValue.ToString("0.00") + " " + valueUnitName); report.Add(valueNameCap + " per fish:"); foreach (KeyValuePair <string, double> pair in valuePerItem) { string item = pair.Key; double value = pair.Value; double percentage = value / totalValue * 100; report.Add("\t" + String.Format("{0, -15}", item) + String.Format("{0, -15}", value.ToString("0.00") + " " + valueUnitName) + "(" + percentage.ToString("0.00") + "%)"); } report.Add(""); double valuePerHour = totalValue / totalTimeInHours; report.Add("Total average " + valueName + " per hour: " + valuePerHour.ToString("0.00") + " " + valueUnitName + "/h"); report.Add("Average " + valueName + " per hour per fish:"); foreach (KeyValuePair <string, double> pair in valuePerItem) { string item = pair.Key; double value = pair.Value; double averageValuePerHour = value / totalTimeInHours; report.Add("\t" + String.Format("{0, -15}", item) + averageValuePerHour.ToString("0.00") + " " + valueUnitName + "/h"); } return(report); }
public void AddFishCatchRequest() { double mass; // validate fields try { // fish name CommonPresenterStuff.ValidateFieldNotEmpty(_view.FishName, "fish"); // caught mass CommonPresenterStuff.ValidateFieldNotEmpty(_view.Mass, "mass"); mass = CommonPresenterStuff.ValidateDoubleString(_view.Mass, "mass"); CommonPresenterStuff.ValidateDoubleGreaterThan(mass, 0.0, "mass"); } catch (Exception e) { _view.ShowErrorMessage(e.Message); return; } // try adding fish catch try { object[] fishCatch = { _view.FishName, mass }; NotifyObservers(fishCatch); } catch (FishCatchAlreadyExistsException) { _view.ShowErrorMessage("Fish has already been caught!"); return; } catch (Exception) { _view.ShowErrorMessage(CommonPresenterStuff.ErrorMessage()); return; } _view.End(); }
public override void Finish(FishingRecord record) { // try updating records try { FishingRecordRepository.GetInstance().UpdateRecord(_recordIndex, record); } catch (FishingRecordsInCollisionException) { _view.ShowErrorMessage(_fishingRecordsInCollisionError); return; } catch (Exception) { _view.ShowErrorMessage(CommonPresenterStuff.ErrorMessage()); } NotifyObservers(new Object()); _view.ShowMessage("Changes saved."); _view.End(); }
public void DeleteLocationRequest(int inLocationIndex) { // warn user if (_view.WarnUser(CommonPresenterStuff.WarnDeleteMessage("location"))) { // try deleting location try { LocationRepository.GetInstance().DeleteLocation(inLocationIndex); } catch (LocationPartOfFishingRecordException) { _view.ShowErrorMessage("Location can't be deleted!\nIt is a part of one or more fishing records."); return; } catch (Exception) { _view.ShowErrorMessage(CommonPresenterStuff.ErrorMessage()); return; } } }