//修改数据库中数据 public void EditSql(string data1, string data2) { try { AnalyseDataToArray(data1); GetDataTreeInitIndex dIndex = new GetDataTreeInitIndex(); string mypath = dIndex.GetDbInfo(); string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mypath + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False"; //生成连接数据库字符串 string strExp = string.Format("select ID from 数据编码表 where 业务大类代码='{0}' and 年度='{1}' and 业务小类代码='{2}'and 行政代码='{3}' and 比例尺='{4}' and 图层代码='{5}' and 数据源名称='6'", array[0], array[1], array[2], array[3], array[4], array[5], comboBoxSource.Text.Trim()); GeoDataCenterDbFun dDbFun = new GeoDataCenterDbFun(); int id1 = dDbFun.GetIDFromMdb(strCon, strExp); AnalyseDataToArray(data2); if (id1 != 0) { strExp = string.Format("update 数据编码表 set 业务大类代码='{0}',年度='{1}',业务小类代码='{2}',行政代码='{3}',比例尺='{4}',图层代码='{5}' where ID={6}", array[0], array[1], array[2], array[3], array[4], array[5], id1); } dDbFun.ExcuteSqlFromMdb(strCon, strExp); //更新数据编码表 dDbFun.UpdateMdbInfoTable(array[0], array[1], array[2], array[3], array[4]); //更新地图入库信息表 } catch (System.Exception e) { MessageBox.Show(e.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
//删除文档 private void btn_Del_Click(object sender, EventArgs e) { bool flag = false; GetDataTreeInitIndex dIndex = new GetDataTreeInitIndex(); string mypath = dIndex.GetDbInfo(); string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mypath + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False";//生成连接数据库字符串 GeoDataCenterDbFun db = new GeoDataCenterDbFun(); string strExp = "select 路径 from 文档数据源信息表 where 虚拟目录名='" + comboBoxCatalog.Text + "'"; string path = db.GetInfoFromMdbByExp(strCon, strExp); foreach (DataGridViewRow row in datagwSource.Rows) { if ((bool)row.Cells[0].EditedFormattedValue == true) { flag = true; } } if (!flag) { MessageBox.Show("没有选中行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } try { string cellvalue = ""; foreach (DataGridViewRow row in datagwSource.Rows) { if ((bool)row.Cells[0].EditedFormattedValue == true) { cellvalue = row.Cells[1].Value.ToString().Trim(); strExp = "select * from 文档入库信息表 where 文档名称='" + cellvalue + "' and 文档虚拟目录='" + comboBoxCatalog.Text + "'"; DataTable dt = db.GetDataTableFromMdb(strCon, strExp); string dir = path + "\\" + dt.Rows[0]["年度"] + dt.Rows[0]["专题类型"] + dt.Rows[0]["行政代码"] + "\\" + cellvalue + "." + dt.Rows[0]["文档类型"]; if (File.Exists(dir)) { File.Delete(dir); dir = dir.Substring(0, dir.LastIndexOf("\\")); if (Directory.GetFiles(dir).Length == 0)//如果该目录中没有其他文档,则删除该目录 { Directory.Delete(dir); } strExp = "delete * from 文档入库信息表 where 文档名称='" + cellvalue + "' and 文档虚拟目录='" + comboBoxCatalog.Text + "'"; db.ExcuteSqlFromMdb(strCon, strExp); } } } datagwSource.Rows.Clear(); LoadGridView();//重新加载数据 MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
//删除数据库中数据 public void DeleteSql(string data) { try { AnalyseDataToArray(data); GetDataTreeInitIndex dIndex = new GetDataTreeInitIndex(); string mypath = dIndex.GetDbInfo(); string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mypath + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False"; //生成连接数据库字符串 string strExp = string.Format("delete from 数据编码表 where 业务大类代码='{0}' and 年度='{1}' and 业务小类代码='{2}'and 行政代码='{3}' and 比例尺='{4}' and 图层代码='{5}' and 数据源名称='{6}'", array[0], array[1], array[2], array[3], array[4], array[5], comboBoxSource.Text.Trim()); GeoDataCenterDbFun dDbFun = new GeoDataCenterDbFun(); dDbFun.ExcuteSqlFromMdb(strCon, strExp); //从数据编码表更新入库信息表 dDbFun.UpdateMdbInfoTable(array[0], array[1], array[2], array[3], array[4]); //从代码更新入库信息表 #region //strExp = "select 图层组成 from 地图入库信息表 where 业务大类代码='" + array[0] + "' And 行政代码 ='" + array[3] + "' And 年度='" + // array[1] + "'And 比例尺='" + array[4] + "'And 业务小类代码='" + array[2] + "'"; //string layers = dDbFun.GetInfoFromMdbByExp(strCon, strExp); //if (!layers.Contains('/'.ToString())) //{ // if (layers.Trim() != array[5]) // return; // else // layers = ""; //} //else //{ // string[] layer = layers.Split('/'); // for (int i = 0; i < layer.Length; i++) // { // if (layer[i].Trim() == array[5]) // { // if (i == 0) // { // layers = layers.Substring(array[5].Length + 1); // } // else // layers = layers.Replace('/' + layer[i], ""); // } // } //} //strExp = "update 地图入库信息表 set 图层组成='" + layers + "' where 业务大类代码='" + array[0] + "' And 行政代码 ='" + array[3] + "' And 年度='" + // array[1] + "'And 比例尺='" + array[4] + "'And 业务小类代码='" + array[2] + "'"; //dDbFun.ExcuteSqlFromMdb(strCon, strExp); #endregion } catch (System.Exception e) { // MessageBox.Show(e.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
// private void btnApply_Click(object sender, EventArgs e) { frmDataUpload frm = new frmDataUpload(); if (textBoxDescri.Text.Trim() == "") { MessageBox.Show("图层描述不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } GetDataTreeInitIndex dIndex = new GetDataTreeInitIndex(); string strExp = ""; string mypath = dIndex.GetDbInfo(); string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mypath + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False";//生成连接数据库字符串 GeoDataCenterDbFun db = new GeoDataCenterDbFun(); strExp = string.Format("insert into 标准图层信息表(代码,描述,业务大类代码,业务小类代码) values('{0}','{1}','{2}','{3}')", comboBoxCode.Text, textBoxDescri.Text, GetCode(comboBoxBig.Text), GetCode(comboBoxSub.Text)); db.ExcuteSqlFromMdb(strCon, strExp); comboBoxCode.Items.Remove(comboBoxCode.Text); if (comboBoxCode.Items.Count == 0) { comboBoxCode.Text = ""; btnApply.Enabled = false; } else { comboBoxCode.SelectedIndex = 0; } textBoxDescri.Text = ""; foreach (ListViewItem item in m_listview.Items) { string strName = item.SubItems[1].Text; if (strName.Length > 15) { string strforward = strName.Substring(0, 15); strName = strName.Substring(15); item.SubItems[1].Text = frm.GetForwadName(strforward, strName); } string strdescri = GetDescrib(strName); if (strdescri.Trim() != "") { item.SubItems[2].Text = strdescri; } else { item.SubItems[2].Text = "需要新增"; } } m_listview.Refresh(); }
//删除数据源 private void btnDel_Click(object sender, EventArgs e) { try { if (!ComBoxName.Items.Contains(ComBoxName.Text)) { MessageBox.Show("虚拟目录名不存在,无法删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!GetVirtualDirectory(constIISWebSiteRoot, ComBoxName.Text)) { MessageBox.Show("虚拟目录名不存在,无法删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } GetDataTreeInitIndex dIndex = new GetDataTreeInitIndex(); string mypath = dIndex.GetDbInfo(); string strExp = ""; string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mypath + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False"; //生成连接数据 strExp = "delete * from 文档数据源信息表 where 虚拟目录名='" + ComBoxName.Text + "'"; GeoDataCenterDbFun db = new GeoDataCenterDbFun(); db.ExcuteSqlFromMdb(strCon, strExp); strExp = "delete * from 文档入库信息表 where 文档虚拟目录='" + ComBoxName.Text + "'"; db.ExcuteSqlFromMdb(strCon, strExp); DirectoryEntry deRoot = new DirectoryEntry(constIISWebSiteRoot); deRoot.RefreshCache(); DirectoryEntry Dirport = deRoot.Children.Find(ComBoxName.Text, "IIsWebVirtualDir"); //deRoot.Invoke("AppDelete", true); deRoot.Children.Remove(Dirport); deRoot.CommitChanges(); deRoot.Close(); ComBoxName.Items.Remove(ComBoxName.Text); MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void btnOK_Click(object sender, EventArgs e) { try { string strtype = ""; string stryear = ""; string strareaname = ""; string strscale = ""; string sourepath = ""; for (int i = 0; i < dataGridView.Rows.Count; i++) { sourepath = dataGridView.Rows[i].Cells["Column5"].Value.ToString();//数据源 if (sourepath == "") { continue; } strtype = dataGridView.Rows[i].Cells["Column1"].Value.ToString(); //专题类型 stryear = dataGridView.Rows[i].Cells["Column2"].Value.ToString(); //年度 strareaname = dataGridView.Rows[i].Cells["Column4"].Value.ToString(); //行政单元 strscale = dataGridView.Rows[i].Cells["Column7"].Value.ToString(); //比例尺 if (index == 0) { GetDataTreeInitIndex dIndex = new GetDataTreeInitIndex(); string mypath = dIndex.GetDbInfo(); string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mypath + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False"; //生成连接数据库字符串 string strExp = string.Format("update 地图入库信息表 set 影像库='{0}' where 专题类型='{1}' and 年度='{2}' and 行政名称='{3}' and 比例尺='{4}' ", sourepath, strtype, stryear, strareaname, strscale); GeoDataCenterDbFun db = new GeoDataCenterDbFun(); db.ExcuteSqlFromMdb(strCon, strExp); } else { GetDataTreeInitIndex dIndex = new GetDataTreeInitIndex(); string mypath = dIndex.GetDbInfo(); string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mypath + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False"; //生成连接数据库字符串 string strExp = string.Format("update 地图入库信息表 set 文档库='{0}' where 专题类型='{1}' and 年度='{2}' and 行政名称='{3}' and 比例尺='{4}' ", sourepath, strtype, stryear, strareaname, strscale); GeoDataCenterDbFun db = new GeoDataCenterDbFun(); db.ExcuteSqlFromMdb(strCon, strExp); } } MessageBox.Show("信息已保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ee) { MessageBox.Show(ee.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void btnOK_Click(object sender, EventArgs e) { if (comboBoxCode.Text.Trim() != "") { if (textBoxDescri.Text.Trim() == "") { MessageBox.Show("图层描述不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } GetDataTreeInitIndex dIndex = new GetDataTreeInitIndex(); string strExp = ""; string mypath = dIndex.GetDbInfo(); string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mypath + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False";//生成连接数据库字符串 GeoDataCenterDbFun db = new GeoDataCenterDbFun(); strExp = string.Format("insert into 标准图层信息表(代码,描述,业务大类代码,业务小类代码) values('{0}','{1}','{2}','{3}')", comboBoxCode.Text, textBoxDescri.Text, GetCode(comboBoxBig.Text), GetCode(comboBoxSub.Text)); db.ExcuteSqlFromMdb(strCon, strExp); } this.DialogResult = DialogResult.OK; this.Hide(); this.Dispose(true); }
private void btn_OK_Click(object sender, EventArgs e) { try { GetDataTreeInitIndex dIndex = new GetDataTreeInitIndex(); string mypath = dIndex.GetDbInfo(); string strExp = ""; string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mypath + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False"; //生成连接数据 if (ComBoxName.Text != "" && textBoxDatasouce.Text != "") { //if (ComBoxName.Items.Contains(ComBoxName.Text)) //{ // MessageBox.Show("虚拟目录名已存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; //} string virtualDirName = ComBoxName.Text;//虚拟目录名称 string physicalPath = @textBoxDatasouce.Text; DirectoryEntry root = new DirectoryEntry(constIISWebSiteRoot); if (GetVirtualDirectory(constIISWebSiteRoot, ComBoxName.Text)) { foreach (DirectoryEntry tmpDir in root.Children) { if (virtualDirName == tmpDir.Name) { tmpDir.Properties["Path"][0] = physicalPath; tmpDir.Invoke("AppCreate", true); tmpDir.Properties["AccessRead"][0] = true; tmpDir.Properties["AccessWrite"][0] = true; tmpDir.Properties["AccessExecute"][0] = true; //tbEntry.Properties["Access"] tmpDir.Properties["ContentIndexed"][0] = true;; tmpDir.Properties["DefaultDoc"][0] = ""; tmpDir.Properties["AppFriendlyName"][0] = virtualDirName; tmpDir.Properties["AccessScript"][0] = true; tmpDir.Properties["DontLog"][0] = true; // tbEntry.Properties["AuthFlags"][0] = 0; tmpDir.Properties["AuthFlags"][0] = 1; //tbEntry.Properties["DirBrower"] tmpDir.CommitChanges(); } } } else { DirectoryEntry tbEntry = root.Children.Add(virtualDirName, root.SchemaClassName); tbEntry.Properties["Path"][0] = physicalPath; tbEntry.Invoke("AppCreate", true); tbEntry.Properties["AccessRead"][0] = true; tbEntry.Properties["AccessWrite"][0] = true; tbEntry.Properties["AccessExecute"][0] = true; //tbEntry.Properties["Access"] tbEntry.Properties["ContentIndexed"][0] = true;; tbEntry.Properties["DefaultDoc"][0] = ""; tbEntry.Properties["AppFriendlyName"][0] = virtualDirName; tbEntry.Properties["AccessScript"][0] = true; tbEntry.Properties["DontLog"][0] = true; // tbEntry.Properties["AuthFlags"][0] = 0; tbEntry.Properties["AuthFlags"][0] = 1; //tbEntry.Properties["DirBrower"] tbEntry.CommitChanges(); } strExp = "insert into 文档数据源信息表 values('" + ComBoxName.Text + "','" + physicalPath + "')"; } if (strExp != "") { GeoDataCenterDbFun db = new GeoDataCenterDbFun(); db.ExcuteSqlFromMdb(strCon, strExp); MessageBox.Show("创建成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("各项不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void btnOK_Click(object sender, EventArgs e) { string physicdir = ""; string strExp; GetDataTreeInitIndex dIndex = new GetDataTreeInitIndex(); string mypath = dIndex.GetDbInfo(); string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mypath + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False";//生成连接数据 GeoDataCenterDbFun db = new GeoDataCenterDbFun(); if (comboBoxScale.Text == "" || comboBoxArea.Text == "" || comboBoxYear.Text == "" || comboBoxType.Text == "") { MessageBox.Show("各选项不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string strscale = GetCode(comboBoxScale.Text); //获得比例尺代码 string strType = GetCode(comboBoxType.Text); //获得专题类型 string strArea = GetCode(comboBoxArea.Text); //获得区域代码 string strAreaname = comboBoxArea.Text.Substring(0, comboBoxArea.Text.LastIndexOf('(')); //获得区域名称 //年度 专题 行政区代码 要按照规则替换 string dir = comboBoxYear.Text + strType + strArea; if (m_soucedir != comboBoxSource.Text) { strExp = "select 路径 from 文档数据源信息表 where 虚拟目录名='" + comboBoxSource.Text + "'"; physicdir = db.GetInfoFromMdbByExp(strCon, strExp) + @"\" + dir;//路径 } else { physicdir = comboBoxSource.Text + @"\" + dir;//路径 } if (!Directory.Exists(physicdir)) { Directory.CreateDirectory(physicdir); } foreach (ListViewItem item in listViewDoc.Items) { try { //string[] str = item.Text.Split('.'); string strfile = item.Text.Substring(item.Text.LastIndexOf("\\") + 1); string[] strBuffer = strfile.Split('.'); string strFileName = strBuffer[0].ToString(); string strFileType = strBuffer[1].ToString(); if (item.Checked && item.SubItems[1].Text == "等待入库") { item.SubItems[1].Text = "正在入库"; listViewDoc.Refresh(); if (File.Exists(item.Text)) { File.Copy(item.Text, physicdir + "\\" + strfile, true); } strExp = string.Format("insert into 文档入库信息表 (行政代码,行政名称,年度,比例尺,专题类型,文档名称,文档类型,文档虚拟目录,处理) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')", strArea, strAreaname, comboBoxYear.Text, strscale, strType, strFileName, strFileType, comboBoxSource.Text, comboBoxOpen.SelectedIndex.ToString()); db.ExcuteSqlFromMdb(strCon, strExp); item.SubItems[1].Text = "入库完成"; } } catch (Exception ex) { MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); item.SubItems[1].Text = "入库失败"; } } MessageBox.Show("操作已完成", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }
//写入数据编码表和地图入库信息表的方法 public bool InsertIntoDatabase(string filename) { bool success; try { if (filename.Contains(".")) { filename = filename.Substring(filename.LastIndexOf(".") + 1);//针对SDE } if (filename.Length > 16) { GetDataTreeInitIndex dIndex = new GetDataTreeInitIndex(); string mypath = dIndex.GetDbInfo(); string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mypath + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False";//生成连接数据库字符串 string strExp = "select 字段名称 from 图层命名规则表"; GeoDataCenterDbFun db = new GeoDataCenterDbFun(); string strname = db.GetInfoFromMdbByExp(strCon, strExp); string[] arrName = strname.Split('+');//分离字段名称 for (int i = 0; i < arrName.Length; i++) { switch (arrName[i]) { case "业务大类代码": array[0] = filename.Substring(0, 2); //业务大类代码 filename = filename.Remove(0, 2); break; case "年度": array[1] = filename.Substring(0, 4); //年度 filename = filename.Remove(0, 4); break; case "业务小类代码": array[2] = filename.Substring(0, 2); //专题 filename = filename.Remove(0, 2); break; case "行政代码": array[3] = filename.Substring(0, 6); //行政代码 filename = filename.Remove(0, 6); break; case "比例尺": array[4] = filename.Substring(0, 1); //比例尺 filename = filename.Remove(0, 1); break; } } array[5] = filename;//图层组成 string sourcename = comboBoxSource.Text.Trim(); strExp = string.Format("select count(*) from 数据编码表 where 业务大类代码='{0}' and 年度='{1}' and 业务小类代码='{2}'and 行政代码='{3}' and 比例尺='{4}' and 图层代码='{5}' and 数据源名称='{6}'", array[0], array[1], array[2], array[3], array[4], array[5], sourcename); GeoDataCenterDbFun dDbFun = new GeoDataCenterDbFun(); int count = dDbFun.GetCountFromMdb(strCon, strExp); if (count != 1) { strExp = string.Format("insert into 数据编码表(业务大类代码,年度,业务小类代码,行政代码,比例尺,图层代码,数据源名称) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", array[0], array[1], array[2], array[3], array[4], array[5], sourcename); dDbFun.ExcuteSqlFromMdb(strCon, strExp); //更新数据编码表 dDbFun.UpdateMdbInfoTable(array[0], array[1], array[2], array[3], array[4]); //更新地图入库信息表 } success = true; } else { m_strErr = "命名不规则,写入数据表失败"; success = false; } } catch (System.Exception e) { MessageBox.Show(e.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); success = false; } return(success); }
//开始分析 private void btn_Analys_Click(object sender, EventArgs e) { SysCommon.CProgress vProgress = new SysCommon.CProgress("开始分析数据"); vProgress.EnableCancel = false; vProgress.ShowDescription = true; vProgress.FakeProgress = true; vProgress.TopMost = true; vProgress.ShowProgress(); try { string strArea = ""; string strArea2 = ""; List <string> strAreaChild = new List <string>(); string strYear = ""; string strScale = ""; string strScale2 = ""; string strExp = ""; bool flat = false; //选了比例尺与否的状态 int index = 0; int ifinish = 0; //显示分析了多少条数据 GeoDataCenterDbFun dbfun = new GeoDataCenterDbFun(); m_list.Clear(); //选择框的8种状态 #region if (comboBoxScale.Text != "" && comboBoxYear.Text != "" && comboBoxArea.Text != "") { index = 1; } else if (comboBoxArea.Text != "" && comboBoxYear.Text != "") { index = 2; } else if (comboBoxArea.Text != "" && comboBoxScale.Text != "") { index = 3; } else if (comboBoxYear.Text != "" && comboBoxScale.Text != "") { index = 4; } else if (comboBoxArea.Text != "") { index = 5; } else if (comboBoxYear.Text != "") { index = 6; } else if (comboBoxScale.Text != "") { index = 7; } else { index = 0; } #endregion if (Node != null && comboBoxArea.Text != "") { string[] arrr = comboBoxArea.Text.Split('(', ')'); strArea2 = arrr[1]; //得到所有该行政区的辖区 switch (Convert.ToInt32(Node.Tag)) { case 1: strArea = "行政代码 like '" + strArea2.Substring(0, 3).Trim() + "*' and "; strExp = "select 行政代码 from 数据单元表 where 行政代码 like '" + strArea2.Substring(0, 3).Trim() + "*'"; break; case 2: strArea = "行政代码 like '" + strArea2.Substring(0, 4).Trim() + "*' and"; strExp = "select 行政代码 from 数据单元表 where 行政代码 like '" + strArea2.Substring(0, 4).Trim() + "*'"; break; case 3: strArea = "行政代码='" + strArea2 + "' and "; strExp = "select 行政代码 from 数据单元表 where 行政代码 = '" + strArea2 + "*'"; break; } strAreaChild = dbfun.GetDataReaderFromMdb(m_con, strExp); } if (comboBoxYear.Text != "") { strYear = "年度='" + comboBoxYear.Text + "' and "; } if (comboBoxScale.Text != "") { string [] arrr = comboBoxScale.Text.Split('(', ')'); strScale2 = arrr[1]; strScale = "比例尺='" + strScale2 + "' and "; //flat = true; } //else // flat = false; //if (flat)//选了比例尺,不用去掉and // strExp = "select ID from 数据编码表 where " + strArea + strYear + strScale + " and 数据源名称='" + GetSourceName(m_path) + "'"; //else if (comboBoxYear.Text != "" ||comboBoxArea.Text != "")//比例尺没有选择,而年度或者行政区划选了,要去掉and //{ //strExp = "select ID from 数据编码表 where " + strArea + strYear + " 数据源名称='" + GetSourceName(m_path) + "'"; //} //else//都没有选择 // strExp = "select ID from 数据编码表 where 数据源名称='" + GetSourceName(m_path) + "'"; strExp = "select ID from 数据编码表 where " + strArea + strYear + strScale + " 数据源名称='" + comboBoxSource.Text.Trim() + "'"; List <string> list = new List <string>(); list = dbfun.GetDataReaderFromMdb(m_con, strExp); // m_path = GetSourcePath(comboBoxSource.Text); for (int i = 0; i < list.Count; i++) { strExp = "delete * from 数据编码表 where ID=" + Convert.ToInt32(list[i]); dbfun.ExcuteSqlFromMdb(m_con, strExp);//从数据编码表删除符合ID条件的行 } m_list = new List <string>(); IWorkspace pWorkspace = GetWorkspace(comboBoxSource.Text); //遍历数据库中数据并存在m_list列表中 if (pWorkspace != null) { IEnumDataset enumDataset = pWorkspace.get_Datasets(esriDatasetType.esriDTFeatureClass) as IEnumDataset; IDataset dataset = enumDataset.Next(); //遍历mdb的每一个独立要素类 while (dataset != null) { IFeatureClass pFeatureClass = dataset as IFeatureClass; m_list.Add(pFeatureClass.AliasName); dataset = enumDataset.Next(); } } else { vProgress.Close(); MessageBox.Show("数据源空间不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Activate(); return; } //从m_list中读取数据并分析 string[] array = new string[6]; bool boolarea = false; for (int i = 0; i < m_list.Count; i++) { flat = false; if (m_list[i].Contains(".")) { m_list[i] = m_list[i].Substring(m_list[i].LastIndexOf(".") + 1); } strExp = "select 字段名称 from 图层命名规则表"; string strname = dbfun.GetInfoFromMdbByExp(m_con, strExp); string[] arrName = strname.Split('+');//分离字段名称 for (int ii = 0; ii < arrName.Length; ii++) { switch (arrName[ii]) { case "业务大类代码": array[0] = m_list[i].Substring(0, 2); //业务大类代码 m_list[i] = m_list[i].Remove(0, 2); break; case "年度": array[1] = m_list[i].Substring(0, 4); //年度 m_list[i] = m_list[i].Remove(0, 4); break; case "业务小类代码": array[2] = m_list[i].Substring(0, 2); //业务小类代码 m_list[i] = m_list[i].Remove(0, 2); break; case "行政代码": array[3] = m_list[i].Substring(0, 6); //行政代码 m_list[i] = m_list[i].Remove(0, 6); break; case "比例尺": array[4] = m_list[i].Substring(0, 1); //比例尺 m_list[i] = m_list[i].Remove(0, 1); break; } } array[5] = m_list[i]; //图层组成 for (int j = 0; j < strAreaChild.Count; j++) //判断是否包含该行政区的辖区 { if (strAreaChild[j] == array[3]) { boolarea = true; break; } } //判断情况条件是否符合 #region switch (index) { case 0: flat = true; break; case 1: if (array[1] == comboBoxYear.Text && array[4] == strScale2 && boolarea) { flat = true; } break; case 2: if (boolarea && array[1] == comboBoxYear.Text) { flat = true; } break; case 3: if (boolarea && array[4] == strScale2) { flat = true; } break; case 4: if (array[1] == comboBoxYear.Text && array[4] == strScale2) { flat = true; } break; case 5: if (boolarea) { flat = true; } break; case 6: if (array[1] == comboBoxYear.Text) { flat = true; } break; case 7: if (array[4] == strScale2) { flat = true; } break; } #endregion string sourecename = comboBoxSource.Text.Trim(); if (flat) { ifinish++; strExp = string.Format("insert into 数据编码表(业务大类代码,年度,业务小类代码,行政代码,比例尺,图层代码,数据源名称) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", array[0], array[1], array[2], array[3], array[4], array[5], sourecename); string strdata = GetLayerName(array[0], array[1], array[2], array[3], array[4]) + array[5];//组织数据 string logpath = Application.StartupPath + "\\..\\Log\\DataManagerLog.txt"; LogFile log = new LogFile(null, logpath); string strLog = "开始分析数据源" + sourecename + "中" + strdata + "数据"; if (log != null) { log.Writelog(strLog); } vProgress.SetProgress(strLog); dbfun.ExcuteSqlFromMdb(m_con, strExp); //更新数据编码表 dbfun.UpdateMdbInfoTable(array[0], array[1], array[2], array[3], array[4]); //更新地图入库信息表 } } ifinish = list.Count >= ifinish ? list.Count : ifinish; vProgress.Close(); this.Activate(); if (ifinish == 0) { MessageBox.Show("没有符合条件的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("分析完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.Close(); } //重新编号 //strExp = "alter table 数据编码表 alter column ID counter(1,1)"; // dbfun.ExcuteSqlFromMdb(m_con,strExp); catch (System.Exception ex) { vProgress.Close(); MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }