Example #1
0
        /// <summary>
        /// 下达
        /// </summary>
        /// <param name="server"></param>
        /// <param name="client"></param>
        /// <param name="tableSynch"></param>
        /// <returns></returns>
        private int Download(OracleDapperDber server, OracleDapperDber client, TableSynch tableSynch)
        {
            int synchCount = 0;

            DataTable dtServer = server.ExecuteDataTable(OracleSqlBuilder.BuildGetNeedSynchTableSQL(tableSynch.TableName, tableSynch.SynchField));

            foreach (DataRow dr in dtServer.Rows)
            {
                string execSql = string.Empty;

                if (client.ExecuteScalar <int>(OracleSqlBuilder.BuildHasRecordSQL(tableSynch.TableName, tableSynch.PrimaryKey, dr[tableSynch.PrimaryKey].ToString())) == 0)
                {
                    execSql = OracleSqlBuilder.BuildInsertSQL(tableSynch.TableName, tableSynch.SynchField, dr);
                }
                else
                {
                    execSql = OracleSqlBuilder.BuildUpdateSQL(tableSynch.TableName, tableSynch.SynchField, tableSynch.PrimaryKey, dr);
                }

                if (client.Execute(execSql) > 0)
                {
                    synchCount += 1;
                    server.Execute(OracleSqlBuilder.BuildUpdateSynchFieldSQL(tableSynch.TableName, tableSynch.PrimaryKey, dr[tableSynch.PrimaryKey].ToString(), tableSynch.SynchField));
                }
            }

            return(synchCount);
        }
        /// <summary>
        /// 上传
        /// </summary>
        /// <param name="server"></param>
        /// <param name="client"></param>
        /// <param name="tableSynch"></param>
        /// <returns></returns>
        private int Upload(OracleDapperDber server, OracleDapperDber client, TableSynch tableSynch)
        {
            int synchCount = 0;

            DataTable dtClient = client.ExecuteDataTable(OracleSqlBuilder.BuildGetNeedSynchTableSQL(tableSynch.TableName, tableSynch.SynchField, this._CommonAppConfig.SyncIdentifier, "上传"));

            foreach (DataRow dr in dtClient.Rows)
            {
                string execSql = string.Empty;

                if (server.ExecuteDataTable(OracleSqlBuilder.BuildHasRecordSQL(tableSynch.TableName, tableSynch.PrimaryKey, dr[tableSynch.PrimaryKey].ToString())).Rows[0][0].ToString() == "0")
                {
                    execSql = OracleSqlBuilder.BuildInsertSQL(tableSynch.TableName, tableSynch.SynchField, this._CommonAppConfig.SyncIdentifier, dr);
                }
                else
                {
                    execSql = OracleSqlBuilder.BuildUpdateSQL(tableSynch.TableName, tableSynch.SynchField, this._CommonAppConfig.SyncIdentifier, tableSynch.PrimaryKey, dr);
                }

                if (server.Execute(execSql) > 0)
                {
                    synchCount += 1;
                    client.Execute(OracleSqlBuilder.BuildUpdateSynchFieldSQL(tableSynch.TableName, tableSynch.PrimaryKey, dr[tableSynch.PrimaryKey].ToString(), tableSynch.SynchField, this._CommonAppConfig.SyncIdentifier, "上传"));
                }
            }

            return(synchCount);
        }