home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dokpr1.zip / lomos / loandet.cpp next >
Text File  |  1995-11-09  |  22KB  |  826 lines

  1.  
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <memory.h>
  5. #include <string.h>
  6. #include "mmemory.h"
  7. #include "range.h"
  8. #include "mesamod.h"
  9. #include "sheetv.h"
  10. #include "sampcont.h"
  11. #include "lomos.h"
  12. #include "loandet.h"
  13. #include "interest.h"
  14. #include "editview.h"
  15.  
  16. extern MSampleController *MyMesa;
  17. MMesaModel * currentModel;
  18.  
  19.  
  20. // we can't send strings like "$2,150.23" into a cell so we need to
  21. // strip out the '$' and the ',' to make it "2150.23".  this procedure
  22. // accomplishes that
  23. void stripDollarAndCommas(char *str)
  24. {
  25.    char *str2 = new char[strlen(str)+1];
  26.    int x=0,y=0;
  27.  
  28.    for (x=0;x < strlen(str)+1 ; x++) {
  29.       if ((str[x] != '$') && (str[x] != ',') &&(str[x] != ' ')) {
  30.          str2[y]=str[x];
  31.          y++;
  32.       } /* endif */
  33.    } /* endfor */
  34.    strcpy(str,str2);
  35.    delete str2;
  36. }
  37.  
  38.  
  39. // this is a major hack.  Right now, any cell that has formattings set
  40. // when the value is queried, it comes back with an extra space at the
  41. // end.  This function strips the space to make it work correctly.
  42. void stripEndingSpace(char *str)
  43. {
  44.    if (str[MStrLen(str)-1] == ' ') {
  45.       str[MStrLen(str)-1]='\0';
  46.    } /* endif */
  47. }
  48.  
  49.  
  50.  
  51. // as mentioned in loandet.h, the LOInterest methods mostly just post messages
  52. // to the window so it knows what is going on in it's model
  53. LOInterest::LOInterest(HWND hw) : MInterest()
  54. {
  55.    theWin=hw;
  56. }
  57.  
  58. LOInterest::~LOInterest()
  59. {
  60. }
  61.  
  62. void LOInterest::redisplay(MChange *mc)
  63. {
  64.    WinPostMsg(theWin,LO_REDISPLAY,(MPARAM)mc,0L);
  65. }
  66. void LOInterest::changedSize(MChange *mc)
  67. {
  68.    WinPostMsg(theWin,LO_CHANGEDSIZE,(MPARAM)mc,0L);
  69. }
  70. void LOInterest::formatsChanged(MChange *mc)
  71. {
  72.    WinPostMsg(theWin,LO_FORMATSCHANGED,(MPARAM)mc,0L);
  73. }
  74. void LOInterest::contentsChanged(MChange *mc)
  75. {
  76.    WinPostMsg(theWin,LO_CONTENTSCHANGED,(MPARAM)mc,0L);
  77. }
  78. void LOInterest::resetView(MChange *mc)
  79. {
  80.    WinPostMsg(theWin,LO_RESETVIEW,(MPARAM)mc,0L);
  81. }
  82.  
  83.  
  84. // this function sets up a new Loan by formatting the top layer of the
  85. // model and inserting the appropriate titles and formulas
  86. void SetupNewLoan(MMesaModel * theModel)
  87. {
  88.     MRange ra;
  89.     MFormat fo;
  90.     MException me;
  91.     MAddress ad,ad2;
  92.    static char per[] = "=if(k2=\"Weekly\", j2*52, j2*12)";
  93.    static char prate[] = "=if(k2=\"Weekly\", h2/52, h2/12)";
  94.    int nper;
  95.  
  96. /* Set range formats */
  97.       fo.init();
  98.         fo.setMergePrecision(1);
  99.         fo.setMergeFormat(1);
  100.       fo.setFormat(generalAlignment);
  101.  
  102.       ad.set(0,0,0);
  103.       ad2.set(31,12,0);
  104.       ra.init();
  105.       ra.set(&ad,&ad2);
  106.           theModel -> setRangeToFormat(&ra,&fo,defaultAction,NULL,&me);
  107.  
  108.         fo.setFormat(currencyTypeFormat |currencySubtypeFormat | 2);
  109.       ad.set(1,6,0);
  110.       ra.set(&ad,&ad);
  111.           theModel -> setRangeToFormat(&ra,&fo,defaultAction,NULL,&me);
  112.  
  113.       ad.set(4,1,0);
  114.       ad2.set(31,4,0);
  115.       ra.set(&ad,&ad2);
  116.           theModel -> setRangeToFormat(&ra,&fo,defaultAction,NULL,&me);
  117.  
  118.       ad.set(2,4,0);
  119.       ra.set(&ad,&ad);
  120.           theModel -> setRangeToFormat(&ra,&fo,defaultAction,NULL,&me);
  121.  
  122.       fo.setFormat(dateFormat);
  123.       ad.set(1,1,0);
  124.       ra.set(&ad,&ad);
  125.           theModel -> setRangeToFormat(&ra,&fo,defaultAction,NULL,&me);
  126.  
  127.       ad.set(1,8,0);
  128.       ra.set(&ad,&ad);
  129.           theModel -> setRangeToFormat(&ra,&fo,defaultAction,NULL,&me);
  130.  
  131.       ad.set(4,0,0);
  132.       ad2.set(31,0,0);
  133.       ra.set(&ad,&ad2);
  134.           theModel -> setRangeToFormat(&ra,&fo,defaultAction,NULL,&me);
  135.      
  136.       fo.setFormat(percentFormat);
  137.       ad.set(1,7,0);
  138.       ra.set(&ad,&ad);
  139.           theModel -> setRangeToFormat(&ra,&fo,defaultAction,NULL,&me);
  140.  
  141.       ad.set(1,12,0);
  142.       ra.set(&ad,&ad);
  143.          theModel -> setRangeToFormat(&ra,&fo,defaultAction,NULL,&me);
  144.  
  145. /* Set headings and subheadings */
  146.         ad.set(0,0,0);
  147.         theModel -> setCellToStringOrNumber(&ad,"Loan ID",0,&me,NULL);
  148.         ad.set(0,1,0);
  149.         theModel -> setCellToStringOrNumber(&ad,"App Date",0,&me,NULL);
  150.         ad.set(0,2,0);
  151.         theModel -> setCellToStringOrNumber(&ad,"Rep ID",0,&me,NULL);
  152.         ad.set(0,3,0);
  153.         theModel -> setCellToStringOrNumber(&ad,"Name",0,&me,NULL);
  154.         ad.set(0,4,0);
  155.         theModel -> setCellToStringOrNumber(&ad,"SS No",0,&me,NULL);
  156.         ad.set(0,5,0);
  157.         theModel -> setCellToStringOrNumber(&ad,"Type",0,&me,NULL);
  158.         ad.set(0,6,0);
  159.         theModel -> setCellToStringOrNumber(&ad,"Amount",0,&me,NULL);
  160.         ad.set(0,7,0);
  161.         theModel -> setCellToStringOrNumber(&ad,"Rate",0,&me,NULL);
  162.         ad.set(0,8,0);
  163.         theModel -> setCellToStringOrNumber(&ad,"Start Date",0,&me,NULL);
  164.         ad.set(0,9,0);
  165.         theModel -> setCellToStringOrNumber(&ad,"Duration",0,&me,NULL);
  166.         ad.set(0,10,0);
  167.         theModel -> setCellToStringOrNumber(&ad,"Periodicity",0,&me,NULL);
  168.       ad.set(0,11,0);
  169.       theModel -> setCellToStringOrNumber(&ad,"Periods",0,&me,NULL);
  170.       ad.set(0,12,0);
  171.       theModel -> setCellToStringOrNumber(&ad,"Periodic Rate",0,&me,NULL);
  172.       ad.set(3,0,0);
  173.       theModel -> setCellToStringOrNumber(&ad,"Month",0,&me,NULL);
  174.       ad.set(3,1,0);
  175.       theModel -> setCellToStringOrNumber(&ad,"Payment",0,&me,NULL);
  176.       ad.set(3,2,0);
  177.       theModel -> setCellToStringOrNumber(&ad,"To Interest",0,&me,NULL);
  178.       ad.set(3,3,0);
  179.       theModel -> setCellToStringOrNumber(&ad,"To Principal",0,&me,NULL);
  180.       ad.set(3,4,0);
  181.       theModel -> setCellToStringOrNumber(&ad,"Outstanding",0,&me,NULL);
  182.  
  183. /* Set the initial values or formulas */
  184.       ad.set(1,0,0);
  185.       theModel -> setCellToStringOrNumber(&ad,"100",0, &me, NULL);
  186.       ad.set(1,1,0);
  187.       theModel -> setCellToString(&ad,"=TODAY",0, &me, NULL);
  188.       ad.set(1,5,0);
  189.       theModel -> setCellToStringOrNumber(&ad,"Student",0, &me, NULL);
  190.       ad.set(1,8,0);
  191.       theModel -> setCellToString(&ad,"=DATE((YEAR(B2)+(MONTH(B2)>11)),(MOD(MONTH(B2),12)+1),DAY(2))",0, &me, NULL);
  192.       ad.set(1,9,0);
  193.       theModel -> setCellToStringOrNumber(&ad,"3",0, &me, NULL);
  194.       ad.set(1,10,0);
  195.       theModel -> setCellToStringOrNumber(&ad,"Weekly",0, &me, NULL);
  196.       ad.set(1,11,0);
  197.       theModel -> setCellToString(&ad,per,0, &me, NULL);
  198.       ad.set(1,12,0);
  199.       theModel -> setCellToString(&ad,prate,0, &me, NULL);
  200.  
  201.       ad.set(4,0,0);
  202.       theModel -> setCellToString(&ad,"=i2",0, &me, NULL);
  203.       ad.set(4,1,0);
  204.       theModel -> setCellToString(&ad,"=0-pmt($m$2,$l$2,$g$2)",0, &me, NULL);
  205.       ad.set(4,2,0);
  206.       theModel -> setCellToString(&ad,"=$m$2*$g$2",0, &me, NULL);
  207.       ad.set(4,3,0);
  208.       theModel -> setCellToString(&ad,"=b5-c5",0, &me, NULL);
  209.       ad.set(4,4,0);
  210.       theModel -> setCellToString(&ad,"=g2-d5",0, &me, NULL);
  211.  
  212.       ad.set(5,0,0);
  213.       theModel -> setCellToString(&ad,"=if(((thisrow-4)<$l$2), (DATE((YEAR(A5)+(MONTH(A5)>11)),(MOD(MONTH(A5),12)+1),DAY(2))))",0, &me, NULL);
  214.       ad.set(5,1,0);
  215.       theModel -> setCellToString(&ad,"=if(((thisrow-4)<$l$2), (0-pmt($m$2,$l$2,$g$2))",0, &me, NULL);
  216.       ad.set(5,2,0);
  217.       theModel -> setCellToString(&ad,"=if(((thisrow-4)<$l$2), ($m$2*$e5)",0, &me, NULL);
  218.       ad.set(5,3,0);
  219.       theModel -> setCellToString(&ad,"=if(((thisrow-4)<$l$2), (b6-c6)",0, &me, NULL);
  220.       ad.set(5,4,0);
  221.       theModel -> setCellToString(&ad,"=if(((thisrow-4)<$l$2), (e5-d6)",0, &me, NULL);
  222.  
  223.   // format and smartfill according to periods at [A]L2 in the model
  224.       ad.set(5,0,0);
  225.       ad2.set(31,0,0);
  226.       ra.set(&ad,&ad2);
  227.       theModel -> fillSmartDown(&ra,0,NULL,&me);
  228.  
  229.       ad.set(5,1,0);
  230.       ad2.set(31,1,0);
  231.       ra.set(&ad,&ad2);
  232.       theModel -> fillSmartDown(&ra,0,NULL,&me);
  233.  
  234.       ad.set(5,2,0);
  235.       ad2.set(31,3,0);
  236.       ra.set(&ad,&ad2);
  237.       theModel -> fillSmartDown(&ra,0,NULL,&me);
  238.  
  239.       ad.set(5,3,0);
  240.       ad2.set(31,3,0);
  241.       ra.set(&ad,&ad2);
  242.       theModel -> fillSmartDown(&ra,0,NULL,&me);
  243.  
  244.       ad.set(5,4,0);
  245.       ad2.set(31,4,0);
  246.       ra.set(&ad,&ad2);
  247.       theModel -> fillSmartDown(&ra,0,NULL,&me);
  248.  
  249.       fo.free();
  250.       ra.free();
  251. }
  252.  
  253. struct _wdata{
  254.     MEditView *theEdit;
  255.     MMesaView *theView;
  256. };
  257.  
  258. // displays the internal model in sheetview format.
  259. MRESULT EXPENTRY ViewSheetProc(HWND hw,ULONG msg,MPARAM mp1,MPARAM mp2)
  260. {
  261.     _wdata * wd =(_wdata*) WinQueryWindowULong(hw,QWL_USER);
  262.     // get the pointer to the view
  263.     switch (msg) {
  264.     case WM_INITDLG :
  265.     {
  266.       MRect tre;
  267.       SWP swp;
  268.       wd = new _wdata;
  269.  
  270.       // query the position of where the sheet view is supposed to
  271.       // be placed
  272.         WinQueryWindowPos(WinWindowFromID(hw,DID_SHEETVIEW),&swp);
  273.         tre.setX(swp.x);
  274.         tre.setY(swp.y);
  275.         tre.setWid(swp.cx);
  276.         tre.setHi(swp.cy);
  277.       // create a new sheet view and set it up
  278.         wd->theView = new MMesaView(0,currentModel);
  279.       wd->theView->setHWND(hw);
  280.         wd->theView -> setUp(&tre);
  281.       wd->theEdit=NULL;
  282.       // save the pointer to the view in the ULong so we can delete it later
  283.       WinSetWindowULong(hw,QWL_USER,(ULONG)wd);
  284.       MyMesa->setHandleForEditViewOwner(hw);
  285.       WinPostMsg(hw,WM_UPDATEFORMULA,NULL,NULL);
  286.     }
  287.     break;
  288.  case WM_DESTROY:
  289.     {
  290.       // cleans it up and deletes it
  291.       if (wd->theEdit) {
  292.           wd->theEdit->cleanUp();
  293.           delete wd->theEdit;
  294.       } // endif
  295.       wd->theView->cleanUp();
  296.       delete wd->theView;
  297.       MyMesa->setHandleForEditViewOwner(0L);
  298.     }
  299.     break;
  300. case WM_UPDATEFORMULA:
  301. {
  302.        char *tmp;
  303.        tmp=wd->theView -> getSelectionContents();
  304.        WinSetDlgItemText(hw,DID_FORMULA,tmp);
  305.        MFree(tmp);
  306. }
  307.     break;
  308. case WM_CREATEEDIT:
  309. {
  310.    if (wd->theEdit) { // get rid of old one
  311.        wd->theEdit->cleanUp();
  312.        delete wd->theEdit;
  313.    } // endif
  314.  
  315.       MRect tre;
  316.       SWP swp;
  317.  
  318.       // query the position of where the edit view is supposed to
  319.       // be placed
  320.         WinQueryWindowPos(WinWindowFromID(hw,DID_FORMULA),&swp);
  321.         tre.setX(swp.x);
  322.         tre.setY(swp.y);
  323.         tre.setWid(swp.cx);
  324.         tre.setHi(swp.cy);
  325.  
  326.     wd->theEdit = new MEditView(0);
  327.     wd->theEdit->setHWND(hw);
  328.     wd->theEdit -> setEditString( (MEditString *)mp1);
  329.     wd->theEdit -> setUp(&tre);
  330. }
  331.     break;
  332. case WM_REMOVEEDIT:
  333.     if (wd->theEdit) {
  334.         wd->theEdit -> cleanUp();
  335.         WinDestroyWindow( wd->theEdit -> getView() );
  336.         delete wd->theEdit;
  337.         wd->theEdit=NULL;
  338.     } // endif
  339.     break;
  340. case WM_INCELLEDIT:
  341.     return (MRESULT)WinSendMsg(WinWindowFromID(hw,DID_INCELL),BM_QUERYCHECK,NULL,NULL);
  342.     break;
  343. case WM_SETFORMULATXT:
  344.      WinSetDlgItemText(hw,DID_FORMULA,(PCHAR)mp1);
  345.     break;
  346. case WM_GETEDITVIEW:
  347.      return (MRESULT)wd->theEdit;
  348.     break;
  349.  default:
  350.     return WinDefDlgProc(hw,msg,mp1,mp2);
  351.    break;
  352.  } /* endswitch */
  353.  return (MRESULT)FALSE;
  354. }
  355.  
  356.  
  357. // this is the constructor for creating a new purchase order.
  358. Loan::Loan(HWND hwnd)
  359. {
  360.   // create a new interest object
  361.   loint=new LOInterest(hwnd);
  362.   // create a new MesaModel and set it up
  363.   theModel=new MMesaModel;
  364.   theModel->setUp(MyMesa);
  365.   // add the formatting and titles appropriate for the purchase order
  366.   SetupNewLoan(theModel);
  367.   // set the pathname to nothing
  368.   theModel->setPathName("",0);
  369.   // register the interest in the model
  370.   theModel->registerInterest(loint);
  371.   // we aren't in the sheet view on startup
  372.   inSheetView=0;
  373. }
  374.  
  375.  
  376. // this is the constructor for createing a PO from a file
  377. Loan::Loan(char * filename,HWND hwnd)
  378. {
  379.   MException me;
  380.  
  381.   // create the interest object
  382.   loint=new LOInterest(hwnd);
  383.   // create a new mesamodel and set it up with the controller
  384.   theModel=new MMesaModel;
  385.   theModel->setUp(MyMesa);
  386.   // set the path name
  387.   theModel->setPathName(filename,0);
  388.   // have the model load it's info from the file
  389.   theModel->loadFromPath(0,&me);
  390.   // register the information
  391.   theModel->registerInterest(loint);
  392.   // we aren't in the sheet view on startup
  393.   inSheetView=0;
  394. }
  395.  
  396. // the PO destructor
  397. Loan::~Loan()
  398. {
  399.  // unregister the interest.  If there are no other interests (should be in our case)
  400.  // the model will automatically delete itself so we don't have to do it here.
  401.  // if there is another interest out there someplace, the model will be deleted
  402.  // when that interest is done with the model
  403.  theModel->unregisterInterest(loint);
  404.  // delete the interest object
  405.  delete loint;
  406. }
  407.  
  408.  
  409. // returns the Loan ID as a string
  410. char *Loan::LoanID()
  411. {
  412.    char * str,*str2;
  413.    MAddress ad;
  414.  
  415.    // get the loan ID from [A]A2 in the model
  416.    ad.set(1,0,0);
  417.    str=theModel->getCellValue(&ad);
  418.    stripEndingSpace(str);
  419.  
  420.    // copy the resulting string to a new string that uses the
  421.    // compiler memory management instead of Mesa's.  Thus, the returned
  422.    // string can just be deleted with delete str instead of using MFree()
  423.    str2=new char[MStrLen(str)+1];
  424.    strcpy(str2,str);
  425.  
  426.    // free the memory and return the string
  427.    MFree(str);
  428.    return str2;
  429. }
  430.  
  431.  
  432. char *Loan::AppDate()
  433. {
  434.    char * str,*str2;
  435.    MAddress ad;
  436.  
  437.    // get the date from [A]B2 in the model
  438.    ad.set(1,1,0);
  439.    str=theModel->getCellValue(&ad);
  440.    stripEndingSpace(str);
  441.  
  442.    // copy the resulting string to a new string that uses the
  443.    // compiler memory management instead of Mesa's.  Thus, the returned
  444.    // string can just be deleted with delete str instead of using MFree()
  445.    str2=new char[MStrLen(str)+1];
  446.    strcpy(str2,str);
  447.  
  448.    // free the memory and return the string
  449.    MFree(str);
  450.    return str2;
  451. }
  452.  
  453. char *Loan::RepID()
  454. {
  455.    char * str,*str2;
  456.    MAddress ad;
  457.  
  458.    // get the representative ID from [A]C2 in the model
  459.    ad.set(1,2,0);
  460.    str=theModel->getCellValue(&ad);
  461.    stripEndingSpace(str);
  462.  
  463.    // copy the resulting string to a new string that uses the
  464.    // compiler memory management instead of Mesa's.  Thus, the returned
  465.    // string can just be deleted with delete str instead of using MFree()
  466.    str2=new char[MStrLen(str)+1];
  467.    strcpy(str2,str);
  468.  
  469.    // free the memory and return the string
  470.    MFree(str);
  471.    return str2;
  472. }
  473.  
  474. char *Loan::Name()
  475. {
  476.    char * str,*str2;
  477.    MAddress ad;
  478.  
  479.    // get the applicants name from [A]D2 in the model
  480.    ad.set(1,3,0);
  481.    str=theModel->getCellValue(&ad);
  482.    stripEndingSpace(str);
  483.  
  484.    // copy the resulting string to a new string that uses the
  485.    // compiler memory management instead of Mesa's.  Thus, the returned
  486.    // string can just be deleted with delete str instead of using MFree()
  487.    str2=new char[MStrLen(str)+1];
  488.    strcpy(str2,str);
  489.  
  490.    // free the memory and return the string
  491.    MFree(str);
  492.    return str2;
  493. }
  494.  
  495. char *Loan::SSNo()
  496. {
  497.    char * str,*str2;
  498.    MAddress ad;
  499.  
  500.    // get the applicants SS # from [A]E2 in the model
  501.    ad.set(1,4,0);
  502.    str=theModel->getCellValue(&ad);
  503.    stripEndingSpace(str);
  504.  
  505.    // copy the resulting string to a new string that uses the
  506.    // compiler memory management instead of Mesa's.  Thus, the returned
  507.    // string can just be deleted with delete str instead of using MFree()
  508.    str2=new char[MStrLen(str)+1];
  509.    strcpy(str2,str);
  510.  
  511.    // free the memory and return the string
  512.    MFree(str);
  513.    return str2;
  514. }
  515.  
  516. char *Loan::Type()
  517. {
  518.    char * str,*str2;
  519.    MAddress ad;
  520.  
  521.    // get the loan type from [A]F2 in the model
  522.    ad.set(1,5,0);
  523.    str=theModel->getCellValue(&ad);
  524.    stripEndingSpace(str);
  525.  
  526.    // copy the resulting string to a new string that uses the
  527.    // compiler memory management instead of Mesa's.  Thus, the returned
  528.    // string can just be deleted with delete str instead of using MFree()
  529.    str2=new char[MStrLen(str)+1];
  530.    strcpy(str2,str);
  531.  
  532.    // free the memory and return the string
  533.    MFree(str);
  534.    return str2;
  535. }
  536.  
  537. char *Loan::Amount()
  538. {
  539.    char * str,*str2;
  540.    MAddress ad;
  541.    stripEndingSpace(str);
  542.  
  543.    // get the loan amount from [A]G2 in the model
  544.    ad.set(1,6,0);
  545.    str=theModel->getCellValue(&ad);
  546.  
  547.    // copy the resulting string to a new string that uses the
  548.    // compiler memory management instead of Mesa's.  Thus, the returned
  549.    // string can just be deleted with delete str instead of using MFree()
  550.    str2=new char[MStrLen(str)+1];
  551.    strcpy(str2,str);
  552.  
  553.    // free the memory and return the string
  554.    MFree(str);
  555.    return str2;
  556. }
  557.  
  558. char *Loan::Rate()
  559. {
  560.    char * str,*str2;
  561.    MAddress ad;
  562.  
  563.    // get the interest rate from [A]H2 in the model
  564.    ad.set(1,7,0);
  565.    str=theModel->getCellValue(&ad);
  566.    stripEndingSpace(str);
  567.  
  568.    // copy the resulting string to a new string that uses the
  569.    // compiler memory management instead of Mesa's.  Thus, the returned
  570.    // string can just be deleted with delete str instead of using MFree()
  571.    str2=new char[MStrLen(str)+1];
  572.    strcpy(str2,str);
  573.  
  574.    // free the memory and return the string
  575.    MFree(str);
  576.    return str2;
  577. }
  578.  
  579. char *Loan::StDate()
  580. {
  581.    char * str,*str2;
  582.    MAddress ad;
  583.  
  584.    // get the start date from [A]I2 in the model
  585.    ad.set(1,8,0);
  586.    str=theModel->getCellValue(&ad);
  587.  
  588.    // copy the resulting string to a new string that uses the
  589.    // compiler memory management instead of Mesa's.  Thus, the returned
  590.    // string can just be deleted with delete str instead of using MFree()
  591.    str2=new char[MStrLen(str)+1];
  592.    strcpy(str2,str);
  593.  
  594.    // free the memory and return the string
  595.    MFree(str);
  596.    return str2;
  597. }
  598.  
  599. char *Loan::Duration()
  600. {
  601.    char * str,*str2;
  602.    MAddress ad;
  603.  
  604.    // get the duration from [A]J2 in the model
  605.    ad.set(1,9,0);
  606.    str=theModel->getCellValue(&ad);
  607.  
  608.    // copy the resulting string to a new string that uses the
  609.    // compiler memory management instead of Mesa's.  Thus, the returned
  610.    // string can just be deleted with delete str instead of using MFree()
  611.    str2=new char[MStrLen(str)+1];
  612.    strcpy(str2,str);
  613.  
  614.    // free the memory and return the string
  615.    MFree(str);
  616.    return str2;
  617. }
  618.  
  619. char *Loan::Periodicity()
  620. {
  621.    char * str,*str2;
  622.    MAddress ad;
  623.  
  624.    // get the periodicity from [A]K2 in the model
  625.    ad.set(1,10,0);
  626.    str=theModel->getCellValue(&ad);
  627.  
  628.    // copy the resulting string to a new string that uses the
  629.    // compiler memory management instead of Mesa's.  Thus, the returned
  630.    // string can just be deleted with delete str instead of using MFree()
  631.    str2=new char[MStrLen(str)+1];
  632.    strcpy(str2,str);
  633.  
  634.    // free the memory and return the string
  635.    MFree(str);
  636.    return str2;
  637. }
  638.  
  639.  
  640. void Loan::setLoanID(char * str)
  641. {
  642.    MException me;
  643.    MAddress ad;
  644.  
  645.    // set the Loan ID at [A]A2 in the model
  646.    if (!inSheetView) {
  647.       ad.set(1,0,0);
  648.       theModel->setCellToString(&ad,str,0,&me,NULL);
  649.    } /* endif */
  650. }
  651.  
  652. void Loan::setAppDate(char *str)
  653. {
  654.    MException me;
  655.    MAddress ad;
  656.  
  657.    // set the date at [A]B2 in the model
  658.    if (!inSheetView) {
  659.       ad.set(1,1,0);
  660.       theModel->setCellToString(&ad,str,0,&me,NULL);
  661.    }
  662. }
  663.  
  664. void Loan::setRepID(char *str)
  665. {
  666.    MException me;
  667.    MAddress ad;
  668.  
  669.    // set the representative ID at [A]C2 in the model
  670.    if (!inSheetView) {
  671.       ad.set(1,2,0);
  672.       theModel->setCellToString(&ad,str,0,&me,NULL);
  673.    }
  674. }
  675.  
  676. void Loan::setName(char *str)
  677. {
  678.    MException me;
  679.    MAddress ad;
  680.  
  681.    // set the applicants name at [A]D2 in the model
  682.    if (!inSheetView) {
  683.       ad.set(1,3,0);
  684.       theModel->setCellToString(&ad,str,0,&me,NULL);
  685.    }
  686. }
  687.  
  688. void Loan::setSSNo(char *str)
  689. {
  690.    MException me;
  691.    MAddress ad;
  692.  
  693.    // set the applicants SS # at [A]E2 in the model
  694.    if (!inSheetView) {
  695.       ad.set(1,4,0);
  696.       theModel->setCellToString(&ad,str,0,&me,NULL);
  697.    }
  698. }
  699.  
  700. void Loan::setType(char *str)
  701. {
  702.    MException me;
  703.    MAddress ad;
  704.  
  705.    // set the loan type at [A]F2 in the model
  706.    if (!inSheetView) {
  707.       ad.set(1,5,0);
  708.       theModel->setCellToString(&ad,str,0,&me,NULL);
  709.    }
  710. }
  711.  
  712. void Loan::setAmount(char *str)
  713. {
  714.    MException me;
  715.    MAddress ad;
  716.  
  717.    // set the loan amount at [A]G2 in the model
  718.    if (!inSheetView) {
  719.       ad.set(1,6,0);
  720.       stripDollarAndCommas(str);
  721.       theModel->setCellToString(&ad,str,0,&me,NULL);
  722.    }
  723. }
  724.  
  725. void Loan::setRate(char *str)
  726. {
  727.    MException me;
  728.    MAddress ad;
  729.  
  730.    // set the interest rate at [A]H2 in the model
  731.    if (!inSheetView) {
  732.       ad.set(1,7,0);
  733.       theModel->setCellToString(&ad,str,0,&me,NULL);
  734.    }
  735. }
  736.  
  737. void Loan::setStDate(char *str)
  738. {
  739.    MException me;
  740.    MAddress ad;
  741.  
  742.    // set the start date at [A]I2 in the model
  743.    if (!inSheetView) {
  744.       ad.set(1,8,0);
  745.       theModel->setCellToString(&ad,str,0,&me,NULL);
  746.    }
  747. }
  748.  
  749. void Loan::setDuration(char *str)
  750. {
  751.    MException me;
  752.    MAddress ad;
  753.  
  754.    // set the duration at [A]J2 in the model
  755.    if (!inSheetView) {
  756.       ad.set(1,9,0);
  757.       theModel->setCellToString(&ad,str,0,&me,NULL);
  758.    }
  759. }
  760.  
  761. void Loan::setPeriodicity(char *str)
  762. {
  763.    MException me;
  764.    MAddress ad;
  765.  
  766.    // set the periodicity at [A]K2 in the model
  767.    if (!inSheetView) {
  768.       ad.set(1,10,0);
  769.       theModel->setCellToString(&ad,str,0,&me,NULL);
  770.    }
  771. }
  772.  
  773. void Loan::setPeriods()
  774. {
  775.    int nper;
  776.    MAddress ad,ad2;
  777.    MException me;
  778.    MRange ra;
  779.  
  780.    // format and smartfill according to periods at [A]L2 in the model
  781.       ad.set(1,11,0);
  782.       nper=atoi(theModel->getCellValue(&ad));
  783.       nper+= 4;
  784.  
  785.       ad.set(4,0,0);
  786.       ad2.set(nper,0,0);
  787.       ra.set(&ad,&ad2);
  788.       theModel -> fillSmartDown(&ra,0,NULL,&me);
  789. }
  790.  
  791.  
  792. // returns the filename that is stored in the model
  793. char *Loan::fileName()
  794. {
  795.    char *str,*str2;
  796.  
  797.    str=theModel->getPathName();
  798.    str2=new char[MStrLen(str)+1];
  799.    strcpy(str2,str);
  800.    MFree(str);
  801.    return str;
  802. }
  803.  
  804. // sets the filename in the model
  805. void Loan::setFileName(char * name)
  806. {
  807.    theModel->setPathName(name,0);
  808. }
  809.  
  810. // saves the model to the filename stored in the model
  811. void Loan::save()
  812. {
  813.    MException me;
  814.    theModel->saveToPath(&me);
  815. }
  816.  
  817. // pops up the dialog with the sheet view in it
  818. void Loan::displaySheetView(HWND hw)
  819. {
  820.   currentModel=theModel;
  821.   inSheetView=1;
  822.   WinDlgBox(HWND_DESKTOP,hw,ViewSheetProc,NULL,IDD_VIEWSHEET,0L);
  823.   inSheetView=0;
  824. }
  825.  
  826.