Example #1
0
        //修改专题
        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);
            }
        }
Example #2
0
        //添加专题
        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);
            }
        }