//Create a method to view all types public List <TypeDAO> GetAllTypes() { //Create a list variable for typelist List <TypeDAO> typelist = new List <TypeDAO>(); try { //Establish the connection for the database using (SqlConnection connection = new SqlConnection(connectionstring)) { //This specifies the command object for the database using (SqlCommand command = new SqlCommand("sp_ViewTypes", connection)) { //this specifies that it is a stored procedure command.CommandType = System.Data.CommandType.StoredProcedure; //This opens the connection connection.Open(); //open the sql data reader using (SqlDataReader reader = command.ExecuteReader()) { //Loop through all the data in the set and write it to the typetolist list while (reader.Read()) { TypeDAO typeToList = new TypeDAO(); typeToList.TypeID = reader.GetInt32(0); typeToList.TypeName = reader.GetString(1); typeToList.xNormal = reader.GetDecimal(2); typeToList.xFire = reader.GetDecimal(3); typeToList.xWater = reader.GetDecimal(4); typeToList.xGrass = reader.GetDecimal(5); typeToList.xElectric = reader.GetDecimal(6); typeToList.xIce = reader.GetDecimal(7); typeToList.xFighting = reader.GetDecimal(8); typeToList.xPoision = reader.GetDecimal(9); typeToList.xGround = reader.GetDecimal(10); typeToList.xFlying = reader.GetDecimal(11); typeToList.xPsychic = reader.GetDecimal(12); typeToList.xBug = reader.GetDecimal(13); typeToList.xRock = reader.GetDecimal(14); typeToList.xGhost = reader.GetDecimal(15); typeToList.xDragon = reader.GetDecimal(16); typeToList.xDark = reader.GetDecimal(17); typeToList.xSteel = reader.GetDecimal(18); typeToList.xFairy = reader.GetDecimal(19); typelist.Add(typeToList); } } } } } catch (Exception errorCaught) { ErrorLogger errorToLog = new ErrorLogger(); errorToLog.errorlogger(errorCaught); } return(typelist); }
//Create a method to calculate the best and worst type for a team to face against public TypeDAO CalculateTypes(List <int> TypesToCalculate) { //Instantiate a new instance of the TypeCalculator object TypeCalculator Calculator = new TypeCalculator(); //Get all types in the types table and assign them to a TypeDAO List List <TypeDAO> AllDAOTypes = typeData.GetAllTypes(); //Create a new Instance of the TypeBO List List <TypeBO> AllBOTypes = new List <TypeBO>(); //Loop thorugh TypeDAO List and map each type and values into a TypeBO Value and send it to the TypeBO List foreach (TypeDAO Types in AllDAOTypes) { //Create a new instance of the TypeBO Object TypeBO BOTypes = new TypeBO(); BOTypes.TypeID = Types.TypeID; BOTypes.TypeName = Types.TypeName; BOTypes.xNormal = Types.xNormal; BOTypes.xFire = Types.xFire; BOTypes.xWater = Types.xWater; BOTypes.xGrass = Types.xGrass; BOTypes.xElectric = Types.xElectric; BOTypes.xIce = Types.xIce; BOTypes.xFighting = Types.xFighting; BOTypes.xPoision = Types.xPoision; BOTypes.xGround = Types.xGround; BOTypes.xFlying = Types.xFlying; BOTypes.xPsychic = Types.xPsychic; BOTypes.xBug = Types.xBug; BOTypes.xRock = Types.xRock; BOTypes.xGhost = Types.xGhost; BOTypes.xDragon = Types.xDragon; BOTypes.xDark = Types.xDark; BOTypes.xSteel = Types.xSteel; BOTypes.xFairy = Types.xFairy; AllBOTypes.Add(BOTypes); } //Create a new TypeBO Object List <TypeBO> TypesToEvaluate = new List <TypeBO>(); //Loop through the list of interagers passed as a parameter foreach (int chosenType in TypesToCalculate) { //Check to make sure the type is not null if (chosenType != 19) { //Loop thorugh all types in the TypeBO List foreach (TypeBO BOType in AllBOTypes) { //Search through the typeBO List until the typeID matches the given interager and add the values of that type to the TypesToEvaluate List //Repeat this until all types have been sifted through if (chosenType == BOType.TypeID) { TypeBO Types = new TypeBO(); Types.TypeID = BOType.TypeID; Types.TypeName = BOType.TypeName; Types.xNormal = BOType.xNormal; Types.xFire = BOType.xFire; Types.xWater = BOType.xWater; Types.xGrass = BOType.xGrass; Types.xElectric = BOType.xElectric; Types.xIce = BOType.xIce; Types.xFighting = BOType.xFighting; Types.xPoision = BOType.xPoision; Types.xGround = BOType.xGround; Types.xFlying = BOType.xFlying; Types.xPsychic = BOType.xPsychic; Types.xBug = BOType.xBug; Types.xRock = BOType.xRock; Types.xGhost = BOType.xGhost; Types.xDragon = BOType.xDragon; Types.xDark = BOType.xDark; Types.xSteel = BOType.xSteel; Types.xFairy = BOType.xFairy; TypesToEvaluate.Add(Types); } } } } //Send the final list of Types to the Buissness logic layer to be evaluated TypeBO FinalTypeValues = Calculator.Calculate(TypesToEvaluate); //Create a new instance of the TypeDAO Object TypeDAO FinalValues = new TypeDAO(); //Map the new calculated values from TypeBO To TypeDAO FinalValues.xNormal = FinalTypeValues.xNormal; FinalValues.xFire = FinalTypeValues.xFire; FinalValues.xWater = FinalTypeValues.xWater; FinalValues.xGrass = FinalTypeValues.xGrass; FinalValues.xElectric = FinalTypeValues.xElectric; FinalValues.xIce = FinalTypeValues.xIce; FinalValues.xFighting = FinalTypeValues.xFighting; FinalValues.xPoision = FinalTypeValues.xPoision; FinalValues.xGround = FinalTypeValues.xGround; FinalValues.xFlying = FinalTypeValues.xFlying; FinalValues.xPsychic = FinalTypeValues.xPsychic; FinalValues.xBug = FinalTypeValues.xBug; FinalValues.xRock = FinalTypeValues.xRock; FinalValues.xGhost = FinalTypeValues.xGhost; FinalValues.xDragon = FinalTypeValues.xDragon; FinalValues.xDark = FinalTypeValues.xDark; FinalValues.xSteel = FinalTypeValues.xSteel; FinalValues.xFairy = FinalTypeValues.xFairy; FinalValues.Max = FinalTypeValues.Max; FinalValues.Max2 = FinalTypeValues.Max2; FinalValues.MaxName = FinalTypeValues.MaxName; FinalValues.Max2Name = FinalTypeValues.Max2Name; FinalValues.Min = FinalTypeValues.Min; FinalValues.Min2 = FinalTypeValues.Min2; FinalValues.MinName = FinalTypeValues.MinName; FinalValues.Min2Name = FinalTypeValues.Min2Name; //Return the final values to the Presentation Layer return(FinalValues); }