home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / visbuild / oasearch / skillb.cpv < prev    next >
Encoding:
Text File  |  1996-02-20  |  5.6 KB  |  168 lines

  1. /******************************************************************************
  2. * .FILE:        skillb.cpv                                                    *
  3. *                                                                             *
  4. * .DESCRIPTION: Implementation of additional member functions for the class   *
  5. *               OASkillBase                                                   *
  6. *                                                                             *
  7. * .CLASSES:                                                                   *
  8. *                                                                             *
  9. * .COPYRIGHT:                                                                 *
  10. *    Licensed Material - Program-Property of IBM                              *
  11. *    (C) Copyright IBM Corp. 1992, 1995, 1996 - All Rights Reserved           *
  12. *                                                                             *
  13. * .DISCLAIMER:                                                                *
  14. *   The following [enclosed] code is sample code created by IBM               *
  15. *   Corporation.  This sample code is not part of any standard IBM product    *
  16. *   and is provided to you solely for the purpose of assisting you in the     *
  17. *   development of your applications.  The code is provided 'AS IS',          *
  18. *   without warranty of any kind.  IBM shall not be liable for any damages    *
  19. *   arising out of your use of the sample code, even if they have been        *
  20. *   advised of the possibility of such damages.                               *
  21. *                                                                             *
  22. * .NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE          *
  23. *                                                                             *
  24. ******************************************************************************/
  25. // Added after OS2 GA
  26. INotificationId OASkillBase::qryFoundId = "OASkillBase::qryFound";
  27.  
  28. // Get skills from database and populate a skill list
  29.  
  30. OASkillBase & OASkillBase::getSkills(const IString & aSkillName, IVSequence<OASkill*>* aList)
  31. {
  32.  
  33.   IProfile *p = new IProfile("skill.ini");
  34.  
  35. // Needed for Windows implementation
  36.  
  37.    primeData(*p);
  38.  
  39. // Check for this skill name in the database
  40.  
  41.   if (!p->containsApplication(aSkillName))
  42.   {
  43.   delete p;
  44.   throw IException("A record was not found for this skill description.");
  45.   return *this;
  46.   }
  47.  
  48. // Otherwise, empty the skill list
  49.  
  50.   if (!(aList->isEmpty()))
  51.     aList->removeAll();
  52.  
  53. // Instantiate new skills and set them
  54.  
  55.   unsigned long numRecs = p->numberOfKeys(aSkillName);
  56.   OASkill* tempSkill;
  57.   IString IDkey, yearkey;
  58.   int i;
  59.  
  60.   for (i=1; i <= (numRecs/2); i++)
  61.     {
  62.      tempSkill = new OASkill;
  63.      tempSkill->setSkillName(aSkillName);
  64.  
  65.      IDkey = "ID" + IString(i);
  66.      yearkey = "year" + IString(i);
  67.  
  68.      if (p->containsKeyName(yearkey, aSkillName))
  69.        tempSkill->setYearsExp(p->elementWithKey(yearkey, aSkillName));
  70.      if (p->containsKeyName(IDkey, aSkillName))
  71.        tempSkill->setContractorID(p->elementWithKey(IDkey, aSkillName));
  72.  
  73.      tempSkill->setKey(IString(i));
  74.  
  75. // Add skill to skill list
  76.  
  77.      aList->addAsLast(tempSkill);
  78.  
  79.     }
  80.  
  81.   delete p;
  82.  
  83. // Execute event to trigger instantiation of OASkillView
  84.   notifyObservers(INotificationEvent(qryFoundId, *this));
  85.  
  86.   return *this;
  87.  
  88. }
  89.  
  90. // Add skill to database
  91.  
  92. OASkillBase & OASkillBase::putSkill(OASkill* aSkill)
  93. {
  94.  
  95.   IProfile *p = new IProfile("skill.ini");
  96.   IString IDkey, yearkey;
  97.  
  98. // Needed for Windows implementation
  99.  
  100.    primeData(*p);
  101.  
  102. // If skill is not in the database at all, set the key index this way
  103.  
  104.   if (!p->containsApplication(aSkill->skillName()))
  105.      aSkill->setKey("1");
  106.  
  107.   else {
  108.  
  109. // Check to see if this record already exists for this contractor and set the key
  110.  
  111.      unsigned long numRecs = p->numberOfKeys(aSkill->skillName());
  112.      IString tempID;
  113.      int flag = 0;
  114.      int i;
  115.  
  116.      for (i=1; i <= (numRecs/2) ; i++) {
  117.  
  118.         IDkey = "ID" + IString(i);
  119.         tempID = p->elementWithKey(IDkey, aSkill->skillName());
  120.  
  121.         if (tempID == aSkill->contractorID()) {
  122.            aSkill->setKey(IString(i));
  123.  
  124.            flag = 1;              // Set flag to indicate record was found
  125.            i = (numRecs/2) + 1;   // Terminate loop immediately
  126.         }
  127.      }
  128.  
  129. // If this is a new entry for an existing skill, set the key index this way
  130.  
  131.      if (flag == 0)
  132.         aSkill->setKey(IString(1 + (numRecs/2)));
  133.   }
  134.  
  135. // Construct the database keys
  136.  
  137.   IDkey = "ID" + aSkill->key();
  138.   yearkey = "year" + aSkill->key();
  139.  
  140. // Add the skill (or replace existing skill records) in database
  141.  
  142.   p->addOrReplaceElementWithKey(IDkey, aSkill->contractorID(), aSkill->skillName());
  143.   p->addOrReplaceElementWithKey(yearkey, aSkill->yearsExp(), aSkill->skillName());
  144.  
  145.   delete p;
  146.   return *this;
  147. }
  148.  
  149. // Prime profile instance in Windows with data
  150.  
  151. OASkillBase & OASkillBase::primeData(IProfile & aDatabase) {
  152.  
  153. // Windows does not read from .ini files.
  154. // It uses a central registry,
  155. // so load initial contract data into the registry.
  156.  
  157.   aDatabase.addOrReplaceElementWithKey("ID1","SusanGCarpenter","Technical writing");
  158.   aDatabase.addOrReplaceElementWithKey("year1","15","Technical writing");
  159.  
  160.   aDatabase.addOrReplaceElementWithKey("ID1","SusanGCarpenter","Testing");
  161.   aDatabase.addOrReplaceElementWithKey("year1","5","Testing");
  162.  
  163.   aDatabase.addOrReplaceElementWithKey("ID1","SusanGCarpenter","C++ programming");
  164.   aDatabase.addOrReplaceElementWithKey("year1","1","C++ programming");
  165.  
  166.   return *this;
  167. }
  168.