当前位置: 首页>>代码示例>>C#>>正文


C# DBConnector.TableRead方法代码示例

本文整理汇总了C#中DBConnector.TableRead方法的典型用法代码示例。如果您正苦于以下问题:C# DBConnector.TableRead方法的具体用法?C# DBConnector.TableRead怎么用?C# DBConnector.TableRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DBConnector的用法示例。


在下文中一共展示了DBConnector.TableRead方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ImportEconomyLevelLocalizations

        /// <summary>
        /// loads the localized economy level names and check
        /// </summary>
        internal void ImportEconomyLevelLocalizations(String Filename)
        {   
            DBConnector               lDBCon = null;
            dsEliteDB                 Data;
            DataSet                   DataNames;
            Dictionary<String, Int32> foundLanguagesFromFile     = new Dictionary<String, Int32>();
            Int32 Counter = 0;

            Data      = new dsEliteDB();
            DataNames = new DataSet();

            try
            {
                lDBCon = new DBConnector(Program.DBCon.ConfigData, true);

                DataNames.ReadXml(Filename);

                lDBCon.TableRead("select * from tbLanguage", Data.tblanguage);
                lDBCon.TableRead("select * from tbLevelLocalization", Data.tblevellocalization);
                lDBCon.TableRead("select * from tbEconomyLevel", Data.tbeconomylevel);

                if(DataNames.Tables["Levels"] != null)
                { 
                    sendProgressEvent(new ProgressEventArgs() {Info="import economy level localization", CurrentValue=Counter, TotalValue=DataNames.Tables["Levels"].Rows.Count });

                    // first check if there's a new language
                    foreach (DataColumn LanguageFromFile in DataNames.Tables["Levels"].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;

                                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"]);
                        }
                    
                    }
                
                    // submit changes (tbLanguage)
                    lDBCon.TableUpdate(Data.tblanguage);

                    // compare and add the localized names
                    foreach (DataRow LocalizationFromFile in DataNames.Tables["Levels"].AsEnumerable())
                    {
                        String    BaseName              = (String)LocalizationFromFile[Program.BASE_LANGUAGE];
                        DataRow[] Level                 = Data.tbeconomylevel.Select("level = " + DBConnector.SQLAString(DBConnector.DTEscape(BaseName)));

                        foreach (KeyValuePair<String, Int32> LanguageFormFile in foundLanguagesFromFile)
	                    {
                            DataRow[] currentLocalizations  = Data.tblevellocalization.Select("     economylevel_id  = " + Level[0]["id"] + 
                                                                                                  " and language_id  = " + LanguageFormFile.Value);

                            if(currentLocalizations.Count() == 0)
                            {
                                // add a new localization
                                dsEliteDB.tblevellocalizationRow newRow = (dsEliteDB.tblevellocalizationRow)Data.tblevellocalization.NewRow();

                                newRow.economylevel_id = (Int32)Level[0]["id"];
                                newRow.language_id     = LanguageFormFile.Value;
                                newRow.locname         = LocalizationFromFile[LanguageFormFile.Key].ToString();

                                Data.tblevellocalization.Rows.Add(newRow);
                            }
	                    }

                        Counter++;
                        sendProgressEvent(new ProgressEventArgs() {Info="import economy level localization", CurrentValue=Counter,  TotalValue=DataNames.Tables["Levels"].Rows.Count });
                    }
                }
                // submit changes
                lDBCon.TableUpdate(Data.tblevellocalization);

                lDBCon.Dispose();
            }
            catch (Exception ex)
            {
                if(lDBCon != null)
                    lDBCon.Dispose();

                throw new Exception("Error while loading commodity names", ex);
            }
//.........这里部分代码省略.........
开发者ID:Duke-Jones,项目名称:ED-IBE,代码行数:101,代码来源:EliteDBIO.cs

示例2: ImportCommodityPriceWarnLevels

        /// <summary>
        /// loads the existing price-warnlevel data
        /// </summary>
        internal void ImportCommodityPriceWarnLevels(String Filename)
        {
            DBConnector               lDBCon = null;
            dsEliteDB                         Data;
            List<EDCommoditiesWarningLevels>  WarnLevels;
            Int32 Counter = 0;

            WarnLevels  = JsonConvert.DeserializeObject<List<EDCommoditiesWarningLevels>>(File.ReadAllText(Filename));
            Data        = new dsEliteDB();

            try
            {
                lDBCon = new DBConnector(Program.DBCon.ConfigData, true);

                lDBCon.TableRead("select * from tbCommodity", Data.tbcommodity);

                sendProgressEvent(new ProgressEventArgs() {Info="import warnlevels", CurrentValue=Counter, TotalValue=WarnLevels.Count });

                // first check if there's a new language
                foreach (EDCommoditiesWarningLevels Warnlevel in WarnLevels)
                {
                    DataRow[] Commodity = Data.tbcommodity.Select("commodity = " + DBConnector.SQLAString(DBConnector.DTEscape(Warnlevel.Name)));

                    if(Commodity.Count() > 0)
                    {
                        Commodity[0]["pwl_demand_buy_low"]    = Warnlevel.PriceWarningLevel_Demand_Buy_Low;
                        Commodity[0]["pwl_demand_buy_high"]   = Warnlevel.PriceWarningLevel_Demand_Buy_High;
                        Commodity[0]["pwl_supply_buy_low"]    = Warnlevel.PriceWarningLevel_Supply_Buy_Low;
                        Commodity[0]["pwl_supply_buy_high"]   = Warnlevel.PriceWarningLevel_Supply_Buy_High;
                        Commodity[0]["pwl_demand_sell_low"]   = Warnlevel.PriceWarningLevel_Demand_Sell_Low;
                        Commodity[0]["pwl_demand_sell_high"]  = Warnlevel.PriceWarningLevel_Demand_Sell_High;
                        Commodity[0]["pwl_supply_sell_low"]   = Warnlevel.PriceWarningLevel_Supply_Sell_Low;
                        Commodity[0]["pwl_supply_sell_high"]  = Warnlevel.PriceWarningLevel_Supply_Sell_High;
                    }

                    Counter++;
                    sendProgressEvent(new ProgressEventArgs() { Info="import warnlevels", CurrentValue=Counter, TotalValue=WarnLevels.Count });
                }
                
                // submit changes (tbLanguage)
                lDBCon.TableUpdate(Data.tbcommodity);

                lDBCon.Dispose();

            }
            catch (Exception ex)
            {
                if(lDBCon != null)
                    lDBCon.Dispose();

                throw new Exception("Error while loading commodity names", ex);
            }

        }
开发者ID:Duke-Jones,项目名称:ED-IBE,代码行数:57,代码来源:EliteDBIO.cs

示例3: 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
                        { 
//.........这里部分代码省略.........
开发者ID:Duke-Jones,项目名称:ED-IBE,代码行数:101,代码来源:EliteDBIO.cs

示例4: 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;
                                    }
//.........这里部分代码省略.........
开发者ID:Duke-Jones,项目名称:ED-IBE,代码行数:101,代码来源:EliteDBIO.cs

示例5: 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
//.........这里部分代码省略.........
开发者ID:Duke-Jones,项目名称:ED-IBE,代码行数:101,代码来源:EliteDBIO.cs

示例6: 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;
//.........这里部分代码省略.........
开发者ID:Duke-Jones,项目名称:ED-IBE,代码行数:101,代码来源:EliteDBIO.cs

示例7: 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);
//.........这里部分代码省略.........
开发者ID:Duke-Jones,项目名称:ED-IBE,代码行数:101,代码来源:EliteDBIO.cs


注:本文中的DBConnector.TableRead方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。