示例#1
0
 /// <summary>
 /// Erhalte ein Tank anhand der Nummer
 /// </summary>
 /// <param name="number"></param>
 /// <returns></returns>
 private Tank GetTankByNumber(int number)
 {
     foreach (Tank tank in tanks)
     {
         if (tank.Number == number)
         {
             return(tank);
         }
     }
     MessageService.AddFatalErrorMessage("Bitte überprüfen Sie ihr fuelConfig.json", "Ungültiger Tank mit der Id " + number + " wurde hinzugefügt");
     return(null);
 }
示例#2
0
 /// <summary>
 /// Erhalte Treibstoffsorte anhand dem Namen
 /// </summary>
 /// <param name="fuelName"></param>
 /// <returns></returns>
 private Fuel GetFuelByName(string fuelName)
 {
     foreach (Fuel fuel in fuels)
     {
         if (fuel.Name == fuelName)
         {
             return(fuel);
         }
     }
     MessageService.AddFatalErrorMessage("Bitte überprüfen Sie ihr receiptConfig.json", "Ungültige Rechnung mit dem fuelName " + fuelName + " wurde hinzugefügt");
     return(null);
 }
示例#3
0
        /// <summary>
        /// Scannt alle json und füllt die Daten in Objekte ab
        /// </summary>
        private void GetDataAsJson()
        {
            try
            {
                //GASPUMP
                using (StreamReader sr = new StreamReader(@"..\..\Data\config\gasPumpConfig.json"))
                {
                    string fileString  = sr.ReadToEnd();
                    JToken gasPumpJson = JObject.Parse(fileString)["gasPumps"];

                    foreach (JToken gasPumpToken in gasPumpJson)
                    {
                        GasPump gasPump = new GasPump(Convert.ToInt32(gasPumpToken["GasPumpNumber"]));
                        gasPump.Status = (GasPumpStatus)Convert.ToInt32(gasPumpToken["Status"]);
                        gasPumps.Add(gasPump);
                    }
                }
            }
            catch (Exception)
            {
                MessageService.AddFatalErrorMessage("Bitte überprüfe Sie ihr gasPumpConfig.json", "GasPump kann nicht ausgelesen werden");
            }

            try
            {
                //TANK
                using (StreamReader sr = new StreamReader(@"..\..\Data\config\tankConfig.json"))
                {
                    string fileString = sr.ReadToEnd();
                    JToken tankJson   = JObject.Parse(fileString)["tanks"];

                    foreach (JToken tankToken in tankJson)
                    {
                        Tank tank = new Tank();
                        tank.Number         = Convert.ToInt32(tankToken["Number"]);
                        tank.Name           = tankToken["Name"].ToString();
                        tank.FuelName       = tankToken["FuelName"].ToString();
                        tank.AvailibleLiter = float.Parse(tankToken["AvailibleLiter"].ToString());
                        tank.VolumeLiter    = float.Parse(tankToken["VolumeLiter"].ToString());
                        tank.MinAmount      = float.Parse(tankToken["MinAmount"].ToString());
                        tanks.Add(tank);
                    }
                }
            }
            catch (Exception)
            {
                MessageService.AddFatalErrorMessage("Bitte überprüfe Sie ihr tankConfig.json", "Tank kann nicht ausgelesen werden");
            }

            try
            {
                //FUEL
                using (StreamReader sr = new StreamReader(@"..\..\Data\config\fuelConfig.json"))
                {
                    string fileString = sr.ReadToEnd();
                    JToken fuelJson   = JObject.Parse(fileString)["fuels"];

                    foreach (JToken fuelToken in fuelJson)
                    {
                        Fuel fuel = new Fuel();
                        fuel.Name          = fuelToken["Name"].ToString();
                        fuel.PricePerLiter = Convert.ToDecimal(fuelToken["PricePerLiter"]);
                        fuels.Add(fuel);
                    }
                }
            }
            catch (Exception)
            {
                MessageService.AddFatalErrorMessage("Bitte überprüfe Sie ihr fuelConfig.json", "Fuel kann nicht ausgelesen werden");
            }

            try
            {
                //RECEIPT
                using (StreamReader sr = new StreamReader(@"..\..\Data\config\receiptConfig.json"))
                {
                    string fileString  = sr.ReadToEnd();
                    JToken receiptJson = JObject.Parse(fileString)["receipts"];

                    foreach (JToken receiptToken in receiptJson)
                    {
                        Receipt receipt = new Receipt();
                        receipt.Id           = Convert.ToInt32(receiptToken["Id"]);
                        receipt.Date         = DateTime.Parse(receiptToken["Date"].ToString());
                        receipt.RelatedFuel  = GetFuelByName(receiptToken["RelatedFuel"].ToString());
                        receipt.RelatedLiter = float.Parse(receiptToken["RelatedLiter"].ToString());
                        receipt.Sum          = Convert.ToDecimal(receiptToken["Sum"].ToString());
                        receipts.Add(receipt);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageService.AddFatalErrorMessage("Bitte überprüfe Sie ihr receiptConfig.json", "Receipt kann nicht ausgelesen werden");
            }

            try
            {
                //Coin
                using (StreamReader sr = new StreamReader(@"..\..\Data\config\coinConfig.json"))
                {
                    string fileString = sr.ReadToEnd();
                    JToken coinJson   = JObject.Parse(fileString)["coins"];

                    foreach (JToken coinToken in coinJson)
                    {
                        Coin coin = new Coin(Convert.ToInt32(coinToken));
                        coins.Add(coin);
                    }
                }
            }
            catch (Exception)
            {
                MessageService.AddFatalErrorMessage("Bitte überprüfe Sie ihr coinConfig.json", "Coin kann nicht ausgelesen werden");
            }
        }