示例#1
0
    public static void SavePlayerData(string name, string pass, bool isUpdate = false)
    {
        DateTime   dateNow = DateTime.UtcNow;
        PlayerData data    = new PlayerData();

        data.Store(name, pass, dateNow);
        players.Add(data);

        var db          = "GoC.sqlite";
        var playerSaver = new DataSaver().DataBase(db);

        var command1 = "PlayersData (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,Name TEXT NOT NULL,Password TEXT NOT NULL, `Date` TEXT NOT NULL, `LatestDate` TEXT,Kingdom TEXT, Score INTEGER DEFAULT 0);";
        var command2 = String.Format("PlayersData (Name, Password, Date, LatestDate, Kingdom) VALUES ('{0}', '{1}', '{2}', '{3}', 'Default');", data.Name, data.Password, data.playDate.ToString(), data.playDate.ToString());

        if (isUpdate)
        {
            command2 = String.Format("PlayersData SET LatestDate = '{0}' WHERE Name='{1}';", DateTime.UtcNow.ToString(), name);
        }

        playerSaver.Open();
        playerSaver.CreateTable(command1);
        if (isUpdate)
        {
            playerSaver.Update(command2);
        }
        else
        {
            playerSaver.Insert(command2);
        }
        playerSaver.Close();
    }