Beispiel #1
0
        private string GetYValue(int timeOfDay, WaterUsageList myList, string unitOfMeasure)
        {
            string yVal = "";

            if (myList != null)
            {
                IEnumerable <WaterUsage> waterUsageQuery =
                    from w in myList
                    where w.TimeOfDay == timeOfDay
                    select w;

                // if the query result contains data, assign the value
                // if not, assign 0 to yVal
                if (waterUsageQuery.Any())
                {
                    foreach (WaterUsage usage in waterUsageQuery)
                    {
                        if (unitOfMeasure == "litres")
                        {
                            yVal = usage.TotalLitresPerHour.ToString();
                        }
                        else
                        { //gallons
                            yVal = Math.Round(usage.TotalGallonsPerHour, 1).ToString();
                        }
                    }
                }
                else
                {
                    yVal = "0";
                }
            }
            else
            {
                yVal = "0";
            }



            return(yVal);
        }
Beispiel #2
0
        private void PopulateWaterUsageGraph(string unitOfMeasure)
        {
            string         yValue         = "";
            string         xValue         = "";
            DateTime       todaysDate     = new DateTime();
            WaterUsageList waterUsageList = WaterUsageManager.GetList();

            for (int i = 9; i < 21; i++)
            {
                xValue            = todaysDate.AddHours(i).ToString("h tt");
                yValue            = GetYValue(i, waterUsageList, unitOfMeasure);
                totalConsumption += Convert.ToDouble(yValue);

                chrtWaterUsage.Series[0].Points.AddXY(xValue, yValue);
            }

            BuildChartTitle();

            // set the Y Axis title
            chrtWaterUsage.ChartAreas[0].AxisY.Title = unitOfMeasure;

            DisplayTotalConsumption(unitOfMeasure);
        }
Beispiel #3
0
        public static WaterUsageList GetList()
        {
            WaterUsageList wList  = null;
            MyDBConnection myConn = new MyDBConnection();
            SqlConnection  conn   = new SqlConnection();
            SqlDataReader  dr;
            SqlCommand     cmd = new SqlCommand();

            try
            {
                // Open the connection
                conn            = myConn.OpenDB();
                cmd.Connection  = conn;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "dbo.GetWaterUsagePerHourCurrentDay";

                dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

                if (dr.HasRows)
                {
                    wList = new  WaterUsageList();
                    while (dr.Read())
                    {
                        wList.Add(FillDataRecord(dr));
                    }
                }

                cmd.Dispose();
                dr.Close();
            }
            finally
            {
                myConn.CloseDB(conn);
            }

            return(wList);
        }