Example #1
0
        public Stats()
        {
            InitializeComponent();

            List <List <string> > dbData = new List <List <string> >();

            Datenbank.SqliteDatabase database = new Datenbank.SqliteDatabase();
            database.connectDB();
            dbData = database.getData();

            //The list is empty so no data is in the database
            if (dbData.Count < 1)
            {
                System.Windows.Forms.MessageBox.Show("Database is empty!");
                Close();
            }
            // the normal way... read data from database
            else
            {
                //go through the database content. the data is saved in a 2D List. The data is (name of winner, played time, count enemys, board size)
                for (int i = 0; i < dbData.Count; i++)
                {
                    tableLayoutPanelDatabase.RowCount = tableLayoutPanelDatabase.RowCount + 1;
                    this.tableLayoutPanelDatabase.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));

                    for (int j = 0; j < dbData[i].Count; j++)
                    {
                        this.tableLayoutPanelDatabase.Controls.Add(new Label()
                        {
                            Text = dbData[i][j].ToString()
                        }, j, tableLayoutPanelDatabase.RowCount - 1);
                    }
                }
            }
        }
Example #2
0
        private void buttonSaveName_Click(object sender, EventArgs e)
        {
            string inputName = textBoxWinnerName.Text.ToString();

            if (String.IsNullOrEmpty(inputName))
            {
                dataTransferObject.setName("anonymous");
            }
            else
            {
                //set the winnername to the DTO Object
                dataTransferObject.setName(textBoxWinnerName.Text.ToString());
            }


            //Save the data in the database and close the db connection
            HexagonalTest.Datenbank.SqliteDatabase dbHandler = new Datenbank.SqliteDatabase();
            dbHandler.connectDB();
            dbHandler.writeData(dataTransferObject.getName(), dataTransferObject.getTime(), dataTransferObject.getEnemyCount(), dataTransferObject.getFieldSize());
            dbHandler.closeDatabase();

            //restart the Application
            Application.Exit();
            System.Diagnostics.Process.Start(Application.ExecutablePath);      // to start new instance of application
        }