DumontEXE 0.0.1
cmcConnection.cpp
00001 /* ***************************************************************************
00002 **
00003 ** Copyright (C) 2007 Lorimark Solutions, LLC. All rights reserved.
00004 **
00005 ** This file is part of the DumontEXE Scripting Extension Kit
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://dumont.showoff-db.org/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://dumont.showoff-db.org/licensing.html 
00017 ** or contact the sales department at sales@lorimarksolutions.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ** author: Mark Petryk ~ Lorimark Solutions, LLC
00023 ** **************************************************************************/
00024 
00025 #include "cmcConnection.h"
00026 #include "cmcForm.h"
00027 #include "cmcConnectionDefs.h"
00028 #include "cmcConnectionDef.h"
00029 #include "cmcFieldDefs.h"
00030 #include "cmcFieldDef.h"
00031 
00032 namespace cmcDatabaseApi {
00033 
00034 cmcConnection::cmcConnection( const cmcConnection & copy ):
00035   cmcApi( copy )
00036 {
00037 }
00038 
00039 cmcConnection::cmcConnection
00040 (
00041   const QString & conName,
00042   IDispatch * dispatch,
00043   cmcForm * parent
00044 ):
00045   cmcApi( conName, dispatch, parent-> app(), (QObject*)parent )
00046 {
00047 //  TRACE_FUNCTION
00048 
00049   m_conName = conName;
00050 
00051   m_definition = NULL;
00052 
00053   /*
00054   ** Set the object name to something that can be looked up on subsequent calls.
00055   **
00056   */
00057   setObjectName( conCatName() );
00058 
00059   reset();
00060 
00061 }
00062 
00063 cmcConnection::~cmcConnection()
00064 {
00065 //  TRACE_FUNCTION
00066 }
00067 
00068 void cmcConnection::reset()
00069 {
00070   /*
00071   ** Let us know that we don't know yet what the previous value is.
00072   **
00073   **
00074   */
00075   m_gotPreviousValue = false;
00076 }
00077 
00078 
00079 bool cmcConnection::isField()
00080 {
00081   return( false );
00082 }
00083 
00084 bool cmcConnection::isConnection()
00085 {
00086   return( true );
00087 }
00088 
00089 cmcForm * cmcConnection::form()
00090 {
00091   return( qobject_cast<cmcForm*>(parent()) );
00092 }  
00093 
00094 cmcConnectionDef * cmcConnection::definition()
00095 {
00096   if( !m_definition )
00097        m_definition  =
00098          form()->
00099            categoryDef()->
00100              connectionDefs()->
00101                get( conName(), toCategory() );
00102   return( m_definition );
00103 }
00104 
00105 QString cmcConnection::name()
00106 {
00107   return( conName() );
00108 }
00109 
00110 QString cmcConnection::fieldName()
00111 {
00112   return( conName() + " " + toCategory() );
00113 }
00114 
00115 QString cmcConnection::conCatName()
00116 {
00117   return( conName() + "->" + toCategory() );
00118 }
00119 
00120 QString cmcConnection::conName()
00121 {
00122   return( m_conName );
00123 }
00124 
00125 QString cmcConnection::toCategory()
00126 {
00127   if( m_toCategory == "" )
00128       m_toCategory = GetServerString( "ToCategory" );
00129   return( m_toCategory );
00130 }
00131 
00132 QString cmcConnection::fieldName( long index )
00133 {
00134   return( definition()-> toCategoryDef()-> fieldDefs()-> get(index)-> name() );
00135 }
00136 
00137 QString cmcConnection::fieldNames()
00138 {
00139   return( QString() );
00140 }
00141 
00142 
00143 long cmcConnection::connectedItemCount()
00144 {
00145   return( GetServerLong( "ConnectedItemCount" ) );
00146 }
00147 
00148 long cmcConnection::cic()
00149 {
00150   return( connectedItemCount() );
00151 }
00152 
00153 long cmcConnection::unconnectedItemCount()
00154 {
00155   return( GetServerLong( "UnconnectedItemCount" ) );
00156 }
00157 
00158 long cmcConnection::uic()
00159 {
00160   return( unconnectedItemCount() );
00161 }
00162 
00163 void cmcConnection::currentSelection( long selection )
00164 {
00165 //  qDebug( "cmcConnection::currentSelection(%lu)", i_selection );
00166   VARIANTARG varg[1];
00167   ::VariantInit(&varg[0]);     // Initialize the VARIANT.
00168 
00169   // load the variant
00170   varg[0].vt = VT_I4; varg[0].lVal = selection;
00171 
00172   DISPID proput = DISPID_PROPERTYPUT;
00173 
00174   // Fill in the DISPPARAMS structure.
00175   DISPPARAMS param;
00176   param.cArgs             = 1;        // Number of arguments
00177   param.rgvarg            = varg;     // Arguments
00178   param.cNamedArgs        = 1;        // Number of named args
00179   param.rgdispidNamedArgs = &proput;  // Named arguments
00180 
00181   // Allocate a variant for the returned parameter.
00182   VARIANT varResult;
00183   ::VariantInit(&varResult);
00184 
00185   // Invoke the function.
00186   HRESULT hr = Invoke
00187   (
00188     "CurrentSelection",
00189     IID_NULL,
00190     GetUserDefaultLCID(),
00191     DISPATCH_PROPERTYPUT,
00192     &param,
00193     &varResult,
00194     NULL,
00195     NULL
00196   );
00197 
00198   if (FAILED(hr))
00199   {
00200 //    TROF( "currentSelection failed hr=" + QString::number(hr,16) ); 
00201   }
00202 
00203 }
00204 
00205 long cmcConnection::currentSelection()
00206 {
00207   return( GetServerLong( "CurrentSelection" ) );
00208 }
00209 
00210 QString cmcConnection::itemName()
00211 {
00212   if( (connectedItemCount() > 0) && (currentSelection() == 0) ) 
00213     currentSelection(1);
00214 
00215   return( GetServerString( "ItemName" ) );
00216 }
00217 
00218 QString cmcConnection::itemClarifyField()
00219 {
00220   if( (connectedItemCount() > 0) && (currentSelection() == 0) ) 
00221     currentSelection(1);
00222 
00223   return( GetServerString( "ItemClarifyField" ) );
00224 }
00225 
00226 void cmcConnection::clear()
00227 {
00228   if( m_gotPreviousValue == false ) value();
00229 
00230   // Fill in the DISPPARAMS structure.
00231   DISPPARAMS param;
00232   param.cArgs             = 0;     // Number of arguments
00233   param.rgvarg            = NULL;  // Arguments
00234   param.cNamedArgs        = 0;     // Number of named args
00235   param.rgdispidNamedArgs = NULL;  // Named arguments
00236 
00237   // Allocate a variant for the returned parameter.
00238   VARIANT varResult;
00239   ::VariantInit(&varResult);
00240 
00241   // Invoke the function.
00242   HRESULT hr = Invoke
00243   (
00244     "Clear",
00245     IID_NULL,
00246     GetUserDefaultLCID(),
00247     DISPATCH_METHOD,
00248     &param,
00249     &varResult,
00250     NULL,
00251     NULL
00252   );
00253 
00254   if( FAILED(hr) )
00255   {
00256     qDebug( "cmcConnection::clear hr=%lx", hr );
00257   }
00258 
00259 }
00260 
00261 void cmcConnection::clearAll()
00262 {
00263   if( m_gotPreviousValue == false ) value();
00264 
00265   // Fill in the DISPPARAMS structure.
00266   DISPPARAMS param;
00267   param.cArgs             = 0;     // Number of arguments
00268   param.rgvarg            = NULL;  // Arguments
00269   param.cNamedArgs        = 0;     // Number of named args
00270   param.rgdispidNamedArgs = NULL;  // Named arguments
00271 
00272   // Allocate a variant for the returned parameter.
00273   VARIANT varResult;
00274   ::VariantInit(&varResult);
00275 
00276   // Invoke the function.
00277   HRESULT hr = Invoke
00278   (
00279     "ClearAll",
00280     IID_NULL,
00281     GetUserDefaultLCID(),
00282     DISPATCH_METHOD,
00283     &param,
00284     &varResult,
00285     NULL,
00286     NULL
00287   );
00288 
00289   if( FAILED(hr) )
00290   {
00291     qDebug( "cmcConnection::clearAll hr=%lx", hr );
00292   }
00293 
00294 }
00295 
00296 void cmcConnection::clearConnection( const QString & itemName, const QString & itemClarify )
00297 {
00298   if( m_gotPreviousValue == false ) value();
00299 
00300   VARIANTARG varg[2];
00301   ::VariantInit(&varg[0]);     // Initialize the VARIANT.
00302   ::VariantInit(&varg[1]);
00303 
00304   // Convert the wide-character string to a BSTR.
00305   BSTR itmName = ::SysAllocString((OLECHAR*)itemName.utf16());
00306   BSTR itmClfy = ::SysAllocString((OLECHAR*)itemClarify.utf16());
00307 
00308   // load the variant
00309   varg[1].vt = VT_BSTR; varg[1].bstrVal = itmName;
00310   varg[0].vt = VT_BSTR; varg[0].bstrVal = itmClfy;
00311 
00312 
00313   // Fill in the DISPPARAMS structure.
00314   DISPPARAMS param;
00315   param.cArgs             = 2;     // Number of arguments
00316   param.rgvarg            = varg;  // Arguments
00317   param.cNamedArgs        = 0;     // Number of named args
00318   param.rgdispidNamedArgs = NULL;  // Named arguments
00319 
00320   // Allocate a variant for the returned parameter.
00321   VARIANT varResult;
00322   ::VariantInit(&varResult);
00323 
00324   // Invoke the function.
00325   HRESULT hr = Invoke
00326   (
00327     "ClearConnection",
00328     IID_NULL,
00329     GetUserDefaultLCID(),
00330     DISPATCH_METHOD,
00331     &param,
00332     &varResult,
00333     NULL,
00334     NULL
00335   );
00336 
00337   ::SysFreeString(itmName);
00338   ::SysFreeString(itmClfy);
00339 
00340   if( FAILED(hr) )
00341   {
00342     qDebug( "cmcConnection::clearConnection hr=%lx", hr );
00343   }
00344 
00345 }
00346 
00347 void cmcConnection::setConnection( const QString & itemName, const QString & itemClarify )
00348 {
00349   if( m_gotPreviousValue == false ) value();
00350 
00351   VARIANTARG varg[2];
00352   ::VariantInit(&varg[0]);     // Initialize the VARIANT.
00353   ::VariantInit(&varg[1]);
00354 
00355   // Convert the wide-character string to a BSTR.
00356   BSTR itmName = ::SysAllocString((OLECHAR*)itemName.utf16());
00357   BSTR itmClfy = ::SysAllocString((OLECHAR*)itemClarify.utf16());
00358 
00359   // load the variant
00360   varg[1].vt = VT_BSTR; varg[1].bstrVal = itmName;
00361   varg[0].vt = VT_BSTR; varg[0].bstrVal = itmClfy;
00362 
00363   // Fill in the DISPPARAMS structure.
00364   DISPPARAMS param;
00365   param.cArgs             = 2;     // Number of arguments
00366   param.rgvarg            = varg;  // Arguments
00367   param.cNamedArgs        = 0;     // Number of named args
00368   param.rgdispidNamedArgs = NULL;  // Named arguments
00369 
00370   // Allocate a variant for the returned parameter.
00371   VARIANT varResult;
00372   ::VariantInit(&varResult);
00373 
00374   // Invoke the function.
00375   HRESULT hr = Invoke
00376   (
00377     "SetConnection",
00378     IID_NULL,
00379     GetUserDefaultLCID(),
00380     DISPATCH_METHOD,
00381     &param,
00382     &varResult,
00383     NULL,
00384     NULL
00385   );
00386 
00387   ::SysFreeString(itmName);
00388   ::SysFreeString(itmClfy);
00389 
00390   if( FAILED(hr) )
00391   {
00392     qDebug( "cmcConnection::clearConnection hr=%lx", hr );
00393   }
00394 
00395 }
00396 
00397 QString cmcConnection::fieldValue( const QString & fieldName )
00398 {
00399   if( m_gotPreviousValue == false ) value();
00400 
00401 //  qDebug( "fetching cmcConnection::fieldValue(%s)", i_fieldName.toAscii().data() );
00402 
00403   /*!
00404   ** \note There is a peculiarity of the Commence Connection object in that
00405   **        if you set a connection value, and then try to immediately read
00406   **        it back again, you will get no data.  This is because the value
00407   **        of the currentSelection() is still at zero, which is inaccurate.
00408   **        I suppose it's possible for the currentSelection() to remain at
00409   **        zero (remember, connection selection indexes are '1' based) after
00410   **        setting a connection, but this is really an invalid state, and
00411   **        somewhat confusing for the software engineer who is trying to
00412   **        figure out why he can't read back a value he just set.  In any 
00413   **        case, what we do here is reset the currentSelection() back to 1,
00414   **        where it should be, any time we try to read the value of a
00415   **        connection, and there are connected items, and the currentSelection()
00416   **        is zero.  This effectively masks the problem.
00417   **
00418   */
00419   if( (connectedItemCount() > 0) && (currentSelection() == 0) )
00420   {
00421     currentSelection(1);
00422   }
00423 
00424   VARIANTARG varg[1];
00425   ::VariantInit(&varg[0]);     // Initialize the VARIANT.
00426 
00427   // Convert the wide-character string to a BSTR.
00428   BSTR bstrIn = ::SysAllocString((OLECHAR*)fieldName.utf16());
00429 
00430   // load the variant
00431   varg[0].vt = VT_BSTR; varg[0].bstrVal = bstrIn;
00432 
00433   // Fill in the DISPPARAMS structure.
00434   DISPPARAMS param;
00435   param.cArgs             = 1;     // Number of arguments
00436   param.rgvarg            = varg;  // Arguments
00437   param.cNamedArgs        = 0;     // Number of named args
00438   param.rgdispidNamedArgs = NULL;  // Named arguments
00439 
00440   // Allocate a variant for the returned parameter.
00441   VARIANT varResult;
00442   ::VariantInit(&varResult);
00443 
00444   // Invoke the function.
00445   HRESULT hr = Invoke
00446   (
00447     "FieldValue", // 0x0c, // did_FieldValue, BUGBUG wow! 0x0e is wrong, why??? took me three days to find it!
00448     IID_NULL,
00449     GetUserDefaultLCID(),
00450     DISPATCH_METHOD,
00451     &param,
00452     &varResult,
00453     NULL,
00454     NULL
00455   );
00456 
00457   ::SysFreeString(bstrIn);
00458 
00459   if( FAILED(hr) )
00460   {
00461     qDebug( "cmcConnection::fieldValue hr=%lx", hr );
00462     return QString("failed");
00463   }
00464 
00465   // Display the returned string.
00466   if( varResult.vt == VT_BSTR )
00467   {
00468     QString retVal = QString::fromWCharArray(varResult.bstrVal);
00469 //    TROF( "fieldValue ok" ); 
00470     return  retVal;
00471   }
00472 
00473   qDebug( "cmcConnection::fieldValue '%s' bad var type=%x", qPrintable(fieldName), varResult.vt ); 
00474 
00475   return QString( "'" + fieldName + "' bad var type " + QString::number(varResult.vt) );
00476 
00477 } // endQString cmcConnection::fieldValue( QString i_fieldName )
00478 
00479 QString cmcConnection::fieldValue( const QString & itmName, const QString & fieldName )
00480 {
00481   for( int i=1; i<=cic(); i++ )
00482   {
00483     currentSelection(i);
00484     if( itemName() == itmName )
00485     {
00486       return( fieldValue(fieldName) );
00487     }
00488   }
00489 
00490   return( "" );
00491 
00492 }
00493 
00494 
00495 QString cmcConnection::fieldValue
00496 (
00497   const QString & compareField,
00498   const QString & compareValue,
00499   const QString & fieldName
00500 )
00501 {
00502   /*
00503   ** Loop through all the items on this connection.
00504   **
00505   */
00506   for( int i=1; i<=cic(); i++ )
00507   {
00508     /*
00509     ** Select each item, one at a time.
00510     **
00511     */
00512     currentSelection(i);
00513 
00514     /*
00515     ** Compare a field value with the compare Value, see if there's
00516     **  a match.
00517     **
00518     */
00519     if( fieldValue(compareField) == compareValue )
00520     {
00521       /*
00522       ** If we found a compare match, then return the field
00523       **  he's requesting.
00524       **
00525       */
00526       return( fieldValue( fieldName ) );
00527 
00528     } // endif( fieldValue(i_compareField) == i_compareValue )
00529 
00530   } // endfor( int i=1; i<=cic(); i++ )
00531   
00532   /*
00533   ** Nothing matched.  This is not an error, just return an empty
00534   **  string.
00535   **
00536   */
00537   return( "" );
00538 
00539 } // endQString cmcConnection::fieldValue( QString i_compareField, QString i_compareValue, QString i_fieldName )
00540 
00541 
00542 
00543 QString cmcConnection::varValue
00544 (
00545   const QString & fieldName, 
00546   const QString & varName
00547 )
00548 {
00549   if( m_gotPreviousValue == false ) value();
00550 
00551   return( var(fieldValue(fieldName),varName) );
00552 }
00553 
00554 void cmcConnection::setFilterKeyword( const QString & keyword, const QString & text, long flags )
00555 {
00556   setProperty( keyword, text );
00557 
00558   VARIANTARG varg[2];
00559   ::VariantInit(&varg[0]);     // Initialize the VARIANT.
00560   ::VariantInit(&varg[1]);     // Initialize the VARIANT.
00561 
00562   //
00563   // Convert the wide-character string to a BSTR.
00564   //
00565   BSTR kyword = ::SysAllocString((OLECHAR*)keyword.utf16());
00566   BSTR txt    = ::SysAllocString((OLECHAR*)text.utf16());
00567 
00568   // load the variant
00569   varg[2].vt = VT_BSTR; varg[2].bstrVal = kyword;
00570   varg[1].vt = VT_BSTR; varg[1].bstrVal = txt;
00571   varg[0].vt = VT_I4;   varg[0].lVal    = flags;
00572 
00573   // Fill in the DISPPARAMS structure.
00574   DISPPARAMS param;
00575   param.cArgs             = 3;     // Number of arguments
00576   param.rgvarg            = varg;  // Arguments
00577   param.cNamedArgs        = 0;     // Number of named args
00578   param.rgdispidNamedArgs = NULL;  // Named arguments
00579 
00580   // Allocate a variant for the returned parameter.
00581   VARIANT varResult;
00582   ::VariantInit(&varResult);
00583 
00584   // Invoke the function.
00585   HRESULT hr = Invoke
00586   (
00587     "SetFilterKeyword",
00588     IID_NULL,
00589     GetUserDefaultLCID(),
00590     DISPATCH_METHOD,
00591     &param,
00592     &varResult,
00593     NULL,
00594     NULL
00595   );
00596 
00597   ::SysFreeString(kyword);
00598   ::SysFreeString(txt);
00599 
00600   if( FAILED(hr) )
00601   {
00602     qDebug( "cmcConnection::setFilterKeyword hr=%lx", hr );
00603   }
00604 
00605 }
00606 
00607 QString cmcConnection::filterKeyword( const QString & keyword )
00608 {
00609   return( property(keyword).toString() );
00610 }
00611 
00612 void cmcConnection::defaultField( const QString & fieldName )
00613 {
00614   m_defaultField = fieldName;
00615 }
00616 
00617 QString cmcConnection::defaultField()
00618 {
00619   return( m_defaultField );
00620 }
00621 
00622 bool cmcConnection::isDirty()
00623 {
00624   return( previousValue() != value() );
00625 }
00626 
00627 QString cmcConnection::changeLog()
00628 {
00629   /*!
00630   ** \returns Formatted ChangeLog or an empty string if there were no changes
00631   **
00632   */
00633   QString retVal;
00634 
00635   if( isDirty() )
00636     retVal = dq( conCatName()    ) + " from " + 
00637              dq( previousValue() ) + " to "   + 
00638              dq( value()         );
00639 
00640   return( retVal );
00641 
00642 }
00643 
00644 void cmcConnection::undo()
00645 {
00646   qDebug( "cmcConnection::undo - not implemented" );
00647 
00648 }
00649 
00650 QString cmcConnection::value()
00651 {
00652   long current = currentSelection();
00653   bool gpv = m_gotPreviousValue;
00654   m_gotPreviousValue = true;
00655 
00656   QStringList retValueList;
00657   for( long i=1; i<=connectedItemCount(); i++ )  // RED ALERT! Connections( index ) == "1-based"
00658     retValueList.append( value(i, 0) );
00659 
00660   /*
00661   ** Record the initial value for undo().
00662   **
00663   */
00664   if( gpv == false )
00665   {
00666     m_previousValue = retValueList.join(vbCrLf);
00667     m_gotPreviousValue = true;
00668   }
00669 
00670   currentSelection( current );
00671 
00672   return( retValueList.join(vbCrLf) );
00673 
00674 }
00675 
00676 QString cmcConnection::previousValue()
00677 {
00678   if( m_gotPreviousValue == false ) value();
00679 
00680   return( m_previousValue );
00681 
00682 }
00683 
00684 QString cmcConnection::value( long index )
00685 {
00686 //  qDebug( "cmcConnection::value(%lu)", i_index );
00687   /*
00688   ** Here we are going to record the current selection, and restore it after
00689   **  we are done.  This is to maintain compatibility with the existing
00690   **  commence API because when we use connection values, we can pull the
00691   **  current field value without manipulating the currentSelection(), but
00692   **  when using this dumont connection object, because it records previous
00693   **  and post values, it does manipulate the currentSelection, and if not
00694   **  restored properly it can lead to vbScript code incompatibilities.
00695   **
00696   */
00697   long current = currentSelection();
00698   QString retVal = value( index, 0 );
00699   currentSelection( current );
00700   return( retVal );
00701 }
00702 
00703 QString cmcConnection::value( long index, long column )
00704 {
00705   currentSelection( index );
00706   return( fieldValue( fieldName(column) ) );
00707 
00708 }
00709 
00710 bool cmcConnection::onEnter()
00711 {
00712   m_enterValue = value();
00713 //  qDebug("cmcConnection::onEnter %s %s '%s'", 
00714 //    conName().toAscii().data(), 
00715 //    toCategory().toAscii().data(),
00716 //    m_enterValue.toAscii().data()
00717 //  );
00718   emit enter( name(), toCategory(), m_enterValue );
00719   return( true );
00720 
00721 }
00722 
00723 bool cmcConnection::onLeave() 
00724 {
00725 //  qDebug("cmcConnection::onLeave %s %s '%s'",
00726 //    conName().toAscii().data(), 
00727 //    toCategory().toAscii().data(),
00728 //    value().toAscii().data()
00729 //  );
00730 
00731   bool retVal = false;
00732   if( m_enterValue != value() )
00733   {
00734     onChange();
00735     retVal = true;
00736   }
00737   emit leave( name(), toCategory(), value() );
00738   return( retVal );
00739 
00740 }
00741 
00742 bool cmcConnection::onChange()
00743 {
00744   emit change( name(), toCategory(), value() );
00745   return( true );
00746 
00747 }
00748 
00749 long cmcConnection::index()
00750 {
00751   return( definition()-> index() +1 );
00752 
00753 }
00754 
00755 #ifdef NEVER
00756 QDomElement cmcConnection::domElement( QDomDocument & doc, QDomNode & parent )
00757 {
00758   QDomElement de = doc.createElement( "connection" + QString::number(index()) );
00759   parent.appendChild(de);
00760   de.setAttribute( "name", conCatName() );
00761 
00762   /*
00763   ** Remember the current selection because we'll want to restore it later.
00764   **
00765   */
00766   long current = currentSelection();
00767 
00768   /*
00769   ** Loop through each value in this connection field and assemble it into a
00770   **  single QDomElement that can be attached to a document.
00771   **
00772   */
00773   for( long i=1; i<=connectedItemCount(); i++ )
00774   {
00775     currentSelection(i);
00776     QDomElement item = doc.createElement( "item" + QString::number(i) );
00777     de.appendChild(item);
00778 
00779 //    QDomText itemVal = doc.createTextNode(value(i));
00780 //    item.appendChild(itemVal);
00781 
00782     QDomElement itemKey = doc.createElement( "key" );
00783     item.appendChild(itemKey);
00784 
00785     QDomText keyElement = doc.createTextNode( itemName() );
00786     itemKey.appendChild( keyElement );
00787 
00788     /*
00789     ** If this category allows duplicates, then we need to do some
00790     **  extra work to add some distinguishing qualities to this
00791     **  connection value.
00792     **
00793     */
00794     if( definition()-> toCategoryDef()-> duplicatesAllowed() )
00795     {
00796       /*
00797       ** If this category has a clarify field, and that clarify
00798       **  field has some data in it, then we'll fetch that as
00799       **  our duplicates-allowed-clarify field.
00800       **
00801       */
00802       if( definition()-> toCategoryDef()-> hasClarifyField() &&
00803           itemClarifyField() != ""                         )
00804       {
00805         QDomElement itemCfy = doc.createElement( "clarify" );
00806         item.appendChild(itemCfy);
00807         QDomText cfyElement = doc.createTextNode( itemClarifyField() );
00808         itemCfy.appendChild( cfyElement );
00809       }
00810 
00811       /*
00812       ** Well, either we don't have a clarify field, or the clarify
00813       **  field is blank, so see if we can use one of the other
00814       **  distinction fields.  That'll either be the cmcID field or
00815       **  the guid field.
00816       **
00817       */
00818       else if( definition()-> toCategoryDef()-> hasVarField() )
00819       {
00820         /*
00821         ** BUGBUG: we need a better way of distinguishing if the cmcID or guid values
00822         **  are stored in a varField or a separate text field.  Right now we're pulling
00823         **  them from a var field, and that's ok, but it might not be portable to
00824         **  someone elses database.
00825         **
00826         */
00827         QString cmcID = varValue( definition()-> toCategoryDef()-> varFieldName(), "cmcID" );
00828         QString guid  = varValue( definition()-> toCategoryDef()-> varFieldName(), "guid"  );
00829 
00830         /*
00831         ** Check the guid field first to see if it has a value.  If so, we'll use that.
00832         **  otherwise try for the cmcID field.
00833         **
00834         */
00835         if( guid != "" )
00836         {
00837           QDomElement itemVar = doc.createElement( "guid" );
00838           item.appendChild(itemVar);
00839           QDomText varElement = doc.createTextNode( guid );
00840           itemVar.appendChild( varElement );
00841         }
00842 
00843         /*
00844         ** The guid field mustv been blank.
00845         **
00846         */
00847         else if( cmcID != "" )
00848         {
00849           QDomElement itemVar = doc.createElement( "cmcID" );
00850           item.appendChild(itemVar);
00851           QDomText varElement = doc.createTextNode( cmcID );
00852           itemVar.appendChild( varElement );
00853         }
00854 
00855       }
00856 
00857     }
00858 
00859   }
00860 
00861   currentSelection( current );
00862 
00863   return( de );
00864 
00865 }
00866 
00867 QString cmcConnection::xml()
00868 {
00869   QDomDocument doc("cmcConnection");
00870 
00871   domElement( doc, doc );
00872 
00873   return( dumont::vbString(doc.toString(3)) );
00874 }
00875 #endif
00876 
00877 
00878 
00879 } // endnamespace cmcDatabaseApi
00880 
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties




~ ~ ~ ~ ~ ~
Source Code without Comments is like a Cranberry Garland
without the berries. Comment your Code!
 
Commence Database User Support Group Forum
http://newsgroup.showoff-db.org/
~ ~ ~ ~ ~ ~
Author: Mark Petryk
Lorimark Solutions, LLC
mark@lorimarksolutions.com