public Chargers GetChargerInfo(int ChargingStationID)
        {
            var connectionString = ConfigurationManager.ConnectionStrings["PCanRepository"].ConnectionString;
            string sql = "SELECT CustomerID,	CustomerName,	FileGrp,	ChargingStationID,	Location from dbo.ChargingStationsVw with(nolock) where [email protected]";
            Chargers c = new Chargers();

            using (SqlConnection con = new SqlConnection(connectionString))
            {

                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Parameters.Add("@ChargingStationID", SqlDbType.Int);
                cmd.Parameters["@ChargingStationID"].Value = ChargingStationID;
                try
                {
                    con.Open();
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {

                        c.ChargingStationID = int.Parse(reader["ChargingStationID"].ToString());
                        c.CustomerID = int.Parse(reader["CustomerID"].ToString());
                        c.Location = reader["Location"].ToString();
                        c.CustomerName = reader["CustomerName"].ToString();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                return c;
            }
        }
        private void Display_ChargingStatus_Faults(Chargers Charger, int WeekNumer, int YearNumer)
        {
            GetChartData gd = new GetChartData();
            DataTable dataTable = gd.Ct_GetWeeklyChargingFails(Charger.ChargingStationID, WeekNumer, YearNumer);

            //  string mainTitle = string.Format("Vehicle Efficiency  - {0}", dt.ToString("MM/dd/yy"));
            //  string subTitle = string.Format("{0} - {1}", v.CustomerName, v.Vin);
            string mainTitle = Charger.Location.ToUpper().ToString() + " - Charger Fails";
            string subTitle = "Week Number " + WeekNumer + ", " + YearNumer;

            hcFrutas.Title = new Title(mainTitle);
            hcFrutas.SubTitle = new SubTitle(subTitle);

            hcFrutas.Theme = "grid";
            hcFrutas.Legend = new Legend { align = Align.right, layout = Layout.vertical, verticalAlign = VerticalAlign.top, x = -10, y = 70, borderWidth = 0 };
            hcFrutas.Appearance = new Appearance { renderTo = "container", animation = false };
            //   hcFrutas.YAxis.Add(new YAxisItem { title = new Title("Time Percentage") });

            //Get point collection
            var pointCollectionVinEfficiency = new PointCollection();
            var pointCollectionCat = new PointCollection();
            //var pointCollectionSocMax = new PointCollection();
            //var pointCollectionSocDas = new PointCollection();

            List<string> buckets = new List<string>();

            // Add string using Add method

            Int32 totalArraySize = dataTable.Rows.Count;
            Object[] XAxisData = new object[totalArraySize];
            Object[] YAxisServices = new object[totalArraySize];
            int J = 0;
            foreach (DataRow drRow in dataTable.Rows)
            {

                YAxisServices[J] = new object[] { drRow[0].ToString(), Convert.ToInt32(drRow[1].ToString()) };
                J += 1;
            }

            SerieCollection series = new SerieCollection();
            Serie serieServices = new Serie();
            serieServices.size = 150;
            // serieServices.cumulative = -0.25;
            serieServices.data = YAxisServices;
            serieServices.type = RenderType.pie;
            serieServices.name = "";
            serieServices.showInLegend = false;
            series.Add(serieServices);

            hcFrutas.PlotOptions = new Highcharts.Core.PlotOptions.PlotOptionsPie
            {
                allowPointSelect = true,
                cursor = "pointer",

                startAngle = 60,
                dataLabels = new Highcharts.Core.PlotOptions.DataLabels { enabled = true, formatter = "this.point.name +': ['+ this.y  + ']'" },
                animation = false
            };

            hcFrutas.Tooltip = new ToolTip("this.point.name +': '+ this.y ");
            hcFrutas.DataSource = series;
            hcFrutas.DataBind();
            hcFrutas.Dispose();
        }
        private void ReportServices_DailyGrab_GenChargerData_ChargerHist(Chargers v, int WeekNumber, int YearNumber)
        {
            GetChartData gd = new GetChartData();

            DataTable DtRange = gd.GetDateRangeFromWeekNumber(WeekNumber, YearNumber);
            DataTable dataTable = gd.Dt_DailyGrab_GetChargerStatusHist(v.ChargingStationID, WeekNumber, YearNumber, Rounding);

            string mainTitle = string.Format("Chrg Status - {0} - {1}  ", Convert.ToDateTime(DtRange.Rows[0]["StartDate"]).ToString("d"), Convert.ToDateTime(DtRange.Rows[0]["EndDate"]).ToString("d"));

            string subTitle = string.Format("{0} - {1}", v.CustomerName, v.ChargingStationID);
               hcFrutas.Title = new Title(mainTitle);
               hcFrutas.SubTitle = new SubTitle(subTitle);
               hcFrutas.Width = 800;
               hcFrutas.Theme = "grid";
               hcFrutas.Legend = new Legend { align = Align.right, layout = Layout.vertical, verticalAlign = VerticalAlign.top, x = -10, y = 70, borderWidth = 0 };
               hcFrutas.Appearance = new Appearance { renderTo = "container", animation = false };
               hcFrutas.YAxis.Add(new YAxisItem { title = new Title("Chrg Status") });

            //Get point collection
            var pointCollectionChgStatusCnt = new PointCollection();

            var pointCollectionChg_TotalDocking = new PointCollection();
            var pointCollectionChg_Complete = new PointCollection();
            var pointCollectionChg_Fail = new PointCollection();
            var pointCollectionChg_OpErrors = new PointCollection();
            var pointCollectionChg_OpAborts = new PointCollection();

            var pointCollectionCat = new PointCollection();
            //var pointCollectionSocMax = new PointCollection();
            //var pointCollectionSocDas = new PointCollection();

            List<string> buckets = new List<string>();
            List<string> status = new List<string>();

            // Add string using Add method

            foreach (DataRow row in dataTable.Rows)
            {
                pointCollectionChg_TotalDocking.Add(new Point(Convert.ToDouble(row["TotalDocking"])));
                pointCollectionChg_Complete.Add(new Point(row["Complete"]));
                pointCollectionChg_Fail.Add(new Point(row["Fail"]));
                pointCollectionChg_OpErrors.Add(new Point(row["OpErrors"]));
                pointCollectionChg_OpAborts.Add(new Point(row["OpAborts"]));

                buckets.Add(row["DateLabel"].ToString());
                //status.Add(row["col"].ToString());

            }

            //Add data to serie
               hcFrutas.XAxis.Add(new XAxisItem { type = AxisDataType.linear, tickColor = "#ccc", categories = buckets.ToArray(), tickLength = 1, title = new Title("Date") });

               var series = new Collection<Serie> { new Serie { name = "TotalDocking",  data = pointCollectionChg_TotalDocking.ToArray(), type = RenderType.column, showInLegend = true } ,
                                                new Serie { name = "Complete",      data = pointCollectionChg_Complete.ToArray(), type = RenderType.column, showInLegend = true } ,
                                                new Serie { name = "Fail",          data = pointCollectionChg_Fail.ToArray(), type = RenderType.column, showInLegend = true } ,
                                                new Serie { name = "OpErrors",      data = pointCollectionChg_OpErrors.ToArray(), type = RenderType.column, showInLegend = true } ,
                                                new Serie { name = "OpAborts",      data = pointCollectionChg_OpAborts.ToArray(), type = RenderType.column, showInLegend = true }
               };

             //  var series = new Collection<Serie> { new Serie { name = "Charge Status", data = pointCollectionChgStatusCnt.ToArray(), type = RenderType.column, showInLegend = false }, new Serie { name = "Charge", data = pointCollectionCat.ToArray(), type = RenderType.column, showInLegend = false } };
               // var series = new Collection<Serie> { new Serie { name = "SocMin", data = pointCollectionSocMin.ToArray() }, new Serie { name = "SocMax", data = pointCollectionSocMax.ToArray() }, new Serie { name = "SocDash", data = pointCollectionSocDas.ToArray() } };

            //hcVendas.PlotOptions = new PlotOptionsLine { marker = new Marker { enabled = true }, dataLabels = new DataLabels { enabled = true } };
               hcFrutas.PlotOptions = new PlotOptionsColumn
               {
               groupPadding = 0,
               pointPadding = 0,
               shadow = true,
               borderWidth = 2,
               borderColor = "#666",
            //   dataLabels = new DataLabels { enabled = true ,formatter="function() { if(this.y != 0) { return this.y;}}"}
               dataLabels = new DataLabels { enabled = true }

               };

            //Bind the control
               hcFrutas.DataSource = series;
               hcFrutas.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //int ChargingStationID = 18;
            //int Rounding = 0;
            //DateTime dt = DateTime.Parse("07/29/2015");
            //int WeekNumber = 31;
            //int YearNumer = 2015;

            int intWeekNumber = 0;
            int intYearNumber = 0;
            int intChargingStationID = 0;

            string ChargingStationID = Request.QueryString["ChargingStationID"].ToString();

            string ProcessDate = String.Empty;
            DateTime dtProcessDate = DateTime.Today;
            if (!string.IsNullOrWhiteSpace(Request.QueryString["ProcessDate"]))
            {
                ProcessDate = Request.QueryString["ProcessDate"].ToString();
                dtProcessDate = DateTime.Parse(ProcessDate);
            }

            string ReportType = String.Empty;
            if (!string.IsNullOrWhiteSpace(Request.QueryString["ReportType"]))
            {
                ReportType = Request.QueryString["ReportType"].ToString();
            }

            string WeekNumber = String.Empty;
            if (!string.IsNullOrWhiteSpace(Request.QueryString["WeekNumber"]))
            {
                WeekNumber = Request.QueryString["WeekNumber"].ToString();
            }

            string YearNumber = String.Empty;
            if (!string.IsNullOrWhiteSpace(Request.QueryString["YearNumber"]))
            {
                YearNumber = Request.QueryString["YearNumber"].ToString();
            }

            string ReportPeriod = String.Empty;
            if (!string.IsNullOrWhiteSpace(Request.QueryString["ReportPeriod"]))
            {
                ReportPeriod = Request.QueryString["ReportPeriod"].ToString();
            }

            Chargers Charger = new Chargers();

            if (ChargingStationID != "")
            {

                bool IsChargerNumeric = int.TryParse(ChargingStationID, out intChargingStationID);

                if (IsChargerNumeric)
                {
                    intChargingStationID = int.Parse(ChargingStationID);

                    GetChartData gcd = new GetChartData();

                    Charger = gcd.GetChargerInfo(intChargingStationID);

                }

                bool IsWeekNumeric = int.TryParse(WeekNumber, out intWeekNumber);
                if (IsWeekNumeric)
                {
                    intWeekNumber = int.Parse(WeekNumber);
                }

                bool IsYearNumeric = int.TryParse(YearNumber, out intYearNumber);
                if (IsYearNumeric)
                {
                    intYearNumber = int.Parse(YearNumber);
                }

                if (ReportType == "ChargerStatus")
                {

                    Display_ChargingStatus_All(Charger, intWeekNumber, intYearNumber);
                }
                else if (ReportType == "ChargerFails")
                {
                    Display_ChargingStatus_Faults(Charger, intWeekNumber, intYearNumber);
                }

            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string VinID =string.Empty;

            if (!String.IsNullOrEmpty(Request.QueryString["VinID"]))
            {
                VinID = Request.QueryString["VinID"].ToString();

            }

            string ChargingStationID = string.Empty;

            if (!String.IsNullOrEmpty(Request.QueryString["ChargingStationID"]))
            {
                ChargingStationID = Request.QueryString["ChargingStationID"].ToString();

            }

            string ProcessDate = String.Empty;
            DateTime dtProcessDate = DateTime.Today;
            if (!string.IsNullOrWhiteSpace(Request.QueryString["ProcessDate"]))
            {
                ProcessDate = Request.QueryString["ProcessDate"].ToString();
                dtProcessDate = DateTime.Parse(ProcessDate);
            }

            string ReportType = String.Empty;
            if (!string.IsNullOrWhiteSpace(Request.QueryString["ReportType"]))
            {
                ReportType = Request.QueryString["ReportType"].ToString();
            }

            string WeekNumber = String.Empty;
            if (!string.IsNullOrWhiteSpace(Request.QueryString["WeekNumber"]))
            {
                WeekNumber = Request.QueryString["WeekNumber"].ToString();
            }

            string YearNumber = String.Empty;
            if (!string.IsNullOrWhiteSpace(Request.QueryString["YearNumber"]))
            {
                YearNumber = Request.QueryString["YearNumber"].ToString();
            }

            string ReportPeriod = String.Empty;
            if (!string.IsNullOrWhiteSpace(Request.QueryString["ReportPeriod"]))
            {
                ReportPeriod = Request.QueryString["ReportPeriod"].ToString();
            }

            int intWeekNumber = 0;
            int intYearNumber = 0;

            string DtRangeWeekly = String.Empty;
            if (ReportPeriod == "Weekly" || ReportPeriod == "NREL")
            {
                bool IsWeekNumeric = int.TryParse(WeekNumber, out intWeekNumber);
                if (IsWeekNumeric)
                {
                    intWeekNumber = int.Parse(WeekNumber);
                }

                bool IsYearNumeric = int.TryParse(YearNumber, out intYearNumber);
                if (IsYearNumeric)
                {
                    intYearNumber = int.Parse(YearNumber);
                }

                GetChartData gd = new GetChartData();
                DataTable DtRange = gd.GetDateRangeFromWeekNumber(intWeekNumber, intYearNumber);

                DtRangeWeekly = Convert.ToDateTime(DtRange.Rows[0]["StartDate"]).ToString("d") + " - " + Convert.ToDateTime(DtRange.Rows[0]["EndDate"]).ToString("d");
            }

            //string ReportType = Request.QueryString["ReportType"].ToString();
            //string ReportPeriod = Request.QueryString["ReportPeriod"].ToString();
            //string WeekNumber = Request.QueryString["WeekNumber"].ToString();
            //string YearNumber = Request.QueryString["YearNumber"].ToString();

            //VinID = "221";
            //  ReportType = "GenVehicleData_VinSpeed";
            //ReportType = "GenVehicleData_CurrentVoltage";
            //ProcessDate = "04/13/2015";
            //DateTime dtProcessDate = DateTime.Parse(ProcessDate);

            Vehicles Vehicle = new Vehicles();

            if (VinID != "")
            {
                int intVinID;
                bool IsVinNumeric = int.TryParse(VinID, out intVinID);

                if (IsVinNumeric)
                {
                    intVinID = int.Parse(VinID);

                    GetChartData gcd = new GetChartData();
                    Vehicle = gcd.GetVinInfo(intVinID);

                }
                else
                {
                    Response.Write(" Vehicle does not exists!");
                    Response.End();
                }

            }
            //else
            //{
            //    Response.Write(" Vehicle does not exists!");
            //    Response.End();
            //}

            Chargers Charger = new Chargers();
            int intChargingStationID = 0;

            if (ChargingStationID != "")
            {

                bool IsChargerNumeric = int.TryParse(ChargingStationID, out intChargingStationID);

                if (IsChargerNumeric)
                {
                    intChargingStationID = int.Parse(ChargingStationID);

                    GetChartData gcd = new GetChartData();
                    Charger = gcd.GetChargerInfo(intChargingStationID);

                }
                else
                {
                    Response.Write(" Charger does not exists!");
                    Response.End();
                }

            }
            //else
            //{
            //    Response.Write(" Charger does not exists!");
            //    Response.End();
            //}

            switch (ReportType)
            {

                case "GenVehicleData_VinSpeedHist":
                    if (ReportPeriod == "Weekly" || ReportPeriod == "NREL")
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinSpeedHist(Vehicle, intWeekNumber, intYearNumber);
                    }
                    else
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinSpeedHist(Vehicle, dtProcessDate);
                    }

                    break;

                case "GenVehicleData_VinEfficiencyHist":
                     if (ReportPeriod == "Weekly" || ReportPeriod == "NREL")
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinEfficiencyHist(Vehicle, intWeekNumber, intYearNumber);
                    }
                    else
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinEfficiencyHist(Vehicle, dtProcessDate);
                    }

                    break;

                case "GenVehicleData_VinAccelPedalHist":
                     if (ReportPeriod == "Weekly" || ReportPeriod == "NREL")
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinAccelPedalHist(Vehicle, intWeekNumber, intYearNumber);
                    }
                    else
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinAccelPedalHist(Vehicle, dtProcessDate);
                    }

                    break;

                case "GenVehicleData_VinBrakePedalHist":
                    if (ReportPeriod == "Weekly" || ReportPeriod == "NREL")
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinBrakePedalHist(Vehicle, intWeekNumber, intYearNumber);
                    }
                    else
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinBrakePedalHist(Vehicle, dtProcessDate);
                    }

                    break;

                case "GenVehicleData_VinChargingHist":
                    if (ReportPeriod == "Weekly" || ReportPeriod == "NREL")
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinChargingHist(Vehicle, intWeekNumber, intYearNumber);
                    }
                    else
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinChargingHist(Vehicle, dtProcessDate);
                    }

                    break;

                case "GenVehicleData_VinVoltageHist":
                    if (ReportPeriod == "Weekly" || ReportPeriod == "NREL")
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinVoltageHist(Vehicle, intWeekNumber, intYearNumber);
                    }
                    else
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinVoltageHist(Vehicle, dtProcessDate);
                    }

                    break;

                case "GenVehicleData_VinSocMinHist":
                     if (ReportPeriod == "Weekly" || ReportPeriod == "NREL")
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinSocMinHist(Vehicle, intWeekNumber, intYearNumber);
                    }
                    else
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinSocMinHist(Vehicle, dtProcessDate);
                    }

                    break;

                case "GenVehicleData_VinBatteryTempMaxHist":
                    if (ReportPeriod == "Weekly" || ReportPeriod == "NREL")
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinBatteryTempMaxHist(Vehicle, intWeekNumber, intYearNumber);
                    }
                    else
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinBatteryTempMaxHist(Vehicle, dtProcessDate);
                    }

                    break;

                case "GenVehicleData_VinPECoolantTempHist":
                     if (ReportPeriod == "Weekly" || ReportPeriod == "NREL")
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinPECoolantTempHist(Vehicle, intWeekNumber, intYearNumber);
                    }
                    else
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinPECoolantTempHist(Vehicle, dtProcessDate);
                    }

                    break;

                case "GenVehicleData_VinDCDCConverterPowerHist":
                     if (ReportPeriod == "Weekly" || ReportPeriod == "NREL")
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinDCDCConverterPowerHist(Vehicle, intWeekNumber, intYearNumber);
                    }
                    else
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinDCDCConverterPowerHist(Vehicle, dtProcessDate);
                    }

                    break;

                case "GenVehicleData_VinTractionMotorRotorTempHist":
                    if (ReportPeriod == "Weekly" || ReportPeriod == "NREL")
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinTractionMotorRotorTempHist(Vehicle, intWeekNumber, intYearNumber);
                    }
                    else
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinTractionMotorRotorTempHist(Vehicle, dtProcessDate);
                    }

                    break;

                case "GenVehicleData_VinStatorTempHist":
                     if (ReportPeriod == "Weekly" || ReportPeriod == "NREL")
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinStatorTempHist(Vehicle, intWeekNumber, intYearNumber);
                    }
                    else
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinStatorTempHist(Vehicle, dtProcessDate);
                    }

                    break;

                case "GenVehicleData_VinTractionMotorInverterTempHist":
                     if (ReportPeriod == "Weekly" || ReportPeriod == "NREL")
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinTractionMotorInverterTempHist(Vehicle, intWeekNumber, intYearNumber);
                    }
                    else
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinTractionMotorInverterTempHist(Vehicle, dtProcessDate);
                    }

                    break;

                case "GenVehicleData_VinTractionMotorIGBTTempHist":
                    if (ReportPeriod == "Weekly" || ReportPeriod == "NREL")
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinTractionMotorIGBTTempHist(Vehicle, intWeekNumber, intYearNumber);
                    }
                    else
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinTractionMotorIGBTTempHist(Vehicle, dtProcessDate);
                    }

                    break;

                case "GenVehicleData_VinRadiatorFanSpeedHist":
                    if (ReportPeriod == "Weekly" || ReportPeriod == "NREL")
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinRadiatorFanSpeedHist(Vehicle, intWeekNumber, intYearNumber);
                    }
                    else
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinRadiatorFanSpeedHist(Vehicle, dtProcessDate);
                    }

                    break;

                case "GenVehicleData_VinBatteryCoolantPumpHist":
                    if (ReportPeriod == "Weekly" || ReportPeriod == "NREL")
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinBatteryCoolantPumpHist(Vehicle, intWeekNumber, intYearNumber);
                    }
                    else
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinBatteryCoolantPumpHist(Vehicle, dtProcessDate);
                    }

                    break;

                case "GenVehicleData_VinMinAirPressureHist":
                     if (ReportPeriod == "Weekly" || ReportPeriod == "NREL")
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinMinAirPressureHist(Vehicle, intWeekNumber, intYearNumber);
                    }
                    else
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinMinAirPressureHist(Vehicle, dtProcessDate);
                    }

                    break;

                case "GenVehicleData_VinTransTempHist":
                     if (ReportPeriod == "Weekly" || ReportPeriod == "NREL")
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinTransTempHist(Vehicle, intWeekNumber, intYearNumber);
                    }
                    else
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinTransTempHist(Vehicle, dtProcessDate);
                    }

                    break;

                case "GenVehicleData_VinChgEnergyHist":
                    if (ReportPeriod == "Weekly" || ReportPeriod == "NREL")
                    {
                        ReportServices_DailyGrab_GenVehicleData_VinChgEnergyHist(Vehicle, intWeekNumber, intYearNumber);
                    }
                    else
                    {
                        //do nothing
                    }

                    break;

                    case "GenVehicleData_ChargerStatusHist":
                    if (ReportPeriod == "Weekly")
                    {
                        ReportServices_DailyGrab_GenChargerData_ChargerHist(Charger, intWeekNumber, intYearNumber);
                    }
                    else
                    {
                        //do nothing
                    }

                    break;

                default:
                    Response.Write(" Chart Type does not exists!");
                    break;
            }
        }