private void TestRemoveSevenths(string quality)
    {
        var entities = new TheoryTrainerEntities();

        var sevenths = from s in entities.SeventhChords
                       where s.SeventhChordQuality.Name == quality
                       select s;

        foreach (var s in sevenths)
        {
            string key = string.Format("{0} {1} seventh", s.Root, s.SeventhChordQuality.Name);
            //TextBox1.Text -= key + ", " + value + "\n";
        }
    }
    private void TestRemoveTriads(string quality)
    {
        var entities = new TheoryTrainerEntities();

        var triads = from t in entities.Triads
                     where t.TriadQuality.Name == quality
                     select t;

        foreach (var t in triads)
        {
            string key = string.Format("{0} {1} triad", t.Root, t.TriadQuality.Name);
            //TextBox1.Text -= key + ", " + value + "\n";
        }
    }
    private void TestAddSevenths(string quality)
    {
        var entities = new TheoryTrainerEntities();

        var sevenths = from s in entities.SeventhChords
                       where s.SeventhChordQuality.Name == quality
                       select s;

        foreach (var s in sevenths)
        {
            string key   = string.Format("{0} {1} seventh", s.Root, s.SeventhChordQuality.Name);
            string value = string.Format("{0}-{1}-{2}-{3}", s.Root, s.Third, s.Fifth, s.Seventh);
            TextBox1.Text += key + ", " + value + "\n";
        }
    }
    private void TestAddTriads(string quality)
    {
        var entities = new TheoryTrainerEntities();

        var triads = from t in entities.Triads
                     where t.TriadQuality.Name == quality
                     select t;

        foreach (var t in triads)
        {
            string key   = string.Format("{0} {1} triad", t.Root, t.TriadQuality.Name);
            string value = string.Format("{0}-{1}-{2}", t.Root, t.Third, t.Fifth);
            TextBox1.Text += key + ", " + value + "\n";
        }
    }
Пример #5
0
    protected void btnLogIn_Click(object sender, EventArgs e)
    {
        string userName = txtUser.Text.Trim();

        // using stmt is not really necessary
        // we use it the whole time, and the object will be released at the end of the event handler
        var entities = new TheoryTrainerEntities();

        // see if the user exists in the database
        var user = (from u in entities.Users
                    where u.Name == userName
                    select u).SingleOrDefault <User>(); // returns null if not found

        if (user == null)
        {
            // if user does not exist, create a new User object and add to db
            var newUser = new User
            {
                Name           = userName,
                CreateDateTime = DateTime.Now,
                UpdateDateTime = DateTime.Now
            };
            entities.Users.Add(newUser);
            entities.SaveChanges();

            // then set UserName property of speller
            speller.UserName = newUser.Name;
        }
        else
        {
            // if user was found, retrieve user from db
            var existingUser = (from u in entities.Users
                                where u.Name == userName
                                select u).SingleOrDefault <User>();

            // set UserNAme property of speller
            speller.UserName = existingUser.Name;

            // display best percentage and datetime
            lblBestPercentage.Text = string.Format("{0} on {1}",
                                                   existingUser.BestPercentage.ToString("p1"),
                                                   existingUser.UpdateDateTime.ToShortDateString());
        }

        // Display UserName
        lblUser.Text = speller.UserName;
    }
Пример #6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        using (var entities = new TheoryTrainerEntities())
        {
            #region Display qualities in labels
            var allTriadQualities = from t in entities.TriadQualities
                                    select t;

            var allSeventhQualities = from s in entities.SeventhChordQualities
                                      select s;

            foreach (var tq in allTriadQualities)
            {
                triadQualityLabel.Text += tq.Name + ", ";
            }

            foreach (var sq in allSeventhQualities)
            {
                seventhQualityLabel.Text += sq.Name + ", ";
            }
            #endregion

            #region Display triads and quality
            var allTriads = from t in entities.Triads
                            select t; // TODO: select the stuff here not in the display [create a new object for more than one property?]

            foreach (var t in allTriads)
            {
                triadsTextBox.Text += string.Format("{0}-{1}-{2}, {3}\n",
                                                    t.Root, t.Third, t.Fifth, t.TriadQuality.Name);
            }
            #endregion

            #region Display sevenths and quality
            var allSevenths = from s in entities.SeventhChords
                              select s;

            foreach (var s in allSevenths)
            {
                seventhsTextBox.Text += string.Format("{0}-{1}-{2}-{3}, {4}\n",
                                                      s.Root, s.Third, s.Fifth, s.Seventh, s.SeventhChordQuality.Name);
            }
            #endregion

            #region Test Add methods
        }
    }
Пример #7
0
    public void RemoveTriads(string quality)
    {
        var entities = new TheoryTrainerEntities();

        var triads = from t in entities.Triads
                     where t.TriadQuality.Name == quality
                     select t;

        foreach (var t in triads)
        {
            string key = string.Format("{0} {1} triad", t.Root, t.TriadQuality.Name);
            if (chordLibrary.ContainsKey(key)) // only remove if key exists
            {
                chordLibrary.Remove(key);
            }
        }
    }
Пример #8
0
    public void RemoveSevenths(string quality)
    {
        var entities = new TheoryTrainerEntities();

        var sevenths = from s in entities.SeventhChords
                       where s.SeventhChordQuality.Name == quality
                       select s;

        foreach (var s in sevenths)
        {
            string key = string.Format("{0} {1} seventh", s.Root, s.SeventhChordQuality.Name);
            if (chordLibrary.ContainsKey(key)) // TEST
            {
                chordLibrary.Remove(key);
            }
        }
    }
Пример #9
0
    public void AddSevenths(string quality)
    {
        var entities = new TheoryTrainerEntities();

        var sevenths = from s in entities.SeventhChords
                       where s.SeventhChordQuality.Name == quality
                       select s;

        foreach (var s in sevenths)
        {
            string key   = string.Format("{0} {1} seventh", s.Root, s.SeventhChordQuality.Name);
            string value = string.Format("{0}-{1}-{2}-{3}", s.Root, s.Third, s.Fifth, s.Seventh);
            if (!chordLibrary.ContainsKey(key))
            {
                chordLibrary.Add(key, value);
            }
        }
    }
Пример #10
0
    // TODO: could the parameter be changed to int and used with an enum defined in ChordSpeller?
    // no, because the LINQ query requires a string name [verify no workaround, translate int to string?]
    public void AddTriads(string quality)
    {
        var entities = new TheoryTrainerEntities();

        var triads = from t in entities.Triads
                     where t.TriadQuality.Name == quality
                     select t;

        foreach (var t in triads)
        {
            string key   = string.Format("{0} {1} triad", t.Root, t.TriadQuality.Name);
            string value = string.Format("{0}-{1}-{2}", t.Root, t.Third, t.Fifth);
            if (!chordLibrary.ContainsKey(key)) // only add if key does not yet exist
            {
                chordLibrary.Add(key, value);
            }
        }
    }
Пример #11
0
    protected void btnLogOut_Click(object sender, EventArgs e)
    {
        string userName = txtUser.Text.Trim(); // TODO: this could be unreliable

        var entities = new TheoryTrainerEntities();

        var currentUser = (from u in entities.Users
                           where u.Name == userName
                           select u).SingleOrDefault <User>();

        // update the session percentage, rounded to 3 decimal places
        // the if stmt prevents an exception if user logs in and immediately logs out without trying to spell a chord
        if (speller.PercentageCorrect > 0)
        {
            currentUser.SessionPercentage = Math.Round(speller.PercentageCorrect, 3);
        }
        else
        {
            currentUser.SessionPercentage = 0;
        }

        // check to see if it's a new "best" percentage
        if (speller.PercentageCorrect > currentUser.BestPercentage)
        {
            currentUser.BestPercentage = Math.Round(speller.PercentageCorrect, 3);
        }

        currentUser.UpdateDateTime = DateTime.Now;
        entities.SaveChanges();

        ResetUIChords();
        ResetUIStats();

        // Reset the "user" properties of speller to clear out the user who logged out
        speller.UserName       = null;
        speller.UserSpelling   = null;
        speller.Attempts       = 0;
        speller.CorrectAnswers = 0;
    }