コード例 #1
0
ファイル: DbTask.cs プロジェクト: Elinos/TelerikAcademy
 public static void Insert(string taskString, SQLiteDatabase db)
 {
     try
     {
         Dictionary<string, string> data = new Dictionary<string, string>();
         data.Add("taskString", SQLiteDatabase.EscapeSpecialChars(taskString));
         data.Add("taskStatus", "0");
         db.Insert("Tasks", data);
     }
     catch (Exception fail)
     {
         throw new FSSQLiteException("An error occurred when trying to insert a new task.");
     }
 }
コード例 #2
0
ファイル: DbBook.cs プロジェクト: Elinos/TelerikAcademy
 public static void Insert(Book bookToInsert, SQLiteDatabase db)
 {
     try
     {
         Dictionary<string, string> data = BookToFieldsDictionary(bookToInsert);
         bool succ = db.Insert("Books", data);
         if (!succ)
         {
             return;
             //throw new Exception();
         }
     }
     catch
     {
         throw new FSSQLiteException("An unexpected error occured when trying to insert a new book.");
     }
 }
コード例 #3
0
ファイル: BooksLibrary.cs プロジェクト: Elinos/TelerikAcademy
        /// <summary>
        /// Insert a book in DB
        /// </summary>
        /// <param name="bookToInsert"></param>
        /// <param name="db"></param>
        public static void InsertBook(Book bookToInsert, SQLiteDatabase db)
        {
            try
            {
                Dictionary<string, string> data = new Dictionary<string, string>();

                data.Add("title", SQLiteDatabase.EscapeSpecialChars(bookToInsert.Title));
                data.Add("isbn", SQLiteDatabase.EscapeSpecialChars(bookToInsert.Isbn));
                data.Add("publisher", SQLiteDatabase.EscapeSpecialChars(bookToInsert.Publisher));
                data.Add("userRating", bookToInsert.UserRating.ToString());
                data.Add("LibraryThingRating", bookToInsert.SiteRating.ToString());
                data.Add("datePublication", bookToInsert.PublicationDate.ToString());
                string genresString = "";
                foreach (Genre genre in bookToInsert.Genres)
                {
                    genresString+=genre.ToString()+"";
                }
                data.Add("genres", genresString);
                data.Add("description", SQLiteDatabase.EscapeSpecialChars(bookToInsert.Description));
                data.Add("pages", bookToInsert.NumberOfPages.ToString());
                db.Insert("Books", data);

                /*foreach (var genre in bookToInsert.Genres)
                {
                    DataTable genreIds = db.GetIdByItem("Genres", genre.Name);
                    foreach (DataRow g in genreIds.Rows)
                    {
                        data.Add("genres", g["id"].ToString());
                    }
                }

                foreach (var author in bookToInsert.Authors)
                {
                    DataTable authorIds = db.GetIdByItem("Genres", author.FullName);
                    foreach (DataRow a in authorIds.Rows)
                    {
                        data.Add("authors", a["id"].ToString());
                    }
                }*/
            }
            catch (Exception fail)
            {
                throw new FSSQLiteException("An error occurred when trying to insert a new book.");
            }
        }
コード例 #4
0
ファイル: DbBook.cs プロジェクト: Elinos/TelerikAcademy
 public static void Insert(string bookTitle, SQLiteDatabase db)
 {
     try
     {
         Dictionary<string, string> data = new Dictionary<string, string>();
         string[] splitedFileName=bookTitle.Split(new string[]{"\\"},StringSplitOptions.RemoveEmptyEntries);
         data.Add("Title",splitedFileName[splitedFileName.Length-1]);
         data.Add("FilePath", bookTitle);
         bool succ = db.Insert("Books", data);
         if (!succ)
         {
             return;
             //throw new Exception();
         }
     }
     catch
     {
         throw new FSSQLiteException("An unexpected error occured when trying to insert a new book.");
     }
 }
コード例 #5
0
ファイル: BooksLibrary.cs プロジェクト: Elinos/TelerikAcademy
 /// <summary>
 /// Insert a book only with a title
 /// </summary>
 /// <param name="title"></param>
 /// <param name="db"></param>
 public static void InsertBook(string title, SQLiteDatabase db)
 {
     try
     {
         Dictionary<string, string> data = new Dictionary<string, string>();
         data.Add("title", SQLiteDatabase.EscapeSpecialChars(title));
         db.Insert("Books", data);
     }
     catch (Exception fail)
     {
         throw new FSSQLiteException("An error occurred when trying to insert a new book.");
     }
 }