コード例 #1
0
    private void LoadRigInner(SqlDataReader r)
    {
        Id       = Convert.ToInt32(r["id"]);
        PlayerId = Convert.ToInt32(r["player_id"]);
        Tag      = Convert.ToString(r["tag"]);
        int ShipModelId = Convert.ToInt32(r["ship_model_id"]);

        sModel = ShipModel.ModelById(ShipModelId);
        if ((int)r["ship_id"] > 0)
        {
            this.Ship = Ship.GetShipById((int)r["ship_id"]);
        }


        if (r["rig_code"] == DBNull.Value)
        {
            RigCode = Guid.NewGuid();
            string q = $@"UPDATE ss_rigs SET rig_code = CAST('{RigCode.ToString()}' AS uniqueidentifier) WHERE id = {Id}";
            DataConnection.Execute(q);
        }
        else
        {
            RigCode = (Guid)r["rig_code"];
        }

        ForBattleId = (int)r["for_battle_id"];

        LoadSlots();
    }
コード例 #2
0
    public string SaveData(int playerId, string tag)
    {
        if (playerId > 0)
        {
            SpaceshipRig rigByGuid = RigByGuid(this.RigCode);
            if (rigByGuid != null)
            {
                if (rigByGuid.PlayerId != playerId)
                {
                    return("Wrong guid");
                }
                Id = rigByGuid.Id;
            }
        }


        string        q;
        List <string> names = new List <string> {
            tag
        };
        int shipId = 0;

        if (Ship != null)
        {
            Ship baseShip = Ship.GetShipByGuid(Ship.ShipCode);
            if (baseShip == null)
            {
                return("ship can't be found");
            }
            if (baseShip.PlayerId != playerId)
            {
                return("Error ship ownership");
            }
            Ship   = baseShip;
            shipId = Ship.Id;
        }

        if (Id == 0)
        {
            if (RigCode == Guid.Empty)
            {
                RigCode = Guid.NewGuid();
            }
            q  = $@"
                INSERT INTO ss_rigs(ship_model_id, ship_id, player_id, tag, rig_code, for_battle_id) 
                             VALUES({sModel.Id}, {shipId}, {playerId}, @str1, CAST('{RigCode.ToString()}' AS uniqueidentifier), {ForBattleId})
                SELECT @@IDENTITY AS Result";
            Id = DataConnection.GetResultInt(q, names);
        }
        else
        {
            q = $@"
                UPDATE ss_rigs SET
                    ship_model_id = {sModel.Id},
                    ship_id = {shipId},
                    player_id = {playerId},
                    tag = @str1,
                    for_battle_id = {ForBattleId}
                WHERE
                    id = {Id}";
            DataConnection.Execute(q, names);
        }

        string idsDoNotDelete = "";

        if (Slots.Count > 0)
        {
            foreach (RigSlot slot in Slots)
            {
                slot.SaveData(Id);
                if (idsDoNotDelete != "")
                {
                    idsDoNotDelete += ",";
                }
                idsDoNotDelete += slot.Id;
            }
        }

        q = $"DELETE FROM ss_rigs_slots WHERE ss_rig_id = {Id} ";
        if (idsDoNotDelete != "")
        {
            q += " AND id NOT IN (" + idsDoNotDelete + ")";
        }
        DataConnection.Execute(q);

        UpdateRigDict(this);

        if (Ship != null)
        {
            Ship.RigId = Id;
            Ship.Save();
        }

        return("");
    }