using KGIS.Framework.DBOperator; using KGIS.Framework.Maps; using KGIS.Framework.Platform; using KGIS.Framework.Utils; using KGIS.Framework.Utils.Dialog; using KGIS.Framework.Utils.ExtensionMethod; using KGIS.Framework.Utils.Helper; using KGIS.Framework.Utils.Utility; using Kingo.PluginServiceInterface; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.IO; using System.Linq; using System.Windows; using System.Xml; using UIShell.OSGi; namespace Kingo.Plugin.MapView.Views.AppMenuView { /// /// 设置工作目录功能 的交互逻辑 /// public partial class UCSetWorkCatalog : BaseWindow { IWorkCatalog _workCatalog = null; List XZQCodeList = new List(); //行政区代码集合 List XZQCoderesult = new List(); List _WorkCatalogPaths = new List(); /// /// 授权加密-区划代码 /// private static string getCodes = ""; public UCSetWorkCatalog() { try { InitializeComponent(); //行政区集合赋值 Box_XZQCode.ItemsSource = GetXZQDic(); _workCatalog = BundleRuntime.Instance.GetFirstOrDefaultService(); if (_workCatalog != null && _workCatalog.SaveWorkSapcePath != null && !string.IsNullOrWhiteSpace(_workCatalog.SaveWorkSapcePath)) { string[] dirColl = Directory.GetDirectories(_workCatalog.SaveWorkSapcePath); foreach (var dir in dirColl) { string folderName = Path.GetFileName(dir); var XZQTemp = XZQCoderesult.FirstOrDefault(x => x.NAME == folderName.Split('(')[0]); if (XZQTemp == null) continue; string itemType = string.Format("{0}({1})", folderName.Split('(')[0], XZQTemp.CODE);//作为工作目录次级目录文件夹 if (XZQCodeList.FirstOrDefault(f => f.Descriction == itemType && f.ItemType == itemType) != null) continue; XZQCodeList.Add(new XZQCodeData() { IsChecked = true, IsEnabled = false, Descriction = itemType, ItemType = itemType }); } lbTBList.ItemsSource = null; lbTBList.ItemsSource = XZQCodeList; } LoadXMLAttritue(_workCatalog.SaveWorkSapcePath, SysAppPath.GetRecentOpenProjectRecordConfigPath()); } catch (Exception ex) { LogAPI.Debug("打开工作目录页面初始化时发生异常,异常信息如下:"); LogAPI.Debug(ex); } } /// /// 区划代码集(330110-余杭区) /// /// public List GetXZQDic() { IRDBHelper rdbHelper = null; try { string systemPath = SysAppPath.GetDataBasePath() + "System.mdb"; if (File.Exists(systemPath)) { string connStr = SysConfigsOprator.GetDBConnectionByName("MDBOledbConnection"); connStr = string.Format(connStr, systemPath); rdbHelper = RDBFactory.CreateDbHelper(connStr, DatabaseType.MSAccess); string strSQL = "select OBJECTID AS ID, XZQ AS CODE,XZQMC AS NAME from XZQ Where XZQ LIKE '" + getCodes + "%'"; DataTable dt = rdbHelper.ExecuteDatatable("Dic", strSQL, true); if (dt != null) { XZQCoderesult = TBToList.ToList(dt); foreach (var item in XZQCoderesult) { item.DisplayName = item.CODE + "-" + item.NAME; if (dt.Rows.Count == 1) Box_XZQCode.DisplayMemberPath = item.DisplayName; } } } } catch (Exception ex) { LogAPI.Debug(ex); } finally { if (rdbHelper != null) rdbHelper.DisConnect(); } return XZQCoderesult; } /// /// 行政区代码数据实体 /// public class XZQCodeData : INotifyPropertyChanged { private bool _IsChecked; public bool IsChecked { get { return _IsChecked; } set { _IsChecked = value; RaisePropertyChanged("IsChecked"); } } public string ItemType { get; set; } public string Descriction { get; set; } public bool IsEnabled { get; set; } public event PropertyChangedEventHandler PropertyChanged; protected void RaisePropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } /// /// 创建工作目录 /// /// /// private void btnExtract_Click(object sender, RoutedEventArgs e) { try { _workCatalog = BundleRuntime.Instance.GetFirstOrDefaultService(); if (_workCatalog != null) { if (!_workCatalog.IsOpenView) _workCatalog.Open(); if (string.IsNullOrEmpty(btnSetWorkPath.Text.ToString())) return; //不存在该目录,则创建 if (!Directory.Exists(btnSetWorkPath.Text.ToString())) Directory.CreateDirectory(btnSetWorkPath.Text.ToString()); //设置工作目录模板 foreach (var xzqcode in XZQCodeList) { if (xzqcode.IsChecked) { DirectoryCopy(btnSetWorkPath.Text.ToString(), xzqcode.ItemType); } } //同一当前目录-加载/添加目录不需要加载工程 if (_workCatalog.SaveWorkSapcePath == btnSetWorkPath.Text.ToString()) _workCatalog.IsLoadProject = false; else _workCatalog.IsLoadProject = true; _workCatalog.SetWorksapce(btnSetWorkPath.Text.ToString()); this.Close(); ProjectInfo ProInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; if (ProInfo != null) { if (ProInfo.ProjType == EnumProjType.BHTBTQ && Platform.Instance.SystemType != SystemTypeEnum.BGFWCG || ProInfo.ProjType != EnumProjType.BHTBTQ && Platform.Instance.SystemType == SystemTypeEnum.BGFWCG) { ClearData(); LogAPI.Debug("工程类型与当前软件类型不匹配,将会导致功能不可用,请正确打开工程类型!"); KGIS.Framework.Utils.Helper.MessageHelper.ShowError("当前工程类型与当前软件类型不匹配,将会导致一些功能不可正常使用,请重新正确打开工程类型!"); return; } } if (ProInfo != null && ProInfo.ProjType == EnumProjType.BHTBTQ && Platform.Instance.SystemType == SystemTypeEnum.BGFWCG) { //添加作业区标注 PluginServiceInterface.Helper.MarkLabelLayerForZYQ.MarkLayer(); IUcZYQMagrHelper ucZYQMagrHelper = BundleRuntime.Instance.GetFirstOrDefaultService(); if (ucZYQMagrHelper != null) { ucZYQMagrHelper.UpdataData(); } IUcMulitMapControlHelper ucMulitMapControlHelper = BundleRuntime.Instance.GetFirstOrDefaultService(); if (ucMulitMapControlHelper != null) { ucMulitMapControlHelper.ClearData(); ucMulitMapControlHelper.SetLayer(); ucMulitMapControlHelper.MarkLabelLayer(); } } } else { MessageHelper.Show("打开工作目录失败!"); } } catch (Exception ex) { MessageHelper.Show("打开工作目录失败,请查看系统日志!"); LogAPI.Debug("打开工作目录时发生异常,异常信息如下:"); LogAPI.Debug(ex); } } private void ClearData() { MapsManager.Instance.MapService.getAxMapControl().ClearLayers(); if (Platform.Instance.SystemType == SystemTypeEnum.BGFWCG) { IUcZYQMagrHelper ucZYQMagrHelper = BundleRuntime.Instance.GetFirstOrDefaultService(); if (ucZYQMagrHelper != null) { ucZYQMagrHelper.ClearData(); } IUcMulitMapControlHelper ucMulitMapControlHelper = BundleRuntime.Instance.GetFirstOrDefaultService(); if (ucMulitMapControlHelper != null) { ucMulitMapControlHelper.ClearData(); } } } /// /// 取消 /// /// /// private void btnConfirm_Click(object sender, RoutedEventArgs e) { this.Close(); } /// /// 选择工作目录 /// /// /// private void BtnSelectedWorkCatalog_Click(object sender, RoutedEventArgs e) { FolderBrowserDialog m_Dialog = new FolderBrowserDialog(); System.Windows.Forms.DialogResult result = m_Dialog.ShowDialog(); if (result == System.Windows.Forms.DialogResult.Cancel) { btnSetWorkPath.SelectedIndex = 0; return; } _WorkCatalogPaths.Add(new WorkCatalogPaths { WorkCatalogPath = m_Dialog.SelectedPath.Trim(), UpdateTime = DateTime.Now, CODE = m_Dialog.SelectedPath.Trim(), DisplayName = m_Dialog.SelectedPath.Trim() }); btnSetWorkPath.ItemsSource = null; _WorkCatalogPaths = _WorkCatalogPaths.OrderByDescending(x => x.UpdateTime).ToList(); //string currPath = _workCatalog.SaveWorkSapcePath; btnSetWorkPath.ItemsSource = _WorkCatalogPaths; btnSetWorkPath.SelectedItem = _WorkCatalogPaths[0]; } /// /// 工作目录文件夹复制 /// /// 存放工程文件名 /// 被创建的目录 public void DirectoryCopy(string targetDirPath, string xzqCode_Name) { try { string targetDir = targetDirPath + "\\" + xzqCode_Name; //创建工程目录文件 if (!Directory.Exists(targetDir)) Directory.CreateDirectory(targetDir); if (NCSJ.IsChecked == true && !Directory.Exists(targetDir + "\\" + NCSJ.Content.ToString())) Directory.CreateDirectory(targetDir + "\\" + NCSJ.Content.ToString()); if (GCML.IsChecked == true && !Directory.Exists(targetDir + "\\" + GCML.Content.ToString())) Directory.CreateDirectory(targetDir + "\\" + GCML.Content.ToString()); if (CKSJ.IsChecked == true && !Directory.Exists(targetDir + "\\" + CKSJ.Content.ToString())) Directory.CreateDirectory(targetDir + "\\" + CKSJ.Content.ToString()); if (JZCG.IsChecked == true && !Directory.Exists(targetDir + "\\" + JZCG.Content.ToString())) Directory.CreateDirectory(targetDir + "\\" + JZCG.Content.ToString()); } catch (Exception ex) { LogAPI.Debug("创建工程目录页面中,文件夹复制时失败,异常原因: " + ex.Message + " ; "); throw; } } /// /// 添加行政区 /// /// /// private void AddXZQCode_Click(object sender, RoutedEventArgs e) { try { if (string.IsNullOrWhiteSpace(Box_XZQCode.SelectedValue.ToTrim())) return; SelectXZQCodeData.ItemsSource = null; string dispalyName = XZQCoderesult.FirstOrDefault(x => x.CODE == Box_XZQCode.SelectedValue.ToTrim()).NAME; string itemType = string.Format("{0}({1})", dispalyName, Box_XZQCode.SelectedValue.ToTrim());//作为工作目录次级目录文件夹 XZQCodeList.Add(new XZQCodeData() { IsChecked = true, Descriction = itemType, ItemType = itemType }); lbTBList.ItemsSource = null; lbTBList.ItemsSource = XZQCodeList; //SelectXZQCodeData.ItemsSource = XZQCodeList; } catch (Exception ex) { LogAPI.Debug("添加行政区发生错误:" + ex.Message); throw; } } /// /// 加载工作目录集合 /// /// /// private void LoadXMLAttritue(string workcatalog, string sXmlPath) { XmlDocument doc = new XmlDocument(); XmlElement orderElement = null; XmlNodeList orderChildr = null; try { //if (string.IsNullOrWhiteSpace(workcatalog) == true || string.IsNullOrWhiteSpace(workcatalog) == true) return; if (File.Exists(sXmlPath) == false) return; doc.Load(sXmlPath); orderElement = doc.DocumentElement;// 获取根节点 if (orderElement == null) return; if (orderElement.ChildNodes == null || orderElement.ChildNodes.Count <= 0) return; orderChildr = orderElement.ChildNodes; if (orderChildr == null || orderChildr.Count <= 0) return; _WorkCatalogPaths = new List(); foreach (XmlNode item in orderChildr) { string path = item.Attributes["ProjectPath"].Value; if (string.IsNullOrWhiteSpace(path) || !Directory.Exists(path)) continue; _WorkCatalogPaths.Add(new WorkCatalogPaths { WorkCatalogPath = item.Attributes["ProjectPath"].Value, UpdateTime = Convert.ToDateTime(item.Attributes["LastOpenTime"].Value), CODE = item.Attributes["ProjectPath"].Value, DisplayName = item.Attributes["ProjectPath"].Value }); } if (_WorkCatalogPaths.Count > 0) { _WorkCatalogPaths = _WorkCatalogPaths.OrderByDescending(x => x.UpdateTime).ToList(); //string currPath = _workCatalog.SaveWorkSapcePath; btnSetWorkPath.ItemsSource = _WorkCatalogPaths; btnSetWorkPath.SelectedItem = _WorkCatalogPaths[0]; } } catch (Exception ex) { LogAPI.Debug(ex.Message); return; } finally { if (doc != null) doc = null; if (orderElement != null) orderElement = null; if (orderChildr != null && orderChildr.Count > 0) orderChildr = null; if (string.IsNullOrWhiteSpace(sXmlPath) == false) sXmlPath = ""; } } /// /// 自动筛选实体类 /// public class WorkCatalogPaths { public override string ToString() { return WorkCatalogPath; } /// /// 工作目录路径 /// public string WorkCatalogPath { get; set; } public string CODE { get; set; } public string DisplayName { get; set; } public DateTime UpdateTime { get; set; } } private void btnSetWorkPath_SelectedIndexChanged(object sender, RoutedEventArgs e) { var item = btnSetWorkPath.SelectedItem; if (item is WorkCatalogPaths) { string[] dirColl = Directory.GetDirectories((item as WorkCatalogPaths).WorkCatalogPath); XZQCodeList.Clear(); foreach (var dir in dirColl) { string folderName = Path.GetFileName(dir); var XZQTemp = XZQCoderesult.FirstOrDefault(x => x.NAME == folderName.Split('(')[0] && x.CODE == folderName.Split('(')[1].TrimEnd(')')); if (XZQTemp == null) continue; string itemType = string.Format("{0}({1})", folderName.Split('(')[0], XZQTemp.CODE);//作为工作目录次级目录文件夹 if (XZQCodeList.FirstOrDefault(f => f.Descriction == itemType && f.ItemType == itemType) != null) continue; XZQCodeList.Add(new XZQCodeData() { IsChecked = true, IsEnabled = false, Descriction = itemType, ItemType = itemType }); } lbTBList.ItemsSource = null; lbTBList.ItemsSource = XZQCodeList; } } } }