Esempio n. 1
0
        /// <summary>
        /// Function used to set database (or no database).
        /// </summary>
        public void DatabaseSelectionMenu()
        {
            string[] options = new string[] { "Window login Authentication", "SQL Server Authentication", "No SQL Database" };
            string[] sqlInfo;
            string   firstConnection;

            bool run = true;

            Reporter.Log("Program starting");
            do
            {
                byte answer = VisualCalculator.MenuRun(options, "Database");
                switch (answer)
                {
                case 0:
                    sqlInfo    = new string[2];
                    sqlInfo[0] = Support.CollectString("Enter Servername");
                    sqlInfo[1] = Support.CollectString("Enter database");
                    if (!ShallDatabaseInitialiseMenu())
                    {
                        try
                        {
                            SQLCode.SQLControl.DataBase = sqlInfo[1];
                            firstConnection             = SQLCode.SQLControl.CreateConnectionString(sqlInfo[0], "master");
                            run = !SQLCode.SQLControl.InitalitionOfDatabase(sqlInfo, firstConnection, true);
                            SQLCode.SQLControl.DatabaseInUse = true;
                        }
                        catch (Exception e)
                        {
                            Support.ErrorHandling(e, $"Encounted an error: {e.Message}");
                            run = true;
                        }
                    }
                    else
                    {
                        try
                        {
                            SQLCode.SQLControl.DataBase = sqlInfo[1];
                            run = !SQLCode.SQLControl.CreateConnection(sqlInfo, true);
                            SQLCode.SQLControl.DatabaseInUse = true;
                        }
                        catch (Exception e)
                        {
                            Support.ErrorHandling(e, $"Encounted an error: {e.Message}");
                            run = true;
                        }
                    }
                    break;

                case 1:
                    sqlInfo    = new string[4];
                    sqlInfo[0] = Support.CollectString("Enter Servername");
                    sqlInfo[1] = Support.CollectString("Enter SQL Username");
                    sqlInfo[2] = Support.HiddenText("Enter Password");
                    sqlInfo[3] = Support.CollectString("Enter database");
                    if (!ShallDatabaseInitialiseMenu())
                    {
                        try
                        {
                            SQLCode.SQLControl.DataBase = sqlInfo[3];
                            firstConnection             = SQLCode.SQLControl.CreateConnectionString(sqlInfo[0], sqlInfo[1], sqlInfo[2], "master");
                            run = !SQLCode.SQLControl.InitalitionOfDatabase(sqlInfo, firstConnection, false);
                            SQLCode.SQLControl.DatabaseInUse = true;
                        }
                        catch (Exception e)
                        {
                            Support.ErrorHandling(e, $"Encounted an error: {e.Message}");
                            run = true;
                        }
                    }
                    else
                    {
                        try {
                            SQLCode.SQLControl.DataBase = sqlInfo[3];
                            run = !SQLCode.SQLControl.CreateConnection(sqlInfo, false);
                            SQLCode.SQLControl.DatabaseInUse = true;
                        }
                        catch (Exception e)
                        {
                            Support.ErrorHandling(e, $"Encounted an error: {e.Message}");
                            run = true;
                        }
                    }

                    break;

                case 2:
                    WareInformation.AddWareDefault();
                    SQLCode.SQLControl.DatabaseInUse = false;
                    break;
                }
                if (answer == options.Length - 1)
                {
                    run = false;
                }
                if (run == true)
                {
                    Console.Clear();
                    Console.WriteLine("Could not establish connection to the database");
                    Support.WaitOnKeyInput();
                }
            } while (run);
        }
Esempio n. 2
0
 /// <summary>
 /// Asks the user to enter an ID and returns it.
 /// </summary>
 /// <returns>Returns the inputted ID.</returns>
 private string CollectID()
 {
     return(Support.CollectString("Enter ID"));
 }