private void MenuMember_CreateGroup_Click( object sender, EventArgs e )
        {
            var ships = GetSelectedShipID();
            if ( ships.Count() == 0 )
                return;

            using ( var dialog = new DialogTextInput( "グループの追加", "グループ名を入力してください:" ) ) {

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

                    var group = KCDatabase.Instance.ShipGroup.Add();

                    group.Name = dialog.InputtedText.Trim();

                    for ( int i = 0; i < ShipView.Columns.Count; i++ ) {
                        var newdata = new ShipGroupData.ViewColumnData( ShipView.Columns[i] );
                        if ( SelectedTab == null )
                            newdata.Visible = true;		//初期状態では全行が非表示のため
                        group.ViewColumns.Add( ShipView.Columns[i].Name, newdata );
                    }

                    // 艦船ID == 0 を作成(空リストを作る)
                    group.Expressions.Expressions.Add( new ExpressionList( false, true, false ) );
                    group.Expressions.Expressions[0].Expressions.Add( new ExpressionData( ".MasterID", ExpressionData.ExpressionOperator.Equal, 0 ) );
                    group.Expressions.Compile();

                    group.AddInclusionFilter( ships );

                    TabPanel.Controls.Add( CreateTabLabel( group.GroupID ) );

                }

            }
        }
        private void MenuGroup_Copy_Click( object sender, EventArgs e )
        {
            ImageLabel senderLabel = MenuGroup.SourceControl as ImageLabel;
            if ( senderLabel == null )
                return;		//想定外

            using ( var dialog = new DialogTextInput( "グループをコピー", "グループ名を入力してください:" ) ) {

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

                    var group = KCDatabase.Instance.ShipGroup[(int)senderLabel.Tag].Clone();

                    group.GroupID = KCDatabase.Instance.ShipGroup.GetUniqueID();
                    group.Name = dialog.InputtedText.Trim();

                    KCDatabase.Instance.ShipGroup.ShipGroups.Add( group );

                    TabPanel.Controls.Add( CreateTabLabel( group.GroupID ) );

                }
            }
        }
        private void MenuGroup_Rename_Click( object sender, EventArgs e )
        {
            ImageLabel senderLabel = MenuGroup.SourceControl as ImageLabel;
            if ( senderLabel == null ) return;

            ShipGroupData group = KCDatabase.Instance.ShipGroup[(int)senderLabel.Tag];

            if ( group != null ) {

                using ( var dialog = new DialogTextInput( "グループ名の変更", "グループ名を入力してください:" ) ) {

                    dialog.InputtedText = group.Name;

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

                        group.Name = senderLabel.Text = dialog.InputtedText.Trim();

                    }
                }

            } else {
                MessageBox.Show( "このグループの名前を変更することはできません。", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
            }
        }
        private void MenuGroup_Add_Click( object sender, EventArgs e )
        {
            using ( var dialog = new DialogTextInput( "グループを追加", "グループ名を入力してください:" ) ) {

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

                    var group = KCDatabase.Instance.ShipGroup.Add();

                    group.Name = dialog.InputtedText.Trim();

                    for ( int i = 0; i < ShipView.Columns.Count; i++ ) {
                        var newdata = new ShipGroupData.ViewColumnData( ShipView.Columns[i] );
                        if ( SelectedTab == null )
                            newdata.Visible = true;		//初期状態では全行が非表示のため
                        group.ViewColumns.Add( ShipView.Columns[i].Name, newdata );
                    }

                    TabPanel.Controls.Add( CreateTabLabel( group.GroupID ) );

                }

            }
        }
        private void MenuMember_CreateGroup_Click( object sender, EventArgs e )
        {
            using ( var dialog = new DialogTextInput( GeneralRes.CreateGroup,  GeneralRes.CreateGroupName) ) {

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

                    var group = KCDatabase.Instance.ShipGroup.Add();

                    group.Name = dialog.InputtedText.Trim();
                    foreach ( DataGridViewRow row in ShipView.SelectedRows.OfType<DataGridViewRow>().OrderBy( r => r.Tag ) ) {

                        group.Members.Add( (int)row.Cells[ShipView_ID.Index].Value );
                    }
                    group.ColumnFilter = ShipView.Columns.OfType<DataGridViewColumn>().Select( c => c.Visible ).ToList();
                    group.ColumnWidth = ShipView.Columns.OfType<DataGridViewColumn>().Select( c => c.Width ).ToList();
                    group.ColumnAutoSize = MenuMember_ColumnAutoSize.Checked;

                    ImageLabel il = CreateTabLabel( group.GroupID );
                    TabPanel.Controls.Add( il );

                    ChangeShipView( il );
                }
            }
        }
        private void MenuGroup_Rename_Click( object sender, EventArgs e )
        {
            ImageLabel senderLabel = MenuGroup.SourceControl as ImageLabel;
            if ( senderLabel == null ) return;

            ShipGroupData group = KCDatabase.Instance.ShipGroup[(int)senderLabel.Tag];

            if ( group != null && group.GroupID >= 0 ) {

                using ( var dialog = new DialogTextInput( GeneralRes.ChangeGroupName, GeneralRes.SpecifyGroupName ) ) {

                    dialog.InputtedText = group.Name;

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

                        group.Name = senderLabel.Text = dialog.InputtedText.Trim();

                    }
                }

            } else {
                MessageBox.Show( GeneralRes.CannotChangeGroupName, Properties.Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
            }
        }
        private void MenuGroup_Add_Click( object sender, EventArgs e )
        {
            using ( var dialog = new DialogTextInput( GeneralRes.AddGroup, GeneralRes.SpecifyGroupName ) ) {

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

                    var group = KCDatabase.Instance.ShipGroup.Add();

                    group.Name = dialog.InputtedText.Trim();
                    group.ColumnFilter = ShipView.Columns.OfType<DataGridViewColumn>().Select( c => c.Visible ).ToList();
                    if ( group.ColumnFilter.All( f => !f ) )
                        group.ColumnFilter = Enumerable.Repeat<bool>( true, ShipView.Columns.Count ).ToList();
                    group.ColumnWidth = ShipView.Columns.OfType<DataGridViewColumn>().Select( c => c.Width ).ToList();
                    group.ColumnAutoSize = MenuMember_ColumnAutoSize.Checked;

                    TabPanel.Controls.Add( CreateTabLabel( group.GroupID ) );

                }

            }
        }
        private void MenuMember_CreateFromSelection_Click( object sender, EventArgs e )
        {
            if ( ShipView.Rows.GetRowCount( DataGridViewElementStates.Selected ) == 0 )
                return;

            using ( var dialog = new DialogTextInput( "選択範囲から固定グループを作成", "グループ名を入力してください:" ) ) {

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

                    var group = KCDatabase.Instance.ShipGroup.Add();

                    group.Name = dialog.InputtedText.Trim();

                    for ( int i = 0; i < ShipView.Columns.Count; i++ ) {
                        var newdata = new ShipGroupData.ViewColumnData( ShipView.Columns[i] );
                        if ( SelectedTab == null )
                            newdata.Visible = true;		//初期状態では全行が非表示のため
                        group.ViewColumns.Add( ShipView.Columns[i].Name, newdata );
                    }

                    group.Expressions.Expressions.Add( new ExpressionList( false, true, false ) );

                    var exp = group.Expressions.Expressions[0];
                    foreach ( int id in ShipView.SelectedRows.Cast<DataGridViewRow>().Select( r => (int)r.Cells[ShipView_ID.Index].Value ) ) {
                        exp.Expressions.Add( new ExpressionData( ".MasterID", ExpressionData.ExpressionOperator.Equal, id ) );
                    }

                    TabPanel.Controls.Add( CreateTabLabel( group.GroupID ) );

                }

            }
        }