using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using ESRI.ArcGIS.Geodatabase;
using KGIS.Framework.DBOperator;
using KGIS.Framework.Maps;
using KGIS.Framework.OpenData.Control;
using KGIS.Framework.OpenData.Filter;
using KGIS.Framework.Platform;
using KGIS.Framework.Platform.Helper;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using KGIS.Framework.Views;
using Kingo.Plugin.DataDictionary.Helper;
using Kingo.PluginServiceInterface;
using UIShell.OSGi;
using KUI.Windows;
namespace Kingo.Plugin.DataDictionary.Views
{
///
/// NewDataManage.xaml 的交互逻辑
///
public partial class KBGNewDataManage : BaseWindow
{
///
/// 记录选择图层数据的字段集合
///
private List lstName = new List();
///
/// 记录所有的数据(权属单位代码,权属单位名称和坐落单位名称)
///
private List ListQsdwEntity = null;
///
/// 保存权属单位数据
///
private string XJFid = null;
private string FJFid = null;
private string QsdmID = null;
private List ListQsdm = null;
private IFeatureClass pFC = null;
public Action Refresh;
public KBGNewDataManage()
{
InitializeComponent();
}
#region
public bool InserDataLsitSon()
{
string dbPath = System.IO.Path.GetDirectoryName((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetProjFilePath()) + @"\BGTJ.sqlite";
if (string.IsNullOrWhiteSpace(dbPath))
return false;
IRDBHelper rdbHelper = null;
try
{
rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
if (ListQsdm != null && ListQsdm.Count > 0)
{
rdbHelper.BeginTransaction();
foreach (var item in ListQsdm)
{
//修改人:李忠盼 修改时间:20190220 向表中插入行政区名称
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;
}
}
}
}
rdbHelper.Commit();
return true;
}
return true;
}
catch (Exception e)
{
rdbHelper.Rollback();
return false;
throw e;
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
}
}
#endregion
public void OrderBy(string XJCode, string XJName)
{
try
{
if (ListQsdwEntity != null && ListQsdwEntity.Count > 0)
{
ListQsdm = new List();
var GroupEntity = ListQsdwEntity.Where(x => x.ZLDWDM.Length == 19).GroupBy(x => x.ZLDWDM.Substring(0, 9)).Select(x => x.Key).ToList();//获取村级坐落获取镇级权属代码前九位
var Temp = ListQsdwEntity.FirstOrDefault(x => x.Qsdwdm == XJCode.PadRight(19, '0'));
if (Temp != null && Temp.Qsdwmc != XJName)
GroupEntity.Add(Temp.Qsdwdm.Substring(0, 9));
foreach (var item in GroupEntity)//截取乡镇权属代码
{
QSDWinformation Qsdm = new QSDWinformation();
Qsdm.ZLDWDM = item;
Qsdm.Qsdwdm = item;
BasicDataModel[] xzqDic = DicHelper.GetXZQDic(2);
if (xzqDic == null)
return;
var xzqInfo = xzqDic.Where(x => x.Code == item).ToList();
if (xzqInfo.Count == 0)
xzqInfo = xzqDic.Where(x => x.Code == item.Replace(item.Substring(0, 6), xzqDic[0].Code.Substring(0, 6))).ToList();
foreach (var xzq in xzqInfo)
{
Qsdm.Qsdwmc = xzq.Name;
Qsdm.Zldwmc = xzq.Name;
}
List ListCjQsdm = new List();
if (item == XJCode.PadRight(9, '0'))//特殊案例-与县级同权属代码的镇一级(并且为非飞入地)
{
Qsdm.ZLDWDM = XJCode.PadRight(9, '0');
Qsdm.Qsdwdm = XJCode.PadRight(9, '0');
Qsdm.Qsdwmc = Temp.Qsdwmc;
Qsdm.Zldwmc = Temp.Qsdwmc;
QSDWinformation CjQsdm = new QSDWinformation();
CjQsdm.Qsdwdm = XJCode.PadRight(12, '0');
CjQsdm.ZLDWDM = XJCode.PadRight(12, '0');
CjQsdm.Qsdwmc = Temp.Qsdwmc;
CjQsdm.Zldwmc = Temp.Qsdwmc;
List ListCjDMQsdm = new List();
QSDWinformation CjDMQsdm = new QSDWinformation();
CjDMQsdm.Qsdwdm = "";
CjDMQsdm.Qsdwmc = "";
ListCjDMQsdm.Add(CjDMQsdm);
CjQsdm.ListQsdwInfor = null;//权属村级子级
ListCjQsdm.Add(CjQsdm);
Qsdm.ListQsdwInfor = null;//权属镇级子级
ListQsdm.Add(Qsdm);
continue;
}
#region
var CJGroupEntity = ListQsdwEntity.Where(x => x.HasCheck).GroupBy(x => x.ZLDWDM).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 = CJitem;
CjQsdm.ZLDWDM = CJitem;
#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)
{
CjQsdm.Zldwmc = ListQsdwEntity.FirstOrDefault(x => x.ZLDWDM == citem).Zldwmc;
List ListCjDMQsdm = new List();
var CJDMGroupEntity = ListQsdwEntity.Where(x => x.HasCheck).GroupBy(x => x.ZLDWDM).Select(x => x.Key).Distinct().ToList();//.Select(n => n);
var tmpglist = CJDMGroupEntity.Where(x => x.Substring(0, 12) == CJitem.Substring(0, 12)).ToList();
foreach (var CJDMitem in tmpglist)//获取村级代码
{
#region
var cjkeylist = ListQsdwEntity.Where(x => x.HasCheck && x.ZLDWDM == CJDMitem).Distinct().ToList();
foreach (var itemsD in cjkeylist)//获取村级小组权属代码名称
{
var cu = ListCjDMQsdm.Count(x => x.Qsdwdm == itemsD.Qsdwdm && x.Qsdwmc == itemsD.Qsdwmc);
if (cu == 0)
{
QSDWinformation CjDMQsdm = new QSDWinformation();
CjDMQsdm.Qsdwdm = itemsD.Qsdwdm;
CjDMQsdm.Qsdwmc = itemsD.Qsdwmc;
ListCjDMQsdm.Add(CjDMQsdm);
}
}
#endregion
}
CjQsdm.ListQsdwInfor = ListCjDMQsdm;
}
ListCjQsdm.Add(CjQsdm);
#endregion
}
Qsdm.ListQsdwInfor = ListCjQsdm;
ListQsdm.Add(Qsdm);
#endregion
}
}
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 省级代码文本框值发生变化事件
///
///
///
private void txt_XJDM_TextChanged(object sender, TextChangedEventArgs e)
{
try
{
Regex re = new Regex("^[0-9]*$");
if (!re.IsMatch(this.txt_XJDM.Text.ToString()))
{
MessageHelper.Show("输入错误,请重新输入!");
this.txt_XJDM.Text = "";
return;
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
MessageHelper.Show("抱歉,新增字典异常!");
}
}
///
/// 市级代码文本框值发生变化事件
///
///
///
private void txt_XianJDMCD_TextChanged(object sender, TextChangedEventArgs e)
{
try
{
Regex re = new Regex("^[0-9]*$");
if (!re.IsMatch(this.txt_XianJDMCD.Text.ToString()))
{
MessageHelper.Show("输入错误,请重新输入!");
this.txt_XianJDMCD.Text = "";
return;
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
MessageHelper.Show("抱歉,新增字典异常!");
}
}
///
/// 县级代码文本框值发生变化事件
///
///
///
private void txt_CJDMCD_TextChanged(object sender, TextChangedEventArgs e)
{
try
{
Regex re = new Regex("^[0-9]*$");
if (!re.IsMatch(this.txt_CJDMCD.Text.ToString()))
{
MessageHelper.Show("输入错误,请重新输入!");
this.txt_CJDMCD.Text = "";
return;
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
MessageHelper.ShowError("抱歉,新增字典异常!");
}
}
///
/// 选择地类图斑按钮事件
///
///
///
private void btn_DLTB_Click(object sender, RoutedEventArgs e)
{
try
{
OpenDataDialog pDialog = new OpenDataDialog();
KGIS.Framework.OpenData.InterFace.ISpatialDataObjectFilter pOFilter;
pOFilter = new FilterDatasetsAndLayers();
pDialog.AddFilter(pOFilter, true);
pDialog.Title = "选择导入的数据";
pDialog.AllowMultiSelect = false;
pDialog.RestoreLocation = true;
pDialog.StartLocation = pDialog.FinalLocation;
if (pDialog.ShowDialog() == System.Windows.Forms.DialogResult.Cancel || pDialog.Selection.Count <= 0)
{
return;
}
ListQsdwEntity = new List();
this.ShowLoading("正在解析文件...", 0, 0);
KGIS.Framework.OpenData.InterFace.ISpatialDataObject distObj = pDialog.Selection[0];
if (distObj.DatasetType == esriDatasetType.esriDTFeatureClass)
{
btn_DLTB.Text = distObj.FullName;
pFC = (distObj.DatasetName as ESRI.ArcGIS.esriSystem.IName).Open() as IFeatureClass;
if (pFC != null)
{
BindComboxField(pFC);
FullData(pFC);
AnalysisCode();
}
}
}
catch (Exception ex)
{
this.CloseLoading();
MessageHelper.ShowError("解析文件异常:" + ex.Message);
}
finally
{
this.CloseLoading();
}
}
///
/// 绑定权属单位代码,名称和坐落单位名称下拉框,并获取所有的数据
///
///
private void BindComboxField(IFeatureClass pFeatureClass)
{
try
{
cmb_Qsdwdmzd.ItemsSource = null;
cmb_Qsdwmczd.ItemsSource = null;
cmb_Zldwmczd.ItemsSource = null;
cmb_Zldwdmzd.ItemsSource = null;
txt_XJDM.Text = string.Empty;
txt_XianJDMCD.Text = string.Empty;
txt_CJDMCD.Text = string.Empty;
txt_ShengJMC.Text = string.Empty;//省级名称
txt_ShiJMC.Text = string.Empty;//市级名称
txt_XJMC.Text = string.Empty;//县级名称
lstName.Clear();
int qsdwdmIndex = -1;
int qsdwmcIndex = -1;
int zldwmcIndex = -1;
int zldwdmIndex = -1;
for (int i = 0; i < pFeatureClass.Fields.FieldCount; i++)
{
FeatureName FeatuName = new FeatureName();
FeatuName.Id = i;
FeatuName.Name = pFeatureClass.Fields.get_Field(i).Name;
lstName.Add(FeatuName);
if (FeatuName.Name.ToUpper() == "QSDWDM")
{
qsdwdmIndex = i;
}
if (FeatuName.Name.ToUpper() == "QSDWMC")
{
qsdwmcIndex = i;
}
if (FeatuName.Name.ToUpper() == "ZLDWMC")
{
zldwmcIndex = i;
}
if (FeatuName.Name.ToUpper() == "ZLDWDM")
{
zldwdmIndex = i;
}
}
cmb_Qsdwdmzd.ItemsSource = lstName;
cmb_Qsdwmczd.ItemsSource = lstName;
cmb_Zldwmczd.ItemsSource = lstName;
cmb_Zldwdmzd.ItemsSource = lstName;
cmb_Qsdwdmzd.SelectedIndex = qsdwdmIndex;
cmb_Qsdwmczd.SelectedIndex = qsdwmcIndex;
cmb_Zldwmczd.SelectedIndex = zldwmcIndex;
cmb_Zldwdmzd.SelectedIndex = zldwdmIndex;
}
catch (Exception ex)
{
throw ex;
}
}
///
///
///
///
///
///
///
///
///
private void FullData(IFeatureClass pFeatureClass)
{
int qsdwdmIndex = cmb_Qsdwdmzd.SelectedIndex;
int qsdwmcIndex = cmb_Qsdwmczd.SelectedIndex;
int zldwmcIndex = cmb_Zldwmczd.SelectedIndex;
int zldwdmIndex = cmb_Zldwdmzd.SelectedIndex;
List restlist = new List();
IFeatureCursor featureCursor = null;
try
{
IFeature feature = null;
featureCursor = pFeatureClass.Search(null, true);
ListQsdwEntity.Clear();
while ((feature = featureCursor.NextFeature()) != null)
{
QSDWinformation QsdwEntity = new QSDWinformation();
if (qsdwdmIndex > -1)
{
var tempQsdwdm = feature.get_Value(qsdwdmIndex).ToString();
QsdwEntity.Qsdwdm = tempQsdwdm;
}
if (qsdwmcIndex > -1)
{
QsdwEntity.Qsdwmc = feature.get_Value(qsdwmcIndex).ToString();
if (QsdwEntity.Qsdwmc == "部队") { }
}
if (zldwmcIndex > -1)
{
QsdwEntity.Zldwmc = feature.get_Value(zldwmcIndex).ToString();
}
if (zldwdmIndex > -1)
{
var tempZLDWDM = feature.get_Value(zldwdmIndex).ToString();
QsdwEntity.ZLDWDM = tempZLDWDM;
}
QsdwEntity.HasCheck = true;
if (ListQsdwEntity != null && ListQsdwEntity.Where(x => x.ZLDWDM == QsdwEntity.ZLDWDM).Count() == 0)
{
ListQsdwEntity.Add(QsdwEntity);
}
}
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
throw ex;
}
finally
{
if (featureCursor != null)
{
Marshal.ReleaseComObject(featureCursor);
}
}
}
private void AnalysisCode()
{
KGIS.Framework.DBOperator.IRDBHelper rdbHelper = null;
try
{
//去除坐落单位代码
if (ListQsdwEntity != null && ListQsdwEntity.Count > 0)
{
var first = ListQsdwEntity.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.ZLDWDM) && (new[] { 12, 19 }).Contains(x.ZLDWDM.Length));
if (first != null)
{
txt_XJDM.Text = first.ZLDWDM.Substring(0, 2).ToString();
txt_XianJDMCD.Text = first.ZLDWDM.Substring(0, 4).ToString();
txt_CJDMCD.Text = first.ZLDWDM.Substring(0, 6).ToString();
string systemPath = SysAppPath.GetDataBasePath() + "System.mdb";
if (System.IO.File.Exists(systemPath))
{
string connStr = SysConfigsOprator.GetDBConnectionByName("MDBOledbConnection");
connStr = string.Format(connStr, systemPath);
rdbHelper = RDBFactory.CreateDbHelper(connStr, DatabaseType.MSAccess);
string strSQL = String.Format("select XZQMC, XZQ,SDM,SMC,SHDM,SHMC from XZQ Where XZQ ='{0}' ", txt_CJDMCD.Text);
DataTable dt = rdbHelper.ExecuteDatatable("Dic", strSQL, true);
if (dt != null && dt.Rows.Count != 0)
{
DataRow row = dt.Rows[0];
txt_ShengJMC.Text = row["SHMC"].ToString();//省级名称
txt_ShiJMC.Text = row["SMC"].ToString();//市级名称
txt_XJMC.Text = row["XZQMC"].ToString();//县级名称
}
}
}
else
{
txt_XJDM.Text = "";
txt_XianJDMCD.Text = "";
txt_CJDMCD.Text = "";
txt_ShengJMC.Text = "";//省级名称
txt_ShiJMC.Text = "";//市级名称
txt_XJMC.Text = "";//县级名称
this.CloseLoading();
MessageHelper.ShowError("解析坐落代码数据失败,请选择正确的坐落代码字段!");
}
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
}
}
///
/// 检查数据库是否已经存在权属单位代码字典
///
private void CheckExist()
{
IRDBHelper rdbHelper = null;
try
{
string Path = System.IO.Path.GetDirectoryName((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetProjFilePath()) + @"\BGTJ.sqlite";
rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + Path, DatabaseType.SQLite);
if (rdbHelper == null)
{
throw new Exception("打开数据库连接失败!");
}
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)
{
var dr = MessageHelper.ShowYesNoAndTips("权属代码字典已存在,是否替换?");
if (dr == System.Windows.Forms.DialogResult.Yes)
{
this.UpdateMsg("正在生成字典......");
//先删除数据库已存在的字典
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
return;
}
}
else//数据库不存在权属单位代码字典
{
this.UpdateMsg("正在生成字典......");
//插入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);
if (InserDataLsitSon())
{
//loading.Visibility = Visibility.Collapsed;
//修改原因:不需要将字典保存到工程文件中 修改人:高山 修改时间:2019.09.21
this.CloseLoading();
MessageHelper.Show("新增字典成功!");
Refresh?.Invoke();
this.Close();
return;
}
}
catch (Exception ex)
{
MessageHelper.ShowError(ex.Message);
}
finally
{
this.CloseLoading();
if (rdbHelper != null)
rdbHelper.DisConnect();
}
}
///
/// 插入字典数据
///
/// 数据库连接
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;
if (!string.IsNullOrWhiteSpace(txt_XJDM.Text.Trim().ToString()))
strSql = string.Format("insert into Sys_DicDetail (PID,NAME,CODE,OWNERDIC,REMARK,PAIXU)" + "VALUES ('{0}','{1}','{2}','{3}','{4}',{5})", "", txt_ShengJMC.Text.Trim().ToString(), txt_XJDM.Text.Trim().ToString(), 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})", "", txt_ShengJMC.Text.Trim().ToString(), txt_ShengJMC.Text.Trim().ToString(), QuerySon.Rows[0]["ID"].ToString(), "", 0);
int insertCount = rdbHelper.ExecuteSQL(strSql);
if (insertCount <= 0)
return;
DataTable QueryQSSon = null;
if (!string.IsNullOrWhiteSpace(txt_XJDM.Text.Trim().ToString()))
{
QueryQSSon = rdbHelper.ExecuteDatatable("QueryQS", string.Format("SELECT ID FROM Sys_DicDetail WHERE NAME='{0}' AND PID='' AND CODE='{1}' AND OWNERDIC='{2}'", txt_ShengJMC.Text.Trim().ToString(), txt_XJDM.Text.Trim().ToString(), QuerySon.Rows[0]["ID"].ToString()), false);
}
else
{
QueryQSSon = rdbHelper.ExecuteDatatable("QueryQS", string.Format("SELECT ID FROM Sys_DicDetail WHERE NAME='{0}' AND PID='' AND CODE='{1}' AND OWNERDIC='{2}'", txt_ShengJMC.Text.Trim().ToString(), txt_ShengJMC.Text.Trim().ToString(), QuerySon.Rows[0]["ID"].ToString()), false);
}
if (QueryQSSon == null || QueryQSSon.Rows.Count <= 0)
{
return;
}
if (!string.IsNullOrWhiteSpace(txt_XianJDMCD.Text.Trim().ToString()))
{
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(), txt_ShiJMC.Text.Trim().ToString(), txt_XianJDMCD.Text.Trim().ToString(), 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(), txt_ShiJMC.Text.Trim().ToString(), txt_ShiJMC.Text.Trim().ToString(), QuerySon.Rows[0]["ID"].ToString(), "", 0);
}
insertCount = rdbHelper.ExecuteSQL(strSql);
if (insertCount <= 0)
return;
DataTable QueryQSSons = null;
if (txt_XianJDMCD.Text.Trim().ToString() != "")
{
QueryQSSons = rdbHelper.ExecuteDatatable("QueryQSs", string.Format("SELECT ID FROM Sys_DicDetail WHERE NAME='{0}' AND PID='{1}' AND CODE='{2}' AND OWNERDIC='{3}'", txt_ShiJMC.Text.Trim().ToString(), QueryQSSon.Rows[0]["ID"].ToString(), txt_XianJDMCD.Text.Trim().ToString(), QuerySon.Rows[0]["ID"].ToString()), false);
}
else
{
QueryQSSons = rdbHelper.ExecuteDatatable("QueryQSs", string.Format("SELECT ID FROM Sys_DicDetail WHERE NAME='{0}' AND PID='{1}' AND CODE='{2}' AND OWNERDIC='{3}'", txt_ShiJMC.Text.Trim().ToString(), QueryQSSon.Rows[0]["ID"].ToString(), txt_ShiJMC.Text.Trim().ToString(), QuerySon.Rows[0]["ID"].ToString()), false);
}
if (QueryQSSons == null || QueryQSSons.Rows.Count <= 0)
return;
if (!string.IsNullOrWhiteSpace(txt_CJDMCD.Text.Trim().ToString()))
{
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(), txt_XJMC.Text.Trim().ToString(), txt_CJDMCD.Text.Trim().ToString(), 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(), txt_XJMC.Text.Trim().ToString(), txt_XJMC.Text.Trim().ToString(), QuerySon.Rows[0]["ID"].ToString(), "", 0);
}
insertCount = rdbHelper.ExecuteSQL(strSql);
if (insertCount <= 0)
return;
DataTable QueryQSSonsd = null;
if (txt_CJDMCD.Text.Trim().ToString() != "")
{
QueryQSSonsd = rdbHelper.ExecuteDatatable("QueryQSsd", string.Format("SELECT ID FROM Sys_DicDetail WHERE NAME='{0}' AND PID='{1}' AND CODE='{2}' AND OWNERDIC='{3}'", txt_XJMC.Text.Trim().ToString(), QueryQSSons.Rows[0]["ID"].ToString(), txt_CJDMCD.Text.Trim().ToString(), QuerySon.Rows[0]["ID"].ToString()), false);
}
else
{
QueryQSSonsd = rdbHelper.ExecuteDatatable("QueryQSsd", string.Format("SELECT ID FROM Sys_DicDetail WHERE NAME='{0}' AND PID='{1}' AND CODE='{2}' AND OWNERDIC='{3}'", txt_XJMC.Text.Trim().ToString(), QueryQSSons.Rows[0]["ID"].ToString(), txt_XJMC.Text.Trim().ToString(), QuerySon.Rows[0]["ID"].ToString()), false);
}
if (QueryQSSonsd != null && QueryQSSonsd.Rows.Count > 0)
{
XJFid = QueryQSSonsd.Rows[0]["ID"].ToString();
FJFid = QuerySon.Rows[0]["ID"].ToString();
}
}
catch (Exception ex)
{
LogAPI.Debug("插入字典失败:" + ex.Message);
throw ex;
}
}
///
/// 窗口关闭事件
///
///
///
private void btn_nO_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
///
/// 确定按钮事件
///
///
///
private void btn_oK_Click(object sender, RoutedEventArgs e)
{
try
{
if (this.txt_XJDM.Text.Trim().ToString() == "")
{
MessageHelper.Show("省级代码解析错误!");
return;
}
if (this.txt_XianJDMCD.Text.Trim().ToString() == "")
{
MessageHelper.Show("市级代码解析错误!");
return;
}
if (this.txt_CJDMCD.Text.Trim().ToString() == "")
{
MessageHelper.Show("县级代码解析错误!");
return;
}
if (this.txt_ShengJMC.Text.Trim().ToString() == "")
{
MessageHelper.Show("省级名称不能为空,请重新输入!");
return;
}
if (this.txt_ShiJMC.Text.Trim().ToString() == "")
{
MessageHelper.Show("市级名称不能为空,请重新输入!");
return;
}
if (this.txt_XJMC.Text.Trim().ToString() == "")
{
MessageHelper.Show("县级名称不能为空,请重新输入!");
return;
}
this.ShowLoading("正在生成权属单位字典...", 0, 0);
//CustomLogAPI.WriteSystemOperationLog("数据新增", this.Title);
//判断是否有不符合要求的数据
if ((ListQsdwEntity == null || ListQsdwEntity.Count == 0) && pFC != null)
{
FullData(pFC);
Run();
}
var count = 0;
var qsount = 0;
if (ListQsdwEntity != null)
{
count = ListQsdwEntity.Where(x => string.IsNullOrWhiteSpace(x.ZLDWDM) || (new[] { 12, 19 }).Contains(x.ZLDWDM.Length) == false).Count();
//判断是否有不符合要求的数据
qsount = ListQsdwEntity.Where(x => string.IsNullOrWhiteSpace(x.Qsdwdm) || (new[] { 12, 19 }).Contains(x.Qsdwdm.Length) == false).Count();
}
else
{
ListQsdwEntity = new List();
}
if (count > 0 || qsount > 0)
{
//this.CloseLoading();
if (MessageHelper.ShowYesNoAndWarning("所选数据坐落代码和权属代码存在异常,是否继续生成?") == System.Windows.Forms.DialogResult.Yes)
{
this.UpdateMsg("正在生成权属单位字典...");
Run();
OrderBy(txt_CJDMCD.Text.Trim().ToString(), txt_XJMC.Text.Trim().ToString());
this.CloseLoading();
CheckExist();
}
}
else
{
Run();
OrderBy(txt_CJDMCD.Text.Trim().ToString(), txt_XJMC.Text.Trim().ToString());
CheckExist();
}
}
catch (Exception ex)
{
this.CloseLoading();
MessageHelper.ShowError("数据字典保存异常:" + ex.Message);
}
finally
{
if (pFC != null)
Marshal.ReleaseComObject(pFC);
}
}
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;
}
});
//处理验证失败的数据
for (var i = 0; i < ListQsdwEntity.Count; i++)
{
if (ListQsdwEntity[i].HasCheck == false)
{
ListQsdwEntity.Remove(ListQsdwEntity[i]);
if (i > 0)
{
i = i - 1;
}
}
}
}
}
public class FeatureName
{
private int _id;
private string _name;
public int Id
{
get
{
return _id;
}
set
{
_id = value;
}
}
public string Name
{
get
{
return _name;
}
set
{
_name = value;
}
}
}
}