ab56a9bcf7
SVN-Revision: r240
4371 lines
280 KiB
C#
4371 lines
280 KiB
C#
using DevExpress.Utils;
|
||
using DevExpress.XtraEditors.Controls;
|
||
using DevExpress.XtraEditors.Repository;
|
||
using DevExpress.XtraGrid;
|
||
using DevExpress.XtraGrid.Columns;
|
||
using Lskj.Control;
|
||
using MySql.Data.MySqlClient;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Data.SqlClient;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Text.RegularExpressions;
|
||
using System.Windows.Forms;
|
||
using static AFKAbutment.EnumClass;
|
||
|
||
namespace AFKAbutment
|
||
{
|
||
public partial class FrmMain : Form
|
||
{
|
||
public FrmMain(string[] args)
|
||
{
|
||
arg = args;
|
||
this.FormClosed += Form1_FormClosed;
|
||
this.KeyDown += Form1_KeyDown;
|
||
InitializeComponent();
|
||
}
|
||
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
|
||
{
|
||
if (thread != null)
|
||
{
|
||
thread.Abort();
|
||
}
|
||
this.Dispose();
|
||
this.Close();
|
||
}
|
||
|
||
public string[] arg;
|
||
public bool rightClickExecute = false;
|
||
public System.Threading.Thread thread = null;
|
||
public bool isStop = false;
|
||
|
||
public string sqlHelperConStr = "";
|
||
public string mySqlHelperConStr = "";
|
||
public int taskNum = 1;
|
||
public string separator = "Lserp$specialTag";//分割符
|
||
public List<System.Threading.Timer> timers = new List<System.Threading.Timer>();
|
||
|
||
//初始化
|
||
private void Form1_Load(object sender, EventArgs e)
|
||
{
|
||
this.startBtn.Appearance.BackColor = Color.FromArgb(140, 208, 1);
|
||
this.startBtn.MouseHover += new EventHandler(OnStartBtn_MouseHover);
|
||
this.startBtn.MouseLeave += new EventHandler(OnStartBtn_MouseLeave);
|
||
this.stopBtn.MouseHover += new EventHandler(OnStoptBtn_MouseHover);
|
||
this.stopBtn.MouseLeave += new EventHandler(OnStopBtn_MouseLeave);
|
||
|
||
//afk
|
||
afkSeverId.Text = IniHelper.Read("Setting.ini", "AFK", "serverName"); //地址
|
||
afkPortNumber.Text = IniHelper.Read("Setting.ini", "AFK", "port"); //端口
|
||
afkDataBase.Text = IniHelper.Read("Setting.ini", "AFK", "dbName");//数据库名
|
||
afkName.Text = IniHelper.Read("Setting.ini", "AFK", "user");//用户名
|
||
afkPassword.Text = IniHelper.Read("Setting.ini", "AFK", "password"); //密码
|
||
//ls
|
||
lsSeverId.Text = IniHelper.Read("Setting.ini", "LS", "serverName"); //地址
|
||
lsDataBase.Text = IniHelper.Read("Setting.ini", "LS", "dbName");//数据库名
|
||
lsName.Text = IniHelper.Read("Setting.ini", "LS", "user");//用户名
|
||
lsPassword.Text = IniHelper.Read("Setting.ini", "LS", "password"); //密码
|
||
//parameter
|
||
string time = IniHelper.Read("Setting.ini", "parameter", "time"); //间隔时间
|
||
if (string.IsNullOrEmpty(time)) time = "30";
|
||
if (Convert.ToInt32(time) < 30) time = "30";
|
||
intervalTime.Text = time;
|
||
intervalTime.LostFocus += new EventHandler(intervalTime_LostFocus);
|
||
if (arg.Length > 0)
|
||
{
|
||
if (arg[0].Equals("1"))
|
||
{
|
||
StartMethod();
|
||
}
|
||
}
|
||
InitializeDataSettings();
|
||
InitLsToAfkGrid();
|
||
InitAfkToLsGrid();
|
||
}
|
||
// <summary>
|
||
/// 时间间隔TextBox失去焦点事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void intervalTime_LostFocus(object sender, EventArgs e)
|
||
{
|
||
string checkStr = intervalTime.Text.ToString();
|
||
if (string.IsNullOrEmpty(checkStr)) intervalTime.Text = "30";
|
||
int check = Convert.ToInt32(intervalTime.Text.ToString());
|
||
if (check < 30)
|
||
{
|
||
intervalTime.Text = "30";
|
||
}
|
||
IniHelper.Write("parameter", "time", intervalTime.Text.ToString());
|
||
}
|
||
|
||
private async System.Threading.Tasks.Task StartMethod()
|
||
{
|
||
await System.Threading.Tasks.Task.Run(async () =>
|
||
{
|
||
try
|
||
{
|
||
RefreshLogUIThread(DateTime.Now + "正在初始化平台.\r\n");
|
||
//连接服务器
|
||
if (ConnectServer() && ConnectMySql())
|
||
{
|
||
RefreshLogUIThread(DateTime.Now + "初始化平台成功.\r\n");
|
||
|
||
//await this.SynchroDataSingleNormalDataFirst(DataDirection.AfkToLs);//先同步afk基础数据到朗速
|
||
SynchData synchData = new SynchData();
|
||
synchData.mysqlConnectionString = mySqlHelperConStr;
|
||
synchData.sqlServerConnectionString = sqlHelperConStr;
|
||
synchData.CreateAndSyncTable("LS_BillcoMaintab_Temp001", "LS_BillcoMaintab");
|
||
//this.SynchroDataSingleDateTimeSet(DataDirection.AfkToLs);
|
||
|
||
//this.SynchroDataSingleDateTimeSet(DataDirection.LsToAfk);
|
||
|
||
}
|
||
else
|
||
{
|
||
RefreshLogUIThread(DateTime.Now + " 初始化平台失败.\r\n");
|
||
thread = null;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
RefreshLogUIThread(DateTime.Now + string.Format("初始化失败.原因:{0}.\r\n", ex.Message));
|
||
}
|
||
});
|
||
}
|
||
private async void startBtn_Click(object sender, EventArgs e)
|
||
{
|
||
if (thread == null)
|
||
{
|
||
await StartMethod();
|
||
}
|
||
else
|
||
{
|
||
RefreshLogUIThread(string.Format("恢复同步,同步中……\r\n"));
|
||
isStop = false;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 重新开始同步
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void stopBtn_Click(object sender, EventArgs e)
|
||
{
|
||
isStop = true;
|
||
}
|
||
/// <summary>
|
||
/// 根据传入的列和值,转成数据库可以获取的值
|
||
/// </summary>
|
||
/// <param name="column"></param>
|
||
/// <param name="Value"></param>
|
||
/// <returns></returns>
|
||
public string GetTheRealValue(DataColumn column, string Value)
|
||
{
|
||
//如果数据源类型是bool,就替换成0(false)或1(true)
|
||
if (column.DataType == typeof(Boolean))
|
||
{
|
||
if (Value.Equals("true", StringComparison.OrdinalIgnoreCase))
|
||
{
|
||
Value = "1";
|
||
}
|
||
else
|
||
{
|
||
Value = "0";
|
||
}
|
||
}
|
||
if (column.DataType == typeof(int))
|
||
{
|
||
if (Value.Equals(""))
|
||
{
|
||
Value = "0";
|
||
}
|
||
}
|
||
if (Value.Equals(""))
|
||
{
|
||
Value = "null";
|
||
}
|
||
return Value;
|
||
}
|
||
#region 数据异步传递汇总
|
||
#region 同步数据单条执行
|
||
public void SynchroDataSingle(DataTable synchronousTable, DataDirection dataDirection, bool isRightStop = false)
|
||
{
|
||
string selectCond = string.Format("directionTag='{0}'", ((int)dataDirection));
|
||
DataRow[] performDr = synchronousTable.Select(selectCond);//需要执行的数据条数
|
||
RefreshLogUIThread(string.Format("开始从{0}获取数据:\r\n", dataDirection == 0 ? "中航爱福客" : "朗速"));
|
||
RefreshLogUIThread(string.Format("开始同步:\r\n"));
|
||
|
||
foreach (DataRow item in performDr)//循环需要同步的表
|
||
{
|
||
string[] targetStrs = (item["targetTabSql"] + "").ToLower().Split('^');//数据源字段解析
|
||
string[] synchroStrs = (item["synchroSql"] + "").ToLower().Split('^');//同步字段解析
|
||
string[] synLogStrs = (item["synLogSql"] + "").ToLower().Split('^');//同步日志表字段解析
|
||
string[] primaryKeys = null;
|
||
if (synchroStrs.Length == 4)
|
||
{
|
||
primaryKeys = synchroStrs[3].Replace(" ", "").Split('=');
|
||
}
|
||
#region 中航方相关信息
|
||
string afkTabName = dataDirection == 0 ? targetStrs[0].Replace(" ", "") : synchroStrs[0].Replace(" ", "");//表名
|
||
string afkTargeFields = dataDirection == 0 ? synchroStrs[2].Replace(" ", "") : synchroStrs[1].Replace(" ", "");//字段名
|
||
string afkPrimaryKey = dataDirection == 0 ? (primaryKeys != null && primaryKeys.Length == 2 ? primaryKeys[1] : "") : (primaryKeys != null && primaryKeys.Length == 2 ? primaryKeys[0] : "");
|
||
#endregion
|
||
#region 朗速方相关信息
|
||
string lsTabName = dataDirection == 0 ? synchroStrs[0].Replace(" ", "") : targetStrs[0].Replace(" ", "");
|
||
string lsTargeFields = dataDirection == 0 ? synchroStrs[1].Replace(" ", "") : synchroStrs[2].Replace(" ", "");
|
||
string lsPrimaryKey = dataDirection == 0 ? (primaryKeys != null && primaryKeys.Length == 2 ? primaryKeys[0] : "") : (primaryKeys != null && primaryKeys.Length == 2 ? primaryKeys[1] : "");
|
||
#endregion
|
||
#region 日志表相关信息
|
||
string logTabName = synLogStrs.Length == 3 ? synLogStrs[0].Replace(" ", "") : "";
|
||
string[] logFields = synLogStrs.Length == 3 ? synLogStrs[1].Replace(" ", "").Split(',') : null;
|
||
string[] logAsFields = synLogStrs.Length == 3 ? synLogStrs[2].Replace(" ", "").Split(',') : null;
|
||
string logSucceeId = "";
|
||
string logErrorType = "";
|
||
string logErrorMessage = "";
|
||
#endregion
|
||
#region 其他信息
|
||
string afterSql = (item["afterSql"] + "").ToLower();//同步完成后执行的sql
|
||
string disableFieids = (item["disableField"] + "").ToLower();//tagid是3或者4,指定字段改变
|
||
//数据库属性表
|
||
DataTable SQLQueryPropertySheet = SqlHelper.ExecuteDataTable(string.Format("select COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,IS_NULLABLE from information_schema.columns where table_name = '{0}'", lsTabName));
|
||
DataTable MYSQLPropertySheet = MySqlHelper.ExecuteDataTable(string.Format("show full columns from {0}", afkTabName));
|
||
#endregion
|
||
int ErrorNumber = 0;
|
||
try
|
||
{
|
||
string lsExistTagStr = string.Format(@"if not exists(select * from syscolumns
|
||
where id=object_id('{0}') and name='directTag')
|
||
begin
|
||
alter table {0} add directTag int
|
||
end", lsTabName);
|
||
SqlHelper.ExecuteNonQuery(lsExistTagStr);//判断朗速方是否存在同步完成字段
|
||
string afkExistTagStr = string.Format(@"select CASE when (select count(1)
|
||
FROM information_schema.COLUMNS
|
||
WHERE table_schema = '{0}'
|
||
and table_name = '{1}'
|
||
AND column_name = 'isSynchro') > 0
|
||
then '1'
|
||
else '2'
|
||
end
|
||
", afkDataBase.Text + "", afkTabName);
|
||
string afkExistResult = MySqlHelper.ExecuteScalar(afkExistTagStr) + "";//判断中航方有无标识列
|
||
if (afkExistResult.Equals("2"))
|
||
{
|
||
string afkAddTagStr = string.Format("alter table {0} add column isSynchro varchar(30);", afkTabName); //如果不存在则添加标识列
|
||
MySqlHelper.ExecuteNonQuery(afkAddTagStr);
|
||
}
|
||
//判断数据源是否有where条件,
|
||
string sourceWhereCond = string.Empty;//获取数据源where条件
|
||
if (targetStrs.Length == 1)
|
||
sourceWhereCond = dataDirection == 0 ? "where isSynchro=1" : " where directTag<>2";//数据源是afk则默认条件字段没有意义,数据源是ls则需获取默认条件字段不为2的数据
|
||
else
|
||
sourceWhereCond = string.Format(" where {0}", dataDirection == 0 ? targetStrs[1] + " and isSynchro=1 " : targetStrs[1]);
|
||
#region 获取数据源
|
||
//如果是ls获取数据,要先把数据源中当前的全部数据的isSynchro变为1
|
||
if (dataDirection == 0)
|
||
{
|
||
string conditions = string.Empty;
|
||
conditions = targetStrs.Length == 2 ? " where " + targetStrs[1] : "";
|
||
string sql = string.Format("update {0} set isSynchro='1' {1}", afkTabName, conditions);
|
||
MySqlHelper.ExecuteNonQuery(sql);
|
||
}
|
||
string sourceTabNale = dataDirection == 0 ? afkTabName : lsTabName;//数据源表名
|
||
string getSourceTabName = dataDirection == 0 ? lsTabName : afkTabName;//接受数据表表名
|
||
string sourceSelectFields = dataDirection == 0 ? afkTargeFields : lsTargeFields;//数据源字段
|
||
if (sourceSelectFields.Contains("getdate()"))//处理各种特殊字段
|
||
sourceSelectFields = sourceSelectFields.Replace("getdate()", dataDirection == 0 ? "now() as as_senddate" : "getdate() as as_senddate");
|
||
if (sourceSelectFields.Contains("#add$_"))
|
||
sourceSelectFields = sourceSelectFields.Replace("#add$_", "");
|
||
string selectSourceSql = string.Format("select {0} from {1}{2}", sourceSelectFields, sourceTabNale, sourceWhereCond);//查询数据源sql
|
||
DataTable sourceTab = dataDirection == 0 ? MySqlHelper.ExecuteDataTable(selectSourceSql) : SqlHelper.ExecuteDataTable(selectSourceSql);//获取数据源
|
||
#endregion
|
||
RefreshLogUIThread(string.Format("正在同步: {0} {2} >>>>> {1} {3}\r\n", dataDirection == 0 ? "中航爱福客" : "朗速", dataDirection == 0 ? "朗速" : "中航爱福客", dataDirection == 0 ? afkTabName : lsTabName, dataDirection == 0 ? lsTabName : afkTabName));
|
||
string modeOfOperation = sourceTab.Columns.Contains("tagid") ? "tagid" : sourceTab.Columns.Contains("tag_id") ? "tag_id" : "";//获取执方式的字段
|
||
string dataTransferSql = "";//执行数据传递sql
|
||
string dataTransferLogSql = "";//接收数据需要向中间表写日志
|
||
string lsErrorLogSqlStr = "";//朗速日志表
|
||
ErrorNumber = 0;
|
||
if (!string.IsNullOrEmpty(modeOfOperation))
|
||
{
|
||
IEnumerable<IGrouping<string, DataRow>> resultGroup = sourceTab.Rows.Cast<DataRow>().GroupBy<DataRow, string>(dr => dr[modeOfOperation] + "");//C# 对DataTable中的某列分组,result中的Key是分组后的值
|
||
foreach (IGrouping<string, DataRow> afkTagGroup in resultGroup)//按tagid分组
|
||
{
|
||
switch (afkTagGroup.Key)
|
||
{
|
||
case "1"://传递新增
|
||
#region 新增
|
||
foreach (DataRow sourceRow in afkTagGroup)
|
||
{
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
lsErrorLogSqlStr = "";
|
||
bool pushLog = false;
|
||
string getSourcePrimaryKey = dataDirection == 0 ? lsPrimaryKey : afkPrimaryKey;
|
||
string sourcePrimaryKey = dataDirection == 0 ? afkPrimaryKey : lsPrimaryKey;
|
||
string primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
string insertKeysStr = "";//insert语句keys
|
||
string insertValuesStr = "";//insert语句values
|
||
//判断是否有不能为空的数据
|
||
string SaveErrorMessage = IsValueBlank(SQLQueryPropertySheet, MYSQLPropertySheet, sourceRow, lsTargeFields, afkTargeFields, dataDirection);
|
||
if (!string.IsNullOrWhiteSpace(SaveErrorMessage))
|
||
{
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = SaveErrorMessage;
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, logErrorMessage);
|
||
continue;
|
||
}
|
||
try
|
||
{
|
||
string getSourceKeys = dataDirection == 0 ? lsTargeFields : afkTargeFields;//接收数据表字段
|
||
GetInsertSqlStr(sourceRow, getSourceKeys, afkTargeFields, getSourceTabName, out insertKeysStr, out insertValuesStr, out dataTransferSql, dataDirection);
|
||
if (dataDirection == 0 && IsExistPrimaryValue(sourceRow, getSourceTabName, getSourcePrimaryKey, sourcePrimaryKey, dataDirection))//朗速获取数据前应判断主键是否存在,执行前
|
||
{
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = string.Format("主键值{0}已存在", primaryValue);
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条增加" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "异常", string.Format("主键值{0}已存在", primaryValue), dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, logErrorMessage);
|
||
continue;
|
||
}
|
||
int result = dataDirection == 0 ? SqlHelper.ExecuteNonQuery(dataTransferSql) : MySqlHelper.ExecuteNonQuery(dataTransferSql);
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue) values ('{0}','{1}','{2}')", afkTabName, afkPrimaryKey, primaryValue);
|
||
if (dataDirection == DataDirection.AfkToLs)//接收数据时aftersql判断
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(afterSql))
|
||
{
|
||
DataTable afterTab = SqlHelper.ExecuteDataTable(ReplaceRowValue(afterSql, sourceRow));//执行成功失败
|
||
string execsql = "";
|
||
string type = "";
|
||
if (afterTab != null && afterTab.Rows.Count > 0)
|
||
{
|
||
DataRow afterRow = afterTab.Rows[0];
|
||
execsql = afterRow.Table.Columns.Contains("execsql") ? afterRow["execsql"] + "" : "";
|
||
type = afterRow.Table.Columns.Contains("type") ? afterRow["type"] + "" : "";
|
||
}
|
||
string afterReturnMsg = execsql;
|
||
if (afterReturnMsg.Equals("Exec_BillOutPush", StringComparison.CurrentCultureIgnoreCase))
|
||
{
|
||
afterReturnMsg = BillOutPush(sourceRow, type);
|
||
if (!string.IsNullOrWhiteSpace(afterSql) && string.IsNullOrEmpty(afterReturnMsg))//返回为空则成功
|
||
{
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
}
|
||
else if (!string.IsNullOrWhiteSpace(afterSql) && !string.IsNullOrEmpty(afterReturnMsg))
|
||
{
|
||
if (afterReturnMsg.Equals("99999"))
|
||
{
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = "未检测到明细表数据";
|
||
updateIssychro(sourceTabNale, sourcePrimaryKey, sourceRow);
|
||
pushLog = true;
|
||
continue;
|
||
}
|
||
logErrorMessage = afterReturnMsg;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条增加" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "正常", "", dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = ex.Message.Replace("'", "''");
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条增加" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "异常", ex.Message, dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
finally
|
||
{
|
||
try
|
||
{
|
||
//LS》AFK要处理双方数据的directTag问题
|
||
if (dataDirection == DataDirection.LsToAfk)
|
||
{
|
||
//把传输的数据directTag改为2
|
||
string sql = string.Format("update {0} set directTag='2' where {1}='{2}'", afkTabName, afkPrimaryKey, sourceRow[lsPrimaryKey.Trim()]);
|
||
MySqlHelper.ExecuteNonQuery(sql);
|
||
//把ls数据库中已经传输的数据directTag改为2
|
||
sql = string.Format("update {0} set directTag='2' where {1}='{2}'", lsTabName, lsPrimaryKey, sourceRow[lsPrimaryKey.Trim()]);
|
||
SqlHelper.ExecuteNonQuery(sql);//插入朗速日志表
|
||
}
|
||
#region 处理中间表写入日志
|
||
if (synLogStrs.Length == 3)
|
||
{
|
||
try
|
||
{
|
||
string[] logArgs = new string[] { logSucceeId, logErrorType, logErrorMessage };
|
||
GetLogSqlStr(logFields, logAsFields, logArgs, insertKeysStr, insertValuesStr, logTabName, out dataTransferLogSql);
|
||
if (!pushLog)
|
||
{
|
||
int logResult = dataDirection == 0 ? MySqlHelper.ExecuteNonQuery(dataTransferLogSql) : 0;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, ex.Message.Replace("'", "''"));
|
||
}
|
||
}
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr);//插入朗速日志表
|
||
#endregion
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
break;
|
||
case "2"://传递修改
|
||
#region 修改
|
||
if (dataDirection == 0)
|
||
{
|
||
#region 修改朗速为修改语句
|
||
foreach (DataRow sourceRow in afkTagGroup)
|
||
{
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
lsErrorLogSqlStr = "";
|
||
string getSourcePrimaryKey = dataDirection == 0 ? lsPrimaryKey : afkPrimaryKey;
|
||
string sourcePrimaryKey = dataDirection == 0 ? afkPrimaryKey : lsPrimaryKey;
|
||
string primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
string insertLogKeysStr = "";//insert日志语句keys
|
||
string insertLogValuesStr = "";//insert日志语句values
|
||
try
|
||
{
|
||
dataTransferSql = "update {0} set {1} where {2}";
|
||
string getSourceKeys = dataDirection == 0 ? lsTargeFields : afkTargeFields;//接收数据表字段
|
||
GetUpdateSqlStr(sourceRow, getSourceKeys, afkTargeFields, getSourceTabName, getSourcePrimaryKey, sourcePrimaryKey, out insertLogKeysStr, out insertLogValuesStr, out dataTransferSql);
|
||
int result = SqlHelper.ExecuteNonQuery(dataTransferSql);
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";//执行成功
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue) values ('{0}','{1}','{2}')", afkTabName, afkPrimaryKey, primaryValue);
|
||
if (dataDirection == DataDirection.AfkToLs)//接收数据时aftersql判断
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(afterSql))
|
||
{
|
||
DataTable afterTab = SqlHelper.ExecuteDataTable(ReplaceRowValue(afterSql, sourceRow));//执行成功失败
|
||
string execsql = "";
|
||
string type = "";
|
||
if (afterTab != null && afterTab.Rows.Count > 0)
|
||
{
|
||
DataRow afterRow = afterTab.Rows[0];
|
||
execsql = afterRow.Table.Columns.Contains("execsql") ? afterRow["execsql"] + "" : "";
|
||
type = afterRow.Table.Columns.Contains("type") ? afterRow["type"] + "" : "";
|
||
}
|
||
string afterReturnMsg = execsql;
|
||
if (afterReturnMsg.Equals("Exec_BillOutPush", StringComparison.CurrentCultureIgnoreCase))
|
||
{
|
||
afterReturnMsg = BillOutPush(sourceRow, type);
|
||
if (!string.IsNullOrWhiteSpace(afterSql) && string.IsNullOrEmpty(afterReturnMsg))//返回为空则成功
|
||
{
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
}
|
||
else if (!string.IsNullOrWhiteSpace(afterSql) && !string.IsNullOrEmpty(afterReturnMsg))
|
||
{
|
||
logErrorMessage = afterReturnMsg;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "正常", "", dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = ex.Message.Replace("'", "''");
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "异常", ex.Message, dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
finally
|
||
{
|
||
try
|
||
{
|
||
#region 处理中间表写入日志
|
||
if (synLogStrs.Length == 3 && dataDirection == 0)
|
||
{
|
||
try
|
||
{
|
||
string[] logArgs = new string[] { logSucceeId, logErrorType, logErrorMessage };
|
||
GetLogSqlStr(logFields, logAsFields, logArgs, insertLogKeysStr, insertLogValuesStr, logTabName, out dataTransferLogSql);
|
||
int logResult = MySqlHelper.ExecuteNonQuery(dataTransferLogSql);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, ex.Message.Replace("'", "''"));
|
||
}
|
||
}
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr);
|
||
#endregion
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
else
|
||
{
|
||
#region 修改爱福客为新增语句
|
||
foreach (DataRow sourceRow in afkTagGroup)
|
||
{
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
lsErrorLogSqlStr = "";
|
||
string getSourcePrimaryKey = dataDirection == 0 ? lsPrimaryKey : afkPrimaryKey;
|
||
string sourcePrimaryKey = dataDirection == 0 ? afkPrimaryKey : lsPrimaryKey;
|
||
string primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
string insertKeysStr = "";//insert语句keys
|
||
string insertValuesStr = "";//insert语句values
|
||
try
|
||
{
|
||
string getSourceKeys = dataDirection == 0 ? lsTargeFields : afkTargeFields;//接收数据表字段
|
||
GetInsertSqlStr(sourceRow, getSourceKeys, afkTargeFields, getSourceTabName, out insertKeysStr, out insertValuesStr, out dataTransferSql, dataDirection);
|
||
int result = MySqlHelper.ExecuteNonQuery(dataTransferSql);
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";//执行成功
|
||
// lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "正常", "", dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue) values ('{0}','{1}','{2}')", afkTabName, afkPrimaryKey, primaryValue);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = ex.Message.Replace("'", "''");
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "异常", ex.Message, dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, logErrorMessage);
|
||
|
||
}
|
||
finally
|
||
{
|
||
try
|
||
{
|
||
//LS》AFK要处理双方数据的directTag问题
|
||
//把传输的数据directTag改为2
|
||
string sql = string.Format("update {0} set directTag='2' where {1}='{2}'", afkTabName, afkPrimaryKey, sourceRow[lsPrimaryKey.Trim()]);
|
||
MySqlHelper.ExecuteNonQuery(sql);
|
||
//把ls数据库中已经传输的数据directTag改为2
|
||
sql = string.Format("update {0} set directTag='2' where {1}='{2}'", lsTabName, lsPrimaryKey, sourceRow[lsPrimaryKey.Trim()]);
|
||
SqlHelper.ExecuteNonQuery(sql);//插入朗速日志表
|
||
#region 处理中间表写入日志,向爱福客插入数据不需向中间表添加日志
|
||
//string[] logArgs = new string[] { logSucceeId, logErrorType, logErrorMessage };
|
||
//GetLogSqlStr(logFields, logAsFields, logArgs, insertKeysStr, insertValuesStr, logTabName, out dataTransferLogSql);
|
||
//int logResult = dataDirection == 0 ? MySqlHelper.ExecuteNonQuery(dataTransferLogSql) : 0;
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr); //插入朗速日志表
|
||
#endregion
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
#endregion
|
||
break;
|
||
case "3"://更改状态,禁用,上下架等
|
||
#region 更改状态,禁用,上下架等
|
||
if (dataDirection == 0)
|
||
{
|
||
#region 修改朗速为修改语句
|
||
foreach (DataRow sourceRow in afkTagGroup)
|
||
{
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
lsErrorLogSqlStr = "";
|
||
string getSourcePrimaryKey = dataDirection == 0 ? lsPrimaryKey : afkPrimaryKey;
|
||
string sourcePrimaryKey = dataDirection == 0 ? afkPrimaryKey : lsPrimaryKey;
|
||
string primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
string insertLogKeysStr = "";//insert日志语句keys
|
||
string insertLogValuesStr = "";//insert日志语句values
|
||
string[] disableFieidsArgs = disableFieids.Replace(" ", "").Split('^');
|
||
string stateField = disableFieidsArgs[0];//3对应第一个状态
|
||
try
|
||
{
|
||
dataTransferSql = "update {0} set {1} where {2}";
|
||
string getSourceKeys = dataDirection == 0 ? lsTargeFields : afkTargeFields;//接收数据表字段
|
||
GetChangeStateSqlStr(sourceRow, stateField, getSourceKeys, afkTargeFields, getSourceTabName, getSourcePrimaryKey, sourcePrimaryKey, out insertLogKeysStr, out insertLogValuesStr, out dataTransferSql);
|
||
int result = SqlHelper.ExecuteNonQuery(dataTransferSql);
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";//执行成功
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue) values ('{0}','{1}','{2}')", afkTabName, afkPrimaryKey, primaryValue);
|
||
if (dataDirection == DataDirection.AfkToLs)//接收数据时aftersql判断
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(afterSql))
|
||
{
|
||
DataTable afterTab = SqlHelper.ExecuteDataTable(ReplaceRowValue(afterSql, sourceRow));//执行成功失败
|
||
string execsql = "";
|
||
string type = "";
|
||
if (afterTab != null && afterTab.Rows.Count > 0)
|
||
{
|
||
DataRow afterRow = afterTab.Rows[0];
|
||
execsql = afterRow.Table.Columns.Contains("execsql") ? afterRow["execsql"] + "" : "";
|
||
type = afterRow.Table.Columns.Contains("type") ? afterRow["type"] + "" : "";
|
||
}
|
||
string afterReturnMsg = execsql;
|
||
if (afterReturnMsg.Equals("Exec_BillOutPush", StringComparison.CurrentCultureIgnoreCase))
|
||
{
|
||
afterReturnMsg = BillOutPush(sourceRow, type);
|
||
if (!string.IsNullOrWhiteSpace(afterSql) && string.IsNullOrEmpty(afterReturnMsg))//返回为空则成功
|
||
{
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
}
|
||
else if (!string.IsNullOrWhiteSpace(afterSql) && !string.IsNullOrEmpty(afterReturnMsg))
|
||
{
|
||
logErrorMessage = afterReturnMsg;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
}
|
||
}
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "正常", "", dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = ex.Message.Replace("'", "''");
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "异常", ex.Message, dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, logErrorMessage);
|
||
|
||
}
|
||
finally
|
||
{
|
||
try
|
||
{
|
||
#region 处理中间表写入日志
|
||
if (synLogStrs.Length == 3)
|
||
{
|
||
try
|
||
{
|
||
string[] logArgs = new string[] { logSucceeId, logErrorType, logErrorMessage };
|
||
GetLogSqlStr(logFields, logAsFields, logArgs, insertLogKeysStr, insertLogValuesStr, logTabName, out dataTransferLogSql);
|
||
#endregion
|
||
int logResult = MySqlHelper.ExecuteNonQuery(dataTransferLogSql);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, ex.Message.Replace("'", "''"));
|
||
}
|
||
}
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
else
|
||
{
|
||
#region 修改爱福客为新增语句
|
||
foreach (DataRow sourceRow in afkTagGroup)
|
||
{
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
lsErrorLogSqlStr = "";
|
||
string getSourcePrimaryKey = dataDirection == 0 ? lsPrimaryKey : afkPrimaryKey;
|
||
string sourcePrimaryKey = dataDirection == 0 ? afkPrimaryKey : lsPrimaryKey;
|
||
string primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
string insertKeysStr = "";//insert语句keys
|
||
string insertValuesStr = "";//insert语句values
|
||
try
|
||
{
|
||
string getSourceKeys = dataDirection == 0 ? lsTargeFields : afkTargeFields;//接收数据表字段
|
||
GetInsertSqlStr(sourceRow, getSourceKeys, afkTargeFields, getSourceTabName, out insertKeysStr, out insertValuesStr, out dataTransferSql, dataDirection);
|
||
int result = MySqlHelper.ExecuteNonQuery(dataTransferSql);
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";//执行成功
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "正常", "", dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue) values ('{0}','{1}','{2}')", afkTabName, afkPrimaryKey, primaryValue);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = ex.Message.Replace("'", "''");
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "异常", ex.Message, dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, logErrorMessage);
|
||
|
||
}
|
||
finally
|
||
{
|
||
try
|
||
{
|
||
//LS》AFK要处理双方数据的directTag问题
|
||
//把传输的数据directTag改为2
|
||
string sql = string.Format("update {0} set directTag='2' where {1}='{2}'", afkTabName, afkPrimaryKey, sourceRow[lsPrimaryKey.Trim()]);
|
||
MySqlHelper.ExecuteNonQuery(sql);
|
||
//把ls数据库中已经传输的数据directTag改为2
|
||
sql = string.Format("update {0} set directTag='2' where {1}='{2}'", lsTabName, lsPrimaryKey, sourceRow[lsPrimaryKey.Trim()]);
|
||
SqlHelper.ExecuteNonQuery(sql);//插入朗速日志表
|
||
#region 处理中间表写入日志,向爱福客插入数据不需向中间表添加日志
|
||
//string[] logArgs = new string[] { logSucceeId, logErrorType, logErrorMessage };
|
||
//GetLogSqlStr(logFields, logAsFields, logArgs, insertKeysStr, insertValuesStr, logTabName, out dataTransferLogSql);
|
||
//int logResult = dataDirection == 0 ? MySqlHelper.ExecuteNonQuery(dataTransferLogSql) : 0;
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr); //插入朗速日志表
|
||
#endregion
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
#endregion
|
||
break;
|
||
case "4":
|
||
#region 更改状态,禁用,上下架等
|
||
if (dataDirection == 0)
|
||
{
|
||
#region 修改朗速为修改语句
|
||
foreach (DataRow sourceRow in afkTagGroup)
|
||
{
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
lsErrorLogSqlStr = "";
|
||
string getSourcePrimaryKey = dataDirection == 0 ? lsPrimaryKey : afkPrimaryKey;
|
||
string sourcePrimaryKey = dataDirection == 0 ? afkPrimaryKey : lsPrimaryKey;
|
||
string primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
string insertLogKeysStr = "";//insert日志语句keys
|
||
string insertLogValuesStr = "";//insert日志语句values
|
||
string[] disableFieidsArgs = disableFieids.Replace(" ", "").Split('^');
|
||
string stateField = disableFieidsArgs[1];//4对应第二个状态
|
||
try
|
||
{
|
||
dataTransferSql = "update {0} set {1} where {2}";
|
||
string getSourceKeys = dataDirection == 0 ? lsTargeFields : afkTargeFields;//接收数据表字段
|
||
GetChangeStateSqlStr(sourceRow, stateField, getSourceKeys, afkTargeFields, getSourceTabName, getSourcePrimaryKey, sourcePrimaryKey, out insertLogKeysStr, out insertLogValuesStr, out dataTransferSql);
|
||
int result = SqlHelper.ExecuteNonQuery(dataTransferSql);
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";//执行成功
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue) values ('{0}','{1}','{2}')", afkTabName, afkPrimaryKey, primaryValue);
|
||
if (dataDirection == DataDirection.AfkToLs)//接收数据时aftersql判断
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(afterSql))
|
||
{
|
||
DataTable afterTab = SqlHelper.ExecuteDataTable(ReplaceRowValue(afterSql, sourceRow));//执行成功失败
|
||
string execsql = "";
|
||
string type = "";
|
||
if (afterTab != null && afterTab.Rows.Count > 0)
|
||
{
|
||
DataRow afterRow = afterTab.Rows[0];
|
||
execsql = afterRow.Table.Columns.Contains("execsql") ? afterRow["execsql"] + "" : "";
|
||
type = afterRow.Table.Columns.Contains("type") ? afterRow["type"] + "" : "";
|
||
}
|
||
string afterReturnMsg = execsql;
|
||
if (afterReturnMsg.Equals("Exec_BillOutPush", StringComparison.CurrentCultureIgnoreCase))
|
||
{
|
||
afterReturnMsg = BillOutPush(sourceRow, type);
|
||
if (!string.IsNullOrWhiteSpace(afterSql) && string.IsNullOrEmpty(afterReturnMsg))//返回为空则成功
|
||
{
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
}
|
||
else if (!string.IsNullOrWhiteSpace(afterSql) && !string.IsNullOrEmpty(afterReturnMsg))
|
||
{
|
||
logErrorMessage = afterReturnMsg;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
}
|
||
}
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "正常", "", dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = ex.Message.Replace("'", "''");
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "异常", ex.Message, dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
finally
|
||
{
|
||
try
|
||
{
|
||
#region 处理中间表写入日志
|
||
if (synLogStrs.Length == 3)
|
||
{
|
||
try
|
||
{
|
||
string[] logArgs = new string[] { logSucceeId, logErrorType, logErrorMessage };
|
||
GetLogSqlStr(logFields, logAsFields, logArgs, insertLogKeysStr, insertLogValuesStr, logTabName, out dataTransferLogSql);
|
||
#endregion
|
||
int logResult = MySqlHelper.ExecuteNonQuery(dataTransferLogSql);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, ex.Message.Replace("'", "''"));
|
||
}
|
||
}
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
else
|
||
{
|
||
#region 修改爱福客为新增语句
|
||
foreach (DataRow sourceRow in afkTagGroup)
|
||
{
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
lsErrorLogSqlStr = "";
|
||
string getSourcePrimaryKey = dataDirection == 0 ? lsPrimaryKey : afkPrimaryKey;
|
||
string sourcePrimaryKey = dataDirection == 0 ? afkPrimaryKey : lsPrimaryKey;
|
||
string primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
string insertKeysStr = "";//insert语句keys
|
||
string insertValuesStr = "";//insert语句values
|
||
try
|
||
{
|
||
string getSourceKeys = dataDirection == 0 ? lsTargeFields : afkTargeFields;//接收数据表字段
|
||
GetInsertSqlStr(sourceRow, getSourceKeys, afkTargeFields, getSourceTabName, out insertKeysStr, out insertValuesStr, out dataTransferSql, dataDirection);
|
||
int result = MySqlHelper.ExecuteNonQuery(dataTransferSql);
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";//执行成功
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "正常", "", dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue) values ('{0}','{1}','{2}')", afkTabName, afkPrimaryKey, primaryValue);
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = ex.Message.Replace("'", "''");
|
||
// lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "异常", ex.Message, dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, logErrorMessage);
|
||
|
||
}
|
||
finally
|
||
{
|
||
try
|
||
{
|
||
//LS》AFK要处理双方数据的directTag问题
|
||
//把传输的数据directTag改为2
|
||
string sql = string.Format("update {0} set directTag='2' where {1}='{2}'", afkTabName, afkPrimaryKey, sourceRow[lsPrimaryKey.Trim()]);
|
||
MySqlHelper.ExecuteNonQuery(sql);
|
||
//把ls数据库中已经传输的数据directTag改为2
|
||
sql = string.Format("update {0} set directTag='2' where {1}='{2}'", lsTabName, lsPrimaryKey, sourceRow[lsPrimaryKey.Trim()]);
|
||
SqlHelper.ExecuteNonQuery(sql);//插入朗速日志表
|
||
#region 处理中间表写入日志,向爱福客插入数据不需向中间表添加日志
|
||
//string[] logArgs = new string[] { logSucceeId, logErrorType, logErrorMessage };
|
||
//GetLogSqlStr(logFields, logAsFields, logArgs, insertKeysStr, insertValuesStr, logTabName, out dataTransferLogSql);
|
||
//int logResult = dataDirection == 0 ? MySqlHelper.ExecuteNonQuery(dataTransferLogSql) : 0;
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr); //插入朗速日志表
|
||
#endregion
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
#endregion
|
||
break;
|
||
case ""://没有可执行的操作
|
||
#region 没有可执行的操作
|
||
foreach (DataRow sourceRow in afkTagGroup)
|
||
{
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
lsErrorLogSqlStr = "";
|
||
string getSourcePrimaryKey = dataDirection == 0 ? lsPrimaryKey : afkPrimaryKey;
|
||
string sourcePrimaryKey = dataDirection == 0 ? afkPrimaryKey : lsPrimaryKey;
|
||
string primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
string insertKeysStr = "";//insert语句keys
|
||
string insertValuesStr = "";//insert语句values
|
||
try
|
||
{
|
||
string getSourceKeys = dataDirection == 0 ? lsTargeFields : afkTargeFields;//接收数据表字段
|
||
GetInsertSqlStr(sourceRow, getSourceKeys, afkTargeFields, getSourceTabName, out insertKeysStr, out insertValuesStr, out dataTransferSql, dataDirection);
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = string.Format("{0}为空,没有可执行的操作", modeOfOperation);
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条增加" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "异常", string.Format("{0}为空,没有可执行的操作", modeOfOperation), dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = ex.Message.Replace("'", "''");
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条增加" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "异常", ex.Message, dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
finally
|
||
{
|
||
try
|
||
{
|
||
#region 处理中间表写入日志
|
||
if (synLogStrs.Length == 3)
|
||
{
|
||
try
|
||
{
|
||
string[] logArgs = new string[] { logSucceeId, logErrorType, logErrorMessage };
|
||
GetLogSqlStr(logFields, logAsFields, logArgs, insertKeysStr, insertValuesStr, logTabName, out dataTransferLogSql);
|
||
int logResult = dataDirection == 0 ? MySqlHelper.ExecuteNonQuery(dataTransferLogSql) : 0;
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr);//插入朗速日志表
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, ex.Message.Replace("'", "''"));
|
||
}
|
||
}
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr);
|
||
#endregion
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
#region 没有标识字段默认新增
|
||
foreach (DataRow sourceRow in sourceTab.Rows)
|
||
{
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
lsErrorLogSqlStr = "";
|
||
string getSourcePrimaryKey = dataDirection == 0 ? lsPrimaryKey : afkPrimaryKey;
|
||
string sourcePrimaryKey = dataDirection == 0 ? afkPrimaryKey : lsPrimaryKey;
|
||
string primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
string insertKeysStr = "";//insert语句keys
|
||
string insertValuesStr = "";//insert语句values
|
||
try
|
||
{
|
||
string getSourceKeys = dataDirection == 0 ? lsTargeFields : afkTargeFields;//接收数据表字段
|
||
GetInsertSqlStr(sourceRow, getSourceKeys, afkTargeFields, getSourceTabName, out insertKeysStr, out insertValuesStr, out dataTransferSql, dataDirection);
|
||
int result = dataDirection == 0 ? SqlHelper.ExecuteNonQuery(dataTransferSql) : MySqlHelper.ExecuteNonQuery(dataTransferSql);
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";//执行成功
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue) values ('{0}','{1}','{2}')", afkTabName, afkPrimaryKey, primaryValue);
|
||
if (dataDirection == DataDirection.AfkToLs)//接收数据时aftersql判断
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(afterSql))
|
||
{
|
||
DataTable afterTab = SqlHelper.ExecuteDataTable(ReplaceRowValue(afterSql, sourceRow));//执行成功失败
|
||
string execsql = "";
|
||
string type = "";
|
||
if (afterTab != null && afterTab.Rows.Count > 0)
|
||
{
|
||
DataRow afterRow = afterTab.Rows[0];
|
||
execsql = afterRow.Table.Columns.Contains("execsql") ? afterRow["execsql"] + "" : "";
|
||
type = afterRow.Table.Columns.Contains("type") ? afterRow["type"] + "" : "";
|
||
}
|
||
string afterReturnMsg = execsql;
|
||
if (afterReturnMsg.Equals("Exec_BillOutPush", StringComparison.CurrentCultureIgnoreCase))
|
||
{
|
||
afterReturnMsg = BillOutPush(sourceRow, type);
|
||
if (!string.IsNullOrWhiteSpace(afterSql) && string.IsNullOrEmpty(afterReturnMsg))//返回为空则成功
|
||
{
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
}
|
||
else if (!string.IsNullOrWhiteSpace(afterSql) && !string.IsNullOrEmpty(afterReturnMsg))
|
||
{
|
||
logErrorMessage = afterReturnMsg;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
}
|
||
}
|
||
// lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条增加" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "正常", "", dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = ex.Message.Replace("'", "''");
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条增加" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "异常", ex.Message, dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
finally
|
||
{
|
||
try
|
||
{
|
||
#region 处理中间表写入日志
|
||
if (synLogStrs.Length == 3)
|
||
{
|
||
try
|
||
{
|
||
string[] logArgs = new string[] { logSucceeId, logErrorType, logErrorMessage };
|
||
GetLogSqlStr(logFields, logAsFields, logArgs, insertKeysStr, insertValuesStr, logTabName, out dataTransferLogSql);
|
||
int logResult = dataDirection == 0 ? MySqlHelper.ExecuteNonQuery(dataTransferLogSql) : 0;
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr);//插入朗速日志表
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", afkTabName, afkPrimaryKey, primaryValue, ex.Message.Replace("'", "''"));
|
||
}
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr);
|
||
}
|
||
#endregion
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
//删除
|
||
if (dataDirection == 0)
|
||
{
|
||
string deleteSql = string.Format("delete from {0} where isSynchro='1'", afkTabName);
|
||
MySqlHelper.ExecuteNonQuery(deleteSql);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
try
|
||
{
|
||
string direction = dataDirection == 0 ? "朗速获取AFK数据错误" : "AFK获取朗速数据错误";
|
||
string sql = string.Format("insert into P_RemarkTable(LsTableName,Messages) values ('{0}','{1}')", lsTabName, direction + ":" + ex.Message.Replace("'", "''") + "");
|
||
SqlHelper.ExecuteNonQuery(sql);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
finally
|
||
{
|
||
RefreshLogUIThread("同步完成,失败条数:" + ErrorNumber + "\r\n");
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
#region 同步到朗速数据特殊批量执行方法(单据等需要存储过程判断)
|
||
public async System.Threading.Tasks.Task SynchroToLsBatch(DataRow[] items, DataDirection dataDirection)
|
||
{
|
||
await System.Threading.Tasks.Task.Run(async () =>
|
||
{
|
||
try
|
||
{
|
||
NSqlHelper SqlHelper = new NSqlHelper(new SqlConnection(sqlHelperConStr));
|
||
try
|
||
{
|
||
DataRow[] firstItems = items.Where(n => (n["isBefore"] + "").Equals("true")).ToArray();
|
||
DataRow[] afterItems = items.Where(n => (n["isBatch"] + "").Equals("true")).ToArray();
|
||
string uuid = System.Guid.NewGuid().ToString("N");
|
||
Dictionary<DataRow, AbutmentModel> itemModel = new Dictionary<DataRow, AbutmentModel>();//记录行与模型的关系
|
||
StringBuilder changeSynchroTagSql = new StringBuilder();
|
||
foreach (DataRow item in items)//批量时统一改变同步标记
|
||
{
|
||
string sql = GetChangeSynchroTagSql(item, dataDirection);
|
||
if (!string.IsNullOrEmpty(sql))
|
||
{
|
||
changeSynchroTagSql.Append(sql + ";\r\n");
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(changeSynchroTagSql.ToString())) MySqlHelper.ExecuteNonQuery(changeSynchroTagSql.ToString());
|
||
foreach (DataRow item in firstItems)//同步提前数据
|
||
{
|
||
AbutmentModel rtnAbutmentModel = await SynchroDataSingleAsync(item, dataDirection, uuid);
|
||
itemModel.Add(item, rtnAbutmentModel);
|
||
}
|
||
foreach (DataRow item in afterItems)//同步批量数据
|
||
{
|
||
AbutmentModel rtnAbutmentModel = await SynchroDataSingleAsync(item, dataDirection, uuid);
|
||
itemModel.Add(item, rtnAbutmentModel);
|
||
}
|
||
foreach (DataRow item in afterItems)//执行批量存储过程
|
||
{
|
||
ExecBatchAfterSql(item, dataDirection, uuid, itemModel);
|
||
}
|
||
foreach (DataRow item in afterItems)//同步批量日志数据
|
||
{
|
||
await SynchroDataSingleAsync(item, dataDirection, uuid, itemModel, true);
|
||
}
|
||
foreach (DataRow item in afterItems)//删除临时表数据
|
||
{
|
||
DeleteTempTabData(item, dataDirection, uuid, itemModel);
|
||
}
|
||
//同步完成后执行afterSql
|
||
DataTable dt = SqlHelper.ExecuteDataTable("select * from p_synchrTab where id='9999999'");
|
||
if (dt != null && dt.Rows.Count > 0)
|
||
{
|
||
string afterSql = dt.Rows[0]["afterSql"] + "";//同步完成后执行的sql
|
||
if (!string.IsNullOrWhiteSpace(afterSql)) SqlHelper.ExecuteNonQuery(afterSql);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
try
|
||
{
|
||
string direction = "循环进程执行错误";
|
||
string sql = string.Format("insert into P_RemarkTable(LsTableName,Messages) values ('{0}','{1}')", "", direction + ":" + ex.Message.Replace("'", "''") + "");
|
||
SqlHelper.ExecuteNonQuery(sql);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
finally
|
||
{
|
||
if (SqlHelper._connection != null)
|
||
{
|
||
SqlHelper._connection.Close();
|
||
SqlHelper._connection.Dispose();
|
||
SqlHelper = null;
|
||
}
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
finally
|
||
{
|
||
}
|
||
System.Threading.Timer timer = DateTimeUtil.SetTimeOut((o) =>
|
||
{
|
||
SynchroToLsBatch(items, dataDirection);
|
||
//NSqlHelper NSqlHelper = new NSqlHelper(new SqlConnection(sqlHelperConStr));
|
||
//try
|
||
//{
|
||
// foreach (DataRow item in items)//同步批量数据
|
||
// {
|
||
// await SynchroDataSingleAsync(item, dataDirection);
|
||
// }
|
||
// foreach (DataRow item in items)//同步批量日志数据
|
||
// {
|
||
// await SynchroDataSingleAsync(item, dataDirection, true);
|
||
// }
|
||
// //同步完成后执行afterSql
|
||
// DataTable dt = NSqlHelper.ExecuteDataTable("select * from p_synchrTab where id='9999999'");
|
||
// if (dt != null && dt.Rows.Count > 0)
|
||
// {
|
||
// string afterSql = dt.Rows[0]["afterSql"] + "";//同步完成后执行的sql
|
||
// if (!string.IsNullOrWhiteSpace(afterSql)) SqlHelper.ExecuteNonQuery(afterSql);
|
||
// }
|
||
//}
|
||
//finally
|
||
//{
|
||
// if (NSqlHelper._connection != null)
|
||
// {
|
||
// NSqlHelper._connection.Close();
|
||
// NSqlHelper._connection.Dispose();
|
||
// NSqlHelper = null;
|
||
// }
|
||
//}
|
||
}, Convert.ToInt32(intervalTime.Text) * 1000);
|
||
timers.Add(timer);
|
||
});
|
||
}
|
||
#endregion
|
||
#region 同步批量数据按顺序执行.isBatch=false
|
||
private async System.Threading.Tasks.Task SynchroToLsNoBatch(DataRow item, DataDirection dataDirection)
|
||
{
|
||
await SynchroDataNormal(item, dataDirection);
|
||
}
|
||
#endregion
|
||
public async System.Threading.Tasks.Task SynchroDataNormal(DataRow item, DataDirection dataDirection)
|
||
{
|
||
await System.Threading.Tasks.Task.Run(async () =>
|
||
{
|
||
try
|
||
{
|
||
string uuid = System.Guid.NewGuid().ToString("N");
|
||
await SynchroDataSingleAsync(item, dataDirection, uuid);
|
||
if (dataDirection == 0)
|
||
{
|
||
NSqlHelper SqlHelper = new NSqlHelper(new SqlConnection(sqlHelperConStr));
|
||
//同步完成后执行afterSql
|
||
try
|
||
{
|
||
DataTable dt = SqlHelper.ExecuteDataTable("select * from p_synchrTab where id='9999999'");
|
||
if (dt != null && dt.Rows.Count > 0)
|
||
{
|
||
string afterSql = dt.Rows[0]["afterSql"] + "";//同步完成后执行的sql
|
||
if (!string.IsNullOrWhiteSpace(afterSql)) SqlHelper.ExecuteNonQuery(afterSql);
|
||
}
|
||
SqlHelper._connection.Close();
|
||
SqlHelper._connection.Dispose();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
try
|
||
{
|
||
string direction = "单条进程执行错误";
|
||
string sql = string.Format("insert into P_RemarkTable(LsTableName,Messages) values ('{0}','{1}')", "", direction + ":" + ex.Message.Replace("'", "''") + "");
|
||
SqlHelper.ExecuteNonQuery(sql);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
finally
|
||
{
|
||
if (SqlHelper._connection != null)
|
||
{
|
||
SqlHelper._connection.Close();
|
||
SqlHelper._connection.Dispose();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
finally
|
||
{
|
||
}
|
||
System.Threading.Timer timer = DateTimeUtil.SetTimeOut((o) =>
|
||
{
|
||
SynchroDataNormal(item, dataDirection);
|
||
//await SynchroDataSingleAsync(item, dataDirection);
|
||
//if (dataDirection == 0)
|
||
//{
|
||
// NSqlHelper SSqlHelper = new NSqlHelper(new SqlConnection(sqlHelperConStr));
|
||
// try//同步完成后执行afterSql
|
||
// {
|
||
// DataTable dt = SqlHelper.ExecuteDataTable("select * from p_synchrTab where id='9999999'");
|
||
// if (dt != null && dt.Rows.Count > 0)
|
||
// {
|
||
// string afterSql = dt.Rows[0]["afterSql"] + "";//同步完成后执行的sql
|
||
// if (!string.IsNullOrWhiteSpace(afterSql)) SqlHelper.ExecuteNonQuery(afterSql);
|
||
// }
|
||
// SSqlHelper._connection.Close();
|
||
// SSqlHelper._connection.Dispose();
|
||
// }
|
||
// catch (Exception)
|
||
// {
|
||
// if (SSqlHelper._connection != null)
|
||
// {
|
||
// SSqlHelper._connection.Close();
|
||
// SSqlHelper._connection.Dispose();
|
||
// }
|
||
// }
|
||
//}
|
||
}, Convert.ToInt32(intervalTime.Text) * 1000);
|
||
timers.Add(timer);
|
||
});
|
||
}
|
||
|
||
#region 同步数据异步执行
|
||
/// <summary>
|
||
/// 同步数据异步执行
|
||
/// </summary>
|
||
/// <param name="dataDirection"></param>
|
||
/// <returns></returns>
|
||
public async System.Threading.Tasks.Task SynchroDataSingleDateTimeSet(DataDirection dataDirection)
|
||
{
|
||
NSqlHelper SqlHelper = new NSqlHelper(new SqlConnection(sqlHelperConStr));
|
||
|
||
DataTable dataDirectTable = dataDirection == 0 ? SqlHelper.ExecuteDataTable("select * from p_synchrTab where disableTag='true' and directionTag='0' ORDER BY id") : SqlHelper.ExecuteDataTable("select * from p_synchrTab where disableTag='true' and directionTag='1' ORDER BY id");// and id in(38,39)
|
||
string selectCond = string.Format("directionTag='{0}'", ((int)dataDirection));
|
||
|
||
DataRow[] PerformDr = dataDirectTable.Select(selectCond);//需要执行的数据条数
|
||
RefreshLogUIThread(string.Format("开始从{0}获取数据:\r\n", dataDirection == 0 ? "中航爱福客" : "朗速"));
|
||
RefreshLogUIThread(string.Format("开始同步:\r\n"));
|
||
|
||
if (dataDirection == 0) //同步到ls
|
||
{
|
||
DataRow[] batchRow = PerformDr.Where(n => (n["isBatch"] + "").Equals("true") || (n["isBefore"] + "").Equals("true")).ToArray();
|
||
DataRow[] normalRow = PerformDr.Where(n => !(n["isBatch"] + "").Equals("true") && !(n["isBefore"] + "").Equals("true")).ToArray();
|
||
|
||
SynchroToLsBatch(batchRow, dataDirection);//同步特殊批量数据
|
||
foreach (DataRow item in normalRow)
|
||
{
|
||
SynchroDataNormal(item, dataDirection);//同步普通数据
|
||
}
|
||
}
|
||
else//同步到afk
|
||
{
|
||
foreach (DataRow item in PerformDr)//同步普通数据
|
||
{
|
||
SynchroDataNormal(item, dataDirection);
|
||
}
|
||
}
|
||
SqlHelper._connection.Close();
|
||
SqlHelper._connection.Dispose();
|
||
}
|
||
//多任务处理_批量
|
||
public async System.Threading.Tasks.Task<AbutmentModel> SynchroDataSingleAsync(DataRow item, DataDirection dataDirection, string uuid, Dictionary<DataRow, AbutmentModel> itemModel = null, bool isBatchLog = false)
|
||
{
|
||
NMySqlHelper MySqlHelper = new NMySqlHelper(new MySqlConnection(mySqlHelperConStr));
|
||
NSqlHelper SqlHelper = new NSqlHelper(new SqlConnection(sqlHelperConStr));
|
||
|
||
List<System.Threading.Tasks.Task> tasks = new List<System.Threading.Tasks.Task>();
|
||
string logSucceeId = "1";
|
||
string logErrorType = "0";
|
||
string logErrorMessage = "";
|
||
int ErrorNumber = 0;
|
||
AbutmentModel abutmentModel = null;
|
||
if (itemModel != null && itemModel.ContainsKey(item))
|
||
{
|
||
abutmentModel = itemModel[item];
|
||
}
|
||
else
|
||
{
|
||
abutmentModel = new AbutmentModel(item, dataDirection, this.afkDataBase.Text + "", sqlHelperConStr, mySqlHelperConStr);
|
||
}
|
||
abutmentModel.uuid = uuid;
|
||
if (dataDirection == 0)
|
||
{
|
||
RefreshLogUIAddRow(AfkToLsGrid, abutmentModel.id);
|
||
}
|
||
else
|
||
{
|
||
RefreshLogUIAddRow(LsToAfkGrid, abutmentModel.id);
|
||
}
|
||
try
|
||
{
|
||
string lsExistTagStr = string.Format(@"if not exists(select * from syscolumns
|
||
where id=object_id('{0}') and name='directTag')
|
||
begin
|
||
alter table {0} add directTag int
|
||
end", abutmentModel.lsTabName);
|
||
SqlHelper.ExecuteNonQuery(lsExistTagStr);//判断朗速方是否存在同步完成字段
|
||
string afkExistTagStr = string.Format(@"select CASE when (select count(1)
|
||
FROM information_schema.COLUMNS
|
||
WHERE table_schema = '{0}'
|
||
and table_name = '{1}'
|
||
AND column_name = 'isSynchro') > 0
|
||
then '1'
|
||
else '2'
|
||
end
|
||
", afkDataBase.Text + "", abutmentModel.afkTabName);
|
||
string afkExistResult = MySqlHelper.ExecuteScalar(afkExistTagStr) + "";//判断中航方有无标识列
|
||
if (afkExistResult.Equals("2"))
|
||
{
|
||
string afkAddTagStr = string.Format("alter table {0} add column isSynchro varchar(30);", abutmentModel.afkTabName); //如果不存在则添加标识列
|
||
MySqlHelper.ExecuteNonQuery(afkAddTagStr);
|
||
}
|
||
//if (dataDirection == 0 && !isBatchLog)//如果是ls获取数据,要先把数据源中当前的全部数据的isSynchro变为1
|
||
//{
|
||
// string conditions = string.Empty;
|
||
// conditions = abutmentModel.targetStrs.Length == 2 ? " where " + abutmentModel.targetStrs[1] : "";
|
||
// string sql = string.Format("update {0} set isSynchro='1' {1}", abutmentModel.afkTabName, conditions);
|
||
// MySqlHelper.ExecuteNonQuery(sql);
|
||
//}
|
||
if (!isBatchLog)
|
||
{
|
||
if (dataDirection == 0)
|
||
{
|
||
RefreshLogUIThread(this.AfkToLsGrid, abutmentModel.id, "direction", "Afk to Ls");
|
||
RefreshLogUIThread(this.AfkToLsGrid, abutmentModel.id, "tabName", string.Format("{0} to {1}", abutmentModel.afkTabName, abutmentModel.lsTabName));
|
||
}
|
||
else
|
||
{
|
||
RefreshLogUIThread(this.LsToAfkGrid, abutmentModel.id, "direction", "Ls to Afk");
|
||
RefreshLogUIThread(this.LsToAfkGrid, abutmentModel.id, "tabName", string.Format("{0} to {1}", abutmentModel.lsTabName, abutmentModel.afkTabName));
|
||
}
|
||
//RefreshLogUIThread(string.Format("正在同步: {0} {2} >>>>> {1} {3}\r\n", dataDirection == 0 ? "中航爱福客" : "朗速", dataDirection == 0 ? "朗速" : "中航爱福客", dataDirection == 0 ? abutmentModel.afkTabName : abutmentModel.lsTabName, dataDirection == 0 ? abutmentModel.lsTabName : abutmentModel.afkTabName));
|
||
}
|
||
else
|
||
{
|
||
if (dataDirection == 0)
|
||
{
|
||
RefreshLogUIThread(this.AfkToLsGrid, abutmentModel.id, "direction", "Afk to Ls");
|
||
RefreshLogUIThread(this.AfkToLsGrid, abutmentModel.id, "tabName", string.Format("日志表{0}", abutmentModel.logTabName));
|
||
}
|
||
else
|
||
{
|
||
RefreshLogUIThread(this.LsToAfkGrid, abutmentModel.id, "direction", "Ls to Afk");
|
||
RefreshLogUIThread(this.LsToAfkGrid, abutmentModel.id, "tabName", string.Format("日志表{0}", abutmentModel.logTabName));
|
||
}
|
||
//RefreshLogUIThread(string.Format("正在同步: {0} {2} >>>>> {1} 日志表: {3}\r\n", dataDirection == 0 ? "中航爱福客" : "朗速", dataDirection == 0 ? "朗速" : "中航爱福客", dataDirection == 0 ? abutmentModel.afkTabName : abutmentModel.lsTabName, dataDirection == 0 ? abutmentModel.lsTabName : abutmentModel.logTabName));
|
||
}
|
||
string modeOfOperation = abutmentModel.sourceTab.Columns.Contains("tagid") ? "tagid" : abutmentModel.sourceTab.Columns.Contains("tag_id") ? "tag_id" : "";//获取执方式的字段
|
||
string dataTransferSql = "";//执行数据传递sql
|
||
string dataTransferLogSql = "";//接收数据需要向中间表写日志
|
||
string lsErrorLogSqlStr = "";//朗速日志表
|
||
if (!string.IsNullOrEmpty(modeOfOperation))
|
||
{
|
||
IEnumerable<IGrouping<string, DataRow>> resultGroup = abutmentModel.sourceTab.Rows.Cast<DataRow>().OrderBy<DataRow, string>(dr => dr[modeOfOperation] + "").GroupBy<DataRow, string>(dr => dr[modeOfOperation] + "");//C# 对DataTable中的某列分组,result中的Key是分组后的值
|
||
if (dataDirection == 0 && abutmentModel.isBatch)//批量逻辑
|
||
{
|
||
foreach (IGrouping<string, DataRow> afkTagGroup in resultGroup)
|
||
{
|
||
switch (afkTagGroup.Key)
|
||
{
|
||
case "1"://传递新增
|
||
case "2"://传递修改,新增到copy表后存储过程处理
|
||
StringBuilder getDataSql = new StringBuilder();
|
||
StringBuilder getDataLogSql = new StringBuilder();
|
||
if (!isBatchLog)
|
||
{
|
||
int result = 0;
|
||
foreach (DataRow sourceRow in afkTagGroup)
|
||
{
|
||
var task = GetDataBatch(abutmentModel, item, sourceRow, dataDirection, 1, ErrorNumber);
|
||
tasks.Add(task);
|
||
if (tasks.Count >= 500)
|
||
{
|
||
while (tasks.Count > 0)
|
||
{
|
||
System.Threading.Tasks.Task getTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
System.Threading.Tasks.Task<string> finishedTask = getTask as System.Threading.Tasks.Task<string>;
|
||
if (!string.IsNullOrEmpty(finishedTask.Result))
|
||
{
|
||
getDataSql.Append(string.Format("{0};\r\n", finishedTask.Result));
|
||
}
|
||
tasks.Remove(getTask);
|
||
getTask.Dispose();
|
||
}
|
||
try
|
||
{
|
||
if (!string.IsNullOrEmpty(getDataSql.ToString()))
|
||
{
|
||
result = SqlHelper.ExecuteNonQuery(getDataSql.ToString());
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
try
|
||
{
|
||
string direction = dataDirection == 0 ? "朗速获取AFK数据错误" : "AFK获取朗速数据错误";
|
||
string sql = string.Format("insert into P_RemarkTable(LsTableName,Messages) values ('{0}','{1}')", abutmentModel.lsTabName, direction + ":" + ex.Message.Replace("'", "''") + "");
|
||
SqlHelper.ExecuteNonQuery(sql);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
getDataSql = new StringBuilder();
|
||
}
|
||
}
|
||
while (tasks.Count > 0)
|
||
{
|
||
System.Threading.Tasks.Task getTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
System.Threading.Tasks.Task<string> finishedTask = getTask as System.Threading.Tasks.Task<string>;
|
||
if (!string.IsNullOrEmpty(finishedTask.Result))
|
||
{
|
||
getDataSql.Append(string.Format("{0};\r\n", finishedTask.Result));
|
||
}
|
||
tasks.Remove(getTask);
|
||
getTask.Dispose();
|
||
}
|
||
try
|
||
{
|
||
if (!string.IsNullOrEmpty(getDataSql.ToString()))
|
||
{
|
||
result = SqlHelper.ExecuteNonQuery(getDataSql.ToString());
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
try
|
||
{
|
||
string direction = dataDirection == 0 ? "朗速获取AFK数据错误" : "AFK获取朗速数据错误";
|
||
string sql = string.Format("insert into P_RemarkTable(LsTableName,Messages) values ('{0}','{1}')", abutmentModel.lsTabName, direction + ":" + ex.Message.Replace("'", "''") + "");
|
||
SqlHelper.ExecuteNonQuery(sql);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
getDataSql = new StringBuilder();
|
||
try
|
||
{
|
||
if (dataDirection == 0 && !string.IsNullOrEmpty(abutmentModel.afterSql))
|
||
{
|
||
SqlHelper.ExecuteNonQuery(abutmentModel.afterSql);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
try
|
||
{
|
||
string direction = dataDirection == 0 ? "朗速获取AFK数据AFTERSQL错误" : "AFK获取朗速AFTERSQL数据错误";
|
||
string sql = string.Format("insert into P_RemarkTable(LsTableName,Messages) values ('{0}','{1}')", abutmentModel.lsTabName, direction + ":" + ex.Message.Replace("'", "''") + "");
|
||
SqlHelper.ExecuteNonQuery(sql);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
}
|
||
else//写入日志
|
||
{
|
||
string selectResultSql = string.Format("select {0},synchroSuccess,synchroMessage,suuid from {1} where uuid = '{2}'", abutmentModel.lsPrimaryKey, abutmentModel.lsTempTabName, abutmentModel.uuid);
|
||
DataTable selectLogTab = SqlHelper.ExecuteDataTable(selectResultSql);
|
||
foreach (DataRow sourceRow in afkTagGroup)
|
||
{
|
||
string afkPrimaryValue = "";
|
||
DataRow selectLogRow = null;
|
||
try
|
||
{
|
||
afkPrimaryValue = sourceRow["suuid"] + "";
|
||
selectLogRow = selectLogTab.Select().Where(n => (n["suuid"] + "").Equals(afkPrimaryValue)).FirstOrDefault();
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
var task = GetDataLogBatch(abutmentModel, selectLogRow, item, sourceRow, dataDirection, ErrorNumber);
|
||
tasks.Add(task);
|
||
if (tasks.Count >= 500)
|
||
{
|
||
while (tasks.Count > 0)
|
||
{
|
||
System.Threading.Tasks.Task getTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
System.Threading.Tasks.Task<string> finishedTask = getTask as System.Threading.Tasks.Task<string>;
|
||
if (!string.IsNullOrEmpty(finishedTask.Result))
|
||
{
|
||
getDataLogSql.Append(string.Format("{0};\r\n", finishedTask.Result));
|
||
}
|
||
tasks.Remove(getTask);
|
||
getTask.Dispose();
|
||
}
|
||
try
|
||
{
|
||
if (!string.IsNullOrEmpty(getDataLogSql.ToString()))
|
||
{
|
||
int result = MySqlHelper.ExecuteNonQuery(getDataLogSql.ToString());
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
try
|
||
{
|
||
string direction = dataDirection == 0 ? "朗速获取AFK数据错误" : "AFK获取朗速数据错误";
|
||
string sql = string.Format("insert into P_RemarkTable(LsTableName,Messages) values ('{0}','{1}')", abutmentModel.lsTabName, direction + ":" + ex.Message.Replace("'", "''") + "");
|
||
SqlHelper.ExecuteNonQuery(sql);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
getDataLogSql = new StringBuilder();
|
||
}
|
||
}
|
||
while (tasks.Count > 0)
|
||
{
|
||
System.Threading.Tasks.Task getTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
System.Threading.Tasks.Task<string> finishedTask = getTask as System.Threading.Tasks.Task<string>;
|
||
if (!string.IsNullOrEmpty(finishedTask.Result))
|
||
{
|
||
getDataLogSql.Append(string.Format("{0};\r\n", finishedTask.Result));
|
||
}
|
||
tasks.Remove(getTask);
|
||
getTask.Dispose();
|
||
}
|
||
try
|
||
{
|
||
if (!string.IsNullOrEmpty(getDataLogSql.ToString()))
|
||
{
|
||
int result = MySqlHelper.ExecuteNonQuery(getDataLogSql.ToString());
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
try
|
||
{
|
||
string direction = dataDirection == 0 ? "朗速获取AFK数据错误" : "AFK获取朗速数据错误";
|
||
string sql = string.Format("insert into P_RemarkTable(LsTableName,Messages) values ('{0}','{1}')", abutmentModel.lsTabName, direction + ":" + ex.Message.Replace("'", "''") + "");
|
||
SqlHelper.ExecuteNonQuery(sql);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
getDataLogSql = new StringBuilder();
|
||
}
|
||
break;
|
||
default:
|
||
#region 其他情况使用单条处理模式
|
||
if (isBatchLog)//写日志时增加后执行修改
|
||
{
|
||
foreach (DataRow sourceRow in afkTagGroup)
|
||
{
|
||
int index = abutmentModel.sourceTab.Rows.IndexOf(sourceRow);
|
||
var task = SendDataSingle(abutmentModel, item, dataDirection, sourceRow, ErrorNumber, modeOfOperation, afkTagGroup.Key, index);
|
||
tasks.Add(task);
|
||
if (tasks.Count >= taskNum)
|
||
{
|
||
System.Threading.Tasks.Task finishTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
tasks.Remove(finishTask);
|
||
finishTask.Dispose();
|
||
}
|
||
}
|
||
while (tasks.Count > 0)
|
||
{
|
||
System.Threading.Tasks.Task finishTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
tasks.Remove(finishTask);
|
||
finishTask.Dispose();
|
||
}
|
||
}
|
||
#endregion
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
foreach (IGrouping<string, DataRow> afkTagGroup in resultGroup)//按tagid分组
|
||
{
|
||
switch (afkTagGroup.Key)
|
||
{
|
||
case "1"://传递新增
|
||
#region 新增
|
||
if (!string.IsNullOrEmpty(abutmentModel.batchAfterSql))
|
||
{
|
||
int result = 0;
|
||
StringBuilder insertSql = new StringBuilder();
|
||
foreach (DataRow sourceRow in afkTagGroup)
|
||
{
|
||
var task = GetDataBatch(abutmentModel, item, sourceRow, dataDirection, 1, ErrorNumber);
|
||
tasks.Add(task);
|
||
if (tasks.Count >= 500)
|
||
{
|
||
while (tasks.Count > 0)
|
||
{
|
||
System.Threading.Tasks.Task getTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
System.Threading.Tasks.Task<string> finishedTask = getTask as System.Threading.Tasks.Task<string>;
|
||
if (!string.IsNullOrEmpty(finishedTask.Result))
|
||
{
|
||
insertSql.Append(string.Format("{0};\r\n", finishedTask.Result));
|
||
}
|
||
tasks.Remove(getTask);
|
||
getTask.Dispose();
|
||
}
|
||
try
|
||
{
|
||
if (!string.IsNullOrEmpty(insertSql.ToString()))
|
||
{
|
||
result = SqlHelper.ExecuteNonQuery(insertSql.ToString());
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
try
|
||
{
|
||
string direction = dataDirection == 0 ? "朗速获取AFK数据错误" : "AFK获取朗速数据错误";
|
||
string sql = string.Format("insert into P_RemarkTable(LsTableName,Messages) values ('{0}','{1}')", abutmentModel.lsTabName, direction + ":" + ex.Message.Replace("'", "''") + "");
|
||
SqlHelper.ExecuteNonQuery(sql);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
insertSql = new StringBuilder();
|
||
}
|
||
}
|
||
while (tasks.Count > 0)
|
||
{
|
||
System.Threading.Tasks.Task getTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
System.Threading.Tasks.Task<string> finishedTask = getTask as System.Threading.Tasks.Task<string>;
|
||
if (!string.IsNullOrEmpty(finishedTask.Result))
|
||
{
|
||
insertSql.Append(string.Format("{0};\r\n", finishedTask.Result));
|
||
}
|
||
tasks.Remove(getTask);
|
||
getTask.Dispose();
|
||
}
|
||
try
|
||
{
|
||
if (!string.IsNullOrEmpty(insertSql.ToString()))
|
||
{
|
||
result = SqlHelper.ExecuteNonQuery(insertSql.ToString());
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
insertSql = new StringBuilder();
|
||
StringBuilder getDataLogSql = new StringBuilder();
|
||
try//执行aftersql
|
||
{
|
||
if (dataDirection == 0 && !string.IsNullOrEmpty(abutmentModel.afterSql))
|
||
{
|
||
SqlHelper.ExecuteNonQuery(abutmentModel.afterSql);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
try
|
||
{
|
||
string direction = dataDirection == 0 ? "朗速获取AFK数据AFTERSQL错误" : "AFK获取朗速AFTERSQL数据错误";
|
||
string sql = string.Format("insert into P_RemarkTable(LsTableName,Messages) values ('{0}','{1}')", abutmentModel.lsTabName, direction + ":" + ex.Message.Replace("'", "''") + "");
|
||
SqlHelper.ExecuteNonQuery(sql);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
result = SqlHelper.ExecuteNonQuery(abutmentModel.batchAfterSql.Replace("{uuid}", abutmentModel.uuid));
|
||
string selectResultSql = string.Format("select {0},suuid,synchroSuccess,synchroMessage from {1} where uuid = '{2}'", abutmentModel.lsPrimaryKey, abutmentModel.lsTempTabName, abutmentModel.uuid);
|
||
DataTable selectLogTab = SqlHelper.ExecuteDataTable(selectResultSql);
|
||
foreach (DataRow sourceRow in afkTagGroup)
|
||
{
|
||
string afkPrimaryValue = "";
|
||
DataRow selectLogRow = null;
|
||
try
|
||
{
|
||
afkPrimaryValue = sourceRow["suuid"] + "";
|
||
selectLogRow = selectLogTab.Select().Where(n => (n["suuid"] + "").Equals(afkPrimaryValue)).FirstOrDefault();
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
var task = GetDataLogBatch(abutmentModel, selectLogRow, item, sourceRow, dataDirection, ErrorNumber);
|
||
tasks.Add(task);
|
||
if (tasks.Count >= 500)
|
||
{
|
||
while (tasks.Count > 0)
|
||
{
|
||
System.Threading.Tasks.Task getTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
System.Threading.Tasks.Task<string> finishedTask = getTask as System.Threading.Tasks.Task<string>;
|
||
if (!string.IsNullOrEmpty(finishedTask.Result))
|
||
{
|
||
getDataLogSql.Append(string.Format("{0};\r\n", finishedTask.Result));
|
||
}
|
||
tasks.Remove(getTask);
|
||
getTask.Dispose();
|
||
}
|
||
try
|
||
{
|
||
if (!string.IsNullOrEmpty(getDataLogSql.ToString()))
|
||
{
|
||
result = MySqlHelper.ExecuteNonQuery(getDataLogSql.ToString());
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
try
|
||
{
|
||
string direction = dataDirection == 0 ? "朗速获取AFK数据错误" : "AFK获取朗速数据错误";
|
||
string sql = string.Format("insert into P_RemarkTable(LsTableName,Messages) values ('{0}','{1}')", abutmentModel.lsTabName, direction + ":" + ex.Message.Replace("'", "''") + "");
|
||
SqlHelper.ExecuteNonQuery(sql);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
getDataLogSql = new StringBuilder();
|
||
}
|
||
}
|
||
while (tasks.Count > 0)
|
||
{
|
||
System.Threading.Tasks.Task getTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
System.Threading.Tasks.Task<string> finishedTask = getTask as System.Threading.Tasks.Task<string>;
|
||
if (!string.IsNullOrEmpty(finishedTask.Result))
|
||
{
|
||
getDataLogSql.Append(string.Format("{0};\r\n", finishedTask.Result));
|
||
}
|
||
tasks.Remove(getTask);
|
||
}
|
||
try
|
||
{
|
||
if (!string.IsNullOrEmpty(getDataLogSql.ToString()))
|
||
{
|
||
result = MySqlHelper.ExecuteNonQuery(getDataLogSql.ToString());
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
try
|
||
{
|
||
string direction = dataDirection == 0 ? "朗速获取AFK数据错误" : "AFK获取朗速数据错误";
|
||
string sql = string.Format("insert into P_RemarkTable(LsTableName,Messages) values ('{0}','{1}')", abutmentModel.lsTabName, direction + ":" + ex.Message.Replace("'", "''") + "");
|
||
SqlHelper.ExecuteNonQuery(sql);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
getDataLogSql = new StringBuilder();
|
||
}
|
||
else
|
||
{
|
||
foreach (DataRow sourceRow in afkTagGroup)
|
||
{
|
||
int index = abutmentModel.sourceTab.Rows.IndexOf(sourceRow);
|
||
var task = SendDataSingle(abutmentModel, item, dataDirection, sourceRow, ErrorNumber, modeOfOperation, afkTagGroup.Key, index);
|
||
tasks.Add(task);
|
||
if (tasks.Count >= taskNum)
|
||
{
|
||
System.Threading.Tasks.Task finishTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
tasks.Remove(finishTask);
|
||
finishTask.Dispose();
|
||
}
|
||
}
|
||
while (tasks.Count > 0)
|
||
{
|
||
System.Threading.Tasks.Task finishTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
tasks.Remove(finishTask);
|
||
finishTask.Dispose();
|
||
}
|
||
}
|
||
#endregion
|
||
break;
|
||
case "2"://传递修改
|
||
#region 修改
|
||
if (dataDirection == 0)
|
||
{
|
||
#region 修改朗速为修改语句
|
||
foreach (DataRow sourceRow in afkTagGroup)
|
||
{
|
||
int index = abutmentModel.sourceTab.Rows.IndexOf(sourceRow);
|
||
var task = SendDataSingle(abutmentModel, item, dataDirection, sourceRow, ErrorNumber, modeOfOperation, afkTagGroup.Key, index);
|
||
tasks.Add(task);
|
||
if (tasks.Count >= taskNum)
|
||
{
|
||
System.Threading.Tasks.Task finishTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
tasks.Remove(finishTask);
|
||
finishTask.Dispose();
|
||
}
|
||
}
|
||
while (tasks.Count > 0)
|
||
{
|
||
System.Threading.Tasks.Task finishTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
tasks.Remove(finishTask);
|
||
finishTask.Dispose();
|
||
}
|
||
#endregion
|
||
}
|
||
else
|
||
{
|
||
#region 修改爱福客为新增语句
|
||
foreach (DataRow sourceRow in afkTagGroup)
|
||
{
|
||
int index = abutmentModel.sourceTab.Rows.IndexOf(sourceRow);
|
||
var task = SendDataSingle(abutmentModel, item, dataDirection, sourceRow, ErrorNumber, modeOfOperation, afkTagGroup.Key, index);
|
||
tasks.Add(task);
|
||
if (tasks.Count >= taskNum)
|
||
{
|
||
System.Threading.Tasks.Task finishTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
tasks.Remove(finishTask);
|
||
finishTask.Dispose();
|
||
}
|
||
}
|
||
while (tasks.Count > 0)
|
||
{
|
||
System.Threading.Tasks.Task finishTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
tasks.Remove(finishTask);
|
||
finishTask.Dispose();
|
||
}
|
||
#endregion
|
||
}
|
||
#endregion
|
||
break;
|
||
case "3"://更改状态,禁用,上下架等
|
||
#region 更改状态,禁用,上下架等
|
||
if (dataDirection == 0)
|
||
{
|
||
#region 修改朗速为修改语句
|
||
foreach (DataRow sourceRow in afkTagGroup)
|
||
{
|
||
int index = abutmentModel.sourceTab.Rows.IndexOf(sourceRow);
|
||
var task = SendDataSingle(abutmentModel, item, dataDirection, sourceRow, ErrorNumber, modeOfOperation, afkTagGroup.Key, index);
|
||
tasks.Add(task);
|
||
if (tasks.Count >= taskNum)
|
||
{
|
||
System.Threading.Tasks.Task finishTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
tasks.Remove(finishTask);
|
||
finishTask.Dispose();
|
||
}
|
||
}
|
||
while (tasks.Count > 0)
|
||
{
|
||
System.Threading.Tasks.Task finishTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
tasks.Remove(finishTask);
|
||
finishTask.Dispose();
|
||
}
|
||
#endregion
|
||
}
|
||
else
|
||
{
|
||
#region 修改爱福客为新增语句
|
||
foreach (DataRow sourceRow in afkTagGroup)
|
||
{
|
||
int index = abutmentModel.sourceTab.Rows.IndexOf(sourceRow);
|
||
var task = SendDataSingle(abutmentModel, item, dataDirection, sourceRow, ErrorNumber, modeOfOperation, afkTagGroup.Key, index);
|
||
tasks.Add(task);
|
||
if (tasks.Count >= taskNum)
|
||
{
|
||
System.Threading.Tasks.Task finishTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
tasks.Remove(finishTask);
|
||
finishTask.Dispose();
|
||
}
|
||
}
|
||
while (tasks.Count > 0)
|
||
{
|
||
System.Threading.Tasks.Task finishTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
tasks.Remove(finishTask);
|
||
finishTask.Dispose();
|
||
}
|
||
#endregion
|
||
}
|
||
#endregion
|
||
break;
|
||
case "4":
|
||
#region 更改状态,禁用,上下架等
|
||
if (dataDirection == 0)
|
||
{
|
||
#region 修改朗速为修改语句
|
||
foreach (DataRow sourceRow in afkTagGroup)
|
||
{
|
||
int index = abutmentModel.sourceTab.Rows.IndexOf(sourceRow);
|
||
var task = SendDataSingle(abutmentModel, item, dataDirection, sourceRow, ErrorNumber, modeOfOperation, afkTagGroup.Key, index);
|
||
tasks.Add(task);
|
||
if (tasks.Count >= taskNum)
|
||
{
|
||
System.Threading.Tasks.Task finishTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
tasks.Remove(finishTask);
|
||
finishTask.Dispose();
|
||
}
|
||
}
|
||
while (tasks.Count > 0)
|
||
{
|
||
System.Threading.Tasks.Task finishTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
tasks.Remove(finishTask);
|
||
finishTask.Dispose();
|
||
}
|
||
#endregion
|
||
}
|
||
else
|
||
{
|
||
#region 修改爱福客为新增语句
|
||
foreach (DataRow sourceRow in afkTagGroup)
|
||
{
|
||
int index = abutmentModel.sourceTab.Rows.IndexOf(sourceRow);
|
||
var task = SendDataSingle(abutmentModel, item, dataDirection, sourceRow, ErrorNumber, modeOfOperation, afkTagGroup.Key, index);
|
||
tasks.Add(task);
|
||
if (tasks.Count >= taskNum)
|
||
{
|
||
System.Threading.Tasks.Task finishTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
tasks.Remove(finishTask);
|
||
finishTask.Dispose();
|
||
}
|
||
}
|
||
while (tasks.Count > 0)
|
||
{
|
||
System.Threading.Tasks.Task finishTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
tasks.Remove(finishTask);
|
||
finishTask.Dispose();
|
||
}
|
||
#endregion
|
||
}
|
||
#endregion
|
||
break;
|
||
case ""://没有可执行的操作
|
||
#region 没有可执行的操作
|
||
foreach (DataRow sourceRow in afkTagGroup)
|
||
{
|
||
int index = abutmentModel.sourceTab.Rows.IndexOf(sourceRow);
|
||
var task = SendDataSingle(abutmentModel, item, dataDirection, sourceRow, ErrorNumber, modeOfOperation, afkTagGroup.Key, index);
|
||
tasks.Add(task);
|
||
if (tasks.Count >= taskNum)
|
||
{
|
||
System.Threading.Tasks.Task finishTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
tasks.Remove(finishTask);
|
||
finishTask.Dispose();
|
||
}
|
||
}
|
||
while (tasks.Count > 0)
|
||
{
|
||
System.Threading.Tasks.Task finishTask = await System.Threading.Tasks.Task.WhenAny(tasks);
|
||
tasks.Remove(finishTask);
|
||
finishTask.Dispose();
|
||
}
|
||
#endregion
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
#region 没有标识字段默认新增
|
||
foreach (DataRow sourceRow in abutmentModel.sourceTab.Rows)
|
||
{
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
lsErrorLogSqlStr = "";
|
||
string getSourcePrimaryKey = dataDirection == 0 ? abutmentModel.lsPrimaryKey : abutmentModel.afkPrimaryKey;
|
||
string sourcePrimaryKey = dataDirection == 0 ? abutmentModel.afkPrimaryKey : abutmentModel.lsPrimaryKey;
|
||
string primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
string insertKeysStr = "";//insert语句keys
|
||
string insertValuesStr = "";//insert语句values
|
||
try
|
||
{
|
||
string getSourceKeys = dataDirection == 0 ? abutmentModel.lsTargeFields : abutmentModel.afkTargeFields;//接收数据表字段
|
||
GetInsertSqlStr(sourceRow, getSourceKeys, abutmentModel.afkTargeFields, abutmentModel.getSourceTabName, out insertKeysStr, out insertValuesStr, out dataTransferSql, dataDirection);
|
||
int result = dataDirection == 0 ? SqlHelper.ExecuteNonQuery(dataTransferSql) : MySqlHelper.ExecuteNonQuery(dataTransferSql);
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";//执行成功
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue) values ('{0}','{1}','{2}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue);
|
||
if (dataDirection == DataDirection.AfkToLs)//接收数据时aftersql判断
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(abutmentModel.afterSql))
|
||
{
|
||
DataTable afterTab = SqlHelper.ExecuteDataTable(ReplaceRowValue(abutmentModel.afterSql, sourceRow));//执行成功失败
|
||
string execsql = "";
|
||
string type = "";
|
||
if (afterTab != null && afterTab.Rows.Count > 0)
|
||
{
|
||
DataRow afterRow = afterTab.Rows[0];
|
||
execsql = afterRow.Table.Columns.Contains("execsql") ? afterRow["execsql"] + "" : "";
|
||
type = afterRow.Table.Columns.Contains("type") ? afterRow["type"] + "" : "";
|
||
}
|
||
string afterReturnMsg = execsql;
|
||
if (afterReturnMsg.Equals("Exec_BillOutPush", StringComparison.CurrentCultureIgnoreCase))
|
||
{
|
||
afterReturnMsg = BillOutPush(sourceRow, type);
|
||
if (!string.IsNullOrWhiteSpace(abutmentModel.afterSql) && string.IsNullOrEmpty(afterReturnMsg))//返回为空则成功
|
||
{
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
}
|
||
else if (!string.IsNullOrWhiteSpace(abutmentModel.afterSql) && !string.IsNullOrEmpty(afterReturnMsg))
|
||
{
|
||
logErrorMessage = afterReturnMsg;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
}
|
||
}
|
||
// lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条增加" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "正常", "", dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = ex.Message.Replace("'", "''");
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条增加" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "异常", ex.Message, dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
finally
|
||
{
|
||
try
|
||
{
|
||
#region 处理中间表写入日志
|
||
if (abutmentModel.synLogStrs.Length == 3)
|
||
{
|
||
try
|
||
{
|
||
string[] logArgs = new string[] { logSucceeId, logErrorType, logErrorMessage };
|
||
GetLogSqlStr(abutmentModel.logFields, abutmentModel.logAsFields, logArgs, insertKeysStr, insertValuesStr, abutmentModel.logTabName, out dataTransferLogSql);
|
||
int logResult = dataDirection == 0 ? MySqlHelper.ExecuteNonQuery(dataTransferLogSql) : 0;
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr);//插入朗速日志表
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, ex.Message.Replace("'", "''"));
|
||
}
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr);
|
||
}
|
||
#endregion
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
//删除
|
||
if (dataDirection == 0)
|
||
{
|
||
string truncateSql = string.Format("TRUNCATE TABLE {0}", abutmentModel.lsTempTabName);
|
||
string deleteSql = string.Format("delete from {0} {1}", abutmentModel.afkTabName, abutmentModel.sourceWhereCond);
|
||
if (abutmentModel.isBatch)
|
||
{
|
||
//if (isBatchLog)
|
||
//{
|
||
// //if (abutmentModel.id == 64)
|
||
// //{
|
||
// // string updateSynchrosql = string.Format("update {0} set isSynchro='3' {1}", abutmentModel.afkTabName, abutmentModel.sourceWhereCond);
|
||
// // MySqlHelper.ExecuteNonQuery(updateSynchrosql);
|
||
// //}
|
||
// //else
|
||
// //{
|
||
// // MySqlHelper.ExecuteNonQuery(deleteSql);
|
||
// //}
|
||
// MySqlHelper.ExecuteNonQuery(deleteSql);
|
||
// SqlHelper.ExecuteNonQuery(truncateSql);//最后完成后清空临时表
|
||
//}
|
||
}
|
||
else
|
||
{
|
||
MySqlHelper.ExecuteNonQuery(deleteSql);
|
||
if (!string.IsNullOrEmpty(abutmentModel.batchAfterSql))
|
||
{
|
||
SqlHelper.ExecuteNonQuery(truncateSql);//最后完成后清空临时表
|
||
}
|
||
}
|
||
}
|
||
if (dataDirection == 0)
|
||
{
|
||
RefreshLogUIThread(this.AfkToLsGrid, abutmentModel.id, "issucceed", "true");
|
||
}
|
||
else
|
||
{
|
||
RefreshLogUIThread(this.LsToAfkGrid, abutmentModel.id, "issucceed", "true");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
try
|
||
{
|
||
if (dataDirection == 0)
|
||
{
|
||
RefreshLogUIThread(this.AfkToLsGrid, abutmentModel.id, "issucceed", "false");
|
||
RefreshLogUIThread(this.AfkToLsGrid, abutmentModel.id, "errorMsg", ex.Message);
|
||
}
|
||
else
|
||
{
|
||
RefreshLogUIThread(this.LsToAfkGrid, abutmentModel.id, "issucceed", "false");
|
||
RefreshLogUIThread(this.LsToAfkGrid, abutmentModel.id, "errorMsg", ex.Message);
|
||
}
|
||
string direction = dataDirection == 0 ? "朗速获取AFK数据错误" : "AFK获取朗速数据错误";
|
||
string sql = string.Format("insert into P_RemarkTable(LsTableName,Messages) values ('{0}','{1}')", abutmentModel.lsTabName, direction + ":" + ex.Message.Replace("'", "''") + "");
|
||
SqlHelper.ExecuteNonQuery(sql);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
finally
|
||
{
|
||
if (MySqlHelper._connection != null)
|
||
{
|
||
MySqlHelper._connection.Close();
|
||
MySqlHelper._connection.Dispose();
|
||
MySqlHelper = null;
|
||
}
|
||
if (SqlHelper._connection != null)
|
||
{
|
||
SqlHelper._connection.Close();
|
||
SqlHelper._connection.Dispose();
|
||
SqlHelper = null;
|
||
}
|
||
RefreshLogUIThread("同步完成,失败条数:" + ErrorNumber + "\r\n");
|
||
}
|
||
return abutmentModel;
|
||
}
|
||
#endregion
|
||
#region 修改批量标记isSynchro=1
|
||
private string GetChangeSynchroTagSql(DataRow item, DataDirection dataDirection)
|
||
{
|
||
string sql = "";
|
||
try
|
||
{
|
||
AbutmentModel abutmentModel = new AbutmentModel(item, dataDirection, this.afkDataBase.Text + "", sqlHelperConStr, mySqlHelperConStr);
|
||
string conditions = string.Empty;
|
||
conditions = abutmentModel.targetStrs.Length == 2 ? " where isSynchro is null and " + abutmentModel.targetStrs[1] : "";
|
||
sql = string.Format("update {0} set isSynchro='1' {1} ", abutmentModel.afkTabName, conditions);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
return sql;
|
||
}
|
||
#endregion
|
||
#region 执行批量存储过程
|
||
private void ExecBatchAfterSql(DataRow item, DataDirection dataDirection, string uuid, Dictionary<DataRow, AbutmentModel> itemModel)
|
||
{
|
||
AbutmentModel abutmentModel = null;
|
||
if (itemModel.ContainsKey(item))
|
||
{
|
||
abutmentModel = itemModel[item];
|
||
}
|
||
else
|
||
{
|
||
abutmentModel = new AbutmentModel(item, dataDirection, this.afkDataBase.Text + "", sqlHelperConStr, mySqlHelperConStr);
|
||
}
|
||
abutmentModel.uuid = uuid;
|
||
if (dataDirection == 0)
|
||
{
|
||
if (!string.IsNullOrEmpty(abutmentModel.batchAfterSql))
|
||
{
|
||
try
|
||
{
|
||
int result = SqlHelper.ExecuteNonQuery(abutmentModel.batchAfterSql.Replace("{uuid}", abutmentModel.uuid));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
try
|
||
{
|
||
string direction = "批量传递执行存储过程失败";
|
||
string sql = string.Format("insert into P_RemarkTable(LsTableName,Messages) values ('{0}','{1}')", abutmentModel.lsTabName, direction + ":" + ex.Message.Replace("'", "''") + "");
|
||
SqlHelper.ExecuteNonQuery(sql);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
#region 批量删除临时表数据
|
||
private void DeleteTempTabData(DataRow item, DataDirection dataDirection, string uuid, Dictionary<DataRow, AbutmentModel> itemModel)
|
||
{
|
||
AbutmentModel abutmentModel = null;
|
||
if (itemModel.ContainsKey(item))
|
||
{
|
||
abutmentModel = itemModel[item];
|
||
}
|
||
else
|
||
{
|
||
abutmentModel = new AbutmentModel(item, dataDirection, this.afkDataBase.Text + "", sqlHelperConStr, mySqlHelperConStr);
|
||
}
|
||
abutmentModel.uuid = uuid;
|
||
if (dataDirection == 0)
|
||
{
|
||
string truncateSql = string.Format("TRUNCATE TABLE {0}", abutmentModel.lsTempTabName);
|
||
string deleteSql = string.Format("delete from {0} {1}", abutmentModel.afkTabName, abutmentModel.sourceWhereCond);
|
||
if (abutmentModel.isBatch)
|
||
{
|
||
//if (abutmentModel.id == 64)
|
||
//{
|
||
// string updateSynchrosql = string.Format("update {0} set isSynchro='3' {1}", abutmentModel.afkTabName, abutmentModel.sourceWhereCond);
|
||
// MySqlHelper.ExecuteNonQuery(updateSynchrosql);
|
||
//}
|
||
//else
|
||
//{
|
||
// MySqlHelper.ExecuteNonQuery(deleteSql);
|
||
//}
|
||
MySqlHelper.ExecuteNonQuery(deleteSql);
|
||
SqlHelper.ExecuteNonQuery(truncateSql);//最后完成后清空临时表
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
#region 删除copy表数据
|
||
private void DeleteCopyTab(DataRow item, DataDirection dataDirection)
|
||
{
|
||
AbutmentModel abutmentModel = new AbutmentModel(item, dataDirection, this.afkDataBase.Text + "", sqlHelperConStr, mySqlHelperConStr);
|
||
if (dataDirection == 0)
|
||
{
|
||
string truncateSql = string.Format("TRUNCATE TABLE {0}", abutmentModel.lsTempTabName);
|
||
SqlHelper.ExecuteNonQuery(truncateSql);//最后完成后清空临时表
|
||
}
|
||
}
|
||
#endregion
|
||
#region 多任务处理_单条
|
||
public async System.Threading.Tasks.Task<int> SendDataSingle(AbutmentModel abutmentModel, DataRow item, DataDirection dataDirection, DataRow sourceRow, int ErrorNumber, string modeOfOperation, string switchKey, int asyncNo)
|
||
{
|
||
await System.Threading.Tasks.Task.Run(async () =>
|
||
{
|
||
//string num = string.Format("1.{0}", sourceRow.Table.Rows.IndexOf(sourceRow));
|
||
//await System.Threading.Tasks.Task.Delay(Convert.ToInt32(Math.Round(Convert.ToDouble(num) * 50)));
|
||
NMySqlHelper MySqlHelper = new NMySqlHelper(new MySqlConnection(mySqlHelperConStr));
|
||
NSqlHelper SqlHelper = new NSqlHelper(new SqlConnection(sqlHelperConStr));
|
||
|
||
string logSucceeId = "";
|
||
string logErrorType = "";
|
||
string logErrorMessage = "";
|
||
string dataTransferSql = "";//执行数据传递sql
|
||
string dataTransferLogSql = "";//接收数据需要向中间表写日志
|
||
string lsErrorLogSqlStr = "";//朗速日志表
|
||
string getSourcePrimaryKey = "";
|
||
string sourcePrimaryKey = "";
|
||
string primaryValue = "";
|
||
string insertKeysStr = "";
|
||
string insertValuesStr = "";
|
||
string insertLogKeysStr = "";
|
||
string insertLogValuesStr = "";
|
||
switch (switchKey)
|
||
{
|
||
case "1"://传递新增
|
||
#region 新增
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
lsErrorLogSqlStr = "";
|
||
bool pushLog = false;
|
||
getSourcePrimaryKey = dataDirection == 0 ? abutmentModel.lsPrimaryKey : abutmentModel.afkPrimaryKey;
|
||
sourcePrimaryKey = dataDirection == 0 ? abutmentModel.afkPrimaryKey : abutmentModel.lsPrimaryKey;
|
||
primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
insertKeysStr = "";//insert语句keys
|
||
insertValuesStr = "";//insert语句values
|
||
//判断是否有不能为空的数据
|
||
string SaveErrorMessage = IsValueBlank(abutmentModel.SQLQueryPropertySheet, abutmentModel.MYSQLPropertySheet, sourceRow, abutmentModel.lsTargeFields, abutmentModel.afkTargeFields, dataDirection);
|
||
if (!string.IsNullOrWhiteSpace(SaveErrorMessage))
|
||
{
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = SaveErrorMessage;
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, logErrorMessage);
|
||
return asyncNo;
|
||
}
|
||
try
|
||
{
|
||
string getSourceKeys = dataDirection == 0 ? abutmentModel.lsTargeFields : abutmentModel.afkTargeFields;//接收数据表字段
|
||
GetInsertSqlStr(sourceRow, getSourceKeys, abutmentModel.afkTargeFields, abutmentModel.getSourceTabName, out insertKeysStr, out insertValuesStr, out dataTransferSql, dataDirection);
|
||
if (dataDirection == 0 && IsExistPrimaryValue(sourceRow, abutmentModel.getSourceTabName, getSourcePrimaryKey, sourcePrimaryKey, dataDirection))//朗速获取数据前应判断主键是否存在,执行前
|
||
{
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = string.Format("主键值{0}已存在", primaryValue);
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条增加" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "异常", string.Format("主键值{0}已存在", primaryValue), dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, logErrorMessage);
|
||
return asyncNo;
|
||
}
|
||
int result = dataDirection == 0 ? SqlHelper.ExecuteNonQuery(dataTransferSql) : MySqlHelper.ExecuteNonQuery(dataTransferSql);
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue) values ('{0}','{1}','{2}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue);
|
||
if (dataDirection == DataDirection.AfkToLs)//接收数据时aftersql判断
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(abutmentModel.afterSql))
|
||
{
|
||
DataTable afterTab = new DataTable();
|
||
string afterExecSql = abutmentModel.afterSql;
|
||
string execsql = "";
|
||
string type = "";
|
||
if (afterExecSql.StartsWith("@"))
|
||
{
|
||
afterExecSql = afterExecSql.Substring(1, afterExecSql.Length - 1);
|
||
afterTab = SqlHelper.ExecuteDataTable(ReplaceRowValue(afterExecSql, sourceRow));//执行成功失败
|
||
}
|
||
else
|
||
SqlHelper.ExecuteNonQuery(afterExecSql);
|
||
if (afterTab != null && afterTab.Rows.Count > 0)
|
||
{
|
||
DataRow afterRow = afterTab.Rows[0];
|
||
execsql = afterRow.Table.Columns.Contains("execsql") ? afterRow["execsql"] + "" : "";
|
||
type = afterRow.Table.Columns.Contains("type") ? afterRow["type"] + "" : "";
|
||
}
|
||
string afterReturnMsg = execsql;
|
||
if (afterReturnMsg.Equals("Exec_BillOutPush", StringComparison.CurrentCultureIgnoreCase))
|
||
{
|
||
afterReturnMsg = BillOutPush(sourceRow, type);
|
||
if (!string.IsNullOrWhiteSpace(abutmentModel.afterSql) && string.IsNullOrEmpty(afterReturnMsg))//返回为空则成功
|
||
{
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
}
|
||
else if (!string.IsNullOrWhiteSpace(abutmentModel.afterSql) && !string.IsNullOrEmpty(afterReturnMsg))
|
||
{
|
||
if (afterReturnMsg.Equals("99999"))
|
||
{
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = "未检测到明细表数据";
|
||
updateIssychro(abutmentModel.sourceTabNale, sourcePrimaryKey, sourceRow);
|
||
pushLog = true;
|
||
return asyncNo;
|
||
}
|
||
logErrorMessage = afterReturnMsg;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条增加" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "正常", "", dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = ex.Message.Replace("'", "''");
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条增加" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "异常", ex.Message, dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
finally
|
||
{
|
||
try
|
||
{
|
||
//LS》AFK要处理双方数据的directTag问题
|
||
if (dataDirection == DataDirection.LsToAfk)
|
||
{
|
||
//把传输的数据directTag改为2
|
||
string sql = string.Format("update {0} set directTag='2' where {1}='{2}'", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, sourceRow[abutmentModel.lsPrimaryKey.Trim()]);
|
||
MySqlHelper.ExecuteNonQuery(sql);
|
||
//把ls数据库中已经传输的数据directTag改为2
|
||
sql = string.Format("update {0} set directTag='2' where {1}='{2}'", abutmentModel.lsTabName, abutmentModel.lsPrimaryKey, sourceRow[abutmentModel.lsPrimaryKey.Trim()]);
|
||
SqlHelper.ExecuteNonQuery(sql);//插入朗速日志表
|
||
}
|
||
#region 处理中间表写入日志
|
||
if (abutmentModel.synLogStrs.Length == 3)
|
||
{
|
||
try
|
||
{
|
||
string[] logArgs = new string[] { logSucceeId, logErrorType, logErrorMessage };
|
||
GetLogSqlStr(abutmentModel.logFields, abutmentModel.logAsFields, logArgs, insertKeysStr, insertValuesStr, abutmentModel.logTabName, out dataTransferLogSql);
|
||
if (!pushLog)
|
||
{
|
||
int logResult = dataDirection == 0 ? MySqlHelper.ExecuteNonQuery(dataTransferLogSql) : 0;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, ex.Message.Replace("'", "''"));
|
||
}
|
||
}
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr);//插入朗速日志表
|
||
#endregion
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
#endregion
|
||
break;
|
||
case "2"://传递修改
|
||
#region 修改
|
||
if (dataDirection == 0)
|
||
{
|
||
#region 修改朗速为修改语句
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
lsErrorLogSqlStr = "";
|
||
getSourcePrimaryKey = dataDirection == 0 ? abutmentModel.lsPrimaryKey : abutmentModel.afkPrimaryKey;
|
||
sourcePrimaryKey = dataDirection == 0 ? abutmentModel.afkPrimaryKey : abutmentModel.lsPrimaryKey;
|
||
primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
insertLogKeysStr = "";//insert日志语句keys
|
||
insertLogValuesStr = "";//insert日志语句values
|
||
try
|
||
{
|
||
dataTransferSql = "update {0} set {1} where {2}";
|
||
string getSourceKeys = dataDirection == 0 ? abutmentModel.lsTargeFields : abutmentModel.afkTargeFields;//接收数据表字段
|
||
GetUpdateSqlStr(sourceRow, getSourceKeys, abutmentModel.afkTargeFields, abutmentModel.getSourceTabName, getSourcePrimaryKey, sourcePrimaryKey, out insertLogKeysStr, out insertLogValuesStr, out dataTransferSql);
|
||
int result = SqlHelper.ExecuteNonQuery(dataTransferSql);
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";//执行成功
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue) values ('{0}','{1}','{2}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue);
|
||
if (dataDirection == DataDirection.AfkToLs)//接收数据时aftersql判断
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(abutmentModel.afterSql))
|
||
{
|
||
DataTable afterTab = new DataTable();
|
||
string afterExecSql = abutmentModel.afterSql;
|
||
string execsql = "";
|
||
string type = "";
|
||
if (afterExecSql.StartsWith("@"))
|
||
{
|
||
afterExecSql = afterExecSql.Substring(1, afterExecSql.Length - 1);
|
||
afterTab = SqlHelper.ExecuteDataTable(ReplaceRowValue(afterExecSql, sourceRow));//执行成功失败
|
||
}
|
||
else
|
||
SqlHelper.ExecuteNonQuery(afterExecSql);
|
||
if (afterTab != null && afterTab.Rows.Count > 0)
|
||
{
|
||
DataRow afterRow = afterTab.Rows[0];
|
||
execsql = afterRow.Table.Columns.Contains("execsql") ? afterRow["execsql"] + "" : "";
|
||
type = afterRow.Table.Columns.Contains("type") ? afterRow["type"] + "" : "";
|
||
}
|
||
string afterReturnMsg = execsql;
|
||
if (afterReturnMsg.Equals("Exec_BillOutPush", StringComparison.CurrentCultureIgnoreCase))
|
||
{
|
||
afterReturnMsg = BillOutPush(sourceRow, type);
|
||
if (!string.IsNullOrWhiteSpace(abutmentModel.afterSql) && string.IsNullOrEmpty(afterReturnMsg))//返回为空则成功
|
||
{
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
}
|
||
else if (!string.IsNullOrWhiteSpace(abutmentModel.afterSql) && !string.IsNullOrEmpty(afterReturnMsg))
|
||
{
|
||
logErrorMessage = afterReturnMsg;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "正常", "", dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = ex.Message.Replace("'", "''");
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "异常", ex.Message, dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
finally
|
||
{
|
||
try
|
||
{
|
||
#region 处理中间表写入日志
|
||
if (abutmentModel.synLogStrs.Length == 3 && dataDirection == 0)
|
||
{
|
||
try
|
||
{
|
||
string[] logArgs = new string[] { logSucceeId, logErrorType, logErrorMessage };
|
||
GetLogSqlStr(abutmentModel.logFields, abutmentModel.logAsFields, logArgs, insertLogKeysStr, insertLogValuesStr, abutmentModel.logTabName, out dataTransferLogSql);
|
||
int logResult = MySqlHelper.ExecuteNonQuery(dataTransferLogSql);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, ex.Message.Replace("'", "''"));
|
||
}
|
||
}
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr);
|
||
#endregion
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
else
|
||
{
|
||
#region 修改爱福客为新增语句
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
lsErrorLogSqlStr = "";
|
||
getSourcePrimaryKey = dataDirection == 0 ? abutmentModel.lsPrimaryKey : abutmentModel.afkPrimaryKey;
|
||
sourcePrimaryKey = dataDirection == 0 ? abutmentModel.afkPrimaryKey : abutmentModel.lsPrimaryKey;
|
||
primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
insertKeysStr = "";//insert语句keys
|
||
insertValuesStr = "";//insert语句values
|
||
try
|
||
{
|
||
string getSourceKeys = dataDirection == 0 ? abutmentModel.lsTargeFields : abutmentModel.afkTargeFields;//接收数据表字段
|
||
GetInsertSqlStr(sourceRow, getSourceKeys, abutmentModel.afkTargeFields, abutmentModel.getSourceTabName, out insertKeysStr, out insertValuesStr, out dataTransferSql, dataDirection);
|
||
int result = MySqlHelper.ExecuteNonQuery(dataTransferSql);
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";//执行成功
|
||
// lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "正常", "", dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue) values ('{0}','{1}','{2}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = ex.Message.Replace("'", "''");
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "异常", ex.Message, dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, logErrorMessage);
|
||
|
||
}
|
||
finally
|
||
{
|
||
try
|
||
{
|
||
//LS》AFK要处理双方数据的directTag问题
|
||
//把传输的数据directTag改为2
|
||
string sql = string.Format("update {0} set directTag='2' where {1}='{2}'", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, sourceRow[abutmentModel.lsPrimaryKey.Trim()]);
|
||
MySqlHelper.ExecuteNonQuery(sql);
|
||
//把ls数据库中已经传输的数据directTag改为2
|
||
sql = string.Format("update {0} set directTag='2' where {1}='{2}'", abutmentModel.lsTabName, abutmentModel.lsPrimaryKey, sourceRow[abutmentModel.lsPrimaryKey.Trim()]);
|
||
SqlHelper.ExecuteNonQuery(sql);//插入朗速日志表
|
||
#region 处理中间表写入日志,向爱福客插入数据不需向中间表添加日志
|
||
//string[] logArgs = new string[] { logSucceeId, logErrorType, logErrorMessage };
|
||
//GetLogSqlStr(logFields, logAsFields, logArgs, insertKeysStr, insertValuesStr, logTabName, out dataTransferLogSql);
|
||
//int logResult = dataDirection == 0 ? MySqlHelper.ExecuteNonQuery(dataTransferLogSql) : 0;
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr); //插入朗速日志表
|
||
#endregion
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
#endregion
|
||
break;
|
||
case "3"://更改状态,禁用,上下架等
|
||
#region 更改状态,禁用,上下架等
|
||
if (dataDirection == 0)
|
||
{
|
||
#region 修改朗速为修改语句
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
lsErrorLogSqlStr = "";
|
||
getSourcePrimaryKey = dataDirection == 0 ? abutmentModel.lsPrimaryKey : abutmentModel.afkPrimaryKey;
|
||
sourcePrimaryKey = dataDirection == 0 ? abutmentModel.afkPrimaryKey : abutmentModel.lsPrimaryKey;
|
||
primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
insertLogKeysStr = "";//insert日志语句keys
|
||
insertLogValuesStr = "";//insert日志语句values
|
||
string[] disableFieidsArgs = abutmentModel.disableFieids.Replace(" ", "").Split('^');
|
||
string stateField = disableFieidsArgs[0];//3对应第一个状态
|
||
try
|
||
{
|
||
dataTransferSql = "update {0} set {1} where {2}";
|
||
string getSourceKeys = dataDirection == 0 ? abutmentModel.lsTargeFields : abutmentModel.afkTargeFields;//接收数据表字段
|
||
GetChangeStateSqlStr(sourceRow, stateField, getSourceKeys, abutmentModel.afkTargeFields, abutmentModel.getSourceTabName, getSourcePrimaryKey, sourcePrimaryKey, out insertLogKeysStr, out insertLogValuesStr, out dataTransferSql);
|
||
int result = SqlHelper.ExecuteNonQuery(dataTransferSql);
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";//执行成功
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue) values ('{0}','{1}','{2}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue);
|
||
if (dataDirection == DataDirection.AfkToLs)//接收数据时aftersql判断
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(abutmentModel.afterSql))
|
||
{
|
||
DataTable afterTab = new DataTable();
|
||
string afterExecSql = abutmentModel.afterSql;
|
||
string execsql = "";
|
||
string type = "";
|
||
if (afterExecSql.StartsWith("@"))
|
||
{
|
||
afterExecSql = afterExecSql.Substring(1, afterExecSql.Length - 1);
|
||
afterTab = SqlHelper.ExecuteDataTable(ReplaceRowValue(afterExecSql, sourceRow));//执行成功失败
|
||
}
|
||
else
|
||
SqlHelper.ExecuteNonQuery(afterExecSql);
|
||
if (afterTab != null && afterTab.Rows.Count > 0)
|
||
{
|
||
DataRow afterRow = afterTab.Rows[0];
|
||
execsql = afterRow.Table.Columns.Contains("execsql") ? afterRow["execsql"] + "" : "";
|
||
type = afterRow.Table.Columns.Contains("type") ? afterRow["type"] + "" : "";
|
||
}
|
||
string afterReturnMsg = execsql;
|
||
if (afterReturnMsg.Equals("Exec_BillOutPush", StringComparison.CurrentCultureIgnoreCase))
|
||
{
|
||
afterReturnMsg = BillOutPush(sourceRow, type);
|
||
if (!string.IsNullOrWhiteSpace(abutmentModel.afterSql) && string.IsNullOrEmpty(afterReturnMsg))//返回为空则成功
|
||
{
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
}
|
||
else if (!string.IsNullOrWhiteSpace(abutmentModel.afterSql) && !string.IsNullOrEmpty(afterReturnMsg))
|
||
{
|
||
logErrorMessage = afterReturnMsg;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
}
|
||
}
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "正常", "", dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = ex.Message.Replace("'", "''");
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "异常", ex.Message, dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, logErrorMessage);
|
||
|
||
}
|
||
finally
|
||
{
|
||
try
|
||
{
|
||
#region 处理中间表写入日志
|
||
if (abutmentModel.synLogStrs.Length == 3)
|
||
{
|
||
try
|
||
{
|
||
string[] logArgs = new string[] { logSucceeId, logErrorType, logErrorMessage };
|
||
GetLogSqlStr(abutmentModel.logFields, abutmentModel.logAsFields, logArgs, insertLogKeysStr, insertLogValuesStr, abutmentModel.logTabName, out dataTransferLogSql);
|
||
#endregion
|
||
int logResult = MySqlHelper.ExecuteNonQuery(dataTransferLogSql);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, ex.Message.Replace("'", "''"));
|
||
}
|
||
}
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
else
|
||
{
|
||
#region 修改爱福客为新增语句
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
lsErrorLogSqlStr = "";
|
||
getSourcePrimaryKey = dataDirection == 0 ? abutmentModel.lsPrimaryKey : abutmentModel.afkPrimaryKey;
|
||
sourcePrimaryKey = dataDirection == 0 ? abutmentModel.afkPrimaryKey : abutmentModel.lsPrimaryKey;
|
||
primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
insertKeysStr = "";//insert语句keys
|
||
insertValuesStr = "";//insert语句values
|
||
try
|
||
{
|
||
string getSourceKeys = dataDirection == 0 ? abutmentModel.lsTargeFields : abutmentModel.afkTargeFields;//接收数据表字段
|
||
GetInsertSqlStr(sourceRow, getSourceKeys, abutmentModel.afkTargeFields, abutmentModel.getSourceTabName, out insertKeysStr, out insertValuesStr, out dataTransferSql, dataDirection);
|
||
int result = MySqlHelper.ExecuteNonQuery(dataTransferSql);
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";//执行成功
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "正常", "", dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue) values ('{0}','{1}','{2}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = ex.Message.Replace("'", "''");
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "异常", ex.Message, dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, logErrorMessage);
|
||
|
||
}
|
||
finally
|
||
{
|
||
try
|
||
{
|
||
//LS》AFK要处理双方数据的directTag问题
|
||
//把传输的数据directTag改为2
|
||
string sql = string.Format("update {0} set directTag='2' where {1}='{2}'", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, sourceRow[abutmentModel.lsPrimaryKey.Trim()]);
|
||
MySqlHelper.ExecuteNonQuery(sql);
|
||
//把ls数据库中已经传输的数据directTag改为2
|
||
sql = string.Format("update {0} set directTag='2' where {1}='{2}'", abutmentModel.lsTabName, abutmentModel.lsPrimaryKey, sourceRow[abutmentModel.lsPrimaryKey.Trim()]);
|
||
SqlHelper.ExecuteNonQuery(sql);//插入朗速日志表
|
||
#region 处理中间表写入日志,向爱福客插入数据不需向中间表添加日志
|
||
//string[] logArgs = new string[] { logSucceeId, logErrorType, logErrorMessage };
|
||
//GetLogSqlStr(logFields, logAsFields, logArgs, insertKeysStr, insertValuesStr, logTabName, out dataTransferLogSql);
|
||
//int logResult = dataDirection == 0 ? MySqlHelper.ExecuteNonQuery(dataTransferLogSql) : 0;
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr); //插入朗速日志表
|
||
#endregion
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
#endregion
|
||
break;
|
||
case "4":
|
||
#region 更改状态,禁用,上下架等
|
||
if (dataDirection == 0)
|
||
{
|
||
#region 修改朗速为修改语句
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
lsErrorLogSqlStr = "";
|
||
getSourcePrimaryKey = dataDirection == 0 ? abutmentModel.lsPrimaryKey : abutmentModel.afkPrimaryKey;
|
||
sourcePrimaryKey = dataDirection == 0 ? abutmentModel.afkPrimaryKey : abutmentModel.lsPrimaryKey;
|
||
primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
insertLogKeysStr = "";//insert日志语句keys
|
||
insertLogValuesStr = "";//insert日志语句values
|
||
string[] disableFieidsArgs = abutmentModel.disableFieids.Replace(" ", "").Split('^');
|
||
string stateField = disableFieidsArgs[1];//4对应第二个状态
|
||
try
|
||
{
|
||
dataTransferSql = "update {0} set {1} where {2}";
|
||
string getSourceKeys = dataDirection == 0 ? abutmentModel.lsTargeFields : abutmentModel.afkTargeFields;//接收数据表字段
|
||
GetChangeStateSqlStr(sourceRow, stateField, getSourceKeys, abutmentModel.afkTargeFields, abutmentModel.getSourceTabName, getSourcePrimaryKey, sourcePrimaryKey, out insertLogKeysStr, out insertLogValuesStr, out dataTransferSql);
|
||
int result = SqlHelper.ExecuteNonQuery(dataTransferSql);
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";//执行成功
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue) values ('{0}','{1}','{2}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue);
|
||
if (dataDirection == DataDirection.AfkToLs)//接收数据时aftersql判断
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(abutmentModel.afterSql))
|
||
{
|
||
DataTable afterTab = new DataTable();
|
||
string afterExecSql = abutmentModel.afterSql;
|
||
string execsql = "";
|
||
string type = "";
|
||
if (afterExecSql.StartsWith("@"))
|
||
{
|
||
afterExecSql = afterExecSql.Substring(1, afterExecSql.Length - 1);
|
||
afterTab = SqlHelper.ExecuteDataTable(ReplaceRowValue(afterExecSql, sourceRow));//执行成功失败
|
||
}
|
||
else
|
||
SqlHelper.ExecuteNonQuery(afterExecSql);
|
||
if (afterTab != null && afterTab.Rows.Count > 0)
|
||
{
|
||
DataRow afterRow = afterTab.Rows[0];
|
||
execsql = afterRow.Table.Columns.Contains("execsql") ? afterRow["execsql"] + "" : "";
|
||
type = afterRow.Table.Columns.Contains("type") ? afterRow["type"] + "" : "";
|
||
}
|
||
string afterReturnMsg = execsql;
|
||
if (afterReturnMsg.Equals("Exec_BillOutPush", StringComparison.CurrentCultureIgnoreCase))
|
||
{
|
||
afterReturnMsg = BillOutPush(sourceRow, type);
|
||
if (!string.IsNullOrWhiteSpace(abutmentModel.afterSql) && string.IsNullOrEmpty(afterReturnMsg))//返回为空则成功
|
||
{
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
}
|
||
else if (!string.IsNullOrWhiteSpace(abutmentModel.afterSql) && !string.IsNullOrEmpty(afterReturnMsg))
|
||
{
|
||
logErrorMessage = afterReturnMsg;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
}
|
||
}
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "正常", "", dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = ex.Message.Replace("'", "''");
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "异常", ex.Message, dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
finally
|
||
{
|
||
try
|
||
{
|
||
#region 处理中间表写入日志
|
||
if (abutmentModel.synLogStrs.Length == 3)
|
||
{
|
||
try
|
||
{
|
||
string[] logArgs = new string[] { logSucceeId, logErrorType, logErrorMessage };
|
||
GetLogSqlStr(abutmentModel.logFields, abutmentModel.logAsFields, logArgs, insertLogKeysStr, insertLogValuesStr, abutmentModel.logTabName, out dataTransferLogSql);
|
||
#endregion
|
||
int logResult = MySqlHelper.ExecuteNonQuery(dataTransferLogSql);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, ex.Message.Replace("'", "''"));
|
||
}
|
||
}
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
else
|
||
{
|
||
#region 修改爱福客为新增语句
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
lsErrorLogSqlStr = "";
|
||
getSourcePrimaryKey = dataDirection == 0 ? abutmentModel.lsPrimaryKey : abutmentModel.afkPrimaryKey;
|
||
sourcePrimaryKey = dataDirection == 0 ? abutmentModel.afkPrimaryKey : abutmentModel.lsPrimaryKey;
|
||
primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
insertKeysStr = "";//insert语句keys
|
||
insertValuesStr = "";//insert语句values
|
||
try
|
||
{
|
||
string getSourceKeys = dataDirection == 0 ? abutmentModel.lsTargeFields : abutmentModel.afkTargeFields;//接收数据表字段
|
||
GetInsertSqlStr(sourceRow, getSourceKeys, abutmentModel.afkTargeFields, abutmentModel.getSourceTabName, out insertKeysStr, out insertValuesStr, out dataTransferSql, dataDirection);
|
||
int result = MySqlHelper.ExecuteNonQuery(dataTransferSql);
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";//执行成功
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "正常", "", dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue) values ('{0}','{1}','{2}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue);
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = ex.Message.Replace("'", "''");
|
||
// lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条修改" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "异常", ex.Message, dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, logErrorMessage);
|
||
|
||
}
|
||
finally
|
||
{
|
||
try
|
||
{
|
||
//LS》AFK要处理双方数据的directTag问题
|
||
//把传输的数据directTag改为2
|
||
string sql = string.Format("update {0} set directTag='2' where {1}='{2}'", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, sourceRow[abutmentModel.lsPrimaryKey.Trim()]);
|
||
MySqlHelper.ExecuteNonQuery(sql);
|
||
//把ls数据库中已经传输的数据directTag改为2
|
||
sql = string.Format("update {0} set directTag='2' where {1}='{2}'", abutmentModel.lsTabName, abutmentModel.lsPrimaryKey, sourceRow[abutmentModel.lsPrimaryKey.Trim()]);
|
||
SqlHelper.ExecuteNonQuery(sql);//插入朗速日志表
|
||
#region 处理中间表写入日志,向爱福客插入数据不需向中间表添加日志
|
||
//string[] logArgs = new string[] { logSucceeId, logErrorType, logErrorMessage };
|
||
//GetLogSqlStr(logFields, logAsFields, logArgs, insertKeysStr, insertValuesStr, logTabName, out dataTransferLogSql);
|
||
//int logResult = dataDirection == 0 ? MySqlHelper.ExecuteNonQuery(dataTransferLogSql) : 0;
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr); //插入朗速日志表
|
||
#endregion
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
#endregion
|
||
break;
|
||
case ""://没有可执行的操作
|
||
#region 没有可执行的操作
|
||
logSucceeId = "1";
|
||
logErrorType = "0";
|
||
logErrorMessage = "";
|
||
lsErrorLogSqlStr = "";
|
||
getSourcePrimaryKey = dataDirection == 0 ? abutmentModel.lsPrimaryKey : abutmentModel.afkPrimaryKey;
|
||
sourcePrimaryKey = dataDirection == 0 ? abutmentModel.afkPrimaryKey : abutmentModel.lsPrimaryKey;
|
||
primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
insertKeysStr = "";//insert语句keys
|
||
insertValuesStr = "";//insert语句values
|
||
try
|
||
{
|
||
string getSourceKeys = dataDirection == 0 ? abutmentModel.lsTargeFields : abutmentModel.afkTargeFields;//接收数据表字段
|
||
GetInsertSqlStr(sourceRow, getSourceKeys, abutmentModel.afkTargeFields, abutmentModel.getSourceTabName, out insertKeysStr, out insertValuesStr, out dataTransferSql, dataDirection);
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = string.Format("{0}为空,没有可执行的操作", modeOfOperation);
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条增加" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "异常", string.Format("{0}为空,没有可执行的操作", modeOfOperation), dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = ex.Message.Replace("'", "''");
|
||
//lsErrorLogSqlStr = string.Format("Insert into ls_errlogtab(Ls_log_tagid,Ls_log_opdt,Ls_log_rulst,Ls_log_buginfo,Ls_log_coname)values('{0}',{1},'{2}','{3}','{4}')", "单条增加" + getSourceTabName + "表,主键" + getSourcePrimaryKey.Replace("'", "''"), "GETDATE()", "异常", ex.Message, dataDirection == 0 ? "朗速" : "中航爱福客");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
finally
|
||
{
|
||
try
|
||
{
|
||
#region 处理中间表写入日志
|
||
if (abutmentModel.synLogStrs.Length == 3)
|
||
{
|
||
try
|
||
{
|
||
string[] logArgs = new string[] { logSucceeId, logErrorType, logErrorMessage };
|
||
GetLogSqlStr(abutmentModel.logFields, abutmentModel.logAsFields, logArgs, insertKeysStr, insertValuesStr, abutmentModel.logTabName, out dataTransferLogSql);
|
||
int logResult = dataDirection == 0 ? MySqlHelper.ExecuteNonQuery(dataTransferLogSql) : 0;
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr);//插入朗速日志表
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, ex.Message.Replace("'", "''"));
|
||
}
|
||
}
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr);
|
||
#endregion
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
#endregion
|
||
break;
|
||
}
|
||
MySqlHelper._connection.Close();
|
||
MySqlHelper._connection.Dispose();
|
||
SqlHelper._connection.Close();
|
||
SqlHelper._connection.Dispose();
|
||
return asyncNo;
|
||
});
|
||
return asyncNo;
|
||
}
|
||
#endregion
|
||
#region 多任务处理_批量获取数据
|
||
public async System.Threading.Tasks.Task<string> GetDataBatch(AbutmentModel abutmentModel, DataRow item, DataRow sourceRow, DataDirection dataDirection, int TabNameTag, int ErrorNumber)
|
||
{
|
||
string dataTransferSql = "";//执行数据传递sql
|
||
await System.Threading.Tasks.Task.Run(() =>
|
||
{
|
||
string logErrorMessage = "";
|
||
string lsErrorLogSqlStr = "";//朗速日志表
|
||
string getSourcePrimaryKey = "";
|
||
string sourcePrimaryKey = "";
|
||
string primaryValue = "";
|
||
string insertKeysStr = "";
|
||
string insertValuesStr = "";
|
||
#region 新增
|
||
getSourcePrimaryKey = dataDirection == 0 ? abutmentModel.lsPrimaryKey : abutmentModel.afkPrimaryKey;
|
||
sourcePrimaryKey = dataDirection == 0 ? abutmentModel.afkPrimaryKey : abutmentModel.lsPrimaryKey;
|
||
primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
try
|
||
{
|
||
string getSourceKeys = dataDirection == 0 ? abutmentModel.lsTargeFields : abutmentModel.afkTargeFields;//接收数据表字段
|
||
if (TabNameTag == 1)
|
||
GetInsertSqlStr(sourceRow, getSourceKeys, abutmentModel.afkTargeFields, abutmentModel.lsTempTabName, out insertKeysStr, out insertValuesStr, out dataTransferSql, dataDirection, abutmentModel.uuid, true);
|
||
else
|
||
GetInsertSqlStr(sourceRow, getSourceKeys, abutmentModel.afkTargeFields, abutmentModel.getSourceTabName, out insertKeysStr, out insertValuesStr, out dataTransferSql, dataDirection);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
logErrorMessage = ex.Message.Replace("'", "''");
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
finally
|
||
{
|
||
try
|
||
{
|
||
if (!string.IsNullOrEmpty(lsErrorLogSqlStr))
|
||
SqlHelper.ExecuteNonQuery(lsErrorLogSqlStr);//插入朗速日志表
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
#endregion
|
||
return dataTransferSql;
|
||
});
|
||
return dataTransferSql;
|
||
}
|
||
#endregion
|
||
#region 多任务处理_批量获取日志数据
|
||
public async System.Threading.Tasks.Task<string> GetDataLogBatch(AbutmentModel abutmentModel, DataRow selectLogRow, DataRow item, DataRow sourceRow, DataDirection dataDirection, int ErrorNumber)
|
||
{
|
||
string dataTransferLogSql = "";//执行数据传递sql
|
||
await System.Threading.Tasks.Task.Run(() =>
|
||
{
|
||
if (abutmentModel.synLogStrs.Length == 3)
|
||
{
|
||
string logSucceeId = "";
|
||
string logErrorType = "";
|
||
string logErrorMessage = "";
|
||
try
|
||
{
|
||
//string afkPrimaryValue = sourceRow["suuid"] + "";
|
||
//DataRow selectLogRow = selectLogTab.Select().Where(n => (n["suuid"] + "").Equals(afkPrimaryValue)).FirstOrDefault();
|
||
if (selectLogRow == null)
|
||
{
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = "未查询到临时表数据,可能是因为PRIMARY文件组已满或其他未知错误";
|
||
}
|
||
else
|
||
{
|
||
logSucceeId = (selectLogRow["synchroSuccess"] + "").Equals("成功") ? "1" : "2";
|
||
logErrorType = logSucceeId.Equals("2") ? "1" : "0";
|
||
logErrorMessage = selectLogRow["synchroMessage"] + "";
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logSucceeId = "2";
|
||
logErrorType = "1";
|
||
logErrorMessage = ex.Message;
|
||
}
|
||
string lsErrorLogSqlStr = "";//朗速日志表
|
||
string getSourcePrimaryKey = "";
|
||
string sourcePrimaryKey = "";
|
||
string primaryValue = "";
|
||
string insertKeysStr = "";
|
||
string insertValuesStr = "";
|
||
string dataTransferSql = "";
|
||
#region 新增
|
||
lsErrorLogSqlStr = "";
|
||
getSourcePrimaryKey = dataDirection == 0 ? abutmentModel.lsPrimaryKey : abutmentModel.afkPrimaryKey;
|
||
sourcePrimaryKey = dataDirection == 0 ? abutmentModel.afkPrimaryKey : abutmentModel.lsPrimaryKey;
|
||
primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
insertKeysStr = "";//insert语句keys
|
||
insertValuesStr = "";//insert语句values
|
||
try
|
||
{
|
||
string getSourceKeys = dataDirection == 0 ? abutmentModel.lsTargeFields : abutmentModel.afkTargeFields;//接收数据表字段
|
||
GetInsertSqlStr(sourceRow, getSourceKeys, abutmentModel.afkTargeFields, abutmentModel.getSourceTabName, out insertKeysStr, out insertValuesStr, out dataTransferSql, dataDirection);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorNumber++;
|
||
logErrorMessage = ex.Message;
|
||
lsErrorLogSqlStr = string.Format("insert into P_RemarkTable(LsTableName,PrimKey,PrimKeyValue,Messages) values ('{0}','{1}','{2}','{3}')", abutmentModel.afkTabName, abutmentModel.afkPrimaryKey, primaryValue, logErrorMessage);
|
||
}
|
||
finally
|
||
{
|
||
string[] logArgs = new string[] { logSucceeId, logErrorType, logErrorMessage.Replace("'", "''") };
|
||
GetLogSqlStr(abutmentModel.logFields, abutmentModel.logAsFields, logArgs, insertKeysStr, insertValuesStr, abutmentModel.logTabName, out dataTransferLogSql);
|
||
}
|
||
}
|
||
#endregion
|
||
return dataTransferLogSql;
|
||
});
|
||
return dataTransferLogSql;
|
||
}
|
||
#endregion
|
||
#region 更新同步字段
|
||
private void updateIssychro(string dataName, string primary, DataRow sourceRow)
|
||
{
|
||
string primaryValue = !string.IsNullOrEmpty(primary) ? sourceRow[primary] + "" : "";
|
||
string sql = "update {0} set issynchro ='0' where {1}='{2}'";
|
||
sql = string.Format(sql, dataName, primary, primaryValue);
|
||
MySqlHelper.ExecuteNonQuery(sql);
|
||
}
|
||
#endregion
|
||
#region 反写固定存储过程些入出库单
|
||
/// <summary>
|
||
/// 反写固定存储过程些入出库单
|
||
/// </summary>
|
||
/// <param name="name">数据行中name字段</param>
|
||
/// <param name="logisticsid">数据行中logisticsid字段</param>
|
||
/// <returns></returns>
|
||
public static string BillOutPush(DataRow sourceRow, string type)
|
||
{
|
||
string name = sourceRow.Table.Columns.Contains("name") ? sourceRow["name"] + "" : "";
|
||
string logisticsid = sourceRow.Table.Columns.Contains("logisticsid") ? sourceRow["logisticsid"] + "" : "";
|
||
string operatorName = "管理员", operatorId = "1";
|
||
if (!string.IsNullOrEmpty(name))
|
||
{
|
||
|
||
string sql = string.Format("select employeeid,employeename from p_employeetab where employeename = '{0}'", name);
|
||
DataTable DataOperTable = SqlHelperOther.ExecuteDataTable(sql);
|
||
if (DataOperTable.Rows.Count > 0)
|
||
{
|
||
operatorId = DataOperTable.Rows[0]["employeeid"] + "";
|
||
operatorName = DataOperTable.Rows[0]["employeename"] + "";
|
||
}
|
||
}
|
||
SqlParameter msg = new SqlParameter("@msg", SqlDbType.VarChar, 3000);
|
||
msg.Direction = ParameterDirection.Output;
|
||
List<SqlParameter> list = new List<SqlParameter>
|
||
{
|
||
new SqlParameter("@nbgys",SqlDbType.VarChar,10),
|
||
new SqlParameter("@type",SqlDbType.Int,4),
|
||
new SqlParameter("@keyvalue",SqlDbType.VarChar,200),
|
||
new SqlParameter("@operatorId",SqlDbType.Int,4),
|
||
new SqlParameter("@operatorName",SqlDbType.VarChar,20),
|
||
msg,
|
||
};
|
||
|
||
SqlParameter[] param = list.ToArray();
|
||
param[0].Value = "e25d5dd2b4b74dd99f79227d8db5b4c7";
|
||
param[1].Value = type;
|
||
param[2].Value = logisticsid;
|
||
param[3].Value = operatorId;
|
||
param[4].Value = operatorName;
|
||
param[5].Value = "";
|
||
try
|
||
{
|
||
SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "wms_createbillpr", "billpr", param);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
return msg.Value + "";
|
||
}
|
||
return msg.Value + "";
|
||
}
|
||
#endregion
|
||
#region 判断主键值是否已经存在
|
||
private bool IsExistPrimaryValue(DataRow sourceRow, string getSourceTabName, string getSourcePrimaryKey, string sourcePrimaryKey, DataDirection dataDirection)
|
||
{
|
||
string primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
if (!string.IsNullOrEmpty(primaryValue))
|
||
{
|
||
string isExistSql = string.Format("select {0} from {1} with(nolock) where {2}='{3}'", getSourcePrimaryKey, getSourceTabName, getSourcePrimaryKey, primaryValue);
|
||
DataTable resultTab = new DataTable();
|
||
if (dataDirection == 0)
|
||
resultTab = SqlHelper.ExecuteDataTable(isExistSql);
|
||
else
|
||
resultTab = MySqlHelper.ExecuteDataTable(isExistSql);
|
||
if (resultTab.Rows.Count > 0)
|
||
return true;
|
||
else
|
||
return false;
|
||
}
|
||
else
|
||
return false;
|
||
}
|
||
#endregion
|
||
#region 判断值是否可以为空
|
||
//sql表格属性表 mysql表格属性表 行数据 ls数据库中的列 afk列 方向
|
||
private string IsValueBlank(DataTable SQLQueryPropertySheet, DataTable MYSQLPropertySheet, DataRow sourceRow, string LsColumnName, string AfkColumnName, DataDirection dataDirection)
|
||
{
|
||
string key = string.Empty;
|
||
string Value = string.Empty;
|
||
string SaveErrorMessage = string.Empty;//提示信息
|
||
|
||
//判断存入的值是否为空
|
||
string[] LsColumnNames = LsColumnName.Split(',');
|
||
string[] AfkColumnNames = AfkColumnName.Split(',');
|
||
|
||
for (int i = 0; i < AfkColumnNames.Length - 1; i++)
|
||
{
|
||
//获取数据源中当前列名
|
||
key = (dataDirection == 0) ? (AfkColumnNames[i] + "").Trim() : (LsColumnNames[i] + "").Trim();
|
||
if (key.Contains("getdate()")) continue;
|
||
|
||
//获取AFK列名或注释
|
||
DataRow[] ListOfAttributes = MYSQLPropertySheet.Select("Field='" + (AfkColumnNames[i] + "").Trim() + "'");
|
||
string name = AfkColumnNames[i];
|
||
if ((!string.IsNullOrWhiteSpace(ListOfAttributes[0]["Comment"] + "")) && (ListOfAttributes[0]["Comment"] + "").Length < 5)
|
||
{
|
||
name = ListOfAttributes[0]["Comment"] + "";
|
||
}
|
||
//当前列的值
|
||
Value = sourceRow[key] + "";
|
||
|
||
//判断是否为空
|
||
if (dataDirection == 0)
|
||
{
|
||
SaveErrorMessage += DatabaseFormatJudgment.SQLQueryVerification(SQLQueryPropertySheet, (LsColumnNames[i] + "").Trim(), Value, name);
|
||
}
|
||
else
|
||
{
|
||
SaveErrorMessage += DatabaseFormatJudgment.MYSqlVerification(MYSQLPropertySheet, (AfkColumnNames[i] + "").Trim(), Value, name);
|
||
}
|
||
}
|
||
return SaveErrorMessage;
|
||
}
|
||
#endregion
|
||
#region 获取insert语句
|
||
private void GetInsertSqlStr(DataRow sourceRow, string getSourceKeys, string afkTargeFields, string getSourceTabName, out string insertKeysStr, out string insertValuesStr, out string dataTransferSql, DataDirection dataDirection, string uuid = "", bool isBatchInsert = false)
|
||
{
|
||
StringBuilder insertKeys = new StringBuilder();
|
||
StringBuilder insertValues = new StringBuilder();
|
||
StringBuilder afkTargeFieldKey = new StringBuilder();
|
||
string insertSql = "insert into {0} ({1}) values ({2})";
|
||
string[] getSourceKeysList = getSourceKeys.Split(',');
|
||
string[] afkTargeFieldsList = afkTargeFields.Split(',');
|
||
for (int i = 0; i < sourceRow.Table.Columns.Count; i++)//循环拼接insert语句
|
||
{
|
||
try
|
||
{
|
||
string sourceKey = sourceRow.Table.Columns[i].ColumnName;
|
||
if (sourceKey.Equals("suuid"))
|
||
{
|
||
continue;
|
||
}
|
||
string intermediateLogKey = afkTargeFieldsList[i];
|
||
string getSourceKey = getSourceKeysList[i];
|
||
string sourceValue = sourceRow[sourceKey] + "";
|
||
if (sourceValue.Contains("'"))
|
||
sourceValue = sourceValue.Replace("'", "''");
|
||
sourceValue = GetTheRealValue(sourceRow.Table.Columns[i], sourceValue);//转换某些特殊值
|
||
if (getSourceKey.Contains("#add$_"))
|
||
{
|
||
getSourceKey = getSourceKey.Replace("#add$_", "");
|
||
afkTargeFieldKey = afkTargeFieldKey.Replace("#add$_", "");
|
||
}
|
||
insertKeys.Append(string.Format("{0},", getSourceKey));
|
||
afkTargeFieldKey.Append(string.Format("{0},", intermediateLogKey));
|
||
insertValues.Append(sourceValue.Equals("null") ? string.Format("{0},", sourceValue) : string.Format("'{0}',", sourceValue));
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
if (isBatchInsert && dataDirection == 0)
|
||
{
|
||
try
|
||
{
|
||
string lsExistSuuidStr = string.Format(@"if not exists(select * from syscolumns
|
||
where id=object_id('{0}') and name='suuid')
|
||
begin
|
||
alter table {0} add suuid varchar(100)
|
||
end", getSourceTabName);
|
||
SqlHelper.ExecuteNonQuery(lsExistSuuidStr);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
//if (!sourceRow.Table.Columns.Contains("suuid"))
|
||
//{
|
||
// sourceRow.Table.Columns.Add("suuid");
|
||
//}
|
||
string sourceIndex = "";
|
||
string suuidend = "";
|
||
string tagid = "";
|
||
try
|
||
{
|
||
string operation = sourceRow.Table.Columns.Contains("tagid") ? "tagid" : sourceRow.Table.Columns.Contains("tag_id") ? "tag_id" : "";//获取执方式的字段
|
||
if (!string.IsNullOrEmpty(operation))
|
||
{
|
||
tagid = sourceRow[operation] + "";
|
||
}
|
||
sourceIndex = sourceRow.Table.Rows.IndexOf(sourceRow) + "";
|
||
suuidend = System.Guid.NewGuid().ToString("N");
|
||
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
string suuid = string.Format("{0}-{1}-{2}-{3}", uuid, suuidend, tagid, sourceIndex);
|
||
sourceRow["suuid"] = suuid;//添加唯一主键
|
||
insertKeys.Append("suuid,");
|
||
insertValues.Append(string.Format("'{0}',", suuid));
|
||
insertKeys.Append("uuid,");
|
||
insertValues.Append(string.Format("'{0}',", uuid));
|
||
}
|
||
insertKeysStr = afkTargeFieldKey.ToString();
|
||
insertValuesStr = insertValues.ToString();
|
||
//dataTransferSql = string.Format(insertSql, getSourceTabName, insertKeys.TrimEnd(','), insertValues.TrimEnd(','));
|
||
dataTransferSql = dataDirection == 0 ? string.Format(insertSql, getSourceTabName, insertKeys + "directTag", insertValues + "2") : string.Format(insertSql, getSourceTabName, insertKeys.ToString().TrimEnd(','), insertValues.ToString().TrimEnd(','));
|
||
}
|
||
#endregion
|
||
#region 获取update语句
|
||
private void GetUpdateSqlStr(DataRow sourceRow, string getSourceKeys, string afkTargeFields, string getSourceTabName, string getSourcePrimaryKey, string sourcePrimaryKey, out string insertLogKeysStr, out string insertLogValuesStr, out string dataTransferSql)
|
||
{
|
||
string primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
StringBuilder insertKeys = new StringBuilder();
|
||
StringBuilder insertValues = new StringBuilder();
|
||
StringBuilder updateKeyValues = new StringBuilder();
|
||
StringBuilder afkTargeFieldKey = new StringBuilder();
|
||
string updateSql = "update {0} set {1} where {2}";
|
||
string[] getSourceKeysList = getSourceKeys.Split(',');
|
||
string[] afkTargeFieldsList = afkTargeFields.Split(',');
|
||
for (int i = 0; i < sourceRow.Table.Columns.Count; i++)//循环拼接insert语句
|
||
{
|
||
try
|
||
{
|
||
string getSourceKey = getSourceKeysList[i];
|
||
string intermediateLogKey = afkTargeFieldsList[i];
|
||
string sourceKey = sourceRow.Table.Columns[i].ColumnName;
|
||
string sourceValue = sourceRow[sourceKey] + "";
|
||
if (sourceValue.Contains("'"))
|
||
sourceValue = sourceValue.Replace("'", "''");
|
||
sourceValue = GetTheRealValue(sourceRow.Table.Columns[i], sourceValue);//转换某些特殊值
|
||
if (getSourceKey.Contains("#add$_"))
|
||
{
|
||
afkTargeFieldKey.Append(string.Format("{0},", intermediateLogKey));
|
||
insertKeys.Append(string.Format("{0},", getSourceKey));
|
||
insertValues.Append(sourceValue.Equals("null") ? string.Format("{0},", sourceValue) : string.Format("'{0}',", sourceValue));
|
||
continue;
|
||
}
|
||
updateKeyValues.Append(sourceValue.Equals("null") ? string.Format("{0}={1},", getSourceKey, sourceValue) : string.Format("{0}='{1}',", getSourceKey, sourceValue));
|
||
afkTargeFieldKey.Append(string.Format("{0},", intermediateLogKey));
|
||
insertKeys.Append(string.Format("{0},", getSourceKey));
|
||
insertValues.Append(sourceValue.Equals("null") ? string.Format("{0},", sourceValue) : string.Format("'{0}',", sourceValue));
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
}
|
||
insertLogKeysStr = afkTargeFieldKey.ToString();
|
||
insertLogValuesStr = insertValues.ToString();
|
||
string updateCond = string.Format("{0}='{1}'", getSourcePrimaryKey, primaryValue);
|
||
dataTransferSql = string.Format(updateSql, getSourceTabName, updateKeyValues.ToString().TrimEnd(','), updateCond);
|
||
}
|
||
#endregion
|
||
#region 获取改变状态语句
|
||
private void GetChangeStateSqlStr(DataRow sourceRow, string stateFieid, string getSourceKeys, string afkTargeFields, string getSourceTabName, string getSourcePrimaryKey, string sourcePrimaryKey, out string insertLogKeysStr, out string insertLogValuesStr, out string dataTransferSql)
|
||
{
|
||
string primaryValue = !string.IsNullOrEmpty(sourcePrimaryKey) ? sourceRow[sourcePrimaryKey] + "" : "";
|
||
StringBuilder insertKeys = new StringBuilder();
|
||
StringBuilder insertValues = new StringBuilder();
|
||
StringBuilder afkTargeFieldKey = new StringBuilder();
|
||
string updateSql = "update {0} set {1} where {2}";
|
||
string[] getSourceKeysList = getSourceKeys.Split(',');
|
||
string[] afkTargeFieldsList = afkTargeFields.Split(',');
|
||
for (int i = 0; i < sourceRow.Table.Columns.Count; i++)//循环拼接insert语句
|
||
{
|
||
string getSourceKey = getSourceKeysList[i];
|
||
string intermediateLogKey = afkTargeFieldsList[i];
|
||
string sourceKey = sourceRow.Table.Columns[i].ColumnName;
|
||
string sourceValue = sourceRow[sourceKey] + "";
|
||
if (sourceValue.Contains("'"))
|
||
sourceValue = sourceValue.Replace("'", "''");
|
||
sourceValue = GetTheRealValue(sourceRow.Table.Columns[i], sourceValue);//转换某些特殊值
|
||
if (getSourceKey.Contains("#add$_"))
|
||
getSourceKey = getSourceKey.Replace("#add$_", "");
|
||
if (intermediateLogKey.Contains("#add$_"))
|
||
intermediateLogKey = intermediateLogKey.Replace("#add$_", "");
|
||
|
||
afkTargeFieldKey.Append(string.Format("{0},", intermediateLogKey));
|
||
insertKeys.Append(string.Format("{0},", getSourceKey));
|
||
insertValues.Append(sourceValue.Equals("null") ? string.Format("{0},", sourceValue) : string.Format("'{0}',", sourceValue));
|
||
}
|
||
insertLogKeysStr = afkTargeFieldKey.ToString();
|
||
insertLogValuesStr = insertValues.ToString();
|
||
string updateCond = string.Format("{0}='{1}'", getSourcePrimaryKey, primaryValue);
|
||
dataTransferSql = string.Format(updateSql, getSourceTabName, stateFieid, updateCond);
|
||
}
|
||
#endregion
|
||
#region 获取logInsert语句
|
||
private void GetLogSqlStr(string[] logFields, string[] logAsFields, string[] logArgs, string insertKeysStr, string insertValuesStr, string logTabName, out string dataTransferLogSql)
|
||
{
|
||
StringBuilder insertLogKeys = new StringBuilder(insertKeysStr);
|
||
StringBuilder insertLogValues = new StringBuilder(insertValuesStr);
|
||
string logSqlStr = "insert into {0} ({1}) values ({2})";
|
||
for (int i = 0; i < logAsFields.Length; i++)
|
||
{
|
||
string logField = logFields[i];
|
||
string logAsField = logAsFields[i];
|
||
insertLogKeys.Append(string.Format("{0},", logField));
|
||
if (logAsField.Equals("getdate()", StringComparison.OrdinalIgnoreCase))
|
||
insertLogValues.Append(string.Format("{0},", "now()"));
|
||
else if (logAsField.Equals("@transferLogo", StringComparison.OrdinalIgnoreCase))
|
||
insertLogValues.Append(string.Format("'{0}',", logArgs[0]));
|
||
else if (logAsField.Equals("@errortype", StringComparison.OrdinalIgnoreCase))
|
||
insertLogValues.Append(string.Format("'{0}',", logArgs[1]));
|
||
else if (logAsField.Equals("@errormessage", StringComparison.OrdinalIgnoreCase))
|
||
insertLogValues.Append(string.Format("'{0}',", logArgs[2]));
|
||
else
|
||
insertLogValues.Append(string.Format("{0},", "null"));
|
||
}
|
||
dataTransferLogSql = string.Format(logSqlStr, logTabName, insertLogKeys.ToString().TrimEnd(','), insertLogValues.ToString().TrimEnd(','));
|
||
}
|
||
#endregion
|
||
#region 替换行数据
|
||
public string ReplaceRowValue(string defaultValue, DataRow row)
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(defaultValue))
|
||
{
|
||
var paramList = GetParamFields(defaultValue);
|
||
foreach (string item in paramList)
|
||
{
|
||
string field = item.Replace("}", "").Replace("{", "").ToLower();
|
||
string value = row.Table.Columns.Contains(field) ? row[field] + "" : "";
|
||
defaultValue = defaultValue.Replace(item, value);
|
||
}
|
||
}
|
||
return defaultValue;
|
||
}
|
||
|
||
public List<string> GetParamFields(string defaultValue)
|
||
{
|
||
List<string> list = new List<string>();
|
||
Regex regex = new Regex("{([^{])+}");
|
||
MatchCollection mcs = regex.Matches(defaultValue);
|
||
foreach (Match item in mcs)
|
||
{
|
||
if (list.IndexOf(item.Value) == -1)
|
||
list.Add(item.Value);
|
||
}
|
||
return list;
|
||
}
|
||
#endregion
|
||
private void InitLsToAfkGrid()
|
||
{
|
||
DataTable dataTable = new DataTable();
|
||
dataTable.Columns.Add("id");
|
||
dataTable.Columns.Add("direction");
|
||
dataTable.Columns.Add("tabName");
|
||
dataTable.Columns.Add("issucceed");
|
||
dataTable.Columns.Add("errorMsg");
|
||
dataTable.Columns.Add("loopNum");
|
||
this.LsToAfkGrid.DataSource = dataTable;
|
||
this.LsToAfkGridView.BestFitColumns();
|
||
}
|
||
private void InitAfkToLsGrid()
|
||
{
|
||
DataTable dataTable = new DataTable();
|
||
dataTable.Columns.Add("id");
|
||
dataTable.Columns.Add("direction");
|
||
dataTable.Columns.Add("tabName");
|
||
dataTable.Columns.Add("issucceed");
|
||
dataTable.Columns.Add("errorMsg");
|
||
dataTable.Columns.Add("loopNum");
|
||
this.AfkToLsGrid.DataSource = dataTable;
|
||
this.AfkToLsGridView.BestFitColumns();
|
||
}
|
||
#endregion
|
||
/// <summary>
|
||
/// <para>说明:获取中间表的主键值,没有就创建标识列</para>
|
||
/// <para>创建人:</para>
|
||
/// <para>创建日期: </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public static string MysqlGetPrimaryKey(string TableName)
|
||
{
|
||
string PrimaryKeyName = string.Empty;
|
||
string sql = string.Format(" SHOW KEYS FROM {0} WHERE Key_name = 'PRIMARY'", TableName);
|
||
DataTable dt = MySqlHelper.ExecuteDataTable(sql);
|
||
if (dt != null && dt.Rows.Count > 0)
|
||
{
|
||
PrimaryKeyName = dt.Rows[0]["Column_name"] + "";
|
||
}
|
||
if (string.IsNullOrWhiteSpace(PrimaryKeyName))
|
||
{
|
||
//没有主键就创建自增长列
|
||
sql = string.Format(@"alter table {0} add AutoPrimaryKey BIGINT;
|
||
alter table {0} change AutoPrimaryKey AutoPrimaryKey BIGINT not null auto_increment primary key; ", TableName);
|
||
MySqlHelper.ExecuteNonQuery(sql);
|
||
PrimaryKeyName = "AutoPrimaryKey";
|
||
}
|
||
return PrimaryKeyName;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:获取表的主键值</para>
|
||
/// <para>创建人:王一帆</para>
|
||
/// <para>创建日期:2020-05-07 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public static string GetPrimaryKey(string TableName)
|
||
{
|
||
string sqlValue = string.Format("SELECT TABLE_NAME,COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME='{0}'", TableName);
|
||
DataTable dtTable = SqlHelper.ExecuteDataTable(sqlValue);
|
||
return (dtTable.Rows.Count > 0) ? dtTable.Rows[0]["COLUMN_NAME"] + "" : string.Empty;
|
||
}
|
||
/// <summary>
|
||
/// 主线程刷新数据
|
||
/// </summary>
|
||
/// <param name="msg"></param>
|
||
public void RefreshLog(string msg)
|
||
{
|
||
//txtLog.Text += msg;
|
||
//txtLog.Select(txtLog.TextLength, 0);
|
||
//txtLog.ScrollToCaret();
|
||
}
|
||
/// <summary>
|
||
/// 后台线程刷新数据
|
||
/// </summary>
|
||
/// <param name="msg"></param>
|
||
public void RefreshLogUIThread(string msg)
|
||
{
|
||
Invoke((EventHandler)delegate
|
||
{
|
||
//if (msg.Equals("清空"))
|
||
//{
|
||
// txtLog.Clear();
|
||
// txtLog.Select(txtLog.TextLength, 0);
|
||
// txtLog.ScrollToCaret();
|
||
//}
|
||
//else
|
||
//{
|
||
// txtLog.Text += msg;
|
||
// txtLog.Select(txtLog.TextLength, 0);
|
||
// txtLog.ScrollToCaret();
|
||
//}G
|
||
});
|
||
}
|
||
private void RefreshLogUIThread(GridControl gridControl, int id, string colName, string value)
|
||
{
|
||
if (gridControl.InvokeRequired)
|
||
{
|
||
// 当一个控件的InvokeRequired属性值为真时,说明有一个创建它以外的线程想访问它
|
||
Action<string, string> actionDelegate = (x, y) =>
|
||
{
|
||
DataTable dataTable = gridControl.DataSource as DataTable;
|
||
DataRow[] selectRows = dataTable.Select(string.Format("id='{0}'", id + ""));
|
||
if (selectRows.Count() > 0)
|
||
{
|
||
DataRow selectRow = selectRows[0];
|
||
selectRow[colName] = value;
|
||
}
|
||
};
|
||
this.gridControl.Invoke(actionDelegate, colName, value);
|
||
}
|
||
}
|
||
private void RefreshLogUIAddRow(GridControl gridControl, int id)
|
||
{
|
||
if (gridControl.InvokeRequired)
|
||
{
|
||
// 当一个控件的InvokeRequired属性值为真时,说明有一个创建它以外的线程想访问它
|
||
Action<GridControl> actionDelegate = (x) =>
|
||
{
|
||
|
||
DataTable dataTable = gridControl.DataSource as DataTable;
|
||
DataRow[] selectRows = dataTable.Select(string.Format("id='{0}'", id + ""));
|
||
if (selectRows.Count() > 0)
|
||
{
|
||
DataRow selecrRow = selectRows[0];
|
||
selecrRow["direction"] = "";
|
||
selecrRow["tabName"] = "";
|
||
selecrRow["issucceed"] = "";
|
||
selecrRow["errorMsg"] = "";
|
||
string loopNum = selecrRow["loopNum"] + "";
|
||
int num = 1;
|
||
if (Convert.ToInt32(loopNum) < 1000)
|
||
{
|
||
num = Convert.ToInt32(loopNum) + 1;
|
||
}
|
||
selecrRow["loopNum"] = num + "";
|
||
}
|
||
else
|
||
{
|
||
DataRow dataRow = dataTable.NewRow();
|
||
dataRow["id"] = id + "";
|
||
dataRow["loopNum"] = "1";
|
||
dataTable.Rows.Add(dataRow);
|
||
}
|
||
};
|
||
this.gridControl.Invoke(actionDelegate, gridControl);
|
||
}
|
||
}
|
||
#region 连接朗速服务器
|
||
/// <summary>
|
||
/// <para>说明:连接服务器</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-08-09 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="isSave">if set to <c>true</c> [is save].</param>
|
||
public bool ConnectServer(bool isSave = false)
|
||
{
|
||
string serverName = this.lsSeverId.Text.Trim();//地址
|
||
string dbName = this.lsDataBase.Text.Trim();//数据库名
|
||
string user = this.lsName.Text.Trim();//用户名
|
||
string password = this.lsPassword.Text.Trim();//密码
|
||
|
||
if (string.IsNullOrWhiteSpace(serverName))
|
||
{
|
||
MessageUtil.Show("请重新输入朗速数据库地址");
|
||
return false;
|
||
}
|
||
|
||
if (string.IsNullOrWhiteSpace(dbName))
|
||
{
|
||
MessageUtil.Show("请重新输入朗速数据库库名");
|
||
return false;
|
||
}
|
||
|
||
if (string.IsNullOrWhiteSpace(user))
|
||
{
|
||
MessageUtil.Show("请重新输入朗速数据库用户名");
|
||
return false;
|
||
}
|
||
|
||
|
||
// 测试数据库连接
|
||
try
|
||
{
|
||
if (ConnectingToDatabase())
|
||
{
|
||
if (isSave)
|
||
{
|
||
|
||
}
|
||
else
|
||
{
|
||
IniHelper.Write("LS", "serverName", serverName);
|
||
IniHelper.Write("LS", "dbName", dbName);
|
||
IniHelper.Write("LS", "user", user);
|
||
IniHelper.Write("LS", "password", password);
|
||
RefreshLogUIThread(DateTime.Now + "朗速数据库连接成功.\r\n");
|
||
return true;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
MessageUtil.Show("连接失败,请检查朗速方配置");
|
||
return false;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageUtil.Show("连接失败,请检查朗速方配置");
|
||
|
||
}
|
||
return true;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:连接服务器</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-08-09 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <param name="isSave">if set to <c>true</c> [is save].</param>
|
||
public bool ConnectServerOther(bool isSave = false)
|
||
{
|
||
string serverName = this.lsSeverId.Text.Trim();//地址
|
||
string dbName = this.lsDataBase.Text.Trim();//数据库名
|
||
string user = this.lsName.Text.Trim();//用户名
|
||
string password = this.lsPassword.Text.Trim();//密码
|
||
|
||
if (string.IsNullOrWhiteSpace(serverName))
|
||
{
|
||
MessageUtil.Show("请重新输入朗速数据库地址");
|
||
return false;
|
||
}
|
||
|
||
if (string.IsNullOrWhiteSpace(dbName))
|
||
{
|
||
MessageUtil.Show("请重新输入朗速数据库库名");
|
||
return false;
|
||
}
|
||
|
||
if (string.IsNullOrWhiteSpace(user))
|
||
{
|
||
MessageUtil.Show("请重新输入朗速数据库用户名");
|
||
return false;
|
||
}
|
||
|
||
|
||
// 测试数据库连接
|
||
try
|
||
{
|
||
if (ConnectingToDatabaseOther())
|
||
{
|
||
if (isSave)
|
||
{
|
||
|
||
}
|
||
else
|
||
{
|
||
IniHelper.Write("LS", "serverName", serverName);
|
||
IniHelper.Write("LS", "dbName", dbName);
|
||
IniHelper.Write("LS", "user", user);
|
||
IniHelper.Write("LS", "password", password);
|
||
return true;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
MessageUtil.Show("连接失败,请检查朗速方配置");
|
||
return false;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageUtil.Show("连接失败,请检查朗速方配置");
|
||
|
||
}
|
||
return true;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:创建数据库连接</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-08-07 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
||
public bool ConnectingToDatabase()
|
||
{
|
||
string connStr = GetConnection();
|
||
sqlHelperConStr = connStr;
|
||
if (SqlHelper._connection != null)
|
||
{
|
||
try
|
||
{
|
||
SqlHelper._connection.Close();
|
||
SqlHelper._connection.Dispose();
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
SqlHelper._connection = null;
|
||
}
|
||
try
|
||
{
|
||
SqlHelper._connection = new SqlConnection(connStr);
|
||
SqlHelper._connection.Open();
|
||
return true;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
// LogHelper.Instance.WriteLog(ex.Message);
|
||
}
|
||
return false;
|
||
}
|
||
/// <summary>
|
||
/// <para>说明:创建数据库连接</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-08-07 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
||
public bool ConnectingToDatabaseOther()
|
||
{
|
||
string connStr = GetConnection();
|
||
if (SqlHelperOther._connection != null)
|
||
{
|
||
try
|
||
{
|
||
SqlHelperOther._connection.Close();
|
||
SqlHelperOther._connection.Dispose();
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
SqlHelperOther._connection = null;
|
||
}
|
||
try
|
||
{
|
||
SqlHelperOther._connection = new SqlConnection(connStr);
|
||
SqlHelperOther._connection.Open();
|
||
return true;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
// LogHelper.Instance.WriteLog(ex.Message);
|
||
}
|
||
return false;
|
||
}
|
||
/// <summary>
|
||
/// 获取连接服务器的字符串
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public string GetConnection()
|
||
{
|
||
return string.Format("Server={0};Database={1};Persist Security Info=True;User ID={2};Password={3};Connection Timeout=5;MultipleActiveResultSets=true", lsSeverId.Text + "", lsDataBase.Text + "", lsName.Text + "", lsPassword.Text + "");
|
||
}
|
||
#endregion
|
||
#region 连接Afk服务器
|
||
public bool ConnectMySql(bool isSave = false)
|
||
{
|
||
string connStr = GetConnection2();
|
||
string serverName = this.afkSeverId.Text.Trim();//地址
|
||
string port = this.afkPortNumber.Text.Trim();//端口
|
||
string dbName = this.afkDataBase.Text.Trim();//数据库名
|
||
string user = this.afkName.Text.Trim();//用户名
|
||
string password = this.afkPassword.Text.Trim();//密码
|
||
|
||
if (string.IsNullOrWhiteSpace(serverName))
|
||
{
|
||
MessageUtil.Show("请重新输入Afk数据库地址");
|
||
return false;
|
||
}
|
||
|
||
if (string.IsNullOrWhiteSpace(port))
|
||
{
|
||
MessageUtil.Show("请重新输入Afk数据库端口");
|
||
return false;
|
||
}
|
||
|
||
if (string.IsNullOrWhiteSpace(dbName))
|
||
{
|
||
MessageUtil.Show("请重新输入Afk数据库库名");
|
||
return false;
|
||
}
|
||
|
||
if (string.IsNullOrWhiteSpace(user))
|
||
{
|
||
MessageUtil.Show("请重新输入Afk数据库用户名");
|
||
return false;
|
||
}
|
||
|
||
// 测试数据库连接
|
||
try
|
||
{
|
||
if (ConnectingToDatabase2())
|
||
{
|
||
if (isSave)
|
||
{
|
||
|
||
}
|
||
else
|
||
{
|
||
IniHelper.Write("AFK", "serverName", serverName);
|
||
IniHelper.Write("AFK", "port", port);
|
||
IniHelper.Write("AFK", "dbName", dbName);
|
||
IniHelper.Write("AFK", "user", user);
|
||
IniHelper.Write("AFK", "password", password);
|
||
RefreshLogUIThread(DateTime.Now + "AFK数据库连接成功.\r\n");
|
||
return true;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
MessageUtil.Show("连接失败,请检查AFK方配置");
|
||
return false;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageUtil.Show("连接失败,请检查AFK方配置");
|
||
|
||
}
|
||
return true;
|
||
|
||
return true;
|
||
}
|
||
|
||
/// <summary>
|
||
/// <para>说明:创建数据库连接</para>
|
||
/// <para>创建人:龚宇超</para>
|
||
/// <para>创建日期:2017-08-07 </para>
|
||
/// <para>修改人:</para>
|
||
/// <para>修改日期:</para>
|
||
/// <para>修改备注:</para>
|
||
/// <para>版本:1.0</para>
|
||
/// </summary>
|
||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
||
public bool ConnectingToDatabase2()
|
||
{
|
||
string connStr = GetConnection2();
|
||
mySqlHelperConStr = connStr;
|
||
if (MySqlHelper._connection != null)
|
||
{
|
||
try
|
||
{
|
||
MySqlHelper._connection.Close();
|
||
MySqlHelper._connection.Dispose();
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
MySqlHelper._connection = null;
|
||
}
|
||
try
|
||
{
|
||
MySqlHelper._connection = new MySqlConnection(connStr);
|
||
MySqlHelper._connection.Open();
|
||
return true;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
// LogHelper.Instance.WriteLog(ex.Message);
|
||
}
|
||
return false;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取连接服务器的字符串
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public string GetConnection2()
|
||
{
|
||
return string.Format("Data Source={0};Port={1};Database={2};User ID={3};Password={4};Charset=utf8;Convert Zero Datetime=True;", afkSeverId.Text + "", afkPortNumber.Text + "", afkDataBase.Text + "", afkName.Text + "", afkPassword.Text + "");
|
||
}
|
||
#endregion
|
||
#region 按钮浮动事件
|
||
private void OnStartBtn_MouseLeave(object sender, EventArgs e)
|
||
{
|
||
DevExpress.XtraEditors.SimpleButton btn = (DevExpress.XtraEditors.SimpleButton)sender;
|
||
btn.Appearance.BackColor = Color.FromArgb(52, 142, 216);
|
||
}
|
||
|
||
private void OnStartBtn_MouseHover(object sender, EventArgs e)
|
||
{
|
||
DevExpress.XtraEditors.SimpleButton btn = (DevExpress.XtraEditors.SimpleButton)sender;
|
||
btn.Appearance.BackColor = Color.FromArgb(140, 208, 1);
|
||
}
|
||
private void OnStopBtn_MouseLeave(object sender, EventArgs e)
|
||
{
|
||
DevExpress.XtraEditors.SimpleButton btn = (DevExpress.XtraEditors.SimpleButton)sender;
|
||
btn.Appearance.BackColor = Color.FromArgb(52, 142, 216);
|
||
}
|
||
private void OnStoptBtn_MouseHover(object sender, EventArgs e)
|
||
{
|
||
if (this.startBtn.Appearance.BackColor != Color.FromArgb(52, 142, 216))
|
||
{
|
||
this.startBtn.Appearance.BackColor = Color.FromArgb(52, 142, 216);
|
||
}
|
||
DevExpress.XtraEditors.SimpleButton btn = (DevExpress.XtraEditors.SimpleButton)sender;
|
||
btn.Appearance.BackColor = Color.FromArgb(140, 208, 1);
|
||
}
|
||
#endregion
|
||
#region 初始化数据配置页
|
||
private void InitializeDataSettings()
|
||
{
|
||
if (ConnectServerOther())
|
||
{
|
||
string explainSql = @"SELECT
|
||
A.name AS table_name,
|
||
B.name AS column_name,
|
||
C.value AS column_description
|
||
FROM sys.tables A
|
||
INNER JOIN sys.columns B ON B.object_id = A.object_id
|
||
LEFT JOIN sys.extended_properties C ON C.major_id = B.object_id AND C.minor_id = B.column_id
|
||
WHERE A.name = 'P_synchrTab'";
|
||
DataTable explainTab = SqlHelperOther.ExecuteDataTable(explainSql);
|
||
DataTable sourceTab = SqlHelperOther.ExecuteDataTable("select * from P_synchrTab order by id");
|
||
this.gridView.Columns.Clear();
|
||
this.gridControl.DataSource = sourceTab;
|
||
foreach (GridColumn gridColumn in this.gridView.Columns)
|
||
{
|
||
DataRow[] captionRows = explainTab.Select(string.Format("{0}='{1}'", "column_name", gridColumn.FieldName));
|
||
if (captionRows.Count() > 0)
|
||
{
|
||
DataRow captionRow = captionRows[0];
|
||
gridColumn.Caption = captionRow["column_description"] + "";
|
||
}
|
||
if (gridColumn.FieldName.Equals("synchroSql") || gridColumn.FieldName.Equals("targetTabSql") || gridColumn.FieldName.Equals("synLogSql") || gridColumn.FieldName.Equals("afterSql") || gridColumn.FieldName.Equals("relevanceSql") || gridColumn.FieldName.Equals("disableField") || gridColumn.FieldName.Equals("batchAfterSql"))
|
||
{
|
||
RepositoryItemMemoExEdit reEdit = new RepositoryItemMemoExEdit();
|
||
reEdit.ScrollBars = ScrollBars.Vertical;
|
||
gridControl.RepositoryItems.Add(reEdit);
|
||
gridColumn.ColumnEdit = reEdit;
|
||
}
|
||
if (gridColumn.FieldName.Equals("directionTag"))
|
||
{
|
||
DataTable directionTab = new DataTable();
|
||
directionTab.Columns.Add("dm");
|
||
directionTab.Columns.Add("mc");
|
||
directionTab.Rows.Add("0", "同步到朗速");
|
||
directionTab.Rows.Add("1", "同步到中航");
|
||
directionTab.Rows.Add("10", "不同步");
|
||
|
||
RepositoryItemLookUpEdit comboxEdit = new RepositoryItemLookUpEdit();
|
||
comboxEdit.SearchMode = SearchMode.AutoFilter;
|
||
comboxEdit.ShowHeader = false;
|
||
comboxEdit.ImmediatePopup = false;
|
||
comboxEdit.NullText = "";
|
||
comboxEdit.PopupBorderStyle = PopupBorderStyles.Flat;
|
||
comboxEdit.AllowNullInput = DefaultBoolean.False;
|
||
comboxEdit.DisplayMember = "mc";
|
||
comboxEdit.ValueMember = "dm";
|
||
//comboxEdit.DataSource = MainImpl.GetDataTableResult(model.SqlSource);
|
||
|
||
|
||
LookUpColumnInfo valueColumn = new LookUpColumnInfo();
|
||
valueColumn.Caption = "编码";
|
||
valueColumn.FieldName = "dm";
|
||
valueColumn.Visible = false;
|
||
|
||
LookUpColumnInfo textColumn = new LookUpColumnInfo();
|
||
textColumn.Caption = "名称";
|
||
textColumn.FieldName = "mc";
|
||
|
||
comboxEdit.Columns.AddRange(new LookUpColumnInfo[] { valueColumn, textColumn });
|
||
gridControl.RepositoryItems.Add(comboxEdit);
|
||
gridColumn.ColumnEdit = comboxEdit;
|
||
comboxEdit.DataSource = directionTab;
|
||
}
|
||
if (gridColumn.FieldName.Equals("disableTag"))
|
||
{
|
||
RepositoryItemCheckEdit comboxEdit = new RepositoryItemCheckEdit();
|
||
comboxEdit.ValueChecked = "false";
|
||
comboxEdit.ValueUnchecked = "true";
|
||
gridControl.RepositoryItems.Add(comboxEdit);
|
||
gridColumn.ColumnEdit = comboxEdit;
|
||
}
|
||
if (gridColumn.FieldName.Equals("isBatch"))
|
||
{
|
||
RepositoryItemCheckEdit comboxEdit = new RepositoryItemCheckEdit();
|
||
comboxEdit.ValueChecked = "true";
|
||
comboxEdit.ValueUnchecked = "false";
|
||
gridControl.RepositoryItems.Add(comboxEdit);
|
||
gridColumn.ColumnEdit = comboxEdit;
|
||
}
|
||
if (gridColumn.FieldName.Equals("isBefore"))
|
||
{
|
||
RepositoryItemCheckEdit comboxEdit = new RepositoryItemCheckEdit();
|
||
comboxEdit.ValueChecked = "true";
|
||
comboxEdit.ValueUnchecked = "false";
|
||
gridControl.RepositoryItems.Add(comboxEdit);
|
||
gridColumn.ColumnEdit = comboxEdit;
|
||
}
|
||
if (gridColumn.FieldName.Equals("id") || gridColumn.FieldName.Equals("rightKeyTag"))
|
||
{
|
||
gridColumn.Visible = false;
|
||
}
|
||
}
|
||
this.gridView.BestFitColumns();
|
||
//this.gridView.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect;
|
||
this.gridView.OptionsSelection.MultiSelect = false;
|
||
this.gridView.OptionsBehavior.EditorShowMode = DevExpress.Utils.EditorShowMode.MouseDownFocused;
|
||
this.contextMenuStrip.ItemClicked += new ToolStripItemClickedEventHandler(OnContextMenuStrip_ItemClicked);
|
||
}
|
||
}
|
||
#endregion
|
||
/// <summary>
|
||
/// 新增按钮
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void addBtn_Click(object sender, EventArgs e)
|
||
{
|
||
DataTable tab = new DataTable();
|
||
tab = (this.gridControl.DataSource as DataTable).Copy();
|
||
if (tab.Rows.Count > 0)
|
||
{
|
||
tab.DefaultView.Sort = "ID ASC";
|
||
DataRow lastRow = tab.DefaultView.ToTable().Rows[tab.Rows.Count - 1];
|
||
if ((lastRow["id"] + "").Equals("9999999"))
|
||
{
|
||
if (tab.Rows.Count > 1)
|
||
{
|
||
DataRow NRow = tab.NewRow();
|
||
NRow["id"] = Convert.ToInt32(tab.DefaultView.ToTable().Rows[tab.Rows.Count - 2]["id"] + "") + 1;
|
||
tab.Rows.Add(NRow);
|
||
}
|
||
else
|
||
{
|
||
DataRow NRow = tab.NewRow();
|
||
NRow["id"] = 1;
|
||
tab.Rows.Add(NRow);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
DataRow NRow = tab.NewRow();
|
||
NRow["id"] = Convert.ToInt32(tab.DefaultView.ToTable().Rows[tab.Rows.Count - 1]["id"] + "") + 1;
|
||
tab.Rows.Add(NRow);
|
||
}
|
||
this.gridControl.DataSource = tab;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 保存按钮
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void savebtn_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (ConnectServerOther())
|
||
{
|
||
DataTable sourceTab = SqlHelperOther.ExecuteDataTable("select * from P_synchrTab");
|
||
DataTable tab = this.gridControl.DataSource as DataTable;
|
||
StringBuilder allSqlStr = new StringBuilder();
|
||
foreach (DataRow row in tab.Rows)
|
||
{
|
||
if (row.RowState == DataRowState.Added)
|
||
{
|
||
string addSqlStr = "insert into P_synchrTab ({0}) values ({1});\r\n";
|
||
StringBuilder sqlKey = new StringBuilder();
|
||
StringBuilder sqlValues = new StringBuilder();
|
||
foreach (DataColumn col in row.Table.Columns)
|
||
{
|
||
sqlKey.Append(string.Format("{0},", col.ColumnName));
|
||
sqlValues.Append(string.Format("'{0}',", (row[col.ColumnName] + "").Replace("'", "''")));
|
||
}
|
||
allSqlStr.Append(string.Format(addSqlStr, sqlKey.ToString().TrimEnd(','), sqlValues.ToString().TrimEnd(',')));
|
||
}
|
||
else if (row.RowState == DataRowState.Modified)
|
||
{
|
||
string updateSqlStr = "update P_synchrTab set {0} = '{1}' where {2} = '{3}';\r\n";
|
||
DataRow[] sourceRows = sourceTab.Select(string.Format("id='{0}'", row["id"] + ""));
|
||
if (sourceRows.Count() > 0)
|
||
{
|
||
DataRow sourceRow = sourceRows[0];
|
||
foreach (DataColumn col in row.Table.Columns)
|
||
{
|
||
if (!(row[col.ColumnName] + "").Equals(sourceRow[col.ColumnName] + ""))
|
||
{
|
||
allSqlStr.Append(string.Format(updateSqlStr, col.ColumnName, (row[col.ColumnName] + "").Replace("'", "''"), "id", row["id"] + ""));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
try
|
||
{
|
||
DialogResult dialogResult = MessageUtil.Show("是否保存当前数据?", MessageBoxButtons.OKCancel);
|
||
if (dialogResult == DialogResult.OK)
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(allSqlStr.ToString())) SqlHelperOther.ExecuteNonQuery(allSqlStr.ToString());
|
||
|
||
MessageUtil.Show("保存成功");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageUtil.Show(string.Format("保存失败,原因:{0}", ex.Message));
|
||
}
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageUtil.Show(ex.Message);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 右键菜单
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void OnContextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (ConnectServerOther())
|
||
{
|
||
DataTable sourceTab = SqlHelperOther.ExecuteDataTable("select * from P_synchrTab");
|
||
DataTable dataTab = this.gridControl.DataSource as DataTable;
|
||
DataRow row = this.gridView.GetDataRow(this.gridView.FocusedRowHandle);
|
||
switch (e.ClickedItem.Name)
|
||
{
|
||
case "AbutmentNowRow":
|
||
string updateSql = "update P_synchrTab set rightKeyTag = '1' where id = {0}";
|
||
int updateResult = SqlHelperOther.ExecuteNonQuery(string.Format(updateSql, row["id"] + ""));
|
||
break;
|
||
case "disableRowData":
|
||
string disableSql = "update P_synchrTab set disableTag = 'false' where id = {0}";
|
||
int disableResult = SqlHelperOther.ExecuteNonQuery(string.Format(disableSql, row["id"] + ""));
|
||
DataRow[] findDisRows = dataTab.Select(string.Format("id='{0}'", row["id"] + ""));
|
||
if (findDisRows.Count() > 0)
|
||
{
|
||
DataRow findDisRow = findDisRows[0];
|
||
findDisRow["disableTag"] = "false";
|
||
}
|
||
break;
|
||
case "disablement":
|
||
string disablementSql = "update P_synchrTab set disableTag = 'true' where id = {0}";
|
||
int disablementResult = SqlHelperOther.ExecuteNonQuery(string.Format(disablementSql, row["id"] + ""));
|
||
DataRow[] findUndisRows = dataTab.Select(string.Format("id='{0}'", row["id"] + ""));
|
||
if (findUndisRows.Count() > 0)
|
||
{
|
||
DataRow findUndisRow = findUndisRows[0];
|
||
findUndisRow["disableTag"] = "true";
|
||
}
|
||
break;
|
||
case "deleteNowRow":
|
||
DialogResult result = MessageUtil.Show("是否确定删除当前选中行?", MessageBoxButtons.OKCancel);
|
||
if (result == DialogResult.OK)
|
||
{
|
||
DataRow[] selectRows = sourceTab.Select(string.Format("id='{0}'", row["id"] + ""));
|
||
if (selectRows.Count() > 0)
|
||
{
|
||
string deleteSql = "delete P_synchrTab where id ='{0}'";
|
||
SqlHelperOther.ExecuteNonQuery(string.Format(deleteSql, row["id"] + ""));
|
||
dataTab.Rows.Remove(row);
|
||
MessageUtil.Show("删除成功");
|
||
}
|
||
else
|
||
{
|
||
dataTab.Rows.Remove(row);
|
||
MessageUtil.Show("删除成功");
|
||
}
|
||
}
|
||
break;
|
||
case "Refresh":
|
||
this.gridControl.DataSource = SqlHelperOther.ExecuteDataTable("select * from P_synchrTab");
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageUtil.Show(ex.Message);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 快捷键
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void Form1_KeyDown(object sender, KeyEventArgs e)
|
||
{
|
||
if (e.KeyCode == Keys.F1)
|
||
{
|
||
ConfigurationTool configurationTool = new ConfigurationTool();
|
||
configurationTool.Show();
|
||
}
|
||
}
|
||
|
||
|
||
private void simpleButton1_Click(object sender, EventArgs e)
|
||
{
|
||
DataRow dr = gridView.GetFocusedDataRow();
|
||
ConfigurationTool configurationTool = new ConfigurationTool();
|
||
configurationTool.returnContent += new ConfigurationTool.ReturnContent(returnContent);
|
||
if (dr != null)
|
||
{
|
||
configurationTool.SegmentedContent = dr["synchroSql"] + "";
|
||
configurationTool.DirectionTag = dr["directionTag"] + "";
|
||
}
|
||
configurationTool.ShowDialog();
|
||
|
||
}
|
||
|
||
private void returnContent(string value)
|
||
{
|
||
DataRow dr = gridView.GetFocusedDataRow();
|
||
dr["synchroSql"] = value;
|
||
this.savebtn_Click(null, null);
|
||
}
|
||
}
|
||
public static class DateTimeUtil
|
||
{
|
||
#region 线程timer
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="callback"></param>
|
||
/// <param name="dealy">单位毫秒</param>
|
||
public static System.Threading.Timer SetTimeOut(System.Threading.TimerCallback callback, int dealy)
|
||
{
|
||
System.Threading.Timer t = null;
|
||
t = new System.Threading.Timer((obj) =>
|
||
{
|
||
if (callback != null)
|
||
{
|
||
callback(obj);
|
||
}
|
||
if (t != null) t.Dispose();
|
||
}, null, dealy, 0);
|
||
return t;
|
||
}
|
||
#endregion
|
||
}
|
||
}
|