示例#1
0
 private void enter_Click(object sender, EventArgs e)
 {
     try
     {
         User record = new User();
         record.Name     = namebox.Text;
         record.Location = locationbox.Text;
         record.Score    = score;
         record.Time     = time;
         record.Date     = DateTime.Now.ToShortDateString();
         hangmancontextDataContext context = new hangmancontextDataContext();
         context.Users.InsertOnSubmit(record);
         context.SubmitChanges();
         context.Dispose();
         UsersView.Items.Clear();
         WinnerDatabase_Load(null, null);
     }
     catch (Exception ob) { MessageBox.Show("Can't insert record rightnow"); }
 }
示例#2
0
        private void WinnerDatabase_Load(object sender, EventArgs e)
        {
            try
            {
                simpleSound = new SoundPlayer("WAVE\\Hangman.wav");
                simpleSound.PlayLooping();
                hangmancontextDataContext context = new hangmancontextDataContext();
                var users = from user in context.Users select user;
                foreach (var user in users)
                {
                    ListViewItem item1 = new ListViewItem(user.Name);
                    item1.SubItems.Add("" + user.Score);
                    item1.SubItems.Add("" + user.Time);
                    item1.SubItems.Add(user.Date);
                    item1.SubItems.Add(user.Location);
                    UsersView.Items.Add(item1);
                }
            }

            catch (Exception ob) { MessageBox.Show("Can't access records rightnow"); }
        }