Ejemplo n.º 1
0
        public async Task SaveWeatherMsg(List <IWeatherMsg> msglist, string name)
        {
            List <string> sqllist = new List <string>();
            int           id      = db.GetAreaIDByName(name);

            if (id == 0)
            {
                MessageBox.Show("该地区暂无天气信息");
                return;
            }
            for (int i = 0; i < msglist.Count; i++)
            {
                string sql;
                if (msglist[i].flag == 1)//小时
                {
                    WeatherHoursMsg hoursMsg = msglist[i] as WeatherHoursMsg;
                    sql =
                        String.Format(
                            "INSERT INTO HoursRainInfo ([day],[time],[temperature],[rains],[wind],[windL],[humidity],[AreaID]) VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')",
                            hoursMsg.day, hoursMsg.time, hoursMsg.temperature, hoursMsg.rains, hoursMsg.wind, hoursMsg.windL,
                            hoursMsg.humidity, id);
                }
                else
                {
                    WeatherDayMsg dayMsg = msglist[i] as WeatherDayMsg;
                    sql =
                        String.Format(
                            "INSERT INTO DayRainInfo ([time],[maxTemp],[minTemp],[wind],[windL],[alarmmsg],[weatherStatus],[AreaID]) VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')",
                            dayMsg.time, dayMsg.maxTemp, dayMsg.minTemp, dayMsg.wind, dayMsg.windL, dayMsg.alarmmsg,
                            dayMsg.weatherStatus, id);
                }
                sqllist.Add(sql);
            }
            db.insertToAccessByBatch(sqllist);
        }