示例#1
0
        public static bool SaveCardToDBVersioned(Card card)
        {
            String versionQuery = String.Format("SELECT MAX(version) FROM cards WHERE cards.guid = '{0}';", card.Guid);
            DBCore dbConnection = new DBCore();
            int version = dbConnection.ExecuteScalar(versionQuery) + 1;
            int success = SaveCardToDBAsIs(card);

            return success > 0;
        }
示例#2
0
 public static int SaveKeyword(Keyword keywordToSave)
 {
     int version = 0;
     DBCore dbConnection = new DBCore();
     if (keywordToSave.Guid != String.Empty)
     {
         String versionQuery = String.Format("SELECT MAX(version) from keywordabilities WHERE guid = '{0}';", keywordToSave.Guid);
         version = dbConnection.ExecuteScalar(versionQuery) + 1;
     }
     if (version == 0)
     {
         String guid = "KW-" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, 12);
         keywordToSave.Guid = guid;
     }
     keywordToSave.Version = version;
     String abilityMarkup = new Serializer(typeof(Keyword)).Serialize(keywordToSave);
     String insertQuery = String.Format(@"INSERT INTO keywordabilities
                     (guid, name, text, hasxvalue, version)
                     VALUES ('{0}', '{1}', '{2}', {3}, {4});",
                     keywordToSave.Guid, keywordToSave.Name, abilityMarkup, keywordToSave.HasXValue, keywordToSave.Version);
     int keywordID = dbConnection.ExecuteInsertQuery(insertQuery);
     return keywordID;
 }
示例#3
0
        private static int SaveCardToDBAsIs(Card card)
        {
            if (card.Version == 0)
            {
                String guid = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 12);
                card.Guid = "C" + guid;
            }
            card.Flavor = card.Flavor.Replace("\"", "\\\"");
            Serializer cardSerializer = new Serializer(typeof(Card));
            String queryMarkup = cardSerializer.Serialize(card);
            card.Flavor.Replace("\\\"", "\"");

            // int deleteStart = queryMarkup.IndexOf("/*");
            // int deleteEnd = queryMarkup.IndexOf("*/", deleteStart + 2);
            // queryMarkup = queryMarkup.Remove(deleteStart, deleteEnd - deleteStart + 1);

            DBCore dbConnection = new DBCore();
            String query = String.Format("INSERT INTO cards (version, guid, editor, markup) VALUES ({0}, '{1}', '{2}', '{3}');", card.Version, card.ID, card.Creds.Designer, queryMarkup);
            int success = dbConnection.ExecuteInsertQuery(query);

            query = String.Format("SELECT LATEST_INSERT_ID()");
            int newID = dbConnection.ExecuteScalar(query);
            card.ID = newID;

            AbilityDB.SaveAbilitiesOnCard(card);
            return newID;
        }