📄 form_sde.cs
字号:
| System.Windows.Forms.AnchorStyles.Left)));
this.button_Cancel.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button_Cancel.Location = new System.Drawing.Point(168, 232);
this.button_Cancel.Name = "button_Cancel";
this.button_Cancel.Size = new System.Drawing.Size(48, 32);
this.button_Cancel.TabIndex = 8;
this.button_Cancel.Text = "取消";
this.button_Cancel.Click += new System.EventHandler(this.button_Cancel_Click);
//
// groupBox_Results
//
this.groupBox_Results.Controls.Add(this.listBox_DataFiles);
this.groupBox_Results.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.groupBox_Results.Location = new System.Drawing.Point(232, 8);
this.groupBox_Results.Name = "groupBox_Results";
this.groupBox_Results.Size = new System.Drawing.Size(224, 216);
this.groupBox_Results.TabIndex = 9;
this.groupBox_Results.TabStop = false;
this.groupBox_Results.Text = "数据库文件列表";
//
// listBox_DataFiles
//
this.listBox_DataFiles.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.listBox_DataFiles.ItemHeight = 14;
this.listBox_DataFiles.Location = new System.Drawing.Point(8, 24);
this.listBox_DataFiles.Name = "listBox_DataFiles";
this.listBox_DataFiles.Size = new System.Drawing.Size(208, 186);
this.listBox_DataFiles.TabIndex = 0;
//
// button_LoadFile
//
this.button_LoadFile.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.button_LoadFile.Enabled = false;
this.button_LoadFile.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button_LoadFile.Location = new System.Drawing.Point(392, 232);
this.button_LoadFile.Name = "button_LoadFile";
this.button_LoadFile.Size = new System.Drawing.Size(48, 32);
this.button_LoadFile.TabIndex = 10;
this.button_LoadFile.Text = "加载";
this.button_LoadFile.Click += new System.EventHandler(this.button_LoadFile_Click);
//
// label_Version
//
this.label_Version.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label_Version.Location = new System.Drawing.Point(8, 112);
this.label_Version.Name = "label_Version";
this.label_Version.Size = new System.Drawing.Size(64, 24);
this.label_Version.TabIndex = 11;
this.label_Version.Text = "版 本:";
//
// textBox_Version
//
this.textBox_Version.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.textBox_Version.Location = new System.Drawing.Point(72, 104);
this.textBox_Version.Name = "textBox_Version";
this.textBox_Version.Size = new System.Drawing.Size(144, 23);
this.textBox_Version.TabIndex = 12;
this.textBox_Version.Text = "SDE.DEFAULT";
//
// Form_SDE
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(464, 270);
this.Controls.Add(this.textBox_Version);
this.Controls.Add(this.label_Version);
this.Controls.Add(this.button_LoadFile);
this.Controls.Add(this.groupBox_Results);
this.Controls.Add(this.button_Cancel);
this.Controls.Add(this.button_Enter);
this.Controls.Add(this.groupBox_User);
this.Controls.Add(this.textBox_Instance);
this.Controls.Add(this.textBox_Database);
this.Controls.Add(this.textBox_Server);
this.Controls.Add(this.label_DatabaseName);
this.Controls.Add(this.label_InstanceName);
this.Controls.Add(this.label_ServerName);
this.Name = "Form_SDE";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "SDE连接";
this.groupBox_User.ResumeLayout(false);
this.groupBox_Results.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void textBox_Server_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar==(char)13)
{
textBox_Instance.Focus();
textBox_Instance.SelectAll();
}
}
private void textBox_Instance_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar==(char)13)
{
textBox_Database.Focus();
textBox_Database.SelectAll();
}
}
private void textBox_Database_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar==(char)13)
{
textBox_User.Focus();
textBox_User.SelectAll();
}
}
private void textBox_User_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar==(char)13)
{
textBox_Password.Focus();
textBox_Password.SelectAll();
}
}
public void SDEConnect() //采用SDE连接
{
//定义一个连接属性
IPropertySet Propset=new PropertySetClass();
//设置数据库服务器名
Propset.SetProperty("SERVER", textBox_Server.Text.ToString());
//设置SDE的端口,这是安装时指定的,默认安装时"port:5151"
Propset.SetProperty ("INSTANCE", textBox_Instance.Text.ToString());
//SDE的用户名
Propset.SetProperty ("USER", textBox_User.Text.ToString());
//密码
Propset.SetProperty ("PASSWORD", textBox_Password.Text.ToString());
//设置数据库的名字,只有SQL Server Informix 数据库才需要设置
Propset.SetProperty ("DATABASE", textBox_Database.Text.ToString());
//SDE的版本,在这为默认版本
Propset.SetProperty ("VERSION", textBox_Version.Text.ToString());
//实例化为SDE的工作空间
IWorkspaceFactory m_WorkspaceFactory = new SdeWorkspaceFactoryClass();
try
{
//打开SDE工作空间
m_SdeWorkSpace=m_WorkspaceFactory.Open(Propset,0);
}
catch(System.Runtime.InteropServices.COMException comExc)
{
MessageBox.Show(comExc.Message,"SDE.连接出错",MessageBoxButtons.OK,MessageBoxIcon.Stop);
return;
}
if(m_SdeWorkSpace != null) //SDE连接成功
{
IEnumDatasetName m_EnumDSName;
// m_EnumDSName=m_SdeWorkSpace.get_DatasetNames(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureDataset);
IDatasetName m_SdeDSName;
// m_SdeDSName=m_EnumDSName.Next();
//
// while (m_SdeDSName != null)
// {
// this.listBox_DataFiles.Items.Add(m_SdeDSName); //获取数据表名(esriDTFeatureDataset)
// m_SdeDSName=m_EnumDSName.Next();
// }
m_EnumDSName=m_SdeWorkSpace.get_DatasetNames(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass);
m_SdeDSName=m_EnumDSName.Next();
int i = 0;
while (m_SdeDSName != null)
{
i++;
this.listBox_DataFiles.Items.Add(m_SdeDSName.Name); //获取要素类名(esriDTFeatureClass)
m_SdeDSName=m_EnumDSName.Next();
}
if(i > 0) button_LoadFile.Enabled=true; //有数据库文件可以加载
}
else //SDE连接失败
{
MessageBox.Show("SDE连接不成功,请重试!","SDE.连接出错",MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
}
private void button_Enter_Click(object sender, System.EventArgs e) //确定按钮,开始连接SDE
{
SDEConnect();
}
private void button_Cancel_Click(object sender, System.EventArgs e) //取消,关闭窗体
{
this.Close();
}
private void button_LoadFile_Click(object sender, System.EventArgs e) //确认加载图层文件
{
if(listBox_DataFiles.SelectedIndex > -1)
{
IFeatureWorkspace m_FeatureWorkspace;
m_FeatureWorkspace=(IFeatureWorkspace)m_SdeWorkSpace; //将SDE工作空间转换成要素工作空间
IFeatureClass m_FeatureClass = m_FeatureWorkspace.OpenFeatureClass //打开要素类
(listBox_DataFiles.SelectedItem.ToString());
IFeatureLayer m_FeatureLayer = new FeatureLayerClass();
m_FeatureLayer.FeatureClass = m_FeatureClass;
m_MapControl.Map.AddLayer(m_FeatureLayer); //Layer加载
m_MapControl.ActiveView.Refresh();
}
}
private void textBox_Password_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
//回车确定
if(e.KeyChar == (char)Keys.Enter)
{
SDEConnect();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -