Exemple #1
0
        /// <summary>
        /// Saves the data.
        /// </summary>
        /// <typeparam name="T">The Type definition of data.</typeparam>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="rowInfos">The row infomation list.</param>
        /// <param name="collection">The data collection.</param>
        /// <param name="index">The index for database.</param>
        private static void SaveData <T>(string tableName, List <DataTableRowInfo> rowInfos, List <DataTableRow> collection, int index) where T : DataTableRow
        {
            string              primayPropertyName  = rowInfos[0].PropertyName;
            BoxDBAdapter        addressMapDbAdapter = GetAddressMapDBAdapter();
            DataTableAddressMap addressMap          = new DataTableAddressMap(tableName, index + 2, primayPropertyName);
            bool success = addressMapDbAdapter.Insert(typeof(DataTableAddressMap).Name, addressMap);

            if (success)
            {
                string       dbPath  = GetDBFilesPath();
                BoxDBAdapter adpater = new BoxDBAdapter(dbPath, addressMap.LocalAddress);
                adpater.EnsureTable <T>(tableName, primayPropertyName);
                adpater.Open();

                for (int i = 0, length = collection.Count; i < length; ++i)
                {
                    T data = (T)collection[i];

                    if (data != null)
                    {
                        success = adpater.Insert(tableName, data);
                    }
                }

                adpater.Dispose();
            }

            addressMapDbAdapter.Dispose();
        }
Exemple #2
0
        /// <summary>
        /// Gets the database adapter of address map database.
        /// </summary>
        /// <returns>The adapter of address map database.</returns>
        private static BoxDBAdapter GetAddressMapDBAdapter()
        {
            string       path    = GetDBFilesPath();
            BoxDBAdapter adapter = new BoxDBAdapter(path);

            adapter.EnsureTable <DataTableAddressMap>(typeof(DataTableAddressMap).Name, DataTableAddressMap.PrimaryKey);
            adapter.Open();
            return(adapter);
        }