using DevExpress.Spreadsheet;
using KGIS.Framework.DBOperator;
using KGIS.Framework.Maps;
using KGIS.Framework.Platform;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using KGIS.Framework.Utils.Utility;
using Kingo.PluginServiceInterface;
using KUI.Windows;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace Kingo.Plugin.DataDictionary.Views
{
///
/// FrmDicManage.xaml 的交互逻辑
///
public partial class FrmDicManage : BaseWindow
{
#region 全局变量
private string connStr = string.Empty;
string Cold = null;
///
/// 导入权属单位集合
///
private List ListQsdwEntity = null;
///
/// 权属单位集合-原始数据
///
private List ExcelLists = null;
///
/// 处理掉的权属集合
///
private List RemoveQsdwEntity = null;
///
/// 当前工程数据库连接
///
private string dbPath = string.Empty;
///
/// 省级代码
///
KeyValuePair ShengInfo { get; set; }
///
/// 市级代码
///
KeyValuePair ShiInfo { get; set; }
///
/// 县级代码
///
KeyValuePair XianInfo { get; set; }
///
/// 省级代码
///
List ShengInfo2 { get; set; }
///
/// 市级代码
///
List ShiInfo2 { get; set; }
///
/// 县级代码
///
List XianInfo2 { get; set; }
public static FrmDicManage frmDicManage = new FrmDicManage();
private string XJFid = null;
private string FJFid = null;
#endregion
public FrmDicManage()
{
InitializeComponent();
this.CustomToolTip = "权属代码可右键导入EXCEL(软件提供EXCEL模板)";
ListQsdwEntity = new List();
RemoveQsdwEntity = new List();
ExcelLists = new List();
dbPath = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetDicDataPath();
Init();
frmDicManage = this;
}
///
/// 初始化
///
private void Init()
{
try
{
LoadTree();
btnDetailAdd.IsEnabled = false;
btnDetailEdit.IsEnabled = false;
btnDetailDel.IsEnabled = false;
}
catch (Exception ex)
{
LogAPI.Debug("字典界面初始化失败:" + ex.Message);
MessageHelper.ShowError("字典界面初始化失败:" + ex.Message);
}
}
///
/// 加载数据
///
///
///
public void LoadTree()
{
IRDBHelper rdbHelper = null;
try
{
rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
if (rdbHelper == null)
{
throw new Exception("数据库连接打开失败:" + dbPath);
}
DataTable dicType = rdbHelper.ExecuteDatatable("Sys_DicType", " SELECT * FROM Sys_DicType ORDER BY paixu ", true);
ObservableCollection itemList = new ObservableCollection();
DataTable dt = rdbHelper.ExecuteDatatable("Sys_DicManage", "SELECT * FROM Sys_DicManage ORDER BY paixu", true);
foreach (DataRow item in dicType.Rows)
{
TreeNode node = new TreeNode()
{
Name = item["NAME"].ToString(),
Paixu = Convert.ToInt32(item["paixu"]),
IsExpanded = true,
Icon = "pack://application:,,,/Kingo.Plugin.DataDictionary;component/Resources/zrz.png",
IsParent = true,
Data = item
};
node.Nodes = new ObservableCollection();
foreach (DataRow drvitem in dt.Rows)
{
TreeNode childNodeItem = new TreeNode();//树节点赋值属性
childNodeItem.Name = drvitem["NAME"].ToString();
childNodeItem.Paixu = Convert.ToInt32(drvitem["PAIXU"]);
childNodeItem.IsExpanded = true;
childNodeItem.Data = drvitem;
childNodeItem.Icon = "pack://application:,,,/Kingo.Plugin.DataDictionary;component/Resources/zrz.png";
if (childNodeItem.Name == "权属代码")
{
QSXZchildNodeItem = childNodeItem;
childNodeItem.cMenu = new ContextMenu();
MenuItem tmpitem = new MenuItem();
tmpitem.Header = "导入Excel";
tmpitem.Click += (s, e) =>
{
var excelfileurl = string.Empty;
//弹出文件选择对话框
var openFileDialog = new Microsoft.Win32.OpenFileDialog()
{
Filter = "Excel Files(*.xlsx)|*.xlsx"
};
var result = openFileDialog.ShowDialog();
if (result == true)
{
ImportExcel(openFileDialog.FileName);
}
};
childNodeItem.cMenu.Items.Add(tmpitem);
tmpitem = new MenuItem();
tmpitem.Header = "导出样式表";
tmpitem.Click += (s, e) =>
{
var excelfileurl = "";
//弹出文件选择对话框
var saveFileDialog = new Microsoft.Win32.SaveFileDialog()
{
Filter = "Excel Files(*.xlsx)|*.xlsx"
};
var result = saveFileDialog.ShowDialog();
if (result.Value)
{
excelfileurl = saveFileDialog.FileName;
var sourcesfile = AppDomain.CurrentDomain.BaseDirectory + @"工作空间\模板\字典模板\权属单位代码样式表.xlsx";
if (System.IO.File.Exists(sourcesfile))
{
try
{
System.IO.File.Copy(sourcesfile, excelfileurl, true);
if (MessageHelper.ShowYesNoAndTips("样式表导出成功,是否打开?") == System.Windows.Forms.DialogResult.Yes)
{
Process.Start(excelfileurl);
}
}
catch (Exception ex)
{
MessageHelper.ShowError("导出样式表失败,错误信息:" + ex.Message);
}
}
else
{
MessageHelper.ShowError("样式表文件不存在,导出失败!");
}
}
};
childNodeItem.cMenu.Items.Add(tmpitem);
}
node.Nodes.Add(childNodeItem);
}
itemList.Add(node);
}
this.tvTypes.ItemsSource = null;
this.tvTypes.ItemsSource = itemList;
}
catch (Exception ex)
{
MessageHelper.ShowError("数据加载异常!" + ex.Message);
LogAPI.Debug("LoadTree异常:" + ex.Message);
LogAPI.Debug("LoadTree异常:" + ex.StackTrace);
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
}
}
///
/// 返回指示文件是否已被其它程序使用的布尔值
///
/// 文件的完全限定名,例如:“C:\MyFile.txt”。
/// 如果文件已被其它程序使用,则为 true;否则为 false。
public Boolean FileIsUsed(String fileFullName)
{
Boolean result = false;
//判断文件是否存在,如果不存在,直接返回 false
if (!System.IO.File.Exists(fileFullName))
{
result = false;
}
else
{
//如果文件存在,则继续判断文件是否已被其它程序使用
//逻辑:尝试执行打开文件的操作,如果文件已经被其它程序使用,则打开失败,抛出异常,根据此类异常可以判断文件是否已被其它程序使用。
System.IO.FileStream fileStream = null;
try
{
fileStream = System.IO.File.Open(fileFullName, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None);
result = false;
}
catch (System.IO.IOException)
{
result = true;
}
catch (System.Exception)
{
result = true;
}
finally
{
if (fileStream != null)
{
fileStream.Close();
}
}
}
return result;
}
///
/// 处理字典数据(区分县级与村级权属代码)
///
private void Run()
{
ListQsdwEntity.ForEach(item =>
{
if (string.IsNullOrWhiteSpace(item.ZLDWDM) == false && string.IsNullOrWhiteSpace(item.Qsdwdm) == false)
{
if (item.ZLDWDM.Length == 12)
{
item.ZLDWDM = item.ZLDWDM.PadRight(19, '0');
}
if (item.ZLDWDM.Length != 19)
{
item.HasCheck = false;
}
if (item.Qsdwdm.Length == 12)
{
item.Qsdwdm = item.Qsdwdm.PadRight(19, '0');
}
if (item.Qsdwdm.Length != 19)
{
item.HasCheck = false;
}
}
else
{
item.HasCheck = false;
}
});
List remove = ListQsdwEntity.FindAll(f => f.HasCheck == false);
for (int i = 0; i < remove.Count; i++)
{
RemoveQsdwEntity.Add(remove[i]);
ListQsdwEntity.Remove(remove[i]);
}
}
private string QsdmID = null;
private List ListQsdm = null;
///
/// 处理字典数据
///
///
///
public void OrderBy(string XJCode, string XJName)
{
try
{
if (ListQsdwEntity != null && ListQsdwEntity.Count > 0)
{
string XJName_Temp = string.Empty;
ListQsdm = new List();
var GroupEntity = ListQsdwEntity.Where(x => x.ZLDWDM.Length == 19).GroupBy(x => x.ZLDWDM.Substring(0, 9)).Select(x => x.Key).ToList();
string skajh = string.Empty;
if (ListQsdwEntity.FirstOrDefault(x => x.Qsdwmc == "部队") != null)
skajh = ListQsdwEntity.FirstOrDefault(x => x.Qsdwmc == "部队").Qsdwdm;
if (ListQsdwEntity.FirstOrDefault(x => x.Qsdwdm == XJCode.PadRight(19, '0')) != null)
XJName_Temp = ListQsdwEntity.FirstOrDefault(x => x.Qsdwdm == XJCode.PadRight(19, '0')).Qsdwmc;
foreach (var item in GroupEntity)//截取乡镇权属代码
{
QSDWinformation Qsdm = new QSDWinformation();
Qsdm.ZLDWDM = item;
Qsdm.Qsdwdm = item;
if (item == XJCode.PadRight(9, '0') && XJName_Temp != XJName)//特殊状况(非飞入地,且与当前县级权属代码一致)
{
Qsdm.Qsdwmc = XJName_Temp;
Qsdm.Zldwmc = XJName_Temp;
Qsdm.ListQsdwInfor = null;
ListQsdm.Add(Qsdm);
continue;
}
string sXian_Temp1 = "";
if (ExcelLists != null && ExcelLists.Count > 0)
{
for (int i = 0; i < ExcelLists.Count(); i++)
{
if (ExcelLists[i].ZLDWDM == item.ToString())
{
sXian_Temp1 = ExcelLists[i].Qsdwmc;
break;
}
else
{
continue;
}
}
Qsdm.Qsdwmc = string.IsNullOrWhiteSpace(sXian_Temp1) == true ? ExcelLists.FirstOrDefault(p => p.ZLDWDM.PadRight(19, '0').Substring(0, 9) == item.ToString()).Qsdwmc : sXian_Temp1;
}
string sXian_Temp2 = "";
if (ExcelLists != null && ExcelLists.Count > 0)
{
for (int i = 0; i < ExcelLists.Count(); i++)
{
if (ExcelLists[i].ZLDWDM == item.ToString())
{
sXian_Temp2 = ExcelLists[i].Zldwmc;
break;
}
else
{
continue;
}
}
Qsdm.Zldwmc = string.IsNullOrWhiteSpace(sXian_Temp2) == true ? ExcelLists.FirstOrDefault(p => p.ZLDWDM.PadRight(19, '0').Substring(0, 9) == item.ToString()).Zldwmc : sXian_Temp2;
}
List ListCjQsdm = new List();
var CJGroupEntity = ListQsdwEntity.Where(x => x.HasCheck).GroupBy(x => x.ZLDWDM.Substring(0, 12)).OrderBy(x => x.Key).Select(x => x.Key).Distinct().ToList();
var tmpcjglist = CJGroupEntity.Where(x => x.Substring(0, 9) == item).ToList();
foreach (var CJitem in tmpcjglist)//截取村级权属代码
{
QSDWinformation CjQsdm = new QSDWinformation();
CjQsdm.Qsdwdm = ExcelLists.FirstOrDefault(p =>
{
bool result = false;
if (p.ZLDWDM.Length > 12)
{
result = p.ZLDWDM.Substring(0, 12) == CJitem.ToString();
}
return result;
}).Qsdwdm;
CjQsdm.ZLDWDM = ExcelLists.FirstOrDefault(p =>
{
bool result = false;
if (p.ZLDWDM.Length > 12)
{
result = p.ZLDWDM.Substring(0, 12) == CJitem.ToString();
}
return result;
}).ZLDWDM;
CjQsdm.Qsdwmc = ExcelLists.FirstOrDefault(p =>
{
bool result = false;
if (p.ZLDWDM.Length > 12)
{
result = p.ZLDWDM.Substring(0, 12) == CJitem.ToString();
}
return result;
}).Qsdwmc;
CjQsdm.Zldwmc = ExcelLists.FirstOrDefault(p =>
{
bool result = false;
if (p.ZLDWDM.Length > 12)
{
result = p.ZLDWDM.Substring(0, 12) == CJitem.ToString();
}
return result;
}).Zldwmc;
#region
var cjlist = ListQsdwEntity.Where(x => x.ZLDWDM.StartsWith(CJitem)).ToList();
var keylist = cjlist.Select(x => x.ZLDWDM).Distinct().ToList();
foreach (var citem in keylist)
{
List ListCjDMQsdm = new List();
var CJDMGroupEntity = ListQsdwEntity.Where(x => x.HasCheck).GroupBy(x => x.Qsdwdm).Select(x => x.Key).Distinct().ToList();
var tmpglist = CJDMGroupEntity.Where(x => x.Substring(0, 12) == CJitem).ToList();
foreach (var CJDMitem in tmpglist)//获取村级代码
{
var cjkeylist = ListQsdwEntity.Where(x => x.HasCheck && x.Qsdwdm == CJDMitem).Distinct().ToList();
foreach (var itemsD in cjkeylist)//获取村级小组权属代码名称
{
var cu = ListCjDMQsdm.Count(x => x.Qsdwdm == CJDMitem && x.Qsdwmc == itemsD.Qsdwmc);
if (cu == 0)
{
QSDWinformation CjDMQsdm = new QSDWinformation();
CjDMQsdm.Qsdwdm = CJDMitem;
CjDMQsdm.Qsdwmc = itemsD.Qsdwmc;
ListCjDMQsdm.Add(CjDMQsdm);
}
}
}
CjQsdm.ListQsdwInfor = ListCjDMQsdm;
}
ListCjQsdm.Add(CjQsdm);
#endregion
}
Qsdm.ListQsdwInfor = ListCjQsdm;
ListQsdm.Add(Qsdm);
}
}
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
throw ex;
}
}
///
/// 检查数据库是否已经存在权属单位代码字典
///
private void CheckExist(TreeNode selectnode)
{
IRDBHelper rdbHelper = null;
DataRow selectitemrow = selectnode.Data as DataRow;
try
{
rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
if (rdbHelper == null)
{
throw new Exception("打开数据库连接失败!");
}
rdbHelper.BeginTransaction();
DataTable dtDict = rdbHelper.ExecuteDatatable("Sys_DicType", "select * from Sys_DicManage where NAME='权属代码'", true);
//数据库已存在
if (dtDict != null && dtDict.Rows.Count > 0)
{
QsdmID = dtDict.Rows[0]["ID"].ToString();
DataTable dtDetail = rdbHelper.ExecuteDatatable("Sys_DicDetail", "select * from Sys_DicDetail where OWNERDIC='" + QsdmID + "'", true);
if (dtDetail != null && dtDetail.Rows.Count > 0)
{
this.ShowLoading("正在导入字典......", 0, 0);
//先删除数据库已存在的字典
int insertCount = rdbHelper.ExecuteSQL("DELETE FROM Sys_DicManage WHERE NAME = '权属代码' AND TYPE=1");
if (insertCount < 0)
{
throw new Exception("删除已存在字典失败!");
}
insertCount = rdbHelper.ExecuteSQL("DELETE FROM Sys_DicDetail WHERE OWNERDIC = '" + QsdmID + "'");
if (insertCount < 0)
{
throw new Exception("删除已存在字典失败!");
}
//插入Sys_DicManage表
insertCount = rdbHelper.ExecuteSQL("INSERT INTO Sys_DicManage (NAME,ALIASNAME,TYPE,REMARK,PAIXU)" + "VALUES ('权属代码','QSDM',1,'',0)");
if (insertCount < 0)
{
throw new Exception("导入字典失败!");
}
}
}
else//数据库不存在权属单位代码字典
{
this.ShowLoading("正在导入字典......", 0, 0);
//插入Sys_DicManage表
int insertCount = rdbHelper.ExecuteSQL("INSERT INTO Sys_DicManage (NAME,ALIASNAME,TYPE,REMARK,PAIXU)" + "VALUES ('权属代码','QSDM',1,'',0)");
if (insertCount < 0)
{
throw new Exception("导入字典失败!");
}
}
InserDataDic(rdbHelper);
//修改原因:不需要将字典保存到工程文件中 修改人:高山 修改时间:2019.09.21
//SaveProjectDic();
if (FJFid != null)
{
selectitemrow["id"] = FJFid;
}
rdbHelper.Commit();
//从新加载树
LoadChildTree(selectnode);
this.CloseLoading();
MessageHelper.ShowTips("导入字典成功!");
}
catch (Exception ex)
{
rdbHelper.Rollback();
this.CloseLoading();
MessageHelper.ShowError(ex.Message);
}
finally
{
this.CloseLoading();
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
}
}
public bool InserDataLsitSon(IRDBHelper rdbHelper, string pParendXZQDM = "")
{
try
{
if (ListQsdm != null && ListQsdm.Count > 0)
{
foreach (var item in ListQsdm)
{
if (!string.IsNullOrWhiteSpace(pParendXZQDM) && !item.Qsdwdm.StartsWith(pParendXZQDM))
continue;
string strSql = string.Format("insert into Sys_DicDetail(PID,NAME,CODE,OWNERDIC,REMARK,PAIXU) VALUES ('{0}','{1}','{2}','{3}','{4}',{5})", XJFid, item.Zldwmc, item.ZLDWDM, FJFid, "", 0);
if (rdbHelper.ExecuteSQL(strSql) > 0)
{
DataTable dts = rdbHelper.ExecuteDatatable("XjTable", string.Format("select id from Sys_DicDetail where PID='{0}' and NAME='{1}' and CODE='{2}' and OWNERDIC='{3}'", XJFid, item.Zldwmc, item.ZLDWDM, FJFid), true);
if (item.ListQsdwInfor == null) continue;//特殊情况
foreach (var CJitem in item.ListQsdwInfor)
{
if (dts == null || dts.Rows.Count <= 0)
{
continue;
}
string strSqlCJ = string.Format("insert into Sys_DicDetail(PID,NAME,CODE,OWNERDIC,REMARK,PAIXU) VALUES ('{0}','{1}','{2}','{3}','{4}',{5})", dts.Rows[0]["ID"].ToString(), CJitem.Zldwmc, CJitem.ZLDWDM, FJFid, "", 0);
if (rdbHelper.ExecuteSQL(strSqlCJ) <= 0)
{
continue;
}
DataTable dtCJDM = rdbHelper.ExecuteDatatable("CJDMTables", string.Format("select id from Sys_DicDetail where PID='{0}' and NAME='{1}' and CODE='{2}' and OWNERDIC='{3}'", dts.Rows[0]["ID"].ToString(), CJitem.Zldwmc, CJitem.ZLDWDM, FJFid), true);
if (CJitem.ListQsdwInfor == null || CJitem.ListQsdwInfor.Count == 0)
{
continue;
}
if (CJitem.ListQsdwInfor == null) continue;//特殊情况
foreach (var CJDMitem in CJitem.ListQsdwInfor)
{
string CJDMstrSql = string.Format("insert into Sys_DicDetail(PID,NAME,CODE,OWNERDIC,REMARK,PAIXU) VALUES ('{0}','{1}','{2}','{3}','{4}',{5})", dtCJDM.Rows[0]["ID"].ToString(), CJDMitem.Qsdwmc, CJDMitem.Qsdwdm, FJFid, "", 0);
if (rdbHelper.ExecuteSQL(CJDMstrSql) < 1)
{
return false;
}
}
}
}
}
return true;
}
return false; ;
}
catch (Exception e)
{
// rdbHelper.Rollback();
return false;
throw e;
}
finally
{ }
}
///
/// 插入字典数据
///
/// 数据库连接
private void InserDataDic(IRDBHelper rdbHelper)
{
try
{
DataTable QuerySon = rdbHelper.ExecuteDatatable("QuerySon", "SELECT ID FROM Sys_DicManage WHERE NAME='权属代码'", false);
string strSql = string.Empty;
if (QuerySon == null || QuerySon.Rows.Count <= 0)
return;
foreach (var item in ShengInfo2)
{
if (!string.IsNullOrWhiteSpace(item.Qsdwdm))
{
strSql = string.Format("insert into Sys_DicDetail (PID,NAME,CODE,OWNERDIC,REMARK,PAIXU)" + "VALUES ('{0}','{1}','{2}','{3}','{4}',{5})", "", item.Qsdwmc.Trim(), item.Qsdwdm, QuerySon.Rows[0]["ID"].ToString(), "", 0);
}
else
{
strSql = string.Format("insert into Sys_DicDetail (PID,NAME,CODE,OWNERDIC,REMARK,PAIXU)" + "VALUES ('{0}','{1}','{2}','{3}','{4}',{5})", "", item.Qsdwmc.Trim(), item.Qsdwmc, QuerySon.Rows[0]["ID"].ToString(), "", 0);
}
int insertCount = rdbHelper.ExecuteSQL(strSql);
if (insertCount <= 0) return;
DataTable QueryQSSon = null;
if (!string.IsNullOrWhiteSpace(item.Qsdwdm))
{
QueryQSSon = rdbHelper.ExecuteDatatable("QueryQS", string.Format("SELECT ID FROM Sys_DicDetail WHERE NAME='{0}' AND PID='' AND CODE='{1}' AND OWNERDIC='{2}'", item.Qsdwmc.Trim(), item.Qsdwdm, QuerySon.Rows[0]["ID"].ToString()), true);
}
else
{
QueryQSSon = rdbHelper.ExecuteDatatable("QueryQS", string.Format("SELECT ID FROM Sys_DicDetail WHERE NAME='{0}' AND PID='' AND CODE='{1}' AND OWNERDIC='{2}'", item.Qsdwmc.Trim(), item.Qsdwmc.Trim(), QuerySon.Rows[0]["ID"].ToString()), true);
}
if (QueryQSSon == null || QueryQSSon.Rows.Count <= 0) return;
foreach (var shi in ShiInfo2)
{
if (!string.IsNullOrWhiteSpace(shi.Qsdwdm))
{
strSql = string.Format("insert into Sys_DicDetail (PID,NAME,CODE,OWNERDIC,REMARK,PAIXU)" + "VALUES ('{0}','{1}','{2}','{3}','{4}',{5})", QueryQSSon.Rows[0]["ID"].ToString(), shi.Qsdwmc.Trim(), shi.Qsdwdm, QuerySon.Rows[0]["ID"].ToString(), "", 0);
}
else
{
strSql = string.Format("insert into Sys_DicDetail (PID,NAME,CODE,OWNERDIC,REMARK,PAIXU)" + "VALUES ('{0}','{1}','{2}','{3}','{4}',{5})", QueryQSSon.Rows[0]["ID"].ToString(), shi.Qsdwmc.Trim(), shi.Qsdwmc.Trim(), QuerySon.Rows[0]["ID"].ToString(), "", 0);
}
insertCount = rdbHelper.ExecuteSQL(strSql);
if (insertCount <= 0) return;
DataTable QueryQSSons = null;
if (!string.IsNullOrWhiteSpace(shi.Qsdwdm))
{
QueryQSSons = rdbHelper.ExecuteDatatable("QueryQSs", string.Format("SELECT ID FROM Sys_DicDetail WHERE NAME='{0}' AND PID='{1}' AND CODE='{2}' AND OWNERDIC='{3}'", shi.Qsdwmc.Trim(), QueryQSSon.Rows[0]["ID"].ToString(), shi.Qsdwdm, QuerySon.Rows[0]["ID"].ToString()), true);
}
else
{
QueryQSSons = rdbHelper.ExecuteDatatable("QueryQSs", string.Format("SELECT ID FROM Sys_DicDetail WHERE NAME='{0}' AND PID='{1}' AND CODE='{2}' AND OWNERDIC='{3}'", shi.Qsdwmc.Trim(), QueryQSSon.Rows[0]["ID"].ToString(), shi.Qsdwdm.Trim(), QuerySon.Rows[0]["ID"].ToString()), true);
}
if (QueryQSSons == null || QueryQSSons.Rows.Count <= 0) return;
foreach (var xian in XianInfo2)
{
if (!string.IsNullOrWhiteSpace(xian.Qsdwdm))
{
strSql = string.Format("insert into Sys_DicDetail (PID,NAME,CODE,OWNERDIC,REMARK,PAIXU)" + "VALUES ('{0}','{1}','{2}','{3}','{4}',{5})", QueryQSSons.Rows[0]["ID"].ToString(), xian.Qsdwmc.Trim(), xian.Qsdwdm, QuerySon.Rows[0]["ID"].ToString(), "", 0);
}
else
{
strSql = string.Format("insert into Sys_DicDetail (PID,NAME,CODE,OWNERDIC,REMARK,PAIXU)" + "VALUES ('{0}','{1}','{2}','{3}','{4}',{5})", QueryQSSons.Rows[0]["ID"].ToString(), xian.Qsdwmc.Trim(), xian.Qsdwmc.Trim(), QuerySon.Rows[0]["ID"].ToString(), "", 0);
}
insertCount = rdbHelper.ExecuteSQL(strSql);
if (insertCount <= 0) return;
DataTable QueryQSSonsd = null;
if (xian.Qsdwdm != "")
{
QueryQSSonsd = rdbHelper.ExecuteDatatable("QueryQSsd", string.Format("SELECT ID FROM Sys_DicDetail WHERE NAME='{0}' AND PID='{1}' AND CODE='{2}' AND OWNERDIC='{3}'", xian.Qsdwmc.Trim(), QueryQSSons.Rows[0]["ID"].ToString(), xian.Qsdwdm, QuerySon.Rows[0]["ID"].ToString()), true);
}
else
{
QueryQSSonsd = rdbHelper.ExecuteDatatable("QueryQSsd", string.Format("SELECT ID FROM Sys_DicDetail WHERE NAME='{0}' AND PID='{1}' AND CODE='{2}' AND OWNERDIC='{3}'", xian.Qsdwmc.Trim(), QueryQSSons.Rows[0]["ID"].ToString(), xian.Qsdwmc.Trim(), QuerySon.Rows[0]["ID"].ToString()), true);
}
if (QueryQSSonsd != null && QueryQSSonsd.Rows.Count > 0)
{
XJFid = QueryQSSonsd.Rows[0]["ID"].ToString();
FJFid = QuerySon.Rows[0]["ID"].ToString();
InserDataLsitSon(rdbHelper, xian.Qsdwdm);
}
}
}
}
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 左侧字典树选择改变事件
///
///
///
private void tvProperties_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs