📄 oraconnection.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
using System.Windows.Forms;
namespace OracleDALGen.Classes.Database
{
[Serializable]
public class OraConnectionList : List<OraConnection>
{
private int defaultConnectionIdx = -1;
public static void Save(OraConnectionList list, string fileName)
{
using (Stream s = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(s, list);
}
}
public static OraConnectionList Load(string fileName)
{
OraConnectionList list = new OraConnectionList();
try
{
using (Stream s = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
BinaryFormatter formatter = new BinaryFormatter();
list = formatter.Deserialize(s) as OraConnectionList;
}
}
catch {}
return list;
}
public List<ListViewItem> GetListViewItems()
{
List<ListViewItem> lwi = new List<ListViewItem>();
foreach (OraConnection conn in this)
{
ListViewItem item = new ListViewItem(conn.Name);
item.SubItems.Add(conn.Host);
item.SubItems.Add(conn.Port.ToString());
item.SubItems.Add(conn.ServiceName);
item.SubItems.Add(conn.UserName);
item.SubItems.Add(conn.Password);
item.Tag = conn;
lwi.Add(item);
if ((lwi.Count - 1) == defaultConnectionIdx)
{
float size = 8.25f;
item.Font = new System.Drawing.Font("Microsoft Sans Serif", size, System.Drawing.FontStyle.Bold);
}
}
return lwi;
}
public int DefaultConnectionIndex
{
get { return defaultConnectionIdx; }
set { defaultConnectionIdx = value; }
}
}
[Serializable]
public class OraConnection
{
private string name;
private string host;
private int port;
private string serviceName;
private string userName;
private string password;
private string dwSchemaName;
private string metaSchemaName;
public OraConnection()
{
}
public OraConnection(string name, string host, int port, string serviceName, string userName, string password)
{
this.name = name;
this.host = host;
this.port = port;
this.serviceName = serviceName;
this.userName = userName;
this.password = password;
}
public string Name
{
get { return name; }
set { name = value; }
}
public string Host
{
get { return host; }
set { host = value; }
}
public int Port
{
get { return port; }
set { port = value; }
}
public string ServiceName
{
get { return serviceName; }
set { serviceName = value; }
}
public string UserName
{
get { return userName; }
set { userName = value; }
}
public string Password
{
get { return password; }
set { password = value; }
}
public string DwSchemaName
{
get
{
if (dwSchemaName.EndsWith("."))
return dwSchemaName;
else
return dwSchemaName + ".";
}
set { dwSchemaName = value; }
}
public string MetaSchemaName
{
get
{
if (metaSchemaName.EndsWith("."))
return metaSchemaName;
else
return metaSchemaName + ".";
}
set { metaSchemaName = value; }
}
public string ConnectionString {
get {
return string.Format("data source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = {0})(PORT = {1}))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = {2})));User ID={3};Password={4};", host, port, serviceName, userName, password);
}
}
public override string ToString()
{
return name;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -