public void DailyElecDataSeries()
{
if (!Chart1Built) { CreateChart1(); }
// Chart1Grid.Children.Clear();
if (Chart1.Series.Count == 0)
{
Chart1.Series.Add(new DataSeries() { RenderAs = RenderAs.Column });
Chart1.Series.Add(new DataSeries() { RenderAs = RenderAs.Column });
}
sDate = DateTime.Now.ToShortDateString();
sDate2 = DateTime.Now.AddDays(-1).ToShortDateString();
CO2Multiplier = ObjRefs[CurrentBuilding].ElecCO2;
CarbonMultiplier = ObjRefs[CurrentBuilding].ElecCarbon;
try
{
decimal maxSample=0;
decimal consumption = 0;
foreach (var c in ElecDayData)
{
decimal dec;
if (Decimal.TryParse(c._day_data.ToString(), out dec))
{
consumption += dec;
if (dec > maxSample) maxSample = dec;
}
}
Value1 = Decimal.Round(consumption, 0).ToString() + " kWh";
Value2 = (Decimal.Round(consumption * Convert.ToDecimal(CO2Multiplier), 0).ToString()) + " kg";
//Value3 = (Decimal.Round((Convert.ToInt32((ElecDayData.Compute("sum(day_data)*" + CarbonMultiplier + "", "")))), 2).ToString()) + " kg";
TodayCO2 = Convert.ToDouble(Decimal.Round(consumption * Convert.ToDecimal(CO2Multiplier), 2).ToString());
decimal prevconsumption = 0;
foreach (var c in ElecPrevDayData)
{
decimal dec;
if (Decimal.TryParse(c._day_data.ToString(), out dec))
{
prevconsumption += dec;
if (dec > maxSample) maxSample = dec;
}
}
Value3 = Decimal.Round(prevconsumption, 0).ToString() + " kWh";
Value4 = (Decimal.Round(prevconsumption * Convert.ToDecimal(CO2Multiplier), 0).ToString()) + " kg";
//Value6 = (Decimal.Round((Convert.ToInt32((ElecPrevDayData.Compute("sum(day_data)*" + CarbonMultiplier + "", "")))), 2).ToString()) + " kg";
Chart1.AxesY[0].AxisMaximum = (maxSample + 1).ToString();
//Also add in the Axis Title at this point,X Axis Title is added in another Method
Chart1.AxesY[0].Title = "kWh";
// Set DataSeries property
Chart1.Series[0].LegendText = "On Hours (kWh)";
Chart1.Series[1].LegendText = "Off Hours (kWh)";
if (count == 0)
{
Chart1.Titles[0].Text = "Electricity Usage Today";
if (!Chart1Built)
{
foreach (var c in ElecDayData)
{
dataPoint = new DataPoint();
dataPoint.AxisXLabel = Convert.ToDateTime(c._Date).ToString("HH:mm");
// Update YValue property of the DataPoint
dataPoint.YValue = 0;
// Add dataPoint to DataPoints collection
Chart1.Series[0].DataPoints.Add(dataPoint);
dataPoint = null;
dataPoint = new DataPoint();
dataPoint.AxisXLabel = Convert.ToDateTime(c._Date).ToString("HH:mm");
// Update YValue property of the DataPoint
dataPoint.YValue = 0;
// Add dataPoint to DataPoints collection
Chart1.Series[1].DataPoints.Add(dataPoint);
dataPoint = null;
}
//Added in to allow animation of datapoints following series clearing
for (Int32 i = 0; i < ElecDayData.Count; i++)
{
Chart1.Series[0].DataPoints[i].YValue = ElecDayData[i]._OnHoursTotal;
Chart1.Series[1].DataPoints[i].YValue = ElecDayData[i]._OffHoursTotal;
}
}
else
{
for (Int32 i = 0; i < ElecDayData.Count; i++)
{
Chart1.Series[0].DataPoints[i].YValue = ElecDayData[i]._OnHoursTotal;
Chart1.Series[1].DataPoints[i].YValue = ElecDayData[i]._OffHoursTotal;
}
}
}
else
{
Chart1.Titles[0].Text = "Electricity Usage Yesterday";
if (!Chart1Built)
{
foreach (var c in ElecPrevDayData)
{
dataPoint = new DataPoint();
dataPoint.AxisXLabel = Convert.ToDateTime(c._Date).ToString("HH:mm");
// Update YValue property of the DataPoint
dataPoint.YValue = 0;
// Add dataPoint to DataPoints collection
Chart1.Series[0].DataPoints.Add(dataPoint);
dataPoint = null;
dataPoint = new DataPoint();
dataPoint.AxisXLabel = Convert.ToDateTime(c._Date).ToString("HH:mm");
// Update YValue property of the DataPoint
dataPoint.YValue = 0;
// Add dataPoint to DataPoints collection
Chart1.Series[1].DataPoints.Add(dataPoint);
dataPoint = null;
}
//Added in to allow animation of datapoints following series clearing
for (Int32 i = 0; i < ElecPrevDayData.Count; i++)
{
Chart1.Series[0].DataPoints[i].YValue = ElecPrevDayData[i]._OnHoursTotal;
Chart1.Series[1].DataPoints[i].YValue = ElecPrevDayData[i]._OffHoursTotal;
}
}
else
{
for (Int32 i = 0; i < ElecPrevDayData.Count; i++)
{
Chart1.Series[0].DataPoints[i].YValue = ElecPrevDayData[i]._OnHoursTotal;
Chart1.Series[1].DataPoints[i].YValue = ElecPrevDayData[i]._OffHoursTotal;
}
}
}
}
catch (Exception ex)
{
string msg = "Daily Electricity Chart Series Rendering Error: ";
msg += ex.InnerException.ToString();
throw new Exception(msg);
}
finally
{
if (!Chart1Built) { Chart1Grid.Children.Add(Chart1); }
Chart1Built = true;
//Chart1 = null;
//Chart1Day=null;
//Chart1PrevDay = null;
//Chart1AxisY = null;
}
}
AND
public void ODBCData(int Count)
{
tBox1Grid.Children.Clear();
tBox2Grid.Children.Clear();
tBox3Grid.Children.Clear();
tBox4Grid.Children.Clear();
try
{
if (Count == 1)
{
ElecPower = Convert.ToDouble(ODBCDatalist[CurrentBuilding].ElecPower);
ElecEquiv = Math.Round(((TodayCO2 / kgPerGallon) * MPG) / 100, 0);
//myGauge1.CurrentValue = Math.Round(ElecPower, 0);
txtStatus.Text = "Today, this Building has emitted the same CO2 as " + ElecEquiv.ToString() + " family Cars covering 100miles";
StatuxBox.Header = "Current Status - Electricity";
txtCost.Text = (Math.Round(ElecPower * Convert.ToDouble(ElecCostPerkWh), 2)).ToString() + " £/hr";
txtCO2.Text = (Math.Round(ElecPower * ElecCO2, 0)).ToString() + " kgCO2/h";
txtElecPower.Text = Math.Round(ElecPower, 1).ToString() + " kW";
transImg1.Source = img1;
transImg2.Source = img3;
transImg4.Source = img5;
}
if ((Count == 3) && (GasAvailable == 1))
{
GasPower = Convert.ToDouble(ODBCDatalist[CurrentBuilding].GasPower);
//GasGauge.CurrentValue = Math.Round(GasPower, 0);
GasCO2 = Math.Round((YesterdayGasUsage * GasCO2) * HomeCO2perYear, 4);
txtStatus.Text = "Yesterday, this Building emitted the equivalent CO2 of " + YesterdayGasCO2.ToString() + " Households Annual Emissions";
StatuxBox.Header = "Current Status - Gas";
txtCost.Text = (Math.Round(GasPower * Convert.ToDouble(GasCostPerkWh), 2)).ToString() + " £/h";
txtCO2.Text = (Math.Round(GasPower * GasCO2, 0)).ToString() + " kgCO2/h";
txtElecPower.Text = Math.Round(GasPower, 1).ToString() + " kW";
transImg1.Source = img2;
transImg2.Source = img4;
transImg4.Source = img5;
}
if (Count == 5)
{
ElecPower = Convert.ToDouble(ODBCDatalist[CurrentBuilding].ElecPower);
ElecEquiv = Math.Round(((ElecPower * 1000) / LaptopPower), 0);
//myGauge1.CurrentValue = Math.Round(ElecPower, 0);
txtStatus.Text = "Today this Building has used the Equivalent Power of " + ElecEquiv.ToString() + " 40-Watt Laptop(s) per hour";
StatuxBox.Header = "Current Status - Electricity";
txtCost.Text = (Math.Round((ElecPower * Convert.ToDouble(ElecCostPerkWh)) * 12, 2)).ToString() + " £/Day";
txtCO2.Text = (Math.Round((ElecPower * ElecCO2) * kgCoal, 0)).ToString() + " kg Coal/h";
txtElecPower.Text = Math.Round(ElecPower, 1).ToString() + " kW";
transImg1.Source = img7;
transImg2.Source = img3;
transImg4.Source = img6;
}
if (Count == 7)
{
ElecPower = Convert.ToDouble(ODBCDatalist[CurrentBuilding].ElecPower);
ElecEquiv = Math.Round(((ElecPower * 1000) / LaptopPower), 0);
//myGauge1.CurrentValue = Math.Round(ElecPower, 0);
txtStatus.Text = "Today this Building has used the Equivalent Power of " + ElecEquiv.ToString() + " 40-Watt Laptop(s) per hour";
StatuxBox.Header = "Current Status - Electricity";
txtCost.Text = (Math.Round((ElecPower * Convert.ToDouble(ElecCostPerkWh)) * 12, 2)).ToString() + " £/Day";
txtCO2.Text = (Math.Round((ElecPower * ElecCO2) * kgCoal, 0)).ToString() + " kg Coal/hr";
txtElecPower.Text = Math.Round(ElecPower, 1).ToString() + " kW";
transImg1.Source = img7;
transImg2.Source = img3;
transImg4.Source = img6;
}
if ((Count == 9) && (WaterAvailable == 1))
{
WaterEquiv = Math.Round(((TodayWater * 1000) / BathUsage), 0);
txtStatus.Text = "Today this Building has used enough water to fill " + WaterEquiv.ToString() + " Baths";
StatuxBox.Header = "Current Status - Water";
txtCost.Text = (Math.Round((WaterCurrentRate * WaterCostm3), 2)).ToString() + " £/hr";
txtCO2.Text = (Math.Round((WaterCurrentRate * 1000) / BathUsage, 0)).ToString() + " Baths/hr";
txtElecPower.Text = Math.Round(WaterCurrentRate, 1).ToString() + " m3/h";
transImg1.Source = img10;
transImg2.Source = img9;
transImg4.Source = img11;
}
transImg3.Source = img8;
}
catch (Exception ex)
{
string msg = "ODBC Data Collection Error: ";
msg += ex.InnerException.ToString(); ;
throw new Exception(msg);
}
finally
{
tBox1Grid.Children.Add(transImg1);
//System.Threading.Thread.Sleep(1000);
tBox2Grid.Children.Add(transImg2);
//System.Threading.Thread.Sleep(1000);
tBox3Grid.Children.Add(transImg3);
//System.Threading.Thread.Sleep(1000);
tBox4Grid.Children.Add(transImg4);
}
}
img1 = new BitmapImage(src1);
img2 = new BitmapImage(src2);
img3 = new BitmapImage(src3);
img4 = new BitmapImage(src4);
img5 = new BitmapImage(src5);
img6 = new BitmapImage(src6);
img7 = new BitmapImage(src7);
img8 = new BitmapImage(src8);
img9 = new BitmapImage(src9);
img10 = new BitmapImage(src10);
img11 = new BitmapImage(src11);
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
In SQL Server 2016, can we configure MASKing rules that applies for application level users ? | 12 | 57 | |
Install Problem | 13 | 31 | |
Sent email using Shared Mailbox from outlook in C# | 5 | 24 | |
C# bracket error | 3 | 31 |
Join the community of 500,000 technology professionals and ask your questions.