Exemple #1
0
        public List <CameraOwner> ReadCameraMakeModelAndOwners()
        {
            if (cameraMakeModelAndOwnersCache == null)
            {
                cameraMakeModelAndOwnersCache = new List <CameraOwner>();

                Mono.Data.Sqlite.SqliteTransaction sqlTransactionSelect;
                do
                {
                    sqlTransactionSelect = dbTools.TransactionBeginSelect();

                    #region SELECT CameraMake, CameraModel, UserAccount FROM CameraOwner
                    string sqlCommand = "SELECT CameraMake, CameraModel, UserAccount FROM CameraOwner";

                    using (CommonSqliteCommand commandDatabase = new CommonSqliteCommand(sqlCommand, dbTools.ConnectionDatabase, sqlTransactionSelect))
                    {
                        //commandDatabase.Prepare();
                        using (CommonSqliteDataReader reader = commandDatabase.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                CameraOwner cameraOwner = new CameraOwner(
                                    dbTools.ConvertFromDBValString(reader["CameraMake"]),
                                    dbTools.ConvertFromDBValString(reader["CameraModel"]),
                                    dbTools.ConvertFromDBValString(reader["UserAccount"]));
                                cameraMakeModelAndOwnersCache.Add(cameraOwner);
                            }
                        }
                    }
                    #endregion
                } while (!dbTools.TransactionCommitSelect(sqlTransactionSelect));
            }
            return(cameraMakeModelAndOwnersCache);
        }
Exemple #2
0
        public List <CameraOwner> ReadCameraMakeModelAndOwnersThatNotExist(List <CameraOwner> cameraOwners)
        {
            Mono.Data.Sqlite.SqliteTransaction sqlTransactionSelect;
            do
            {
                sqlTransactionSelect = dbTools.TransactionBeginSelect();

                #region SELECT DISTINCT CameraMake, CameraModel, NULL as UserAccount FROM MediaMetadata
                string sqlCommand = "SELECT DISTINCT CameraMake, CameraModel, NULL as UserAccount FROM MediaMetadata";

                using (CommonSqliteCommand commandDatabase = new CommonSqliteCommand(sqlCommand, dbTools.ConnectionDatabase, sqlTransactionSelect))
                {
                    //commandDatabase.Prepare();
                    using (CommonSqliteDataReader reader = commandDatabase.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            CameraOwner cameraOwner = new CameraOwner(
                                dbTools.ConvertFromDBValString(reader["CameraMake"]),
                                dbTools.ConvertFromDBValString(reader["CameraModel"]),
                                dbTools.ConvertFromDBValString(reader["UserAccount"]));
                            if (!string.IsNullOrWhiteSpace(cameraOwner.Make) &&
                                !string.IsNullOrWhiteSpace(cameraOwner.Model) &&
                                !CameraOwner.CameraMakeModelExistInList(cameraOwners, cameraOwner))
                            {
                                cameraOwners.Add(cameraOwner);
                            }
                        }
                    }
                }
                #endregion
            } while (!dbTools.TransactionCommitSelect(sqlTransactionSelect));

            return(cameraOwners);
        }
Exemple #3
0
        public void SaveCameraMakeModelAndOwner(CameraOwner cameraOwner)
        {
            if (cameraOwner == null)
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(cameraOwner.Make))
            {
                cameraOwner.Make = CameraOwner.UnknownMake;
            }
            if (string.IsNullOrWhiteSpace(cameraOwner.Model))
            {
                cameraOwner.Model = CameraOwner.UnknownModel;
            }
            //if (string.IsNullOrWhiteSpace(cameraOwner.Owner)) cameraOwner.Owner = CameraOwner.UnknownOwner;

            Mono.Data.Sqlite.SqliteTransaction sqlTransaction;
            do
            {
                sqlTransaction = dbTools.TransactionBegin();
                #region DELETE FROM CameraOwner
                string sqlCommand =
                    "DELETE FROM CameraOwner WHERE " +
                    "CameraMake = @CameraMake AND CameraModel = @CameraModel";
                using (CommonSqliteCommand commandDatabase = new CommonSqliteCommand(sqlCommand, dbTools.ConnectionDatabase, sqlTransaction))
                {
                    //commandDatabase.Prepare();
                    commandDatabase.Parameters.AddWithValue("@CameraMake", cameraOwner.Make);
                    commandDatabase.Parameters.AddWithValue("@CameraModel", cameraOwner.Model);
                    commandDatabase.ExecuteNonQuery();      // Execute the query
                }
                #endregion

                #region INSERT INTO CameraOwner
                sqlCommand =
                    "INSERT INTO CameraOwner (CameraMake, CameraModel, UserAccount) " +
                    "Values (@CameraMake, @CameraModel, @UserAccount)";
                using (CommonSqliteCommand commandDatabase = new CommonSqliteCommand(sqlCommand, dbTools.ConnectionDatabase, sqlTransaction))
                {
                    //commandDatabase.Prepare();
                    commandDatabase.Parameters.AddWithValue("@CameraMake", cameraOwner.Make);
                    commandDatabase.Parameters.AddWithValue("@CameraModel", cameraOwner.Model);
                    commandDatabase.Parameters.AddWithValue("@UserAccount", cameraOwner.Owner);
                    commandDatabase.ExecuteNonQuery();      // Execute the query
                }
                #endregion
            } while (!dbTools.TransactionCommit(sqlTransaction));

            MakeCameraOwnersDirty();
        }