Пример #1
0
        public void LoadData()
        {
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);

            RemoveHandlers();

            var game = GlobalObjects.CurrentGame;

            this.dgvDemons.Enabled = (game != null);
            if (game == null)
            {
                _logger.Info("No data to load; no game is chosen.");
                this.dgvDemons.Rows.Clear();
            }
            else
            {
                _logger.Info("Game '" + game.Name + "' chosen; will load list of demons.");
                var allDemons = GlobalObjects.CurrentGame.Races.SelectMany(x => x.Demons).
                                OrderBy(y => y.Level).ThenBy(z => z.Race.Id).ToList();
                foreach (Domain.Demon d in allDemons)
                {
                    _logger.Info("Loaded this demon: " + d.ToString());
                    this.dgvDemons.Rows.Add(CreateRow(d));
                }
                _logger.Info("Data load complete. Adding event handlers...");
                AddHandlers();
                _logger.Info("Adding complete.");
            }
            _logger.CloseSection(location);
        }
Пример #2
0
        private void SetImpossibleToFuseRace()
        {
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);
            GlobalObjects.ImpossibleToFuseRace = _dbSession.Get <Domain.Race>(0);
            _logger.CloseSection(location);
        }
Пример #3
0
 private static ISession CreateDbSession()
 {
     try
     {
         string location = new StackFrame().GetMethod().DeclaringType.ToString();
         _logger.OpenSection(location);
         var returnDb = NHibernateHelper.GetCurrentSession();
         _logger.CloseSection(location);
         return(returnDb);
     }
     catch (Exception ex)
     {
         _logger.Error(ex);
         throw;
     }
 }
Пример #4
0
        private Domain.Word GetOneWord(Domain.Word currentWord)
        {
            _location = this.GetType().Name + "." + MethodBase.GetCurrentMethod().Name;
            _logger.OpenSection(_location);

            Domain.Word returnedWord;

            do
            {
                var maxId = Math.Min((int)_numberOfCurrentWords / 2, _wordsToStudy.Count - 1);
                wordIndex    = new Random().Next(0, maxId);
                returnedWord = _wordsToStudy[wordIndex];
            }while (currentWord != null && currentWord.Id == returnedWord.Id);

            // TODO better logging
            _logger.CloseSection(_location);
            return(returnedWord);
        }
Пример #5
0
        public void LoadData()
        {
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);

            RemoveHandlers();

            var game = GlobalObjects.CurrentGame;

            this.dgvDemons.Enabled = (game != null);
            if (game == null)
            {
                _logger.Info("No data to load; no game is chosen.");
                this.dgvDemons.Rows.Clear();
            }
            else
            {
                _logger.Info("Game '" + game.Name + "' chosen; will load list of demons for use in fusion calculator.");
                var allDemons =
                    GlobalObjects.CurrentGame.Races
                    .SelectMany(x => x.Demons)
                    .Where(y => y.UseInFusionCalculator > 0)
                    .OrderBy(y => y.Level).ThenBy(z => z.Race.Id)
                    .ToList();
                _maxDemonId = allDemons.Select(x => x.Id).Max().GetValueOrDefault();
                foreach (Domain.Demon d in allDemons)
                {
                    _logger.Info("Loaded this demon: " + d.ToString());
                    this.dgvDemons.Rows.Add(CreateRow(d));
                }
                _logger.Info("Data load complete. Adding event handlers...");
                AddHandlers();
                SetDataGridViewReadOnlyPropertyAndColors();
                _logger.Info("Adding complete.");
            }

            _logger.CloseSection(location);
        }
Пример #6
0
        public FullDemonsListForm()
        {
            _logger = GlobalObjects.Logger;
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);
            _dbSession = GlobalObjects.DbSession;
            _logger.Info("Initializing component...");
            InitializeComponent();

            InitializeColumnsAndStuff();

            _logger.CloseSection(location);
        }
Пример #7
0
        public FusionObject(Domain.Demon d1, Domain.Demon d2, Domain.Demon d3)
        {
            _logger = GlobalObjects.Logger;
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);
            _dbSession = GlobalObjects.DbSession;

            Demon1 = (d1.Level <= d2.Level ? d1 : d2);
            Demon2 = (d1.Level <= d2.Level ? d2 : d1);
            Demon3 = d3;

            _logger.CloseSection(location);
        }
Пример #8
0
        public ChooseGame()
        {
            _logger = GlobalObjects.Logger;
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);
            _dbSession = GlobalObjects.DbSession;
            _logger.Info("Initializing component...");
            InitializeComponent();

            exitWasChosen = false;

            PopulateGamesComboBox();
        }
Пример #9
0
        public ChooseGameForm()
        {
            _logger = GlobalObjects.Logger;
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);
            _dbSession = GlobalObjects.DbSession;
            _logger.Info("Initializing component...");
            InitializeComponent();

            PopulateGamesComboBox();

            SetImpossibleToFuseRace();

            _logger.CloseSection(location);
        }
Пример #10
0
        public bool ImportFile(string databasePath, string filePath)
        {
            string location = this.GetType().Name + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);

            var allText = File.ReadAllText(filePath);

            try
            {
                using (var dbConnection = new SQLiteConnection("Data Source = " + databasePath))
                {
                    dbConnection.Open();
                    using (var dbSession = NHibernateHelper.GetCustomSession(dbConnection))
                    {
                        var allLines = allText.Replace("\r\n", "\r").Split('\r');
                        ParseAllLines(allLines);

                        using (var transaction = dbSession.BeginTransaction())
                        {
                            foreach (var oneSource in SourcesToInsert)
                            {
                                _logger.Info("Saving source in database '" + oneSource.Text + "'...");
                                dbSession.Save(oneSource);
                                _logger.Info("Saved.");
                            }
                            transaction.Commit();
                        }
                        dbSession.Close();
                    }
                    dbConnection.Close();
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                _logger.CloseSection(location);
                return(false);
            }

            _logger.CloseSection(location);
            return(true);
        }
Пример #11
0
        private void PopulateGamesComboBox()
        {
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);

            var games = _dbSession.CreateCriteria <Domain.Game>().List <Domain.Game>();

            if (games.Count == 0)
            {
                this.cbGame.Items.Add(new FeatherItem("(No games in database)", null));
            }
            else
            {
                games.ToList().ForEach(x => this.cbGame.Items.Add(new FeatherItem(x.Name, x)));
            }
            this.cbGame.SelectedIndex = 0;

            _logger.CloseSection(location);
        }
Пример #12
0
        public JapaneseStudyForm(string databasePath)
        {
            _logger = GlobalObjects.Logger;

            _location = this.GetType().Name + "." + MethodBase.GetCurrentMethod().Name;
            _logger.OpenSection(_location);

            _logger.Info("Creating new DB connection");
            _dbConnection = new SQLiteConnection("Data Source = " + databasePath);
            _logger.Info("Connection created");

            InitializeComponent();
            LoadAllWords();
            UpdateLabelsOneTimeOnly();

            CreateRightClickMenus();

            _numberOfCurrentWords = Math.Min(_numberOfTotalWords, STARTING_NUMBER_OF_WORDS_LOADED);

            NextStep();
        }
Пример #13
0
        public FusionsChartForm()
        {
            _logger = GlobalObjects.Logger;
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);
            _dbSession = GlobalObjects.DbSession;
            _logger.Info("Initializing component...");
            InitializeComponent();

            this.dgvFusions.AutoSizeRowsMode                     = DataGridViewAutoSizeRowsMode.None;
            this.dgvFusions.AllowUserToResizeRows                =
                this.dgvFusions.AllowUserToResizeColumns         =
                    this.dgvFusions.AllowUserToAddRows           =
                        this.dgvFusions.AllowUserToDeleteRows    =
                            this.dgvFusions.ColumnHeadersVisible = false;
            this.dgvFusions.RowTemplate.Height                   = 35;
            this.dgvFusions.RowTemplate.MinimumHeight            = 35;

            LoadData();

            _logger.CloseSection(location);
        }
Пример #14
0
        public MainForm()
        {
            _logger = GlobalObjects.Logger;
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);
            _dbSession = GlobalObjects.DbSession;
            _logger.Info("Initializing component...");
            InitializeComponent();

            GlobalObjects.MainForm    = this;
            GlobalObjects.CurrentGame = null;

            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;

            // ShowPartyDemonsForm();
            ShowFusionsChartForm();
            ShowFullDemonsListForm();
            ShowPartyFusionsForm();

            ShowChooseGameForm();

            _logger.CloseSection(location);
        }
Пример #15
0
        public void ChooseGame(Domain.Game game)
        {
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);
            _logger.Info("Called with game = " + (game == null ? "(null)" : game.Name));

            if (game == GlobalObjects.CurrentGame)
            {
                _logger.Info("Game is same as current game, nothing to do.");
            }
            else
            {
                GlobalObjects.CurrentGame = game;

                string text = FORM_NAME + (game == null ? "" : " - " + game.Name);
                _logger.Info("Setting form text to '" + text + "'");
                this.Text = text;

                if (_fullDemonsListForm != null)
                {
                    _fullDemonsListForm.LoadData();
                }
                if (_partyDemonsListForm != null)
                {
                    _partyDemonsListForm.LoadData();
                }
                if (_fusionsForm != null)
                {
                    _fusionsForm.LoadData();
                }
                if (_partyFusionsVerticalForm != null)
                {
                    _partyFusionsVerticalForm.LoadData();
                }
            }

            _logger.CloseSection(location);
        }
Пример #16
0
        private void dgvDemons_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);

            _logger.Info("Called with row index " + e.RowIndex + ", column index = " + e.ColumnIndex);
            var currentRow = this.dgvDemons.Rows[e.RowIndex];

            int numberOfNonNullColumns =
                (currentRow.Cells[DGV_DEMON_COL_LEVEL].Value == null ? 0 : 1) +
                (currentRow.Cells[DGV_DEMON_COL_RACE].Value == null ? 0 : 1) +
                (currentRow.Cells[DGV_DEMON_COL_NAME].Value == null ? 0 : 1);

            var oldValue = currentRow.Cells[e.ColumnIndex].Value;

            if (oldValue != null)
            {
                oldValue = oldValue.ToString();
            }
            var newValue = e.FormattedValue;

            if (newValue != null)
            {
                newValue = newValue.ToString();
            }
            _logger.Info("oldValue = " + (oldValue == null ? "(null)" : "'" + oldValue.ToString() + "'"));
            _logger.Info("newValue = " + (newValue == null ? "(null)" : "'" + newValue.ToString() + "'"));

            _logger.Info("numberOfNonNullColumns = " + numberOfNonNullColumns);

            _cellDemonChanged = (numberOfNonNullColumns >= 2 && oldValue != newValue);

            _logger.Info("Cell changed set to " + _cellDemonChanged);
            _logger.CloseSection(location);
        }
Пример #17
0
        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);
        }
Пример #18
0
        public void LoadData()
        {
            string location = this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name;

            _logger.OpenSection(location);

            RemoveHandlers();

            var game = GlobalObjects.CurrentGame;

            this.dgvFusions.Enabled = (game != null);
            if (game == null)
            {
                _logger.Info("No data to load; no game is chosen.");
                this.dgvFusions.Rows.Clear();
            }
            else
            {
                _logger.Info("Game '" + game.Name + "' chosen; will load list of fusions.");

                var currentGameRaces   = game.Races.ToList();
                var currentGameRaceIds = currentGameRaces.Select(x => x.Id).ToList();
                var allFusions         =
                    _dbSession.CreateCriteria <Domain.Fusion>().List <Domain.Fusion>()
                    .Where(x => currentGameRaceIds.Contains(x.IdRace1))
                    .OrderBy(y => y.IdRace1)
                    .ThenBy(z => z.IdRace2).ToList();

                AddOneColumn(null);
                foreach (var oneRace in currentGameRaces)
                {
                    AddOneColumn(oneRace);
                }

                // first row
                object[] oneRow = new object[currentGameRaces.Count + 1];
                oneRow[0] = " ";
                for (int i = 0; i < currentGameRaces.Count; i++)
                {
                    oneRow[i + 1] = currentGameRaces[i].Name;
                }

                // race tag on every cell of the first row except the first one
                this.dgvFusions.Rows.Add(oneRow);
                for (int i = 0; i < currentGameRaces.Count; i++)
                {
                    this.dgvFusions.Rows[0].Cells[i + 1].Tag = currentGameRaces[i];
                }

                // following rows
                DataGridViewRow oneDgvr;
                foreach (var oneRace in currentGameRaces)
                {
                    oneDgvr = new DataGridViewRow();
                    oneDgvr.Cells.Add(new DataGridViewTextBoxCell()
                    {
                        Value = oneRace.Name,
                        Tag   = oneRace
                    });
                    foreach (var anotherRace in currentGameRaces)
                    {
                        int?idRaceResult =
                            allFusions.Where(x =>
                                             x.IdRace1 == oneRace.Id &&
                                             x.IdRace2 == anotherRace.Id)
                            .Select(y => y.IdRace3).FirstOrDefault();
                        if (idRaceResult == null)
                        {
                            idRaceResult =
                                allFusions.Where(x =>
                                                 x.IdRace2 == oneRace.Id &&
                                                 x.IdRace1 == anotherRace.Id)
                                .Select(y => y.IdRace3).FirstOrDefault();
                        }
                        Domain.Race raceResult =
                            (idRaceResult == null ? null :
                             _dbSession.Get <Domain.Race>(idRaceResult.GetValueOrDefault()));

                        oneDgvr.Cells.Add(new DataGridViewTextBoxCell()
                        {
                            Value = (raceResult == null ? null : raceResult.Name),
                            Tag   = raceResult
                        });
                    }
                    this.dgvFusions.Rows.Add(oneDgvr);
                }

                foreach (DataGridViewCell oneCell in this.dgvFusions.Rows[0].Cells)
                {
                    oneCell.ReadOnly = true;
                    oneCell.Style    = GlobalObjects.GetDefaultDgvcStyle(FONT_SIZE, false);
                }

                foreach (DataGridViewRow aRow in this.dgvFusions.Rows)
                {
                    aRow.Cells[0].ReadOnly = true;
                    aRow.Cells[0].Style    = GlobalObjects.GetDefaultDgvcStyle(FONT_SIZE, false);
                }

                AddHandlers();
                _logger.Info("Adding complete.");

                SetFormats();
            }
            _logger.CloseSection(location);
        }