logo资料库

supermap 做插件开发.doc

第1页 / 共21页
第2页 / 共21页
第3页 / 共21页
第4页 / 共21页
第5页 / 共21页
第6页 / 共21页
第7页 / 共21页
第8页 / 共21页
资料共21页,剩余部分请下载后查看
Supermap 二次开发 做插件 注意:图片仅是辅助作用,此处以文字为主 1. 添 加 项 目 , 选 择 目 标 框 架 选 择 SuperMap Deskpro Plugin , 名 称 命 名 为 SuperMapShow 确定 2.填加完后,可以看到如下信息, (1) SuperMap Deskpro .NET 是 支 持 插 件 式 扩 展 开 发 的 应 用 平 台 , 通 过 “ SuperMap Deskpro Plugin ” 新 建 工 程 , 会 自 动 生 成 三 个 文 件 “CtrlAction.cs”、“DesktopPlugin.cs”、“DesktopPlugin.config”。
(2) 其中“DesktopPlugin.cs”文件是对插件的定义,用来处理插件的初始化工 作。 (3) “CtrlAction.cs”是对操作功能的定义,用来响应控件事件触发时所要执 行的内容。 (4) “DesktopPlugin.config”是插件配置文件,用来管理插件启动以及相关界 面配置。 3. 此 时 直 接 运 行 可 以 看 到 在 SuperMap 主 界 面 出 现 如 下 图 标 , (注:生产的目标框架必须为.NET Frameword 2.0 ,否则 Supermap 界面不会出现 图标) 4.修改插件中的图片 (1)打开 SuperMapShow.config , 找到 button 的 image 属性,修改 image 路 径即可是实现变换背景图片
(2)修改后的效果如下 5.前面仅是准备工作,下面开始进行开发。 (1.)实现输出插件信息 操作 1:在 MyCtrlAction 类中重写 Run()方法。Run()方法是用来响应控件事件,本例 中实现的功能为:将 SuperMap Deskpro .NET 6R 加载的所有插件的名称和所在 程序集的全路径信息输出到应用程序的输出窗口中。在 CtrlAction.cs 文件中, 将 Run() 方法中的 MessageBox.Show("MyCtrlAction.Run");代码替换为如下实现 代码: //获取应用程序中所加载的所有插件的数目 Int32 pluginCount = SuperMap.Desktop.Application.ActiveApplication.PluginManager.Count; //遍历应用程序中的所有插件,并将获取的插件的信息输出到应用程序的输 出窗口 for (Int32 index = 0; index < pluginCount; index++) { //获取应用程序中指定索引值的插件定义类对象 Plugin plugin = SuperMap.Desktop.Application.ActiveApplication.PluginManager[index]; //获取该插件的插件信息类对象 PluginInfo pluginInfo = plugin.PluginInfo; //获取插件的名称
String pluginName = pluginInfo.Name; //获取插件所在的程序集的全路径 String pluginAssemble = pluginInfo.AssemblyName; //将获取的插件名称和所在的程序集信息输出到应用程序的输出窗口 SuperMap.Desktop.Application.ActiveApplication.Output.Output("插件名称:" + pluginName + "\r\n" + "所在的程序集:" + pluginAssemble,InfoLevel.Information); } 操作 2:运行可在 Supermap 的输出窗口看到如下信息: (2)读取数据库添加到用户控件的一个TreeView 上。 操作1:利用Sqlserver数据库,我在此处新建了一个名叫Tree数据,数据库的中有 一个Product表,表有三个字段: ID NodeName ParentID, 数据类型分别是: int nvarchar(50) int ,表中信息如下:
操作 3:建立三层 Model、BLL、DAL 层的 Product.cs Model 层代码: [Serializable] public class Product { public Product() { } private int _id; /// /// 编号 /// public int Id { get { return _id; } set { _id = value; } } private string _nodename; ///
/// 名称 /// public string Nodename { get { return _nodename; } set { _nodename = value; } } private int _parentid; /// /// 父节点编号 /// public int Parentid { get { return _parentid; } set { _parentid = value; } } } DAL 层代码: /// /// 查询详细信息 /// /// /// public DataTable ShowTree(string StrWhere) { DataTable dtCount = null; string SqlnameStr = null; if (string.IsNullOrEmpty(StrWhere)) {
SqlnameStr = "select * from Product"; SqlnameStr = "select * from Product where " + } else { StrWhere; } try { dtCount = DBUtility.SqlHelper.QueryTree.QueryTree(SqlnameStr); } catch (Exception) { } return dtCount; } BLL 层代码: DAL.Product product = new DAL.Product(); public DataTable ShowTree(string StrWhere) { return product.ShowTree(StrWhere); } 此处三层不做过多解释,此处连接数据库由于他不同于我们平时的数据库连接, 因此下面我主要详细介绍一下数据库连接字符串,请参考操作 3-数据库连接 操作 3;数据库连接 [1] 添加一个类库 DBUtility 用户存放连接信息相关的类 [2] 在 SuperMapShow 下新添加一个名叫 APP.config 的配置文件,配置文件中填
写如下信息, [3] 将 APP.config 配置文件的属性设置为 较新则复制,这样就能使得配置文件 放在 Supermap 安装目录下的 Bin>Plugins>SuperMapShow 下方(注:如果不能 生产到此目录下,直接拷贝过去也可以) [4] 在 DBUtility 类库下新建一个 GetAppInfo.cs 的类,用于此类用于得到 APP.config 中的链接字符串。 在此类下添加如下方法: /// /// 得到配置文件的配置信息 /// /// 配置文件的 Key 值 /// public static string GetValue(string AppKey) { XmlDocument xDoc = new XmlDocument(); xDoc.Load(Application.StartupPath + @"\Plugins\SuperMapShow\app.config"); XmlElement = (XmlElement)xDoc.SelectSingleNode("//appSettings").SelectSingleNode("//add[@key ='" + AppKey + "']"); xElem1 return xElem1.GetAttribute("value"); } 注:@"\Plugins\SuperMapShow\app.config" 中 SuperMapShow 为你添加的类的 名称, app.config 为你生成在 Supermap 安装目录下 此路径一定要明确。
分享到:
收藏