You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
149 lines
4.8 KiB
C#
149 lines
4.8 KiB
C#
// ***********************************************************************
|
|
// Assembly : Construction
|
|
// Author : flythink
|
|
// Created : 06-28-2020
|
|
//
|
|
// Last Modified By : flythink
|
|
// Last Modified On : 09-01-2020
|
|
// ***********************************************************************
|
|
// <copyright file="frmDBConnect.cs" company="jindongfang">
|
|
// Copyright (c) jindongfang. All rights reserved.
|
|
// </copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
|
|
namespace WellWorkDataUI.CustomControls
|
|
{
|
|
using System;
|
|
using System.Windows.Forms;
|
|
|
|
using WorkData;
|
|
|
|
/// <summary>
|
|
/// Class FrmDBConnect.
|
|
/// Implements the <see cref="System.Windows.Forms.Form" />
|
|
/// </summary>
|
|
/// <seealso cref="System.Windows.Forms.Form" />
|
|
public partial class FrmDBConnect : Form
|
|
{
|
|
private string dbType = string.Empty;
|
|
|
|
private FrmImportData frm = null;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="FrmDBConnect" /> class.
|
|
/// </summary>
|
|
public FrmDBConnect()
|
|
{
|
|
this.InitializeComponent();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="FrmDBConnect" /> class.
|
|
/// </summary>
|
|
/// <param name="frm">The FRM.</param>
|
|
/// <param name="dbType">Type of the database.</param>
|
|
public FrmDBConnect(object frm, string dbType)
|
|
{
|
|
this.InitializeComponent();
|
|
this.frm = (FrmImportData)frm;
|
|
this.dbType = dbType;
|
|
this.txtPwd.Properties.UseSystemPasswordChar = true;
|
|
|
|
if (dbType == "sqlserver")
|
|
{
|
|
this.txtIp.Text = this.frm.IpSqlServer;
|
|
this.txtDb.Text = this.frm.DbSqlServer;
|
|
this.txtUid.Text = this.frm.UidSqlServer;
|
|
this.txtPwd.Text = this.frm.PwdSqlServer;
|
|
}
|
|
else if (dbType == "oracle")
|
|
{
|
|
this.txtIp.Text = this.frm.IpOracle;
|
|
this.txtDb.Text = this.frm.DbOracle;
|
|
this.txtUid.Text = this.frm.UidOracle;
|
|
this.txtPwd.Text = this.frm.PwdOracle;
|
|
}
|
|
}
|
|
|
|
private void BtnConnect_Click(object sender, EventArgs e)
|
|
{
|
|
if (this.Check())
|
|
{
|
|
MessageBox.Show("连接成功", "提示");
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("连接失败", "提示");
|
|
}
|
|
}
|
|
|
|
private void BtnOk_Click(object sender, EventArgs e)
|
|
{
|
|
if (!this.Check())
|
|
{
|
|
MessageBox.Show("连接失败", "提示");
|
|
return;
|
|
}
|
|
|
|
this.DialogResult = DialogResult.OK;
|
|
}
|
|
|
|
private bool Check()
|
|
{
|
|
Server2008 dB_SQL = null;
|
|
Oracle10g dbOracle = null;
|
|
|
|
try
|
|
{
|
|
string ip = this.txtIp.Text.Trim();
|
|
string db = this.txtDb.Text.Trim();
|
|
string uid = this.txtUid.Text.Trim();
|
|
string pwd = this.txtPwd.Text.Trim();
|
|
string constr = string.Empty;
|
|
|
|
if (this.dbType == "sqlserver")
|
|
{
|
|
constr = "Data Source = " + ip + "; Initial Catalog = " + db + "; User ID = " + uid
|
|
+ "; Password = " + pwd + ";";
|
|
dB_SQL = new Server2008(constr);
|
|
dB_SQL.Dispose();
|
|
this.frm.IpSqlServer = ip;
|
|
this.frm.DbSqlServer = db;
|
|
this.frm.UidSqlServer = uid;
|
|
this.frm.PwdSqlServer = pwd;
|
|
}
|
|
else if (this.dbType == "oracle")
|
|
{
|
|
constr = "User ID=" + uid + ";Password=" + pwd
|
|
+ ";Data Source=(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST = " + ip
|
|
+ ")(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = " + db + ")))";
|
|
dbOracle = new Oracle10g(constr);
|
|
dbOracle.Dispose();
|
|
this.frm.IpOracle = ip;
|
|
this.frm.DbOracle = db;
|
|
this.frm.UidOracle = uid;
|
|
this.frm.PwdOracle = pwd;
|
|
}
|
|
|
|
this.frm.ConnectString = constr;
|
|
return true;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
if (dB_SQL != null)
|
|
{
|
|
dB_SQL.Dispose();
|
|
}
|
|
|
|
if (dbOracle != null)
|
|
{
|
|
dbOracle.Dispose();
|
|
}
|
|
|
|
Console.WriteLine(e.ToString());
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
} |