/// <summary>
 /// //切换台风
 /// </summary>
 private void lstTyphoons_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (timer != null)
     {
         timer.Stop();
         this.btnPlay.IsEnabled = true;
     }
     lstboxTyphoons.Visibility = Visibility.Hidden;
     if (lstboxTyphoons.SelectedIndex == -1)
     {
         return;
     }
     cTyphoon = typhoonList[lstboxTyphoons.SelectedIndex];
     canvasShow.Children.Clear();
     typhoonInitial();
 }
        /// <summary>
        /// //台风列表初始化
        /// </summary>
        private void typhoonlistInitial()
        {
            string         reqMsg  = "typhoon Time " + (DateTime.Now.Year - 2).ToString() + " Time 2014-01-01-00 2014-12-31-24";
            TyphoonRequest request = new TyphoonRequest(reqMsg);

            typhoonList = TyphServer.GetTyphoonData(request);
            if (typhoonList == null)
            {
                MessageBox.Show("与服务器连接异常,没有找到所需的数据");
                btnPlay.IsEnabled = false;
                return;
            }
            for (int i = 0; i < typhoonList.Count; i++)
            {
                Label temp = new Label();
                temp.Content = typhoonList[i].header.typhName;
                lstboxTyphoons.Items.Add(temp);
            }
            cTyphoon = typhoonList[0];
            typhoonInitial();
        }
        /// <summary>
        /// //从最佳路径数据中读取台风数据并转换为MOST模型
        /// </summary>
        private List <CMostTyphoon> GetTyphoon(string fileName)
        {
            List <CMostTyphoon> MOSTTyphoons = new List <CMostTyphoon>();
            StreamReader        sr           = new StreamReader(fileName);

            while (true)                        //依次从文件中读取台风路径数据
            {
                CMostTyphoon typh = new CMostTyphoon();
                if (typh.ReadTyphoon(sr))
                {
                    MOSTTyphoons.Add(typh);
                }
                else
                {
                    break;
                }
            }
            sr.Close();
            sr.Dispose();
            return(MOSTTyphoons);
        }
        /// <summary>
        /// //根据台风路径请求获取台风路径数据
        /// </summary>
        public static List <CMostTyphoon> GetTyphoonData(TyphoonRequest req)
        {
            DataSet          dtset       = new DataSet(); //从数据库中得到检索数据
            MySqlDataAdapter mydbadapter = CMyTyphoonSQL.GetTyphoon(req.SQL);

            mydbadapter.Fill(dtset, "result");
            DataTable           dt = dtset.Tables["result"];
            List <CMostTyphoon> typhoons = new List <CMostTyphoon>();     //生成台风数据集合
            int i = 0, n = dt.Rows.Count;

            if (n == 0)
            {
                return(null);
            }
            CMostTyphoon typh = new CMostTyphoon();
            int          id = (int)dt.Rows[0]["ID"];

            SetTyphoonHeader(typh, dt.Rows[0]);        //设置第一条台风数据头
            for (i = 0; i < n; i++)
            {
                if (id != (int)dt.Rows[i]["ID"])         //如果id号不一样,则说明为另一条台风数据
                {
                    id = (int)dt.Rows[i]["ID"];
                    typh.InitMostModel();
                    typhoons.Add(typh);
                    typh = new CMostTyphoon();
                    SetTyphoonHeader(typh, dt.Rows[i]);
                    typh.points.Add(GetTyphoonPoint(dt.Rows[i]));
                }
                else                          //否则读取台风路径点对象
                {
                    typh.points.Add(GetTyphoonPoint(dt.Rows[i]));
                }
            }
            typhoons.Add(typh);
            typh.InitMostModel();
            dtset.Dispose();
            return(typhoons);
        }
Exemple #5
0
        /// <summary>
        /// //响应搜索台风按钮的事件
        /// </summary>
        private void Search_Click(object sender, RoutedEventArgs e)
        {
            canvasShow.Children.Clear();
            string reqMsg = MySearchControl.GetRequest();

            if (reqMsg == "typhoon Wrong")
            {
                MessageBox.Show("查询请求不正确");
                btnPlay.IsEnabled = false;
                return;
            }
            else if (reqMsg.Contains("search"))
            {
                string   timeText = reqMsg.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries)[1];
                DateTime datetime = DateTime.Parse(timeText);
                if (cTyphoon.POINTSNUM != 0)
                {
                    typhoonInitial();
                    pFTDQ = cTyphoon.FullTimeDomainInquiry(datetime);
                    if (pFTDQ == null)
                    {
                        MessageBox.Show("查询过程出错", "全时域查询结果", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    else
                    {
                        MessageBox.Show(datetime.ToString("yyyy-MM-dd HH:mm:ss") + ",台风位于(" + pFTDQ.latitude.ToString("F4") + "," + pFTDQ.longitude.ToString("F4") + ")", "全时域查询结果", MessageBoxButton.OK, MessageBoxImage.Information);
                        Point point0 = new Point();
                        point0.X = (pFTDQ.longitude - minLong) / (maxLong - minLong) * canvasShow.Width;
                        point0.Y = canvasShow.Height - (pFTDQ.latitude - minLat) / (maxLat - minLat) * canvasShow.Height;
                        Ellipse tp = new Ellipse();
                        tp.Height          = 10 / scale;
                        tp.Width           = 10 / scale;
                        tp.Fill            = Brushes.Red;
                        tp.Stroke          = Brushes.Black;
                        tp.StrokeThickness = 1 / scale;
                        Canvas.SetLeft(tp, point0.X - 5 / scale);
                        Canvas.SetTop(tp, point0.Y - 5 / scale);
                        Canvas.SetZIndex(tp, 2);
                        canvasShow.Children.Add(tp);
                    }
                }
                return;
            }
            TyphoonRequest request = new TyphoonRequest(reqMsg);

            ctyphoonlist = TyphServer.GetTyphoonData(request);
            lstBoxTyphoons.Items.Clear();
            if (ctyphoonlist == null)
            {
                MessageBox.Show("没有符合查询条件的台风");
                btnPlay.IsEnabled = false;
                return;
            }
            for (int i = 0; i < ctyphoonlist.Count; i++)
            {
                Label temp = new Label();
                temp.Content = ctyphoonlist[i].header.typhName;
                lstBoxTyphoons.Items.Add(temp);
            }
            cTyphoon          = ctyphoonlist[0];
            btnPlay.IsEnabled = true;
            typhoonInitial();
        }
 /// <summary>
 /// //设置台风信息头
 /// </summary>
 public static void SetTyphoonHeader(CMostTyphoon typh, DataRow row)
 {
     typh.SetHeaderMsg((int)row["ID"], (int)row["END"], (int)row["INTERVAL"], (string)row["NAME"], (int)row["POINTNUM"]);
 }