/// <summary> /// 矩形查询 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PUButton_Click_19(object sender, RoutedEventArgs e) { if (!(Regex.IsMatch(XMaxTextBox.Text, "^[\\d.]+$") && Regex.IsMatch(XMinTextBox.Text, "^[\\d.]+$") && Regex.IsMatch(YMaxTextBox.Text, "^[\\d.]+$") && Regex.IsMatch(YMinTextBox.Text, "^[\\d.]+$"))) { PUMessageBox.ShowDialog("输入的内容不符合规范"); return; } string sql = "xAsis < " + XMaxTextBox.Text + " AND xAsis > " + XMinTextBox.Text + " AND yAsis < " + YMaxTextBox.Text + " AND yAsis > " + YMinTextBox.Text; bool searchResult = DataHelper.SearchData("BikePnts", sql, "RectangleSearchResult"); if (searchResult == true) { Fields Flds = null; Field Fld = null; long ID = 0; Record Rcd = null; //变量初始化 Rcd = new Record(); Flds = new Fields(); Server svr = new Server(); //连接数据源 svr.Connect("MapGISLocal", "", ""); DataBase GDB = svr.OpenGDB("Templates"); SFeatureCls SFCls = new SFeatureCls(GDB); SFCls.Open("RectangleSearchResult", 0); //获取属性结构 Flds = SFCls.Fields; if (Flds == null) { SFCls.Close(); SearchTabControl.Visibility = Visibility.Collapsed; SearchResultGrid.Visibility = Visibility.Collapsed; NoResultGrid.Visibility = Visibility.Visible; return; } int num = Flds.Count; //目的类对象的个数 int objnum = SFCls.Count; //获取所有对象的ID,思想是根据对象的个数进行循环,若OID不存在,则OID自加继续循环直到循环objnum次 int n = 0; ID = 1; string[] listItem = new string[8]; SearchListView.Items.Clear(); while (n < objnum) { //取得ID=ID.Int的简单要素的属性 Rcd = SFCls.GetAtt(ID); //取得属性结构对象中的字段数目 if (Rcd != null) { Flds = Rcd.Fields; listItem[0] = ID.ToString(); //获取对应属性字段的值 for (int i = 0; i < num; i++) { object val = null; Fld = Flds.GetItem(i); string name = Fld.FieldName; val = Rcd.get_FldVal(name); listItem[i + 1] = ((val != null) ? val.ToString() : ""); } n++; SearchListView.Items.Add(new { BikeID = listItem[3], Time = listItem[4].Substring(9), XAsis = listItem[6].Substring(0, 8), YAsis = listItem[7].Substring(0, 8) }); } ID++; } SFCls.Close(); SearchTabControl.Visibility = Visibility.Collapsed; SearchResultGrid.Visibility = Visibility.Visible; NoResultGrid.Visibility = Visibility.Collapsed; } else { SearchTabControl.Visibility = Visibility.Collapsed; SearchResultGrid.Visibility = Visibility.Collapsed; NoResultGrid.Visibility = Visibility.Visible; } }
/// <summary> /// 搜索 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click_1(object sender, RoutedEventArgs e) { SearchListView.Visibility = Visibility.Collapsed; RideChart.Visibility = Visibility.Collapsed; OnedayChart.Visibility = Visibility.Collapsed; BackgroundStackPanel.Visibility = Visibility.Collapsed; NoResultStackPanel.Visibility = Visibility.Collapsed; SearchListView.Items.Clear(); bool searchResult = DataHelper.SearchData("BikePnts", "BikeID = '" + SearchTextBox.Text + "'", "SearchTemp"); if (searchResult == true) { Fields Flds = null; Field Fld = null; long ID = 0; Record Rcd = null; //变量初始化 Rcd = new Record(); Flds = new Fields(); Server svr = new Server(); //连接数据源 svr.Connect("MapGISLocal", "", ""); DataBase GDB = svr.OpenGDB("Templates"); SFeatureCls SFCls = new SFeatureCls(GDB); SFCls.Open("SearchTemp", 0); //获取属性结构 Flds = SFCls.Fields; if (Flds == null) { SFCls.Close(); OnedayChart.Visibility = Visibility.Collapsed; RideChart.Visibility = Visibility.Collapsed; SearchListView.Visibility = Visibility.Collapsed; BackgroundStackPanel.Visibility = Visibility.Collapsed; NoResultStackPanel.Visibility = Visibility.Visible; return; } int num = Flds.Count; //目的类对象的个数 int objnum = SFCls.Count; //获取所有对象的ID,思想是根据对象的个数进行循环,若OID不存在,则OID自加继续循环直到循环objnum次 int n = 0; ID = 1; string[] listItem = new string[8]; while (n < objnum) { //取得ID=ID.Int的简单要素的属性 Rcd = SFCls.GetAtt(ID); //取得属性结构对象中的字段数目 if (Rcd != null) { Flds = Rcd.Fields; listItem[0] = ID.ToString(); //获取对应属性字段的值 for (int i = 0; i < num; i++) { object val = null; Fld = Flds.GetItem(i); string name = Fld.FieldName; val = Rcd.get_FldVal(name); listItem[i + 1] = ((val != null) ? val.ToString() : ""); } n++; SearchListView.Items.Add(new { OID = listItem[0], BikeID = listItem[3], Time = listItem[4].Substring(9), XAsis = listItem[6].Substring(0, 8), YAsis = listItem[7].Substring(0, 8) }); } ID++; } SFCls.Close(); SearchListView.Visibility = Visibility.Visible; } else { OnedayChart.Visibility = Visibility.Collapsed; RideChart.Visibility = Visibility.Collapsed; SearchListView.Visibility = Visibility.Collapsed; BackgroundStackPanel.Visibility = Visibility.Collapsed; NoResultStackPanel.Visibility = Visibility.Visible; } }
/// <summary> /// 获取单车的距离和时间统计 /// </summary> /// <param name="bikes"></param> /// <returns></returns> public static List <BikeSearchViewModel> GetLengthNTimeData(string className, string bikeid) { List <BikeSearchViewModel> searchResult = new List <BikeSearchViewModel>(); bool haveResult = DataHelper.SearchData("BikePnts", "BikeID = '" + bikeid + "'", bikeid + "Temp"); if (haveResult == false) { return(null); } Fields Flds = null; Field Fld = null; long ID = 0; Record Rcd = null; //变量初始化 Rcd = new Record(); Flds = new Fields(); Server svr = new Server(); //连接数据源 svr.Connect("MapGISLocal", "", ""); DataBase GDB = svr.OpenGDB("Templates"); SFeatureCls tmpSFCls = new SFeatureCls(GDB); tmpSFCls.Open(bikeid + "Temp", 0); //获取属性结构 Flds = tmpSFCls.Fields; if (Flds == null) { tmpSFCls.Close(); return(null); } int num = Flds.Count; //目的类对象的个数 int objnum = tmpSFCls.Count; //获取所有对象的ID,思想是根据对象的个数进行循环,若OID不存在,则OID自加继续循环直到循环objnum次 int n = 0; ID = 1; string[] listItem = new string[8]; while (n < objnum) { //取得ID=ID.Int的简单要素的属性 Rcd = tmpSFCls.GetAtt(ID); //取得属性结构对象中的字段数目 if (Rcd != null) { Flds = Rcd.Fields; listItem[0] = ID.ToString(); //获取对应属性字段的值 for (int j = 0; j < num; j++) { object val = null; Fld = Flds.GetItem(j); string name = Fld.FieldName; val = Rcd.get_FldVal(name); listItem[j + 1] = ((val != null) ? val.ToString() : ""); } n++; BikeSearchViewModel bike = new BikeSearchViewModel { BikeID = listItem[3], Time = Convert.ToDateTime(listItem[4].Substring(9)), XAsis = Convert.ToDouble(listItem[6].Substring(0, 8)), YAsis = Convert.ToDouble(listItem[7].Substring(0, 8)) }; searchResult.Add(bike); } ID++; } tmpSFCls.Close(); return(searchResult); }
/// <summary> /// 导入数据后显示地图 /// </summary> private void ShowMaps() { MapGrid.Visibility = Visibility.Visible; BackgroundGrid.Visibility = Visibility.Collapsed; MapGIS.UI.Controls.MapWorkSpaceTree _Tree = new MapGIS.UI.Controls.MapWorkSpaceTree(); //地图文档 Document doc = _Tree.Document; if (doc.Close(false)) { OpenFileDialog mapxDialog = new OpenFileDialog(); mapxDialog.Filter = ".mapx(地图文档)|*.mapx|.map(地图文档)|*.map|.mbag(地图包)|*.mbag"; if (mapxDialog.ShowDialog() != DialogResult.OK) { return; } string mapUrl = mapxDialog.FileName; //打开地图文档 doc.Open(mapUrl); } Maps maps = doc.GetMaps(); if (maps.Count > 0) { //获取当前第一个地图 Map map = maps.GetMap(0); //设置地图的第一个图层为激活状态 map.get_Layer(0).State = LayerState.Active; this.WuhanMapControl.ActiveMap = map; this.WuhanMapControl.Restore(); } else { return; } disp = WuhanMapControl.Display; userDrawGeoInfo = disp.GetUserDrawGeoInfo(); pntInfo = userDrawGeoInfo.GetPntInfo(); EditGeomInfoForm pntInfoForm = new EditGeomInfoForm((VectorLayer)null, pntInfo); if (pntInfoForm.ShowDialog() == DialogResult.OK) { } pntInfoForm.Dispose(); //画点 Fields Flds = null; Field Fld = null; long ID = 0; Record Rcd = null; //变量初始化 Rcd = new Record(); Flds = new Fields(); Server svr = new Server(); //连接数据源 svr.Connect("MapGISLocal", "", ""); DataBase GDB = svr.OpenGDB("Templates"); SFeatureCls SFCls = new SFeatureCls(GDB); SFCls.Open("BikePnts", 0); //获取属性结构 Flds = SFCls.Fields; if (Flds == null) { SFCls.Close(); return; } int num = Flds.Count; //目的类对象的个数 int objnum = SFCls.Count; //获取所有对象的ID,思想是根据对象的个数进行循环,若OID不存在,则OID自加继续循环直到循环objnum次 int n = 0; ID = 1; string[] listItem = new string[8]; while (n < objnum) { //取得ID=ID.Int的简单要素的属性 Rcd = SFCls.GetAtt(ID); //取得属性结构对象中的字段数目 if (Rcd != null) { Flds = Rcd.Fields; listItem[0] = ID.ToString(); //获取对应属性字段的值 for (int i = 0; i < num; i++) { object val = null; Fld = Flds.GetItem(i); string name = Fld.FieldName; val = Rcd.get_FldVal(name); listItem[i + 1] = ((val != null) ? val.ToString() : ""); } n++; Dot dot = new Dot(); dot.X = Convert.ToDouble(listItem[6]); dot.Y = Convert.ToDouble(listItem[7]); DrawPoint(dot); } ID++; } SFCls.Close(); }