예제 #1
0
            public static bool SaveCard(CardInfos card, SQLiteConnection connection, int loadedid, bool overwrite)
            {
                try
                {
                    SQLiteCommand command;
                    if (overwrite)
                    {
                        command = DatabaseHelper.CreateCommand("UPDATE datas" +
                                                               " SET id= @id, ot = @ot, alias= @alias, setcode= @setcode, type= @type, atk= @atk, def= @def, level= @level, race= @race, attribute= @attribute, category= @category WHERE id = @loadedid", connection);
                    }
                    else
                    {
                        command = DatabaseHelper.CreateCommand("INSERT INTO datas (id,ot,alias,setcode,type,atk,def,level,race,attribute,category)" +
                                                               " VALUES (@id, @ot, @alias, @setcode, @type, @atk, @def, @level, @race, @attribute, @category)", connection);
                    }

                    command.Parameters.Add(new SQLiteParameter("@loadedid", loadedid));
                    command.Parameters.Add(new SQLiteParameter("@id", card.Id));
                    command.Parameters.Add(new SQLiteParameter("@ot", card.Ot));
                    command.Parameters.Add(new SQLiteParameter("@alias", card.AliasId));
                    command.Parameters.Add(new SQLiteParameter("@setcode", card.SetCode));
                    command.Parameters.Add(new SQLiteParameter("@type", card.Type));
                    command.Parameters.Add(new SQLiteParameter("@atk", card.Atk));
                    command.Parameters.Add(new SQLiteParameter("@def", card.Def));
                    command.Parameters.Add(new SQLiteParameter("@level", card.GetLevelCode()));
                    command.Parameters.Add(new SQLiteParameter("@race", card.Race));
                    command.Parameters.Add(new SQLiteParameter("@attribute", card.Attribute));
                    command.Parameters.Add(new SQLiteParameter("@category", card.Category));
                    DatabaseHelper.ExecuteNonCommand(command);

                    if (overwrite)
                    {
                        command = DatabaseHelper.CreateCommand("UPDATE texts" +
                                                               " SET id= @id,name= @name,desc= @des,str1= @str1,str2= @str2,str3= @str3,str4= @str4,str5= @str5,str6= @str6,str7= @str7,str8= @str8,str9= @str9,str10= @str10,str11= @str11,str12= @str12,str13= @str13,str14= @str14,str15= @str15,str16= @str16 WHERE id= @loadedid", connection);
                    }
                    else
                    {
                        command = DatabaseHelper.CreateCommand("INSERT INTO texts (id,name,desc,str1,str2,str3,str4,str5,str6,str7,str8,str9,str10,str11,str12,str13,str14,str15,str16)" +
                                                               " VALUES (@id,@name,@des,@str1,@str2,@str3,@str4,@str5,@str6,@str7,@str8,@str9,@str10,@str11,@str12,@str13,@str14,@str15,@str16)", connection);
                    }
                    command.Parameters.Add(new SQLiteParameter("@loadedid", loadedid));
                    command.Parameters.Add(new SQLiteParameter("@id", card.Id));
                    command.Parameters.Add(new SQLiteParameter("@name", card.Name));
                    command.Parameters.Add(new SQLiteParameter("@des", card.Description));
                    var parameters = new List <SQLiteParameter>();
                    for (int i = 0; i < 16; i++)
                    {
                        parameters.Add(new SQLiteParameter("@str" + (i + 1), (i < card.EffectStrings.Length ? card.EffectStrings[i].ToString() : string.Empty)));
                    }
                    command.Parameters.AddRange(parameters.ToArray());
                    return(DatabaseHelper.ExecuteNonCommand(command));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("[Database ERROR]: {0}", ex.Message);
                    return(false);
                }
            }
 public static void UpdateOrAddCard(CardInfos card)
 {
     if (ContainsCard(card.Id))
     {
         CardData[card.Id] = card;
     }
     else
     {
         CardData.Add(card.Id, card);
     }
 }