Beispiel #1
0
        // ADD NOW BUTTON
        //
        // When a user clicks the 'Add Now' button, the current date and
        //    time are entered into the Dates table as a unix timestamp.
        private void addNowButton_Click(object sender, EventArgs e)
        {
            // Delcare some variables we need
            Int64 unixTimeThen = 0;
            Int64 compare      = 0;
            Int64 highest      = 0;

            // When button is clicked
            Int64 unixTimeNow = DateTimeOffset.Now.ToUnixTimeSeconds();

            // Create a new SQLize instance to get the last date
            SQLize retrieveDate = new SQLize("SELECT * FROM Dates ORDER BY datetime DESC LIMIT 1");

            // Store this data briefly with the Read_OneDateInt function of SQLizer
            unixTimeThen = retrieveDate.Read_OneDateInt();

            // Check the difference between unixTimeNow and unixTimeThen with GuardTime
            // But ONLY if the value of unixTimeThen is not 0 which would indicate
            // that there are no records. We need at least one date entry in the dates
            // table to perform calculations!
            if (unixTimeThen != 0)
            {
                GuardTime guard = new GuardTime();
                compare = guard.CalcUnixTimeSpan(unixTimeThen, unixTimeNow);

                // Create one more SQLize instance to grab the last time span from the achievements table
                SQLize retrieveBest = new SQLize("SELECT * FROM Achievements ORDER BY best_time DESC LIMIT 1");
                highest = retrieveBest.Read_OneDateInt();

                // If the the highest time is 0, then there are no records which means we should add one!
                if (highest == 0)
                {
                    // Create a new SQLize instance
                    SQLize add = new SQLize("INSERT INTO Achievements (best_time) VALUES(" + compare + ")");

                    // Run that command
                    add.Run_Command();
                }

                // If the highest time is not 0, then determine if we should insert a new best time.
                if (compare > highest && highest != 0)
                {
                    // Create a new SQLize instance
                    SQLize add = new SQLize("INSERT INTO Achievements (best_time) VALUES(" + compare + ")");

                    // Run that command
                    add.Run_Command();
                }
            }


            // Issue an Insert statement to the Dates table.
            SQLize insert = new SQLize("INSERT INTO Dates (datetime) VALUES (" + unixTimeNow + ")");

            // Tell SQLize to run the command.
            insert.Run_Command();

            // Call Refresh Data
            RefreshData();

            // Refresh our timers
            RefreshGoalDate();
            RefreshCountdown();
            RefreshElapsed();
        }
Beispiel #2
0
        // ADD BUTTON
        //
        // When a user clicks this button a new record containing a custom date and time
        //    is inserted into the database and the database is refreshed.
        private void addButton_Click(object sender, EventArgs e)
        {
            // Declare some variables we need
            Int64 unixTimeThen = 0;
            Int64 compare      = 0;
            Int64 highest      = 0;

            // Begin by creating a new SQLize instance to get the last date
            SQLize retrieveDate = new SQLize("SELECT * FROM Dates ORDER BY datetime DESC LIMIT 1");

            // Store this data briefly with the Read_OneDateInt function of SQLizer
            unixTimeThen = retrieveDate.Read_OneDateInt();

            // Grab our values from the text box
            // Day
            string day = dayComboBox.Text;
            // Month
            string month = monthComboBox.Text;
            // Year
            string year = yearPicker.Text;
            // Time
            string time = timePicker.Text;

            // Parse these values into Guards date format.
            string   dateStringRaw = day + " " + month + " " + year + " " + time;
            DateTime inputDate     = DateTime.Parse(dateStringRaw);

            // Get ourselves a datetime offset.
            DateTimeOffset dto = new DateTimeOffset(inputDate);

            // Turn this into a unix timestamp!
            Int64 unixTimeNow = dto.ToUnixTimeSeconds();

            // Check the difference between unixTimeNow and unixTimeThen with GuardTime
            // But ONLY if the value of unixTimeThen is not 0 which would indicate
            // that there are no records. We need at least one date entry in the dates
            // table to perform calculations!
            if (unixTimeThen != 0)
            {
                // Check the difference between unixTimeNow and unixTimeThen with GuardTime
                GuardTime guard = new GuardTime();
                compare = guard.CalcUnixTimeSpan(unixTimeThen, unixTimeNow);

                // Create one more SQLize instance to grab the last time span from the achievements table
                SQLize retrieveBest = new SQLize("SELECT * FROM Achievements ORDER BY best_time DESC LIMIT 1");
                highest = retrieveBest.Read_OneDateInt();

                // If the highest time is 0, then there are no records whcih means we should add one!
                if (highest == 0)
                {
                    // Create a new SQLize instance
                    SQLize add = new SQLize("INSERT INTO Achievements (best_time) VALUES(" + compare + ")");

                    // Run that command
                    add.Run_Command();
                }

                // Determine if we should insert a new best time
                // If the highest time is not 0, then determine if we should insert a new best time!
                if (compare > highest && highest != 0)
                {
                    // Create a new SQLize instance
                    SQLize add = new SQLize("INSERT INTO Achievements (best_time) VALUES(" + compare + ")");

                    // Run that command
                    add.Run_Command();
                }
            }


            // Create our date
            //string dateStringNew = "\'" + unixTimeNow.ToString() + "\'";

            // Issue an insert statement to the Dates table
            SQLize insert = new SQLize("INSERT INTO Dates (datetime) VALUES (" + unixTimeNow + ")");

            // Tell SQLize to run the command.
            insert.Run_Command();
        }