private void frmRasterDataReduction_Load(object sender, EventArgs e) { SysCommon.CProgress vProgress = new SysCommon.CProgress("正在加载数据"); vProgress.EnableCancel = false; vProgress.ShowDescription = true; vProgress.FakeProgress = true; vProgress.TopMost = true; vProgress.ShowProgress(); GetDataTreeInitIndex dIndex = new GetDataTreeInitIndex(); string strExp = "select 数据源名称 from 物理数据源表"; 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(); List <string> list = db.GetDataReaderFromMdb(strCon, strExp); for (int i = 0; i < list.Count; i++) { comboBoxSource.Items.Add(list[i]);//加载数据源列表框 } if (list.Count > 0) { comboBoxSource.SelectedIndex = 0;//默认选择第一个 } vProgress.Close(); this.Activate(); }
//以年度为主 private void checkBoxYear_CheckedChanged(object sender, EventArgs e) { if (checkBoxYear.Checked) { groupBoxYear.Enabled = true; string str_Exp = "select 年度 from 数据编码表"; GeoDataCenterDbFun dbfun = new GeoDataCenterDbFun(); List <string> list = dbfun.GetDataReaderFromMdb(m_con, str_Exp); for (int i = 0; i < list.Count; i++) { if (!comboBoxYear.Items.Contains(list[i])) { comboBoxYear.Items.Add(list[i]); } } if (comboBoxYear.Items.Count > 0) { comboBoxYear.SelectedIndex = 0; } } else { groupBoxYear.Enabled = false; comboBoxYear.Items.Clear(); comboBoxYear.Text = ""; } }
//加载列表框 private void LoadCombox() { 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 str_Exp = "select 年度 from 数据编码表"; GeoDataCenterDbFun dbfun = new GeoDataCenterDbFun(); List <string> list = dbfun.GetDataReaderFromMdb(strCon, str_Exp); comboBoxYear.Items.Add("所有年度"); for (int i = 0; i < list.Count; i++) { if (!comboBoxYear.Items.Contains(list[i])) { comboBoxYear.Items.Add(list[i]); } } if (comboBoxYear.Items.Count > 0) { comboBoxYear.SelectedIndex = 0; } //str_Exp = "select 行政名称,行政代码 from 数据单元表"; //DataTable dt = dbfun.GetDataTableFromMdb(strCon, str_Exp); //comboBoxArea.Items.Add("所有行政区"); //for (int i = 0; i < dt.Rows.Count; i++) //{ // comboBoxArea.Items.Add(dt.Rows[i]["行政名称"] + "(" + dt.Rows[i]["行政代码"] + ")"); //} //if (comboBoxArea.Items.Count > 0) // comboBoxArea.SelectedIndex = 0; str_Exp = "select 描述,代码 from 比例尺代码表"; DataTable dt = dbfun.GetDataTableFromMdb(strCon, str_Exp); comboBoxScale.Items.Add("所有比例尺"); for (int i = 0; i < dt.Rows.Count; i++) { comboBoxScale.Items.Add(dt.Rows[i]["描述"] + "(" + dt.Rows[i]["代码"] + ")"); } if (comboBoxScale.Items.Count > 0) { comboBoxScale.SelectedIndex = 0; } str_Exp = "select 描述,专题类型 from 标准专题信息表"; dt = dbfun.GetDataTableFromMdb(strCon, str_Exp); comboBoxSub.Items.Add("所有专题类型"); for (int i = 0; i < dt.Rows.Count; i++) { comboBoxSub.Items.Add(dt.Rows[i]["描述"] + "(" + dt.Rows[i]["专题类型"] + ")"); } if (comboBoxSub.Items.Count > 0) { comboBoxSub.SelectedIndex = 0; } }
//列表框状态改变 private void ChangeGridView() { datagwSource.Rows.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";//生成连接数据库字符串 string str_Exp = "select 文档名称 from 文档入库信息表 where 文档虚拟目录='" + comboBoxCatalog.Text + "' "; GeoDataCenterDbFun db = new GeoDataCenterDbFun(); if (Node != null && Convert.ToInt32(Node.Tag) != 0)//如果选择的不是所有行政区 { switch (Convert.ToInt32(Node.Tag)) { case 1: string code = GetCode(comboBoxArea.Text).Substring(0, 3); str_Exp += "and 行政代码 like '" + code + "___'"; break; case 2: code = GetCode(comboBoxArea.Text).Substring(0, 4); str_Exp += "and 行政代码 like '" + code + "__'"; break; case 3: str_Exp += "and 行政代码='" + GetCode(comboBoxArea.Text) + "'"; break; } } if (comboBoxScale.SelectedIndex > 0)//如果选择的不是所有比例尺 { str_Exp += "and 比例尺 ='" + GetCode(comboBoxScale.Text) + "'"; } if (comboBoxSub.SelectedIndex > 0)//如果选择的不是所有专题类型 { str_Exp += "and 专题类型='" + GetCode(comboBoxSub.Text) + "'"; } if (comboBoxYear.SelectedIndex > 0)//如果选择的不是所有年度 { str_Exp += "and 年度='" + comboBoxYear.Text + "'"; } List <string> list = db.GetDataReaderFromMdb(strCon, str_Exp); for (int i = 0; i < list.Count; i++) { datagwSource.Rows.Add(new object[] { true, list[i] }); } }
private void frmRasterDataUpload_Load(object sender, EventArgs e) { string strExp = "select 数据源名称 from 物理数据源表"; 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"; //生成连接数据库字符串 GeoDataCenterDbFun db = new GeoDataCenterDbFun(); List <string> list = db.GetDataReaderFromMdb(strCon, strExp); for (int ii = 0; ii < list.Count; ii++) { comboBoxSource.Items.Add(list[ii]);//加载数据源列表框 } if (list.Count > 0) { comboBoxSource.SelectedIndex = 0;//默认选择第一个 } }
private void LoadComboBox() { GetDataTreeInitIndex dIndex = new GetDataTreeInitIndex(); string strExp = "select 虚拟目录名 from 文档数据源信息表"; 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(); List <string> list = db.GetDataReaderFromMdb(strCon, strExp); for (int i = 0; i < list.Count; i++) { comboBoxSource.Items.Add(list[i]);//加载数据源列表框 } if (list.Count > 0) { comboBoxSource.SelectedIndex = 0;//默认选择第一个 } }
//窗口加载 private void frmAnalyseInLibMap_Load(object sender, EventArgs e) { checkBoxDelold.Checked = true; GetDataTreeInitIndex dIndex = new GetDataTreeInitIndex(); string mypath = dIndex.GetDbInfo(); m_con = "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 物理数据源表"; List <string> list = db.GetDataReaderFromMdb(m_con, strExp); for (int i = 0; i < list.Count; i++) { comboBoxSource.Items.Add(list[i]);//加载数据源列表框 } if (list.Count > 0) { comboBoxSource.SelectedIndex = 0;//默认选择第一个 } //m_path = GetSourcePath(comboBoxSource.Text.Trim()); }
/// <summary> /// 加载列表框,年度,数据源 /// </summary> /// <param name="cb">列表框</param> /// <param name="str">需要执行的SQL语句</param> private void LoadData(ComboBox cb, string str) { List <string> list = new List <string>(); 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(); list = db.GetDataReaderFromMdb(strCon, str); for (int i = 0; i < list.Count; i++) { if (!cb.Items.Contains(list[i])) { cb.Items.Add(list[i]); } } if (cb.Items.Count != 0) { cb.SelectedIndex = 0; } }
public static TreeNode Node; //数据单元树返回的节点 private void frmDocRedution_Load(object sender, EventArgs e) { Node = null; //初始化进度条 SysCommon.CProgress vProgress = new SysCommon.CProgress("正在加载文档数据"); vProgress.EnableCancel = false; vProgress.ShowDescription = true; vProgress.FakeProgress = true; vProgress.TopMost = true; vProgress.ShowProgress(); m_first = true; LoadGridView(); //加载虚拟目录 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(); List <string> list = db.GetDataReaderFromMdb(strCon, strExp); for (int i = 0; i < list.Count; i++) { if (!comboBoxCatalog.Items.Contains(list[i])) { comboBoxCatalog.Items.Add(list[i]); } } if (comboBoxCatalog.Items.Count > 0) { comboBoxCatalog.SelectedIndex = 0; } vProgress.Close(); this.Activate(); }
//显示全部数据 private void LoadGridView(CProgress vprocess)//重载加载数据函数 { GetDataTreeInitIndex dIndex = new GetDataTreeInitIndex(); string strExp = "select 数据源名称 from 物理数据源表"; 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(); List <string> list = db.GetDataReaderFromMdb(strCon, strExp); for (int i = 0; i < list.Count; i++) { comboBoxSource.Items.Add(list[i]);//加载数据源列表框 } if (list.Count > 0) { comboBoxSource.SelectedIndex = 0;//默认选择第一个 } string player = ""; string sourename = comboBoxSource.Text.Trim(); strExp = "select * from 数据编码表 where 数据源名称='" + sourename + "'"; DataTable dt = db.GetDataTableFromMdb(strCon, strExp); for (int i = 0; i < dt.Rows.Count; i++) { strExp = "select 字段名称 from 图层命名规则表"; string strname = db.GetInfoFromMdbByExp(strCon, strExp); string[] arrName = strname.Split('+'); //分离字段名称 string layername = ""; player = ""; for (int j = 0; j < arrName.Length; j++) { switch (arrName[j]) { case "业务大类代码": layername += dt.Rows[i]["业务大类代码"].ToString(); //业务大类代码 break; case "年度": layername += dt.Rows[i]["年度"].ToString(); //年度 break; case "业务小类代码": layername += dt.Rows[i]["业务小类代码"].ToString(); //业务小类代码 break; case "行政代码": layername += dt.Rows[i]["行政代码"].ToString(); //行政代码 break; case "比例尺": layername += dt.Rows[i]["比例尺"].ToString(); //比例尺 break; } } layername += dt.Rows[i]["图层代码"].ToString(); strExp = "select 描述 from 标准图层信息表 where 代码='" + dt.Rows[i]["图层代码"].ToString() + "'"; string playername = db.GetInfoFromMdbByExp(strCon, strExp); if (playername != "") { player = playername; } else { player = dt.Rows[i]["图层代码"].ToString(); } string username = GetSourceUser(comboBoxSource.Text).Trim().ToUpper();; if (username != "") { layername = username + "." + layername; } datagwSource.Rows.Add(new object[] { true, layername, player }); } //IWorkspaceFactory Pwf = new FileGDBWorkspaceFactoryClass(); //pWorkspace = (IWorkspace)(Pwf.OpenFromFile(comboBoxSource.Text, 0)); //IEnumDataset enumDataset = pWorkspace.get_Datasets(esriDatasetType.esriDTFeatureClass) as IEnumDataset; //IDataset dataset = enumDataset.Next(); ////遍历mdb的每一个独立要素类 //while (dataset != null) //{ // IFeatureClass pFeatureClass = dataset as IFeatureClass; // player = pFeatureClass.AliasName.Substring(15); //strExp = "select 描述 from 标准图层信息表 where 代码='" + player + "'"; //string playername = db.GetInfoFromMdbByExp(strCon, strExp); //if (playername != "") // player = playername; //datagwSource.Rows.Add(new object[] { true, pFeatureClass.AliasName, player }); //dataset = enumDataset.Next(); //} }
//开始分析 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); } }