示例#1
0
        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);
        }
示例#2
0
 //新建数据源
 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);
     }
 }
示例#3
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);
            }
        }