예제 #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);
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
        private CommonAppConfig()
        {
            XmlDocument xdoc = new XmlDocument();

            xdoc.Load(ConfigXmlPath);

            this.AppIdentifier  = xdoc.SelectSingleNode("CommonAppConfig/AppIdentifier").InnerText;
            this.ServerIp       = xdoc.SelectSingleNode("CommonAppConfig/ServerIp").InnerText;
            this.SyncIdentifier = xdoc.SelectSingleNode("CommonAppConfig/SyncIdentifier").InnerText;
            this.ServerConnStr  = xdoc.SelectSingleNode("CommonAppConfig/ServerConnStr").InnerText;
            this.ClientConnStr  = xdoc.SelectSingleNode("CommonAppConfig/ClientConnStr").InnerText;
            this.SynchInterval  = Convert.ToInt32(xdoc.SelectSingleNode("CommonAppConfig/SynchInterval").InnerText);
            this.Startup        = (xdoc.SelectSingleNode("CommonAppConfig/Startup").InnerText.ToLower() == "true");

            foreach (XmlNode xNode in xdoc.SelectNodes("/CommonAppConfig/Synchs/*"))
            {
                if (xNode.Name == "Table")
                {
                    TableSynch tableSynch = new TableSynch();

                    foreach (PropertyInfo pi in tableSynch.GetType().GetProperties())
                    {
                        foreach (XmlNode xnParam in xNode.SelectNodes("Param"))
                        {
                            if (!pi.CanRead || !pi.CanWrite)
                            {
                                continue;
                            }

                            if (pi.Name.ToLower() == xnParam.Attributes["Key"].Value.ToLower())
                            {
                                pi.SetValue(tableSynch, Convert.ChangeType(xnParam.Attributes["Value"].Value, pi.PropertyType), null);
                            }
                        }
                    }

                    this.tableSynchs.Add(tableSynch);
                }
            }
        }