public static void addFloor(FloorType floor) { string stmt = "INSERT INTO Cost (tid, source, amt) VALUES ($1, 'Purchased Floor for', $2)"; IDbConnection connection = Queries.connect(Queries.dbURL); IDbCommand command = connection.CreateCommand(); command.CommandText = stmt; int type = floor.getType(); string name = FloorType.floorMap[type]; command = Queries.addParam(command, DbType.Int32, "1", tid); //command = Queries.addParam (command, DbType.String, "2", name); command = Queries.addParam(command, DbType.Int32, "2", floor.getCost()); command.ExecuteNonQuery(); command.Dispose(); connection.Close(); revenuePerPeriod += floor.revenues(); expense += floor.getCost(); tid++; }
public static void addClient(FloorType client) { string stmt = "INSERT INTO Cost (tid, srcType, amt) VALUES ($1, Added worker to $2 Floor, $3)"; IDbConnection connection = Queries.connect(Queries.dbURL); IDbCommand command = connection.CreateCommand(); command.CommandText = stmt; command = Queries.addParam(command, DbType.Int32, "1", tid); command = Queries.addParam(command, DbType.AnsiString, "2", client.getType()); command = Queries.addParam(command, DbType.Int32, "3", client.getCost()); command.ExecuteNonQuery(); command.Dispose(); connection.Close(); tid++; }
/** * Adds new floor to hotel. */ public void addFloor(FloorType floor) { int arcadeNum = 0; int restaurantNum = 0; int suiteNum = 0; IDbConnection connection2 = Queries.connect(Queries.dbURL); IDbCommand command2 = connection2.CreateCommand(); command2.CommandText = "SELECT SUM(amt) FROM Income"; command2.ExecuteNonQuery(); IDataReader reader = command2.ExecuteReader(); int sum = 0; while (reader.Read()) { if (!reader.IsDBNull(0)) { sum = reader.GetInt32(0); } } command2.Dispose(); command2 = null; connection2.Close(); if (sum < floor.getCost()) { new MobileNativeMessage("Insufficient funds", "Expand your hotel to make more money"); return; } foreach (FloorType f in floors) { if (f.getType() == 0) { arcadeNum++; } else if (f.getType() == 1) { restaurantNum++; } else if (f.getType() == 2) { suiteNum++; } } if (floor.getType() == 0 && arcadeNum == 0) { floors.Add(floor); Queries.addFloor(fid, floor.getType(), FinanceMgr.tid, floor.getCost()); FinanceMgr.addFloor(floor); fid++; new MobileNativeMessage("Floor Added", "Arcade floor added."); } else if (floor.getType() == 1 && restaurantNum == 0) { floors.Add(floor); Queries.addFloor(fid, floor.getType(), FinanceMgr.tid, floor.getCost()); FinanceMgr.addFloor(floor); fid++; new MobileNativeMessage("Floor Added", "Restaurant floor added."); } else if (floor.getType() == 2 && suiteNum < 2) { floors.Add(floor); Queries.addFloor(fid, floor.getType(), FinanceMgr.tid, floor.getCost()); FinanceMgr.addFloor(floor); fid++; new MobileNativeMessage("Floor Added", "Suite floor added."); } else { new MobileNativeMessage("Excessive Number of Floors", "The floor was not added as the number of floors is already at maximum capacity."); } }