違法佔耕輔助處理軟體
1、功能介面
1.1登入介面
1.2主介面
1.2.1功能選項
1.2.2系統設定
1.3屬性質量檢查
1.3.1檢查項設定
1.4屬性對等計算
1.4轉換後屬性質量檢查
1.5 多媒體處理
主介面原始碼:
public partial class MainForm : DevExpress.XtraEditors.XtraForm
{
/// <summary>
/// 委託實現皮膚切換
/// </summary>
public MyDelegateGetSkin getSkinDel;
/// 用於儲存所有要素-屬性計算
/// </summary>
private List<IFeatureLayer> listFLayerCalcu = null;
/// <summary>
/// 用於儲存所有要素-轉換前檢查
/// </summary>
private List<IFeatureLayer> listFLayerZHQ_Check = null;
/// <summary>
/// 用於儲存所有要素-轉換後檢查
/// </summary>
private List<IFeatureLayer> listFLayerZHH_Check = null;
private void tsBTN_openGDB_Click(object sender, EventArgs e)
{
MyFolderBrowserDialog mfbd = new MyFolderBrowserDialog();
if (mfbd.ShowDialog(this) == DialogResult.OK)
{
listFLayerCalcu = new List<IFeatureLayer>();
cmbxFeatureCls.Items.Clear();//清空
culFeatLayer = null;//
//cmbxFeatureCls.SelectedIndex = -1;
//cmbxMB.SelectedIndex = -1;
string strGDB_Path = mfbd.DirectoryPath;
FileGDBWorkspaceFactory fac = new FileGDBWorkspaceFactory();
IFeatureWorkspace pFtWS = (IFeatureWorkspace)fac.OpenFromFile(strGDB_Path, 0);
IWorkspace pWork = (IWorkspace)pFtWS;
IEnumDataset pEnumDs = pWork.get_Datasets(esriDatasetType.esriDTFeatureClass);
IDataset pDs = pEnumDs.Next();
axMapControl1.Map.ClearLayers();
tslbStatus.Text = "正在載入要素...";
statusStrip1.Refresh();
while (pDs != null)
{
IFeatureClass temp = pDs as IFeatureClass;
IFeatureLayer tempLayer = new FeatureLayer();
tempLayer.FeatureClass = temp;
tempLayer.Name = tempLayer.FeatureClass.AliasName;
listFLayerCalcu.Add(tempLayer);
cmbxFeatureCls.Items.Add(temp.AliasName);
axMapControl1.Map.AddLayer(tempLayer);
pDs = pEnumDs.Next();
}
tslbStatus.Text = "載入完成!";
tlSpStLb.Text = " 選項:屬性對等計算 當前資料庫:" + strGDB_Path;
statusStrip1.Refresh();
}
}
/// <summary>
/// 當前選擇的待計算資料
/// </summary>
private IFeatureLayer culFeatLayer = null;
/// <summary>
/// 選擇待計算的資料
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void cmbxFeatureCls_SelectedIndexChanged(object sender, EventArgs e)
{
culFeatLayer= listFLayerCalcu[cmbxFeatureCls.SelectedIndex];
}
private string strSelMB = String.Empty;
/// <summary>
/// 選擇資料計算模板
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void cmbxMB_SelectedIndexChanged(object sender, EventArgs e)
{
if (culFeatLayer==null)
{
MessageBox.Show("請先選擇圖層");
return;
}
strSelMB = cmbxMB.SelectedItem.ToString();
}
/// <summary>
/// 執行計算
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsBTN_ExcuteCacl_Click(object sender, EventArgs e)
{
if (culFeatLayer==null)
{
MessageBox.Show("沒有資料可計算!請先開啟或選擇資料", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (cmbxMB.SelectedIndex == -1)
{
MessageBox.Show("請選擇模板型別", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
DateTime dtStart = DateTime.Now;
splashScreenManager1.ShowWaitForm();
splashScreenManager1.SetWaitFormCaption("正在計算 "+ strSelMB);
splashScreenManager1.SetWaitFormDescription("請耐心等待...");
/*
住宅類
產業類
公共服務類
其他構築物
*/
if (strSelMB == "住宅類")
{
string selSQL = String.Empty;
//計算---直接等於
selSQL = null;
IFeatureLayer tempFeatLayer = culFeatLayer;
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
#region
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "CITY_NAME");
CaculValue2(tempFeatLayer, selSQL, "CITY_NAME", "shi");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "XZQMC_XQ");
CaculValue2(tempFeatLayer, selSQL, "XZQMC_XQ", "xian");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "XZQMC_XZ");
CaculValue2(tempFeatLayer, selSQL, "XZQMC_XZ", "xiang");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "XZQMC_CUN");
CaculValue2(tempFeatLayer, selSQL, "XZQMC_CUN", "cun");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "XXDZ_Z");
CaculValue2(tempFeatLayer, selSQL, "XXDZ_Z", "zu");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "XXDZ_MPH");
CaculValue2(tempFeatLayer, selSQL, "XXDZ_MPH", "mph");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "JBXX_KGSJ");
CaculValue2(tempFeatLayer, selSQL, "JBXX_KGSJ", "kgsj");
//超過本地區宅基地標準面積 cggdmj GLXX_CCBZMJ
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "GLXX_CCBZMJ");
CaculValue3(tempFeatLayer, selSQL, "GLXX_CCBZMJ", "cggdmj");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "glxx_zygdmj");
CaculValue3(tempFeatLayer, selSQL, "glxx_zygdmj", "zygdmj");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "glxx_zyyjjbntmj");
CaculValue3(tempFeatLayer, selSQL, "glxx_zyyjjbntmj", "zyjbntmj");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "BZ");
CaculValue2(tempFeatLayer, selSQL, "BZ", "cjybz");
selSQL = "XXDZ_Z is null or XXDZ_Z=''";
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算2 " + "XXDZ_Z");
CaculValue2(tempFeatLayer, selSQL, "XXDZ_Z", "無");
try
{
//單使用者住宅---個人姓名 grxm JBXX_JSZT_GRXM
selSQL = "\"fwlx\"='" + "單戶住宅" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "JBXX_JSZT_GRXM");
CaculValue2(tempFeatLayer, selSQL, "JBXX_JSZT_GRXM", "grxm");
}catch{ }
try
{
//單使用者住宅---身份證 sfzh JBXX_JSZT_ZJHM
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "JBXX_JSZT_ZJHM");
selSQL = "\"fwlx\"='" + "單戶住宅" + "'";
CaculValue2(tempFeatLayer, selSQL, "JBXX_JSZT_ZJHM", "sfzh");
}catch{}
try
{
//多使用者住宅---計算專案名稱 xmmc JBXX_XMMC
selSQL = "\"fwlx\"='" + "多戶住宅" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "JBXX_XMMC");
CaculValue2(tempFeatLayer, selSQL, "JBXX_XMMC", "xmmc");
} catch { }
//房屋型別 fwlx JBXX_FWLX
//1 - 單戶住宅
//2 - 多戶住宅
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "JBXX_FWLX");
selSQL = "\"fwlx\"='" + "單戶住宅" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_FWLX", 1);
selSQL = "\"fwlx\"='" + "多戶住宅" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_FWLX", 2);
//個人身份 grsf JBXX_JSZT_GRSF
//1:幹部
//2:中共黨員
//3:群眾
selSQL = "\"grsf\"='" + "幹部" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "JBXX_JSZT_GRSF");
CaculValue(tempFeatLayer, selSQL, "JBXX_JSZT_GRSF", 1);
selSQL = "\"grsf\" like '%" + "中共黨員" + "%'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_JSZT_GRSF", 2);
selSQL = "\"grsf\"='" + "群眾" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_JSZT_GRSF", 3);
//是否本村村民 sfbccm JBXX_JSZT_SFBCCM
//1:本村村民
//2:外村村民
//3:城鎮居民
//4:其他
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "JBXX_JSZT_SFBCCM");
foreach (KeyValuePair<string, int> keyValuePair in ModelDataCls.listSFBCCM)
{
selSQL = "\"sfbccm\"='" + keyValuePair.Key + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_JSZT_SFBCCM", keyValuePair.Value);
}
//多戶填報---建設單位名稱 jsdwmc JBXX_JSZT_DWMC
selSQL = "\"fwlx\"='" + "多戶住宅" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "JBXX_JSZT_DWMC");
CaculValue2(tempFeatLayer, selSQL, "JBXX_JSZT_DWMC", "jsdwmc");
//土地主要來源 tdzyly JBXX_TDZYLY
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "JBXX_TDZYLY");
foreach (KeyValuePair<string, int> keyValuePair in ModelDataCls.listJBXX_TDZYLY)
{
if (keyValuePair.Key== "集體自營土地")
{
selSQL = "\"tdzyly\" like '集體自營%'";
}
else
{
selSQL = "\"tdzyly\"='" + keyValuePair.Key + "'";
}
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_TDZYLY", keyValuePair.Value);
}
//
////將老宅基地繼承 計算為 其他8
//
selSQL = "tdzyly='老宅基地繼承'";
CaculValue(tempFeatLayer, selSQL, "JBXX_TDZYLY", 8);
//建房原因 jfyy JBXX_JFYY
//1:分戶
//2:移民搬遷
//3:異地扶貧搬遷
//4:地質災害搬遷
//5:生態整治搬遷
//6:拆遷安置
//7:其他
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "JBXX_JFYY");
foreach (KeyValuePair<string, int> keyValuePair in ModelDataCls.listJFYY)
{
selSQL = "\"jfyy\"='" + keyValuePair.Key + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_JFYY", keyValuePair.Value);
}
//房屋是否出售 fwsfcs JBXX_FWSFCS
//0-否1-部分2-全部
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "JBXX_FWSFCS");
selSQL = "\"fwsfcs\"='" + "否" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_FWSFCS", 0);
selSQL = "\"fwsfcs\"='" + "部分" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_FWSFCS", 1);
selSQL = "\"fwsfcs\"='" + "全部" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_FWSFCS", 2);
//管理資訊_專案總佔用土地面積 GLXX_ZYDMJ=房屋(專案)佔地面積 fwzdmj +附屬設施面積 fsssmj
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "GLXX_ZYDMJ");
CaculValue4(culFeatLayer, "GLXX_ZYDMJ", "fwzdmj", "fsssmj");
//是否符合一戶一宅 sffhyhyz GLXX_SFFH_YHYZHFH
//單戶住宅特有:0-否1-是
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "GLXX_SFFH_YHYZHFH");
selSQL = "\"sffhyhyz\"='" + "否" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_SFFH_YHYZHFH", 0);
selSQL = "\"sffhyhyz\"='" + "是" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_SFFH_YHYZHFH", 1);
//一戶多宅原因 yhdzyy GLXX_YHDZYY
//1:不符合分戶條件
//2:繼承
//3:建新未拆舊
//4:贈予
//5:出售後再建
//6:購買
//7:純多佔
//8:其他
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "GLXX_YHDZYY");
foreach (KeyValuePair<string, int> keyValuePair in ModelDataCls.listYHDZYY)
{
selSQL = "\"yhdzyy\"='" + keyValuePair.Key + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_YHDZYY", keyValuePair.Value);
}
//用地手續情況 ydsxqk GLXX_YDSXQK
//0 - 無手續
//1 - 手續不全
//2 - 有手續但不合規
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "GLXX_YDSXQK");
selSQL = "\"ydsxqk\"='" + "無手續" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_YDSXQK", 1);
selSQL = "\"ydsxqk\"='" + "手續不全" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_YDSXQK", 2);
selSQL = "\"ydsxqk\"='" + "有手續但不合規" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_YDSXQK", 3);
//沒有合法合規用地手續主要原因 wydspyy GLXX_MYSXYY
//1:未申請辦理用地手續
//2:停批
//3:不符合申請條件
//4:不符合規劃
//5:無用地計劃指標
//6:未繳費
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "GLXX_MYSXYY");
foreach (KeyValuePair<string, int> keyValuePair in ModelDataCls.listMYSXYY)
{
selSQL = "\"wydspyy\"='" + keyValuePair.Key + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_MYSXYY", keyValuePair.Value);
}
//佔用耕地主要型別 zygdzylx GLXX_ZYGDLX
//zygdzylx01
//zygdzylx02
//zygdzylx03
//zygdzylx04
//zygdzylx05
//zygdzylx06
//zygdzylx07
//zygdzylx08
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "GLXX_ZYGDLX");
foreach (KeyValuePair<string, int> keyValuePair in ModelDataCls.listGLXX_ZYGDLX)
{
selSQL = "\"zygdzylx\"='" + keyValuePair.Key + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_ZYGDLX", keyValuePair.Value);
}
//是否符合城鄉(村莊)規劃 sffhcxgh GLXX_SFFH_CXGH
//1:未編制規劃
//2:符合
//3:部分符合
//4:不符合
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "GLXX_SFFH_CXGH");
foreach (KeyValuePair<string, int> keyValuePair in ModelDataCls.listSFFH_CXGH)
{
selSQL = "\"sffhcxgh\"='" + keyValuePair.Key + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_SFFH_CXGH", keyValuePair.Value);
}
//是否符合土地利用總體規劃(國土空間規劃)情況 sffhtdly GLXX_SFFH_TDLYGH
//0 - 符合
//1 - 部分符合
//2 - 不符合
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "GLXX_SFFH_TDLYGH");
selSQL = "\"sffhtdly\"='" + "符合" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_SFFH_TDLYGH", 2);
selSQL = "\"sffhtdly\"='" + "部分符合" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_SFFH_TDLYGH", 1);
selSQL = "\"sffhtdly\"='" + "不符合" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_SFFH_TDLYGH", 0);
//是否作出行政處罰 sfxzcf GLXX_SF_XZCF
//0 - 否
//1 - 是
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "GLXX_SF_XZCF");
selSQL = "\"sfxzcf\"='" + "否" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_SF_XZCF", 0);
selSQL = "\"sfxzcf\"='" + "是" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_SF_XZCF", 1);
//是否申請法院強制執行 sfqzzx GLXX_SF_SQFYQZZX
//0 - 否
//1 - 是
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "GLXX_SF_SQFYQZZX");
selSQL = "\"sfqzzx\"='" + "否" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_SF_SQFYQZZX", 0);
selSQL = "\"sfqzzx\"='" + "是" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_SF_SQFYQZZX", 1);
//法院是否受理 fysfsl GLXX_SF_FYSL
//0 - 否
//1 - 是
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "GLXX_SF_FYSL");
selSQL = "\"fysfsl\"='" + "否" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_SF_FYSL", 0);
selSQL = "\"fysfsl\"='" + "是" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_SF_FYSL", 1);
#endregion
}
//
//產業類 公共服務類
//
if (strSelMB == "產業類" || strSelMB == "公共服務類")
{
#region
string selSQL = String.Empty;
//計算---直接等於
selSQL = null;
IFeatureLayer tempFeatLayer = culFeatLayer;
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "CITY_NAME");
CaculValue2(tempFeatLayer, selSQL, "CITY_NAME", "shi");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "XZQMC_XQ");
CaculValue2(tempFeatLayer, selSQL, "XZQMC_XQ", "xian");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "XZQMC_XZ");
CaculValue2(tempFeatLayer, selSQL, "XZQMC_XZ", "xiang");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "XZQMC_CUN");
CaculValue2(tempFeatLayer, selSQL, "XZQMC_CUN", "cun");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "XXDZ_Z");
CaculValue2(tempFeatLayer, selSQL, "XXDZ_Z", "zu");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "XXDZ_MPH");
CaculValue2(tempFeatLayer, selSQL, "XXDZ_MPH", "mph");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "JBXX_XMMC");
CaculValue2(tempFeatLayer, selSQL, "JBXX_XMMC", "xmmc");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "JBXX_JSZTMC");
CaculValue2(tempFeatLayer, selSQL, "JBXX_JSZTMC", "jsztmc");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "JBXX_KGSJ");
CaculValue2(tempFeatLayer, selSQL, "JBXX_KGSJ", "kgsj");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "glxx_zydmj");
CaculValue3(tempFeatLayer, selSQL, "glxx_zydmj", "fwzdmj");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "glxx_zygdmj");
CaculValue3(tempFeatLayer, selSQL, "glxx_zygdmj", "zygdmj");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "glxx_zyyjjbntmj");
CaculValue3(tempFeatLayer, selSQL, "glxx_zyyjjbntmj", "zyjbntmj");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "BZ");
CaculValue2(tempFeatLayer, selSQL, "BZ", "cjybz");
//房屋主要用途 fwzyyt JBXX_FWYT
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "JBXX_FWYT");
foreach (KeyValuePair<string, int> keyValuePair in ModelDataCls.listJBXX_FWYT)
{
selSQL = "\"fwzyyt\"='" + keyValuePair.Key + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_FWYT", keyValuePair.Value);
}
//建設主體性質 jsztxz JBXX_JSZTXZ
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "JBXX_JSZTXZ");
foreach (KeyValuePair<string, int> keyValuePair in ModelDataCls.listJBXX_JSZTXZ)
{
selSQL = "\"jsztxz\"='" + keyValuePair.Key + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_JSZTXZ", keyValuePair.Value);
}
//土地主要來源 tdzyly JBXX_TDZYLY
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "JBXX_TDZYLY");
foreach (KeyValuePair<string, int> keyValuePair in ModelDataCls.listJBXX_TDZYLY)
{
selSQL = "\"tdzyly\"='" + keyValuePair.Key + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_TDZYLY", keyValuePair.Value);
}
//是否扶貧專案 sffp JBXX_SF_FPXM
//0 - 否
//1 - 是
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "JBXX_SF_FPXM");
selSQL = "\"sffp\"='" + "否" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_SF_FPXM", 0);
selSQL = "\"sffp\"='" + "是" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_SF_FPXM", 1);
//是否上級部門有明確要求 sfsjmqyq JBXX_SF_SJBMYQ
//0 - 否
//1 - 是
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "JBXX_SF_SJBMYQ");
selSQL = "\"sfsjmqyq\"='" + "否" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_SF_SJBMYQ", 0);
selSQL = "\"sfsjmqyq\"='" + "是" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_SF_SJBMYQ", 1);
//
//JBXX_BMMC
//
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "JBXX_BMMC");
foreach (KeyValuePair<string, int> keyValuePair in ModelDataCls.listBMMCY)
{
selSQL = "\"bmmc\"='" + keyValuePair.Key + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_BMMC", keyValuePair.Value);
}
//與本村農產品生產、加工銷售等是否直接相關--- 產業類特有 ybcncp JBXX_SFZJXG_NCP
//0 - 否
//1 - 是
if (strSelMB == "產業類")
{
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "JBXX_SFZJXG_NCP");
selSQL = "\"ybcncp\"='" + "否" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_SFZJXG_NCP", 0);
selSQL = "\"ybcncp\"='" + "是" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_SFZJXG_NCP", 1);
}
//利用情況 lyqk JBXX_LYQK--------公共服務類特有
//1:閒置
//2:很少使用
//3:經常使用
if (strSelMB == "公共服務類")
{
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "JBXX_LYQK");
selSQL = "\"lyqk\"='" + "閒置" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_LYQK", 1);
selSQL = "\"lyqk\"='" + "很少使用" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_LYQK", 2);
selSQL = "\"lyqk\"='" + "經常使用" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "JBXX_LYQK", 3);
}
//----------------------------管理資訊--------------------------------------------------
//佔用耕地主要型別 zygdzylx GLXX_ZYGDLX
//zygdzylx01
//zygdzylx02
//zygdzylx03
//zygdzylx04
//zygdzylx05
//zygdzylx06
//zygdzylx07
//zygdzylx08
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "GLXX_ZYGDLX");
foreach (KeyValuePair<string, int> keyValuePair in ModelDataCls.listGLXX_ZYGDLX)
{
selSQL = "\"zygdzylx\"='" + keyValuePair.Key + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_ZYGDLX", keyValuePair.Value);
}
//是否符合城鄉(村莊)規劃 sffhcxgh GLXX_SFFH_CXGH
//1:未編制規劃
//2:符合
//3:部分符合
//4:不符合
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "GLXX_SFFH_CXGH");
foreach (KeyValuePair<string, int> keyValuePair in ModelDataCls.listSFFH_CXGH)
{
selSQL = "\"sffhcxgh\"='" + keyValuePair.Key + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_SFFH_CXGH", keyValuePair.Value);
}
//是否符合土地利用總體規劃(國土空間規劃)情況 sffhtdly GLXX_SFFH_TDLYGH
//0 - 符合
//1 - 部分符合
//2 - 不符合
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "GLXX_SFFH_TDLYGH");
selSQL = "\"sffhtdly\"='" + "符合" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_SFFH_TDLYGH", 0);
selSQL = "\"sffhtdly\"='" + "部分符合" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_SFFH_TDLYGH", 1);
selSQL = "\"sffhtdly\"='" + "不符合" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_SFFH_TDLYGH", 2);
//用地手續情況 ydsxqk GLXX_YDSXQK
//1 - 無手續
//2 - 手續不全
//3 - 有手續但不合規
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "GLXX_YDSXQK");
selSQL = "\"ydsxqk\"='" + "無手續" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_YDSXQK", 1);
selSQL = "\"ydsxqk\"='" + "手續不全" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_YDSXQK", 2);
selSQL = "\"ydsxqk\"='" + "有手續但不合規" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_YDSXQK", 3);
//沒有合法合規用地手續主要原因 wydspyy GLXX_MYSXYY
//1:未申請辦理用地手續
//2:停批
//3:不符合申請條件
//4:不符合規劃
//5:無用地計劃指標
//6:未繳費
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "GLXX_MYSXYY");
foreach (KeyValuePair<string, int> keyValuePair in ModelDataCls.listMYSXYY)
{
selSQL = "\"wydspyy\"='" + keyValuePair.Key + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_MYSXYY", keyValuePair.Value);
}
//是否作出行政處罰 sfxzcf GLXX_SF_XZCF
//0 - 否
//1 - 是
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "GLXX_SF_XZCF");
selSQL = "\"sfxzcf\"='" + "否" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_SF_XZCF", 0);
selSQL = "\"sfxzcf\"='" + "是" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_SF_XZCF", 1);
//是否申請法院強制執行 sfqzzx GLXX_SF_SQFYQZZX
//0 - 否
//1 - 是
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "GLXX_SF_SQFYQZZX");
selSQL = "\"sfqzzx\"='" + "否" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_SF_SQFYQZZX", 0);
selSQL = "\"sfqzzx\"='" + "是" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_SF_SQFYQZZX", 1);
//法院是否受理 fysfsl GLXX_SF_FYSL
//0 - 否
//1 - 是
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "GLXX_SF_FYSL");
selSQL = "\"fysfsl\"='" + "否" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_SF_FYSL", 0);
selSQL = "\"fysfsl\"='" + "是" + "'";
//tempFeatLayer = SelectFeatureLyByAttribute(culFeatLayer, selSQL);
CaculValue(tempFeatLayer, selSQL, "GLXX_SF_FYSL", 1);
#endregion
}
splashScreenManager1.SetWaitFormCaption("正在計算 " + strSelMB + " 根據名稱計算程式碼");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "city"); //city_name
CaculValueGetCodeByNameShi(culFeatLayer, null, "city_name", "city");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "xzqdm_xq");
CaculValueGetCodeByNameQuXian(culFeatLayer, null, "xzqmc_xq", "xzqdm_xq");
//計算鄉鎮程式碼
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "xzqdm_xz");
CaculValueGetCodeByNameXiang(culFeatLayer, null, "xzqmc_xz", "xzqdm_xz");
splashScreenManager1.SetWaitFormCaption("正在計算" + strSelMB);
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "province_name"); //city_name
CaculValue(culFeatLayer, null, "province_name", "貴州省");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "province"); //city_name
CaculValue(culFeatLayer, null, "province", "520000");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "collect_type"); //collect_type
//計算collect_type
string strFeatureLys = culFeatLayer.FeatureClass.AliasName;
if (strFeatureLys.Contains("住宅類"))
{
CaculValue(culFeatLayer, null, "collect_type", "Z");
}else if (strFeatureLys.Contains("產業類"))
{
CaculValue(culFeatLayer, null, "collect_type", "C");
}else if (strFeatureLys.Contains("公共服務類"))
{
CaculValue(culFeatLayer, null, "collect_type", "G");
}
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "id"); //collect_type
CaculValue2(culFeatLayer, null, "id", "fwbh");
DateTime dtEnd = DateTime.Now;
TimeSpan dtDiff = dateDiff(dtStart, dtEnd);
tlSProgressBar.Value = 0;
splashScreenManager1.CloseWaitForm();
MessageBox.Show("計算完成! 耗時("+ dtDiff + ")", "提示資訊", MessageBoxButtons.OK, MessageBoxIcon.Information);
//MessageBox.Show("檢查完成! 檢查結果存放在向量資料的CheckResult欄位裡", "提示資訊", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
/// <summary>
/// 屬性資料預覽
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ts_BTNAttribute_Click(object sender, EventArgs e)
{
if (culFeatLayer == null)
{
MessageBox.Show("請先開啟或選擇資料!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
//FormAttribute formAttribute = new FormAttribute(culFeatLayer);
splashScreenManager1.ShowWaitForm();
splashScreenManager1.SetWaitFormCaption("正在執行 開啟屬性表");
splashScreenManager1.SetWaitFormDescription("請耐心等待...資料載入中");
FormAttribute formAttribute = FormAttribute.getFormFunc(culFeatLayer);
splashScreenManager1.CloseWaitForm();
formAttribute.Text = "違法佔耕輔助處理軟體-" +culFeatLayer.FeatureClass.AliasName+"-屬性預覽";
formAttribute.Show();
}
/// <summary>
/// 獲取時間差
/// </summary>
/// <param name="dtStart"></param>
/// <param name="dtEnd"></param>
/// <returns></returns>
private TimeSpan dateDiff(DateTime dtStart,DateTime dtEnd)
{
TimeSpan tsStart = new TimeSpan(dtStart.Ticks);
TimeSpan tsEnd = new TimeSpan(dtEnd.Ticks);
TimeSpan ts = tsEnd.Subtract(tsStart).Duration();
//int dateDiffSecond = ts.Days * 24 * 60 * 60 + ts.Hours * 60 * 60 + ts.Minutes * 60 + ts.Seconds;
return ts;
}
/// <summary>
/// 根據屬性選擇要素
/// </summary>
/// <param name="culFeatLayer"></param>
/// <param name="selSQL"></param>
/// <returns></returns>
private IFeatureLayer SelectFeatureLyByAttribute(IFeatureLayer culFeatLayer, string selSQL)
{
// ISSUE: variable of a compiler-generated type
IFeatureSelection featureSelection = culFeatLayer as IFeatureSelection;
// ISSUE: variable of a compiler-generated type
IQueryFilter Filter = (IQueryFilter)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("FDFEBD95-ED75-11D0-9A95-080009EC734B")));
Filter.WhereClause = selSQL;
// ISSUE: reference to a compiler-generated method
featureSelection.SelectFeatures(Filter, esriSelectionResultEnum.esriSelectionResultNew, false);
// ISSUE: variable of a compiler-generated type
IFeatureLayer featureLayer = culFeatLayer;
return featureLayer;
}
/// <summary>
/// 屬性計算--賦值int
/// </summary>
/// <param name="culFeatLayer"></param>
/// <param name="FieldName"></param>
/// <param name="value"></param>
private void CaculValue(IFeatureLayer culFeatLayer, string strSQL, string FieldName, int myvalue)
{
IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = strSQL;
pQueryFilter.SubFields = FieldName;
int field = culFeatLayer.FeatureClass.FindField(FieldName);
ITable table = culFeatLayer.FeatureClass as ITable;
IRowBuffer pBuffer = table.CreateRowBuffer();
pBuffer.Value[field] = myvalue;
table.UpdateSearchedRows(pQueryFilter, pBuffer);
Marshal.ReleaseComObject(pQueryFilter);
}
private void CaculValueGetCodeByNameXiang(IFeatureLayer culFeatLayer, string strSQL, string strNameField,string strCodeField)
{
ITable table = culFeatLayer.FeatureClass as ITable;
IQueryFilter pQueryFilter = (IQueryFilter)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("FDFEBD95-ED75-11D0-9A95-080009EC734B")));
//IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = strSQL;
// pQueryFilter.SubFields = caculFieldName;
ICursor cursor = table.Update(pQueryFilter, false);
ESRI.ArcGIS.Geodatabase.IRow Row = cursor.NextRow();
if (Row == null)
return;
int field = Row.Fields.FindField(strNameField);
int field2 = Row.Fields.FindField(strCodeField);
int fieldXQ= Row.Fields.FindField("xzqmc_xq");
int maxCount = table.RowCount(pQueryFilter);
tlSProgressBar.Minimum = 0;
tlSProgressBar.Maximum = maxCount;
string Connstr = SQliteHelperCls.CustomerConnStr(SQliteHelperCls.strDBPath);
for (int i = 0; i < maxCount; i++)
{
// Row.set_Value(field, Row.get_Value(field2));
//object a1 = Row.Value[field];
//object a2 = Row.Value[field2];
tlSProgressBar.Value = i;
try
{
string calValue = Row.Value[field].ToString();
string culXQName = Row.Value[fieldXQ].ToString();
string strdbSQL = "select 鄉鎮程式碼 from 鄉鎮程式碼名稱 where 鄉鎮名稱='"+ calValue + "' and 縣區名稱='"+ culXQName + "'";
object tempcode= SQliteHelperCls.ExecuteScalar(strdbSQL, Connstr);
Row.Value[field2] = tempcode.ToString();
cursor.UpdateRow(Row);
Console.WriteLine(i);
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
Row = cursor.NextRow();
}
Marshal.ReleaseComObject(pQueryFilter);
tlSProgressBar.Value =0;
}
private void CaculValueGetCodeByNameQuXian(IFeatureLayer culFeatLayer, string strSQL, string strNameField, string strCodeField)
{
ITable table = culFeatLayer.FeatureClass as ITable;
IQueryFilter pQueryFilter = (IQueryFilter)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("FDFEBD95-ED75-11D0-9A95-080009EC734B")));
//IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = strSQL;
// pQueryFilter.SubFields = caculFieldName;
ICursor cursor = table.Update(pQueryFilter, false);
ESRI.ArcGIS.Geodatabase.IRow Row = cursor.NextRow();
if (Row == null)
return;
int field = Row.Fields.FindField(strNameField);
int field2 = Row.Fields.FindField(strCodeField);
int maxCount = table.RowCount(pQueryFilter);
tlSProgressBar.Minimum = 0;
tlSProgressBar.Maximum = maxCount;
string Connstr = SQliteHelperCls.CustomerConnStr(SQliteHelperCls.strDBPath);
for (int i = 0; i < maxCount; i++)
{
// Row.set_Value(field, Row.get_Value(field2));
//object a1 = Row.Value[field];
//object a2 = Row.Value[field2];
tlSProgressBar.Value = i;
try
{
string calValue = Row.Value[field].ToString();
string strdbSQL = "select 縣區程式碼 from 縣區程式碼名稱 where 縣區名稱='"+ calValue+"'";
object tempcode = SQliteHelperCls.ExecuteScalar(strdbSQL, Connstr);
Row.Value[field2] = tempcode.ToString();
cursor.UpdateRow(Row);
Console.WriteLine(i);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Row = cursor.NextRow();
}
Marshal.ReleaseComObject(pQueryFilter);
}
private void CaculValueGetCodeByNameShi(IFeatureLayer culFeatLayer, string strSQL, string strNameField, string strCodeField)
{
ITable table = culFeatLayer.FeatureClass as ITable;
IQueryFilter pQueryFilter = (IQueryFilter)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("FDFEBD95-ED75-11D0-9A95-080009EC734B")));
//IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = strSQL;
// pQueryFilter.SubFields = caculFieldName;
ICursor cursor = table.Update(pQueryFilter, false);
ESRI.ArcGIS.Geodatabase.IRow Row = cursor.NextRow();
if (Row == null)
return;
int field = Row.Fields.FindField(strNameField);
int field2 = Row.Fields.FindField(strCodeField);
int maxCount = table.RowCount(pQueryFilter);
tlSProgressBar.Minimum = 0;
tlSProgressBar.Maximum = maxCount;
string Connstr = SQliteHelperCls.CustomerConnStr(SQliteHelperCls.strDBPath);
for (int i = 0; i < maxCount; i++)
{
// Row.set_Value(field, Row.get_Value(field2));
//object a1 = Row.Value[field];
//object a2 = Row.Value[field2];
tlSProgressBar.Value = i;
try
{
string calValue = Row.Value[field].ToString();
string strdbSQL = "select 市州程式碼 from 市州程式碼名稱 where 市州名稱= '"+ calValue+"'";
object tempcode = SQliteHelperCls.ExecuteScalar(strdbSQL, Connstr);
Row.Value[field2] = tempcode.ToString()+"00";
cursor.UpdateRow(Row);
Console.WriteLine(i);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Row = cursor.NextRow();
}
Marshal.ReleaseComObject(pQueryFilter);
}
/// <summary>
/// 屬性計算--賦值object
/// </summary>
/// <param name="culFeatLayer"></param>
/// <param name="FieldName"></param>
/// <param name="value"></param>
private void CaculValue(IFeatureLayer culFeatLayer, string strSQL, string FieldName, object myvalue)
{
IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = strSQL;
pQueryFilter.SubFields = FieldName;
int field = culFeatLayer.FeatureClass.FindField(FieldName);
ITable table = culFeatLayer.FeatureClass as ITable;
IRowBuffer pBuffer = table.CreateRowBuffer();
pBuffer.Value[field] = myvalue;
table.UpdateSearchedRows(pQueryFilter, pBuffer);
Marshal.ReleaseComObject(pQueryFilter);
}
/// <summary>
/// 屬性計算----直接等於 String
/// </summary>
/// <param name="culFeatLayer"></param>
/// <param name="strSQL"></param>
/// <param name="caculFieldName"></param>
/// <param name="strFieldName"></param>
private void CaculValue2(IFeatureLayer culFeatLayer,string strSQL, string caculFieldName, string strFieldName)
{
ITable table = culFeatLayer.FeatureClass as ITable;
IQueryFilter pQueryFilter = (IQueryFilter)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("FDFEBD95-ED75-11D0-9A95-080009EC734B")));
//IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = strSQL;
// pQueryFilter.SubFields = caculFieldName;
ICursor cursor = table.Update(pQueryFilter, false);
ESRI.ArcGIS.Geodatabase.IRow Row = cursor.NextRow();
if (Row == null)
return;
int field = Row.Fields.FindField(caculFieldName);
int field2 = Row.Fields.FindField(strFieldName);
int maxCount = table.RowCount(pQueryFilter);
tlSProgressBar.Minimum = 0;
tlSProgressBar.Maximum = maxCount;
for (int i = 0; i < maxCount; i++)
{
// Row.set_Value(field, Row.get_Value(field2));
//object a1 = Row.Value[field];
//object a2 = Row.Value[field2];
tlSProgressBar.Value = i;
try
{
dynamic calValue = Row.Value[field2];
Row.Value[field] = calValue;
cursor.UpdateRow(Row);
Console.WriteLine(i);
}
catch { }
Row = cursor.NextRow();
}
Marshal.ReleaseComObject(pQueryFilter);
}
/// <summary>
/// 屬性計算----直接等於 double
/// </summary>
/// <param name="culFeatLayer"></param>
/// <param name="caculFieldName"></param>
/// <param name="strFieldName"></param>
private void CaculValue3(IFeatureLayer culFeatLayer, string strSQL, string caculFieldName, string strFieldName)
{
ITable table = culFeatLayer.FeatureClass as ITable;
IQueryFilter pQueryFilter = (IQueryFilter)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("FDFEBD95-ED75-11D0-9A95-080009EC734B")));
//IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = strSQL;
// QueryFilter.SubFields = caculFieldName;
ICursor cursor = table.Update(pQueryFilter, false);
ESRI.ArcGIS.Geodatabase.IRow Row = cursor.NextRow();
if (Row == null)
return;
tlSProgressBar.Minimum = 0;
tlSProgressBar.Maximum = table.RowCount(pQueryFilter);
int field = Row.Fields.FindField(caculFieldName);
int field2 = Row.Fields.FindField(strFieldName);
for (int i = 0; i < table.RowCount(pQueryFilter); i++)
{
tlSProgressBar.Value = i;
try
{
// Row.set_Value(field, Row.get_Value(field2));
Row.Value[field] = Row.Value[field2];
cursor.UpdateRow(Row);
Row = cursor.NextRow();
}
catch{}
}
Marshal.ReleaseComObject(pQueryFilter);
}
/// <summary>
/// 屬性計算----住宅類面積相加
/// </summary>
/// <param name="culFeatLayer"></param>
/// <param name="caculFieldName"></param>
/// <param name="strFieldName"></param>
private void CaculValue4(IFeatureLayer culFeatLayer, string caculFieldName, string strFWMJ,string strFSSSMJ)
{
ITable table = culFeatLayer.FeatureClass as ITable;
IQueryFilter pQueryFilter = (IQueryFilter)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("FDFEBD95-ED75-11D0-9A95-080009EC734B")));
//IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = null;
// QueryFilter.SubFields = caculFieldName;
ICursor cursor = table.Update(pQueryFilter, false);
ESRI.ArcGIS.Geodatabase.IRow Row = cursor.NextRow();
if (Row == null)
return;
int field = Row.Fields.FindField(caculFieldName);
int field2 = Row.Fields.FindField(strFWMJ);
int field3 = Row.Fields.FindField(strFSSSMJ);
tlSProgressBar.Minimum = 0;
tlSProgressBar.Maximum = table.RowCount(pQueryFilter);
for (int i = 0; i < table.RowCount(pQueryFilter); i++)
{
tlSProgressBar.Value = i;
try
{
// Row.set_Value(field, Row.get_Value(field2));
double fwmj=(double) Row.Value[field2];
double fsssmj= (double)Row.Value[field3];
Row.Value[field] = fwmj+ fsssmj;
cursor.UpdateRow(Row);
Row = cursor.NextRow();
}
catch { }
}
Marshal.ReleaseComObject(pQueryFilter);
}
private IFeatureCursor GetSelectedFeature(IFeatureLayer featureLayer)
{
try
{
if (featureLayer == null)
{
// ISSUE: variable of a compiler-generated type
IFeatureCursor featureCursor = (IFeatureCursor)null;
return featureCursor;
}
// ISSUE: variable of a compiler-generated type
IFeatureSelection featureSelection = (IFeatureSelection)featureLayer;
// ISSUE: variable of a compiler-generated type
ISelectionSet selectionSet = featureSelection.SelectionSet;
if (selectionSet.Count == 0)
{
// ISSUE: variable of a compiler-generated type
IFeatureCursor featureCursor = (IFeatureCursor)null;
return featureCursor;
}
// ISSUE: variable of a compiler-generated type
ICursor Cursor;
// ISSUE: reference to a compiler-generated method
selectionSet.Search((IQueryFilter)null, false, out Cursor);
// ISSUE: variable of a compiler-generated type
IFeatureCursor featureCursor1 = (IFeatureCursor)Cursor;
return featureCursor1;
}
catch (Exception ex)
{
int num = (int)MessageBox.Show("選擇要素失敗!", "警告");
// ISSUE: variable of a compiler-generated type
IFeatureCursor featureCursor = (IFeatureCursor)null;
return featureCursor;
}
}
/// <summary>
/// 轉換前檢查的GDB
/// </summary>
private string strZHQSelGDBPath = null;
/// <summary>
/// 轉換前檢查-載入資料
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_unck_OpenData_Click(object sender, EventArgs e)
{
listBox_unck_FtLy.Items.Clear();
tspCombx_unck_SFZ.Items.Clear();
tspCombx_unck_SFZ.SelectedItem = null;
MyFolderBrowserDialog mfbd = new MyFolderBrowserDialog();
if (mfbd.ShowDialog(this) == DialogResult.OK)
{
listFLayerZHQ_Check = new List<IFeatureLayer>();
string strGDB_Path = mfbd.DirectoryPath;
strZHQSelGDBPath = mfbd.DirectoryPath;
FileGDBWorkspaceFactory fac = new FileGDBWorkspaceFactory();
IFeatureWorkspace pFtWS = (IFeatureWorkspace)fac.OpenFromFile(strGDB_Path, 0);
IWorkspace pWork = (IWorkspace)pFtWS;
IEnumDataset pEnumDs = pWork.get_Datasets(esriDatasetType.esriDTFeatureClass);
IDataset pDs = pEnumDs.Next();
axMapControl1.Map.ClearLayers();
tslbStatus.Text = "正在載入要素...";
statusStrip1.Refresh();
while (pDs != null)
{
IFeatureClass temp = pDs as IFeatureClass;
IFeatureLayer tempLayer = new FeatureLayer();
tempLayer.FeatureClass = temp;
tempLayer.Name = tempLayer.FeatureClass.AliasName;
listFLayerZHQ_Check.Add(tempLayer);
listBox_unck_FtLy.Items.Add(tempLayer.FeatureClass.AliasName);
tspCombx_unck_SFZ.Items.Add(tempLayer.FeatureClass.AliasName);
pDs = pEnumDs.Next();
}
tslbStatus.Text = "載入完成!";
tlSpStLb.Text = " 選項:轉換前屬性質量檢查 當前資料庫:" + strGDB_Path;
//tlSpStLb.Text += " 當前資料庫:" + Path.GetFileName(strGDB_Path);
statusStrip1.Refresh();
}
}
/// <summary>
/// 檢查鄉鎮名稱是否存在
/// </summary>
/// <param name="tempFtLy"></param>
/// <param name="strSQL"></param>
/// <param name="strSaveField"></param>
private void CheckUnStandardXiang(IFeatureLayer tempFtLy,string strSQL, string strSaveField)
{
ITable table = tempFtLy.FeatureClass as ITable;
IQueryFilter pQueryFilter = (IQueryFilter)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("FDFEBD95-ED75-11D0-9A95-080009EC734B")));
//IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = strSQL;
// pQueryFilter.SubFields = caculFieldName;
ICursor cursor = table.Update(pQueryFilter, false);
ESRI.ArcGIS.Geodatabase.IRow Row = cursor.NextRow();
if (Row == null)
return;
int fieldXZ = Row.Fields.FindField("xiang");//鄉鎮名稱欄位
int fieldXQ = Row.Fields.FindField("xian");//縣區名稱欄位
int fieldSave = Row.Fields.FindField(strSaveField);//儲存欄位
int maxCount = table.RowCount(pQueryFilter);
tlSProgressBar.Minimum = 0;
tlSProgressBar.Maximum = maxCount;
string Connstr = SQliteHelperCls.CustomerConnStr(SQliteHelperCls.strDBPath);
//string strSQL = "Select 鄉鎮名稱 from 鄉鎮程式碼名稱 where 縣區名稱='息烽縣'";
for (int i = 0; i < maxCount; i++)
{
tlSProgressBar.Value = i;
string strXZName = Row.Value[fieldXZ].ToString();
bool isChinaCode= CheckIsChineseCode.isLegalChinaCode(strXZName);
if(!isChinaCode)
{
Row.Value[fieldSave] = Row.Value[fieldSave].ToString()+";"+"非標準鄉鎮名;";
cursor.UpdateRow(Row);
}
else
{
string strSQLiteSQL = "Select 鄉鎮名稱 from 鄉鎮程式碼名稱 where 縣區名稱='" + Row.Value[fieldXQ].ToString() + "' and 鄉鎮名稱='" + Row.Value[fieldXZ].ToString() + "'";
using (SQLiteConnection SqlConn = new SQLiteConnection(Connstr))
{
using (SQLiteCommand SqlCmd = new SQLiteCommand(strSQLiteSQL, SqlConn))
{
SqlConn.Open();
SQLiteDataReader reader = SqlCmd.ExecuteReader(CommandBehavior.CloseConnection);
if (reader.HasRows==false)
{
Row.Value[fieldSave] = Row.Value[fieldSave].ToString() + ";" + "非標準鄉鎮名;";
cursor.UpdateRow(Row);
}
}
}
}
Row = cursor.NextRow();
}
}
//執行檢查 eg名稱(單戶住宅類、多戶住宅類、產業類、公共服務類)
/// <summary>
/// 轉換前檢查--執行檢查
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_unck_Excute_Click(object sender, EventArgs e)
{
unck_ExcuteFunc(null, false);
}
/// <summary>
/// 轉換前檢查
/// </summary>
/// <param name="culContextFtLy"></param>
/// <param name="isSingelCheck"></param>
private void unck_ExcuteFunc(IFeatureLayer culContextFtLy,bool isSingelCheck)
{
if (listFLayerZHQ_Check == null)
{
MessageBox.Show("沒有資料可查!請先開啟資料", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
DateTime dtStart = DateTime.Now;
splashScreenManager1.ShowWaitForm();
splashScreenManager1.SetWaitFormCaption("執行檢查");
splashScreenManager1.SetWaitFormDescription("請耐心等待...");
for (int i = 0; i < listFLayerZHQ_Check.Count; i++)
{
string strTxtPathes = String.Empty;
string selSQL = String.Empty;
//string strTxtPathes = Directory.GetCurrentDirectory() + "\\檢查項\\轉換前檢查";
IFeatureLayer pFeatureLayer = listFLayerZHQ_Check[i];
string strFyLyName = pFeatureLayer.FeatureClass.AliasName;//要素類名稱
if (isSingelCheck == true)
{
if (culContextFtLy.FeatureClass.AliasName != strFyLyName)
{
continue;
}
}
listBox_unck_FtLy.SelectedValue = strFyLyName;
listBox_unck_FtLy.Refresh();
if (strFyLyName != "單戶住宅類" && strFyLyName != "多戶住宅類" && strFyLyName != "產業類" && strFyLyName != "公共服務類")
{
continue;
}
splashScreenManager1.SetWaitFormDescription("請耐心等待... " + strFyLyName + " 初始化檢查");
initValue(pFeatureLayer);
string strSetTxtPath = "";//儲存檢查項的TXT路徑
if (strFyLyName == "單戶住宅類")
{
strTxtPathes = Directory.GetCurrentDirectory() + "\\檢查項\\轉換前檢查\\單戶住宅類";
strSetTxtPath = System.IO.Directory.GetCurrentDirectory() + "\\checksettings\\danhzzlSet.txt";
if (Convert.ToBoolean(XmlCls.ReadXml(XmlCls.strSettingsInfoXML, "SetCheck_grxm")))
{
splashScreenManager1.SetWaitFormDescription("檢查 單戶住宅類 是否含非法字元" + "之個人姓名");
CkeckDataFunc(pFeatureLayer, null, "grxm", "grxm含非法字元");
}
if (Convert.ToBoolean(XmlCls.ReadXml(XmlCls.strSettingsInfoXML, "SetCheck_cs")))
{
splashScreenManager1.SetWaitFormDescription("檢查 單戶住宅類 cs異常值檢查");
selSQL = "cs<>'0' and cs<>'' and cs is not null";
CheckCSFunc(pFeatureLayer, selSQL);
}
}
else if (strFyLyName == "多戶住宅類")
{
strSetTxtPath = System.IO.Directory.GetCurrentDirectory() + "\\checksettings\\duohzzlSet.txt";
strTxtPathes = Directory.GetCurrentDirectory() + "\\檢查項\\轉換前檢查\\多戶住宅類";
}
else if (strFyLyName == "產業類")
{
strSetTxtPath = System.IO.Directory.GetCurrentDirectory() + "\\checksettings\\cylSet.txt";
strTxtPathes = Directory.GetCurrentDirectory() + "\\檢查項\\轉換前檢查\\產業類";
}
else if (strFyLyName == "公共服務類")
{
strSetTxtPath = System.IO.Directory.GetCurrentDirectory() + "\\checksettings\\ggfwlSet.txt";
strTxtPathes = Directory.GetCurrentDirectory() + "\\檢查項\\轉換前檢查\\公共服務類";
}
if (Convert.ToBoolean(XmlCls.ReadXml(XmlCls.strSettingsInfoXML, "SetCheck_xian")))
{
splashScreenManager1.SetWaitFormDescription("檢查 " + strFyLyName + " 是否含非法字元之xian");
CkeckDataFunc(pFeatureLayer, null, "xian", "xian含非法字元");
}
if (Convert.ToBoolean(XmlCls.ReadXml(XmlCls.strSettingsInfoXML, "SetCheck_xiang")))
{
splashScreenManager1.SetWaitFormDescription("檢查 " + strFyLyName + " 是否含非法字元之xiang");
CkeckDataFunc(pFeatureLayer, null, "xiang", "xiang含非法字元");
}
if (Convert.ToBoolean(XmlCls.ReadXml(XmlCls.strSettingsInfoXML, "SetCheck_cun")))
{
splashScreenManager1.SetWaitFormDescription("檢查 " + strFyLyName + " 是否含非法字元之cun");
CkeckDataFunc(pFeatureLayer, null, "cun", "cun含非法字元");
}
//SetCheck_zu
if (Convert.ToBoolean(XmlCls.ReadXml(XmlCls.strSettingsInfoXML, "SetCheck_zu")))
{
splashScreenManager1.SetWaitFormDescription("檢查 " + strFyLyName + " 是否含非法字元之zu");
selSQL = "zu <>'' and zu is not null";
CkeckIllegalCharFunc(pFeatureLayer, selSQL, "zu", "zu含非法字元");
}
if (Convert.ToBoolean(XmlCls.ReadXml(XmlCls.strSettingsInfoXML, "SetCheck_xzName")))
{
splashScreenManager1.SetWaitFormDescription("檢查 " + strFyLyName + " 非標準鄉鎮名稱");
//檢查非標準鄉鎮名稱
CheckUnStandardXiang(pFeatureLayer, null, "CheckResult");
}
//
//檢查開工時間值域
//
if (Convert.ToBoolean(XmlCls.ReadXml(XmlCls.strSettingsInfoXML, "SetCheck_kgsjZY")))
{
splashScreenManager1.SetWaitFormDescription("檢查 " + strFyLyName + " 開工時間值域");
CheckKGSJFunc(pFeatureLayer, null);
}
listBoxCheckItems.Items.Clear();
this.Refresh();
string[] arrCheckPathes = Directory.GetFiles(strTxtPathes);
for (int j = 0; j < arrCheckPathes.Length; j++)
{
string strtxt = arrCheckPathes[j];
string strname = System.IO.Path.GetFileNameWithoutExtension(strtxt);
listBoxCheckItems.Items.Add(strname);
}
using (StreamReader sr = new StreamReader(strSetTxtPath, Encoding.UTF8))
{
while (!sr.EndOfStream)
{
string str = sr.ReadLine();
if (listBoxCheckItems.Items.Contains(str) == true)
{
int intIndex = listBoxCheckItems.Items.IndexOf(str);
//listBoxCheckItems.SetSelected(intIndex, true);
//listBoxCheckItems.
listBoxCheckItems.SetItemCheckState(intIndex, CheckState.Checked);
}
}
}
listBoxCheckItems.Refresh();
this.Refresh();
for (int j = 0; j < arrCheckPathes.Length; j++)
{
string strtxt = arrCheckPathes[j];
string strName = System.IO.Path.GetFileNameWithoutExtension(strtxt);
if (listBoxCheckItems.CheckedItems.Contains(strName) == false)
{
continue;
}
listBoxCheckItems.SelectedItem = strName;
splashScreenManager1.SetWaitFormDescription("正在檢查... " + strFyLyName + " " + System.IO.Path.GetFileNameWithoutExtension(strtxt) + " " + (j + 1) + "/" + arrCheckPathes.Length);
using (StreamReader sr = new StreamReader(strtxt, Encoding.Default))
{
selSQL = sr.ReadToEnd();
}
try
{
string selSQLBJ = selSQL.Split('&')[0];//錯誤型別
selSQL = selSQL.Split('&')[1];//錯誤程式碼
CkeckDataOverCalcuFunc(pFeatureLayer, selSQL, selSQLBJ);
}
catch (Exception ex)
{
Console.WriteLine("出錯" + ex.ToString());
MessageBox.Show("出錯 " + ex.ToString());
}
}
listBoxCheckItems.Items.Clear();
this.Refresh();
}
DateTime dtEnd = DateTime.Now;
TimeSpan dtDiff = dateDiff(dtStart, dtEnd);
tlSProgressBar.Value = 0;
splashScreenManager1.CloseWaitForm();
using (SpeechSynthesizer speech = new SpeechSynthesizer())
{
speech.Rate = 0; //語速
speech.Volume = 100; //音量
speech.Speak("檢查完成");
}
MessageBox.Show("檢查完成!耗時(" + dtDiff + ")\r\n" + " 檢查結果存放在向量資料的CheckResult欄位裡", "提示資訊", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
/// <summary>
/// 檢查面積值域滿足的條件
/// </summary>
/// <param name="culFeatLayer"></param>
/// <param name="strSQL"></param>
/// <param name="strDescription"></param>
private void CheckMJValue(IFeatureLayer culFeatLayer, string strSQL, string strDescription)
{
ITable table = culFeatLayer.FeatureClass as ITable;
IQueryFilter pQueryFilter = (IQueryFilter)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("FDFEBD95-ED75-11D0-9A95-080009EC734B")));
//IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = strSQL;
ICursor cursor = table.Update(pQueryFilter, false);
ESRI.ArcGIS.Geodatabase.IRow Row = cursor.NextRow();
if (Row == null)
return;
//int field = Row.Fields.FindField(caculFieldName);
// int field2 = Row.Fields.FindField(strFieldName);
int fieldCheckResult = Row.Fields.FindField("CheckResult");
int maxCount = table.RowCount(pQueryFilter);
tlSProgressBar.Minimum = 0;
tlSProgressBar.Maximum = maxCount;
for (int i = 0; i < maxCount; i++)
{
tlSProgressBar.Value = i;
string strCheckResult = (string)Row.Value[fieldCheckResult];
Row.Value[fieldCheckResult] = strCheckResult + strDescription + ";";
cursor.UpdateRow(Row);
Row = cursor.NextRow();
}
}
/// <summary>
/// 非漢字--非法字元檢查
/// </summary>
/// <param name="culFeatLayer"></param>
/// <param name="strSQL"></param>
/// <param name="strFieldName"></param>
/// <param name="strDescription"></param>
private void CkeckDataFunc(IFeatureLayer culFeatLayer, string strSQL,string strFieldName,string strDescription)
{
ITable table = culFeatLayer.FeatureClass as ITable;
IQueryFilter pQueryFilter = (IQueryFilter)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("FDFEBD95-ED75-11D0-9A95-080009EC734B")));
//IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = strSQL;
// pQueryFilter.SubFields = caculFieldName;
ICursor cursor = table.Update(pQueryFilter, false);
ESRI.ArcGIS.Geodatabase.IRow Row = cursor.NextRow();
if (Row == null)
return;
//int field = Row.Fields.FindField(caculFieldName);
int field2 = Row.Fields.FindField(strFieldName);
int fieldCheckResult = Row.Fields.FindField("CheckResult");
int maxCount = table.RowCount(pQueryFilter);
tlSProgressBar.Minimum = 0;
tlSProgressBar.Maximum = maxCount;
for (int i = 0; i < maxCount; i++)
{
// Row.set_Value(field, Row.get_Value(field2));
//object a1 = Row.Value[field];
//object a2 = Row.Value[field2];
tlSProgressBar.Value = i;
try
{
dynamic calValue = Row.Value[field2];
bool isChineseCode= CheckIsChineseCode.isLegalChinaCode(calValue);
if (isChineseCode==false)
{
string strCheckResult= (string) Row.Value[fieldCheckResult];
Row.Value[fieldCheckResult] = strCheckResult + strDescription + ";";
cursor.UpdateRow(Row);
}
//cursor.UpdateRow(Row);
}
catch { }
Row = cursor.NextRow();
}
Marshal.ReleaseComObject(pQueryFilter);
}
/// <summary>
/// zu--非法字元檢查
/// </summary>
/// <param name="culFeatLayer"></param>
/// <param name="strSQL"></param>
/// <param name="strFieldName"></param>
/// <param name="strDescription"></param>
private void CkeckIllegalCharFunc(IFeatureLayer culFeatLayer, string strSQL, string strFieldName, string strDescription)
{
ITable table = culFeatLayer.FeatureClass as ITable;
IQueryFilter pQueryFilter = (IQueryFilter)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("FDFEBD95-ED75-11D0-9A95-080009EC734B")));
//IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = strSQL;
// pQueryFilter.SubFields = caculFieldName;
ICursor cursor = table.Update(pQueryFilter, false);
ESRI.ArcGIS.Geodatabase.IRow Row = cursor.NextRow();
if (Row == null)
return;
//int field = Row.Fields.FindField(caculFieldName);
int field2 = Row.Fields.FindField(strFieldName);
int fieldCheckResult = Row.Fields.FindField("CheckResult");
int maxCount = table.RowCount(pQueryFilter);
tlSProgressBar.Minimum = 0;
tlSProgressBar.Maximum = maxCount;
for (int i = 0; i < maxCount; i++)
{
// Row.set_Value(field, Row.get_Value(field2));
//object a1 = Row.Value[field];
//object a2 = Row.Value[field2];
tlSProgressBar.Value = i;
try
{
dynamic calValue = Row.Value[field2];
//bool isIllegalChar = IllegalCharCheckCls.IsIllegalChar2(calValue);
bool isIllegalChar = IllegalCharCheckCls.ChkBadChar(calValue);
if (isIllegalChar == true)
{
string strCheckResult = (string)Row.Value[fieldCheckResult];
Row.Value[fieldCheckResult] = strCheckResult + strDescription + ";";
cursor.UpdateRow(Row);
}
//cursor.UpdateRow(Row);
}
catch { }
Row = cursor.NextRow();
}
Marshal.ReleaseComObject(pQueryFilter);
}
private void initValue(IFeatureLayer temp)
{
try
{
AddStringField(temp.FeatureClass, "CheckResult");
}
catch
{
Console.WriteLine("新增欄位失敗");
}
CaculValue(temp, null, "CheckResult", ";");
}
/// <summary>
/// 新增字串欄位
/// </summary>
/// <param name="culFeatCls"></param>
/// <param name="strFieldName"></param>
private void AddStringField(IFeatureClass culFeatCls, string strFieldName)
{
IClass pClass = culFeatCls as IClass;
IFieldsEdit fldsE = culFeatCls.Fields as IFieldsEdit;
IField fld = new Field();
IFieldEdit2 fldE = fld as IFieldEdit2;
fldE.Type_2 = esriFieldType.esriFieldTypeString;
fldE.Length_2 = 500;
fldE.Name_2 = strFieldName;
pClass.AddField(fld);
}
/// <summary>
/// 根據名稱得到要素類
/// </summary>
/// <param name="listFLayerZHH_Check"></param>
/// <param name="strFtLayerName"></param>
/// <returns></returns>
private IFeatureLayer GetFeatureLayerByName(List<IFeatureLayer> listFLayerZHH_Check,string strFtLayerName)
{
if (listFLayerZHH_Check.Count<=0|| listFLayerZHH_Check == null)
{
MessageBox.Show("請先開啟資料");
return null;
}
IFeatureLayer temp = null;
for (int i = 0; i < listFLayerZHH_Check.Count; i++)
{
if (listFLayerZHH_Check[i].FeatureClass.AliasName== strFtLayerName)
{
temp = listFLayerZHH_Check[i];
break;
}
}
return temp;
}
//
//轉換後檢查
//
private void btn_iscked_OpenData_Click(object sender, EventArgs e)
{
listBox_iscked_FtLy.Items.Clear();
MyFolderBrowserDialog mfbd = new MyFolderBrowserDialog();
if (mfbd.ShowDialog(this) == DialogResult.OK)
{
listFLayerZHH_Check = new List<IFeatureLayer>();
string strGDB_Path = mfbd.DirectoryPath;
FileGDBWorkspaceFactory fac = new FileGDBWorkspaceFactory();
IFeatureWorkspace pFtWS = (IFeatureWorkspace)fac.OpenFromFile(strGDB_Path, 0);
IWorkspace pWork = (IWorkspace)pFtWS;
IEnumDataset pEnumDs = pWork.get_Datasets(esriDatasetType.esriDTFeatureClass);
IDataset pDs = pEnumDs.Next();
tslbStatus.Text = "正在載入要素...";
statusStrip1.Refresh();
while (pDs != null)
{
IFeatureClass temp = pDs as IFeatureClass;
IFeatureLayer tempLayer = new FeatureLayer();
tempLayer.FeatureClass = temp;
tempLayer.Name = tempLayer.FeatureClass.AliasName;
listBox_iscked_FtLy.Items.Add(tempLayer.Name);
listFLayerZHH_Check.Add(tempLayer);
pDs = pEnumDs.Next();
}
tslbStatus.Text = "載入完成!";
tlSpStLb.Text = " 選項:轉換後屬性質量檢查 當前資料庫:" + strGDB_Path;
statusStrip1.Refresh();
}
}
private void btn_iscked_Excute_Click(object sender, EventArgs e)
{
if (listFLayerZHH_Check == null)
{
MessageBox.Show("沒有資料可查!請先開啟資料", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
splashScreenManager1.ShowWaitForm();
splashScreenManager1.SetWaitFormDescription("請耐心等待...");
for (int i = 0; i < ModelDataCls.FeatureLayerNameModel.Count; i++)
{
string selSQL = String.Empty;
string strName = ModelDataCls.FeatureLayerNameModel[i];
listBox_iscked_FtLy.SelectedValue = strName;
listBox_iscked_FtLy.Refresh();
splashScreenManager1.SetWaitFormCaption("準備檢查" + strName);
IFeatureLayer FtLayerZZL = GetFeatureLayerByName(listFLayerZHH_Check,strName);
if (FtLayerZZL==null)
{
continue;
}
initValue(FtLayerZZL);
string strCheckTXTPath = String.Empty;
splashScreenManager1.SetWaitFormCaption("檢查 " + strName);
if (FtLayerZZL.FeatureClass.AliasName=="住宅類")
{
strCheckTXTPath = Directory.GetCurrentDirectory() + "\\檢查項\\轉換後檢查\\住宅類";
}
if (FtLayerZZL.FeatureClass.AliasName == "產業類")
{
strCheckTXTPath = Directory.GetCurrentDirectory() + "\\檢查項\\轉換後檢查\\產業類";
}
if (FtLayerZZL.FeatureClass.AliasName == "公共服務類")
{
strCheckTXTPath = Directory.GetCurrentDirectory() + "\\檢查項\\轉換後檢查\\公共服務類";
}
string[] arrCheckPathes = Directory.GetFiles(strCheckTXTPath);
for (int j = 0; j < arrCheckPathes.Length; j++)
{
string strtxt = arrCheckPathes[j];
splashScreenManager1.SetWaitFormDescription("正在檢查... " + System.IO.Path.GetFileNameWithoutExtension(strtxt)+" "+(j+1)+"/"+ arrCheckPathes.Length);
using (StreamReader sr = new StreamReader(strtxt, Encoding.Default))
{
selSQL = sr.ReadToEnd();
}
try
{
string selSQLBJ = selSQL.Split('&')[0];//錯誤型別
selSQL = selSQL.Split('&')[1];//錯誤程式碼
CkeckDataOverCalcuFunc(FtLayerZZL, selSQL, selSQLBJ);
}
catch (Exception ex)
{
Console.WriteLine("出錯"+ selSQL);
MessageBox.Show("出錯 " + ex.ToString());
}
}
}
tlSProgressBar.Value = 0;
splashScreenManager1.CloseWaitForm();
MessageBox.Show("檢查完成! 檢查結果存放在向量資料的CheckResult欄位裡", "提示資訊", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void btn_ViewCheckes_Click(object sender, EventArgs e)
{
string strCheckTXTPath = Directory.GetCurrentDirectory() + "\\檢查項\\轉換後檢查";
Process.Start(strCheckTXTPath);
}
/// <summary>
/// 開工時間值域檢查
/// </summary>
/// <param name="culFeatLayer"></param>
/// <param name="strSQL"></param>
private void CheckKGSJFunc(IFeatureLayer culFeatLayer, string strSQL)
{
ITable table = culFeatLayer.FeatureClass as ITable;
IQueryFilter pQueryFilter = (IQueryFilter)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("FDFEBD95-ED75-11D0-9A95-080009EC734B")));
//IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = strSQL;
// pQueryFilter.SubFields = caculFieldName;
ICursor cursor = table.Update(pQueryFilter, false);
ESRI.ArcGIS.Geodatabase.IRow Row = cursor.NextRow();
if (Row == null)
return;
//int field = Row.Fields.FindField(caculFieldName);
// int field2 = Row.Fields.FindField(strFieldName);
int fieldCheckResult = Row.Fields.FindField("CheckResult");
int fieldkgsj = Row.Fields.FindField("kgsj");
int maxCount = table.RowCount(pQueryFilter);
tlSProgressBar.Minimum = 0;
tlSProgressBar.Maximum = maxCount;
for (int i = 0; i < maxCount; i++)
{
// Row.set_Value(field, Row.get_Value(field2));
//object a1 = Row.Value[field];
//object a2 = Row.Value[field2];
tlSProgressBar.Value = i;
try
{
int intkgsj = Convert.ToInt32(Row.Value[fieldkgsj]);
if (intkgsj < 2000 || intkgsj > 2020)
{
string strCheckResult = (string)Row.Value[fieldCheckResult];
Row.Value[fieldCheckResult] = strCheckResult + "kgsj不在值域;";
cursor.UpdateRow(Row);
}
}
catch
{}
Row = cursor.NextRow();
}
Marshal.ReleaseComObject(pQueryFilter);
}
/// <summary>
/// 檢查房屋層數異常
/// </summary>
/// <param name="culFeatLayer"></param>
/// <param name="strSQL"></param>
/// <param name="strDescription"></param>
private void CheckCSFunc(IFeatureLayer culFeatLayer, string strSQL)
{
ITable table = culFeatLayer.FeatureClass as ITable;
IQueryFilter pQueryFilter = (IQueryFilter)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("FDFEBD95-ED75-11D0-9A95-080009EC734B")));
//IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = strSQL;
// pQueryFilter.SubFields = caculFieldName;
ICursor cursor = table.Update(pQueryFilter, false);
ESRI.ArcGIS.Geodatabase.IRow Row = cursor.NextRow();
if (Row == null)
return;
//int field = Row.Fields.FindField(caculFieldName);
// int field2 = Row.Fields.FindField(strFieldName);
int fieldCheckResult = Row.Fields.FindField("CheckResult");
int fieldCS = Row.Fields.FindField("cs");
int maxCount = table.RowCount(pQueryFilter);
tlSProgressBar.Minimum = 0;
tlSProgressBar.Maximum = maxCount;
for (int i = 0; i < maxCount; i++)
{
// Row.set_Value(field, Row.get_Value(field2));
//object a1 = Row.Value[field];
//object a2 = Row.Value[field2];
tlSProgressBar.Value = i;
try
{
string strCs = Row.Value[fieldCS].ToString();
double doubleCS = Convert.ToDouble(strCs);
int intCS = Convert.ToInt32(doubleCS);
double jg = doubleCS - intCS;
if (doubleCS<1.0|| doubleCS>=15.0)
{
string strCheckResult = (string)Row.Value[fieldCheckResult];
Row.Value[fieldCheckResult] = strCheckResult + "cs值疑似異常;";
cursor.UpdateRow(Row);
}
if (jg!=0.0)
{
string strCheckResult = (string)Row.Value[fieldCheckResult];
Row.Value[fieldCheckResult] = strCheckResult + "cs須為整數;";
cursor.UpdateRow(Row);
}
}
catch(Exception ex)
{
string strCheckResult = (string)Row.Value[fieldCheckResult];
Row.Value[fieldCheckResult] = strCheckResult + "cs值疑似異常;";
cursor.UpdateRow(Row);
Console.WriteLine(ex.ToString());
}
Row = cursor.NextRow();
}
Marshal.ReleaseComObject(pQueryFilter);
}
private void CkeckDataOverCalcuFunc(IFeatureLayer culFeatLayer, string strSQL, string strDescription)
{
ITable table = culFeatLayer.FeatureClass as ITable;
IQueryFilter pQueryFilter = (IQueryFilter)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("FDFEBD95-ED75-11D0-9A95-080009EC734B")));
//IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = strSQL;
// pQueryFilter.SubFields = caculFieldName;
ICursor cursor = table.Update(pQueryFilter, false);
ESRI.ArcGIS.Geodatabase.IRow Row = cursor.NextRow();
if (Row == null)
return;
//int field = Row.Fields.FindField(caculFieldName);
// int field2 = Row.Fields.FindField(strFieldName);
int fieldCheckResult = Row.Fields.FindField("CheckResult");
int maxCount = table.RowCount(pQueryFilter);
tlSProgressBar.Minimum = 0;
tlSProgressBar.Maximum = maxCount;
for (int i = 0; i < maxCount; i++)
{
// Row.set_Value(field, Row.get_Value(field2));
//object a1 = Row.Value[field];
//object a2 = Row.Value[field2];
tlSProgressBar.Value = i;
try
{
//dynamic calValue = Row.Value[field2];
//bool isChineseCode = CheckIsChineseCode.isLegalChinaCode(calValue);
//if (isChineseCode == false)
//{
string strCheckResult = (string)Row.Value[fieldCheckResult];
Row.Value[fieldCheckResult] = strCheckResult + strDescription + ";";
cursor.UpdateRow(Row);
//}
// cursor.UpdateRow(Row);
}
catch { }
Row = cursor.NextRow();
}
Marshal.ReleaseComObject(pQueryFilter);
}
private void btn_AddBH_Click(object sender, EventArgs e)
{
if (culFeatLayer == null)
{
MessageBox.Show("請先開啟或選擇資料!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
splashScreenManager1.ShowWaitForm();
splashScreenManager1.SetWaitFormCaption("正在執行 透視統計");
splashScreenManager1.SetWaitFormDescription("請耐心等待...");
string strDBFPath= CommCls.GetStatistics(culFeatLayer);
DataTable dt= CommCls.dbfToDataTable(strDBFPath);
splashScreenManager1.CloseWaitForm();
FormAddBH formAddBH = new FormAddBH();
formAddBH.Text = culFeatLayer.FeatureClass.AliasName+"-新增編號";
formAddBH.dt = dt;
formAddBH.pFeatureLayer = culFeatLayer;
formAddBH.ShowDialog();
}
//private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
//{
// //tlSpStLb
// tlSpStLb.Text = " 選項:" + tabControl1.SelectedTab.Text;
//}
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
if (this.WindowState==FormWindowState.Normal)
{
int intLocationX = this.Location.X;
int intLocationY = this.Location.Y;
XmlCls.UpdateXml(StrSaveXMLPath, "LocationX", intLocationX.ToString());
XmlCls.UpdateXml(StrSaveXMLPath, "LocationY", intLocationY.ToString());
int winWidth = this.Width;
int winHeight = this.Height;
XmlCls.UpdateXml(StrSaveXMLPath, "winWidth", winWidth.ToString());
XmlCls.UpdateXml(StrSaveXMLPath, "winHeight", winHeight.ToString());
}
Application.Exit();
}
/// <summary>
/// 重新計算程式碼
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_CalculateXZDM_Click(object sender, EventArgs e)
{
if (culFeatLayer == null)
{
MessageBox.Show("請先開啟或選擇資料!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
splashScreenManager1.ShowWaitForm();
splashScreenManager1.SetWaitFormCaption("正在計算 根據名稱計算程式碼");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "city");
CaculValueGetCodeByNameShi(culFeatLayer, null, "city_name", "city");
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "xzqdm_xq");
CaculValueGetCodeByNameQuXian(culFeatLayer, null, "xzqmc_xq", "xzqdm_xq");
//計算鄉鎮程式碼
splashScreenManager1.SetWaitFormDescription("請耐心等待...計算 " + "xzqdm_xz");
CaculValueGetCodeByNameXiang(culFeatLayer, null, "xzqmc_xz", "xzqdm_xz");
splashScreenManager1.CloseWaitForm();
MessageBox.Show("計算完成", "提示資訊", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
/// <summary>
/// 讀取照片表資料
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtEdit_PhotoTable_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (files.Length > 1)
{
MessageBox.Show("只允許拖拽一個檔案", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
// Directory.
string strExtension = System.IO.Path.GetExtension(files[0]);
if (strExtension == "")
{
MessageBox.Show("不能選擇資料夾", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (strExtension != ".xlsx")
{
MessageBox.Show("請選擇*.xlsx檔案", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
txtEdit_PhotoTable.Text = files[0];
}
}
private void txtEdit_PhotoTable_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
private void txtEdit_PhotoTable_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
private void txtEdit_YSPhotoPath_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (files.Length > 1)
{
MessageBox.Show("只允許拖拽一個檔案", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
// Directory.
string strExtension = System.IO.Path.GetExtension(files[0]);
if (strExtension != "")
{
MessageBox.Show("不能選擇檔案", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
txtEdit_YSPhotoPath.Text = files[0];
//foreach (string file in files)
//{
// //listBox1_AllPicturePath.Items.Add(file);
// textBox1.Text = file;
//}
}
}
private void txtEdit_YSPhotoPath_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
private void txtEdit_YSPhotoPath_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
private void txtEdit_NewPhotoPath_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (files.Length > 1)
{
MessageBox.Show("只允許拖拽一個檔案", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
// Directory.
string strExtension = System.IO.Path.GetExtension(files[0]);
if (strExtension != "")
{
MessageBox.Show("不能選擇檔案", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
txtEdit_NewPhotoPath.Text = files[0];
//foreach (string file in files)
//{
// //listBox1_AllPicturePath.Items.Add(file);
// textBox1.Text = file;
//}
}
}
private void txtEdit_NewPhotoPath_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
private void txtEdit_NewPhotoPath_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
/// <summary>
/// 使用者儲存原始照片表資料
/// </summary>
private List<ZPB_Cls> listZPB = null;
/// <summary>
/// 獲取照片表資料
/// </summary>
/// <param name="strExcelPath"></param>
private void getZPB_FromPath(string strExcelPath)
{
listZPB = new List<ZPB_Cls>();
using (System.IO.FileStream fs = new System.IO.FileStream(strExcelPath, FileMode.Open, FileAccess.Read))
{
//XSSFWorkbook 適用XLSX格式,HSSFWorkbook 適用XLS格式
string fileExt = System.IO.Path.GetExtension(strExcelPath).ToLower();
IWorkbook workbook;
if (fileExt == ".xlsx") { workbook = new XSSFWorkbook(fs); } else if (fileExt == ".xls") { workbook = new HSSFWorkbook(fs); } else { workbook = null; }
ISheet sheet = workbook.GetSheetAt(0);
for (int i = 1; i <= sheet.LastRowNum; i++)
{
NPOI.SS.UserModel.IRow tempRow = sheet.GetRow(i);
ZPB_Cls tempZPB_Cls = new ZPB_Cls();
tempZPB_Cls.id = tempRow.GetCell(0).ToString();
tempZPB_Cls.name = tempRow.GetCell(1).ToString();
tempZPB_Cls.fwbh = tempRow.GetCell(2).ToString();
tempZPB_Cls.folder = tempRow.GetCell(3).ToString();
listZPB.Add(tempZPB_Cls);
}
}
// return listZPB;
}
/// <summary>
/// 讀取照片表資料
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_PhotoTable_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "開啟照片表";
ofd.Filter = "Excel檔案(*.xlsx)|*.xlsx";
ofd.Multiselect = false;
if (ofd.ShowDialog()==DialogResult.OK)
{
txtEdit_PhotoTable.Text = ofd.FileName;
//getZPB_FromPath(ofd.FileName);
}
}
/// <summary>
/// 原始照片路徑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_YSPhotoPath_Click(object sender, EventArgs e)
{
MyFolderBrowserDialog mfbd = new MyFolderBrowserDialog();
if (mfbd.ShowDialog(this) == DialogResult.OK)
{
txtEdit_YSPhotoPath.Text = mfbd.DirectoryPath;
}
}
/// <summary>
/// 結果照片路徑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_NewPhotoPath_Click(object sender, EventArgs e)
{
MyFolderBrowserDialog mfbd = new MyFolderBrowserDialog();
if (mfbd.ShowDialog(this) == DialogResult.OK)
{
txtEdit_NewPhotoPath.Text = mfbd.DirectoryPath;
}
}
/// <summary>
/// 獲取shp檔案
/// </summary>
/// <param name="shpfilePath">shp檔案路徑</param>
/// <returns></returns>
private IFeatureClass GetShapefile(string shpfilePath)
{
IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
IWorkspaceFactoryLockControl pWorkspaceFactoryLockControl = pWorkspaceFactory as IWorkspaceFactoryLockControl;
if (pWorkspaceFactoryLockControl.SchemaLockingEnabled)
{
pWorkspaceFactoryLockControl.DisableSchemaLocking();
}
string directoryPath = System.IO.Path.GetDirectoryName(shpfilePath);
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(directoryPath, 0);
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(System.IO.Path.GetFileName(shpfilePath));
return pFeatureClass;
}
/// <summary>
/// 儲存照片處理之照片要素類
/// </summary>
private List<IFeatureLayer> listZPFL = null;
/// <summary>
/// 照片處理之讀取GDB資料
/// </summary>
/// <param name="strGDB_Path"></param>
/// <returns></returns>
private List<IFeatureLayer> getZHQ_FLFunc(string strGDB_Path)
{
comboBox1.Items.Clear();
List<IFeatureLayer> listFL = new List<IFeatureLayer>();
FileGDBWorkspaceFactory fac = new FileGDBWorkspaceFactory();
IFeatureWorkspace pFtWS = (IFeatureWorkspace)fac.OpenFromFile(strGDB_Path, 0);
IWorkspace pWork = (IWorkspace)pFtWS;
IEnumDataset pEnumDs = pWork.get_Datasets(esriDatasetType.esriDTFeatureClass);
IDataset pDs = pEnumDs.Next();
while (pDs != null)
{
IFeatureClass temp = pDs as IFeatureClass;
IFeatureLayer tempLayer = new FeatureLayer();
tempLayer.FeatureClass = temp;
tempLayer.Name = tempLayer.FeatureClass.AliasName;
comboBox1.Items.Add(tempLayer.Name);
listFL.Add(tempLayer);
pDs = pEnumDs.Next();
}
return listFL;
}
private void textEdit1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (files.Length > 1)
{
MessageBox.Show("只允許拖拽一個檔案", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
// Directory.
string strExtension = System.IO.Path.GetExtension(files[0]);
if (strExtension != ".gdb")
{
MessageBox.Show("不能選擇檔案", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
textEdit1.Text = files[0];
//foreach (string file in files)
//{
// //listBox1_AllPicturePath.Items.Add(file);
// textBox1.Text = file;
//}
}
}
private void textEdit1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
private void textEdit1_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
private void btn_ZPGDB_Click(object sender, EventArgs e)
{
MyFolderBrowserDialog mfbd = new MyFolderBrowserDialog();
if (mfbd.ShowDialog(this) == DialogResult.OK)
{
textEdit1.Text = mfbd.DirectoryPath;
//listZPFL = getZHQ_FLFunc(textEdit1.Text);
}
}
/// <summary>
/// 照片之要素類
/// </summary>
private IFeatureLayer pZP_FL = null;
/// <summary>
/// 多媒體之選擇要素類
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
pZP_FL = listZPFL[comboBox1.SelectedIndex];
}
private void btn_ExcutePhoto_Click(object sender, EventArgs e)
{
if (pZP_FL==null)
{
return;
}
if (listZPB==null|| listZPB.Count<=0)
{
return;
}
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "處理結果";
sfd.Filter= "Excel檔案|*.xlsx";
sfd.FileName = pZP_FL.FeatureClass.AliasName + "_處理結果";
sfd.AddExtension = true;
if (sfd.ShowDialog()==DialogResult.OK)
{
splashScreenManager1.ShowWaitForm();
splashScreenManager1.SetWaitFormCaption("執行 照片處理");
splashScreenManager1.SetWaitFormDescription("請耐心等待...照片拷貝並重新命名");
// listZPB_ZLJG = new List<ZPB_Cls>();
for (int i = 0; i < listZPB.Count; i++)
{
ZPB_Cls temp = listZPB[i];
string strZP_Path = txtEdit_YSPhotoPath.Text + "\\" + temp.folder + "\\" + temp.name;//原始照片路徑
if(File.Exists(strZP_Path))
{
try
{
//string strZP_Path = txtEdit_YSPhotoPath.Text + "\\" + temp.folder + "\\" + temp.name;//原始照片路徑
string NewFileName = Guid.NewGuid().ToString() + ".jpg";//新照片名稱
temp.strNewName = NewFileName;
string strSQL = "fwbh='" + temp.fwbh + "'";
IFeature pFeature = getPointToZB(pZP_FL, strSQL);
ESRI.ArcGIS.Geometry.IPoint myPoint = pFeature.Shape as ESRI.ArcGIS.Geometry.IPoint;
int pBHField = pFeature.Fields.FindField("BH");
string pBHValue= pFeature.Value[pBHField].ToString();
string strNewZP_Folder = txtEdit_NewPhotoPath.Text + "\\" + pBHValue;
try
{
Directory.CreateDirectory(strNewZP_Folder);
}
catch { }
string strNewZP_Path = txtEdit_NewPhotoPath.Text + "\\" + pBHValue + "\\" + NewFileName;//新照片路徑
if (myPoint!=null)
{
temp.XZB = myPoint.X;
temp.YZB = myPoint.Y;
//listZPB_ZLJG.Add(temp);
//FileInfo fi = new FileInfo(strZP_Path);
//fi.CopyTo(strNewZP_Path,true);
File.Copy(strZP_Path, strNewZP_Path, true);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
//IWorkbook workbook = new XSSFWorkbook();
//ISheet sheet = workbook.CreateSheet("Sheet1");
splashScreenManager1.SetWaitFormDescription("請耐心等待...匯出處理結果表");
string fileExt = System.IO.Path.GetExtension(sfd.FileName).ToLower();
IWorkbook workbook;
if (fileExt == ".xlsx") { workbook = new XSSFWorkbook(); } else if (fileExt == ".xls") { workbook = new HSSFWorkbook(); } else { workbook = null; }
var sheet = workbook.CreateSheet("Sheet1");
NPOI.SS.UserModel.IRow row = sheet.CreateRow(0);
row.CreateCell(0).SetCellValue("id");
row.CreateCell(1).SetCellValue("name");
row.CreateCell(2).SetCellValue("fwbh");
row.CreateCell(3).SetCellValue("NewName");
row.CreateCell(4).SetCellValue("XZB");
row.CreateCell(5).SetCellValue("YZB");
for (int i = 0; i < listZPB.Count; i++)
{
if (listZPB[i].XZB!=0.0)
{
NPOI.SS.UserModel.IRow rowData = sheet.CreateRow(i + 1);
rowData.CreateCell(0).SetCellValue(listZPB[i].id);
rowData.CreateCell(1).SetCellValue(listZPB[i].name);
rowData.CreateCell(2).SetCellValue(listZPB[i].fwbh);
rowData.CreateCell(3).SetCellValue(listZPB[i].strNewName);
rowData.CreateCell(4).SetCellValue(listZPB[i].XZB);
rowData.CreateCell(5).SetCellValue(listZPB[i].YZB);
}
}
splashScreenManager1.SetWaitFormDescription("請耐心等待...寫入磁碟");
using (FileStream fs2 = File.OpenWrite(sfd.FileName))
{
workbook.Write(fs2);
//MessageBox.Show("Excel已經寫入成功!");
}
splashScreenManager1.CloseWaitForm();
}
}
private IFeature getPointToZB(IFeatureLayer culFeatLayer, string strSQL)
{
//ESRI.ArcGIS.Geometry.IPoint pPoint = null;
IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = strSQL;
IFeatureCursor pFCursor = culFeatLayer.FeatureClass.Search(pQueryFilter, false);
IFeature pFeature = pFCursor.NextFeature();
//ESRI.ArcGIS.Geometry.IPoint pPoint = new ESRI.ArcGIS.Geometry.Point();
//ESRI.ArcGIS.Geometry.IArea pArea = pFeature.Shape as ESRI.ArcGIS.Geometry.IArea;
//pArea.QueryCentroid(pPoint);
//pPoint = pFeature.Shape as ESRI.ArcGIS.Geometry.IPoint;
return pFeature;
}
private void txtEdit_PhotoTable_EditValueChanged(object sender, EventArgs e)
{
getZPB_FromPath(txtEdit_PhotoTable.Text);
}
private void textEdit1_EditValueChanged(object sender, EventArgs e)
{
listZPFL = getZHQ_FLFunc(textEdit1.Text);
}
/// <summary>
/// 轉換前處理之鄉鎮名稱最大匹配
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_unck_XZPP_Click(object sender, EventArgs e)
{
if (listFLayerZHQ_Check == null)
{
MessageBox.Show("沒有資料可查!請先開啟資料", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
splashScreenManager1.ShowWaitForm();
for (int i = 0; i < listFLayerZHQ_Check.Count; i++)
{
IFeatureLayer culFeatLayer = listFLayerZHQ_Check[i];
string strFyLyName = culFeatLayer.FeatureClass.AliasName;
listBox_unck_FtLy.SelectedValue = strFyLyName;
listBox_unck_FtLy.Refresh();
splashScreenManager1.SetWaitFormCaption("執行檢查 " + culFeatLayer.FeatureClass.AliasName + " 鄉鎮名稱最大匹配");
//新增欄位
try
{
AddStringField(culFeatLayer.FeatureClass, "CheckMaxMatch");
}
catch
{
Console.WriteLine("新增欄位失敗");
}
splashScreenManager1.SetWaitFormDescription("請耐心等待...準備檢查");
CaculValue(culFeatLayer, null, "CheckMaxMatch", "1");
splashScreenManager1.SetWaitFormDescription("請耐心等待...鄉鎮名稱是否標準");
CkeckXZMC(culFeatLayer, null, "xiang", "xian", "CheckMaxMatch");
splashScreenManager1.SetWaitFormDescription("請耐心等待...鄉鎮名稱最大匹配");
string strSQL = "CheckMaxMatch<>'1'";
CheckXZNameMaxMatch(culFeatLayer, strSQL, "xiang", "xian", "CheckMaxMatch");
}
tlSProgressBar.Value = 0;
splashScreenManager1.CloseWaitForm();
MessageBox.Show("匹配完成,結果存放在\"CheckMaxMatch\"欄位中","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
private void CkeckXZMC(IFeatureLayer culFeatLayer, string strSQL, string strMhFieldXZ, string strMhFieldXQ, string strSaveField)
{
ITable table = culFeatLayer.FeatureClass as ITable;
IQueryFilter pQueryFilter = (IQueryFilter)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("FDFEBD95-ED75-11D0-9A95-080009EC734B")));
//IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = strSQL;
// pQueryFilter.SubFields = caculFieldName;
ICursor cursor = table.Update(pQueryFilter, false);
ESRI.ArcGIS.Geodatabase.IRow Row = cursor.NextRow();
if (Row == null)
return;
int fieldXZ = Row.Fields.FindField(strMhFieldXZ);//鄉鎮名稱欄位
int fieldXQ = Row.Fields.FindField(strMhFieldXQ);//縣區名稱欄位
int fieldSave = Row.Fields.FindField(strSaveField);//儲存最大匹配名稱欄位
int maxCount = table.RowCount(pQueryFilter);
tlSProgressBar.Minimum = 0;
tlSProgressBar.Maximum = maxCount;
string Connstr = SQliteHelperCls.CustomerConnStr(SQliteHelperCls.strDBPath);
//string strSQL = "Select 鄉鎮名稱 from 鄉鎮程式碼名稱 where 縣區名稱='息烽縣'";
for (int i = 0; i < maxCount; i++)
{
tlSProgressBar.Value = i;
string strXZName = Row.Value[fieldXZ].ToString();
string strXQName = Row.Value[fieldXQ].ToString();
try
{
string strSQLiteSQL = "Select 鄉鎮名稱 from 鄉鎮程式碼名稱 where 縣區名稱='" + strXQName + "' and 鄉鎮名稱 = '" + strXZName + "'";
using (SQLiteConnection SqlConn = new SQLiteConnection(Connstr))
{
using (SQLiteCommand SqlCmd = new SQLiteCommand(strSQLiteSQL, SqlConn))
{
SqlConn.Open();
using (SQLiteDataReader reader = SqlCmd.ExecuteReader(CommandBehavior.CloseConnection))
{
if (reader.HasRows == false)
{
try
{
Row.Value[fieldSave] = "未找到鄉鎮名稱";
cursor.UpdateRow(Row);
}
catch { }
}
}
}
}
}
catch { }
Console.WriteLine(i);
Row = cursor.NextRow();
}
//using (SQLiteConnection SqlConn = new SQLiteConnection(Connstr))
//{
// SqlConn.Open();
// for (int i = 0; i < maxCount; i++)
// {
// tlSProgressBar.Value = i;
// string strXZName = Row.Value[fieldXZ].ToString();
// string strXQName = Row.Value[fieldXQ].ToString();
// try
// {
// string strSQLiteSQL = "Select 鄉鎮名稱 from 鄉鎮程式碼名稱 where 縣區名稱='" + strXQName + "' and 鄉鎮名稱 = '" + strXZName + "'";
// using (SQLiteCommand SqlCmd = new SQLiteCommand(strSQLiteSQL, SqlConn))
// {
// // SqlConn.Open();
// using (SQLiteDataReader reader = SqlCmd.ExecuteReader(CommandBehavior.CloseConnection))
// {
// if (reader.HasRows == false)
// {
// try
// {
// Row.Value[fieldSave] = "false";
// cursor.UpdateRow(Row);
// }
// catch { }
// }
// }
// }
// }
// catch{}
// Console.WriteLine(i);
// Row = cursor.NextRow();
// }
//}
}
/// <summary>
/// 查詢名稱最大匹配
/// </summary>
/// <param name="culFeatLayer"></param>
/// <param name="strSQL"></param>
/// <param name="strMhFieldXZ">鄉鎮名稱欄位</param>
/// <param name="strMhFieldXQ">縣區名稱欄位</param>
/// <param name="strSaveField">儲存最大匹配欄位</param>
private void CheckXZNameMaxMatch(IFeatureLayer culFeatLayer, string strSQL,string strMhFieldXZ,string strMhFieldXQ,string strSaveField)
{
ITable table = culFeatLayer.FeatureClass as ITable;
IQueryFilter pQueryFilter = (IQueryFilter)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("FDFEBD95-ED75-11D0-9A95-080009EC734B")));
//IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = strSQL;
// pQueryFilter.SubFields = caculFieldName;
ICursor cursor = table.Update(pQueryFilter, false);
ESRI.ArcGIS.Geodatabase.IRow Row = cursor.NextRow();
if (Row == null)
return;
int fieldXZ = Row.Fields.FindField(strMhFieldXZ);//鄉鎮名稱欄位
int fieldXQ = Row.Fields.FindField(strMhFieldXQ);//縣區名稱欄位
int fieldSave = Row.Fields.FindField(strSaveField);//儲存最大匹配名稱欄位
int maxCount = table.RowCount(pQueryFilter);
tlSProgressBar.Minimum = 0;
tlSProgressBar.Maximum = maxCount;
string Connstr = SQliteHelperCls.CustomerConnStr(SQliteHelperCls.strDBPath);
//string strSQL = "Select 鄉鎮名稱 from 鄉鎮程式碼名稱 where 縣區名稱='息烽縣'";
for (int i = 0; i < maxCount; i++)
{
tlSProgressBar.Value = i;
string strXZName = Row.Value[fieldXZ].ToString();
//移除非法字元
strXZName = CheckIsChineseCode.GetNewChinaCode(strXZName);
strXZName = strXZName.Replace("辦事處", "");
strXZName = strXZName.Replace("街道", "");
strXZName = strXZName.Replace("族", "");
//if (strXZName.Contains("街道")|| strXZName.Contains("族"))
//{
// try { strXZName = strXZName.Substring(0, 2); }
// catch { }
//}
string strXQName = Row.Value[fieldXQ].ToString();
string strZDPPName = "1";
string temp = String.Empty;//記錄最終 最大匹配值
//string strSQLiteSQL = "Select 鄉鎮名稱 from 鄉鎮程式碼名稱 where 縣區名稱='"+ strXQName + "' and 鄉鎮名稱 = '"+ strXZName + "'";
string strSQLiteSQL = "Select 鄉鎮名稱 from 鄉鎮程式碼名稱 where 縣區名稱='" + strXQName + "'";
using (SQLiteConnection SqlConn = new SQLiteConnection(Connstr))
{
using (SQLiteCommand SqlCmd = new SQLiteCommand(strSQLiteSQL, SqlConn))
{
SqlConn.Open();
SQLiteDataReader reader = SqlCmd.ExecuteReader(CommandBehavior.CloseConnection);
if (reader.HasRows)
{
while (reader.Read())
{
string str = reader.GetString(0);//標準鄉鎮名稱
string strJG = LCS(str, strXZName);//最大匹配值
// string strJG = LCS(textBox1.Text, str);
if (String.IsNullOrEmpty(strJG) == false && strJG.Length >= 2)
{
if(temp.Length< strJG.Length)
{
temp = strJG;
strZDPPName = str;
}
}
// Console.WriteLine(str);
}
}
}
}
try
{
if (strZDPPName != "1")
{
Row.Value[fieldSave] = strZDPPName;
cursor.UpdateRow(Row);
}
Console.WriteLine(i);
}
catch { }
Row = cursor.NextRow();
}
}
#region LCS演算法實現
/// <summary>
/// 最大公共字串
/// LCS演算法
/// Longest Common Subsequence
/// </summary>
/// <param name="str1">字串A</param>
/// <param name="str2">字串B</param>
/// <returns></returns>
private string LCS(string str1, string str2)
{
if (str1 == str2)
{
return str1;
}
else if (String.IsNullOrEmpty(str1) || String.IsNullOrEmpty(str2))
{
return null;
}
var d = new int[str1.Length, str2.Length];
var index = 0;
var length = 0;
for (int i = 0; i < str1.Length; i++)
{
for (int j = 0; j < str2.Length; j++)
{
//左上角
var n = i - 1 >= 0 && j - 1 >= 0 ? d[i - 1, j - 1] : 0;
//當前節點值 = “1 + 左上角的值”:“0”
d[i, j] = str1[i] == str2[j] ? 1 + n : 0;
//如果是最大值,則記錄該值和行號
if (d[i, j] > length)
{
length = d[i, j];
index = i;
}
}
}
return str1.Substring(index - length + 1, length);
}
#endregion
/// <summary>
/// 新增雙精度欄位
/// </summary>
/// <param name="culFeatCls"></param>
/// <param name="strFieldName"></param>
private void AddDoubleField(IFeatureClass culFeatCls, string strFieldName)
{
IClass pClass = culFeatCls as IClass;
IFieldsEdit fldsE = culFeatCls.Fields as IFieldsEdit;
IField fld = new Field();
IFieldEdit2 fldE = fld as IFieldEdit2;
fldE.Type_2 = esriFieldType.esriFieldTypeDouble;
// fldE.Length_2 = 500;
fldE.Name_2 = strFieldName;
pClass.AddField(fld);
}
/// <summary>
/// 執行檢查未完全採集
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BTN_BWQCJ_Excute_Click(object sender, EventArgs e)
{
if (culHBFtLy==null)
{
MessageBox.Show("請先開啟或選擇紅斑資料", "提示資訊", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (listCJDFylys==null)
{
MessageBox.Show("請開啟採集點資料", "提示資訊", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (comboBoxBHFields.SelectedIndex==-1)
{
MessageBox.Show("請選擇圖斑面積欄位", "提示資訊", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
splashScreenManager1.ShowWaitForm();
splashScreenManager1.SetWaitFormCaption("執行 不完全採集核查");
splashScreenManager1.SetWaitFormDescription("請耐心等待..初始化計算...");
try
{
AddDoubleField(culHBFtLy.FeatureClass, "TotalMJ");//新增總面積欄位
}
catch{}
CaculValue(culHBFtLy, null, "TotalMJ", 0.0);//初始化
for (int i = 0; i < listCJDFylys.Count; i++)
{
IFeatureLayer culCJDFtLy = listCJDFylys[i];
splashScreenManager1.SetWaitFormDescription("請耐心等待.. 計算 "+ culCJDFtLy.FeatureClass.AliasName);
if (culCJDFtLy.FeatureClass.AliasName=="單戶住宅類"|| culCJDFtLy.FeatureClass.AliasName == "多戶住宅類")
{
GetZZLAreaAddFunc(culHBFtLy, null, culCJDFtLy);
}
else
{
//GetFZZLAreaAddFunc(culHBFtLy, null, culCJDFtLy);
}
}
tlSProgressBar.Value = 0;
splashScreenManager1.CloseWaitForm();
}
/// <summary>
/// 計算單戶住宅類和多戶住宅類的面積相加
/// </summary>
/// <param name="culHBFtLayer">紅斑要素類</param>
/// <param name="strSQL"></param>
/// <param name="culCJDFtLayer">採集點</param>
private void GetZZLAreaAddFunc(IFeatureLayer culHBFtLayer, string strSQL, IFeatureLayer culCJDFtLayer)
{
IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = "";
//pFeatureSelection = mianfeatureLayer as IFeatureSelection;
int maxCount= culHBFtLayer.FeatureClass.FeatureCount(pQueryFilter);
tlSProgressBar.Maximum = maxCount;
tlSProgressBar.Minimum = 0;
IFeatureCursor pfCursor = culHBFtLayer.Search(pQueryFilter, false);
IFeature pmianFeature = pfCursor.NextFeature();
int kk = 0;
while (pmianFeature != null)
{
Console.WriteLine(kk++);
tlSProgressBar.Value = kk;
int fieldTotal = pmianFeature.Fields.FindField("TotalMJ");//紅斑-疊加的總面積欄位索引
IGeometry pGeometry = pmianFeature.Shape;
ISpatialFilter spatialFilter = new SpatialFilter();
spatialFilter.Geometry = pGeometry;
spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
IFeatureSelection pdianFeatureSelection = culCJDFtLayer as IFeatureSelection;
pdianFeatureSelection.SelectFeatures(spatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
ISelectionSet pSelectionSet = pdianFeatureSelection.SelectionSet;
int intCount = pSelectionSet.Count;
//定義ICursor介面的遊標以遍歷整個選擇集
ICursor cursor;
//使用ISelectionSet介面的Search方法,使用null作為查詢過濾器,cursor作為返回值獲取整個選擇集
pSelectionSet.Search(null, false, out cursor);
IFeatureCursor pdianEnumFeature = cursor as IFeatureCursor;
//IEnumFeature pdianEnumFeature = pSelectionSet as IEnumFeature;
IFeature pdianFeature = pdianEnumFeature.NextFeature();
while (pdianFeature != null)
{
int fieldFwzdMJ = pdianFeature.Fields.FindField("fwzdmj");//採集點-房屋佔地面積欄位索引
int fieldFsssMJ = pdianFeature.Fields.FindField("fsssmj");//採集點-附屬設施面積欄位索引
double dbTatalMJ = 0;
try
{
dbTatalMJ = Convert.ToDouble(pmianFeature.Value[fieldTotal]);
}
catch
{
dbTatalMJ = 0;
}
double dbFwzdMJ = Convert.ToDouble(pdianFeature.Value[fieldFwzdMJ]);
try
{
dbFwzdMJ = Convert.ToDouble(pdianFeature.Value[fieldFwzdMJ]);
}
catch
{
dbFwzdMJ = 0;
}
double FsssMJ = Convert.ToDouble(pdianFeature.Value[fieldFsssMJ]);
try
{
FsssMJ = Convert.ToDouble(pdianFeature.Value[fieldFsssMJ]);
}
catch
{
FsssMJ = 0;
}
double newTatalMJ = dbTatalMJ + dbFwzdMJ + FsssMJ;
pmianFeature.set_Value(fieldTotal, newTatalMJ);
pmianFeature.Store();
pdianFeature = pdianEnumFeature.NextFeature();
}
pmianFeature = pfCursor.NextFeature();
}
}
/// <summary>
/// 計算非住宅類的面積相加
/// </summary>
/// <param name="culHBFtLayer">紅斑要素類</param>
/// <param name="strSQL"></param>
/// <param name="culCJDFtLayer">採集點</param>
private void GetFZZLAreaAddFunc(IFeatureLayer culHBFtLayer, string strSQL, IFeatureLayer culCJDFtLayer)
{
IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = "";
//pFeatureSelection = mianfeatureLayer as IFeatureSelection;
IFeatureCursor pfCursor = culHBFtLayer.Search(pQueryFilter, false);
IFeature pmianFeature = pfCursor.NextFeature();
while (pmianFeature != null)
{
int fieldTotal = pmianFeature.Fields.FindField("TotalMJ");//紅斑-疊加的總面積欄位索引
IGeometry pGeometry = pmianFeature.Shape;
ISpatialFilter spatialFilter = new SpatialFilter();
spatialFilter.Geometry = pGeometry;
spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
IFeatureSelection pdianFeatureSelection = culCJDFtLayer as IFeatureSelection;
pdianFeatureSelection.SelectFeatures(spatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
ISelectionSet pSelectionSet = pdianFeatureSelection.SelectionSet;
int intCount = pSelectionSet.Count;
//定義ICursor介面的遊標以遍歷整個選擇集
ICursor cursor;
//使用ISelectionSet介面的Search方法,使用null作為查詢過濾器,cursor作為返回值獲取整個選擇集
pSelectionSet.Search(null, false, out cursor);
IFeatureCursor pdianEnumFeature = cursor as IFeatureCursor;
//IEnumFeature pdianEnumFeature = pSelectionSet as IEnumFeature;
IFeature pdianFeature = pdianEnumFeature.NextFeature();
while (pdianFeature != null)
{
int fieldFwzdMJ = pdianFeature.Fields.FindField("fwzdmj");//採集點-房屋佔地面積欄位索引
double dbTatalMJ = 0;
try
{
dbTatalMJ = Convert.ToDouble(pmianFeature.Value[fieldTotal]);
}
catch
{
dbTatalMJ = 0;
}
double dbFwzdMJ = Convert.ToDouble(pdianFeature.Value[fieldFwzdMJ]);
try
{
dbFwzdMJ = Convert.ToDouble(pdianFeature.Value[fieldFwzdMJ]);
}
catch
{
dbFwzdMJ = 0;
}
double newTatalMJ = dbTatalMJ + dbFwzdMJ;
pmianFeature.set_Value(fieldTotal, newTatalMJ);
pmianFeature.Store();
pdianFeature = pdianEnumFeature.NextFeature();
}
pmianFeature = pfCursor.NextFeature();
}
}
#region 面要素所在GDB
private void txtEd_BWQCJ_MGDB_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (files.Length > 1)
{
MessageBox.Show("只允許拖拽一個檔案", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
// Directory.
string strExtension = System.IO.Path.GetExtension(files[0]);
if (strExtension != ".gdb")
{
MessageBox.Show("不能選擇檔案", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
txtEd_BWQCJ_MGDB.Text = files[0];
}
}
private void txtEd_BWQCJ_MGDB_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
private void txtEd_BWQCJ_MGDB_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
#endregion
#region 採集點要素所在GDB
private void txtEd_BWQCJ_DGDB_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (files.Length > 1)
{
MessageBox.Show("只允許拖拽一個檔案", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
// Directory.
string strExtension = System.IO.Path.GetExtension(files[0]);
if (strExtension != ".gdb")
{
MessageBox.Show("不能選擇檔案", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
txtEd_BWQCJ_DGDB.Text = files[0];
}
}
private void txtEd_BWQCJ_DGDB_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
private void txtEd_BWQCJ_DGDB_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
#endregion
private void btn_BWQCJ_MGDB_Click(object sender, EventArgs e)
{
MyFolderBrowserDialog mfbd = new MyFolderBrowserDialog();
if (mfbd.ShowDialog(this) == DialogResult.OK)
{
txtEd_BWQCJ_MGDB.Text = mfbd.DirectoryPath;
}
}
private void BTN_BWQCJ_DGDB_Click(object sender, EventArgs e)
{
MyFolderBrowserDialog mfbd = new MyFolderBrowserDialog();
if (mfbd.ShowDialog(this) == DialogResult.OK)
{
txtEd_BWQCJ_DGDB.Text = mfbd.DirectoryPath;
}
}
/// <summary>
/// 其他-讀取紅斑要素類
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtEd_BWQCJ_MGDB_EditValueChanged(object sender, EventArgs e)
{
listHBFylys = getHBFtLyFunc(txtEd_BWQCJ_MGDB.Text);
}
/// <summary>
/// 當前選擇的紅斑要素類
/// </summary>
private IFeatureLayer culHBFtLy = null;
/// <summary>
/// 其他-紅斑要素類集合
/// </summary>
private List<IFeatureLayer> listHBFylys = null;
/// <summary>
/// 其他-獲取紅斑要素類集合非法
/// </summary>
/// <param name="strGDB_Path"></param>
/// <returns></returns>
private List<IFeatureLayer> getHBFtLyFunc(string strGDB_Path)
{
cmbx_BWQCJ_MGDB.Items.Clear();
List<IFeatureLayer> listFL = new List<IFeatureLayer>();
FileGDBWorkspaceFactory fac = new FileGDBWorkspaceFactory();
IFeatureWorkspace pFtWS = (IFeatureWorkspace)fac.OpenFromFile(strGDB_Path, 0);
IWorkspace pWork = (IWorkspace)pFtWS;
IEnumDataset pEnumDs = pWork.get_Datasets(esriDatasetType.esriDTFeatureClass);
IDataset pDs = pEnumDs.Next();
while (pDs != null)
{
IFeatureClass temp = pDs as IFeatureClass;
IFeatureLayer tempLayer = new FeatureLayer();
tempLayer.FeatureClass = temp;
tempLayer.Name = tempLayer.FeatureClass.AliasName;
cmbx_BWQCJ_MGDB.Items.Add(tempLayer.Name);
listFL.Add(tempLayer);
pDs = pEnumDs.Next();
}
return listFL;
}
/// <summary>
/// 其他-採集點要素類集合
/// </summary>
private List<IFeatureLayer> listCJDFylys = null;
/// <summary>
/// 其他-獲取採集點要素類集合
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtEd_BWQCJ_DGDB_EditValueChanged(object sender, EventArgs e)
{
listCJDFylys = getCJDFtLyFunc(txtEd_BWQCJ_DGDB.Text);
}
/// <summary>
/// 其他-獲取採集點要素類集合非法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private List<IFeatureLayer> getCJDFtLyFunc(string strGDB_Path)
{
listBoxControlCJD.Items.Clear();
List<IFeatureLayer> listFL = new List<IFeatureLayer>();
FileGDBWorkspaceFactory fac = new FileGDBWorkspaceFactory();
IFeatureWorkspace pFtWS = (IFeatureWorkspace)fac.OpenFromFile(strGDB_Path, 0);
IWorkspace pWork = (IWorkspace)pFtWS;
IEnumDataset pEnumDs = pWork.get_Datasets(esriDatasetType.esriDTFeatureClass);
IDataset pDs = pEnumDs.Next();
while (pDs != null)
{
IFeatureClass temp = pDs as IFeatureClass;
IFeatureLayer tempLayer = new FeatureLayer();
tempLayer.FeatureClass = temp;
tempLayer.Name = tempLayer.FeatureClass.AliasName;
listBoxControlCJD.Items.Add(tempLayer.Name);
listFL.Add(tempLayer);
pDs = pEnumDs.Next();
}
return listFL;
}
///// <summary>
///// 當前選擇的 要素欄位集合
///// </summary>
//List<IField> listCulSelField = null;
/// <summary>
/// 其他-獲取當前選擇的紅斑要素類
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void cmbx_BWQCJ_MGDB_SelectedIndexChanged(object sender, EventArgs e)
{
culHBFtLy = listHBFylys[cmbx_BWQCJ_MGDB.SelectedIndex];
comboBoxBHFields.Items.Clear();
comboBoxBHFields.SelectedItem = null;
int FieldCounts = culHBFtLy.FeatureClass.Fields.FieldCount;
for (int i = 0; i < FieldCounts; i++)
{
//listCulSelField.Add(culHBFtLy.FeatureClass.Fields.get_Field(i));
comboBoxBHFields.Items.Add(culHBFtLy.FeatureClass.Fields.get_Field(i).AliasName);
}
}
/// <summary>
/// 轉換前檢查-檢查結果統計-按錯誤型別統計
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_unck_JCJGTJ_Click(object sender, EventArgs e)
{
//JCJGTJ_ModelCls
if (listFLayerZHQ_Check == null)
{
MessageBox.Show("沒有資料可統計!請先開啟資料", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
MyFolderBrowserDialog mfbd = new MyFolderBrowserDialog();
if (mfbd.ShowDialog(this) == DialogResult.OK)
{
string strSaveFolder= mfbd.DirectoryPath;
splashScreenManager1.ShowWaitForm();
splashScreenManager1.SetWaitFormCaption("執行 檢查結果統計");
for (int i = 0; i < listFLayerZHQ_Check.Count; i++)
{
IFeatureLayer culTempFtLy = listFLayerZHQ_Check[i];
string strculFtLyName = culTempFtLy.FeatureClass.AliasName;
listBox_unck_FtLy.SelectedValue = strculFtLyName;
listBox_unck_FtLy.Refresh();
splashScreenManager1.SetWaitFormDescription("請耐心等待... 統計 " + strculFtLyName + " 中");
int kk = culTempFtLy.FeatureClass.FindField("CheckResult");
if (kk != -1)
{
string strSavePath = strSaveFolder + "\\" + strculFtLyName + "_檢查結果統計.xlsx";
try { File.Delete(strSavePath); }
catch { }
Dictionary<string, int> dicJCJGTJ=JCJGTJByLX_Func(culTempFtLy, null);
int intTotal = 0;
foreach (var temp in dicJCJGTJ)
{
intTotal += temp.Value;
}
dicJCJGTJ.Add("合計", intTotal);
splashScreenManager1.SetWaitFormDescription("請耐心等待... 儲存中");
using (var excel = new ExcelPackage(new FileInfo(strSavePath)))
{
//建立一個工作表
var ws = excel.Workbook.Worksheets.Add("Sheet1");
ws.Cells[1, 1].Value = "問題描述";
//ws.Cells[1 + 2, 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
//ws.Cells[1 + 2, 1].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
ws.Cells[1, 2].Value = "數量";
//ws.Cells[1, 2].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
//ws.Cells[1, 2].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
int bj = 0;
foreach (var temp in dicJCJGTJ)
{
ws.Cells[bj + 2, 1].Value = temp.Key;
//ws.Cells[bj + 2, 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
//ws.Cells[bj + 2, 1].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
ws.Cells[bj + 2, 2].Value = temp.Value;
//ws.Cells[bj + 2, 2].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
//ws.Cells[bj + 2, 2].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
bj++;
}
ws.Cells.Style.VerticalAlignment = ExcelVerticalAlignment.Center;
ws.Cells.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
ws.Column(1).AutoFit();
ws.Column(2).AutoFit();
//儲存表格資訊
excel.Save();
}
}
}
splashScreenManager1.CloseWaitForm();
tlSProgressBar.Value = 0;
DialogResult dirlt= MessageBox.Show("處理完成,是否開啟?", "提示資訊", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (dirlt==DialogResult.OK)
{
Process.Start(strSaveFolder);
}
}
}
/// <summary>
/// 按錯誤型別統計
/// </summary>
/// <param name="culTempFtLy"></param>
/// <param name="strSQL"></param>
/// <returns></returns>
private Dictionary<string, int> JCJGTJByLX_Func(IFeatureLayer culTempFtLy,string strSQL)
{
Dictionary<string, int> dicJCJGTJ = new Dictionary<string, int>();
ITable table = culTempFtLy.FeatureClass as ITable;
IQueryFilter pQueryFilter = (IQueryFilter)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("FDFEBD95-ED75-11D0-9A95-080009EC734B")));
//IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = strSQL;
// pQueryFilter.SubFields = caculFieldName;
ICursor cursor = table.Update(pQueryFilter, false);
ESRI.ArcGIS.Geodatabase.IRow Row = cursor.NextRow();
if (Row == null)
return null;
int fieldCheckResult = Row.Fields.FindField("CheckResult");
int maxCount = table.RowCount(pQueryFilter);
tlSProgressBar.Minimum = 0;
tlSProgressBar.Maximum = maxCount;
for (int i = 0; i < maxCount; i++)
{
tlSProgressBar.Value = i;
string strCheckResult = Row.Value[fieldCheckResult].ToString();
if (!String.IsNullOrEmpty(strCheckResult))
{
string[] strArr= strCheckResult.Split(';');
for (int j = 0; j < strArr.Length; j++)
{
string strTemp = strArr[j];
if (!String.IsNullOrEmpty(strTemp))
{
if (dicJCJGTJ.ContainsKey(strTemp))
{
dicJCJGTJ[strTemp] = dicJCJGTJ[strTemp] + 1;
}
else
{
dicJCJGTJ.Add(strTemp, 1);
}
}
}
}
Row = cursor.NextRow();
}
Marshal.ReleaseComObject(pQueryFilter);
return dicJCJGTJ;
}
/// <summary>
/// 用於驗證身份證的要素類
/// </summary>
private IFeatureLayer pcheckSFZ_FtLy = null;
/// <summary>
/// 身份證必填及合法性檢查
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_unck_ExcuteFSZ_Click(object sender, EventArgs e)
{
if (pcheckSFZ_FtLy == null)
{
MessageBox.Show("請開啟資料或選擇圖層!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
try
{
AddStringField(pcheckSFZ_FtLy.FeatureClass, "sfzh_Check");
}
catch
{
Console.WriteLine("新增欄位失敗");
}
//CaculValue(pcheckSFZ_FtLy, null, "sfzh_Check", ";");
splashScreenManager1.ShowWaitForm();
splashScreenManager1.SetWaitFormCaption("執行 sfzh驗證");
splashScreenManager1.SetWaitFormDescription("請耐心等待...sfzh必填驗證中");
string strSQL = "sfzh='' or sfzh is null";
CaculValue(pcheckSFZ_FtLy, strSQL, "sfzh_Check", "sfzh必填");
splashScreenManager1.SetWaitFormDescription("請耐心等待...sfzh合法驗證中");
strSQL = "sfzh<>'' and sfzh is not null";
Check_SFZH_Islegal(pcheckSFZ_FtLy, strSQL, "sfzh_Check", "sfzh非法");
tlSProgressBar.Value = 0;
splashScreenManager1.CloseWaitForm();
MessageBox.Show("驗證完成!驗證結果儲存在欄位\"sfzh_Check\"中", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
/// <summary>
/// 驗證身份證合法性
/// </summary>
/// <param name="tempLayer"></param>
/// <param name="strSQL"></param>
/// <param name="strSaveFieldName"></param>
/// <param name="strDiscription"></param>
private void Check_SFZH_Islegal(IFeatureLayer tempLayer,string strSQL,string strSaveFieldName,string strDiscription)
{
ITable table = tempLayer.FeatureClass as ITable;
IQueryFilter pQueryFilter = (IQueryFilter)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("FDFEBD95-ED75-11D0-9A95-080009EC734B")));
//IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = strSQL;
// pQueryFilter.SubFields = caculFieldName;
ICursor cursor = table.Update(pQueryFilter, false);
ESRI.ArcGIS.Geodatabase.IRow Row = cursor.NextRow();
if (Row == null)
return;
int maxCount = table.RowCount(pQueryFilter);
tlSProgressBar.Minimum = 0;
tlSProgressBar.Maximum = maxCount;
int field = Row.Fields.FindField("sfzh");
int fieldSave = Row.Fields.FindField(strSaveFieldName);
for (int i = 0; i < maxCount; i++)
{
tlSProgressBar.Value = i;
string sfzh_Value = Row.Value[field].ToString();
//驗證
bool isRight=IDcardsNoVerifyCls.IDcards_isright(sfzh_Value);
//string strCheckBirthDay = Check_BirthDay_Islegal(sfzh_Value);
if (isRight==false)
{
string strCheckDiscrib=IDcardsNoVerifyCls.MyIDcards_isright(sfzh_Value);
if(strCheckDiscrib!="")
{
Row.Value[fieldSave] = strDiscription + " " + strCheckDiscrib;
}
else
{
Row.Value[fieldSave] = strDiscription;
}
//if (strCheckBirthDay!="")
//{
// Row.Value[fieldSave] = strDiscription + " " + strCheckBirthDay;
//}
//else
//{
// Row.Value[fieldSave] = strDiscription;
//}
cursor.UpdateRow(Row);
}
Row = cursor.NextRow();
}
}
private string Check_BirthDay_Islegal(string idNumber)
{
string birth = String.Empty;
if (idNumber.Length==18)
{
birth = idNumber.Substring(6, 8).Insert(6, "-").Insert(4, "-");
}
else if (idNumber.Length == 15)
{
birth = idNumber.Substring(6, 6).Insert(4, "-").Insert(2, "-");
}
DateTime time = new DateTime();
if (DateTime.TryParse(birth, out time) == false)
{
return "生日驗證失敗=" + birth;
//return false;//生日驗證
}
return "";
}
/// <summary>
/// 獲取待驗證身份證的圖層
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tspCombx_unck_SFZ_SelectedIndexChanged(object sender, EventArgs e)
{
if(tspCombx_unck_SFZ.SelectedIndex==-1)
{
return;
}
try
{
pcheckSFZ_FtLy = listFLayerZHQ_Check[tspCombx_unck_SFZ.SelectedIndex];
}
catch (System.Exception ex)
{
Console.WriteLine(ex.ToString());
}
int indexField= pcheckSFZ_FtLy.FeatureClass.FindField("sfzh");
if (indexField==-1)
{
MessageBox.Show("所選擇的圖層沒有\"sfzh\"欄位,請重新選擇!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
tspCombx_unck_SFZ.SelectedItem = null;
pcheckSFZ_FtLy = null;
}
}
private string StrSaveXMLPath = null;
private void MainForm_Load(object sender, EventArgs e)
{
//barButtonItem1.Enabled = false;
//barButtonItem3.Enabled = false;
//barButtonItem5.Enabled = false;
//barButtonItem6.Enabled = false;
//barButtonItem7.Enabled = false;
//barButtonItem8.Enabled = false;
int winWidth = Convert.ToInt32(XmlCls.ReadXml(StrSaveXMLPath, "winWidth"));
int winHeight= Convert.ToInt32(XmlCls.ReadXml(StrSaveXMLPath, "winHeight"));
this.Width = winWidth;
this.Height = winHeight;
this.Location = new System.Drawing.Point(Convert.ToInt32(XmlCls.ReadXml(StrSaveXMLPath, "LocationX")), Convert.ToInt32(XmlCls.ReadXml(StrSaveXMLPath, "LocationY")));
bool IsMaxShowMainForn= Convert.ToBoolean(XmlCls.ReadXml(StrSaveXMLPath, "IsMaxShowMainForn"));
if(IsMaxShowMainForn==true)
{
this.WindowState = FormWindowState.Maximized;
}
else if (IsMaxShowMainForn == false)
{
this.WindowState = FormWindowState.Normal;
}
bool isShowAll= Convert.ToBoolean(XmlCls.ReadXml(StrSaveXMLPath, "showAll"));
bool isNotShowAll = Convert.ToBoolean(XmlCls.ReadXml(StrSaveXMLPath, "NotshowAll"));
bool isShowZHQ_Only = Convert.ToBoolean(XmlCls.ReadXml(StrSaveXMLPath, "showZHQ_Only"));
if (isShowAll == true)
{
xtraTabPage1.PageVisible = true;
xtraTabPage2.PageVisible = true;
xtraTabPage3.PageVisible = true;
xtraTabPage4.PageVisible = true;
xtraTabPage5.PageVisible = true;
xtraTabControl1.Show();
}
else
{
if (isNotShowAll == true)
{
xtraTabPage1.PageVisible = false;
xtraTabPage2.PageVisible = false;
xtraTabPage3.PageVisible = false;
xtraTabPage4.PageVisible = false;
xtraTabPage5.PageVisible = false;
xtraTabControl1.Hide();
}
else
{
if (isShowZHQ_Only == true)
{
xtraTabPage1.PageVisible = true;
xtraTabPage2.PageVisible = false;
xtraTabPage3.PageVisible = false;
xtraTabPage4.PageVisible = false;
xtraTabPage5.PageVisible = false;
xtraTabControl1.Show();
}
else if (isShowZHQ_Only == false)
{
xtraTabPage1.PageVisible = false;
xtraTabPage2.PageVisible = false;
xtraTabPage3.PageVisible = false;
xtraTabPage4.PageVisible = false;
xtraTabPage5.PageVisible = false;
xtraTabControl1.Hide();
}
}
}
}
private void xtraTabControl1_SelectedPageChanged(object sender, DevExpress.XtraTab.TabPageChangedEventArgs e)
{
try
{
tlSpStLb.Text = " 選項:" + xtraTabControl1.SelectedTabPage.Text;
}
catch (System.Exception ex)
{
tlSpStLb.Text = "";
}
}
private void xtraTabControl1_CloseButtonClick(object sender, EventArgs e)
{
//xtraTabControl1.se
//xtraTabControl1.ShowHeaderFocus = DevExpress.Utils.DefaultBoolean.False;
//xtraTabControl1.SelectedTabPage.Hide();
//xtraTabControl1.SelectedTabPage.PageVisible = true;
//xtraTabControl1.SelectedTabPage.Dispose();
ClosePageButtonEventArgs arg=e as ClosePageButtonEventArgs;
(arg.Page as XtraTabPage).PageVisible = false;
if (xtraTabPage1.PageVisible == false&& xtraTabPage2.PageVisible == false&& xtraTabPage3.PageVisible == false && xtraTabPage4.PageVisible == false && xtraTabPage5.PageVisible == false)
{
xtraTabControl1.Hide();
}
}
private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
xtraTabControl1.Show();
xtraTabPage1.PageVisible = true;
xtraTabControl1.SelectedTabPage = xtraTabPage1;
}
private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
xtraTabControl1.Show();
xtraTabPage2.PageVisible = true;
xtraTabControl1.SelectedTabPage = xtraTabPage2;
}
private void barButtonItem5_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
xtraTabControl1.Show();
xtraTabPage3.PageVisible = true;
xtraTabControl1.SelectedTabPage = xtraTabPage3;
}
private void barButtonItem6_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
xtraTabControl1.Show();
xtraTabPage4.PageVisible = true;
xtraTabControl1.SelectedTabPage = xtraTabPage4;
}
private void barButtonItem7_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
xtraTabControl1.Show();
xtraTabPage5.PageVisible = true;
xtraTabControl1.SelectedTabPage = xtraTabPage5;
}
private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
xtraTabControl1.Show();
xtraTabPage1.PageVisible = true;
xtraTabPage2.PageVisible = true;
xtraTabPage3.PageVisible = true;
xtraTabPage4.PageVisible = true;
xtraTabPage5.PageVisible = true;
}
private void barButtonItem8_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
xtraTabPage1.PageVisible = false;
xtraTabPage2.PageVisible = false;
xtraTabPage3.PageVisible = false;
xtraTabPage4.PageVisible = false;
xtraTabPage5.PageVisible = false;
xtraTabControl1.Hide();
}
/// <summary>
/// 關於
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void barButtonItem9_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
FormAbout pFormAbout = new FormAbout();
pFormAbout.ShowDialog();
}
/// <summary>
/// 按錯誤條目統計
/// </summary>
/// <param name="culTempFtLy"></param>
/// <param name="strSQL"></param>
/// <returns></returns>
private int JCJGTJByTM_Func(IFeatureLayer culTempFtLy, string strSQL)
{
int defaultCount = 0;
ITable table = culTempFtLy.FeatureClass as ITable;
IQueryFilter pQueryFilter = (IQueryFilter)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("FDFEBD95-ED75-11D0-9A95-080009EC734B")));
//IQueryFilter pQueryFilter = new QueryFilter();
pQueryFilter.WhereClause = strSQL;
// pQueryFilter.SubFields = caculFieldName;
ICursor cursor = table.Update(pQueryFilter, false);
ESRI.ArcGIS.Geodatabase.IRow Row = cursor.NextRow();
if (Row == null)
return 0;
int fieldCheckResult = Row.Fields.FindField("CheckResult");
int maxCount = table.RowCount(pQueryFilter);
tlSProgressBar.Minimum = 0;
tlSProgressBar.Maximum = maxCount;
for (int i = 0; i < maxCount; i++)
{
tlSProgressBar.Value = i;
string strCheckResult = Row.Value[fieldCheckResult].ToString();
if (!String.IsNullOrEmpty(strCheckResult))
{
strCheckResult = strCheckResult.Replace("cjybz不能為空;","");
strCheckResult = strCheckResult.Replace("fhr不能為空;", "");
strCheckResult = strCheckResult.Replace("shr不能為空;", "");
if (strCheckResult!=";")
{
defaultCount++;
}
}
Row = cursor.NextRow();
}
return defaultCount;
}
/// <summary>
/// 轉換前檢查-檢查結果統計-按錯誤條目統計
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_unck_JCJGTJByTM_Click(object sender, EventArgs e)
{
if (listFLayerZHQ_Check == null)
{
MessageBox.Show("沒有資料可統計!請先開啟資料", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "(Excel檔案)|*.xlsx";
sfd.Title = "檢查結果統計-按錯誤條目統計結果";
sfd.FileName = System.IO.Path.GetFileNameWithoutExtension(strZHQSelGDBPath) + "_" + "按錯誤條目統計結果";
sfd.AddExtension = true;
if (sfd.ShowDialog() == DialogResult.OK)
{
string strSavePath = sfd.FileName;
try { File.Delete(strSavePath); }
catch {
MessageBox.Show("檔案存在並且被佔用","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
List<StaticByTM_ModelCls> listStaticTMS = new List<StaticByTM_ModelCls>();
splashScreenManager1.ShowWaitForm();
splashScreenManager1.SetWaitFormCaption("執行 檢查結果統計-按錯誤條目");
for (int i = 0; i < listFLayerZHQ_Check.Count; i++)
{
StaticByTM_ModelCls tempModel = new StaticByTM_ModelCls();
IFeatureLayer culTempFtLy = listFLayerZHQ_Check[i];
string strculFtLyName = culTempFtLy.FeatureClass.AliasName;
tempModel.strLX = strculFtLyName;
splashScreenManager1.SetWaitFormDescription("請耐心等待... 統計 " + strculFtLyName + " 中");
tempModel.countTMS = culTempFtLy.FeatureClass.FeatureCount(null);
listBox_unck_FtLy.SelectedValue = strculFtLyName;
listBox_unck_FtLy.Refresh();
int kk = culTempFtLy.FeatureClass.FindField("CheckResult");
if (kk != -1)
{
tempModel.countCWTMS = JCJGTJByTM_Func(culTempFtLy, null);
}
tempModel.BL = (Convert.ToDouble(tempModel.countCWTMS) / tempModel.countTMS).ToString("P2");
listStaticTMS.Add(tempModel);
}
StaticByTM_ModelCls tempModelTotal = new StaticByTM_ModelCls();
for (int i = 0; i < listStaticTMS.Count; i++)
{
tempModelTotal.countTMS += listStaticTMS[i].countTMS;
tempModelTotal.countCWTMS += listStaticTMS[i].countCWTMS;
}
tempModelTotal.strLX = "合計";
tempModelTotal.BL = (Convert.ToDouble(tempModelTotal.countCWTMS) / tempModelTotal.countTMS).ToString("P2");
listStaticTMS.Add(tempModelTotal);
//寫入Excel
using (var excel = new ExcelPackage(new FileInfo(strSavePath)))
{
//建立一個工作表
var ws = excel.Workbook.Worksheets.Add("Sheet1");
ws.Cells[1, 1].Value = "型別";
ws.Cells[1, 2].Value = "條目數";
ws.Cells[1, 3].Value = "屬性錯誤條目數";
ws.Cells[1, 4].Value = "錯誤比例";
for (int i = 0; i < listStaticTMS.Count; i++)
{
ws.Cells[i + 2, 1].Value = listStaticTMS[i].strLX;
ws.Cells[i + 2, 2].Value = listStaticTMS[i].countTMS;
ws.Cells[i + 2, 3].Value = listStaticTMS[i].countCWTMS;
ws.Cells[i + 2, 4].Value = listStaticTMS[i].BL;
}
ws.Cells.Style.VerticalAlignment = ExcelVerticalAlignment.Center;
ws.Cells.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
ws.Column(1).AutoFit();
ws.Column(2).AutoFit();
ws.Column(3).AutoFit();
ws.Column(4).AutoFit();
//儲存表格資訊
excel.Save();
}
splashScreenManager1.CloseWaitForm();
tlSProgressBar.Value = 0;
try
{
DialogResult dirlt = MessageBox.Show("處理完成,是否開啟?", "提示資訊", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (dirlt == DialogResult.OK)
{
Process.Start(strSavePath);
}
}
catch (System.Exception ex)
{}
}
}
/// <summary>
/// 系統設定
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Settings_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
FormSettings tempForm = new FormSettings();
tempForm.getSkinDel = getSkinDel;
tempForm.ShowDialog();
}
/// <summary>
/// 幫助文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_OpenHelpDoc_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
try
{
Process.Start(Directory.GetCurrentDirectory() + "\\幫助文件.pdf");
}
catch (System.Exception ex)
{
}
}
/// <summary>
/// 轉換前檢查項設定
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_CheckItemSet_Click(object sender, EventArgs e)
{
FormCheckSet formCheckSet = new FormCheckSet();
formCheckSet.ShowDialog();
}
private void tsBTN_TownManege_Click(object sender, EventArgs e)
{
FormTownSet formTownSet = new FormTownSet();
formTownSet.ShowDialog();
}
/// <summary>
/// 右鍵執行單獨檢查
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void listBox_unck_FtLy_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
int posindex = listBox_unck_FtLy.IndexFromPoint(new System.Drawing.Point(e.X, e.Y));
listBox_unck_FtLy.ContextMenuStrip = null;
if (posindex>=0&&posindex<listBox_unck_FtLy.Items.Count)
{
listBox_unck_FtLy.SelectedIndex = posindex;
contextMenuStrip1.Show(listBox_unck_FtLy, new System.Drawing.Point(e.X, e.Y));
}
}
}
IFeatureLayer culContextFtLy = null;
private void listBox_unck_FtLy_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
culContextFtLy = listFLayerZHQ_Check[listBox_unck_FtLy.SelectedIndex];
}
catch (System.Exception ex)
{
}
}
private void 單獨檢查該項ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (culContextFtLy==null)
{
return;
}
unck_ExcuteFunc(culContextFtLy, true);
}
private void ts_BTNCalcuSet_Click(object sender, EventArgs e)
{
}
}
歡迎交流:18798835893