//删除数据源 private void btnDel_Click(object sender, EventArgs e) { GeoDataCenterDbFun db = new GeoDataCenterDbFun(); try { if (comboBoxDsName.Text == "") { MessageBox.Show("数据源名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string mypath = m_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 count(*) from 物理数据源表 where 数据源名称=‘" + comboBoxDsName.Text + "’ "; //int i = db.GetCountFromMdb(strCon, strExp); //if (i == 0) //{ // MessageBox.Show("数据源不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; //} string strExp = "delete from 物理数据源表 where 数据源名称='" + comboBoxDsName.Text + "'"; db.ExcuteSqlFromMdb(strCon, strExp); strExp = "delete from 数据编码表 where 数据源名称='" + comboBoxDsName.Text + "'";//added by yjl remove noexist source data db.ExcuteSqlFromMdb(strCon, strExp); strExp = "delete from 逻辑数据源表 where 数据源名称='" + comboBoxDsName.Text + "'"; InitializeComDSname(); 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 Tambole = ""; strfildname = ""; string type; //字段类型 string Length; //字段长度 string strregex = ""; //表达式 string strName = ""; //字段名称 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 = ""; foreach (ListViewItem item in listView.Items) { type = item.SubItems[2].Text; Length = item.SubItems[3].Text; strName = item.Text; switch (strName) { case "业务大类代码": strregex += "(^[A-Z]{" + Length + "}$)"; break; case "年度": strregex += "(^20[0-9]{2}$)"; break; case "业务小类代码": strregex += "(^[0-9]{" + Length + "}$)"; break; case "行政代码": int ln = (Convert.ToInt32(Length)) - 1; strregex += "(^[1-9][0-9]{" + ln + "}$)"; break; case "比例尺": strregex += "(^[B-I]{" + Length + "}$)"; break; } strfildname += item.Text + "+"; Tambole += item.SubItems[4].Text; int index = item.Index + 1; strExp = "update 图层命名初始化表 set 排序='" + index + "' where 字段名称='" + item.Text + "'"; db.ExcuteSqlFromMdb(strCon, strExp); } strfildname = strfildname.Substring(0, strfildname.LastIndexOf("+")); strExp = "delete * from 图层命名规则表"; db.ExcuteSqlFromMdb(strCon, strExp); strExp = "insert into 图层命名规则表(命名规则,示例,字段名称) values('" + strregex + "','" + Tambole + "','" + strfildname + "')"; db.ExcuteSqlFromMdb(strCon, strExp); MessageBox.Show("命名规则已改", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }
//删除专题 private void MenuItemDelSub_Click(object sender, EventArgs e) { if (listViewControl.SelectedItems.Count <= 0) { MessageBox.Show("请选择要删除的专题!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string strTip = "确定删除【" + listViewControl.SelectedItems[0].SubItems[1].Text + "】"; if (MessageBox.Show(strTip, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) { return; } //获取数值添加到“标准专题信息表”中 string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + m_mypath + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False"; //生成连接数据库字符串 OleDbConnection mycon = new OleDbConnection(constr); //定义OleDbConnection对象实例并连接数据库 string strExp = ""; strExp = "delete from 标准专题信息表 where 专题类型 = '" + listViewControl.SelectedItems[0].Text + "'"; OleDbCommand aCommand = new OleDbCommand(strExp, mycon); try { mycon.Open(); //删除记录 int iRows = aCommand.ExecuteNonQuery(); //关闭连接,这很重要 mycon.Close(); } catch (System.Exception err) { Console.WriteLine(err.Message); } strExp = "delete from 地图入库信息表 where 专题类型 = '" + listViewControl.SelectedItems[0].Text + "'"; GeoDataCenterDbFun db = new GeoDataCenterDbFun(); db.ExcuteSqlFromMdb(constr, strExp); //删除脚本文件 string strIndexFile = Application.StartupPath + "\\..\\Template\\" + listViewControl.SelectedItems[0].SubItems[2].Text; if (File.Exists(strIndexFile)) { File.Delete(strIndexFile); } //删除listview listViewControl.Items.Remove(listViewControl.SelectedItems[0]); treeViewControl.Nodes.Clear(); }
//生成正则表达式 private void btnGet_Click(object sender, EventArgs e) { textBoxExp.Text = ""; textBoxExample.Text = ""; strfildname = ""; string type; //字段类型 string Length; //字段长度 string strregex = ""; //表达式 string strName = ""; //字段名称 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 = ""; foreach (ListViewItem item in listView.Items) { type = item.SubItems[2].Text; Length = item.SubItems[3].Text; strName = item.Text; switch (strName) { case "业务大类代码": strregex += "(^[A-Z]{" + Length + "}$)"; break; case "年度": strregex += "(^20[0-9]{2}$)"; break; case "业务小类代码": strregex += "(^[0-9]{" + Length + "}$)"; break; case "行政代码": int ln = (Convert.ToInt32(Length)) - 1; strregex += "(^[1-9][0-9]{" + ln + "}$)"; break; case "比例尺": strregex += "(^[B-I]{" + Length + "}$)"; break; } strfildname += item.Text + "+"; textBoxExample.Text += item.SubItems[4].Text; int index = item.Index + 1; strExp = "update 图层命名初始化表 set 排序='" + index + "' where 字段名称='" + item.Text + "'"; db.ExcuteSqlFromMdb(strCon, strExp); } textBoxExp.Text = strregex; strfildname = strfildname.Substring(0, strfildname.LastIndexOf("+")); }
//取消关键图层 private void MenuItemCanceMainLayer_Click(object sender, EventArgs e) { if (treeViewControl.SelectedNode.ForeColor.Equals(Color.Red)) { treeViewControl.SelectedNode.ForeColor = Color.Black; string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + m_mypath + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False"; //生成连接数据库字符串 string strExp = ""; GeoDataCenterDbFun db = new GeoDataCenterDbFun(); strExp = "update 标准专题信息表 set 关键图层='' where 专题类型='" + m_Typecode + "'"; db.ExcuteSqlFromMdb(constr, strExp); } MenuItemCanceMainLayer.Enabled = true; treeViewControl.Refresh(); }
private void btnDel_Click(object sender, EventArgs e) { if (comboBoxDsName.Text == "") { MessageBox.Show("数据源为空,无法删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string mypath = m_dIndex.GetDbInfo(); string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mypath + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False"; //生成连接数据库字符串 string strExp = "delete * from 逻辑数据源表 where 行政代码='" + comboBoxAreaCode.Text + "' and 数据源名称='" + comboBoxDsName.Text + "'"; GeoDataCenterDbFun db = new GeoDataCenterDbFun(); db.ExcuteSqlFromMdb(strCon, strExp); MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void btnOK_Click(object sender, EventArgs e) { if (comBoxName.Text == "") { MessageBox.Show("字段名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (textBoxDefault.Text == "") { MessageBox.Show("缺省值不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } 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; if (m_flag == 1) { strExp = "select max(排序) from 图层命名初始化表"; int index = Convert.ToInt32(db.GetInfoFromMdbByExp(strCon, strExp)) + 1; strExp = string.Format("insert into 图层命名初始化表(字段名称,描述,字段类型,字段长度,缺省,可变,排序) values('{0}','{1}','{2}','{3}','{4}',{5},'{6}')", comBoxName.Text, textBoxDescribe.Text, comboBoxType.Text, textBoxLength.Text, textBoxDefault.Text, checkBoxChange.Checked, index.ToString()); db.ExcuteSqlFromMdb(strCon, strExp); MessageBox.Show("添加字段成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { strExp = string.Format("update 图层命名初始化表 set 字段名称='{0}',描述='{1}',字段类型='{2}',字段长度='{3}',缺省='{4}',可变={5} where ID={6}", comBoxName.Text, textBoxDescribe.Text, comboBoxType.Text, textBoxLength.Text, textBoxDefault.Text, checkBoxChange.Checked, id); db.ExcuteSqlFromMdb(strCon, strExp); MessageBox.Show("编辑字段成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.Close(); }
private void ChangeIndex() { 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 = ""; foreach (ListViewItem item in listView.Items) { int index = item.Index + 1; strExp = "update 图层命名初始化表 set 排序='" + index + "' where 字段名称='" + item.Text + "'"; db.ExcuteSqlFromMdb(strCon, strExp); } }
//更新标准图层信息表 private void UpdateLayersInfo() { string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + m_mypath + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False"; //生成连接数据库字符串 string strExp = ""; GeoDataCenterDbFun db = new GeoDataCenterDbFun(); string layer = ""; string strSearchRoot = "//Layer"; XmlNodeList xmlNodelist = m_xmldoc.SelectNodes(strSearchRoot); foreach (XmlNode node in xmlNodelist) { XmlElement xmlelment = node as XmlElement; layer += xmlelment.GetAttribute("sFile") + "/"; } if (layer.Contains("/")) { layer = layer.Substring(0, layer.LastIndexOf("/")); } strExp = "update 标准专题信息表 set 图层组成='" + layer + "' where 专题类型='" + m_Typecode + "'"; db.ExcuteSqlFromMdb(constr, strExp); }
//设置成关键图层 private void MenuItemMainLayer_Click(object sender, EventArgs e) { string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + m_mypath + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False"; //生成连接数据库字符串 string strExp = ""; GeoDataCenterDbFun db = new GeoDataCenterDbFun(); string layer = ""; // strExp = "select 关键图层 from 标准专题信息表 where 专题类型='" + m_Typecode + "'"; //string Mainlayer = db.GetInfoFromMdbByExp(constr, strExp); layer = treeViewControl.SelectedNode.Name; strExp = "select 代码 from 标准图层信息表 where 描述 ='" + layer + "'"; layer = db.GetInfoFromMdbByExp(constr, strExp); strExp = "update 标准专题信息表 set 关键图层='" + layer + "' where 专题类型='" + m_Typecode + "'"; db.ExcuteSqlFromMdb(constr, strExp); ChangeColor(); treeViewControl.SelectedNode.ForeColor = Color.Red; MenuItemCanceMainLayer.Enabled = true; treeViewControl.ExpandAll(); treeViewControl.Refresh(); }
private void btnNew_Click(object sender, EventArgs e) { if (comboBoxDsName.Text == "") { MessageBox.Show("请先配置物理数据源", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string mypath = m_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 count(*) from 逻辑数据源表 where 行政代码='" + comboBoxAreaCode.Text + "' and 数据源名称='" + comboBoxDsName.Text + "'"; GeoDataCenterDbFun db = new GeoDataCenterDbFun(); int i = db.GetCountFromMdb(strCon, strExp); if (i != 0) { MessageBox.Show("数据源已配置", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } strExp = "insert into 逻辑数据源表(行政代码,数据源名称) values('" + comboBoxAreaCode.Text + "','" + comboBoxDsName.Text + "')"; db.ExcuteSqlFromMdb(strCon, strExp); MessageBox.Show("新建成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }
//新建数据源 private void btnOK_Click(object sender, EventArgs e) { try { GeoDataCenterDbFun db = new GeoDataCenterDbFun(); if (comboBoxDsName.Text == "") { MessageBox.Show("数据源名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string mypath = m_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 count(*) from 物理数据源表 where 数据源名称='" + comboBoxDsName.Text + "'"; int count = db.GetCountFromMdb(strCon, strExp); if (count > 0) { MessageBox.Show("数据源名称已存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (labelX5.Text == "数据库:") { strExp = string.Format("insert into 物理数据源表(数据源名称,服务器,数据库,用户,密码,数据源类型) values('{0}','{1}','{2}','{3}','{4}','{5}')", comboBoxDsName.Text, "", txtServer.Text, "", "", cboDataType.Text); } else { strExp = string.Format("insert into 物理数据源表(数据源名称,服务器,数据库,用户,密码,数据源类型) values('{0}','{1}','{2}','{3}','{4}','{5}')", comboBoxDsName.Text, txtServer.Text, txtDataBase.Text, txtUser.Text, txtPassWord.Text, cboDataType.Text); } db.ExcuteSqlFromMdb(strCon, strExp); MessageBox.Show("新建成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); InitializeComDSname(); } catch { MessageBox.Show("新建失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
//删除 private void btnDel_Click(object sender, EventArgs e) { if (listView.SelectedItems.Count != 1) { MessageBox.Show("请选择一项进行删除!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } int index = listView.SelectedItems[0].Index;//取得选中项索引 DialogResult result = MessageBox.Show("是否确定删除此项?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { 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 name = listView.Items[index].Text; string strExp = "delete * from 图层命名初始化表 where 字段名称='" + name + "'"; db.ExcuteSqlFromMdb(strCon, strExp); listView.Items.RemoveAt(index); MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
//编辑图层 private void MenuItemEditLayer_Click(object sender, EventArgs e) { string strCurSubName = null;//组节点的text TreeNode tparentNode = null; TreeNode tNode = null; strCurSubName = treeViewControl.SelectedNode.Parent.Text; tparentNode = treeViewControl.SelectedNode.Parent; tNode = treeViewControl.SelectedNode; string stroldText = tNode.Name;//记录原有节点名称 AddLayerForm dlg = new AddLayerForm(m_xmldoc, tNode); if (dlg.ShowDialog() == DialogResult.OK) { tNode.Text = dlg.m_strLayerDescri; tNode.Name = dlg.m_strLayerName; tNode.Tag = 3; tNode.ImageIndex = 3; tNode.SelectedImageIndex = 3; tparentNode.ExpandAll(); treeViewControl.Refresh(); //更新xml文件 //删除原有节点 string strSearch = "//Layer[@sItemName='" + stroldText + "']"; XmlNode xmlNode = m_xmldoc.SelectSingleNode(strSearch); //xmlNode.ParentNode.RemoveChild(xmlNode);// //string strSearchRoot = "//SubGroup[@sItemName = '" + strCurSubName + "']"; //XmlNode xmlNodeRoot = m_xmldoc.SelectSingleNode(strSearchRoot); //XmlElement xmlElemGroup = (XmlElement)xmlNodeRoot; //XmlElement xmlElemt= m_xmldoc.CreateElement("Layer"); XmlElement xmlElemt = xmlNode as XmlElement; xmlElemt.SetAttribute("sDemo", tNode.Text); xmlElemt.SetAttribute("sDispScale", dlg.m_strScale); xmlElemt.SetAttribute("sDiaphaneity", dlg.m_strTransp); xmlElemt.SetAttribute("sItemName", tNode.Name); //xmlElemGroup.AppendChild(xmlElemt); //添加 文件名称 业务大类代码 业务小类代码 string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + m_mypath + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False"; //生成连接数据库字符串 OleDbConnection mycon = new OleDbConnection(constr); //定义OleDbConnection对象实例并连接数据库 string strExp = ""; strExp = "select * from 标准图层信息表 where 描述 = '" + tNode.Name + "'"; OleDbCommand aCommand = new OleDbCommand(strExp, mycon); strExp = "select 图层组成 from 标准专题信息表 where 专题类型='" + m_Typecode + "'"; GeoDataCenterDbFun db = new GeoDataCenterDbFun(); string layer = db.GetInfoFromMdbByExp(constr, strExp); try { mycon.Open(); //创建datareader 对象来连接到表单 OleDbDataReader aReader = aCommand.ExecuteReader(); while (aReader.Read()) { xmlElemt.SetAttribute("sFile", aReader["代码"].ToString()); xmlElemt.SetAttribute("sBigClass", aReader["业务大类代码"].ToString()); xmlElemt.SetAttribute("sSubClass", aReader["业务小类代码"].ToString()); if (layer == "") { layer = aReader["代码"].ToString(); } else if (!GetExists(aReader["代码"].ToString(), layer)) { layer += "/" + aReader["代码"].ToString();//更改图层组成 } } //关闭reader对象 aReader.Close(); //关闭连接,这很重要 mycon.Close(); //更新标准专题信息表 strExp = "update 标准专题信息表 set 图层组成='" + layer + "' where 专题类型='" + m_Typecode + "'"; db.ExcuteSqlFromMdb(constr, strExp); } catch (System.Exception err) { } //更新xml文件 m_xmldoc.Save(m_xmlPath); } }
//添加组 private void MenuItemTreeAddGroup_Click(object sender, EventArgs e) { AddGroupForm dlg = new AddGroupForm(); if (dlg.ShowDialog() == DialogResult.OK) { //修改树视图 TreeNode tNewGroupNode = new TreeNode(); tNewGroupNode.Name = "【" + dlg.m_strSubName + "】"; tNewGroupNode.Text = "【" + dlg.m_strSubName + "】"; tNewGroupNode.Tag = 2; tNewGroupNode.ImageIndex = 2; tNewGroupNode.SelectedImageIndex = 2; m_tMapNode.Nodes.Add(tNewGroupNode); m_tMapNode.ExpandAll(); //修改xml文件 string strSearchRoot = "//GisMap"; XmlNode xmlNodeRoot = m_xmldoc.SelectSingleNode(strSearchRoot); XmlElement xmlElentRoot = (XmlElement)xmlNodeRoot; XmlElement xmlElemGroup = m_xmldoc.CreateElement("SubGroup"); string strGroupName = "【" + dlg.m_strSubName + "】"; xmlElemGroup.SetAttribute("sItemName", strGroupName); xmlElemGroup.SetAttribute("sType", "GROUP"); xmlElentRoot.AppendChild(xmlElemGroup); //获取组内图层列表 TreeNode tNewNode = null; foreach (TreeNode fCurNode in dlg.totreeView.Nodes) { XmlNode boolnode = m_xmldoc.SelectSingleNode("//Layer[@sItemName='" + fCurNode.Text + "']"); if (boolnode != null) { MessageBox.Show(fCurNode.Text + "图层已存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); continue; } XmlElement xmlElemt = m_xmldoc.CreateElement("Layer"); xmlElemt.SetAttribute("sDemo", fCurNode.Text); xmlElemt.SetAttribute("sItemName", fCurNode.Text); //添加 文件名称 业务大类代码 业务小类代码 string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + m_mypath + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False"; //生成连接数据库字符串 OleDbConnection mycon = new OleDbConnection(constr); //定义OleDbConnection对象实例并连接数据库 string strExp = ""; strExp = "select * from 标准图层信息表 where 描述 = '" + fCurNode.Text + "'"; OleDbCommand aCommand = new OleDbCommand(strExp, mycon); strExp = "select 图层组成 from 标准专题信息表 where 专题类型='" + m_Typecode + "'"; GeoDataCenterDbFun db = new GeoDataCenterDbFun(); string layer = db.GetInfoFromMdbByExp(constr, strExp); try { mycon.Open(); //创建datareader 对象来连接到表单 OleDbDataReader aReader = aCommand.ExecuteReader(); while (aReader.Read()) { xmlElemt.SetAttribute("sFile", aReader["代码"].ToString()); xmlElemt.SetAttribute("sBigClass", aReader["业务大类代码"].ToString()); xmlElemt.SetAttribute("sSubClass", aReader["业务小类代码"].ToString()); if (layer == "") { layer = aReader["代码"].ToString(); } else if (!GetExists(aReader["代码"].ToString(), layer)) { layer += "/" + aReader["代码"].ToString();//更改图层组成 } } //关闭reader对象 aReader.Close(); //关闭连接,这很重要 mycon.Close(); //更新标准专题信息表 strExp = "update 标准专题信息表 set 图层组成='" + layer + "' where 专题类型='" + m_Typecode + "'"; db.ExcuteSqlFromMdb(constr, strExp); } catch (System.Exception err) { } //更新树 tNewNode = new TreeNode(); tNewNode.Text = fCurNode.Text; tNewNode.Name = fCurNode.Name; tNewNode.Tag = 3; tNewNode.ImageIndex = 3; tNewNode.SelectedImageIndex = 3; tNewGroupNode.Nodes.Add(tNewNode); tNewGroupNode.ExpandAll(); xmlElemGroup.AppendChild(xmlElemt); } treeViewControl.Refresh(); //更新xml文件 m_xmldoc.Save(m_xmlPath); } }
//修改专题 private void MenuItemModifySub_Click(object sender, EventArgs e) { if (listViewControl.SelectedItems.Count <= 0) { MessageBox.Show("请选择要修改的专题!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //获取数据库中信息 更改 //获取数值添加到“标准专题信息表”中 string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + m_mypath + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False"; //生成连接数据库字符串 OleDbConnection mycon = new OleDbConnection(constr); //定义OleDbConnection对象实例并连接数据库 string strExp = ""; GeoDataCenterDbFun db = new GeoDataCenterDbFun(); //获取节点名称 string strSubOldName = null; string strSubOldCode = null; string strSubOldIndexFile = null; string strSubOldMapFile = null; SubAttForm dlg = new SubAttForm(); dlg.strSubCode = listViewControl.SelectedItems[0].Text; strSubOldCode = listViewControl.SelectedItems[0].Text; dlg.strSubName = listViewControl.SelectedItems[0].SubItems[1].Text; strSubOldName = listViewControl.SelectedItems[0].SubItems[1].Text; dlg.strIndexFile = listViewControl.SelectedItems[0].SubItems[2].Text; strSubOldIndexFile = listViewControl.SelectedItems[0].SubItems[2].Text; strExp = "select 配图方案文件 from 标准专题信息表 where " + "专题类型 = '" + strSubOldCode + "' "; strSubOldMapFile = dlg.strMapSymIndexFile = db.GetInfoFromMdbByExp(constr, strExp); dlg.SetFormTextBoxAtt(); if (dlg.ShowDialog() == DialogResult.OK) { //没发生变化 if (strSubOldCode.Equals(dlg.strSubCode) && strSubOldName.Equals(dlg.strSubName) && strSubOldIndexFile.Equals(dlg.strIndexFile) && strSubOldMapFile.Equals(dlg.strMapSymIndexFile)) { return; } //修改listview listViewControl.SelectedItems[0].Text = dlg.strSubCode; listViewControl.SelectedItems[0].SubItems[1].Text = dlg.strSubName; listViewControl.SelectedItems[0].SubItems[2].Text = dlg.strIndexFile; listViewControl.Refresh(); } // strExp = "update 标准专题信息表 set 专题类型 = '" + dlg.strSubCode + "'," + "描述 = '" + dlg.strSubName + "' where " + "专题类型 = '" + strSubOldCode + "'"; strExp = "update 标准专题信息表 set 专题类型 = '" + dlg.strSubCode + "'," + "描述 = '" + dlg.strSubName + "'," + "脚本文件 = '" + dlg.strIndexFile + "'," + "配图方案文件 = '" + dlg.strMapSymIndexFile + "' where " + "专题类型 = '" + strSubOldCode + "'"; OleDbCommand aCommand = new OleDbCommand(strExp, mycon); try { mycon.Open(); //g更新记录 int iRows = aCommand.ExecuteNonQuery(); //关闭连接,这很重要 mycon.Close(); } catch (System.Exception err) { Console.WriteLine(err.Message); } strExp = "update 地图入库信息表 set 专题类型='" + dlg.strSubCode + "' where " + "专题类型 = '" + strSubOldCode + "'"; db.ExcuteSqlFromMdb(constr, strExp); string strModFile = Application.StartupPath + "\\..\\Template\\StandardBlank.xml"; string strIndexFile = Application.StartupPath + "\\..\\Template\\" + dlg.strIndexFile; if (strSubOldIndexFile.CompareTo(dlg.strIndexFile) != 0) { if (!File.Exists(strIndexFile)) { File.Copy(strModFile, strIndexFile, true); } } if (strSubOldName.CompareTo(dlg.strSubName) != 0) //修改了专题描述才修改对应的xml文件 { //加载文件并修改GisMap ItemName="" XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(strIndexFile); string strSearchRoot = "//GisMap"; XmlNode xmlNodeRoot = xmldoc.SelectSingleNode(strSearchRoot); XmlElement xmlElentRoot = (XmlElement)xmlNodeRoot; xmlElentRoot.SetAttribute("sItemName", dlg.strSubName); xmldoc.Save(strIndexFile); } }