private object[] CreateRow(FusionObject fo) { var returnObjectArray = new object[Enum.GetNames(typeof(MyDataGridColumns)).Length]; returnObjectArray[(int)MyDataGridColumns.colFusionObject] = fo; returnObjectArray[(int)MyDataGridColumns.colId1] = fo.Demon1.Id; returnObjectArray[(int)MyDataGridColumns.colLevel1] = fo.Demon1.Level; returnObjectArray[(int)MyDataGridColumns.colRaceObject1] = fo.Demon1.Race; returnObjectArray[(int)MyDataGridColumns.colRace1] = fo.Demon1.Race.Name; returnObjectArray[(int)MyDataGridColumns.colName1] = fo.Demon1.Name; returnObjectArray[(int)MyDataGridColumns.colId2] = fo.Demon2.Id; returnObjectArray[(int)MyDataGridColumns.colLevel2] = fo.Demon2.Level; returnObjectArray[(int)MyDataGridColumns.colRaceObject2] = fo.Demon2.Race; returnObjectArray[(int)MyDataGridColumns.colRace2] = fo.Demon2.Race.Name; returnObjectArray[(int)MyDataGridColumns.colName2] = fo.Demon2.Name; returnObjectArray[(int)MyDataGridColumns.colId3] = fo.Demon3 == null ? "" : fo.Demon3.Id.ToString(); returnObjectArray[(int)MyDataGridColumns.colLevel3] = fo.FusionIsImpossible ? "-" : fo.Demon3 == null ? "" : fo.Demon3.Level.ToString(); returnObjectArray[(int)MyDataGridColumns.colRace3] = fo.FusionIsImpossible ? "-" : fo.Demon3 == null ? "" : fo.Demon3.Race.Name; returnObjectArray[(int)MyDataGridColumns.colName3] = fo.FusionIsImpossible ? "-" : fo.Demon3 == null ? "?" : fo.Demon3.Name; // TODO maybe: // do a select * on all races of the game // create a combobox with it // assign the combo box to object array 2 // select the index of the correct race return(returnObjectArray); }
public void LoadData() { string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name; _logger.OpenSection(location); RemoveHandlers(); var game = GlobalObjects.CurrentGame; this.dgvPartyFusions.Enabled = (game != null); if (game == null) { _logger.Info("No data to load; no game is chosen."); this.dgvPartyFusions.Rows.Clear(); } else { _logger.Info("Game '" + game.Name + "' chosen; will load fusions for demons."); this.dgvPartyFusions.Rows.Clear(); var demonsForFusions = GlobalObjects.CurrentGame.Races.SelectMany(x => x.Demons). Where(y => y.UseInFusionCalculatorBoolean).ToList(); for (int i = 0; i < demonsForFusions.Count; i++) { for (int j = i + 1; j < demonsForFusions.Count; j++) { if (j < demonsForFusions.Count) { _logger.Info("First demon for fusion: " + demonsForFusions[i].ToString()); _logger.Info("Second demon for fusion: " + demonsForFusions[j].ToString()); _logger.Info("Checking if this fusion was already calculated..."); var strSql = " SELECT IdDemon3 FROM CalculatedFusions cf" + " WHERE (cf.IdDemon1 = " + demonsForFusions[i].Id + " AND cf.IdDemon2 = " + demonsForFusions[j].Id + ")" + " OR (cf.IdDemon2 = " + demonsForFusions[i].Id + " AND cf.IdDemon1 = " + demonsForFusions[j].Id + ")"; _logger.Info("Query: '" + strSql + "'"); var existingFusions = _dbSession.CreateSQLQuery(strSql) .AddScalar("IdDemon3", NHibernateUtil.Int32).List(); FusionObject oneFusionObject; if (existingFusions.Count > 0) { var DemonResult = _dbSession.Get <Domain.Demon>(Convert.ToInt32(existingFusions[0])); oneFusionObject = new FusionObject (demonsForFusions[i], demonsForFusions[j], DemonResult); } else { var oneFusion = _dbSession.CreateCriteria <Domain.Fusion>().List <Domain.Fusion>() .Where(x => (x.IdRace1 == demonsForFusions[i].Race.Id && x.IdRace2 == demonsForFusions[j].Race.Id) || (x.IdRace2 == demonsForFusions[i].Race.Id && x.IdRace1 == demonsForFusions[j].Race.Id)) .SingleOrDefault(); oneFusionObject = new FusionObject (demonsForFusions[i], demonsForFusions[j], oneFusion); if (oneFusionObject.Demon3 != null) { var strSqlUpdate = " INSERT INTO CalculatedFusions (IdDemon1, IdDemon2, IdDemon3)" + " VALUES (" + oneFusionObject.Demon1.Id + ", " + oneFusionObject.Demon2.Id + ", " + oneFusionObject.Demon3.Id + ")"; _dbSession.CreateSQLQuery(strSqlUpdate).ExecuteUpdate(); } } this.dgvPartyFusions.Rows.Add(this.CreateRow(oneFusionObject)); var formattedRow = this.dgvPartyFusions.Rows[this.dgvPartyFusions.Rows.Count - 1]; ChangeCellColorsBasedOnParty(oneFusionObject.Demon1, new DataGridViewCell[] { formattedRow.Cells[(int)MyDataGridColumns.colLevel1], formattedRow.Cells[(int)MyDataGridColumns.colRace1], formattedRow.Cells[(int)MyDataGridColumns.colName1] }); ChangeCellColorsBasedOnParty(oneFusionObject.Demon2, new DataGridViewCell[] { formattedRow.Cells[(int)MyDataGridColumns.colLevel2], formattedRow.Cells[(int)MyDataGridColumns.colRace2], formattedRow.Cells[(int)MyDataGridColumns.colName2] }); ChangeCellColorsBasedOnParty(oneFusionObject.Demon3, new DataGridViewCell[] { formattedRow.Cells[(int)MyDataGridColumns.colLevel3], formattedRow.Cells[(int)MyDataGridColumns.colRace3], formattedRow.Cells[(int)MyDataGridColumns.colName3] }); } } } ReorderTable(); } this.dgvPartyFusions.ClearSelection(); _logger.Info("Adding complete."); AddHandlers(); _logger.CloseSection(location); }