public string Delete(NPCFlockData data) { string query = ""; using (SqlCommand command = new SqlCommand()) { StringBuilder sqlCommand = new StringBuilder(); sqlCommand.Append(@"" + data.GetLookupStatement() + "\nDELETE FROM [dbo].[npcflock] WHERE @flockID=id;"); command.CommandText = sqlCommand.ToString(); SqlConnection conn = new SqlConnection(this.ConnString); command.Parameters.AddWithValue("@flockID", data.id); conn.Open(); command.Connection = conn; command.ExecuteNonQuery(); conn.Close(); query = command.CommandText; foreach (SqlParameter p in command.Parameters) { if (p.ParameterName != "@flockID") { if (SqlDbType.NVarChar.Equals(p.SqlDbType) || SqlDbType.VarChar.Equals(p.SqlDbType)) { query = query.Replace(p.ParameterName, "'" + p.Value.ToString() + "'"); } else { query = query.Replace(p.ParameterName, p.Value.ToString()); } } } } return(query); }
public NPCFlockData copy() { NPCFlockData d = new NPCFlockData(); d.id = this.id; d.behaviorType = this.behaviorType; d.dBAction = this.dBAction; d.definition = this.definition; d.enabled = this.enabled; d.flockmembercount = this.flockmembercount; d.homerange = this.homerange; d.iscallforhelp = this.iscallforhelp; d.name = this.name; d.note = this.note; d.NPCDefinitionName = this.NPCDefinitionName; d.presenceid = this.presenceid; d.respawnmultiplierlow = this.respawnmultiplierlow; d.respawnseconds = this.respawnseconds; d.spawnoriginX = this.spawnoriginX; d.spawnoriginY = this.spawnoriginY; d.spawnrangeMax = this.spawnrangeMax; d.spawnrangeMin = this.spawnrangeMin; d.totalspawncount = this.totalspawncount; return(d); }
public string Save(NPCFlockData item) { string query = ""; using (SqlCommand command = new SqlCommand()) { StringBuilder sqlCommand = new StringBuilder(); sqlCommand.Append(@"UPDATE [dbo].[npcflock] SET [name] = @name ,[presenceid] = @presenceID, [flockmembercount] = @flockmembercount, [definition] = @definitionID, [spawnoriginX] = @spawnoriginX, [spawnoriginY] = @spawnoriginY ,[spawnrangeMin] = @spawnrangeMin, [spawnrangeMax] = @spawnrangeMax,[respawnseconds] = @respawnseconds, [totalspawncount] = @totalspawncount, [homerange] = @homerange ,[note] = @note, [respawnmultiplierlow] = @respawnmultiplierlow, [enabled] = @enabled, [iscallforhelp] = @iscallforhelp, [behaviorType] = @behaviorType WHERE id=@id;"); command.CommandText = sqlCommand.ToString(); command.Parameters.AddWithValue("@id", item.id); command.Parameters.AddWithValue("@name", item.name); command.Parameters.AddWithValue("@presenceID", item.presenceid); command.Parameters.AddWithValue("@flockmembercount", item.flockmembercount); command.Parameters.AddWithValue("@definitionID", item.definition); command.Parameters.AddWithValue("@spawnoriginX", item.spawnoriginX); command.Parameters.AddWithValue("@spawnoriginY", item.spawnoriginY); command.Parameters.AddWithValue("@spawnrangeMin", item.spawnrangeMin); command.Parameters.AddWithValue("@spawnrangeMax", item.spawnrangeMax); command.Parameters.AddWithValue("@respawnseconds", item.respawnseconds); command.Parameters.AddWithValue("@respawnmultiplierlow", item.respawnmultiplierlow); command.Parameters.AddWithValue("@totalspawncount", item.totalspawncount); command.Parameters.AddWithValue("@homerange", item.homerange); command.Parameters.AddWithValue("@note", item.note); command.Parameters.AddWithValue("@enabled", item.enabled); command.Parameters.AddWithValue("@iscallforhelp", item.iscallforhelp); command.Parameters.AddWithValue("@behaviorType", item.behaviorType); SqlConnection conn = new SqlConnection(this.ConnString); conn.Open(); command.Connection = conn; command.ExecuteNonQuery(); conn.Close(); query = command.CommandText; foreach (SqlParameter p in command.Parameters) { if (p.ParameterName != "@presenceID" && p.ParameterName != "@definitionID") { if (SqlDbType.NVarChar.Equals(p.SqlDbType) || SqlDbType.VarChar.Equals(p.SqlDbType)) { query = query.Replace(p.ParameterName, "'" + p.Value.ToString() + "'"); } else { query = query.Replace(p.ParameterName, p.Value.ToString()); } } } } return(query); }
public List <NPCFlockData> getByPresenceID(int presID) { List <NPCFlockData> list = new List <NPCFlockData>(); using (SqlConnection conn = new SqlConnection(this.ConnString)) { using (SqlCommand command = new SqlCommand()) { StringBuilder sqlCommand = new StringBuilder(); sqlCommand.Append(@"SELECT entitydefaults.definitionname, npcflock.* FROM npcflock JOIN entitydefaults on entitydefaults.definition=npcflock.definition WHERE presenceid=@id;"); command.Parameters.AddWithValue("@id", presID); command.CommandText = sqlCommand.ToString(); command.Connection = conn; conn.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { NPCFlockData flock = new NPCFlockData(); flock.behaviorType = Convert.ToInt32(reader["behaviorType"]); flock.definition = Convert.ToInt32(reader["definition"]); flock.enabled = Convert.ToInt32(reader["enabled"]); flock.flockmembercount = Convert.ToInt32(reader["flockmembercount"]); flock.homerange = Convert.ToInt32(reader["homerange"]); flock.id = Convert.ToInt32(reader["id"]); flock.iscallforhelp = Convert.ToInt32(reader["iscallforhelp"]); flock.name = Convert.ToString(reader["name"]); flock.note = Convert.ToString(reader["note"]); flock.presenceid = Convert.ToInt32(reader["presenceid"]); flock.respawnmultiplierlow = Convert.ToInt32(reader["respawnmultiplierlow"]); flock.respawnseconds = Convert.ToInt32(reader["respawnseconds"]); flock.spawnoriginX = Convert.ToInt32(reader["spawnoriginX"]); flock.spawnoriginY = Convert.ToInt32(reader["spawnoriginY"]); flock.spawnrangeMax = Convert.ToInt32(reader["spawnrangeMax"]); flock.spawnrangeMin = Convert.ToInt32(reader["spawnrangeMin"]); flock.totalspawncount = Convert.ToInt32(reader["totalspawncount"]); flock.NPCDefinitionName = Convert.ToString(reader["definitionname"]); flock.dBAction = DBAction.UPDATE; list.Add(flock); } } } } return(list); }