/// <summary> /// 获取更改的表 /// </summary> /// <param name="ts">The ts.</param> /// <param name="sqlConn">The SQL connection.</param> /// <param name="insertTable">The insert table.</param> /// <param name="otherTable">The other table.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public static bool GetChangedData(TableStatus ts, MySqlConnection sqlConn, out DataTable insertTable, out DataTable otherTable) { insertTable = null; otherTable = null; if (!ts.GetAllRecords().Any()) { return(false); } if (sqlConn.State == ConnectionState.Closed) { sqlConn.Open(); } using (var cmd = sqlConn.CreateCommand()) { cmd.CommandText = string.Format("select * from {0} where 0=1", ts.TableName); insertTable = new DataTable(ts.TableName); using (var da = new MySqlDataAdapter(cmd)) { da.Fill(insertTable); } otherTable = insertTable.Copy(); } if (ts.AppendedRecords != null) { foreach (var record in ts.AppendedRecords) { var row = insertTable.NewRow(); foreach (var item in record) { row[item.Key] = item.Value; } insertTable.Rows.Add(row); } } if (ts.ModifiedRecords != null) { foreach (var record in ts.ModifiedRecords) { var row = otherTable.NewRow(); foreach (var item in record) { row[item.Key] = item.Value; } otherTable.Rows.Add(row); row.AcceptChanges(); row.SetModified(); } } if (ts.DeletedRecords != null) { foreach (var record in ts.DeletedRecords) { var row = otherTable.NewRow(); foreach (var item in record) { row[item.Key] = item.Value; } otherTable.Rows.Add(row); row.AcceptChanges(); row.Delete(); } } return(true); }