コード例 #1
0
        internal void save_Saves_DB()
        {
            using (var db = new Blackjack_DBEntities1())
            {
                s_id = (from s in db.Saves_DB
                            select s).Count();

                Saves_DB new_save = new Saves_DB()
                {
                    save_name = Save_Name,
                    id = s_id,
                    active_player = players.Active_Player,
                    active_players = players.Active_Players,
                    deal_visibility = Deal_Button_Visibility,
                    move_visibility = Move_Visibility,
                    done_visibility = Done_Button_Visibility
                };

                db.Saves_DB.Add(new_save);

                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                            eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                ve.PropertyName, ve.ErrorMessage);
                        }
                    }

                }
            }
        }
コード例 #2
0
        internal void save_Ontable_DB()
        {
            int a = s_id;
            using (var db = new Blackjack_DBEntities1())
            {
                int pk = (from s in db.Ontable_DB
                          select s).Count();
                Ontable_DB ontable_db;
                foreach (Card c in deck.OnTable)
                {
                    ontable_db = new Ontable_DB()
                    {
                        Id = pk,
                        save_id = s_id,
                        image_name = c.Card_Image.Name,
                        c_value = c.Card_Value,
                        fname = c.Card_Filename,
                        x_coord = Canvas.GetLeft(c.Card_Image),
                        y_coord = Canvas.GetTop(c.Card_Image),
                        z_coord = Canvas.GetZIndex(c.Card_Image)
                    };
                    db.Ontable_DB.Add(ontable_db);
                    pk++;
                }

                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                            eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                ve.PropertyName, ve.ErrorMessage);
                        }
                    }

                }

            }
        }
コード例 #3
0
        internal void save_Player_DB()
        {
            using (var db = new Blackjack_DBEntities1())
            {
                int pk = (from s in db.Player_hands_DB
                          select s).Count();

                Players_DB players_db;
                Player_hands_DB player_hands_db;
                string player_rowguid;

                for (int i = 0; i < 5; ++i)
                {
                    if (players.is_active(i))
                    {
                        player_rowguid = s_id.ToString() + i.ToString();
                        int p_id = Convert.ToInt32(player_rowguid);
                        players_db = new Players_DB()
                        {
                            player_id = p_id,
                            save_id = s_id,
                            name = players.get_player(i).Player_Name,
                            money = players.get_player(i).Player_Money,
                            total_bet = players.get_player(i).Player_Bet,
                            bet0 = players.get_player(i).get_bet(0),
                            bet1 = players.get_player(i).get_bet(1),
                            bet2 = players.get_player(i).get_bet(2),
                            bet3 = players.get_player(i).get_bet(3),
                            active_hand = players.get_player(i).Active_Hand,
                            nr_of_hands = players.get_player(i).nr_of_hands,
                            player_nr = i

                        };
                        db.Players_DB.Add(players_db);

                        for (int s = 0; s <= players.get_player(i).nr_of_hands; ++s)
                        {

                            foreach (Card c in players.get_player(i).get_hand(s))
                            {
                                player_hands_db = new Player_hands_DB()
                                {
                                    id = pk,
                                    player_id = p_id,
                                    hand = s,
                                    image_name = c.Card_Image.Name
                                };
                                db.Player_hands_DB.Add(player_hands_db);
                                pk++;
                            }
                        }
                    }

                }

                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                            eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                ve.PropertyName, ve.ErrorMessage);
                        }
                    }

                }
                catch(DbUpdateException e)
                {
                    Console.WriteLine("Exception: ", e.Message);
                    Console.WriteLine("Inner exception: ", e.InnerException);
                }

            }
        }
コード例 #4
0
        internal void save_Dealer_DB()
        {
            using (var db = new Blackjack_DBEntities1())
            {
                int pk = (from s in db.Dealer_DB
                          select s).Count();
                Dealer_DB dealer_db = new Dealer_DB()
                {
                    Id = pk,
                    save_id = s_id,
                    hand_value = dealer.Hand_Value,
                    x_offset = dealer.Xoffset
                };
                db.Dealer_DB.Add(dealer_db);

                int fk = pk;
                pk = (from s in db.Dealer_Hand_DB
                      select s).Count();
                Dealer_Hand_DB dealer_hand_db;
                foreach (int i in dealer.Dealer_Hand)
                {
                    dealer_hand_db = new Dealer_Hand_DB()
                    {
                        Id = pk,
                        d_id = fk,
                        c_value = i
                    };
                    pk++;
                    db.Dealer_Hand_DB.Add(dealer_hand_db);
                }

                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                            eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                ve.PropertyName, ve.ErrorMessage);
                        }
                    }

                }
            }
        }