コード例 #1
0
 //修改数据库中数据
 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);
     }
 }
コード例 #2
0
        //删除数据库中数据
        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);
            }
        }
コード例 #3
0
ファイル: frmDataUpload.cs プロジェクト: siszoey/geosufan
        //写入数据编码表和地图入库信息表的方法
        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);
        }
コード例 #4
0
        //开始分析
        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);
            }
        }