Ejemplo n.º 1
0
        public List <WindData> DataList(WindData data)
        {
            var list = new List <WindData>();

            list.Add(data);
            return(list);
        }
Ejemplo n.º 2
0
        public List <WindData> ReadFromExcel(string path)
        {
            // Get the input file paths
            FileInfo inputFile = new FileInfo(path);

            //Create a worksheet
            FastExcel.Worksheet worksheet = null;

            // Create an instance of Fast Excel
            using (FastExcel.FastExcel fastExcel = new FastExcel.FastExcel(inputFile, true))
            {
                // Read the rows using worksheet name
                worksheet = fastExcel.Read("Sheet1");

                worksheet = fastExcel.Read(1);
                list      = worksheet.Rows.ToArray().ToList();
                foreach (var item in list)
                {
                    windData = new WindData();
                    foreach (var cellItem in item.Cells)
                    {
                        if (item.RowNumber != 1)
                        {
                            switch (cellItem.ColumnNumber)
                            {
                            case 1:
                                windData.year = cellItem.Value.ToString();
                                break;

                            case 2:
                                windData.month = cellItem.Value.ToString();
                                break;

                            case 3:
                                windData.day = cellItem.Value.ToString();
                                break;

                            case 4:
                                windData.timeUTC = cellItem.Value.ToString();
                                break;

                            case 5:
                                windData.windSpeed = cellItem.Value.ToString();
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    if (item.RowNumber != 1)
                    {
                        listData.Add(FixDirection(windData));
                    }
                }
            }

            return(listData);
        }
Ejemplo n.º 3
0
 public void InsertDB(WindData item)
 {
     if (list.Count != 0)
     {
         Wind w = new Wind();
         w.Date      = item.day;
         w.Speed     = item.windSpeed;
         w.Direction = item.direction;
         db.Winds.InsertOnSubmit(w);
         //db.SubmitChanges();
     }
 }
Ejemplo n.º 4
0
        public WindData FixDirection(WindData data)
        {
            if (data.windSpeed != "")
            {
                if (data.windSpeed != null)
                {
                    string[] arr = data.windSpeed.Split('/');
                    data.windSpeed = arr[0].Trim();
                    data.direction = "/" + arr[1];
                }
            }

            return(data);
        }
Ejemplo n.º 5
0
        public string FixDate(WindData item)
        {
            string time  = "";
            string month = "";
            string day   = "";
            string year  = "";


            year = item.year.Replace("20", "").Trim();

            if (int.Parse(item.month) < 10)
            {
                month = "0" + item.month;
            }
            else
            {
                month = item.month;
            }

            if (int.Parse(item.day) < 10)
            {
                day = "0" + item.day;
            }
            else
            {
                day = item.day;
            }


            if (int.Parse(item.timeUTC) < 10)
            {
                time = "0" + item.timeUTC + ":00";
            }
            else
            {
                time = item.timeUTC + ":00";
            }

            return(day + "-" + month + "-" + year + " " + time);
        }