📄 clslinkattdatabase.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using System.Collections;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.GeoAnalyst;
using ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.Analyst3D;
using ESRI.ArcGIS.Analyst3DTools;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Output;
using ESRI.ArcGIS.DataSourcesRasterUI;
namespace EngineScene
{
public class ClsLinkAttDataBase //连接属性数据库
{
public string strSQL;
//与Oracle Server的连接字符串设置
public string p_ConnectionString;//="Data Source=orcl;User ID=u_runmon;Password=runmon;Unicode=True";
//与数据库的连接
public OracleConnection mConnection;
public OracleCommand mCommand;
public OracleDataAdapter mda;
[DllImport("kernel32")]
public static extern bool WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32")]
public static extern int GetPrivateProfileString(string section, string key, string def, byte[] retVal, int size, string filePath);
public ClsLinkAttDataBase()
{
string sdatasource = ReadString("PATH", "Database", Application.StartupPath);
String suser = ReadString("PATH", "User", Application.StartupPath);
String spassword = ReadString("PATH", "Password", Application.StartupPath);
p_ConnectionString = "Data Source=" + sdatasource + ";User ID=" + suser + ";Password=" + spassword + ";Unicode=True";
// TODO: 在此处添加构造函数逻辑
//
}
///////////////////////////////// 操作脱机数据库(创建了该类的实例时直接用) /////////////////////////////////////////////////////
//根据输入的SQL语句检索数据库数据
public DataSet SelectDataBase(string tempStrSQL, string tempTableName)
{
this.strSQL = tempStrSQL;
try
{
this.mConnection = new OracleConnection(this.p_ConnectionString);
this.mda = new OracleDataAdapter(this.strSQL, this.mConnection);
}
catch
{
MessageBox.Show("数据库连接失败");
Environment.Exit(0);
}
DataSet mds = new DataSet();
this.mda.Fill(mds, tempTableName);
this.mda = null;
this.mConnection.Close();
return mds;//返回填充了数据的DataSet,其中数据表以tempTableName给出的字符串命名
}
///////////////////////////////// 直接操作数据库(未创建该类的实例时直接用) /////////////////////////////////////////////////////
//数据库数据更新(传字符串,直接操作数据库)
public void UpdateDataBase(string tempStrSQL)
{
try
{
this.mConnection = new OracleConnection(this.p_ConnectionString);
//使用Command之前一定要先打开连接,后关闭连接,而DataAdapter则会自动打开关闭连接
this.mConnection.Open();
this.mCommand = new OracleCommand(tempStrSQL, this.mConnection);
mCommand.ExecuteNonQuery();//返回数据库中影响的行数
this.mCommand.Dispose();
this.mCommand = null;
this.mConnection.Close();
}
catch
{
MessageBox.Show("数据库连接失败");
Environment.Exit(0);
}
}
public OracleDateTime ReaderDataBase(string tempStrSQL)
{
try
{
this.mConnection = new OracleConnection(this.p_ConnectionString);
//使用Command之前一定要先打开连接,后关闭连接,而DataAdapter则会自动打开关闭连接
this.mConnection.Open();
this.mCommand = new OracleCommand(tempStrSQL, this.mConnection);
}
catch
{
MessageBox.Show("数据库连接失败");
Environment.Exit(0);
}
OracleDataReader reader = mCommand.ExecuteReader();
reader.Read();
OracleDateTime Nowtime = reader.GetOracleDateTime(0);
this.mCommand.Dispose();
this.mCommand = null;
this.mConnection.Close();
return Nowtime;
}
//读取ini文件
public string ReadString(string Section, string Ident, string Default)
{
Byte[] Buffer = new Byte[65535];
int bufLen = GetPrivateProfileString(Section, Ident, Default, Buffer, Buffer.GetUpperBound(0), Default + "\\path.ini");
//必须设定0(系统默认的代码页)的编码方式,否则无法支持中文
string s = Encoding.GetEncoding(0).GetString(Buffer);
s = s.Substring(0, bufLen);
return s.Trim();
}
public string Gettime()
{
String timeSQL = "select sysdate time from dual";//获取oracle数据库当前时间
OracleDateTime oracltime = ReaderDataBase(timeSQL);
DateTime dtime = (DateTime)oracltime;
String SNowtime = dtime.AddDays(-1).ToString("s");//日统计,获取前一天时间
//2009-01-05T
String dateSql = SNowtime.Substring(0, 4) + SNowtime.Substring(5, 2) + SNowtime.Substring(8, 2);
return dateSql;
}
public string Getmonth()
{
String timeSQL = "select sysdate time from dual";//获取oracle数据库当前时间
OracleDateTime oracltime = ReaderDataBase(timeSQL);
DateTime dtime = (DateTime)oracltime;
String SNowtime = dtime.AddMonths(-1).ToString("s");//月统计,获取前一个月时间
String dateSql = SNowtime.Substring(0, 4) + SNowtime.Substring(5, 2);
return dateSql;
}
public string Getmondate()
{
String timeSQL = "select sysdate time from dual";//获取oracle数据库当前时间
OracleDateTime oracltime = ReaderDataBase(timeSQL);
DateTime dtime = (DateTime)oracltime;
String SNowtime = dtime.AddDays(0).ToString("s");//月统计,获取前一个月时间
String dateSql =SNowtime.Substring(8, 2);
return dateSql;
}
public string Getyeardate()
{
String timeSQL = "select sysdate time from dual";//获取oracle数据库当前时间
OracleDateTime oracltime = ReaderDataBase(timeSQL);
DateTime dtime = (DateTime)oracltime;
String SNowtime = dtime.AddDays(0).ToString("s");//月统计,获取前一个月时间
String dateSql = SNowtime.Substring(5, 2) + SNowtime.Substring(8, 2);
return dateSql;
}
public string Getyear()
{
String timeSQL = "select sysdate time from dual";//获取oracle数据库当前时间
OracleDateTime oracltime = ReaderDataBase(timeSQL);
DateTime dtime = (DateTime)oracltime;
String SNowtime = dtime.AddYears(-1).ToString("s");//年统计,获取前一年时间
String dateSql = SNowtime.Substring(0, 4);
return dateSql;
}
public void addfield(int nTem1, String item, IFeatureClass pFC, DataTable WndTable10)
{
if (nTem1 == -1)
{
IField pField = new FieldClass();
IFieldEdit pFieldEdit = (IFieldEdit)pField;
pFieldEdit.AliasName_2 = item;
pFieldEdit.Name_2 = item;
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
pFC.AddField(pField);
pFieldEdit = null;
pField = null;
}
IFeature pFeature;
IFeatureCursor pFeatureCursor;
pFeatureCursor = pFC.Update(null, false);
if (item == "wpd")
{
item="wpowerdensity";
}
pFeature = pFeatureCursor.NextFeature();
while (pFeature != null)
{
for (int j = 0; j < WndTable10.Rows.Count; j++)
{
DataRow windRow = WndTable10.Rows[j];
if ((pFeature.get_Value(2).ToString().Trim() == windRow["STATIONNUM"].ToString().Trim()) && (windRow[item].ToString().Trim() != ""))
{
pFeature.set_Value(8, windRow[item].ToString().Trim());
pFeature.Store();
}
windRow = null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -