152 lines
7.6 KiB
C#
152 lines
7.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using HZQR.Common;
|
|
|
|
namespace DataBaseTransfer
|
|
{
|
|
public partial class MainForm : Form
|
|
{
|
|
public MainForm()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void MainForm_Load(object sender, EventArgs e)
|
|
{
|
|
string OwnerName = ConfigurationManager.AppSettings["OwnerName"];
|
|
string _OracleConnStr = ConfigurationManager.AppSettings["OracleConnStr"];
|
|
string _OracleConnStrTemp = ConfigurationManager.AppSettings["OracleConnStrTemp"];
|
|
|
|
Method.OracleHelper oracleHelper = new Method.OracleHelper(_OracleConnStr.Split(',')[0], _OracleConnStr.Split(',')[1],
|
|
_OracleConnStr.Split(',')[2], _OracleConnStr.Split(',')[3], _OracleConnStr.Split(',')[4]);
|
|
Method.OracleHelper oracleHelperTemp = new Method.OracleHelper(_OracleConnStrTemp.Split(',')[0], _OracleConnStrTemp.Split(',')[1],
|
|
_OracleConnStrTemp.Split(',')[2], _OracleConnStrTemp.Split(',')[3], _OracleConnStrTemp.Split(',')[4]);
|
|
|
|
TransferData(OwnerName, oracleHelper, oracleHelperTemp);
|
|
//ModifySequence(OwnerName, oracleHelper, oracleHelperTemp);
|
|
Close();
|
|
}
|
|
|
|
public void TransferData(string OwnerName, Method.OracleHelper oracleHelper, Method.OracleHelper oracleHelperTemp)
|
|
{
|
|
int ExcuteCount;
|
|
string SQLString;
|
|
|
|
if (!string.IsNullOrWhiteSpace(OwnerName))
|
|
{
|
|
foreach (string Owner in OwnerName.Split(','))
|
|
{
|
|
LogUtil.WriteLog($"///------------开始执行【{ Owner }】用户数据同步------------///");
|
|
|
|
SQLString = $"SELECT TABLE_NAME FROM SYS.ALL_TABLES WHERE OWNER = '{ Owner }'";
|
|
DataTable dtTableName = oracleHelperTemp.ExcuteSqlGetDataTable(SQLString);
|
|
|
|
foreach (DataRow drTableName in dtTableName.Rows)
|
|
{
|
|
try
|
|
{
|
|
SQLString = $"DELETE FROM { Owner }.{ drTableName[0] }";
|
|
ExcuteCount = oracleHelper.ExcuteSql(SQLString);
|
|
LogUtil.WriteLog($"删除表【{ Owner }.{ drTableName[0] }】{ ExcuteCount }条记录");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogUtil.WriteLog(null, $"删除表【{ Owner }.{ drTableName[0] }】出现异常:{ ex.Message }",
|
|
DateTime.Now.ToString("yyyyMMdd") + "_Error");
|
|
|
|
SQLString = $@"CREATE TABLE { Owner }.{ drTableName[0] } AS
|
|
SELECT * FROM { Owner }.{ drTableName[0] }@ACT WHERE 1 = 2";
|
|
ExcuteCount = oracleHelper.ExcuteSql(SQLString);
|
|
LogUtil.WriteLog(null, $"重建表【{ Owner }.{ drTableName[0] }】{ ExcuteCount }条记录",
|
|
DateTime.Now.ToString("yyyyMMdd") + "_Rebuild");
|
|
}
|
|
|
|
try
|
|
{
|
|
SQLString = $@"INSERT INTO { Owner }.{ drTableName[0] }@ACT
|
|
SELECT * FROM { Owner }.{ drTableName[0] }";
|
|
ExcuteCount = oracleHelperTemp.ExcuteSql(SQLString);
|
|
LogUtil.WriteLog($"更新表【{ Owner }.{ drTableName[0] }】{ ExcuteCount }条记录");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogUtil.WriteLog(null, $"更新表【{ Owner }.{ drTableName[0] }】记录出现异常:{ ex.Message }",
|
|
DateTime.Now.ToString("yyyyMMdd") + "_Error");
|
|
|
|
SQLString = $"DROP TABLE { Owner }.{ drTableName[0] }";
|
|
ExcuteCount = oracleHelper.ExcuteSql(SQLString);
|
|
LogUtil.WriteLog(null, $"移除表【{ Owner }.{ drTableName[0] }】{ ExcuteCount }条记录",
|
|
DateTime.Now.ToString("yyyyMMdd") + "_Drop");
|
|
|
|
SQLString = $@"CREATE TABLE { Owner }.{ drTableName[0] } AS
|
|
SELECT * FROM { Owner }.{ drTableName[0] }@ACT WHERE 1 = 2";
|
|
ExcuteCount = oracleHelper.ExcuteSql(SQLString);
|
|
LogUtil.WriteLog(null, $"重建表【{ Owner }.{ drTableName[0] }】{ ExcuteCount }条记录",
|
|
DateTime.Now.ToString("yyyyMMdd") + "_Rebuild");
|
|
|
|
SQLString = $@"INSERT INTO { Owner }.{ drTableName[0] }@ACT
|
|
SELECT * FROM { Owner }.{ drTableName[0] }";
|
|
ExcuteCount = oracleHelperTemp.ExcuteSql(SQLString);
|
|
LogUtil.WriteLog($"更新表【{ Owner }.{ drTableName[0] }】{ ExcuteCount }条记录");
|
|
}
|
|
}
|
|
|
|
LogUtil.WriteLog($"///------------用户【{ Owner }】数据同步结束------------///");
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ModifySequence(string OwnerName, Method.OracleHelper oracleHelper, Method.OracleHelper oracleHelperTemp)
|
|
{
|
|
int ExcuteCount;
|
|
string SQLString;
|
|
|
|
if (!string.IsNullOrWhiteSpace(OwnerName))
|
|
{
|
|
foreach (string Owner in OwnerName.Split(','))
|
|
{
|
|
LogUtil.WriteLog($"///------------开始执行【{ Owner }】用户序列同步------------///");
|
|
|
|
SQLString = $"SELECT * FROM SYS.ALL_SEQUENCES WHERE SEQUENCE_OWNER = '{ Owner }'";
|
|
DataTable dtSequence = oracleHelperTemp.ExcuteSqlGetDataTable(SQLString);
|
|
|
|
foreach (DataRow drSequence in dtSequence.Rows)
|
|
{
|
|
try
|
|
{
|
|
SQLString = $@"DROP SEQUENCE { Owner }.{ drSequence["SEQUENCE_NAME"] }";
|
|
ExcuteCount = oracleHelper.ExcuteSql(SQLString);
|
|
LogUtil.WriteLog($"移除序列【{ Owner }.{ drSequence["SEQUENCE_NAME"] }】{ ExcuteCount }条记录");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogUtil.WriteLog(null, $"移除序列【{ Owner }.{ drSequence["SEQUENCE_NAME"] }】记录出现异常:{ ex.Message }",
|
|
DateTime.Now.ToString("yyyyMMdd") + "_Error");
|
|
}
|
|
|
|
SQLString = $@"CREATE SEQUENCE { Owner }.{ drSequence["SEQUENCE_NAME"] }
|
|
INCREMENT BY 1
|
|
START WITH { drSequence["LAST_NUMBER"] }
|
|
NOMAXVALUE
|
|
NOMINVALUE
|
|
NOCYCLE
|
|
CACHE 2
|
|
NOORDER";
|
|
ExcuteCount = oracleHelper.ExcuteSql(SQLString);
|
|
LogUtil.WriteLog(null, $"重建序列【{ Owner }.{ drSequence["SEQUENCE_NAME"] }】{ ExcuteCount }条记录",
|
|
DateTime.Now.ToString("yyyyMMdd") + "_Sequence");
|
|
}
|
|
|
|
LogUtil.WriteLog($"///------------用户【{ Owner }】序列同步结束------------///");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|