private void MenuMember_CSVOutput_Click( object sender, EventArgs e )
        {
            IEnumerable<ShipData> ships;

            if ( SelectedTab == null ) {
                ships = KCDatabase.Instance.Ships.Values;

            } else {
                //*/
                ships = ShipView.Rows.Cast<DataGridViewRow>().Select( r => KCDatabase.Instance.Ships[(int)r.Cells[ShipView_ID.Index].Value] );
                /*/
                var group = KCDatabase.Instance.ShipGroup[(int)SelectedTab.Tag];
                if ( group == null )
                    ships = KCDatabase.Instance.Ships.Values;
                else
                    ships = group.MembersInstance;
                //*/
            }

            using ( var dialog = new DialogShipGroupCSVOutput() ) {

                if ( dialog.ShowDialog( this ) == System.Windows.Forms.DialogResult.OK ) {

                    try {

                        using ( StreamWriter sw = new StreamWriter( dialog.OutputPath, false, Utility.Configuration.Config.Log.FileEncoding ) ) {

                            string[] header = dialog.OutputFormat == DialogShipGroupCSVOutput.OutputFormatConstants.User ? ShipCSVHeaderUser : ShipCSVHeaderData;

                            sw.WriteLine( string.Join( ",", header ) );

                            string arg = string.Format( "{{{0}}}", string.Join( "},{", Enumerable.Range( 0, header.Length ) ) );

                            foreach ( ShipData ship in ships ) {

                                if ( ship == null ) continue;

                                if ( dialog.OutputFormat == DialogShipGroupCSVOutput.OutputFormatConstants.User ) {

                                    sw.WriteLine( arg,
                                        ship.MasterID,
                                        ship.MasterShip.ShipTypeName,
                                        ship.MasterShip.NameWithClass,
                                        ship.Level,
                                        ship.ExpTotal,
                                        ship.ExpNext,
                                        ship.ExpNextRemodel,
                                        ship.HPCurrent,
                                        ship.HPMax,
                                        ship.Condition,
                                        ship.Fuel,
                                        ship.Ammo,
                                        GetEquipmentString( ship, 0 ),
                                        GetEquipmentString( ship, 1 ),
                                        GetEquipmentString( ship, 2 ),
                                        GetEquipmentString( ship, 3 ),
                                        GetEquipmentString( ship, 4 ),
                                        GetEquipmentString( ship, 5 ),
                                        DateTimeHelper.ToTimeRemainString( DateTimeHelper.FromAPITimeSpan( ship.RepairTime ) ),
                                        ship.FirepowerBase,
                                        ship.FirepowerRemain,
                                        ship.FirepowerTotal,
                                        ship.TorpedoBase,
                                        ship.TorpedoRemain,
                                        ship.TorpedoTotal,
                                        ship.AABase,
                                        ship.AARemain,
                                        ship.AATotal,
                                        ship.ArmorBase,
                                        ship.ArmorRemain,
                                        ship.ArmorTotal,
                                        ship.ASWBase,
                                        ship.ASWTotal,
                                        ship.EvasionBase,
                                        ship.EvasionTotal,
                                        ship.LOSBase,
                                        ship.LOSTotal,
                                        ship.LuckBase,
                                        ship.LuckRemain,
                                        ship.LuckTotal,
                                        Constants.GetRange( ship.Range ),
                                        Constants.GetSpeed( ship.MasterShip.Speed ),
                                        ship.IsLocked ? "●" : ship.IsLockedByEquipment ? "■" : "-",
                                        ship.SallyArea,
                                        ship.AirBattlePower,
                                        ship.ShellingPower,
                                        ship.AircraftPower,
                                        ship.AntiSubmarinePower,
                                        ship.TorpedoPower,
                                        ship.NightBattlePower );

                                } else {		//data

                                    sw.WriteLine( arg,
                                        ship.MasterID,
                                        ship.MasterShip.ShipType,
                                        ship.MasterShip.NameWithClass,
                                        ship.ShipID,
                                        ship.Level,
                                        ship.ExpTotal,
                                        ship.ExpNext,
                                        ship.ExpNextRemodel,
                                        ship.HPCurrent,
                                        ship.HPMax,
                                        ship.Condition,
                                        ship.Fuel,
                                        ship.Ammo,
                                        GetEquipmentString( ship, 0 ),
                                        GetEquipmentString( ship, 1 ),
                                        GetEquipmentString( ship, 2 ),
                                        GetEquipmentString( ship, 3 ),
                                        GetEquipmentString( ship, 4 ),
                                        GetEquipmentString( ship, 5 ),
                                        ship.Slot[0],
                                        ship.Slot[1],
                                        ship.Slot[2],
                                        ship.Slot[3],
                                        ship.Slot[4],
                                        ship.ExpansionSlot,
                                        ship.Aircraft[0],
                                        ship.Aircraft[1],
                                        ship.Aircraft[2],
                                        ship.Aircraft[3],
                                        ship.Aircraft[4],
                                        ship.RepairTime,
                                        ship.RepairFuel,
                                        ship.RepairSteel,
                                        ship.FirepowerBase,
                                        ship.FirepowerRemain,
                                        ship.FirepowerTotal,
                                        ship.TorpedoBase,
                                        ship.TorpedoRemain,
                                        ship.TorpedoTotal,
                                        ship.AABase,
                                        ship.AARemain,
                                        ship.AATotal,
                                        ship.ArmorBase,
                                        ship.ArmorRemain,
                                        ship.ArmorTotal,
                                        ship.ASWBase,
                                        ship.ASWTotal,
                                        ship.EvasionBase,
                                        ship.EvasionTotal,
                                        ship.LOSBase,
                                        ship.LOSTotal,
                                        ship.LuckBase,
                                        ship.LuckRemain,
                                        ship.LuckTotal,
                                        ship.Range,
                                        ship.MasterShip.Speed,
                                        ship.IsLocked ? 1 : ship.IsLockedByEquipment ? 2 : 0,
                                        ship.SallyArea,
                                        ship.AirBattlePower,
                                        ship.ShellingPower,
                                        ship.AircraftPower,
                                        ship.AntiSubmarinePower,
                                        ship.TorpedoPower,
                                        ship.NightBattlePower );

                                }

                            }

                        }

                        Utility.Logger.Add( 2, "艦船グループ CSVを " + dialog.OutputPath + " に保存しました。" );

                    } catch ( Exception ex ) {

                        Utility.ErrorReporter.SendErrorReport( ex, "艦船グループ CSVの出力に失敗しました。" );
                        MessageBox.Show( "艦船グループ CSVの出力に失敗しました。\r\n" + ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error );

                    }

                }
            }
        }
        private void MenuMember_CSVOutput_Click( object sender, EventArgs e )
        {
            IEnumerable<ShipData> ships;
            ImageLabel senderLabel = MenuGroup.SourceControl as ImageLabel;
            if ( senderLabel == null ) {
                ships = KCDatabase.Instance.Ships.Values;

            } else {
                ShipGroupData group = KCDatabase.Instance.ShipGroup[(int)senderLabel.Tag];
                if ( group != null && group.GroupID >= 0 ) {
                    ships = group.MembersInstance;

                } else {
                    ships = KCDatabase.Instance.Ships.Values;
                }

            }

            using ( var dialog = new DialogShipGroupCSVOutput() ) {

                if ( dialog.ShowDialog( this ) == System.Windows.Forms.DialogResult.OK ) {

                    try {

                        using ( StreamWriter sw = new StreamWriter( dialog.OutputPath, false, Utility.Configuration.Config.Log.FileEncoding ) ) {

                            string[] header = dialog.OutputFormat == DialogShipGroupCSVOutput.OutputFormatConstants.User ? ShipCSVHeaderUser : ShipCSVHeaderData;

                            sw.WriteLine( string.Join( ",", header ) );

                            string arg = string.Format( "{{{0}}}", string.Join( "},{", Enumerable.Range( 0, header.Length ) ) );

                            foreach ( ShipData ship in ships ) {

                                if ( ship == null ) continue;

                                if ( dialog.OutputFormat == DialogShipGroupCSVOutput.OutputFormatConstants.User ) {

                                    sw.WriteLine( arg,
                                        ship.MasterID,
                                        ship.MasterShip.ShipTypeName,
                                        ship.MasterShip.NameWithClass,
                                        ship.Level,
                                        ship.ExpTotal,
                                        ship.ExpNext,
                                        ship.ExpNextRemodel,
                                        ship.HPCurrent,
                                        ship.HPMax,
                                        ship.Condition,
                                        ship.Fuel,
                                        ship.Ammo,
                                        GetEquipmentString( ship, 0 ),
                                        GetEquipmentString( ship, 1 ),
                                        GetEquipmentString( ship, 2 ),
                                        GetEquipmentString( ship, 3 ),
                                        GetEquipmentString( ship, 4 ),
                                        DateTimeHelper.ToTimeRemainString( DateTimeHelper.FromAPITimeSpan( ship.RepairTime ) ),
                                        ship.FirepowerBase,
                                        ship.FirepowerRemain,
                                        ship.TorpedoBase,
                                        ship.TorpedoRemain,
                                        ship.AABase,
                                        ship.AARemain,
                                        ship.ArmorBase,
                                        ship.ArmorRemain,
                                        ship.ASWBase,
                                        ship.EvasionBase,
                                        ship.LOSBase,
                                        ship.LuckBase,
                                        ship.LuckRemain,
                                        Constants.GetRange( ship.Range ),
                                        ship.IsLocked ? "❤" : "-",
                                        ship.SallyArea );

                                } else {		//data

                                    sw.WriteLine( arg,
                                        ship.MasterID,
                                        ship.MasterShip.ShipType,
                                        ship.MasterShip.NameWithClass,
                                        ship.ShipID,
                                        ship.Level,
                                        ship.ExpTotal,
                                        ship.ExpNext,
                                        ship.ExpNextRemodel,
                                        ship.HPCurrent,
                                        ship.HPMax,
                                        ship.Condition,
                                        ship.Fuel,
                                        ship.Ammo,
                                        GetEquipmentOnlyString( ship, 0 ),		//undone: IDにしたいけどよく考えたら強化値が反映されない
                                        GetEquipmentOnlyString( ship, 1 ),
                                        GetEquipmentOnlyString( ship, 2 ),
                                        GetEquipmentOnlyString( ship, 3 ),
                                        GetEquipmentOnlyString( ship, 4 ),
                                        ship.Aircraft[0],
                                        ship.Aircraft[1],
                                        ship.Aircraft[2],
                                        ship.Aircraft[3],
                                        ship.Aircraft[4],
                                        ship.RepairTime * 10000,
                                        ship.FirepowerBase,
                                        ship.FirepowerRemain,
                                        ship.TorpedoBase,
                                        ship.TorpedoRemain,
                                        ship.AABase,
                                        ship.AARemain,
                                        ship.ArmorBase,
                                        ship.ArmorRemain,
                                        ship.ASWBase,
                                        ship.EvasionBase,
                                        ship.LOSBase,
                                        ship.LuckBase,
                                        ship.LuckRemain,
                                        ship.Range,
                                        ship.IsLocked ? 1 : 0,
                                        ship.SallyArea
                                        );

                                }

                            }

                        }

                    } catch ( Exception ex ) {

                        Utility.ErrorReporter.SendErrorReport( ex, GeneralRes.FailedToCreateCSV );
                        MessageBox.Show( GeneralRes.FailedToCreateCSV + "\r\n" + ex.Message, Properties.Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error );

                    }

                }
            }
        }