using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ExcelDataReader;
using KGIS.Framework.AE;
using KGIS.Framework.AE.Enum;
using KGIS.Framework.AE.GPHelper;
using KGIS.Framework.Maps;
using KGIS.Framework.OpenData.Control;
using KGIS.Framework.OpenData.Filter;
using KGIS.Framework.OpenData.InterFace;
using KGIS.Framework.Platform;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.ExtensionMethod;
using KGIS.Framework.Utils.Helper;
using KGIS.Framework.Utils.Model;
using Kingo.Plugin.MapView.Model;
using Kingo.PluginServiceInterface;
using KUI.Windows;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Input;
using UIShell.OSGi;
using Path = System.IO.Path;
namespace Kingo.Plugin.MapView.Views.AppMenuView
{
    /// 
    /// 工程属性 的交互逻辑
    /// 
    public partial class UCProjectInformation : BaseWindow
    {
        /// 
        /// 工作目录服务接口
        /// 
        IWorkCatalog _workCatalog = null;
        private ProjectInfo ProInfo = null;
        List Dics_QS = null;//权属字典
        ObservableCollection ListZLXXInfo = null;//坐落信息变化数据
        //划入库数据路径集合
        private List HRDataPaths;
        public UCProjectInformation()
        {
            InitializeComponent();
            DevExpress.Xpf.Core.ThemeManager.SetTheme(this, DevExpress.Xpf.Core.Theme.Office2013LightGray);
            //工作目录接口
            _workCatalog = BundleRuntime.Instance.GetFirstOrDefaultService();
            ProInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo;
            if (ProInfo != null)
                InitData(ProInfo);
        }
        public void InitData(ProjectInfo pPrj)
        {
            try
            {
                if (_workCatalog != null)
                    btnPrjDir.Text = _workCatalog.SaveWorkSapcePath;
                #region 工程类型
                switch (pPrj.ProjType)
                {
                    case EnumProjType.NDBG:
                        projectType.SelectedIndex = 0;
                        break;
                    case EnumProjType.RCBG_ZJG:
                        projectType.SelectedIndex = 1;
                        break;
                    case EnumProjType.RCBG_BCGD:
                        projectType.SelectedIndex = 2;
                        break;
                    default:
                        break;
                }
                #endregion
                #region 比例尺
                List listScale = new List
                {
                    new ScaleCodeTable() { Scale = "1:2000", ScaleCode = "I" },
                    new ScaleCodeTable() { Scale = "1:5000", ScaleCode = "H" },
                    new ScaleCodeTable() { Scale = "1:10000", ScaleCode = "G" },
                    new ScaleCodeTable() { Scale = "1:25000", ScaleCode = "F" },
                    new ScaleCodeTable() { Scale = "1:50000", ScaleCode = "E" },
                    new ScaleCodeTable() { Scale = "1:100000", ScaleCode = "D" },
                    new ScaleCodeTable() { Scale = "1:250000", ScaleCode = "C" },
                    new ScaleCodeTable() { Scale = "1:500000", ScaleCode = "B" }
                };
                combScale.ItemsSource = listScale;
                if (!string.IsNullOrWhiteSpace(pPrj.ScaleCode))
                {
                    combScale.SelectedItem = listScale.FirstOrDefault(x => x.ScaleCode == pPrj.ScaleCode);
                }
                else if (!string.IsNullOrWhiteSpace(pPrj.ScaleCode))
                {
                    combScale.SelectedItem = listScale.FirstOrDefault(x => x.Scale == pPrj.Scale);
                }
                else
                {
                    combScale.SelectedIndex = 0;
                }
                #endregion
                #region 容差
                List listResolution = new List
                {
                    new ScaleCodeTable() { Scale = "万分之一", ScaleCode = "0.0001" },
                    new ScaleCodeTable() { Scale = "十万分之一", ScaleCode = "0.00001" }
                };
                combXYResolution.ItemsSource = listResolution;
                if (!string.IsNullOrWhiteSpace(pPrj.XYResolution.ToTrim()) && pPrj.XYResolution != 0)
                {
                    combXYResolution.SelectedItem = listResolution.FirstOrDefault(x => x.ScaleCode == pPrj.XYResolution.ToTrim());
                }
                else
                {
                    combXYResolution.SelectedIndex = 0;
                }
                #endregion
                //坐标系
                btnPrjFile.Text = pPrj.GetPRJName();
                //坐落信息
                if (pPrj.ListZLXXInfo == null)
                {
                    pPrj.ListZLXXInfo = new ObservableCollection
                    {
                        new ZLXXInfo() { ID = 0 }
                    };
                }
                else if (pPrj.ListZLXXInfo.Count == 0)
                {
                    pPrj.ListZLXXInfo.Add(new ZLXXInfo() { ID = 0 });
                }
                gvCtrl.ItemsSource = pPrj.ListZLXXInfo;
                if (pPrj.KZMJ != null)
                {
                    pPrj.DCMJ = pPrj.KZMJ.TZH_LDMJ;
                    pPrj.DCMJHD = pPrj.KZMJ.TZH_HDMJ;
                }
                #region 加载调入本县范围的其他区县基础库
                if (HRDataPaths == null || HRDataPaths?.Count == 0)
                    HRDataPaths = new List() { new HRDataPath() { ID = 0 } };
                if (pPrj.DR_DataKPaths != null)
                {
                    for (int i = 0; i < pPrj.DR_DataKPaths.Count; i++)
                    {
                        HRDataPaths.Add(new HRDataPath() { ID = i + 1, HRPath = pPrj.DR_DataKPaths[i] });
                    }
                }
                gvCtrlHR.ItemsSource = HRDataPaths.Count > 1 ? HRDataPaths.FindAll(x => !string.IsNullOrWhiteSpace(x.HRPath)).ToList() : HRDataPaths;
                #endregion 
                this.DataContext = pPrj;
            }
            catch (Exception ex)
            {
                LogAPI.Debug("加载工程信息页面数据时失败,异常原因: " + ex.Message + " ; ");
                MessageHelper.ShowTips(ex.Message);
            }
        }
        /// 
        /// 保存工程信息
        /// 
        /// 
        /// 
        private void BtnOK_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                bool TZH_LDMJ0 = Double.TryParse(TZH_LDMJ.Text.Trim(), out double TZH_LDMJValue);
                bool TZH_HDMJ0 = Double.TryParse(TZH_HDMJ.Text.Trim(), out double TZH_HDMJValue);
                if (TZH_LDMJ0 == false || TZH_HDMJ0 == false || (TZH_LDMJValue + TZH_HDMJValue) <= 0)
                {
                    MessageHelper.ShowTips("陆地和海岛面积之和不能为零且值为数字类型!");
                    return;
                }
                if (combScale.SelectedItem is ScaleCodeTable)//比例尺
                {
                    ProInfo.ScaleCode = (combScale.SelectedItem as ScaleCodeTable).ScaleCode;
                    ProInfo.Scale = (combScale.SelectedItem as ScaleCodeTable).Scale;
                }
                //陆地海岛面积
                ProInfo.DCMJ = Convert.ToDouble(TZH_LDMJ.Text.Trim());
                ProInfo.DCMJHD = Convert.ToDouble(TZH_HDMJ.Text.Trim());
                ProInfo.KZMJ.TZH_LDMJ = Convert.ToDouble(TZH_LDMJ.Text.Trim());
                ProInfo.KZMJ.TZH_HDMJ = Convert.ToDouble(TZH_HDMJ.Text.Trim());
                ProInfo.KZMJ.TZQ_HDMJ = Convert.ToDouble(DCMJHD.Text.Trim());
                ProInfo.KZMJ.TZQ_LDMJ = Convert.ToDouble(DCMJ.Text.Trim());
                ProInfo.XZQDMChange = cb_XZQDMChange.IsChecked == true;
                ProInfo.ZLDWMCChange = cb_ZLDWMCChange.IsChecked == true;
                ProInfo.DR_DataKPaths = new List();
                if (HRDataPaths != null && HRDataPaths?.Count > 1)
                    foreach (HRDataPath item in HRDataPaths)
                    {
                        if (!string.IsNullOrWhiteSpace(item.HRPath))
                            ProInfo.DR_DataKPaths.Add(item.HRPath);
                    }
                if (gvCtrl.ItemsSource is ObservableCollection && (gvCtrl.ItemsSource as ObservableCollection).Count == 1)
                    if ((gvCtrl.ItemsSource as ObservableCollection).FirstOrDefault().ID == 0)
                        (gvCtrl.ItemsSource as ObservableCollection).Clear();
                ProInfo.ListZLXXInfo = (gvCtrl.ItemsSource as ObservableCollection);
                //工程保存
                if (ProInfo.Save())
                    this.Close();
                else
                    MessageHelper.ShowWarning("工程修改失败!");
            }
            catch (Exception ex)
            {
                LogAPI.Debug(ex.Message);
            }
        }
        #region 添加坐落变更信息
        private void Txt_Add_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            ProInfo.ListZLXXInfo.Add(new ZLXXInfo()
            {
                ID = ProInfo.ListZLXXInfo.OrderByDescending(x => x.ID).FirstOrDefault() == null ? 0 : ProInfo.ListZLXXInfo.OrderByDescending(x => x.ID).FirstOrDefault().ID + 1,
            });
        }
        #endregion
        #region 删除坐落变更信息
        private void Txt_Delete_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (sender is TextBlock TextBlock)
                {
                    var Info = ProInfo.ListZLXXInfo.FirstOrDefault(f => f.ID == TextBlock.Tag.ToInt());
                    ProInfo.ListZLXXInfo.Remove(Info);
                    if (ProInfo.ListZLXXInfo.Count == 0)
                        ProInfo.ListZLXXInfo.Add(new ZLXXInfo() { ID = 0 });
                }
            }
            catch (Exception ex)
            {
                LogAPI.Debug("删除坐落信息失败:" + ex.Message);
            }
        }
        #endregion
        private void Validate(object sender, DevExpress.Xpf.Editors.ValidationEventArgs e)
        {
            if (e.Value != null)
            {
                if (e.Value is string)
                {
                    if (string.IsNullOrWhiteSpace(e.Value as string))
                    {
                        e.IsValid = false;
                        e.ErrorContent = "值不能为空";
                    }
                }
                else if (e.Value is float || e.Value is double || e.Value is Int32 || e.Value is decimal)
                {
                    double db = Convert.ToDouble(e.Value);
                    if (db == 0)
                    {
                        e.IsValid = false;
                        e.ErrorContent = "值不能为0";
                    }
                }
            }
            else
            {
                e.IsValid = false;
                e.ErrorContent = "值不能为空";
            }
        }
        private void BtnCanel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
        private void BtnSelTB_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string xzdltbPaths = "";
                IFeatureLayer BGFeatureClass = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBBG");
                IFeatureLayer JClayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("地类图斑");
                IFeatureClass dltbFc = GetFeatureClass("请选择新增的地类图斑数据", ref xzdltbPaths);
                if (dltbFc != null)
                {
                    btnNewData.Text = xzdltbPaths;
                    IFeatureLayer SelLocation_Layer = GeoDBAPI.CreateFeatureLayerInmemeory("SelLocation", "选择范围图斑数据", (dltbFc as IGeoDataset).SpatialReference, dltbFc.ShapeType, dltbFc.Fields);
                    (SelLocation_Layer.FeatureClass as ITable).DeleteSearchedRows(null);
                    InsertDataToMemeoryLayer(dltbFc, SelLocation_Layer.FeatureClass, null);
                    #region 选择的图斑与基础数据库相交,获取图形 并赋 QSDWDM 与 ZLDWDM
                    if (SelLocation_Layer != null && SelLocation_Layer.FeatureClass.FeatureCount(null) > 0)
                    {
                        this.ShowLoading("正在根据矢量数据范围提取变更图斑,请稍后...", 0, 0);
                        IFeatureLayer JCDLTB_DLTBBGLayer = null;
                        string resultPath = Path.Combine(SysAppPath.GetCurrentAppPath(), "Temp\\Intersect_DLTBBG_DLTB");
                        if (!Directory.Exists(resultPath))
                            Directory.CreateDirectory(resultPath);
                        else
                            PluginServiceInterface.CommonHelper.DelectDir(resultPath);
                        string savePath = Path.Combine(resultPath, "Intersect_DLTBBG_DLTB.gdb");
                        string templeteGDBPath = Path.Combine(SysAppPath.GetCurrentAppPath(), "Template", "TempGDB.gdb");
                        CopyDirectory(templeteGDBPath, savePath, true);
                        string outPath = Path.Combine(savePath, "Intersect_DLTBBG_DLTB");
                        KGIS.Framework.AE.GPHelper.GPParamClass gPParamClass = new GPParamClass
                        {
                            FirstFeatureLayer = SelLocation_Layer,
                            SecondFeatureLayer = JClayer,
                            OutFeatureClassPath = outPath,
                            IsGetOutPutFeature = true
                        };
                        GeoprocessorHelper.IntersectAnalysis(gPParamClass, ref JCDLTB_DLTBBGLayer);
                        if (JCDLTB_DLTBBGLayer != null)
                        {
                            //修改坐落单位代码
                            IFeatureClassAPI fcAPI = new FeatureClassAPI(JCDLTB_DLTBBGLayer.FeatureClass);
                            fcAPI.FcToFc(BGFeatureClass.FeatureClass, null, true);
                            if (fcAPI != null)
                                fcAPI.CloseFeatureClass();
                            if (BGFeatureClass != null)
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(BGFeatureClass);
                            BGFeatureClass = null;
                        }
                        this.CloseLoading();
                        MessageHelper.ShowTips("提取完成!");
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                this.CloseLoading();
                LogAPI.Debug("选择范围图斑异常:" + ex.Message);
                LogAPI.Debug("选择范围图斑异常:" + ex.StackTrace);
                MessageHelper.ShowError("选择范围图斑异常:" + ex.Message);
            }
            finally
            {
                this.CloseLoading();
                GC.Collect();
            }
        }
        private void InsertDataToMemeoryLayer(IFeatureClass pSource, IFeatureClass pTarget, IQueryFilter pFilter = null)
        {
            try
            {
                if (pSource == null || pTarget == null) return;
                IFeatureClassAPI fcAPI = new FeatureClassAPI(pSource);
                if (pTarget != null)
                    fcAPI.FcToFc(pTarget, pFilter, false);
            }
            catch (Exception ex)
            {
                LogAPI.Debug("插入数据失败:");
                LogAPI.Debug(ex);
            }
        }
        public static IFeatureClass GetFeatureClass(string title, ref string paths)
        {
            IFeatureClass result = null;
            try
            {
                // 获取源数据
                OpenDataDialog pDialog = new OpenDataDialog();
                ISpatialDataObjectFilter pOFilter;
                pOFilter = new FilterFeatureDatasetsAndFeatureClasses();
                pDialog.AddFilter(pOFilter, true);
                if (!string.IsNullOrWhiteSpace(title))
                    pDialog.Title = title;
                else
                    pDialog.Title = "选择数据";
                pDialog.AllowMultiSelect = false;
                pDialog.RestoreLocation = true;
                pDialog.StartLocation = pDialog.FinalLocation;
                if (pDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK && pDialog.Selection.Count > 0)
                {
                    List distObj = pDialog.Selection;
                    foreach (var obj in distObj)
                    {
                        if (obj.DatasetType == esriDatasetType.esriDTFeatureClass)
                        {
                            IFeatureClass featureclass = (obj.DatasetName as IName).Open() as IFeatureClass;
                            result = featureclass;
                            paths += obj.FullName;//展示完整路径
                            //paths = featureclass.AliasName;//展示文件名
                        }
                    }
                }
                return result;
            }
            catch (Exception ex)
            {
                LogAPI.Debug("选择数据失败:" + ex.Message.ToString());
                return result;
            }
        }
        /// 
        /// 拷贝模板gdb文件夹
        /// 
        /// 
        /// 
        /// 
        public static void CopyDirectory(string SourcePath, string DestinationPath, bool overwriteexisting)
        {
            try
            {
                SourcePath = SourcePath.EndsWith(@"\") ? SourcePath : SourcePath + @"\";
                DestinationPath = DestinationPath.EndsWith(@"\") ? DestinationPath : DestinationPath + @"\";
                if (Directory.Exists(SourcePath))
                {
                    if (Directory.Exists(DestinationPath) == false)
                        Directory.CreateDirectory(DestinationPath);
                    foreach (string fls in Directory.GetFiles(SourcePath))
                    {
                        FileInfo flinfo = new FileInfo(fls);
                        flinfo.CopyTo(DestinationPath + flinfo.Name, overwriteexisting);
                    }
                    foreach (string drs in Directory.GetDirectories(SourcePath))
                    {
                        DirectoryInfo drinfo = new DirectoryInfo(drs);
                        CopyDirectory(drs, DestinationPath + drinfo.Name, overwriteexisting);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void BtnOpenFile_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (MessageHelper.ShowYesNoAndTips("是否要先获取当前坐落变更表格模板?") == System.Windows.Forms.DialogResult.Yes)
                {
                    string savepaths = string.Empty;
                    SaveFileDialog dialogCopy = new SaveFileDialog
                    {
                        DefaultExt = "xlsx",
                        Filter = "Excel Files(*.xlsx)|*.xlsx",
                        FileName = "变更坐落" + DateTime.Now.ToString("yyyyMMddHHmmssfff")
                    };
                    if (dialogCopy.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        savepaths = dialogCopy.FileName;
                    else
                        return;
                    if (string.IsNullOrWhiteSpace(savepaths))
                    {
                        MessageHelper.Show("未获取到文件路径!");
                        return;
                    }
                    if (File.Exists(savepaths))
                    {
                        var result = MessageHelper.ShowYesNoAndTips("文件已存在,是否覆盖?");
                        if (result == System.Windows.Forms.DialogResult.No) return;
                    }
                    string strPath = AppDomain.CurrentDomain.BaseDirectory + @"工作空间\模板\坐落变更模板\坐落变更模板.xlsx";
                    File.Copy(strPath, savepaths, true);
                    if (MessageHelper.ShowYesNoAndTips("模板下载已完成,是否打开?") == System.Windows.Forms.DialogResult.Yes)
                    {
                        System.Diagnostics.Process.Start("explorer.exe", savepaths);
                    }
                    return;
                }
                string filePath = string.Empty;
                KGIS.Framework.Utils.Dialog.OpenFileDialog dialog = new KGIS.Framework.Utils.Dialog.OpenFileDialog
                {
                    DefaultExt = "xls",
                    Filter = "Excel文件|*.xls;*.xlsx"
                };
                if (dialog.ShowDialog())
                {
                    filePath = dialog.FileName;
                    if (Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.QSDM) == null)
                    {
                        MessageHelper.ShowError("请先进行字典设置!");
                        return;
                    }
                    Dics_QS = Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.QSDM).ToLookup(x => x.CODE).ToDictionary(x => x.Key, x => x.First()).Values.ToList();
                    using (var streamData = File.Open(filePath, FileMode.Open, FileAccess.Read))
                    {
                        using (var readerData = ExcelReaderFactory.CreateReader(streamData))
                        {
                            var result = readerData.AsDataSet();
                            DataTable tempDT = result.Tables[0];
                            if (tempDT.Columns == null || tempDT.Columns.Count != 5)
                            {
                                MessageHelper.ShowError("导入模板错误!");
                                return;
                            }
                            tempDT.Columns[0].ColumnName = "变更前代码";
                            tempDT.Columns[1].ColumnName = "变更前名称";
                            tempDT.Columns[2].ColumnName = "变更后代码";
                            tempDT.Columns[3].ColumnName = "变更后名称";
                            tempDT.Columns[4].ColumnName = "是否仅权属变化";
                            tempDT.Rows.RemoveAt(0);
                            if (tempDT != null && tempDT.Rows.Count > 0)
                            {
                                var Index = -1;
                                ListZLXXInfo = new ObservableCollection();
                                foreach (DataRow row in tempDT.Rows)
                                {
                                    var QS = Dics_QS?.Where(x => x.CODE == row["变更后代码"].ToString()).FirstOrDefault();
                                    if (QS != null)
                                        Index = Dics_QS.IndexOf(QS);
                                    if (Index > 0)
                                        ListZLXXInfo.Add(new ZLXXInfo()
                                        {
                                            ID = ListZLXXInfo.OrderByDescending(x => x.ID).FirstOrDefault() == null ? 1 : ListZLXXInfo.OrderByDescending(x => x.ID).FirstOrDefault().ID + 1,
                                            BGQDM = row["变更前代码"].ToString(),
                                            BGQMC = row["变更前名称"].ToString(),
                                            BGHDM = row["变更后代码"].ToString(),
                                            BGHMC = row["变更后名称"].ToString(),
                                            IsQS = row["是否仅权属变化"].ToString(),
                                            Data = Dics_QS,
                                            DataDicTionary = QS
                                        });
                                }
                                ProInfo.ListZLXXInfo = ListZLXXInfo;
                                gvCtrl.ItemsSource = null;
                                gvCtrl.ItemsSource = ListZLXXInfo;
                                ProInfo.Save();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogAPI.Debug("选择坐落变更代码数据表格数据导入异常:" + ex);
                MessageHelper.ShowError("选择坐落变更代码数据表格数据导入异常:" + ex.Message);
            }
        }
        //加载调入本县范围的其他区县基础库
        private void Add_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            IWorkspaceAPI workApi = null;
            try
            {
                string FinalLocation = "";
                PluginServiceInterface.Helper.OpenDataDialogHelper.OpenDataDialog("选择调入本县范围的其他区县基础库", ref FinalLocation);
                if (!string.IsNullOrWhiteSpace(FinalLocation))
                {
                    string ImportDataType = Path.GetExtension(FinalLocation).ToUpper().Replace('.', ' ').TrimStart();
                    WorkspaceTypeEnum workspaceType = ImportDataType == "GDB" ? WorkspaceTypeEnum.GDBFile : WorkspaceTypeEnum.MDBFile;
                    workApi = new WorkspaceAPI(FinalLocation, workspaceType, true);
                    if (!workApi.ExistFeatureClass("CJDCQ"))
                    {
                        MessageHelper.ShowError("缺失CJDCQ图层数据!");
                        return;
                    }
                    else if (!workApi.ExistFeatureClass("CZCDYD"))
                    {
                        MessageHelper.ShowError("缺失CZCDYD图层数据!");
                        return;
                    }
                    else if (!workApi.ExistFeatureClass("XZQ"))
                    {
                        MessageHelper.ShowError("缺失XZQ图层数据!");
                        return;
                    }
                    if (HRDataPaths?.FirstOrDefault(x => x.HRPath.Trim().Equals(FinalLocation.Trim())) != null)
                    {
                        MessageHelper.ShowError("划入数据路径重复!");
                        return;
                    }
                    HRDataPaths.Add(new HRDataPath()
                    {
                        ID = HRDataPaths.OrderByDescending(x => x.ID).FirstOrDefault().ID + 1,
                        HRPath = FinalLocation
                    });
                }
                if (HRDataPaths?.Count >= 2)
                    gvCtrlHR.ItemsSource = HRDataPaths.FindAll(x => !string.IsNullOrWhiteSpace(x.HRPath)).ToList();
                gvCtrlHR.RefreshData();
            }
            catch (Exception ex)
            {
                MessageHelper.ShowError("添加路径报错:" + ex.Message);
            }
            finally
            {
                workApi?.CloseWorkspace();
            }
        }
        private void Del_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (sender is TextBlock TextBlock)
                {
                    var Info = HRDataPaths.FirstOrDefault(f => f.ID == TextBlock.Tag.ToInt());
                    HRDataPaths.Remove(Info);
                    if (HRDataPaths.Count == 0)
                        HRDataPaths.Add(new HRDataPath() { ID = 0 });
                    if (HRDataPaths?.Count > 1)
                        gvCtrlHR.ItemsSource = HRDataPaths.FindAll(x => !string.IsNullOrWhiteSpace(x.HRPath)).ToList();
                    else
                    {
                        gvCtrlHR.ItemsSource = HRDataPaths;
                    }
                    gvCtrlHR.RefreshData();
                }
            }
            catch (Exception ex)
            {
                LogAPI.Debug("删除信息失败:" + ex.Message);
            }
        }
    }
}