年度变更建库软件5.0版本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

334 lines
11 KiB

using DevExpress.XtraEditors;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Nodes;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using KGIS.Plugin.LayerProperty.EventHandler;
using KGIS.Plugin.LayerProperty.Interface;
using KGIS.Plugin.LayerProperty.Utils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
namespace KGIS.Plugin.LayerProperty.View
{
public partial class FormGalleryPathSelector : XtraForm, IUIPlugIn, IPlugIn
{
private TreeListNode m_LocalRootNode;
private TreeListNode m_DBRootNode;
private KGIS.Framework.Utils.Dialog.OpenFileDialog m_OpenFileDialog;
private IDoStyleGalleryStorage m_DistStyleGalleryStorage;
private IDoStyleGallery m_DistStyleGallery;
private object selectedPath;
public string UpdateTextName;
public object SelectedPath
{
get
{
return this.selectedPath;
}
set
{
this.selectedPath = value;
}
}
public ICoreRDBHelper RDBHelper
{
get;
//{
// return RdbUtil.RDBHelper;
//}
set;
//{
// RdbUtil.RDBHelper = value;
//}
}
public ITraceHandler TraceHandler
{
get;
//{
// return RdbUtil.TraceHandler;
//}
set;
//{
// RdbUtil.TraceHandler = value;
//}
}
public ILogEvent Log
{
set
{
//RdbUtil.Log = value;
}
}
public FormGalleryPathSelector()
{
InitializeComponent();
}
public void Init()
{
try
{
this.tlstGalleryTree.Nodes.Clear();
this.tlstGalleryTree.OptionsBehavior.Editable = false;
TreeListNode treeListNode = this.tlstGalleryTree.AppendNode(new object[]
{
"数据库图库"
}, null);
treeListNode.Tag = null;
treeListNode.StateImageIndex = 0;
this.RefreshRootNode(treeListNode);
this.m_DBRootNode = treeListNode;
TreeListNode treeListNode2 = this.tlstGalleryTree.AppendNode(new object[]
{
"本地图库"
}, null);
treeListNode2.Tag = "local";
treeListNode2.StateImageIndex = 0;
this.m_LocalRootNode = treeListNode2;
AddLocalFile();
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
}
private void AddLocalFile()
{
try
{
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"工作空间\符号库");
if (Directory.Exists(path))
{
string[] fileInfo = Directory.GetFiles(path, "*.ServerStyle?");
if (fileInfo != null && fileInfo.Length > 0)
{
foreach (string text in fileInfo)
{
this.AddFile(text);
}
}
}
}
catch (Exception ex)
{
throw ex;
}
}
private void RefreshRootNode(TreeListNode node)
{
try
{
if (node != null)
{
node.Nodes.Clear();
StyleGalleryFactory.Clear();
StyleGalleryFactory.LoadAllDistStyleGalleryPath();
List<IDoStyleGalleryPath> distStyleGalleryPathList = StyleGalleryFactory.DistStyleGalleryPathList;
foreach (IDoStyleGalleryPath current in distStyleGalleryPathList)
{
TreeListNode treeListNode = this.tlstGalleryTree.AppendNode(new object[]
{
current.Name
}, node);
treeListNode.Tag = current;
treeListNode.StateImageIndex = 5;
}
if (node.Nodes.Count > 0)
{
this.tlstGalleryTree.FocusedNode = node.Nodes[0];
node.Nodes[0].Selected = true;
}
}
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
}
private void tlstGalleryTree_FocusedNodeChanged(object sender, FocusedNodeChangedEventArgs e)
{
try
{
this.btnOK.Enabled = true;
if (e.Node == null)
{
this.btnOK.Enabled = false;
}
if (e.Node == this.m_LocalRootNode)
{
this.btnOK.Enabled = false;
}
if (e.Node == this.m_DBRootNode)
{
this.btnOK.Enabled = false;
}
this.selectedPath = e.Node.Tag;
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
}
private string OpenServerStyleFile()
{
if (this.m_OpenFileDialog == null)
{
this.m_OpenFileDialog = new KGIS.Framework.Utils.Dialog.OpenFileDialog();
}
this.m_OpenFileDialog.Filter = "ESRI ServerStyle(*.ServerStyle)|*.ServerStyle";
if (this.m_DistStyleGalleryStorage != null)
this.m_OpenFileDialog.InitialDirectory = this.m_DistStyleGalleryStorage.DefaultStylePath;
if (this.m_OpenFileDialog.ShowDialog())
{
return this.m_OpenFileDialog.FileName;
}
return "";
}
private void AddFile(string filename)
{
if (!File.Exists(filename))
{
return;
}
bool flag = false;
if (this.m_LocalRootNode != null && this.m_LocalRootNode.Nodes != null && this.m_LocalRootNode.Nodes.Count > 0)
{
foreach (TreeListNode treeListNode in this.m_LocalRootNode.Nodes)
{
if (treeListNode.Tag.ToString() == filename)
{
flag = true;
}
}
}
if (!flag)
{
FileInfo fileInfo = new FileInfo(filename);
TreeListNode treeListNode2 = this.tlstGalleryTree.AppendNode(new object[]
{
fileInfo.Name
}, this.m_LocalRootNode);
treeListNode2.Tag = fileInfo.FullName;
}
}
public bool Save()
{
return true;
}
public void DiscardModify()
{
}
public bool CanLeave()
{
return true;
}
public void RefreshData()
{
}
public void SimpleCallBack(CallBack<string> param)
{
}
public void Initialize()
{
}
private void btnOK_Click(object sender, System.EventArgs e)
{
if (this.tlstGalleryTree.FocusedNode != null && this.tlstGalleryTree.FocusedNode.Tag != null)
{
base.DialogResult = DialogResult.OK;
this.UpdateTextName = this.tlstGalleryTree.FocusedNode.Tag.ToString();
base.Close();
}
}
private void btnCancel_Click(object sender, System.EventArgs e)
{
base.DialogResult = DialogResult.Cancel;
base.Close();
}
private void btnAddStyleFile_Click(object sender, System.EventArgs e)
{
string text = this.OpenServerStyleFile();
if (text != "")
{
this.AddFile(text);
}
}
private void btnDelete_Click(object sender, System.EventArgs e)
{
try
{
string str = null;
TreeListNodes treeListNode = this.tlstGalleryTree.Nodes;
if (tlstGalleryTree.FocusedNode.Tag == null)
{
MessageHelper.Show("数据库图库不能删除!!!");
return;
}
str = tlstGalleryTree.FocusedNode.Tag.ToString();
if (this.m_LocalRootNode != null && this.m_LocalRootNode.Nodes.Count != 0)
{
TreeListNodes localtreeListNode = this.m_LocalRootNode.Nodes;//删除本地图库下的节点
foreach (TreeListNode item in localtreeListNode)
{
if (str != null && item.Tag != null && item.Tag.ToString() == str)
{
this.m_LocalRootNode.Nodes.Remove(item);
MessageHelper.ShowTips("删除成功!");
return;
}
}
}
foreach (TreeListNode item in treeListNode)//删除数据库图库,本地图库节点
{
if (str != null && item.Tag != null && item.Tag.ToString() == str)
{
this.tlstGalleryTree.Nodes.Remove(item);
MessageHelper.ShowTips("删除成功!");
return;
}
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
MessageHelper.ShowError("删除失败!");
}
}
private void tlstGalleryTree_MouseDoubleClick(object sender, MouseEventArgs e)
{
try
{
TreeListHitInfo treeListHitInfo = this.tlstGalleryTree.CalcHitInfo(System.Windows.Forms.Control.MousePosition);
if (treeListHitInfo != null)
{
TreeListNode treeListNode = treeListHitInfo.Node;
if (treeListNode == null)
{
treeListNode = this.tlstGalleryTree.FocusedNode;
}
if (treeListNode != null && treeListNode != this.m_LocalRootNode && treeListNode != this.m_DBRootNode)
{
this.selectedPath = treeListNode.Tag;
this.btnOK_Click(null, null);
}
}
}
catch (Exception ex)
{
//RdbUtil.AddException(ex);
}
}
bool IUIPlugIn.Visible
{
get;
set;
}
}
}