📄 frmmain.cs
字号:
System.Data.DataTable lyTypeTbl = this._environment.m_dataSet.Tables["地名类型"];
System.Data.DataRow[] rowsType = lyTypeTbl.Select();
foreach (System.Data.DataRow myRow in rowsType)
{
//加第1层
TreeNode node = new TreeNode(myRow[0].ToString());
node.Checked = true;
//加第2层
System.Data.DataTable subTypeTbl = this._environment.m_dataSet.Tables["地名中类型"];
System.Data.DataRow[] rowsSubTypes = subTypeTbl.Select("大类='"+myRow[0].ToString()+"'");
int []aIndex = new int[_environment.m_nLayerNum];
foreach (System.Data.DataRow myRow2 in rowsSubTypes)
{
string szSubType = myRow2["中类"].ToString();
TreeNode node2 = new TreeNode(szSubType);
node2.Checked = true;
//加第3层
int nCount = GetNodeArray2(aIndex,node.Text,szSubType);
if (nCount > 0)
{
TreeNode[] nodes = new TreeNode[nCount];
int count = 0;
for (int j = 0; j < nCount; j ++)
{
nodes[j] = new TreeNode( _environment.m_layerInfos[aIndex[j]].szName);
if (_environment.m_layerInfos[aIndex[j]].bVisible)
nodes[j].Checked = true;
else
nodes[j].Checked = false;
if (_environment.m_layerInfos[aIndex[j]].bCanControl)
{
node2.Nodes.Add(nodes[j]);
count ++;
}
}
if (0 == count)
continue;
}
else
{
continue;
}
node.Nodes.Add(node2);
node.Expand();
}
if (node.Nodes != null && node.Nodes.Count > 0 )
{
topNode.Nodes.Add(node);
topNode.Expand();
}
}
break;
case TVType.TV_Legend:
{
}
break;
default:
break;
}
}
private int GetNodeArray2(int []aIndex,string szType,string szSubType)
{
int nCount = 0;
for (int i = 0; i < _environment.m_nLayerNum; i ++)
{
if (_environment.m_layerInfos[i].szType .Equals(szType) && _environment.m_layerInfos[i].szSubType.Equals(szSubType))
{
aIndex[nCount] = new int();
aIndex[nCount] = i;
nCount ++;
}
}
return nCount;
}
/////////////////////////////////////////////////////////////////////////////
//功能:创建工作区
//参数:无
//返回值:void
protected void CreateWorkspace()
{
//创建地图选项卡
CreateMapOutlookBar();
//创建查询选项卡
CreateQueryOutlookBar();
// 设置两个选项卡
_cIndexWnd = _manager.Contents.Add(_mapOutlookBar, "地图",_imagesWorkspace,2);
_cQueryWnd = _manager.Contents.Add(_queryOutlookBar, "查询",_imagesWorkspace,1);
_cIndexWnd.CloseButton = false;
_cIndexWnd.HideButton =false;
_cIndexWnd.DisplaySize = new Size(this.Width/5 ,this.Height * 3 /4);
_cIndexWnd.Control.Width = this.Width/5;
_cQueryWnd.CloseButton = false;
_cQueryWnd.HideButton = false;
this.SuspendLayout();
// 将地图选项卡放置在工作区的左边
_wc = _manager.AddContentWithState(_cIndexWnd, State.DockRight) as WindowContent;
_manager.AddContentToWindowContent(_cQueryWnd, _wc);
_cQueryWnd.ParentWindowContent.ZoneArea = 125;
_mapEye = new AxMapObjects2.AxMap();
_cEyeWnd = _manager.Contents.Add(_mapEye);
_cEyeWnd.FullTitle = "缩略图";
_cEyeWnd.CloseButton = false;
_cEyeWnd.HideButton = false;
_cEyeWnd.DisplaySize = new Size(this.Width/5 ,this.Height /4);
//2003.3.16
this._mapEye.AfterLayerDraw += new AxMapObjects2._DMapEvents_AfterLayerDrawEventHandler(_mapEye_AfterLayerDraw);
this._mapEye.MouseUpEvent += new AxMapObjects2._DMapEvents_MouseUpEventHandler(_mapEye_MouseUpEvent);
_manager.AddContentToZone(_cEyeWnd, _wc.ParentZone , 1);
_cEyeWnd.ParentWindowContent.ZoneArea = 25;
this.ResumeLayout();
}
void CreateQueryOutlookBar()
{
// 创建查询选项卡
_queryOutlookBar = new OutlookBar();
// 在查询选项卡中加入面板控件
_queryOutlookBar.Bands.Add(new OutlookBarBand("地名索引", this._panelIndex));
_queryOutlookBar.Bands.Add(new OutlookBarBand("地名查询", this._panelQuery ));
_queryOutlookBar.Bands.Add(new OutlookBarBand("查找最近", this._panelDist ));
_queryOutlookBar.Bands.Add(new OutlookBarBand("公共交通查询", this._panelBus));
InitIndexPanel();
InitQueryPanel();
InitDistPanel();
InitBusPanel();
//创建Output窗口
_queryOutlookBar.Bands.Add(new OutlookBarBand("查询结果", this._panelOutput));
}
//2003.3.16
private void _mapEye_AfterLayerDraw(object sender, AxMapObjects2._DMapEvents_AfterLayerDrawEvent e)
{
if(e.index!=0)
return;
MapObjects2.Symbol sym = new MapObjects2.Symbol();
sym.OutlineColor = (uint)MapObjects2.ColorConstants.moRed ;
sym.Outline =true;
sym.SymbolType = MapObjects2.SymbolTypeConstants.moFillSymbol;
sym.Style = (short)MapObjects2.FillStyleConstants.moTransparentFill;
_mapEye.DrawShape(_map.Extent,sym);
}
//2003.3.16
private void _mapEye_MouseUpEvent(object sender, AxMapObjects2._DMapEvents_MouseUpEvent e)
{
MapObjects2.Symbol sym = new MapObjects2.Symbol();
sym.OutlineColor = (uint)MapObjects2.ColorConstants.moRed ;
sym.Outline =true;
sym.SymbolType = MapObjects2.SymbolTypeConstants.moFillSymbol;
sym.Style = (short)MapObjects2.FillStyleConstants.moTransparentFill;
MapObjects2.Point point;
point = _mapEye.ToMapPoint(e.x, e.y);
_map.CenterAt(point.X,point.Y);
_mapEye.Extent =_mapEye.Extent;
}
//Initialize
void Initialize()
{
_environment = new CEnvironment();
_environment.m_szSDBPath = Application.StartupPath + "\\电子地图\\";
_environment.m_szDBName = Application.StartupPath + "\\地名数据库.mdb";
_environment.m_AppPath =Application.StartupPath;
_environment.m_szHelpPath =Application.StartupPath + "\\帮助\\start.htm";
}
/// //////////////////////////////////////////////////////////////////////////////////////////
//功能:Load Data
//参数:void
//返回值:void
/// //////////////////////////////////////////////////////////////////////////////////////////
void LoadData()
{
CreateDataSet();
_environment.m_db = new MapObjects2.DataConnection();
_environment.m_db.Database = _environment.m_szSDBPath;
}
//Create DatabSet
void CreateDataSet()
{
string strConnectionString;
string strDatabasePath;
//Create connection string
strDatabasePath = Application.StartupPath;
strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + _environment.m_szDBName +
";Persist Security Info=False";
System.Data.OleDb.OleDbConnection myConnection = new System.Data.OleDb.OleDbConnection(strConnectionString);
try
{
myConnection.Open();
}
catch(System.InvalidOperationException myException)
{
MessageBox.Show(
"Message: " + myException.Message + "\n" +
"Source: " + myException.Source + "\n"
);
}
catch (System.Data.OleDb.OleDbException myException)
{
for (int i=0; i < myException.Errors.Count; i++)
{
MessageBox.Show("Index #" + i + "\n" +
"Message: " + myException.Errors[i].Message + "\n" +
"Native: " + myException.Errors[i].NativeError.ToString() + "\n" +
"Source: " + myException.Errors[i].Source + "\n" +
"SQL: " + myException.Errors[i].SQLState + "\n");
}
}
//创建数据库
//创建数据字典
_environment.m_dataSet = new System.Data.DataSet("地名数据库");
System.Data.OleDb.OleDbDataAdapter myDataAdapter = new System.Data.OleDb.OleDbDataAdapter("Select * From 地图集信息表",myConnection);
myDataAdapter.Fill(_environment.m_dataSet,"地图集信息表");
//创建地图集
System.Data.DataTable mapsTbl = this._environment.m_dataSet.Tables["地图集信息表"];
System.Data.DataRow[] rowsMaps = mapsTbl.Select();
_environment.m_nMapNum = rowsMaps.Length;
_environment.m_mapInfos = new MapInfo [_environment.m_nMapNum];
int nIndex = 0;
foreach (System.Data.DataRow myRow in rowsMaps)
{
string szTableName = myRow["表名"].ToString();
if (szTableName != "")
{
_environment.m_mapInfos[nIndex].szName = myRow["名称"].ToString();
_environment.m_mapInfos[nIndex].szMetaTable = szTableName;
_environment.m_mapInfos[nIndex].szIndexTable = myRow["索引表名"].ToString();
myDataAdapter.SelectCommand.CommandText = "Select * From " + szTableName + " Where 存在 = True Order By 显示次序1,显示次序2,id";
myDataAdapter.Fill(_environment.m_dataSet,szTableName);
if (_environment.m_mapInfos[nIndex].szIndexTable != "")
{
myDataAdapter.SelectCommand.CommandText = "Select * From " + _environment.m_mapInfos[nIndex].szIndexTable + " Order By id";
myDataAdapter.Fill(_environment.m_dataSet,_environment.m_mapInfos[nIndex].szIndexTable);
}
_environment.m_mapInfos[nIndex].rect = new MapObjects2.Rectangle();
_environment.m_mapInfos[nIndex].rect.Left = (double)myRow["X1"];
_environment.m_mapInfos[nIndex].rect.Top = (double)myRow["Y1"];
_environment.m_mapInfos[nIndex].rect.Right = (double)myRow["X2"];
_environment.m_mapInfos[nIndex].rect.Bottom = (double)myRow["Y2"];
nIndex ++;
}
}
_environment.m_nCurrMapIndex = 0;
myDataAdapter.SelectCommand.CommandText = "Select 大类 From 地名类型";
myDataAdapter.Fill(_environment.m_dataSet,"地名类型");
myDataAdapter.SelectCommand.CommandText = "Select * From 地名中类型";
myDataAdapter.Fill(_environment.m_dataSet,"地名中类型");
myDataAdapter.SelectCommand.CommandText = "Select * From 地名索引";
myDataAdapter.Fill(_environment.m_dataSet,"地名索引");
myDataAdapter.SelectCommand.CommandText = "Select distinct 线路名 From 公交车站路线 Order By 线路名";
myDataAdapter.Fill(_environment.m_dataSet,"公交线路");
myDataAdapter.SelectCommand.CommandText = "Select distinct 站名 From 公交车站路线 Order By 站名";
myDataAdapter.Fill(_environment.m_dataSet,"公交车站");
myDataAdapter.SelectCommand.CommandText = "Select * From 公交车站";
myDataAdapter.Fill(_environment.m_dataSet,"公交车站2");
myDataAdapter.SelectCommand.CommandText = "Select * From 公交车站路线 Order By 线路名";
myDataAdapter.Fill(_environment.m_dataSet,"公交车站路线");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -