我做的WPF
<Window x:Class="test.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:h="clr-namespace:test" Title="地理信息数据转换系统" Height="500" Width="900" Loaded="Window_Loaded"> <Window.Resources> <XmlDataProvider x:Key="xml" Source="XMLData.xml"> </XmlDataProvider> </Window.Resources> <Grid> <Border Margin="0,0,557.77,0"> <TreeView Margin="0,0,-0.115,0" Name="TreeVI"> <TreeViewItem> <TreeViewItem.HeaderTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <Image Width="25" Height="25" Source="Images/数据连接.png" /> <TextBlock Text="数据库连接" RenderTransformOrigin="0.445,1.247" Height="17.446" FontWeight="Bold" /> </StackPanel> </DataTemplate> </TreeViewItem.HeaderTemplate> <TreeViewItem Selected="TreeViewItem_Selected"> <TreeViewItem.HeaderTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <Image Width="25" Height="25" Source="Images/新建数据连接.png" /> <TextBlock Text="新建数据库连接" RenderTransformOrigin="0.445,1.247" Height="17.446" FontWeight="Bold" /> </StackPanel> </DataTemplate> </TreeViewItem.HeaderTemplate> </TreeViewItem> <TreeViewItem BorderThickness="0" Name="three" ItemsSource="{Binding Source={StaticResource xml},XPath=/Person/Information/Address}" Selected="three_Selected"> <TreeViewItem.HeaderTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <Image Width="25" Height="25" Source="Images/经纬网.png" /> <TextBlock Text="已连接记录" RenderTransformOrigin="0.445,1.247" Height="17.446" FontWeight="Bold" /> </StackPanel> </DataTemplate> </TreeViewItem.HeaderTemplate> <TreeViewItem.ContextMenu> <ContextMenu> <MenuItem Header="删除" Click="MenuItem_Click_2"> </MenuItem> </ContextMenu> </TreeViewItem.ContextMenu> </TreeViewItem> <TreeViewItem Visibility="Hidden" Name="tv"> <TreeViewItem> <TreeViewItem.HeaderTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <Image Width="25" Height="25" Source="Images/坐标信息.png" /> <TextBlock Text="矢量瓦片数据集" RenderTransformOrigin="0.445,1.247" Height="17.446" FontWeight="Bold" /> </StackPanel> </DataTemplate> </TreeViewItem.HeaderTemplate> <ListView BorderThickness="0" Name="Lv"> <ListView.ContextMenu> <ContextMenu> <MenuItem Header="显示当前视图" Click="MenuItem_Click"> </MenuItem> <MenuItem Header="删除"> </MenuItem> </ContextMenu> </ListView.ContextMenu> </ListView> </TreeViewItem> <TreeViewItem> <TreeViewItem.HeaderTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <Image Width="25" Height="25" Source="Images/经纬网.png" /> <TextBlock Text="影像瓦片数据集" RenderTransformOrigin="0.445,1.247" Height="17.446" FontWeight="Bold" /> </StackPanel> </DataTemplate> </TreeViewItem.HeaderTemplate> <ListView BorderThickness="0" Name="Lv1"> <ListView.ContextMenu> <ContextMenu> <MenuItem Header="显示当前视图" Click="MenuItem_Click_1"> </MenuItem> <MenuItem Header="删除"> </MenuItem> </ContextMenu> </ListView.ContextMenu> </ListView> </TreeViewItem> </TreeViewItem> </TreeViewItem> <TreeViewItem> <TreeViewItem.HeaderTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <Image Width="25" Height="25" Source="Images/文件数据连接.png" /> <TextBlock Text="文件数据连接" RenderTransformOrigin="0.445,1.247" Height="17.446" FontWeight="Bold" /> </StackPanel> </DataTemplate> </TreeViewItem.HeaderTemplate> <TreeViewItem Selected="Document_Selected"> <TreeViewItem.HeaderTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <Image Width="25" Height="25" Source="Images/连接文件夹.png" /> <TextBlock Text="新建数据库连接" RenderTransformOrigin="0.445,1.247" Height="17.446" FontWeight="Bold" /> </StackPanel> </DataTemplate> </TreeViewItem.HeaderTemplate> </TreeViewItem> <TreeView Name="Tv" BorderThickness="0"> </TreeView> </TreeViewItem> </TreeView> </Border> <Border Margin="234.23,0,0,0"> <WindowsFormsHost Name="test" Margin="-14.925,0,0.23,0" /> </Border> </Grid> </Window>
using GeoDataFieldCheck.Help; using GGeoTileDatasetManager; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Forms; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using test.DataContent; namespace test { public partial class MainWindow : Window { //全局变量m-Geo; public static AxGeoSpaceLib.AxGeoSpace m_Geo; //滚轮包装 CMouseWheelZoom m_MouseWheelZoom = null; private void m_Geo_GeoMouseWheel(object sender, AxGeoSpaceLib._DGeoSpaceEvents_GeoMouseWheelEvent e) { m_MouseWheelZoom.MouseWheelDelta(e.zDelta, 0, 0); } private void m_MouseWheelZoom_OnViewEnvlopeChange(GeoStarCore.IEnvelope vEnv) { MainWindow.m_Geo.ViewEnvelope = vEnv; MainWindow.m_Geo.Update(); } public MainWindow() { InitializeComponent(); //获取计算机上的驱动 SystemMenu.load(Tv); } private void Window_Loaded(object sender, RoutedEventArgs e) { GeoSpace gg = new GeoSpace(); test.Child = gg; MainWindow.m_Geo.GeoMouseWheel += m_Geo_GeoMouseWheel; //滚轮事件 m_MouseWheelZoom = new CMouseWheelZoom(MainWindow.m_Geo.LayoutBox.MapFrame.Map as GeoStarCore.IActiveView); m_MouseWheelZoom.OnViewEnvlopeChange += new CMouseWheelZoom.ViewEnvlopeChange(m_MouseWheelZoom_OnViewEnvlopeChange); m_MouseWheelZoom.WheelUpZoomIn = true; //ShowViewinfo(); } //定义全局变量获取传过来的值 DatasetMeta m_Meta; private void TreeViewItem_Selected(object sender, RoutedEventArgs e) { Window1 w = new Window1(); w.ShowDialog(); //获取传递进来的参数 m_Meta = w.GetData(); Lv.Items.Clear(); GeoGlobeDataManager.IEnumTileProviderName pEnumName = FunctionClass.ConnectionInfo(m_Meta.DataBase, m_Meta.UserName, m_Meta.Password); GeoGlobeDataManager.ITileProviderName pProviderName = pEnumName.Next(); if (pProviderName != null) { tv.Visibility = System.Windows.Visibility.Visible; tv.Header = m_Meta.UserName + "." + m_Meta.ServerName + "." + m_Meta.DataBaseName; } while (pProviderName != null) { //判断是否为矢量数据类型 if (GetType(pProviderName.Type) == "矢量") { Lv.Items.Add(pProviderName.Name); pProviderName = pEnumName.Next(); } //判断是否为影像数据类型 else if(GetType(pProviderName.Type)=="影像") { Lv1.Items.Add(pProviderName.Name); pProviderName = pEnumName.Next(); } } } //打开文件数据 private void Document_Selected(object sender, RoutedEventArgs e) { FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog(); DialogResult result = folderBrowserDialog.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { //txt.Text = folderBrowserDialog.SelectedPath; } } //判断要加载的空间数据类型 private string GetType(GeoGlobeDataManager.enumTileDataSetType nType) { switch (nType) { case GeoGlobeDataManager.enumTileDataSetType.eImageDs: return "影像"; case GeoGlobeDataManager.enumTileDataSetType.eTerrainDs: return "地形"; case GeoGlobeDataManager.enumTileDataSetType.ePreRaserVectorDs: return "矢量"; } return ""; } //矢量数据右键选中当前值显示 private void MenuItem_Click(object sender, RoutedEventArgs e) { FunctionClass.ViewDisplay(m_Meta.DataBase, m_Meta.UserName, m_Meta.Password, Lv.SelectedItem.ToString()); } //影像数据右键选中当前值显示 private void MenuItem_Click_1(object sender, RoutedEventArgs e) { FunctionClass.ViewDisplay(m_Meta.DataBase, m_Meta.UserName, m_Meta.Password, Lv1.SelectedItem.ToString()); } private void MenuItem_Click_2(object sender, RoutedEventArgs e) { TreeViewItem item = TreeVI.SelectedItem as TreeViewItem; TreeVI.Items.Remove(item); TreeVI.UpdateLayout(); } private void three_Selected(object sender, RoutedEventArgs e) { Window1 w = new Window1(); string str = TreeVI.SelectedValue.ToString(); w.ServerName.Text = str.Substring(str.IndexOf(".") + 1, 14); w.DataName.Text = str.Substring(str.LastIndexOf(".") + 1); w.UserName.Text = str.Substring(0, str.IndexOf(".")); w.Name.Text = str; w.ShowDialog(); } } }
<Window x:Class="test.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="350" Width="480" Title="连接数据库" ResizeMode="NoResize" MouseDown="Window_MouseDown"> <Window.Resources> <XmlDataProvider x:Key="xml" Source="XMLData.xml"> </XmlDataProvider> </Window.Resources> <StackPanel> <Grid x:Name="连接数据库" Margin="0,0,0,-1.439"> <Label Content="名称" HorizontalAlignment="Left" Margin="29,10,0,0" VerticalAlignment="Top"/> <TextBox x:Name="Name" HorizontalAlignment="Left" Height="23" Margin="95.136,13,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="327.194" /> <GroupBox Header="连接信息" Margin="10,42,10,60.968"> <Canvas Margin="-15.827,-34.014,-2,45.396" > <Label Content="数据库类型" HorizontalAlignment="Left" Margin="13.136,41,0,0" VerticalAlignment="Top"/> <TextBlock x:Name="DataType" HorizontalAlignment="Left" Margin="100.136,46,0,0" TextWrapping="Wrap" Text="Oracle数据库" VerticalAlignment="Top" Width="115" Height="24.618"/> <Label Content="服务器名称" HorizontalAlignment="Left" Margin="13.136,72,0,0" VerticalAlignment="Top" RenderTransformOrigin="-0.27,0.326"/> <ComboBox x:Name="ServerName" ItemsSource="{Binding Source={StaticResource xml},XPath=/Person/Student/Infor/IP}" HorizontalAlignment="Left" Margin="95.136,76,0,0" VerticalAlignment="Top" Width="327.194" IsEditable="True"/> <Label Content="数据库名称" HorizontalAlignment="Left" Margin="13.136,107,0,0" VerticalAlignment="Top"/> <ComboBox x:Name="DataName" ItemsSource="{Binding Source={StaticResource xml},XPath=/Person/Student/Infor/DataBaseName}" HorizontalAlignment="Left" Margin="95.136,107,0,0" VerticalAlignment="Top" Width="327.194" IsEditable="True"/> <Label Content="用户名" HorizontalAlignment="Left" Margin="25.136,134,0,0" VerticalAlignment="Top"/> <Label Content="密码" HorizontalAlignment="Left" Margin="29,165,0,0" VerticalAlignment="Top"/> <Label Content="端口号" HorizontalAlignment="Left" Margin="25.136,193,0,0" VerticalAlignment="Top"/> <TextBox x:Name="Port" HorizontalAlignment="Left" Height="23" Margin="95.136,196,0,0" TextWrapping="Wrap" Text="1521" VerticalAlignment="Top" Width="327.194"/> <PasswordBox x:Name="PassWord" HorizontalAlignment="Left" Margin="95.136,165,0,0" VerticalAlignment="Top" Width="327.194"/> <Button Content="+" Name="btn" HorizontalAlignment="Left" VerticalAlignment="Top" Width="28.958" RenderTransformOrigin="1.656,1.13" Canvas.Left="433" Canvas.Top="-13" Height="26.316" Click="btn_Click"/> <CheckBox Content="" Canvas.Left="433" Canvas.Top="165" Height="20" Width="24.827"/> <ComboBox x:Name="UserName" ItemsSource="{Binding Source={StaticResource xml}, XPath=/Person/Student/Infor/UserName}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="327.194" IsEditable="True" Canvas.Left="95.136" Canvas.Top="136"/> </Canvas> </GroupBox> <Button Content="测试连接" HorizontalAlignment="Left" Width="75" Canvas.Left="13.136" Canvas.Top="249.303" Margin="10,280.407,0,0.032" Click="Button_Click_1"/> <Button Content="确定" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Click="Button_Click" Canvas.Left="274.101" Canvas.Top="249" RenderTransformOrigin="-0.255,0.42" Margin="307,280.407,0,0"/> <Button Content="取消" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Canvas.Left="354" Canvas.Top="249" Margin="387,280.407,0,0" Click="Button_Click_2"/> </Grid> <Popup Name="pp" IsOpen="False" Placement="Right" Margin="0,0,123.381,0" > <ListView AlternationCount="2" Name="Tv" ItemsSource="{Binding Source={StaticResource xml},XPath=/Person/Student/Infor}" Height="238.173" Width="227.105" SelectionChanged="Tv_SelectionChanged" ScrollViewer.CanContentScroll="False"> <ListView.ItemContainerStyle> <Style TargetType="ListViewItem"> <Style.Triggers> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="ItemsControl.AlternationIndex" Value="1"/> <Condition Property="IsSelected" Value="False" /> <Condition Property="IsMouseOver" Value="False" /> </MultiTrigger.Conditions> <Setter Property="Background" Value="LightCyan"/> </MultiTrigger> </Style.Triggers> </Style> </ListView.ItemContainerStyle> </ListView> </Popup> </StackPanel> </Window>
1 using GGeoTileDatasetManager; 2 using System; 3 using System.Collections.Generic; 4 using System.IO; 5 using System.Linq; 6 using System.Text; 7 using System.Windows; 8 using System.Windows.Controls; 9 using System.Windows.Data; 10 using System.Windows.Documents; 11 using System.Windows.Input; 12 using System.Windows.Media; 13 using System.Windows.Media.Imaging; 14 using System.Windows.Shapes; 15 using System.Xml; 16 17 namespace test 18 { 19 /// <summary> 20 /// Window1.xaml 的交互逻辑 21 /// </summary> 22 public partial class Window1 : Window 23 { 24 public Window1() 25 { 26 InitializeComponent(); 27 init(); 28 29 } 30 public void init() 31 { 32 ServerName.Text = Properties.Settings.Default.Server; 33 DataName.Text = Properties.Settings.Default.Database; 34 UserName.Text = Properties.Settings.Default.Username; 35 } 36 public void Rinit() 37 { 38 Properties.Settings.Default.Server=ServerName.Text; 39 Properties.Settings.Default.Database=DataName.Text; 40 Properties.Settings.Default.Username=UserName.Text; 41 Properties.Settings.Default.Save(); 42 } 43 private DatasetMeta dt; 44 public void Button_Click(object sender, RoutedEventArgs e) 45 { 46 dt = new DatasetMeta(ServerName.Text, DataName.Text, int.Parse(Port.Text), 47 UserName.Text, PassWord.Password, "", 0); 48 Rinit(); 49 if (dt != null) 50 { 51 SaveData(); 52 } 53 this.Close(); 54 } 55 //保存数据 56 private void SaveData() 57 { 58 XmlDocument xml = new XmlDocument(); 59 string str_path = @"J:\WPF\test\XMLData.xml"; 60 XmlNode root = null; 61 if (File.Exists(str_path)) 62 { 63 xml.Load(str_path); 64 root = xml.SelectSingleNode("Person"); 65 } 66 67 XmlNodeList nodelist = xml.SelectNodes("/Person/Student/Infor"); 68 XmlElement inf,adr, stu, info, UN, IP, DB; 69 bool bl_exist = true; 70 foreach (XmlNode node in nodelist) 71 { 72 if (node.ChildNodes[1].InnerText == (ServerName.Text + ".").ToString() && 73 node.ChildNodes[0].InnerText == (UserName.Text + ".").ToString() && 74 node.ChildNodes[2].InnerText ==DataName.Text) 75 { 76 bl_exist = false; 77 break; 78 } 79 } 80 if (bl_exist) 81 { 82 stu = xml.CreateElement("Student"); //创建元素 83 info = xml.CreateElement("Infor"); 84 UN = xml.CreateElement("UserName"); 85 IP = xml.CreateElement("IP"); 86 DB = xml.CreateElement("DataBaseName"); 87 88 inf = xml.CreateElement("Information"); 89 adr = xml.CreateElement("Address"); 90 adr.InnerText = (UserName.Text + "." + ServerName.Text + "." + DataName.Text).ToString(); 91 root.AppendChild(inf); 92 inf.AppendChild(adr); 93 94 UN.InnerText = (UserName.Text + ".").ToString(); 95 IP.InnerText = (ServerName.Text + ".").ToString(); 96 DB.InnerText = DataName.Text; 97 stu.AppendChild(info); 98 info.AppendChild(UN); 99 info.AppendChild(IP); 100 info.AppendChild(DB); 101 root.AppendChild(stu); 102 MessageBox.Show("数据保存成功"); 103 } 104 xml.Save(str_path); 105 } 106 //返回数据 107 public DatasetMeta GetData() 108 { 109 return dt; 110 } 111 112 //关闭窗体 113 private void Button_Click_2(object sender, RoutedEventArgs e) 114 { 115 this.Close(); 116 } 117 //测试连接 118 private void Button_Click_1(object sender, RoutedEventArgs e) 119 { 120 System.Threading.Thread.Sleep(2000); 121 MessageBox.Show("测试成功"); 122 } 123 124 private void btn_Click(object sender, RoutedEventArgs e) 125 { 126 pp.IsOpen = true; 127 } 128 129 private void Window_MouseDown(object sender, MouseButtonEventArgs e) 130 { 131 pp.IsOpen = false; 132 } 133 134 private void Tv_SelectionChanged(object sender, SelectionChangedEventArgs e) 135 { 136 string str= Tv.SelectedValue.ToString(); 137 ServerName.Text = str.Substring(str.IndexOf(".") + 1,14); 138 DataName.Text=str.Substring(str.LastIndexOf(".")+1); 139 UserName.Text=str.Substring(0, str.IndexOf(".")); 140 Name.Text = str; 141 } 142 } 143 }