本文整理汇总了C#中DBConnector.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# DBConnector.Execute方法的具体用法?C# DBConnector.Execute怎么用?C# DBConnector.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBConnector
的用法示例。
在下文中一共展示了DBConnector.Execute方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportCommodities
/// <summary>
/// imports the data from the list
/// (only newer data will be imported)
/// </summary>
/// <param name="fileName"></param>
internal void ImportCommodities(List<EDCommodities> Commodities)
{
String sqlString;
Int32 Counter = 0;
DBConnector lDBCon = new DBConnector(Program.DBCon.ConfigData, true);
try
{
// gettin' some freaky performance
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=2");
lDBCon.TransBegin();
sendProgressEvent(new ProgressEventArgs() { Info="import commodities", CurrentValue=0, TotalValue=Commodities.Count });
// insert or update all commodities
foreach (EDCommodities Commodity in Commodities)
{
sqlString = "insert into tbCategory(id, category, loccategory) values (" +
Commodity.Category.Id.ToString() + "," +
SQL.DBConnector.SQLAString(Commodity.Category.Name.ToString()) + "," +
SQL.DBConnector.SQLAString(Commodity.Category.Name.ToString()) +
") ON DUPLICATE KEY UPDATE " +
"category = " + SQL.DBConnector.SQLAString(Commodity.Category.Name.ToString()) + "," +
"loccategory = " + SQL.DBConnector.SQLAString(Commodity.Category.Name.ToString());
lDBCon.Execute(sqlString);
sqlString = "insert into tbCommodity(id, commodity, loccommodity, category_id, average_price) values (" +
Commodity.Id.ToString() + "," +
SQL.DBConnector.SQLAString(Commodity.Name.ToString()) + "," +
SQL.DBConnector.SQLAString(Commodity.Name.ToString()) + "," +
Commodity.CategoryId.ToString() + "," +
DBConvert.ToString(Commodity.AveragePrice) +
") ON DUPLICATE KEY UPDATE " +
"commodity = " + SQL.DBConnector.SQLAString(Commodity.Name.ToString()) + "," +
"loccommodity = " + SQL.DBConnector.SQLAString(Commodity.Name.ToString()) + "," +
"category_id = " + Commodity.CategoryId.ToString() + "," +
"average_price = " + DBConvert.ToString(Commodity.AveragePrice);
lDBCon.Execute(sqlString);
Counter++;
if(sendProgressEvent(new ProgressEventArgs() { Info="import commodities", CurrentValue=Counter, TotalValue=Commodities.Count }))
break;
}
lDBCon.TransCommit();
// reset freaky performance
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=1");
lDBCon.Dispose();
}
catch (Exception ex)
{
if(lDBCon.TransActive())
lDBCon.TransRollback();
try
{
// reset freaky performance
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=1");
lDBCon.Dispose();
}
catch (Exception) { }
throw new Exception("Error while importing system data", ex);
}
}
示例2: ImportCommodityLocalizations
/// <summary>
/// loads the localized commodity names and check if
/// the self added names now included in the official dictionary
/// </summary>
internal void ImportCommodityLocalizations(DataSet DataNames, enLocalisationImportType importType = enLocalisationImportType.onlyNew)
{
DBConnector lDBCon = null;
dsEliteDB Data;
Dictionary<String, Int32> foundLanguagesFromFile = new Dictionary<String, Int32>();
String sqlString;
Int32 currentSelfCreatedIndex;
Int32 Counter = 0;
Boolean idColumnFound = false;
String BaseName;
DataRow[] Commodity;
Data = new dsEliteDB();
try
{
lDBCon = new DBConnector(Program.DBCon.ConfigData, true);
// gettin' some freaky performance
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=2");
sqlString = "select min(id) As min_id from tbCommodity";
lDBCon.Execute(sqlString, "minID", DataNames);
if(Convert.IsDBNull(DataNames.Tables["minID"].Rows[0]["min_id"]))
currentSelfCreatedIndex = -1;
else
{
currentSelfCreatedIndex = ((Int32)DataNames.Tables["minID"].Rows[0]["min_id"]) - 1;
if(currentSelfCreatedIndex >= 0)
currentSelfCreatedIndex = -1;
}
lDBCon.TableRead("select * from tbLanguage", Data.tblanguage);
lDBCon.TableRead("select * from tbCommodityLocalization", Data.tbcommoditylocalization);
lDBCon.TableRead("select * from tbCommodity", Data.tbcommodity);
if(DataNames.Tables["Names"] != null)
{
sendProgressEvent(new ProgressEventArgs() {Info="import commodity localization", CurrentValue=Counter, TotalValue=DataNames.Tables["Names"].Rows.Count });
// first check if there's a new language
foreach (DataColumn LanguageFromFile in DataNames.Tables["Names"].Columns)
{
if(!LanguageFromFile.ColumnName.Equals("id", StringComparison.InvariantCultureIgnoreCase))
{
DataRow[] LanguageName = Data.tblanguage.Select("language = " + DBConnector.SQLAString(LanguageFromFile.ColumnName));
if(LanguageName.Count() == 0)
{
// add a non existing language
DataRow newRow = Data.tblanguage.NewRow();
int? Wert = DBConvert.To<int?>(Data.tblanguage.Compute("max(id)", ""));
if(Wert == null)
Wert = 0;
Wert += 1;
newRow["id"] = Wert;
newRow["language"] = LanguageFromFile.ColumnName;
Data.tblanguage.Rows.Add(newRow);
foundLanguagesFromFile.Add(LanguageFromFile.ColumnName, (Int32)Wert);
}
else
foundLanguagesFromFile.Add((String)LanguageName[0]["language"], (Int32)LanguageName[0]["id"]);
}
else
idColumnFound = true;
}
// submit changes (tbLanguage)
lDBCon.TableUpdate(Data.tblanguage);
// compare and add the localized names
foreach (DataRow LocalizationFromFile in DataNames.Tables["Names"].AsEnumerable())
{
int? commodityID = null;
if (idColumnFound)
commodityID = DBConvert.To<int?>(LocalizationFromFile["id"]);
if (commodityID == 1)
Debug.Print("Stop");
BaseName = (String)LocalizationFromFile[Program.BASE_LANGUAGE];
if ((commodityID == null) || (commodityID < 0))
{
// no id or selfcreated
Commodity = Data.tbcommodity.Select("commodity = " + DBConnector.SQLAString(DBConnector.DTEscape(BaseName)));
}
else
{
//.........这里部分代码省略.........
示例3: ImportCommandersLog
/// <summary>
/// imports the "Commander's Log" into the database
/// </summary>
/// <param name="fileName"></param>
public Int32 ImportCommandersLog(String Filename)
{
DataSet Data;
String sqlString;
Int32 added = 0;
List<EDSystem> Systems = new List<EDSystem>();
List<EDStation> Stations = new List<EDStation>();
Int32 currentIndex = 0;
Int32 Counter = 0;
Dictionary<int, int> changedSystemIDs;
DBConnector lDBCon = new DBConnector(Program.DBCon.ConfigData, true);
try
{
Data = new DataSet();
Data.ReadXml(Filename);
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=2");
if(Data.Tables.Contains("CommandersLogEvent"))
{
sendProgressEvent(new ProgressEventArgs() { Info="import log", CurrentValue=Counter, TotalValue=Data.Tables["CommandersLogEvent"].Rows.Count });
foreach(DataRow Event in Data.Tables["CommandersLogEvent"].AsEnumerable())
{
String System = Event["System"].ToString().Trim();
Systems.Add(new EDSystem{Name = System});
}
changedSystemIDs = ImportSystems_Own(ref Systems, true);
foreach(DataRow Event in Data.Tables["CommandersLogEvent"].AsEnumerable())
{
String Station = StructureHelper.CombinedNameToStationName((String)Event["Station"]).Trim();
Stations.Add(new EDStation{Name = Station, SystemId = Systems[currentIndex].Id});
currentIndex++;
}
ImportStations_Own(Stations, changedSystemIDs, true);
foreach(DataRow Event in Data.Tables["CommandersLogEvent"].AsEnumerable())
{
DateTime EventTime = DateTime.Parse((String)Event["EventDate"], CultureInfo.CurrentUICulture , DateTimeStyles.AssumeUniversal);
String System = Event["System"].ToString().Trim();
String Station = StructureHelper.CombinedNameToStationName((String)Event["Station"]).Trim();
String EventType = Event["EventType"].ToString().Trim().Length == 0 ? "Other" : Event["EventType"].ToString().Trim();
// add a new log entry
sqlString = String.Format("INSERT INTO tbLog(time, system_id, station_id, event_id, commodity_id," +
" cargoaction_id, cargovolume, credits_transaction, credits_total, notes)" +
" SELECT d.* FROM (SELECT" +
" {0} AS time," +
" (select id from tbSystems" +
" where systemname = {1}" +
" order by updated_at limit 1" +
" ) AS system_id," +
" (select id from tbStations where stationname = {2} " +
" and system_id = (select id from tbSystems" +
" where systemname = {1}" +
" order by updated_at limit 1)" +
" ) AS station_id," +
" (select id from tbEventType where eventtype = {3}) As event_id," +
" (select id from tbCommodity where commodity = {4} or loccommodity = {4} limit 1) As commodity_id," +
" (select id from tbCargoAction where cargoaction = {5}) AS cargoaction_id," +
" {6} AS cargovolume," +
" {7} AS credits_transaction," +
" {8} AS credits_total," +
" {9} AS notes) AS d" +
" WHERE 0 IN (SELECT COUNT(*)" +
" FROM tbLog" +
" WHERE time = {0})",
DBConnector.SQLDateTime(EventTime),
DBConnector.SQLAString(DBConnector.SQLEscape(Event["System"].ToString())),
DBConnector.SQLAString(DBConnector.SQLEscape(Station)),
DBConnector.SQLAString(EventType),
DBConnector.SQLAString(Event["Cargo"].ToString()),
DBConnector.SQLAString(Event["CargoAction"].ToString()),
Event["CargoVolume"],
Event["TransactionAmount"],
Event["Credits"],
Event["Notes"].ToString().Trim() == String.Empty ? "null" : String.Format("'{0}'", DBConnector.SQLEscape(Event["Notes"].ToString())));
added += lDBCon.Execute(sqlString);
if ((added > 0) && ((added % 10) == 0))
Debug.Print(added.ToString());
Counter++;
sendProgressEvent(new ProgressEventArgs() { Info="import log", CurrentValue=Counter, TotalValue=Data.Tables["CommandersLogEvent"].Rows.Count });
}
}
// reset freaky performance
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=1");
lDBCon.Dispose();
//.........这里部分代码省略.........
示例4: ImportPrices
/// <summary>
/// Imports the prices from the list of stations. It's clever
/// firstly to import the stations from the same file.
/// </summary>
/// <param name="Stations"></param>
private void ImportPrices(List<EDStation> Stations, enImportBehaviour importBehaviour, enDataSource dataSource)
{
DBConnector lDBCon = new DBConnector(Program.DBCon.ConfigData, true);
ProgressEventArgs eva;
try
{
StringBuilder sqlStringB = new StringBuilder();
String timeFilter = "";
Int32 Counter;
Dictionary<Int32, Int32> commodityIDs = new Dictionary<Int32, Int32>();
List<Listing> missedListings = new List<Listing>();
Listing[] currentListing;
Boolean currentListingDone;
Int32 priceCountTotal = 0;
Int32 priceCount = 0;
Int32 SourceID;
enDataSource initialDataSource = dataSource;
if ((dataSource == enDataSource.fromRN) || (dataSource == enDataSource.fromIBE_OCR))
dataSource = enDataSource.fromIBE;
if(dataSource == enDataSource.fromEDDN_T)
dataSource = enDataSource.fromEDDN;
// for the prices is no transaction necessary, because we're changing
// only a single table
// count the prices for messages
foreach (EDStation Station in Stations)
priceCountTotal += Station.Listings.Count();
Counter = 0;
sendProgressEvent(new ProgressEventArgs() { Info="updating prices...", AddSeparator=true });
Boolean AddComma = false;
int? DemandLevel = null;
int? SupplyLevel = null;
Dictionary<String, int?> Levels = new Dictionary<String, int?>();
// gettin' some freaky performance
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=2");
// now add the commodities and prices
foreach (EDStation Station in Stations)
{
currentListingDone = false;
missedListings.Clear();
currentListing = Station.Listings;
do
{
commodityIDs.Clear();
currentListingDone = true;
if ((Station.Id != 0) && (currentListing.Count() > 0))
{
sqlStringB.Clear();
sqlStringB.Append("insert into tbCommodityData(id, station_id, commodity_id, Sell, Buy," +
"Demand, DemandLevel, Supply, SupplyLevel, Sources_id, timestamp) ");
foreach (Listing StationListing in currentListing)
{
// is this commodity already added in this round ? ....
if (!commodityIDs.ContainsKey(StationListing.CommodityId))
{
// ... no
if (!String.IsNullOrEmpty(StationListing.DataSource))
SourceID = (Int32)BaseTableNameToID("source", StationListing.DataSource);
else
SourceID = (Int32)dataSource;
if (dataSource <= 0)
throw new Exception("Illegal SourceID for import : " + SourceID);
if (AddComma)
sqlStringB.Append(" union all ");
// cache level-ids
getLevels(ref DemandLevel, ref SupplyLevel, Levels, StationListing);
switch (importBehaviour)
{
case enImportBehaviour.OnlyNewer:
timeFilter = String.Format("SC1.timestamp < {0}) or (SC1.timestamp is null)", DBConnector.SQLDateTime(DateTimeOffset.FromUnixTimeSeconds(StationListing.CollectedAt).DateTime));
break;
case enImportBehaviour.NewerOrEqual:
timeFilter = String.Format("SC1.timestamp <= {0}) or (SC1.timestamp is null)", DBConnector.SQLDateTime(DateTimeOffset.FromUnixTimeSeconds(StationListing.CollectedAt).DateTime));
break;
case enImportBehaviour.All:
//.........这里部分代码省略.........
示例5: ImportVisitedStations
/// <summary>
/// imports the old list of visited stations to the database
/// </summary>
/// <param name="StationObject"></param>
/// <param name="EconomyRow"></param>
public void ImportVisitedStations(string Filename)
{
String sqlString;
Int32 Counter = 0;
DBConnector lDBCon = new DBConnector(Program.DBCon.ConfigData, true);
try
{
List<StationVisit> History = JsonConvert.DeserializeObject<List<StationVisit>>(File.ReadAllText(Filename));
// gettin' some freaky performance
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=2");
lDBCon.TransBegin("ImportVisitedStations");
sendProgressEvent(new ProgressEventArgs() { Info="import visited stations", CurrentValue=Counter, TotalValue=History.Count });
foreach(StationVisit VisitEvent in History)
{
String System = StructureHelper.CombinedNameToSystemName(VisitEvent.Station);
String Station = StructureHelper.CombinedNameToStationName(VisitEvent.Station);
//Debug.Print(System + "," + Location);
try
{
sqlString = String.Format("insert ignore into tbVisitedSystems(system_id, time)" +
" SELECT d.* FROM (SELECT" +
" (select id from tbSystems where systemname = {0}) as system_id," +
" {1} as time) as d",
DBConnector.SQLAString(DBConnector.SQLEscape(System)),
DBConnector.SQLDateTime(VisitEvent.Visited));
lDBCon.Execute(sqlString);
}
catch (Exception)
{
//Debug.Print("Error while importing system in history :" + System);
};
try
{
sqlString = String.Format("insert ignore into tbVisitedStations(station_id, time)" +
" SELECT d.* FROM (SELECT" +
" (select id from tbStations" +
" where stationname = {0}" +
" and system_id = (select id from tbSystems where systemname = {1})) as station_id," +
" {2} as time) as d",
DBConnector.SQLAString(DBConnector.SQLEscape(Station)),
DBConnector.SQLAString(DBConnector.SQLEscape(System)),
DBConnector.SQLDateTime(VisitEvent.Visited));
lDBCon.Execute(sqlString);
}
catch (Exception)
{
//Debug.Print("Error while importing station in history :" + Location);
};
Counter++;
sendProgressEvent(new ProgressEventArgs() { Info="import visited stations", CurrentValue=Counter, TotalValue=History.Count });
}
lDBCon.TransCommit();
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=1");
lDBCon.Dispose();
}
catch (Exception ex)
{
if(lDBCon.TransActive())
lDBCon.TransRollback();
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=1");
lDBCon.Dispose();
throw new Exception("Error while importing the history of visited stations", ex);
}
}
示例6: ImportStations_Own
/// <summary>
/// imports the "own" station data into the database
/// </summary>
/// <param name="fileName"></param>
public void ImportStations_Own(List<EDStation> Stations, Dictionary<Int32, Int32> changedSystemIDs, Boolean OnlyAddUnknown = false, Boolean setVisitedFlag = false)
{
DBConnector lDBCon = null;
String sqlString;
dsEliteDB.tbstationsRow[] FoundRows;
dsEliteDB.tbsystemsRow[] FoundSysRows;
DateTime Timestamp_new, Timestamp_old;
Int32 ImportCounter = 0;
Int32 currentSelfCreatedIndex = -1;
dsEliteDB Data = new dsEliteDB();
Int32 Counter = 0;
try
{
lDBCon = new DBConnector(Program.DBCon.ConfigData, true);
// gettin' some freaky performance
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=2");
lDBCon.TransBegin();
sqlString = "select * from tbStations lock in share mode";
lDBCon.TableRead(sqlString, Data.tbstations);
sqlString = "select * from tbStations_org lock in share mode";
lDBCon.TableRead(sqlString, Data.tbstations_org);
sqlString = "select * from tbStationEconomy lock in share mode";
lDBCon.TableRead(sqlString, Data.tbstationeconomy);
// get the smallest ID for self added stations
sqlString = "select min(id) As min_id from tbStations";
lDBCon.Execute(sqlString, "minID", Data);
if (Convert.IsDBNull(Data.Tables["minID"].Rows[0]["min_id"]))
currentSelfCreatedIndex = -1;
else
{
currentSelfCreatedIndex = ((Int32)Data.Tables["minID"].Rows[0]["min_id"]) - 1;
if (currentSelfCreatedIndex >= 0)
currentSelfCreatedIndex = -1;
}
sendProgressEvent(new ProgressEventArgs() { Info="import self-added stations", CurrentValue=Counter, TotalValue=Stations.Count });
foreach (EDStation Station in Stations)
{
Int32 SystemID;
if(Station.Name == "Glass City")
Debug.Print("stop");
// is the system id changed ? --> get the new system id, otherwise the original
if (changedSystemIDs.TryGetValue(Station.SystemId, out SystemID))
Station.SystemId = SystemID;
// if there are missing system ids, try to get them
if ((Station.SystemId == 0) && (!String.IsNullOrEmpty(Station.SystemName)))
{
FoundSysRows = (dsEliteDB.tbsystemsRow[])Data.tbsystems.Select("systemname=" + DBConnector.SQLAString(DBConnector.DTEscape(Station.SystemName)));
if((FoundSysRows != null) && (FoundSysRows.Count() > 0))
{
// got it - set the id
Station.SystemId = FoundSysRows[0].id;
}
}
if (!String.IsNullOrEmpty(Station.Name.Trim()) && (Station.SystemId != 0))
{
// self-created stations don't have the correct id so they must be identified by name
FoundRows = (dsEliteDB.tbstationsRow[])Data.tbstations.Select("stationname=" + DBConnector.SQLAString(DBConnector.DTEscape(Station.Name)) + " and " +
"system_id = " + Station.SystemId);
if ((FoundRows != null) && (FoundRows.Count() > 0))
{
// Location is existing, get the same Id
Station.Id = (Int32)FoundRows[0]["id"];
if (!OnlyAddUnknown)
{
if ((bool)(FoundRows[0]["is_changed"]))
{
// existing data data is also changed by user - keep the newer version
Timestamp_old = (DateTime)(FoundRows[0]["updated_at"]);
Timestamp_new = DateTimeOffset.FromUnixTimeSeconds(Station.UpdatedAt).DateTime;
if (Timestamp_new > Timestamp_old)
{
// data from file is newer
CopyEDStationToDataRow(Station, (DataRow)FoundRows[0], true, null, true);
CopyEDStationEconomiesToDataRows(Station, Data.tbstationeconomy);
// commodities are not considered because there was no possibility for input in the old RN
ImportCounter += 1;
}
//.........这里部分代码省略.........
示例7: ImportStations
/// <summary>
/// imports the data from the file into the database
/// (only newer data will be imported)
/// </summary>
/// <param name="fileName"></param>
public void ImportStations(String Filename, Boolean addPrices)
{
DBConnector lDBCon = null;
String sqlString;
List<EDStation> Stations;
dsEliteDB.tbstations_orgRow[] FoundRows_org;
dsEliteDB.tbstationsRow[] FoundRows;
DateTime Timestamp_new, Timestamp_old;
Int32 ImportCounter = 0;
dsEliteDB Data;
Int32 Counter = 0;
UInt32 currentComodityClassificationID=0;
Int32 updated = 0;
Int32 added = 0;
Data = new dsEliteDB();
try
{
lDBCon = new DBConnector(Program.DBCon.ConfigData, true);
// gettin' some freaky performance
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=2");
Stations = JsonConvert.DeserializeObject<List<EDStation>>(File.ReadAllText(Filename));
sendProgressEvent(new ProgressEventArgs() { Info="import systems", NewLine = true });
lDBCon.TransBegin();
sqlString = "select * from tbStations lock in share mode";
lDBCon.TableRead(sqlString, Data.tbstations);
sqlString = "select * from tbStations_org lock in share mode";
lDBCon.TableRead(sqlString, Data.tbstations_org);
sqlString = "select * from tbStationEconomy lock in share mode";
lDBCon.TableRead(sqlString, Data.tbstationeconomy);
sqlString = "select * from tbsource";
lDBCon.Execute(sqlString, Data.tbsource);
sqlString = "select * from tbCommodityClassification lock in share mode";
lDBCon.TableRead(sqlString, Data.tbcommodityclassification);
sqlString = "select * from tbcommodity_has_attribute lock in share mode";
lDBCon.TableRead(sqlString, Data.tbcommodity_has_attribute);
sqlString = "select * from tbattribute lock in share mode";
lDBCon.TableRead(sqlString, Data.tbattribute);
currentComodityClassificationID = getFreeIndex("tbCommodityClassification");
lDBCon.Execute(sqlString, Data.tbsource);
foreach (EDStation Station in Stations)
{
FoundRows = (dsEliteDB.tbstationsRow[])Data.tbstations.Select("id=" + Station.Id.ToString());
if (FoundRows.Count() > 0)
{
// Location is existing
if ((bool)(FoundRows[0]["is_changed"]))
{
// data is changed by user - hold it ...
// ...and check table "tbStations_org" for the original data
FoundRows_org = (dsEliteDB.tbstations_orgRow[])Data.tbstations_org.Select("id=" + Station.Id.ToString());
if ((FoundRows_org != null) && (FoundRows_org.Count() > 0))
{
// Location is in "tbStations_org" existing - keep the newer version
Timestamp_old = (DateTime)(FoundRows_org[0]["updated_at"]);
Timestamp_new = DateTimeOffset.FromUnixTimeSeconds(Station.UpdatedAt).DateTime;
if (Timestamp_new > Timestamp_old)
{
// data from file is newer
CopyEDStationToDataRow(Station, (DataRow)FoundRows_org[0], false, null, true);
CopyEDStationEconomiesToDataRows(Station, Data.tbstationeconomy);
CopyEDStationCommodityToDataRow(Station, Data, ref currentComodityClassificationID);
ImportCounter += 1;
}
}
}
else
{
// Location is existing - keep the newer version
Timestamp_old = (DateTime)(FoundRows[0]["updated_at"]);
Timestamp_new = DateTimeOffset.FromUnixTimeSeconds(Station.UpdatedAt).DateTime;
if (Timestamp_new > Timestamp_old)
{
// data from file is newer
//.........这里部分代码省略.........
示例8: ImportSystems_Own
/// <summary>
/// imports the data from the list of systems
/// </summary>
/// <param name="fileName"></param>
public Dictionary<Int32, Int32> ImportSystems_Own(ref List<EDSystem> Systems, Boolean OnlyAddUnknown = false, Boolean setVisitedFlag = false)
{
DBConnector lDBCon = null;
String sqlString;
dsEliteDB.tbsystemsRow[] FoundRows;
DateTime Timestamp_new, Timestamp_old;
Int32 ImportCounter = 0;
Dictionary<Int32, Int32> changedSystemIDs = new Dictionary<Int32, Int32>();
Int32 currentSelfCreatedIndex = -1;
dsEliteDB Data;
Int32 Counter = 0;
try
{
lDBCon = new DBConnector(Program.DBCon.ConfigData, true);
Data = new dsEliteDB();
// gettin' some freaky performance
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=2");
lDBCon.TransBegin();
sqlString = "select * from tbSystems lock in share mode";
lDBCon.TableRead(sqlString, Data.tbsystems);
sqlString = "select * from tbSystems_org lock in share mode";
lDBCon.TableRead(sqlString, Data.tbsystems_org);
currentSelfCreatedIndex = getNextOwnSystemIndex();
sendProgressEvent(new ProgressEventArgs() { Info="import self-added systems", CurrentValue=Counter, TotalValue=Systems.Count });
foreach (EDSystem System in Systems)
{
if (!String.IsNullOrEmpty(System.Name.ToString().Trim()))
{
// self-created systems don't have the correct id so it must be identified by name
FoundRows = (dsEliteDB.tbsystemsRow[])Data.tbsystems.Select("systemname=" + DBConnector.SQLAString(DBConnector.DTEscape(System.Name.ToString())));
if ((FoundRows != null) && (FoundRows.Count() > 0))
{
if (!OnlyAddUnknown)
{
// system is existing
// memorize the changed system ids for importing user changed stations in the (recommend) second step
changedSystemIDs.Add(System.Id, (Int32)FoundRows[0]["id"]);
System.Id = (Int32)FoundRows[0]["id"];
if ((bool)(FoundRows[0]["is_changed"]))
{
// old data is changed by user and the new data is also a user changed data
// keep the newer version in the main table
Timestamp_old = (DateTime)(FoundRows[0]["updated_at"]);
Timestamp_new = DateTimeOffset.FromUnixTimeSeconds(System.UpdatedAt).DateTime;
if (Timestamp_new > Timestamp_old)
{
// data from file is newer -> take it but hold the old id
CopyEDSystemToDataRow(System, (DataRow)FoundRows[0], true, null, true);
ImportCounter += 1;
}
}
else
{
// new data is user changed data, old data is original data
// copy the original data ("tbSystems") to the saving data table ("tbSystems_org")
// and get the correct system ID
Data.tbsystems_org.LoadDataRow(FoundRows[0].ItemArray, false);
CopyEDSystemToDataRow(System, (DataRow)FoundRows[0], true, null, true);
ImportCounter += 1;
}
}
else
{
System.Id = (Int32)FoundRows[0]["id"];
}
}
else
{
// add a new system
// memorize the changed system ids for importing user changed stations in the (recommend) second step
if (!OnlyAddUnknown)
changedSystemIDs.Add(System.Id, currentSelfCreatedIndex);
System.Id = currentSelfCreatedIndex;
dsEliteDB.tbsystemsRow newRow = (dsEliteDB.tbsystemsRow)Data.tbsystems.NewRow();
CopyEDSystemToDataRow(System, (DataRow)newRow, true, null, true);
newRow.visited = setVisitedFlag;
newRow.updated_at = DateTime.UtcNow;
//.........这里部分代码省略.........
示例9: ImportSystems
/// <summary>
/// imports the data from the file into the database
/// (only newer data will be imported)
/// </summary>
/// <param name="fileName"></param>
public void ImportSystems(String Filename)
{
DBConnector lDBCon = null;
String sqlString;
List<EDSystem> Systems;
EDSystem importSystem;
dsEliteDB.tbsystemsRow[] FoundRows;
dsEliteDB.tbsystems_orgRow[] FoundRows_org;
DateTime Timestamp_new, Timestamp_old;
Int32 ImportCounter = 0;
Dictionary<Int32, Int32> changedSystemIDs = new Dictionary<Int32, Int32>();
dsEliteDB localDataSet;
Int32 counter = 0;
Boolean dataChanged;
localDataSet = new dsEliteDB();
Int32 updated = 0;
Int32 added = 0;
MySql.Data.MySqlClient.MySqlDataAdapter dataAdapter_sys = null;
MySql.Data.MySqlClient.MySqlDataAdapter dataAdapter_sysorg = null;
Int32 systemsTotal=0;
try
{
lDBCon = new DBConnector(Program.DBCon.ConfigData, true);
// gettin' some freaky performance
lDBCon.Execute("set global innodb_flush_log_at_trx_commit=2");
StreamReader rawDataStream;
JsonTextReader jsonReader;
JsonSerializer serializer = new JsonSerializer();
rawDataStream = new StreamReader(Filename);
jsonReader = new JsonTextReader(rawDataStream);
sendProgressEvent(new ProgressEventArgs() { Info="import systems...", NewLine = true } );
while (jsonReader.Read())
if((jsonReader.TokenType == JsonToken.StartObject) && (jsonReader.Depth == 1))
systemsTotal++;
jsonReader.Close();
rawDataStream.Close();
rawDataStream.Dispose();
rawDataStream = new StreamReader(Filename);
jsonReader = new JsonTextReader(rawDataStream);
while(jsonReader.Read())
{
if((jsonReader.TokenType == JsonToken.StartObject) && (jsonReader.Depth == 1))
{
dataChanged = false;
importSystem = serializer.Deserialize<EDSystem>(jsonReader);
localDataSet.Clear();
if(dataAdapter_sys != null)
{
dataAdapter_sys.Dispose();
dataAdapter_sys = null;
}
if(dataAdapter_sysorg != null)
{
dataAdapter_sysorg.Dispose();
dataAdapter_sysorg = null;
}
lDBCon.TableRead(String.Format("select * from tbSystems where id = {0} lock in share mode;", importSystem.Id), localDataSet.tbsystems, ref dataAdapter_sys);
//sqlString = "select * from tbSystems_org lock in share mode";
//lDBCon.TableRead(sqlString, Data.tbsystems_org);
if (localDataSet.tbsystems.Rows.Count > 0)
{
// system is existing
if ((bool)(localDataSet.tbsystems.Rows[0]["is_changed"]))
{
// data is changed by user - hold it ...
// ...and check table "tbSystems_org" for the original data
lDBCon.TableRead(String.Format("select * from tbSystems_org where id = {0} lock in share mode;", importSystem.Id), localDataSet.tbsystems_org, ref dataAdapter_sysorg);
if (localDataSet.tbsystems_org.Rows.Count > 0)
{
// system is in "tbSystems_org" existing - keep the newer version
Timestamp_old = (DateTime)(localDataSet.tbsystems_org.Rows[0]["updated_at"]);
Timestamp_new = DateTimeOffset.FromUnixTimeSeconds(importSystem.UpdatedAt).DateTime;
if (Timestamp_new > Timestamp_old)
{
// data from file is newer
CopyEDSystemToDataRow(importSystem, (DataRow)localDataSet.tbsystems_org.Rows[0], false, null, true);
//.........这里部分代码省略.........