コード例 #1
0
ファイル: FieldManagerDlg.cpp プロジェクト: wyrover/GDES
/*
 * 方法:
 *	  1) 得到原始的字段链表L1和字段列表框中的字段链表L2
 *    2) 遍历链表L2,判断字段是否存在于L1中
 *       a) 如果存在,则该字段保持不变,并从L1中移除该字段;
 *       b) 如果不存在,则转第(3)步
 *    3) 该字段是新添加的字段,则执行"增加字段"操作Add
 *    4) 完成遍历L2,最后剩下的L1的元素就是需要删除的字段
 *    5) 执行"删除字段"操作Remove
 */
void FieldManagerDlg::OnBnClickedApplyBtn()
{
    if( m_fieldListBox.GetCount() > 0 )
    {
        // 切换之前更新上次选择的字段信息
        // 并检查字段信息的有效性
        if( !updateFieldInfo() ) return;
    }

    // 选择的图元类型
    CString selType = getSelType();
    if( selType.GetLength() == 0 ) return;

    AcStringArray fields;
    FieldHelper::GetAllFields( selType, fields );
    if( fields.isEmpty() && m_fieldListBox.GetCount() == 0 )
    {
        MessageBox( _T( "没有字段可更新" ) );
        return;
    }

    // "剩余"字段
    // 与m_infoes应该是一一对应的
    AcStringArray leftFields;
    for( int i = 0; i < m_fieldListBox.GetCount(); i++ )
    {
        CString text;
        m_fieldListBox.GetText( i, text );
        leftFields.append( text );
    }

    int len = leftFields.length();
    for( int i = 0; i < len; i++ )
    {
        CString field = leftFields[i].kACharPtr();
        int index = fields.find( field );
        if( index >= 0 ) // 已存在,不变
        {
            fields.removeAt( index );
        }
        else
        {
            // 增加字段
            FieldHelper::AddField( selType, field );
        }
        // 默认属性设置不需要添加到词典中
        if( m_infoes[i]->isDefault() )
        {
            FieldInfoHelper::RemoveFieldInfo( selType, field );
        }
        else
        {
            // 新增的字段
            if( index < 0 || !FieldInfoHelper::FindFieldInfo( selType, field ) )
            {
                FieldInfoHelper::AddFieldInfo( selType, field, *m_infoes[i] );
            }
            else
            {
                // 更新已有的字段信息
                FieldInfoHelper::WriteFieldInfo( selType, field, *m_infoes[i] );
            }
        }
    }

    // 删除字段
    len = fields.length();
    for( int i = 0; i < len; i++ )
    {
        FieldHelper::RemoveField( selType, fields[i].kACharPtr() );
    }

    MessageBox( _T( "字段信息更新成功!" ) );
}