home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dokpr1.zip / posys / porder.cpp < prev    next >
Text File  |  1995-11-09  |  24KB  |  899 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 "posys.h"
  12. #include "porder.hpp"
  13. #include "interest.h"
  14. #include "editview.h"
  15.  
  16. extern MSampleController *MyMesa;
  17. MMesaModel * currentModel;
  18.  
  19.  
  20.  
  21. // we can't send strings like "$2,150.23" into a cell so we need to
  22. // strip out the '$' and the ',' to make it "2150.23".  this procedure
  23. // accomplishes that
  24. void stripDollarAndCommas(char *str)
  25. {
  26.    char *str2 = new char[strlen(str)+1];
  27.    int x=0,y=0;
  28.  
  29.    for (x=0;x < strlen(str)+1 ; x++) {
  30.       if ((str[x] != '$') && (str[x] != ',') &&(str[x] != ' ')) {
  31.          str2[y]=str[x];
  32.          y++;
  33.       } /* endif */
  34.    } /* endfor */
  35.    strcpy(str,str2);
  36.    delete str2;
  37. }
  38.  
  39.  
  40. // this is a major hack.  Right now, any cell that has formattings set
  41. // when the value is queried, it comes back with an extra space at the
  42. // end.  This function strips the space to make it work correctly.
  43. void stripEndingSpace(char *str)
  44. {
  45.    if (str[MStrLen(str)-1] == ' ') {
  46.       str[MStrLen(str)-1]='\0';
  47.    } /* endif */
  48. }
  49.  
  50.  
  51.  
  52. // as mentioned in porder.hpp, the POInterest methods mostly just post messages
  53. // to the window so it knows what is going on in it's model
  54. POInterest::POInterest(HWND hw) : MInterest()
  55. {
  56.    theWin=hw;
  57. }
  58.  
  59. POInterest::~POInterest()
  60. {
  61. }
  62.  
  63. void POInterest::redisplay(MChange *mc)
  64. {
  65.    WinPostMsg(theWin,PO_REDISPLAY,(MPARAM)mc,0L);
  66. }
  67. void POInterest::changedSize(MChange *mc)
  68. {
  69.    WinPostMsg(theWin,PO_CHANGEDSIZE,(MPARAM)mc,0L);
  70. }
  71. void POInterest::formatsChanged(MChange *mc)
  72. {
  73.    WinPostMsg(theWin,PO_FORMATSCHANGED,(MPARAM)mc,0L);
  74. }
  75. void POInterest::contentsChanged(MChange *mc)
  76. {
  77.    WinPostMsg(theWin,PO_CONTENTSCHANGED,(MPARAM)mc,0L);
  78. }
  79. void POInterest::resetView(MChange *mc)
  80. {
  81.    WinPostMsg(theWin,PO_RESETVIEW,(MPARAM)mc,0L);
  82. }
  83.  
  84.  
  85. // this function sets up a new PO by formatting the top layer of the
  86. // model and inserting the appropriate titles and formulas
  87. void SetupNewPO(MMesaModel * theModel)
  88. {
  89.     MRange ra;
  90.     MFormat fo;
  91.     MException me;
  92.     MAddress ad,ad2;
  93.  
  94.       fo.init();
  95.         fo.setMergePrecision(1);
  96.         fo.setMergeFormat(1);
  97.       fo.setFormat(generalAlignment);
  98.  
  99.       ad.set(0,0,0);
  100.       ad2.set(31,13,0);
  101.       ra.init();
  102.       ra.set(&ad,&ad2);
  103.           theModel -> setRangeToFormat(&ra,&fo,defaultAction,NULL,&me);
  104.  
  105.         fo.setFormat(currencyTypeFormat |currencySubtypeFormat | 2);
  106.  
  107.       ad.set(1,4,0);
  108.       ad2.set(31,4,0);
  109.       ra.set(&ad,&ad2);
  110.           theModel -> setRangeToFormat(&ra,&fo,defaultAction,NULL,&me);
  111.  
  112.       ad.set(1,6,0);
  113.       ad2.set(31,6,0);
  114.       ra.set(&ad,&ad2);
  115.           theModel -> setRangeToFormat(&ra,&fo,defaultAction,NULL,&me);
  116.  
  117.       ad.set(1,7,0);
  118.       ra.set(&ad,&ad);
  119.           theModel -> setRangeToFormat(&ra,&fo,defaultAction,NULL,&me);
  120.       ad.set(1,9,0);
  121.       ra.set(&ad,&ad);
  122.           theModel -> setRangeToFormat(&ra,&fo,defaultAction,NULL,&me);
  123.       ad.set(1,10,0);
  124.       ra.set(&ad,&ad);
  125.           theModel -> setRangeToFormat(&ra,&fo,defaultAction,NULL,&me);
  126.       ad.set(1,11,0);
  127.       ra.set(&ad,&ad);
  128.           theModel -> setRangeToFormat(&ra,&fo,defaultAction,NULL,&me);
  129.  
  130.       fo.setFormat(dateFormat);
  131.       ad.set(1,1,0);
  132.       ra.set(&ad,&ad);
  133.           theModel -> setRangeToFormat(&ra,&fo,defaultAction,NULL,&me);
  134.  
  135.       fo.setFormat(percentFormat);
  136.       ad.set(1,8,0);
  137.       ra.set(&ad,&ad);
  138.           theModel -> setRangeToFormat(&ra,&fo,defaultAction,NULL,&me);
  139.  
  140.         ad.set(0,0,0);
  141.         theModel -> setCellToStringOrNumber(&ad,"PO Num",0,&me,NULL);
  142.         ad.set(0,1,0);
  143.         theModel -> setCellToStringOrNumber(&ad,"Date",0,&me,NULL);
  144.         ad.set(0,2,0);
  145.         theModel -> setCellToStringOrNumber(&ad,"Initials",0,&me,NULL);
  146.         ad.set(0,3,0);
  147.         theModel -> setCellToStringOrNumber(&ad,"Descriptions",0,&me,NULL);
  148.         ad.set(0,4,0);
  149.         theModel -> setCellToStringOrNumber(&ad,"Cost",0,&me,NULL);
  150.         ad.set(0,5,0);
  151.         theModel -> setCellToStringOrNumber(&ad,"Qty.",0,&me,NULL);
  152.         ad.set(0,6,0);
  153.         theModel -> setCellToStringOrNumber(&ad,"Total",0,&me,NULL);
  154.         ad.set(0,7,0);
  155.         theModel -> setCellToStringOrNumber(&ad,"Sub Total",0,&me,NULL);
  156.         ad.set(0,12,0);
  157.         theModel -> setCellToStringOrNumber(&ad,"Comments",0,&me,NULL);
  158.         ad.set(0,13,0);
  159.         theModel -> setCellToStringOrNumber(&ad,"Flags",0,&me,NULL);
  160.         ad.set(0,8,0);
  161.         theModel -> setCellToStringOrNumber(&ad,"Tax Rate",0,&me,NULL);
  162.         ad.set(0,9,0);
  163.         theModel -> setCellToStringOrNumber(&ad,"Tax",0,&me,NULL);
  164.         ad.set(0,10,0);
  165.         theModel -> setCellToStringOrNumber(&ad,"Shipping",0,&me,NULL);
  166.         ad.set(0,11,0);
  167.         theModel -> setCellToStringOrNumber(&ad,"Total",0,&me,NULL);
  168.  
  169.         ad.set(1,7,0);
  170.         theModel -> setCellToString(&ad,"=sum(G2:G32)",0,&me,NULL);
  171.         ad.set(1,9,0);
  172.         theModel -> setCellToString(&ad,"=h2*i2",0,&me,NULL);
  173.                 ad.set(1,10,0);
  174.                 theModel -> setCellToStringOrNumber(&ad,"$0.00",0,&me,NULL);
  175.         ad.set(1,11,0);
  176.         theModel -> setCellToString(&ad,"=j2+h2+k2",0,&me,NULL);
  177.         ad.set(1,6,0);
  178.         theModel -> setCellToString(&ad,"=e2*f2",0,&me,NULL);
  179.       ad2.set(21,6,0);
  180.       ra.set(&ad,&ad2);
  181.       theModel -> fillSmartDown(&ra,0,NULL,&me);
  182.  
  183.       fo.free();
  184.       ra.free();
  185. }
  186.  
  187. struct _wdata{
  188.     MEditView *theEdit;
  189.     MMesaView *theView;
  190. };
  191.  
  192. // displays the internal model in sheetview format.
  193. MRESULT EXPENTRY ViewSheetProc(HWND hw,ULONG msg,MPARAM mp1,MPARAM mp2)
  194. {
  195.     _wdata * wd =(_wdata*) WinQueryWindowULong(hw,QWL_USER);
  196.     // get the pointer to the view
  197.     switch (msg) {
  198.     case WM_INITDLG :
  199.     {
  200.       MRect tre;
  201.       SWP swp;
  202.       wd = new _wdata;
  203.  
  204.       // query the position of where the sheet view is supposed to
  205.       // be placed
  206.         WinQueryWindowPos(WinWindowFromID(hw,DID_SHEETVIEW),&swp);
  207.         tre.setX(swp.x);
  208.         tre.setY(swp.y);
  209.         tre.setWid(swp.cx);
  210.         tre.setHi(swp.cy);
  211.       // create a new sheet view and set it up
  212.         wd->theView = new MMesaView(0,currentModel);
  213.       wd->theView->setHWND(hw);
  214.         wd->theView -> setUp(&tre);
  215.       wd->theEdit=NULL;
  216.       // save the pointer to the view in the ULong so we can delete it later
  217.       WinSetWindowULong(hw,QWL_USER,(ULONG)wd);
  218.       MyMesa->setHandleForEditViewOwner(hw);
  219.       WinPostMsg(hw,WM_UPDATEFORMULA,NULL,NULL);
  220.     }
  221.     break;
  222.  case WM_DESTROY:
  223.     {
  224.       // clean it ups and delete it
  225.       if (wd->theEdit) {
  226.           wd->theEdit->cleanUp();
  227.           delete wd->theEdit;
  228.       } // endif
  229.       wd->theView->cleanUp();
  230.       delete wd->theView;
  231.       MyMesa->setHandleForEditViewOwner(0L);
  232.     }
  233.     break;
  234. case WM_UPDATEFORMULA:
  235. {
  236.        char *tmp;
  237.        tmp=wd->theView -> getSelectionContents();
  238.        WinSetDlgItemText(hw,DID_FORMULA,tmp);
  239.        MFree(tmp);
  240. }
  241.     break;
  242. case WM_CREATEEDIT:
  243. {
  244.    if (wd->theEdit) { // get rid of old one
  245.        wd->theEdit->cleanUp();
  246.        delete wd->theEdit;
  247.    } // endif
  248.  
  249.       MRect tre;
  250.       SWP swp;
  251.  
  252.       // query the position of where the edit view is supposed to
  253.       // be placed
  254.         WinQueryWindowPos(WinWindowFromID(hw,DID_FORMULA),&swp);
  255.         tre.setX(swp.x);
  256.         tre.setY(swp.y);
  257.         tre.setWid(swp.cx);
  258.         tre.setHi(swp.cy);
  259.  
  260.     wd->theEdit = new MEditView(0);
  261.     wd->theEdit->setHWND(hw);
  262.     wd->theEdit -> setEditString( (MEditString *)mp1);
  263.     wd->theEdit -> setUp(&tre);
  264. }
  265.     break;
  266. case WM_REMOVEEDIT:
  267.     if (wd->theEdit) {
  268.         wd->theEdit -> cleanUp();
  269.         WinDestroyWindow( wd->theEdit -> getView() );
  270.         delete wd->theEdit;
  271.         wd->theEdit=NULL;
  272.     } // endif
  273.     break;
  274. case WM_INCELLEDIT:
  275.     return (MRESULT)WinSendMsg(WinWindowFromID(hw,DID_INCELL),BM_QUERYCHECK,NULL,NULL);
  276.     break;
  277. case WM_SETFORMULATXT:
  278.      WinSetDlgItemText(hw,DID_FORMULA,(PCHAR)mp1);
  279.     break;
  280. case WM_GETEDITVIEW:
  281.      return (MRESULT)wd->theEdit;
  282.     break;
  283.  default:
  284.     return WinDefDlgProc(hw,msg,mp1,mp2);
  285.    break;
  286.  } /* endswitch */
  287.  return (MRESULT)FALSE;
  288. }
  289.  
  290.  
  291. // this is the constructor for creating a new purchase order.
  292. POrder::POrder(HWND hwnd)
  293. {
  294.   // create a new interest object
  295.   point=new POInterest(hwnd);
  296.   // create a new MesaModel and set it up
  297.   theModel=new MMesaModel;
  298.   theModel->setUp(MyMesa);
  299.   // add the formatting and titles appropriate for the purchase order
  300.   SetupNewPO(theModel);
  301.   // set the pathname to nothing
  302.   theModel->setPathName("",0);
  303.   // register the interest in the model
  304.   theModel->registerInterest(point);
  305.   // we aren't in the sheet view on startup
  306.   inSheetView=0;
  307. }
  308.  
  309.  
  310. // this is the constructor for createing a PO from a file
  311. POrder::POrder(char * filename,HWND hwnd)
  312. {
  313.   MException me;
  314.  
  315.   // create the interest object
  316.   point=new POInterest(hwnd);
  317.   // create a new mesamodel and set it up with the controller
  318.   theModel=new MMesaModel;
  319.   theModel->setUp(MyMesa);
  320.   // set the path name
  321.   theModel->setPathName(filename,0);
  322.   // have the model load it's info from the file
  323.   theModel->loadFromPath(0,&me);
  324.   // register the information
  325.   theModel->registerInterest(point);
  326.   // we aren't in the sheet view on startup
  327.   inSheetView=0;
  328. }
  329.  
  330. // the PO destructor
  331. POrder::~POrder()
  332. {
  333.  // unregister the interest.  If there are no other interests (should be in our case)
  334.  // the model will automatically delete itself so we don't have to do it here.
  335.  // if there is another interest out there someplace, the model will be deleted
  336.  // when that interest is done with the model
  337.  theModel->unregisterInterest(point);
  338.  // delete the interest object
  339.  delete point;
  340. }
  341.  
  342.  
  343. // returns the PO number as a string
  344. char *POrder::PONum()
  345. {
  346.    char * str,*str2;
  347.    MAddress ad;
  348.  
  349.    // get the po number from [A]A2 in the model
  350.    ad.set(1,0,0);
  351.    str=theModel->getCellValue(&ad);
  352.    stripEndingSpace(str);
  353.  
  354.    // copy the resulting string to a new string that uses the
  355.    // compiler memory management instead of Mesa's.  Thus, the returned
  356.    // string can just be deleted with delete str instead of using MFree()
  357.    str2=new char[MStrLen(str)+1];
  358.    strcpy(str2,str);
  359.  
  360.    // free the memory and return the string
  361.    MFree(str);
  362.    return str2;
  363. }
  364.  
  365.  
  366. char *POrder::Date()
  367. {
  368.    char * str,*str2;
  369.    MAddress ad;
  370.  
  371.    // get the date from [A]B2 in the model
  372.    ad.set(1,1,0);
  373.    str=theModel->getCellValue(&ad);
  374.    stripEndingSpace(str);
  375.  
  376.    // copy the resulting string to a new string that uses the
  377.    // compiler memory management instead of Mesa's.  Thus, the returned
  378.    // string can just be deleted with delete str instead of using MFree()
  379.    str2=new char[MStrLen(str)+1];
  380.    strcpy(str2,str);
  381.  
  382.    // free the memory and return the string
  383.    MFree(str);
  384.    return str2;
  385. }
  386.  
  387. char *POrder::Initials()
  388. {
  389.    char * str,*str2;
  390.    MAddress ad;
  391.  
  392.    // get the initials from [A]C2 in the model
  393.    ad.set(1,2,0);
  394.    str=theModel->getCellValue(&ad);
  395.    stripEndingSpace(str);
  396.  
  397.    // copy the resulting string to a new string that uses the
  398.    // compiler memory management instead of Mesa's.  Thus, the returned
  399.    // string can just be deleted with delete str instead of using MFree()
  400.    str2=new char[MStrLen(str)+1];
  401.    strcpy(str2,str);
  402.  
  403.    // free the memory and return the string
  404.    MFree(str);
  405.    return str2;
  406. }
  407.  
  408. char *POrder::SubTotal()
  409. {
  410.    char * str,*str2;
  411.    MAddress ad;
  412.  
  413.    // get the subtotal from [A]H2 in the model
  414.    ad.set(1,7,0);
  415.    str=theModel->getCellValue(&ad);
  416.    stripEndingSpace(str);
  417.  
  418.    // copy the resulting string to a new string that uses the
  419.    // compiler memory management instead of Mesa's.  Thus, the returned
  420.    // string can just be deleted with delete str instead of using MFree()
  421.    str2=new char[MStrLen(str)+1];
  422.    strcpy(str2,str);
  423.  
  424.    // free the memory and return the string
  425.    MFree(str);
  426.    return str2;
  427. }
  428.  
  429. char *POrder::Tax()
  430. {
  431.    char * str,*str2;
  432.    MAddress ad;
  433.  
  434.    // get the tax amount from [A]J2 in the model
  435.    ad.set(1,9,0);
  436.    str=theModel->getCellValue(&ad);
  437.    stripEndingSpace(str);
  438.  
  439.    // copy the resulting string to a new string that uses the
  440.    // compiler memory management instead of Mesa's.  Thus, the returned
  441.    // string can just be deleted with delete str instead of using MFree()
  442.    str2=new char[MStrLen(str)+1];
  443.    strcpy(str2,str);
  444.  
  445.    // free the memory and return the string
  446.    MFree(str);
  447.    return str2;
  448. }
  449.  
  450. char *POrder::TaxRate()
  451. {
  452.    char * str,*str2;
  453.    MAddress ad;
  454.  
  455.    // get the tax rate from [A]I2 in the model
  456.    ad.set(1,8,0);
  457.    str=theModel->getCellValue(&ad);
  458.    stripEndingSpace(str);
  459.  
  460.    // copy the resulting string to a new string that uses the
  461.    // compiler memory management instead of Mesa's.  Thus, the returned
  462.    // string can just be deleted with delete str instead of using MFree()
  463.    str2=new char[MStrLen(str)+1];
  464.    strcpy(str2,str);
  465.  
  466.    // free the memory and return the string
  467.    MFree(str);
  468.    return str2;
  469. }
  470.  
  471. char *POrder::Shipping()
  472. {
  473.    char * str,*str2;
  474.    MAddress ad;
  475.    stripEndingSpace(str);
  476.  
  477.    // get the shipping charges from [A]K2 in the model
  478.    ad.set(1,10,0);
  479.    str=theModel->getCellValue(&ad);
  480.  
  481.    // copy the resulting string to a new string that uses the
  482.    // compiler memory management instead of Mesa's.  Thus, the returned
  483.    // string can just be deleted with delete str instead of using MFree()
  484.    str2=new char[MStrLen(str)+1];
  485.    strcpy(str2,str);
  486.  
  487.    // free the memory and return the string
  488.    MFree(str);
  489.    return str2;
  490. }
  491.  
  492. char *POrder::Total()
  493. {
  494.    char * str,*str2;
  495.    MAddress ad;
  496.  
  497.    // get the total from [A]L2 in the model
  498.    ad.set(1,11,0);
  499.    str=theModel->getCellValue(&ad);
  500.    stripEndingSpace(str);
  501.  
  502.    // copy the resulting string to a new string that uses the
  503.    // compiler memory management instead of Mesa's.  Thus, the returned
  504.    // string can just be deleted with delete str instead of using MFree()
  505.    str2=new char[MStrLen(str)+1];
  506.    strcpy(str2,str);
  507.  
  508.    // free the memory and return the string
  509.    MFree(str);
  510.    return str2;
  511. }
  512.  
  513. char *POrder::Comments()
  514. {
  515.    char * str,*str2;
  516.    MAddress ad;
  517.  
  518.    // get the comments from [A]M2 in the model
  519.    ad.set(1,12,0);
  520.    str=theModel->getCellValue(&ad);
  521.  
  522.    // copy the resulting string to a new string that uses the
  523.    // compiler memory management instead of Mesa's.  Thus, the returned
  524.    // string can just be deleted with delete str instead of using MFree()
  525.    str2=new char[MStrLen(str)+1];
  526.    strcpy(str2,str);
  527.  
  528.    // free the memory and return the string
  529.    MFree(str);
  530.    return str2;
  531. }
  532.  
  533. char *POrder::Flags()
  534. {
  535.    char * str,*str2;
  536.    MAddress ad;
  537.  
  538.    // get the flags from [A]N1 in the model
  539.    ad.set(1,13,0);
  540.    str=theModel->getCellValue(&ad);
  541.  
  542.    // copy the resulting string to a new string that uses the
  543.    // compiler memory management instead of Mesa's.  Thus, the returned
  544.    // string can just be deleted with delete str instead of using MFree()
  545.    str2=new char[MStrLen(str)+1];
  546.    strcpy(str2,str);
  547.  
  548.    // free the memory and return the string
  549.    MFree(str);
  550.    return str2;
  551. }
  552.  
  553.  
  554. void POrder::setPONum(char * str)
  555. {
  556.    MException me;
  557.    MAddress ad;
  558.  
  559.    // set po number the at [A]A2 in the model
  560.    if (!inSheetView) {
  561.       ad.set(1,0,0);
  562.       theModel->setCellToString(&ad,str,0,&me,NULL);
  563.    } /* endif */
  564. }
  565.  
  566. void POrder::setDate(char *str)
  567. {
  568.    MException me;
  569.    MAddress ad;
  570.  
  571.    // set the date at [A]B2 in the model
  572.    if (!inSheetView) {
  573.       ad.set(1,1,0);
  574.       theModel->setCellToString(&ad,str,0,&me,NULL);
  575.    }
  576. }
  577.  
  578. void POrder::setInitials(char *str)
  579. {
  580.    MException me;
  581.    MAddress ad;
  582.  
  583.    // set the initials at [A]C2 in the model
  584.    if (!inSheetView) {
  585.       ad.set(1,2,0);
  586.       theModel->setCellToString(&ad,str,0,&me,NULL);
  587.    }
  588. }
  589.  
  590. void POrder::setTaxRate(char *str)
  591. {
  592.    MException me;
  593.    MAddress ad;
  594.  
  595.    // set the taxrate at [A]I2 in the model
  596.    if (!inSheetView) {
  597.       ad.set(1,8,0);
  598.       theModel->setCellToString(&ad,str,0,&me,NULL);
  599.    }
  600. }
  601.  
  602. void POrder::setShipping(char *str)
  603. {
  604.    MException me;
  605.    MAddress ad;
  606.  
  607.    // set the shipping charges at [A]K2 in the model
  608.    if (!inSheetView) {
  609.       ad.set(1,10,0);
  610.       stripDollarAndCommas(str);
  611.       theModel->setCellToString(&ad,str,0,&me,NULL);
  612.    }
  613. }
  614.  
  615. void POrder::setComments(char *str)
  616. {
  617.    MException me;
  618.    MAddress ad;
  619.  
  620.    // set the at [A]M2 in the model
  621.    if (!inSheetView) {
  622.       ad.set(1,12,0);
  623.       theModel->setCellToString(&ad,str,0,&me,NULL);
  624.    }
  625. }
  626.  
  627. void POrder::setFlags(char *str)
  628. {
  629.    MException me;
  630.    MAddress ad;
  631.  
  632.    // set the at [A]N2 in the model
  633.    if (!inSheetView) {
  634.       ad.set(1,13,0);
  635.       theModel->setCellToString(&ad,str,0,&me,NULL);
  636.    }
  637. }
  638.  
  639. void POrder::setItemCost(char *desc, char *cost)
  640. {
  641.    MAddress ad,ad2;
  642.    MException me;
  643.    MRange ra;
  644.  
  645.    // set the range in which to find the description
  646.    if (!inSheetView) {
  647.       ad.set(0,3,0);
  648.       ad2.set(31,3,0);
  649.       ra.init();
  650.       ra.set(&ad,&ad2);
  651.       ad2=theModel->find(desc,stringFindFlag,0,&ra,&ad);
  652.  
  653.       // once the cell for the description is found, advance 1 column
  654.       // to get the cost and set it to the new value.
  655.       ad2.setCol(ad2.getCol()+1);
  656.       stripDollarAndCommas(cost);
  657.       theModel->setCellToString(&ad2,cost,0,&me,NULL);
  658.    }
  659. }
  660.  
  661. void POrder::setItemQuantity(char *desc, char *quan)
  662. {
  663.    MAddress ad,ad2;
  664.    MException me;
  665.    MRange ra;
  666.  
  667.    // set the range in which to find the description
  668.    if (!inSheetView) {
  669.       ad.set(0,3,0);
  670.       ad2.set(31,3,0);
  671.       ra.init();
  672.       ra.set(&ad,&ad2);
  673.       ad2=theModel->find(desc,stringFindFlag,0,&ra,&ad);
  674.  
  675.       // once the cell for the description is found, advance 2 columns
  676.       // to get the quanitity and set it to the new value.
  677.       ad2.setCol(ad2.getCol()+2);
  678.       stripEndingSpace(quan);
  679.       theModel->setCellToString(&ad2,quan,0,&me,NULL);
  680.    }
  681. }
  682.  
  683. char *POrder::queryItemCost(char *desc)
  684. {
  685.    MAddress ad,ad2;
  686.    MRange ra;
  687.    char *str,*str2;
  688.  
  689.    // set the range in which to find the description
  690.    ad.set(0,3,0);
  691.    ad2.set(31,3,0);
  692.    ra.init();
  693.    ra.set(&ad,&ad2);
  694.    ad2=theModel->find(desc,stringFindFlag,0,&ra,&ad);
  695.  
  696.    // once the cell for the description is found, advance to next column
  697.    // to get the cost and get it.
  698.    ad2.setCol(ad2.getCol()+1);
  699.    str=theModel->getCellValue(&ad2);
  700.    // copy the resulting string to a new string that uses the
  701.    // compiler memory management instead of Mesa's.  Thus, the returned
  702.    // string can just be deleted with delete str instead of using MFree()
  703.    str2=new char[MStrLen(str)+1];
  704.    strcpy(str2,str);
  705.  
  706.    // free the memory and return the string
  707.    MFree(str);
  708.    return str2;
  709. }
  710.  
  711. char *POrder::queryItemQuantity(char *desc)
  712. {
  713.    MAddress ad,ad2;
  714.    MRange ra;
  715.    char *str,*str2;
  716.  
  717.    // set the range in which to find the description
  718.    ad.set(0,3,0);
  719.    ad2.set(31,3,0);
  720.    ra.init();
  721.    ra.set(&ad,&ad2);
  722.    ad2=theModel->find(desc,stringFindFlag,0,&ra,&ad);
  723.  
  724.    // once the cell for the description is found, advance 2 columns
  725.    // to get the quanitity and get it.
  726.    ad2.setCol(ad2.getCol()+2);
  727.    str=theModel->getCellValue(&ad2);
  728.    // copy the resulting string to a new string that uses the
  729.    // compiler memory management instead of Mesa's.  Thus, the returned
  730.    // string can just be deleted with delete str instead of using MFree()
  731.    str2=new char[MStrLen(str)+1];
  732.    strcpy(str2,str);
  733.  
  734.    // free the memory and return the string
  735.    MFree(str);
  736.    return str2;
  737. }
  738.  
  739. char *POrder::queryItemTotal(char *desc)
  740. {
  741.    MAddress ad,ad2;
  742.    MRange ra;
  743.    char *str,*str2;
  744.  
  745.    // set the range in which to find the description
  746.    ad.set(0,3,0);
  747.    ad2.set(31,3,0);
  748.    ra.init();
  749.    ra.set(&ad,&ad2);
  750.    ad2=theModel->find(desc,stringFindFlag,0,&ra,&ad);
  751.  
  752.    // once the cell for the description is found, advance 3 columns
  753.    // to get the items total and get it.
  754.    ad2.setCol(ad2.getCol()+3);
  755.    str=theModel->getCellValue(&ad2);
  756.    // copy the resulting string to a new string that uses the
  757.    // compiler memory management instead of Mesa's.  Thus, the returned
  758.    // string can just be deleted with delete str instead of using MFree()
  759.    str2=new char[MStrLen(str)+1];
  760.    strcpy(str2,str);
  761.  
  762.    // free the memory and return the string
  763.    MFree(str);
  764.    return str2;
  765. }
  766.  
  767. char *POrder::startEnumDescriptions()
  768. {
  769.    char *str,*str2;
  770.  
  771.    currentEnum.set(1,3,0);
  772.    str=theModel->getCellValue(¤tEnum);
  773.    // copy the resulting string to a new string that uses the
  774.    // compiler memory management instead of Mesa's.  Thus, the returned
  775.    // string can just be deleted with delete str instead of using MFree()
  776.    str2=new char[MStrLen(str)+1];
  777.    strcpy(str2,str);
  778.  
  779.    // free the memory and return the string
  780.    MFree(str);
  781.    return str2;
  782. }
  783.  
  784. void POrder::endEnumDescriptions()
  785. {
  786.    currentEnum.set(0,3,0);
  787. }
  788.  
  789. char *POrder::nextDescription()
  790. {
  791.    char *str,*str2;
  792.  
  793.    currentEnum.setRow(currentEnum.getRow()+1);
  794.    str=theModel->getCellValue(¤tEnum);
  795.    // copy the resulting string to a new string that uses the
  796.    // compiler memory management instead of Mesa's.  Thus, the returned
  797.    // string can just be deleted with delete str instead of using MFree()
  798.    str2=new char[MStrLen(str)+1];
  799.    strcpy(str2,str);
  800.  
  801.    // free the memory and return the string
  802.    MFree(str);
  803.    return str2;
  804. }
  805.  
  806.  
  807. // returns the filename that is stored in the model
  808. char *POrder::fileName()
  809. {
  810.    char *str,*str2;
  811.  
  812.    str=theModel->getPathName();
  813.    str2=new char[MStrLen(str)+1];
  814.    strcpy(str2,str);
  815.    MFree(str);
  816.    return str;
  817. }
  818.  
  819. // sets the filename in the model
  820. void POrder::setFileName(char * name)
  821. {
  822.    theModel->setPathName(name,0);
  823. }
  824.  
  825. // saves the model to the filename stored in the model
  826. void POrder::save()
  827. {
  828.    MException me;
  829.    theModel->saveToPath(&me);
  830. }
  831.  
  832. // pops up the dialog whith the sheet view in it
  833. void POrder::displaySheetView(HWND hw)
  834. {
  835.   currentModel=theModel;
  836.   inSheetView=1;
  837.   WinDlgBox(HWND_DESKTOP,hw,ViewSheetProc,NULL,IDD_VIEWSHEET,0L);
  838.   inSheetView=0;
  839. }
  840.  
  841. // adds an item to the PO
  842. void POrder::addItem(char *desc, char *cost ,char *quantity)
  843. {
  844.    MAddress ad,ad2;
  845.    MException me;
  846.  
  847.    // strip the extra formatting of the cost
  848.    stripDollarAndCommas(cost);
  849.  
  850.    // start at the bottom of the description column ([A]D32)
  851.    ad.set(31,3,0);
  852.    // find the first cell from the bottom that contains text
  853.    // equivilent to hitting <end><up> in Mesa 2
  854.    theModel->findPriorCellInCol(1,&ad,&ad2);
  855.    // we want the empty cell below it
  856.    ad2.setRow(ad2.getRow()+1);
  857.    // set the cell to the description
  858.    theModel->setCellToString(&ad2,desc,0,&me,NULL);
  859.    //set the cost and quantity
  860.    setItemCost(desc,cost);
  861.    setItemQuantity(desc,quantity);
  862. }
  863.  
  864. // deletes an item from the PO and shifts the items up to remove
  865. // any white space
  866. void POrder::deleteItem(char *desc)
  867. {
  868.    MAddress ad,ad2;
  869.    MRange ra;
  870.    MException me;
  871.    MFormat fo;
  872.    char *str,*str2;
  873.  
  874.    // set the range in which to find the description
  875.    ad.set(0,3,0);
  876.    ad2.set(31,3,0);
  877.    ra.init();
  878.    ra.set(&ad,&ad2);
  879.    ad2=theModel->find(desc,stringFindFlag,0,&ra,&ad);
  880.  
  881.    // once the description is found, we'll move everything
  882.    // bellow it up
  883.  
  884.    ad.set(31,5,0);
  885.    ad2.setRow(ad2.getRow()+1);
  886.    ra.set(&ad2,&ad);
  887.    ad.set(-1,0,0);
  888.    theModel->moveCells(&ra,&ad,0,&me,NULL);
  889.  
  890.    // reforma the bottom row
  891.    ad.set(31,4,0);
  892.    fo.init();
  893.    fo.setMergePrecision(1);
  894.    fo.setMergeFormat(1);
  895.    ra.set(&ad,&ad);
  896.    fo.setFormat(currencyTypeFormat |currencySubtypeFormat | 2);
  897.    theModel -> setRangeToFormat(&ra,&fo,defaultAction,NULL,&me);
  898. }
  899.