Ejemplo n.º 1
0
 private void button1_Click(object sender, EventArgs e)
 {
     using (var db = new GameTrackerDBmodel())
     {
         try
         {
             var game = new GAME
             {
                 GENREID     = Convert.ToInt32(genreTxt.Text),
                 GAMENAME    = nameTxt.Text,
                 PUBLISHDATE = Convert.ToDateTime(publishTxt.Text),
                 GAMEDESC    = descTxt.Text
             };
             db.GAMES.Add(game);
             db.SaveChanges();
             MessageBox.Show("Your game has been added to the database", "Added Game", MessageBoxButtons.OK, MessageBoxIcon.Information);
             genreTxt.Clear();
             nameTxt.Clear();
             publishTxt.Clear();
             descTxt.Clear();
             var query = (from b in db.GAMES
                          orderby b.GAMENAME
                          select b).ToList();
             dataGridView1.DataSource = query;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Data Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Ejemplo n.º 2
0
 private void button1_Click(object sender, EventArgs e)
 {
     using (var db = new GameTrackerDBmodel())
     {
         try
         {
             var system = new SYSTEM
             {
                 SYSTEMNAME     = sysNameTxt.Text,
                 SYSTEMRELEASE  = Convert.ToDateTime(sysPubTxt.Text),
                 SYSMANUFACTURE = sysMenuTxt.Text
             };
             db.SYSTEMS.Add(system);
             db.SaveChanges();
             MessageBox.Show("Your game has been added to the database", "Added Game", MessageBoxButtons.OK, MessageBoxIcon.Information);
             sysNameTxt.Clear();
             sysMenuTxt.Clear();
             sysPubTxt.Clear();
             var query = (from b in db.SYSTEMS
                          orderby b.SYSTEMNAME
                          select b).ToList();
             dataGridView1.DataSource = query;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Data Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }