Ejemplo n.º 1
0
        //写入数据编码表和地图入库信息表的方法
        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);
        }