示例#1
0
		public bool MoveToNext ()
		{
			stepResult = statement.Step ();

			currentRow++;

			return stepResult == SQLiteResult.ROW;
		}
 public static bool IsSuccess(this SQLiteResult result)
 {
     return(result == SQLiteResult.OK || result == SQLiteResult.DONE);
 }
        /// <summary>
        /// This method is looking for a books, adds books to the main page if they are not contains in the database,
        /// deletes books if they don't exist on the user's device. It helps to hold actual data.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">An object that contains the event data.</param>
        private async void OnClickSearchBooksButton(object sender, EventArgs args)
        {
            IFiler filer = DependencyService.Get <IFiler>();
            IEnumerable <string> pathsOfFoundFiles = await filer.GetFilesPathsAsync(FileExtension.EPUB).ConfigureAwait(false);

            List <EpubBook> epubBooks = new List <EpubBook>();

            foreach (var path in pathsOfFoundFiles)
            {
                EpubBook book = await EpubReader.EpubReader.ReadBookAsync(path).ConfigureAwait(false);

                epubBooks.Add(book);
            }

            List <string> pathsOfExistingFiles = this.bookEntities.Select(entity => entity.FilePath).ToList();

            // Try to read not all book information.
            // I need to read only a necessary information e.g. Title, Author, Cover.
            foreach (EpubBook epubBook in epubBooks)
            {
                // If the book entity does not exist.
                // Add a new book info to the main page.
                if (pathsOfExistingFiles.Contains(epubBook.FilePath) == false)
                {
                    BookEntity bookEntity = new BookEntity
                    {
                        Id     = Guid.NewGuid().ToNonDashedString(),
                        Title  = epubBook.Title,
                        Author = epubBook.Author,
                        // It should be changed.
                        // An image might be missed.
                        Cover    = epubBook.Content.Images.FirstOrDefault().Value.Content,
                        FilePath = epubBook.FilePath
                    };

                    SettingsEntity settingsEntity = new SettingsEntity
                    {
                        BookId   = bookEntity.Id,
                        LastPage = 1,
                        FontSize = 14
                    };

                    SQLiteResult result = this.bookRepository.Add(bookEntity);
                    SQLiteResult settingsInsertResult = this.settingsRepository.Add(settingsEntity);

                    // 0 is SQLITE_OK
                    // But returns 1 and entity is successfully saved into database.
                    //if (bookInsertStatusCode == 1)
                    //{
                    this.bookEntities.Add(bookEntity);
                    BookInfoViewModel model = bookEntity.ToBookInfoModelMapper();
                    this.books.Add(model);
                    //}
                }
            }

            // Delete book info models and book entities which do not exist yet.
            foreach (var pathOfExistingFile in pathsOfExistingFiles)
            {
                if (pathsOfFoundFiles.Contains(pathOfExistingFile) == false)
                {
                    // Delete entity.
                    BookEntity deletedBookEntity = this.bookEntities.FirstOrDefault(e => e.FilePath == pathOfExistingFile);
                    this.bookRepository.DeleteById(deletedBookEntity.Id);
                    this.bookEntities.Remove(deletedBookEntity);

                    // Delete book info view model.
                    BookInfoViewModel deletedBookInfoViewModel = this.books.FirstOrDefault(m => m.FilePath == pathOfExistingFile);
                    this.books.Remove(deletedBookInfoViewModel);
                }
            }

            Xamarin.Forms.Device.BeginInvokeOnMainThread(() => this.UpdateBookLibrary(this.books));
        }
 private static void ValidateResult(SQLiteResult result)
 {
     if (result != SQLiteResult.DONE)
     {
         throw new SQLiteException(string.Format("Query execution failed with result: '{0}'.", result));
     }
 }
示例#5
0
 public SQLiteException(SQLiteResult r, string message)
     : base(message)
 {
     SqLiteResult = r;
 }
        //Update info

        public static int updateIncome(IncExp incExp)
        {
            int    status      = 0;
            String name        = incExp.Name;
            double amount      = incExp.Amount;
            String payer       = incExp.Person;
            String category    = incExp.Category;
            String description = incExp.Description;
            String id          = incExp.Id;
            String date        = incExp.Date;
            bool   isIncome    = incExp.Income;
            int    cond        = 0;

            if (isIncome)
            {
                cond = 1;
            }
            String accID = incExp.AccID;

            try
            {
                using (var connection = new SQLitePCL.SQLiteConnection("Storage.db"))
                {
                    using (var statement = connection.Prepare(@"UPDATE IncExp SET Name=?, Amount=?, Person=?,
                                                                Category=?, Description=?, ID=?, Date=?, Income=?, Acc_ID=?
                                                                WHERE ID=?;"))
                    {
                        statement.Bind(1, name);
                        statement.Bind(2, amount.ToString());
                        statement.Bind(3, payer);
                        statement.Bind(4, category);
                        statement.Bind(5, description);
                        statement.Bind(6, id);
                        statement.Bind(7, date.ToString());
                        statement.Bind(8, cond);
                        statement.Bind(9, accID);
                        statement.Bind(10, id);


                        SQLiteResult s = statement.Step();
                        statement.Reset();
                        statement.ClearBindings();

                        if ((s.ToString().Equals("DONE")))
                        {
                            Debug.WriteLine("Update done");
                            status = 1;
                        }
                        else
                        {
                            Debug.WriteLine("Update failed");
                            status = 0;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return(status);
        }
        //Insert info

        public static int insertIncome(IncExp incExp)
        {
            int    status      = 0;
            String name        = incExp.Name;
            double amount      = incExp.Amount;
            String payer       = incExp.Person;
            String category    = incExp.Category;
            String description = incExp.Description;
            String id          = incExp.Id;

            String[] dateArray = incExp.Date.ToString().Split(' ');
            String   date      = dateArray[0];

            bool isIncome = incExp.Income;
            int  cond     = 0;

            if (isIncome)
            {
                cond = 1;
            }
            String accID = incExp.AccID;

            try
            {
                using (var connection = new SQLitePCL.SQLiteConnection("Storage.db"))
                {
                    using (var statement = connection.Prepare(@"INSERT INTO IncExp (Name, Amount, Person,
                                                                Category, Description, ID, Date, Income, Acc_ID)
                                    VALUES(?,?,?,?,?,?,?,?,?);"))
                    {
                        statement.Bind(1, name);
                        statement.Bind(2, amount.ToString());
                        statement.Bind(3, payer);
                        statement.Bind(4, category);
                        statement.Bind(5, description);
                        statement.Bind(6, id);
                        statement.Bind(7, date.ToString());
                        statement.Bind(8, cond);
                        statement.Bind(9, accID);


                        SQLiteResult s = statement.Step();
                        statement.Reset();
                        statement.ClearBindings();
                        if ((s.ToString().Equals("DONE")))
                        {
                            Debug.WriteLine("Step done");
                            status = 1;
                        }
                        else
                        {
                            Debug.WriteLine("Step failed");
                            status = 0;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return(status);
        }
示例#8
0
        /// <summary>
        /// 마지막 접근 폴더를 갱신한다.
        /// </summary>
        /// <param name="folderInfo"></param>
        /// <returns></returns>
        public SQLiteResult ReplaceLastFolder(StorageItemInfo folderInfo)
        {
            SQLiteResult result = SQLiteResult.EMPTY;

            string coumn = @",CASE WHEN (SELECT COUNT(*) 
                                           FROM FOLDER T 
                                          WHERE T.PATH = PATH 
                                            AND T.FOLDER_TYPE = 1) > 0 THEN 'Y' 
                                   ELSE 'N' 
                              END AS IS_ADDED_FOLDER";

            //이전의 마지막 폴더 조회
            using (var stmt = conn.Prepare(DML_SELECT.Replace("${COLUMN}", coumn)))
            {
                string prevItemName = string.Empty;
                stmt.Bind("@FOLDER_TYPE", (int)SubType.LastFolder);

                while (stmt.Step() == SQLitePCL.SQLiteResult.ROW)
                {
                    StorageItemInfo fi            = GetRowData(stmt);
                    bool            isAddedFolder = stmt.GetText("IS_ADDED_FOLDER") == "Y";

                    //먼저 마지막 폴더의 타입이 Last folder인 것을 삭제
                    using (var stmt2 = conn.Prepare(DML_DELETE))
                    {
                        stmt2.Bind("@PATH", fi.Path);
                        stmt2.Bind("@FOLDER_TYPE", (int)fi.SubType);
                        result = stmt2.Step();
                    }
                    //타입 삭제 여부
                    if (result != SQLiteResult.DONE)
                    {
                        return(result);
                    }

                    //삭제하려는 폴더가 추가된 폴더로 등록되어 있지 않는 폴더라면, FutrueAccessList를 검사하여 삭제 시킴
                    if (!isAddedFolder && !string.IsNullOrEmpty(fi.FalToken) && StorageApplicationPermissions.FutureAccessList.ContainsItem(fi.FalToken))
                    {
                        //FAL삭제
                        StorageApplicationPermissions.FutureAccessList.Remove(fi.FalToken);
                    }
                }
            }

            if (folderInfo != null)
            {
                //새롭게 폴더 등록
                using (var stmt = conn.Prepare(DML_INSERT))
                {
                    stmt.Bind("@PATH", folderInfo.Path);
                    stmt.Bind("@FOLDER_TYPE", (int)SubType.LastFolder);
                    stmt.Bind("@NAME", folderInfo.Name);
                    stmt.Bind("@ROOT_PATH", folderInfo.RootPath);
                    stmt.Bind("@FAL_TOKEN", folderInfo.FalToken);

                    result = stmt.Step();
                }
            }

            return(result);
        }
示例#9
0
 public SQLiteException(SQLiteResult r, string message)
     : base(message)
 {
     SQLiteResult = r;
 }