public StatisticsObj[] GetStatisticsAjax(string fact_no, string start_date, string end_date)
    {
        List<StatisticsObj> list = new List<StatisticsObj>();
        //string fact_no="", start_date="20140401",  end_date="20141201";
        fact_no = Request.Form["factno"];
        start_date = Request.Form["startdate"];
        end_date = Request.Form["enddate"];

        DataSet ds = GetStatistics(fact_no, start_date, end_date);
        DataTable dt = ds.Tables[0];//acc

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            DataRow dr = dt.Rows[i];

            string fact_no1 = dr["fact_no"].ToString();
            string floor = dr["floor"].ToString();
            string emp_no = dr["emp_no"].ToString();
            string user_desc = dr["user_desc"].ToString();
            string insp = dr["insp"].ToString();
            string acc = dr["acc"].ToString();
            string yyyymm = dr["yyyymm"].ToString();

            StatisticsObj obj = new StatisticsObj(fact_no1, floor, emp_no, user_desc, insp, acc, yyyymm);
            list.Add(obj);

        }

        return list.ToArray();
    }
    public static StatisticsObj[] GetStatisticsAjaxNew(string pfact_no, string start_date, string end_date)
    {
        List<StatisticsObj> list = new List<StatisticsObj>();
        List<CYYYYMM> listYM = new List<CYYYYMM>();
        //string pfact_no = "", start_date = "20140401", end_date = "20141201";

        try
        {

            DataSet ds = GetStatistics(pfact_no, start_date, end_date);

            DataTable dt = ds.Tables[0];//acc
            DataTable dt1 = ds.Tables[1];//insp

            DataColumnCollection dcs = dt.Columns;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow dr = dt.Rows[i];
                DataRow dr1 = dt1.Rows[i];

                string fact_no = dr["fact_no"].ToString();
                string floor = dr["floor"].ToString();
                string emp_no = dr["emp_no"].ToString();
                string user_desc = dr["user_desc"].ToString();
                string insp = "0";
                string acc = "0", sColName = "";

                //get yyyymm columns
                foreach (DataColumn dc in dcs)
                {
                    if (!CheckColumns(dc))
                    {
                        sColName = dc.ColumnName;
                        acc = dr[sColName].ToString();
                        insp = dr1[sColName].ToString();
                        CYYYYMM al = new CYYYYMM(sColName, acc, insp);//mang luu ten cot
                        listYM.Add(al);
                    }
                }

                StatisticsObj obj = new StatisticsObj(fact_no, floor, emp_no, user_desc, listYM);
                list.Add(obj);
                //reset listYM
                listYM = new List<CYYYYMM>();
            }
        }
        catch (Exception ex)
        {
        }

        return list.ToArray();
    }
        private void CreateList()
        {
            List <Tep_Sekvencia> tepList = null;

            try
            {
                tepList = _context.PulseSekv.ToList();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Cant find list pulse for selected time" + e.ToString());
            }
            List <Teplota_Sekvencia> tempList = null;

            try
            {
                tempList = _context.TemperatureSekv.ToList();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Cant find list temperature for selected time" + e.ToString());
            }

            /* try {
             * tepList = _context.PulseSekv.Where(p => DateTime.Parse(p.TimeStart) >= StartdateTime && DateTime.Parse(p.TimeStart) <= StopdateTime || DateTime.Parse(p.TimeStart) <= StartdateTime && DateTime.Parse(p.TimeClose) >= StartdateTime || DateTime.Parse(p.TimeStart) <= StopdateTime && DateTime.Parse(p.TimeClose) >= StopdateTime || DateTime.Parse(p.TimeStart) <= StartdateTime && DateTime.Parse(p.TimeClose) >= StopdateTime).ToList();
             * }
             * catch(Exception e)
             * {
             *   System.Diagnostics.Debug.WriteLine("Cant find list pulse for selected time" + e.ToString());
             *   try
             *   {
             *       tepList = _context.PulseSekv.Where(p => DateTime.Parse(p.TimeStart) <= StartdateTime).ToList();
             *   }
             *   catch (Exception ee)
             *   {
             *       System.Diagnostics.Debug.WriteLine("Cant find list pulse for selected time" + ee.ToString());
             *   }
             *
             *   System.Diagnostics.Debug.WriteLine("Cant find list pulse for selected time" + e.ToString());
             * }
             *
             *
             * foreach (var t in tepList) {
             *   System.Diagnostics.Debug.WriteLine("************ Pulse: " + t.TimeStart + " " + t.TimeClose + " " + t.Sekvencia);
             *
             * }
             * List<Teplota_Sekvencia> tempList = null;
             * try
             * {
             *   tempList = _context.TemperatureSekv.Where(p => DateTime.Parse(p.TimeStart) >= StartdateTime && DateTime.Parse(p.TimeStart) <= StopdateTime || DateTime.Parse(p.TimeStart) <= StartdateTime && DateTime.Parse(p.TimeClose) >= StartdateTime || DateTime.Parse(p.TimeStart) <= StopdateTime && DateTime.Parse(p.TimeClose) >= StopdateTime || DateTime.Parse(p.TimeStart) <= StartdateTime && DateTime.Parse(p.TimeClose) >= StopdateTime).ToList();
             * }
             * catch (Exception e)
             * {
             *   System.Diagnostics.Debug.WriteLine("Cant find list temperature for selected time" + e.ToString());
             *
             *   try
             *   {
             *       tempList = _context.TemperatureSekv.Where(p => DateTime.Parse(p.TimeStart) <= StartdateTime).ToList();
             *   }
             *   catch (Exception ee)
             *   {
             *       System.Diagnostics.Debug.WriteLine("Cant find list temperature for selected time" + ee.ToString());
             *
             *   }
             *
             * }*/


            foreach (var t in tempList)
            {
                System.Diagnostics.Debug.WriteLine("************ Temperature: " + t.TimeStart + " " + t.TimeClose + " " + t.Sekvencia);
            }

            DateTime myTime = StartdateTime;

            Helpers.SekvenceHelper.LimitCheck loader = new Helpers.SekvenceHelper.LimitCheck();

            while (myTime <= StopdateTime)
            {
                string tempVal   = "NA";
                string tempAlert = "";
                try
                {
                    foreach (var t in tempList)
                    {
                        if (DateTime.Parse(t.TimeStart).TimeOfDay <= myTime.TimeOfDay && DateTime.Parse(t.TimeStart).Date == DateTime.Parse(_roomStatistics.StartDate))
                        {
                            if (t.TimeClose.Equals(""))
                            {
                                tempVal   = t.Sekvencia.ToString("n2") + " °C";
                                tempAlert = loader.getStringValuePulseAndTempLimit(t.Upozornenie);
                                if (!teplotaListConst.Contains(t))
                                {
                                    teplotaListConst.Add(t);
                                }
                                break;
                            }
                            else if (TimeSpan.Compare(DateTime.Parse(t.TimeClose).TimeOfDay, myTime.TimeOfDay) >= 0)
                            {
                                tempVal   = t.Sekvencia.ToString("n2") + " °C";
                                tempAlert = loader.getStringValuePulseAndTempLimit(t.Upozornenie);
                                if (!teplotaListConst.Contains(t))
                                {
                                    teplotaListConst.Add(t);
                                }
                                break;
                            }
                            else
                            {
                                tempVal   = "NA";
                                tempAlert = "";
                            }
                        }
                    }

/*
 *                  var temp = tempList.Where(p => DateTime.Parse(p.TimeStart).TimeOfDay <= myTime.TimeOfDay && DateTime.Parse(p.TimeClose).TimeOfDay >= myTime.TimeOfDay).First();
 *
 *                  tempVal = temp.Sekvencia.ToString("n2") + " °C";
 *                  tempAlert = loader.getStringValuePulseAndTempLimit(temp.Upozornenie);*/
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("Cant find value for selected time" + e.ToString());

                    /* try
                     * {
                     *   var temp = tempList.Where(p => DateTime.Parse(p.TimeStart) <= myTime && p.TimeClose == "").First();
                     *
                     *   tempVal = temp.Sekvencia.ToString("n2") + " °C";
                     *   tempAlert = loader.getStringValuePulseAndTempLimit(temp.Upozornenie);
                     * }
                     * catch (Exception ee)
                     * {
                     *   System.Diagnostics.Debug.WriteLine("Cant find value for selected time" + ee.ToString());
                     *
                     * }*/
                }

                string pulseVal   = "NA";
                string pulseAlert = "";

                try
                {
                    /* var pulse = tepList.Where(p => DateTime.Parse(p.TimeStart) <= myTime && DateTime.Parse(p.TimeClose) >= myTime).First();
                     * pulseVal = pulse.Sekvencia.ToString() + " BPM";
                     * pulseAlert = loader.getStringValuePulseAndTempLimit(pulse.Upozornenie);*/
                    foreach (var t in tepList)
                    {
                        if (DateTime.Parse(t.TimeStart).TimeOfDay <= myTime.TimeOfDay && DateTime.Parse(t.TimeStart).Date == DateTime.Parse(_roomStatistics.StartDate))
                        {
                            if (t.TimeClose.Equals(""))
                            {
                                pulseVal   = t.Sekvencia.ToString() + " BPM";
                                pulseAlert = loader.getStringValuePulseAndTempLimit(t.Upozornenie);
                                if (!tepListConst.Contains(t))
                                {
                                    tepListConst.Add(t);
                                }
                                break;
                            }
                            else if (TimeSpan.Compare(DateTime.Parse(t.TimeClose).TimeOfDay, myTime.TimeOfDay) >= 0)
                            {
                                pulseVal   = t.Sekvencia.ToString() + " BPM";
                                pulseAlert = loader.getStringValuePulseAndTempLimit(t.Upozornenie);
                                if (!tepListConst.Contains(t))
                                {
                                    tepListConst.Add(t);
                                }
                                break;
                            }
                            else
                            {
                                pulseVal   = "NA";
                                pulseAlert = "";
                            }
                        }
                    }
                } catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("Cant find value for selected time" + e.ToString());

                    /* try
                     * {
                     *   var pulse = tepList.Where(p => DateTime.Parse(p.TimeStart) <= myTime).First();
                     *   pulseVal = pulse.Sekvencia.ToString() + " BPM";
                     *   pulseAlert = loader.getStringValuePulseAndTempLimit(pulse.Upozornenie);
                     *
                     * }
                     * catch (Exception ee)
                     * {
                     *   System.Diagnostics.Debug.WriteLine("Cant find value for selected time" + ee.ToString());
                     *
                     * }*/
                }

                string fallValue = "";
                try
                {
                    var fall = fallList.Where(p => DateTime.Parse(p.TimeStamp) >= myTime && DateTime.Parse(p.TimeStamp) <= myTime.AddMinutes(1)).First();
                    if (fall != null)
                    {
                        fallValue = "Áno";
                    }
                    //System.Diagnostics.Debug.WriteLine("find value for selected time fall " + fall.TimeStamp);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("Cant find value for selected time fall " + e.ToString());
                }

                StatisticsObj statisticsObj = new StatisticsObj
                {
                    Time             = myTime.ToShortTimeString(),
                    PulseValue       = pulseVal,
                    PulseAlert       = pulseAlert,
                    TemperatureValue = tempVal,
                    TemperatureAlert = tempAlert,
                    isFall           = fallValue
                };

                StatsList.Add(statisticsObj);

                //  System.Diagnostics.Debug.WriteLine("--- LIST ---" + myTime + " " + pulseVal + " " + pulseAlert + " " + tempVal + " " + tempAlert + " " + fallValue);

                myTime = myTime.AddMinutes(1);
            }
            //StatsList = new ObservableCollection<StatisticsObj>(StatsList.Reverse());
        }