예제 #1
0
        private List <ConsumptionModel> GetConsumptionModels(string consumptionContent)
        {
            List <ConsumptionModel> conModels = new List <ConsumptionModel>();

            switch (CurrentConsumption)
            {
            case ConsumptionFor.Premises:
                var modelPremise = JsonConvert.DeserializeObject <List <Premise> >(consumptionContent);
                conModels = modelPremise.ConvertAll(x => new ConsumptionModel()
                {
                    Id       = x.PremiseID,
                    Name     = CurrentConsumption.ToString() + " - " + x.PremiseName,
                    Consumed = Convert.ToString(Math.Round((x.MonthlyConsumption / 1000), 2)) + " K",
                    Expected = Convert.ToString(Math.Round((x.MonthlyPrediction / 1000), 2)) + " K",
                    Overused = Convert.ToString(Math.Round((x.MonthlyPrediction - x.MonthlyConsumption) / 1000, 2)) + " K"
                });
                break;

            case ConsumptionFor.Buildings:
                var modelBuilding = JsonConvert.DeserializeObject <List <Building> >(consumptionContent);
                return(modelBuilding.ConvertAll(x => new ConsumptionModel()
                {
                    Id = x.BuildingID,
                    Name = CurrentConsumption.ToString() + " - " + x.BuildingName,
                    Consumed = Convert.ToString(Math.Round((x.MonthlyConsumption / 1000), 2)) + " K",
                    Expected = Convert.ToString(Math.Round((x.MonthlyPrediction / 1000), 2)) + " K",
                    Overused = Convert.ToString(Math.Round((x.MonthlyPrediction - x.MonthlyConsumption) / 1000, 2)) + " K"
                }));

            case ConsumptionFor.Meters:
                var modelMeter = JsonConvert.DeserializeObject <List <Meter> >(consumptionContent);
                return(modelMeter.ConvertAll(x => new ConsumptionModel()
                {
                    Id = x.Id,
                    Name = CurrentConsumption.ToString() + " - " + x.PowerScout,
                    Consumed = Convert.ToString(Math.Round((x.MonthlyConsumption / 1000), 2)) + " K",
                    Expected = Convert.ToString(Math.Round((x.MonthlyPrediction / 1000), 2)) + " K",
                    Overused = Convert.ToString(Math.Round((x.MonthlyPrediction - x.MonthlyConsumption) / 1000, 2)) + " K"
                }));
            }
            return(conModels);
        }
        private void BtnBack_TouchUpInside(object sender, EventArgs e)
        {
            btnBack.Hidden = false;
            switch (CurrentConsumption)
            {
            case ConsumptionFor.Buildings:
                CurrentConsumption = ConsumptionFor.Premises;
                GetConsumptionDetails(CurrentConsumption, 0);
                CurrentPremisesId = 0;
                btnBack.Hidden    = true;
                break;

            case ConsumptionFor.Meters:
                CurrentConsumption = ConsumptionFor.Buildings;
                GetConsumptionDetails(CurrentConsumption, CurrentPremisesId);

                break;

            case ConsumptionFor.Premises:
                btnBack.Hidden = true;
                break;
            }
            lblHeader.Text = CurrentConsumption.ToString();
        }