private void AddField_Load(object sender, EventArgs e) { 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)//添加字段 { comboBoxType.SelectedIndex = 0; } else//编辑字段 { strExp = "select * from 图层命名初始化表 where 字段名称='" + m_fleldname + "'"; DataTable dt = db.GetDataTableFromMdb(strCon, strExp); comBoxName.Text = m_fleldname; textBoxDescribe.Text = dt.Rows[0]["描述"].ToString(); comboBoxType.Text = dt.Rows[0]["字段类型"].ToString(); textBoxLength.Text = dt.Rows[0]["字段长度"].ToString(); checkBoxChange.Checked = (bool)(dt.Rows[0]["可变"]); textBoxDefault.Text = dt.Rows[0]["缺省"].ToString(); id = Convert.ToInt32(dt.Rows[0]["ID"]); } }
//删除数据源 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 SetLogicDataSourceForm_Load(object sender, EventArgs e) { 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 数据源名称 from 物理数据源表"; GeoDataCenterDbFun db = new GeoDataCenterDbFun(); List <string> list = db.GetDataReaderFromMdb(strCon, strExp); for (int i = 0; i < list.Count; i++) { comboBoxDsName.Items.Add(list[i]); } if (comboBoxDsName.Items.Count > 0) { comboBoxDsName.SelectedIndex = 0; } strExp = "select 行政代码 from 数据单元表"; list = new List <string>(); list = db.GetDataReaderFromMdb(strCon, strExp); for (int i = 0; i < list.Count; i++) { comboBoxAreaCode.Items.Add(list[i]); } if (comboBoxAreaCode.Items.Count > 0) { comboBoxAreaCode.SelectedIndex = 0; } }
//插入数据库 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 comboBoxAreaCode_SelectedIndexChanged(object sender, EventArgs e) { if (comboBoxAreaCode.Text != "") { 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 行政名称 from 数据单元表 where 行政代码='" + comboBoxAreaCode.Text + "'"; GeoDataCenterDbFun db = new GeoDataCenterDbFun(); txtAreaName.Text = db.GetInfoFromMdbByExp(strCon, strExp); } }
//生成正则表达式 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 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 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 ToTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { labelCode.Text = ""; if (ToTreeView.SelectedNode != e.Node) { ToTreeView.SelectedNode = e.Node; } 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 标准数据单元表 where 行政名称='" + ToTreeView.SelectedNode.Text + "' and 数据单元级别=" + ToTreeView.SelectedNode.Tag + ""; GeoDataCenterDbFun db = new GeoDataCenterDbFun(); labelCode.Text = db.GetInfoFromMdbByExp(strCon, strExp); }
private void frmMapProperty_Load(object sender, EventArgs e) { //显示图件名称 labNewname.Text = thisNode.Parent.Parent.Text + thisNode.Parent.Text + thisNode.Text; //获取专题类型 string strSubType = thisNode.Tag.ToString();//专题类型代码 labNewType.Text = thisNode.Parent.Text; //生成连接数据库字符串 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 strYear = thisNode.Text.Substring(0, 4); labNewYear.Text = strYear; //获取比例尺及其代码 GeoDataCenterDbFun dDbFun = new GeoDataCenterDbFun(); int iStartPos = thisNode.Text.IndexOf("【"); int iEndPos = thisNode.Text.IndexOf("】"); int iLength = iEndPos - iStartPos - 1; string strScaleName = thisNode.Text.Substring(iStartPos + 1, iLength); labNewScale.Text = strScaleName; string strExp = "select 代码 from 比例尺代码表 where 描述 ='" + strScaleName + "'"; string strScaleCode = dDbFun.GetInfoFromMdbByExp(strCon, strExp); //获取行政区划 labNewDivision.Text = thisNode.Parent.Parent.Text; //从地图入库信息表中获取已入库数据信息(图层组成) strExp = "select 图层组成 from 地图入库信息表 where 行政名称 ='" + thisNode.Parent.Parent.Text + "'" + "And " + " 年度='" + strYear + "'" + "And " + " 比例尺='" + strScaleCode + "'" + "And " + " 专题类型='" + strSubType + "'"; string strLayerGroup = dDbFun.GetInfoFromMdbByExp(strCon, strExp); string[] array = strLayerGroup.Split("/".ToCharArray()); for (int i = 0; i < array.Length; i++) { strExp = "select 描述 from 标准图层信息表 where 代码='" + array[i] + "'"; string strBussinessName = dDbFun.GetInfoFromMdbByExp(strCon, strExp); listLayer.Items.Add(strBussinessName); } }
//编辑字段 private void btnEdit_Click(object sender, EventArgs e) { if (listView.SelectedItems.Count != 1) { 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(); AddField frm = new AddField(); frm.flag = 2; frm.fleldname = listView.SelectedItems[0].Text.Trim(); frm.ShowDialog(); }
//加载数据源名称 private void InitializeComDSname() { comboBoxDsName.Items.Clear(); 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 数据源名称 from 物理数据源表"; GeoDataCenterDbFun db = new GeoDataCenterDbFun(); List <string> list = db.GetDataReaderFromMdb(strCon, strExp); for (int i = 0; i < list.Count; i++) { comboBoxDsName.Items.Add(list[i]); } if (comboBoxDsName.Items.Count > 0) { comboBoxDsName.SelectedIndex = 0; } }
private void InitComBoxName() { ComboBoxName.Items.Clear(); GetDataTreeInitIndex dIndex = new GetDataTreeInitIndex(); string path = dIndex.GetDbInfo(); string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False";//生成连接数据库字符串 string strExp = "select 描述 from 标准图层信息表"; GeoDataCenterDbFun db = new GeoDataCenterDbFun(); List <string> list = db.GetDataReaderFromMdb(strCon, strExp); for (int i = 0; i < list.Count; i++) { ComboBoxName.Items.Add(list[i]); } if (list.Count > 0) { ComboBoxName.SelectedIndex = 0; } }
/// <summary> /// 创建专题节点 /// </summary> /// <param name="tRootItem">县级行政区节点</param> /// <param name="strCon">连接语句</param> public void CreateSubTreeItem(TreeNode tRootItem, string strCon) { string strXzqCode = tRootItem.Name; GeoDataCenterDbFun dDbFun = new GeoDataCenterDbFun(); string strExp = "select distinct 专题类型 from 地图入库信息表 where 行政代码 = '" + strXzqCode + "'"; OleDbConnection mycon = new OleDbConnection(strCon); //定义OleDbConnection对象实例并连接数据库 OleDbCommand aCommand = new OleDbCommand(strExp, mycon); try { mycon.Open(); OleDbDataReader aReader = aCommand.ExecuteReader(); string strSql = ""; string strSubType = ""; string strSubTypeName = ""; TreeNode tSubItem; while (aReader.Read()) { strSubType = aReader["专题类型"].ToString(); //获取专题类型 strSql = "select 描述 from 标准专题信息表 where 专题类型 ='" + strSubType + "'"; strSubTypeName = dDbFun.GetInfoFromMdbByExp(strCon, strSql); tSubItem = new TreeNode(); tSubItem.Text = strSubTypeName; tRootItem.Nodes.Add(tSubItem); //tRootItem.ExpandAll(); } //关闭reader对象 aReader.Close(); //关闭连接 mycon.Close(); } catch (System.Exception e) { Console.WriteLine(e.Message); } }
//添加叶子节点 public void AddLeafItem(TreeNode treeNode, XmlNode xmlNode) { 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 + "'"; layer = db.GetInfoFromMdbByExp(constr, strExp); strExp = "select 描述 from 标准图层信息表 where 代码='" + layer + "'"; layer = db.GetInfoFromMdbByExp(constr, strExp); if (treeNode != null && xmlNode != null) { TreeNode tNewNode; string strLayerDescribed = ""; //图层名称 地类图斑等 string strFileName = ""; XmlNodeList xmlNdList; xmlNdList = xmlNode.ChildNodes; foreach (XmlNode xmlChild in xmlNdList) { strLayerDescribed = ""; XmlElement xmlElent = (XmlElement)xmlChild; strLayerDescribed = xmlElent.GetAttribute("sDemo"); //描述 strFileName = xmlElent.GetAttribute("sItemName"); //名称 //修改sfile名称 tNewNode = new TreeNode(); tNewNode.Text = strLayerDescribed; tNewNode.Name = strFileName; tNewNode.Tag = 3; treeNode.Nodes.Add(tNewNode); tNewNode.ImageIndex = 3; tNewNode.SelectedImageIndex = 3; if (strFileName.Trim().CompareTo(layer.Trim()) == 0) { tNewNode.ForeColor = Color.Red; } } treeNode.ExpandAll(); } }
private void LoadListView() { listView.Items.Clear(); 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 图层命名初始化表 order by 排序"; string strExp = "select 字段名称,描述,字段类型,字段长度,缺省,排序 from 图层命名初始化表 order by 排序"; DataTable dt = db.GetDataTableFromMdb(strCon, strExp); for (int i = 0; i < dt.Rows.Count; i++) { listView.Items.Add(dt.Rows[i]["字段名称"].ToString()); listView.Items[i].SubItems.Add(dt.Rows[i]["描述"].ToString()); listView.Items[i].SubItems.Add(dt.Rows[i]["字段类型"].ToString()); listView.Items[i].SubItems.Add(dt.Rows[i]["字段长度"].ToString()); listView.Items[i].SubItems.Add(dt.Rows[i]["缺省"].ToString()); } }
//设置成关键图层 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 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 comboBoxDsName_SelectedIndexChanged(object sender, EventArgs e) { GeoDataCenterDbFun db = new GeoDataCenterDbFun(); if (comboBoxDsName.Text.Trim() == "") { cboDataType.Text = ""; txtUser.Text = ""; txtPassWord.Text = ""; txtServer.Text = txtDataBase.Text = ""; return; } else { string strExp = "select * from 物理数据源表 where 数据源名称='" + comboBoxDsName.Text + "'"; 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"; //生成连接数据库字符串 DataTable dt = db.GetDataTableFromMdb(strCon, strExp); if (dt.Rows.Count == 0) { return; } //cboDataType.Text = dt.Rows[0]["数据源类型"].ToString(); txtUser.Text = dt.Rows[0]["用户"].ToString(); txtPassWord.Text = dt.Rows[0]["密码"].ToString(); cboDataType.SelectedItem = dt.Rows[0]["数据源类型"]; if (dt.Rows[0]["数据源类型"].Equals("SDE")) { //SDE txtServer.Text = dt.Rows[0]["服务器"].ToString(); txtDataBase.Text = dt.Rows[0]["数据库"].ToString(); } else { txtServer.Text = dt.Rows[0]["数据库"].ToString(); txtDataBase.Text = ""; } } }
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 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 MenuItemAddSub_Click(object sender, EventArgs e) { SubAttForm dlg = new SubAttForm(); if (dlg.ShowDialog() == DialogResult.OK) { 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 = "select count(*) from 标准专题信息表 where 专题类型='" + dlg.strSubCode + "'"; GeoDataCenterDbFun db = new GeoDataCenterDbFun(); int count = db.GetCountFromMdb(constr, strExp); if (count > 0) { MessageBox.Show("专题已存在,请修改专题类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //向当前listview添加一条记录 ListViewItem lvItem; ListViewItem.ListViewSubItem lSubItem; ListViewItem.ListViewSubItem lSubItemSecond; lvItem = new ListViewItem(); lvItem.Text = dlg.strSubCode; lSubItem = new ListViewItem.ListViewSubItem(); lSubItem.Text = dlg.strSubName; lvItem.SubItems.Add(lSubItem); lSubItemSecond = new ListViewItem.ListViewSubItem(); lSubItemSecond.Text = dlg.strIndexFile; lvItem.SubItems.Add(lSubItemSecond); listViewControl.Items.Add(lvItem); listViewControl.Refresh(); //获取数值添加到“标准专题信息表”中 strExp = "insert into 标准专题信息表 (专题类型,描述,脚本文件,配图方案文件) values('" + dlg.strSubCode + "','" + dlg.strSubName + "','" + dlg.strIndexFile + "','" + dlg.strMapSymIndexFile + "')"; OleDbCommand aCommand = new OleDbCommand(strExp, mycon); try { mycon.Open(); //插入记录 int iRows = aCommand.ExecuteNonQuery(); //关闭连接,这很重要 mycon.Close(); } catch (System.Exception err) { Console.WriteLine(err.Message); } //在\Template目录下生成对应文件 string strModFile = Application.StartupPath + "\\..\\Template\\StandardBlank.xml"; string strIndexFile = Application.StartupPath + "\\..\\Template\\" + dlg.strIndexFile; if (!File.Exists(strIndexFile)) { File.Copy(strModFile, strIndexFile, true); } //加载文件并修改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); m_Typecode = dlg.strSubCode; LoadTreeView(dlg.strIndexFile); } }
//修改专题 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); } }
//进入 private void btnIn_Click(object sender, EventArgs e) { //从 数据单元表 中获取信息 GetDataTreeInitIndex dIndex = new GetDataTreeInitIndex(); string mypath = dIndex.GetDbInfo(); string strDispLevel = dIndex.GetXmlElementValue("UnitTree", "tIsDisp"); //是否从市级开始创建数据单元树 string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mypath + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False"; //生成连接数据库字符串 string strExp = "select 行政名称 from 数据单元表 where 数据单元级别='1'"; GeoDataCenterDbFun db = new GeoDataCenterDbFun(); string strProvince = db.GetInfoFromMdbByExp(constr, strExp); //获取当前点击节点 省、市节点 //ToTreeView.Nodes.Clear(); TreeNode tFromSelNode = FromTreeView.SelectedNode; if (tFromSelNode != null) { //是省级节点 包含整个市的 if (tFromSelNode.Tag.Equals(1)) { ToTreeView.Nodes.Clear(); //获取该省级节点的所有子节点 TreeNode tRootNode; TreeNode tCityNode; TreeNode tCountyNode; tRootNode = new TreeNode(); tRootNode.Name = tFromSelNode.Name; tRootNode.Text = tFromSelNode.Text; tRootNode.Tag = tFromSelNode.Tag; tRootNode.ImageIndex = tFromSelNode.ImageIndex; ToTreeView.Nodes.Add(tRootNode); m_NewRootNode = tRootNode; int iNodeCount = tFromSelNode.GetNodeCount(false); tCityNode = new TreeNode(); TreeNode tOldCityNode = tFromSelNode.FirstNode; tCityNode.Name = tOldCityNode.Name; tCityNode.Text = tOldCityNode.Text; tCityNode.Tag = tOldCityNode.Tag; tCityNode.ImageIndex = tOldCityNode.ImageIndex; while (iNodeCount > 0) { tRootNode.Nodes.Add(tCityNode); int iLeafCount = tOldCityNode.GetNodeCount(false); tCountyNode = new TreeNode(); TreeNode tOldCountyNode = tOldCityNode.FirstNode; tCountyNode.Name = tOldCountyNode.Name; tCountyNode.Text = tOldCountyNode.Text; tCountyNode.Tag = tOldCountyNode.Tag; tCountyNode.ImageIndex = tOldCountyNode.ImageIndex; tCountyNode.ExpandAll(); while (iLeafCount > 0) { tCityNode.Nodes.Add(tCountyNode); if (tOldCountyNode != tOldCityNode.LastNode) { tOldCountyNode = tOldCountyNode.NextNode; tCountyNode = new TreeNode(); tCountyNode.Name = tOldCountyNode.Name; tCountyNode.Text = tOldCountyNode.Text; tCountyNode.Tag = tOldCountyNode.Tag; tCountyNode.ImageIndex = tOldCountyNode.ImageIndex; tCountyNode.ExpandAll(); } iLeafCount--; } if (tOldCityNode != tFromSelNode.LastNode) { tOldCityNode = tOldCityNode.NextNode; tCityNode = new TreeNode(); tCityNode.Name = tOldCityNode.Name; tCityNode.Text = tOldCityNode.Text; tCityNode.Tag = tOldCityNode.Tag; tCityNode.ImageIndex = tOldCityNode.ImageIndex; tCityNode.ExpandAll(); } iNodeCount--; tRootNode.Expand(); } // ToTreeView.Refresh(); } else if (tFromSelNode.Tag.Equals(2)) //是市级节点 要包含省的 { //获取省级节点 然后该市级节点包含子节点 TreeNode tParentNode = tFromSelNode.Parent; TreeNode tRootNode = null; TreeNode tCityNode = null; TreeNode tCountyNode = null; if (ToTreeView.Nodes.Count >= 1) { if (strProvince != (tParentNode.Text) && ToTreeView.Nodes[0].Text != tParentNode.Text)//是该省节点 { ToTreeView.Nodes.Clear(); tRootNode = new TreeNode(); //插入省节点 tRootNode.Name = tParentNode.Name; tRootNode.Text = tParentNode.Text; tRootNode.Tag = tParentNode.Tag; tRootNode.ImageIndex = tParentNode.ImageIndex; ToTreeView.Nodes.Add(tRootNode); } else { tRootNode = ToTreeView.Nodes[0]; } if (ToTreeView.Nodes[0].Nodes.Count > 0)//已经有市节点 { foreach (TreeNode node in ToTreeView.Nodes[0].Nodes) { if ((node.Text.Trim() == tFromSelNode.Text.Trim()))//市节点已存在, { DialogResult result = MessageBox.Show("是否替换该市节点?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (result == DialogResult.No) //不替换 { return; //不做反应,直接返回 } else//替换 { node.Remove();//移除该节点 } } } } tCityNode = new TreeNode(); //插入市节点 tCityNode.Name = tFromSelNode.Name; tCityNode.Text = tFromSelNode.Text; tCityNode.Tag = tFromSelNode.Tag; tCityNode.ImageIndex = tFromSelNode.ImageIndex; tRootNode.Nodes.Add(tCityNode); tRootNode.Expand(); } else { tRootNode = new TreeNode(); //插入省节点 tRootNode.Name = tParentNode.Name; tRootNode.Text = tParentNode.Text; tRootNode.Tag = tParentNode.Tag; tRootNode.ImageIndex = tParentNode.ImageIndex; ToTreeView.Nodes.Add(tRootNode);; tCityNode = new TreeNode(); //插入市节点 tCityNode.Name = tFromSelNode.Name; tCityNode.Text = tFromSelNode.Text; tCityNode.Tag = tFromSelNode.Tag; tCityNode.ImageIndex = tFromSelNode.ImageIndex; tRootNode.Nodes.Add(tCityNode); tRootNode.Expand(); } m_NewRootNode = tRootNode; //插入县级节点 int iNodeCount = tFromSelNode.GetNodeCount(false); tCountyNode = new TreeNode(); TreeNode tOldCountyNode = tFromSelNode.FirstNode; if (tOldCountyNode != null) { tCountyNode.Name = tOldCountyNode.Name; tCountyNode.Text = tOldCountyNode.Text; tCountyNode.Tag = tOldCountyNode.Tag; tCountyNode.ImageIndex = tOldCountyNode.ImageIndex; } while (iNodeCount > 0) { tCityNode.Nodes.Add(tCountyNode); tCountyNode = new TreeNode(); if (tOldCountyNode != tFromSelNode.LastNode) { tOldCountyNode = tOldCountyNode.NextNode; tCountyNode.Name = tOldCountyNode.Name; tCountyNode.Text = tOldCountyNode.Text; tCountyNode.Tag = tOldCountyNode.Tag; tCountyNode.ImageIndex = tOldCountyNode.ImageIndex; } iNodeCount--; } } else if (tFromSelNode.Tag.Equals(3)) //县级节点 { //获取省级节点 然后该市级节点包含子节点 TreeNode tParentNode = tFromSelNode.Parent.Parent; TreeNode tRootNode = null; TreeNode tCityNode = null; TreeNode tCountyNode = null; if (ToTreeView.Nodes.Count >= 1) { if (strProvince != (tParentNode.Text) && ToTreeView.Nodes[0].Text != tParentNode.Text)//是该省节点 { ToTreeView.Nodes.Clear(); tRootNode = new TreeNode(); //插入省节点 tRootNode.Name = tParentNode.Name; tRootNode.Text = tParentNode.Text; tRootNode.Tag = tParentNode.Tag; tRootNode.ImageIndex = tParentNode.ImageIndex; ToTreeView.Nodes.Add(tRootNode); } else { tRootNode = ToTreeView.Nodes[0]; } if (ToTreeView.Nodes[0].Nodes.Count > 0)//已经有市节点 { foreach (TreeNode node in ToTreeView.Nodes[0].Nodes) { if ((node.Text.Trim() == tFromSelNode.Parent.Text.Trim()))//市节点已存在, { tCityNode = node; } } } if (tCityNode == null)//没有该市节点,添加一个市节点 { tCityNode = new TreeNode(); //插入市节点 tCityNode.Name = tFromSelNode.Parent.Name; tCityNode.Text = tFromSelNode.Parent.Text; tCityNode.Tag = tFromSelNode.Parent.Tag; tCityNode.ImageIndex = tFromSelNode.Parent.ImageIndex; tRootNode.Nodes.Add(tCityNode); tRootNode.ExpandAll(); tCityNode.ExpandAll(); } } else { tRootNode = new TreeNode(); //插入省节点 tRootNode.Name = tParentNode.Name; tRootNode.Text = tParentNode.Text; tRootNode.Tag = tParentNode.Tag; tRootNode.ImageIndex = tParentNode.ImageIndex; ToTreeView.Nodes.Add(tRootNode); tCityNode = new TreeNode(); //插入市节点 tCityNode.Name = tFromSelNode.Parent.Name; tCityNode.Text = tFromSelNode.Parent.Text; tCityNode.Tag = tFromSelNode.Parent.Tag; tCityNode.ImageIndex = tFromSelNode.Parent.ImageIndex; tRootNode.Nodes.Add(tCityNode); } m_NewRootNode = tRootNode; tRootNode.Expand(); //插入县级节点 if (tCityNode.Nodes.Count > 0) { foreach (TreeNode node in tCityNode.Nodes) { if ((node.Text.Trim() == tFromSelNode.Text.Trim()))//县节点已存在, { MessageBox.Show("该节点已存在!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information); return; } } } tCountyNode = new TreeNode(); tCountyNode.Name = tFromSelNode.Name; tCountyNode.Text = tFromSelNode.Text; tCountyNode.Tag = tFromSelNode.Tag; tCountyNode.ImageIndex = tFromSelNode.ImageIndex; tCountyNode.ExpandAll(); tCityNode.Nodes.Add(tCountyNode); tCityNode.ExpandAll(); tCountyNode.ExpandAll(); } } }
//添加组 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 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); } }