示例#1
0
        public static string Builder()
        {
            //Find movie folder path
            string movieDir = BuildDB.MovieDirPath();

            //Create MovieTable
            Console.WriteLine("\n  Creating MovieMetaDataBase . . . .");
            SQLiteConnection mDBconn = DBCommands.CreateConnection();
            object           mDBcmd  = DBCommands.CreateNewMovieTable(mDBconn);

            Console.WriteLine("\n\n  Database created.  You should now populate it.");
            return(movieDir);
        }
示例#2
0
        // Insert Proprties of object holing OMDB API resonse
        // This dyanmially builds the SQL and uses Reflection and parameterization of object to avoid SQL Injection
        public static void InsertOBDMData(SQLiteConnection mDBconn, ResponseStrings OMDBResponse2)
        {
            SQLiteCommand mDBcmd  = mDBconn.CreateCommand();
            string        cmdText = @"INSERT INTO MovieTable  (";
            string        keyText = "";
            string        valText = "";
            //create dictionary
            var OMDBDict = BuildDB.ObjectToDictionary(OMDBResponse2);

            //set up for creating sql command text
            mDBcmd.CommandType = CommandType.Text;
            for (int index = 0; index < OMDBDict.Count - 2; index++)
            {
                var    item    = OMDBDict.ElementAt(index);
                var    itemKey = item.Key;
                string itemVal = item.Value.ToString();

                if (index < OMDBDict.Count - 3)
                {
                    keyText += itemKey + ", ";
                    valText += "@" + itemKey + ", ";  //"=" + itemKey +
                    mDBcmd.Parameters.Add("@" + itemKey, DbType.AnsiString).Value = itemVal;
                    Console.WriteLine(" Added to Database: " + itemKey + " = " + itemVal);
                }
                else
                {
                    keyText += itemKey + " )";
                    valText += "@" + itemKey + " )";  //"=" + itemKey +
                    mDBcmd.Parameters.Add("@" + itemKey, DbType.AnsiString).Value = itemVal;
                    Console.WriteLine(" Added to Database: " + itemKey + " = " + itemVal);
                }
            }
            cmdText += keyText + " VALUES (" + valText + ";";
            try
            {
                mDBcmd.CommandText = cmdText;
                mDBconn.Open();
                mDBcmd.ExecuteNonQuery();
            }
            catch (System.Data.SqlClient.SqlException sx)
            {
                Console.Write(sx); //TODO:  improve SQL error handling
            }
            finally
            {
                mDBconn.Close();
                Console.WriteLine("\n Movie data insertion complete: " + OMDBResponse2.Title + "\n");
            }
        }
示例#3
0
        public static void MenuOptions(string menuChoice)
        {
            switch (menuChoice)
            {
            case "A":
                Console.WriteLine("\n\tYou are about to create a new empty MovieMetaData database and erase any existing database." +
                                  "\n\tContinue?    Y or N \n");
                ConsoleKeyInfo readKey;
                bool           check = false;
                do
                {
                    readKey = Console.ReadKey(true);
                    check   = !((readKey.Key == ConsoleKey.Y) || (readKey.Key == ConsoleKey.N));
                } while (check);
                switch (readKey.Key)
                {
                case ConsoleKey.Y: BuildDB.Builder();  break;

                case ConsoleKey.N: AppMainMenu(); break;
                }
                break;

            case "B":
                string movieDir = BuildDB.MovieDirPath();
                BuildDB.CycleThuFolders(movieDir);
                break;

            case "C":
                if (DBCommands.CheckIfDBExists() == true)
                {
                    DBCommands.ViewMovieList();
                }
                else
                {
                    Console.WriteLine("\n\n  Returned to Main Menu.");
                }
                break;

            case "D":
                if (DBCommands.CheckIfDBExists() == true)
                {
                    DBCommands.SearchMovieTable();
                }
                else
                {
                    Console.WriteLine("\n  before searching the database.\n\n  Returned to Main Menu.");
                }
                break;

            case "E":
                if (DBCommands.CheckIfDBExists() == true)
                {
                    DBCommands.UpdateUserComment();
                }
                else
                {
                    Console.WriteLine("\n  before updating comments.\n\n  Returned to Main Menu.");
                }


                break;

            case "X":
                Console.BackgroundColor = ConsoleColor.White;
                Console.WriteLine("\n ");
                Console.Beep();
                DateTime Tthen = DateTime.Now;
                do
                {
                } while (Tthen.AddSeconds(1) > DateTime.Now);
                System.Environment.Exit(0);
                break;

            default:
                Console.WriteLine("\n Invalid response");
                //Console.ForegroundColor = ConsoleColor.DarkBlue;
                break;
            }
            //Console.WriteLine("Key to End");
            //Console.ReadKey();
        }