Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string strAccessConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Faks\Diploma\vs2015\DemoMPE\DemoMPE\App_Data\Asfaltna_baza.mdb";
            string strAccessSelect = "SELECT * FROM gorivo";

            DataSet myDataSet = new DataSet();
            OleDbConnection myAccessConn = null;
            try
            {
                myAccessConn = new OleDbConnection(strAccessConn);
            }
            catch (Exception ex)
            {
                LabelTotalText.Text = $"Error: Failed to create a database connection. \n{ex.Message}";
                return;
            }

            try
            {
                OleDbCommand myAccessCommand = new OleDbCommand(strAccessSelect, myAccessConn);
                OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myAccessCommand);

                myAccessConn.Open();
                myDataAdapter.Fill(myDataSet, "gorivo");
            }
            catch (Exception ex)
            {
                LabelTotalText.Text = $"Error: Failed to retrieve the required data from the DataBase.\n{ex.Message}";
                return;
            }
            finally
            {
                myAccessConn.Close();
            }

            DataRowCollection dra = myDataSet.Tables["gorivo"].Rows;

            object[,] dataFill = new object[dra.Count, 2];
            for (int j = 0; j < dra.Count; j++)
            {
                dataFill[j, 0] = dra[j][1];
                dataFill[j, 1] = Convert.ToDecimal(dra[j][6]);
            }

            Series serie = new Series { Data = new Data(dataFill) };
            Highstock chart = new Highstock("chart");
            chart.SetSeries(serie);
            chart.SetYAxis(new YAxis { Labels = new YAxisLabels { Formatter = "function() { return Highcharts.numberFormat(this.value, 2) ;}" } });
            chart.SetTooltip(new Tooltip { PointFormat = "Value: {point.y:.2f}" });

            ltrChartGas.Text = chart.ToHtmlString();
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            GasContext _db = new GasContext();
            IQueryable<DateTime> gasPricesDate = _db.GasPrices
                .Select(x => x.gasDate);
            var gd = gasPricesDate.ToArray();
            var gds = new string[gd.Length];
            for (int i = 0; i < gd.Length; i++)
            {
                gds[i] = Conversion.getTime(gd[i]).ToString();
            }

            IQueryable<decimal> gasPricesPrice = _db.GasPrices
                .Select(x => x.gasPrice);
            var gp = gasPricesPrice.ToArray();
            var gps = new decimal[gp.Length];
            for (int i = 0; i < gp.Length; i++)
            {
                gps[i] = gp[i];
            }

            object[,] dataFill = new object[gasPricesDate.Count(), 2];
            for (int i = 0; i < gasPricesDate.Count(); i++)
            {
                dataFill[i, 0] = gds[i];
                dataFill[i, 1] = gps[i];
            }

            Series serie = new Series { Data = new Data(dataFill) };
            Highstock chart = new Highstock("chart");
            chart.SetSeries(serie);
            chart.SetYAxis(new YAxis { Labels = new YAxisLabels { Formatter = "function() { return Highcharts.numberFormat(this.value, 2) ;}" } });
            chart.SetTooltip(new Tooltip { PointFormat = "Value: {point.y:.2f}" });

            ltrChartGasPrice.Text = chart.ToHtmlString();
        }