public string this[string vehicle] { get { string result = null; switch (vehicle) { case "RegistrationNumber": if (string.IsNullOrEmpty(RegistrationNumber)) { result = "It cannot be empty"; } break; case "Model": if (string.IsNullOrEmpty(Model)) { result = "It cannot be empty"; } break; case "Manufacturer": if (string.IsNullOrWhiteSpace(Manufacturer)) { result = "it cannot be empty"; } else if (Manufacturer.Length < 3) { result = "it must be minimum of 3 characters"; } break; case "MakeYear": if (string.IsNullOrWhiteSpace(MakeYear.ToString())) { result = "it cannot be empty"; } break; case "TankCapacity": if (string.IsNullOrWhiteSpace(TankCapacity.ToString())) { result = "it cannot be empty"; } break; } if (ErrorCollection.ContainsKey(vehicle)) { ErrorCollection[vehicle] = result; } else if (result != null) { ErrorCollection.Add(vehicle, result); } OnPropertyChanged("ErrorCollection"); return(result); } }
private void WriteRow(StringBuilder target, string name, TankCapacity row) { target.AppendFormat("{0,-20}", name); if (row.TankCount > 1) { target.AppendFormat(" x{0,-2}", row.TankCount); } else { target.Append(" "); } target.AppendFormat(" {0,3:#0%}", row.AvailableContents / row.Capacity); target.AppendFormat(" {0,4} / {1,4}", Unit.Volume.FormatSI(row.AvailableContents), Unit.Volume.FormatSI(row.Capacity)); if (row.IsStockpiling) { target.AppendFormat(" ({0,4})", Unit.Volume.FormatSI(row.Contents)); } target.AppendLine(); }
//Method to withdraw water from tank public string WithdrawWater(int gallonsToWithdraw) { //Declare local variables string withdrawString; //Add water if not at capacity if (gallonsToWithdraw <= WaterLevel) { WaterLevel = (WaterLevel - gallonsToWithdraw); withdrawString = $" Gallons Drained: {gallonsToWithdraw.ToString()} \r\n Current Water Level: {WaterLevel.ToString()} \r\n Tank Capacity: {TankCapacity.ToString()}"; } else { withdrawString = $" Insufficient water level. \r\n Maximum Allowed Gallons: {WaterLevel.ToString()}"; } //Return value return(withdrawString); }
//Method to add water to tank public string AddWater(int gallonsToAdd) { //Declare local variables string addString; //Add water if not at capacity if (gallonsToAdd <= (TankCapacity - WaterLevel)) { WaterLevel += gallonsToAdd; addString = $" Gallons Added: {gallonsToAdd.ToString()} \r\n Current Water Level: {WaterLevel.ToString()} \r\n Tank Capacity: {TankCapacity.ToString()}"; } else { addString = $" WARNING! Tank will overflow. \r\n Current Water Level: {WaterLevel.ToString()} \r\n Maximum Additional Gallons: {(TankCapacity - WaterLevel).ToString()}"; } //Return value return(addString); }