Exemplo n.º 1
0
        private void ExportButton_Click(object sender, EventArgs e)
        {
            var fileName = GetSelectedSavedGame();
            var filePath = BuildSavedGameFilePath(fileName);

            using (var savedGameConnection = new SavedGameConnection(filePath))
            {
                // Export to file
                var teams = TeamsDataGridView.DataSource as TeamCollection;
                if (teams == null)
                {
                    MessageBox.Show("Please import data from a saved game file first before attempting to export.",
                                    Settings.Default.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                foreach (var team in teams)
                {
                    var valueMapping = new Data.ValueMapping.SavedGame.Team.Team(team.Id);
                    savedGameConnection.WriteInteger(valueMapping.Department1Motivation, team.Department1Motivation);
                    savedGameConnection.WriteInteger(valueMapping.Department1Happiness, team.Department1Happiness);
                    savedGameConnection.WriteInteger(valueMapping.Department2Motivation, team.Department2Motivation);
                    savedGameConnection.WriteInteger(valueMapping.Department2Happiness, team.Department2Happiness);
                    savedGameConnection.WriteInteger(valueMapping.Department3Motivation, team.Department3Motivation);
                    savedGameConnection.WriteInteger(valueMapping.Department3Happiness, team.Department3Happiness);
                    savedGameConnection.WriteInteger(valueMapping.Department4Motivation, team.Department4Motivation);
                    savedGameConnection.WriteInteger(valueMapping.Department4Happiness, team.Department4Happiness);
                    savedGameConnection.WriteInteger(valueMapping.Department5Motivation, team.Department5Motivation);
                    savedGameConnection.WriteInteger(valueMapping.Department5Happiness, team.Department5Happiness);
                }

                MessageBox.Show("Export complete!");
            }
        }