PrintAndReset() public method

public PrintAndReset ( string Info ) : void
Info string
return void
Ejemplo n.º 1
0
//        private Dictionary<DataTable, MySql.Data.MySqlClient.MySqlDataAdapter>     m_BaseData_UpdateObjects = new Dictionary<DataTable, MySql.Data.MySqlClient.MySqlDataAdapter>();
        



        /// <summary>
        /// loads the data from the basetables into memory. For correct initialization it is
        /// necessary to call this fuction with a unset tableName
        /// 
        /// </summary>
        /// <param name="m_BaseData"></param>
        internal void PrepareBaseTables(String TableName = "", Boolean saveChanged = false)
        {
            PerformanceTimer Runtime;
            //MySql.Data.MySqlClient.MySqlDataAdapter dataAdapter;
            DBConnector currentDBCon;

            try
            {
                Runtime = new PerformanceTimer();

                if(String.IsNullOrEmpty(TableName))
                { 
                    if(m_BaseData == null)
                    {
                        m_BaseData              = new dsEliteDB();
                        m_BaseData_Connector    = new Dictionary<DataTable, DBConnector>();
                    }

                    foreach (String BaseTable in BaseTables_Systems)
                    {
                        if (!m_BaseData_Connector.TryGetValue(m_BaseData.Tables[BaseTable], out currentDBCon))
                        {
                            // each basetable gets it's own DBConnector, because 
                            // the contained DataReaders will be hold open for possible 
                            // changes (MySQL doesn't support MARS "Multiple Active result Sets")

                            currentDBCon = new DBConnector(Program.DBCon.ConfigData);
                            m_BaseData_Connector.Add(m_BaseData.Tables[BaseTable], currentDBCon);

                            currentDBCon.Connect();
                        }

                        Runtime.startMeasuring();
                        m_BaseData.Tables[BaseTable].Clear();

                        if (!Program.SplashScreen.IsDisposed)
                            Program.SplashScreen.InfoAdd("...loading basetable '" + BaseTable + "'...");                            

                        // preload all tables with base data
                        currentDBCon.TableRead(String.Format("select * from {0}", BaseTable), BaseTable, m_BaseData);
                        
                        if (!Program.SplashScreen.IsDisposed)
                            Program.SplashScreen.InfoAppendLast("<OK>");                            

                        Runtime.PrintAndReset("loading full table '" + BaseTable + "':");
                    }
                }
                else if(BaseTables_Systems.Contains(TableName))
                {
                    currentDBCon = m_BaseData_Connector[m_BaseData.Tables[TableName]];

                    if(saveChanged)
                    {
                        // save all containing changes
                        Runtime.PrintAndReset("saving changes in table '" + TableName + "':");
                        currentDBCon.TableUpdate(TableName, m_BaseData);
                    }
                    else
                    {
                        Runtime.startMeasuring();

                        m_BaseData.Tables[TableName].Clear();

                        // reload selected table
                        currentDBCon.TableRead("", TableName, m_BaseData);

                        Runtime.PrintAndReset("re-loading full table '" + TableName + "':");
                    }
                }
                else
                {
                    throw new Exception(string.Format("Attempt to load an unknown basetable : <{0}>", TableName));
                }

            }
            catch (Exception ex)
            {
                throw new Exception("Error while preparing base tables", ex);
            }
        }