public DialogShipGroupFilter( ExpressionManager exp )
        {
            InitializeComponent();

            #region init DataTable
            {
                _dtAndOr = new DataTable();
                _dtAndOr.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( bool ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                _dtAndOr.Rows.Add( true, "And" );
                _dtAndOr.Rows.Add( false, "Or" );
                _dtAndOr.AcceptChanges();

                ExpressionView_InternalAndOr.ValueMember = "Value";
                ExpressionView_InternalAndOr.DisplayMember = "Display";
                ExpressionView_InternalAndOr.DataSource = _dtAndOr;

                ExpressionView_ExternalAndOr.ValueMember = "Value";
                ExpressionView_ExternalAndOr.DisplayMember = "Display";
                ExpressionView_ExternalAndOr.DataSource = _dtAndOr;
            }
            {
                _dtLeftOperand = new DataTable();
                _dtLeftOperand.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( string ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                foreach ( var lont in ExpressionData.LeftOperandNameTable )
                    _dtLeftOperand.Rows.Add( lont.Key, lont.Value );
                _dtLeftOperand.AcceptChanges();

                LeftOperand.ValueMember = "Value";
                LeftOperand.DisplayMember = "Display";
                LeftOperand.DataSource = _dtLeftOperand;
            }
            {
                _dtOperator = new DataTable();
                _dtOperator.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( ExpressionData.ExpressionOperator ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                foreach ( var ont in ExpressionData.OperatorNameTable )
                    _dtOperator.Rows.Add( ont.Key, ont.Value );
                _dtOperator.AcceptChanges();

                Operator.ValueMember = "Value";
                Operator.DisplayMember = "Display";
                Operator.DataSource = _dtOperator;
            }
            {
                _dtOperator_bool = new DataTable();
                _dtOperator_bool.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( ExpressionData.ExpressionOperator ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                _dtOperator_bool.Rows.Add( ExpressionData.ExpressionOperator.Equal, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.Equal] );
                _dtOperator_bool.Rows.Add( ExpressionData.ExpressionOperator.NotEqual, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.NotEqual] );
                _dtOperator_bool.AcceptChanges();
            }
            {
                _dtOperator_number = new DataTable();
                _dtOperator_number.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( ExpressionData.ExpressionOperator ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                _dtOperator_number.Rows.Add( ExpressionData.ExpressionOperator.Equal, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.Equal] );
                _dtOperator_number.Rows.Add( ExpressionData.ExpressionOperator.NotEqual, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.NotEqual] );
                _dtOperator_number.Rows.Add( ExpressionData.ExpressionOperator.LessThan, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.LessThan] );
                _dtOperator_number.Rows.Add( ExpressionData.ExpressionOperator.LessEqual, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.LessEqual] );
                _dtOperator_number.Rows.Add( ExpressionData.ExpressionOperator.GreaterThan, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.GreaterThan] );
                _dtOperator_number.Rows.Add( ExpressionData.ExpressionOperator.GreaterEqual, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.GreaterEqual] );
                _dtOperator_number.AcceptChanges();
            }
            {
                _dtOperator_string = new DataTable();
                _dtOperator_string.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( ExpressionData.ExpressionOperator ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                _dtOperator_string.Rows.Add( ExpressionData.ExpressionOperator.Equal, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.Equal] );
                _dtOperator_string.Rows.Add( ExpressionData.ExpressionOperator.NotEqual, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.NotEqual] );
                _dtOperator_string.Rows.Add( ExpressionData.ExpressionOperator.Contains, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.Contains] );
                _dtOperator_string.Rows.Add( ExpressionData.ExpressionOperator.NotContains, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.NotContains] );
                _dtOperator_string.Rows.Add( ExpressionData.ExpressionOperator.BeginWith, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.BeginWith] );
                _dtOperator_string.Rows.Add( ExpressionData.ExpressionOperator.NotBeginWith, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.NotBeginWith] );
                _dtOperator_string.Rows.Add( ExpressionData.ExpressionOperator.EndWith, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.EndWith] );
                _dtOperator_string.Rows.Add( ExpressionData.ExpressionOperator.NotEndWith, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.NotEndWith] );
                _dtOperator_string.AcceptChanges();
            }
            {
                _dtOperator_array = new DataTable();
                _dtOperator_array.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( ExpressionData.ExpressionOperator ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                _dtOperator_array.Rows.Add( ExpressionData.ExpressionOperator.ArrayContains, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.ArrayContains] );
                _dtOperator_array.Rows.Add( ExpressionData.ExpressionOperator.ArrayNotContains, ExpressionData.OperatorNameTable[ExpressionData.ExpressionOperator.ArrayNotContains] );
                _dtOperator_array.AcceptChanges();
            }
            {
                _dtRightOperand_bool = new DataTable();
                _dtRightOperand_bool.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( bool ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                _dtRightOperand_bool.Rows.Add( true, "○" );
                _dtRightOperand_bool.Rows.Add( false, "×" );
                _dtRightOperand_bool.AcceptChanges();
            }
            {
                _dtRightOperand_shipname = new DataTable();
                _dtRightOperand_shipname.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( int ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                foreach ( var s in KCDatabase.Instance.MasterShips.Values.Where( s => !s.IsAbyssalShip ).OrderBy( s => s.NameWithClass ).OrderBy( s => s.NameReading ) )
                    _dtRightOperand_shipname.Rows.Add( s.ShipID, s.Name );
                _dtRightOperand_shipname.AcceptChanges();
            }
            {
                _dtRightOperand_shiptype = new DataTable();
                _dtRightOperand_shiptype.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( int ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                foreach ( var st in KCDatabase.Instance.ShipTypes.Values )
                    _dtRightOperand_shiptype.Rows.Add( st.TypeID, st.Name );
                _dtRightOperand_shiptype.AcceptChanges();
            }
            {
                _dtRightOperand_range = new DataTable();
                _dtRightOperand_range.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( int ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                for ( int i = 0; i <= 4; i++ )
                    _dtRightOperand_range.Rows.Add( i, Constants.GetRange( i ) );
                _dtRightOperand_range.AcceptChanges();
            }
            {
                _dtRightOperand_speed = new DataTable();
                _dtRightOperand_speed.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( int ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                _dtRightOperand_speed.Rows.Add( 0, Constants.GetSpeed( 0 ) );
                _dtRightOperand_speed.Rows.Add( 5, Constants.GetSpeed( 5 ) );
                _dtRightOperand_speed.Rows.Add( 10, Constants.GetSpeed( 10 ) );
                _dtRightOperand_speed.AcceptChanges();
            }
            {
                _dtRightOperand_rarity = new DataTable();
                _dtRightOperand_rarity.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( int ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                for ( int i = 1; i <= 8; i++ )
                    _dtRightOperand_rarity.Rows.Add( i, Constants.GetShipRarity( i ) );
                _dtRightOperand_rarity.AcceptChanges();
            }
            {
                _dtRightOperand_equipment = new DataTable();
                _dtRightOperand_equipment.Columns.AddRange( new DataColumn[]{
                    new DataColumn( "Value", typeof( int ) ),
                    new DataColumn( "Display", typeof( string ) ) } );
                foreach ( var eq in KCDatabase.Instance.MasterEquipments.Values.Where( eq => !eq.IsAbyssalEquipment ).OrderBy( eq => eq.CategoryType ) )
                    _dtRightOperand_equipment.Rows.Add( eq.EquipmentID, eq.Name );
                _dtRightOperand_equipment.AcceptChanges();
            }

            RightOperand_ComboBox.ValueMember = "Value";
            RightOperand_ComboBox.DisplayMember = "Display";
            RightOperand_ComboBox.DataSource = _dtRightOperand_bool;

            SetExpressionSetter( ExpressionData.LeftOperandNameTable.Keys.First() );

            #endregion

            _target = exp.Clone();

            LabelResult.Tag = false;
            UpdateExpressionLabel();
        }
        public void ImportExpressionData( ExpressionManager exm )
        {
            _target = exm.Clone();

            ExpressionView.Rows.Clear();

            var rows = new DataGridViewRow[exm.Expressions.Count];
            for ( int i = 0; i < rows.Length; i++ ) {
                rows[i] = GetExpressionViewRow( exm.Expressions[i] );
            }

            ExpressionView.Rows.AddRange( rows.ToArray() );

            ExpressionDetailView.Rows.Clear();
        }