Advertisement
Guest User

Untitled

a guest
Mar 1st, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 18.62 KB | None | 0 0
  1.  //-----___-----___-----___-----____
  2.  //                                 |
  3.  //  HealthCare Pharmacy            |
  4.  //  Pricing and Monitoring System  |
  5.  //                                 |
  6.  //_____---_____---_____---_____---_|
  7.  
  8.  #include <stdio.h>
  9.  #include <conio.h>
  10.  #include <ctype.h>
  11.  #include <string.h>
  12.  #include <dos.h>
  13.  #include "stdlib.h"
  14.  
  15.  #define PIECES 50
  16.  #define DISCOUNT 0.03
  17.  #define MAXPWD 15
  18.  
  19.  void details();
  20.  void add_item();
  21.  void search_item();
  22.  void search_by_brand();
  23.  void reports();
  24.  void main_header();
  25.  void pressany();
  26.  void date2day(int col, int row);
  27.  void next_page();
  28.  void log_in();
  29.  void menu();
  30.  int Password(int,int);
  31.  int FindItemCode(char [],int);
  32.  
  33.  
  34.  char TypePassword[MAXPWD];
  35.  
  36.  struct Drug
  37.  {
  38.      char ItemCode[10];
  39.      char BrandName[20];
  40.      char Description[20];
  41.      char Generic[20];
  42.      char Manufacturer[20];
  43.      char Indication[30];
  44.      char ItemLoc[30];
  45.  
  46.      struct {
  47.      float UnitPrice;
  48.      float Sum;
  49.      float BoxPrice;
  50.      float totDiscount;
  51.      } Prices;
  52.  };
  53.  
  54.  struct User
  55.  {
  56.     char currentUser[15];
  57.     char currentPass[15];
  58.     char Pharmacist[15];
  59.     char *Pharmacist2;
  60.     char PPassword[10];
  61.     char *PPassword2;
  62.     char Salesman[15];
  63.     char *Salesman2;
  64.     char *SPassword2;
  65.     char SPassword[10];
  66.  };
  67.  
  68.  struct Drug DrugRec;
  69.  
  70.  struct User UserRec;
  71.  
  72.  FILE *PharmacyFile, *TempFile;
  73.  
  74.  char PharmacyFileDir[] = "C:\\PHARMACY.DAT";
  75.  char TempFileDir[] = "C:\\TEMP.DAT";
  76.  
  77.  void main()
  78.  {
  79.    textcolor(WHITE);
  80.    //Wrapped it with a do while
  81.    do {
  82.    log_in();}
  83.    while(1);
  84.  }
  85.  
  86.   /* This is the main part of the program, the User's Log in */
  87.  void log_in()
  88.  {
  89.    char UserAns;
  90.    UserRec.Pharmacist2 = "pharmacist";
  91.    UserRec.PPassword2 = "drug";
  92.    UserRec.Salesman2 = "salesperson";
  93.    UserRec.SPassword2 = "cash";
  94.    strcpy(UserRec.Pharmacist, UserRec.Pharmacist2); /* assigning value     */
  95.    strcpy(UserRec.Salesman, UserRec.Salesman2);     /* for the             */
  96.    strcpy(UserRec.PPassword, UserRec.PPassword2);   /* username & password */
  97.    strcpy(UserRec.SPassword, UserRec.SPassword2);   /*                     */
  98.    clrscr();
  99.    main_header();
  100.    gotoxy(25,8);printf("User's Log-In:");
  101.    gotoxy(28,10); printf("Username: ");
  102.    gotoxy(28,11); printf("Password: ");
  103.    fflush(stdin);gotoxy(38,10);gets(UserRec.currentUser); /* inputs the user name */
  104.    fflush(stdin);gotoxy(38,11);Password(38,11);           /* then the password    */
  105.  
  106.    if (strcmp(UserRec.currentUser,UserRec.Pharmacist) == 0 && strcmp(TypePassword,UserRec.PPassword) == 0)
  107.    {
  108.       menu();
  109.    }
  110.    else
  111.      if (strcmp(UserRec.currentUser,UserRec.Salesman) == 0 && strcmp(TypePassword,UserRec.SPassword) == 0)
  112.      {
  113.       menu();
  114.      }
  115.    else {
  116.      gotoxy(20,14);printf("Unknown Username & Password! ");
  117.      gotoxy(20,15);printf("Do you want to Log-in again? [Y]es/[N]o");
  118.      UserAns = toupper(getche());
  119.       switch (UserAns)
  120.       {
  121.      case 'Y':
  122.        //ANKIT CHANGE
  123.        //Commented out main()
  124.            break;
  125.     default:
  126.        exit(1);
  127.        break;
  128.       }
  129.    }
  130.  }
  131.  /***End**/
  132.  
  133.  
  134.  void pressany()
  135.  {
  136.    textcolor(WHITE);
  137.    gotoxy(51,25);cprintf("<<press any key to continue>>");
  138.    getch();
  139.  }
  140.  
  141.  void main_header()
  142.  {
  143.    int col;
  144.    textcolor(LIGHTGRAY);
  145.    for (col=3; col<=78; col++) {
  146.        gotoxy(col,1); cprintf("Ä"); /* displays a horizontal line  */
  147.        gotoxy(col,3); cprintf("Ä"); /* at the top of the screen    */
  148.        gotoxy(col,25); cprintf("Ä");
  149.    }
  150.     gotoxy(30,2); textcolor(WHITE);cprintf("HealthCare Pharmacy");
  151.     date2day(60,1);
  152.     textcolor(WHITE);
  153.  }
  154.  
  155.  //****Function to display the current date
  156.  void  date2day(int col, int row)
  157.  {
  158.    struct date d;
  159.    getdate(&d);
  160.    textcolor(WHITE);
  161.    gotoxy(col,row); cprintf("[ Date: %d-%d-%d ]", d.da_day, d.da_mon, d.da_year);
  162.  }
  163.  
  164.  void details()
  165.  {
  166.    //These function displays the label for each input
  167.    gotoxy(6,8);  printf("Item Code                  :   ");
  168.    gotoxy(6,9);  printf("Generic Name               :   ");
  169.    gotoxy(6,10); printf("Brand Name                 :   ");
  170.    gotoxy(6,11); printf("Drug Indication            :   ");
  171.    gotoxy(6,12); printf("Description                :   ");
  172.    gotoxy(6,13); printf("Manufacturer's Name        :   ");
  173.    gotoxy(6,15); printf("Individual Price           : P ");
  174.    gotoxy(6,16); printf("Price per Box (50 Pieces)  : P ");
  175.    gotoxy(6,18); printf("Item Location              :   ");
  176.  }
  177.  
  178.  void choices()
  179.  {
  180.    textcolor(WHITE);
  181.    gotoxy(3,6); cprintf("[N]ew/Add Item ³ Search [I]temCode/[B]randName ³ [V]iew All  ³ [E]xit Program");
  182.    gotoxy(3,4); cprintf("Welcome, %s", UserRec.currentUser);
  183.    gotoxy(3,24);cprintf("[R]e-Log In");
  184.    textcolor(GREEN);
  185.    gotoxy(4,6);cprintf("N"); gotoxy(28,6);cprintf("I"); gotoxy(39,6);cprintf("B");
  186.    gotoxy(53,6);cprintf("V"); gotoxy(67,6);cprintf("E");
  187.    gotoxy(4,24);cprintf("R");textcolor(WHITE);
  188.    gotoxy(3,10); cprintf("Select your Choice: ");
  189.    textcolor(WHITE);
  190.  }
  191.  
  192.  void menu()
  193.  {
  194.    //***** Enter choices from the main menu  *****/
  195.    char UserChoice;
  196.    do {
  197.    clrscr();
  198.    main_header();
  199.    choices();
  200.    gotoxy(23,10);
  201.    UserChoice = toupper(getche());
  202.    if (isalpha(UserChoice))
  203.    {
  204.       switch(UserChoice)
  205.       {
  206.       case 'R':
  207.          log_in();
  208.          break;
  209.       case 'N':
  210.          if (strcmp(UserRec.currentUser,UserRec.Pharmacist) != 0)
  211.          {
  212.            gotoxy(23,14);printf("Error:");
  213.            gotoxy(26,15); printf("You are not Allowed to Add!!");
  214.            gotoxy(26,16); printf("Please Log-in as Pharmacist..");
  215.            pressany();
  216.            getch();
  217.          }
  218.          else {
  219.            add_item(); }
  220.          break;
  221.       case 'I':
  222.          if (strcmp(UserRec.currentUser,UserRec.Pharmacist) != 0)
  223.          {
  224.            gotoxy(23,14);printf("Error:");
  225.            gotoxy(26,15); printf("You are not Allowed to Search by Item!!");
  226.            gotoxy(26,16); printf("Please Log-in as Pharmacist..");
  227.            pressany();
  228.            getch();
  229.          }
  230.          else {
  231.            search_item(); }
  232.          break;
  233.       case 'V':
  234.          reports();
  235.          break;
  236.       case 'B':
  237.          search_by_brand();
  238.          break;
  239.       case 'E':
  240.          exit(1);
  241.          break;
  242.       default:
  243.          gotoxy(16,16); printf("Error:");
  244.          gotoxy(19,17);
  245.          printf("Please select the letters enclosed with [brackets] only!");
  246.          pressany();
  247.       }
  248.      }
  249.    else {
  250.     gotoxy(20,16); printf("Error: Please select letters only!.");
  251.     pressany(); }
  252.    } while (UserChoice != 'E');
  253.  }
  254.  
  255.  /** Function to hide the characters of the password */
  256.  /** being typed, and replace it with asterisk(*)    */
  257.  int Password(int col,int row)
  258.  {
  259.    char letter;
  260.    int index=0,lcontinue=1;
  261.    do {
  262.       letter = getch();
  263.       if (letter != 13 && letter != '\b' && index < MAXPWD) {
  264.       gotoxy(col,row);printf("*");
  265.       TypePassword[index] = letter;
  266.       index++;
  267.       col++;
  268.       }
  269.       if (letter == '\b' && index != 0) {
  270.       col--;
  271.       gotoxy(col,row);printf(" ");
  272.       gotoxy(col,row);
  273.       TypePassword[index] = '\b';
  274.       index--;
  275.     }
  276.       if (letter == 13)
  277.       lcontinue = 0;
  278.    } while (lcontinue);
  279.    return 0;
  280.  }
  281.  /**** End of Function ***/
  282.  
  283.  
  284.  /** Function for adding a new item in the pharmacy**/
  285.  void add_item()
  286.  {
  287.    char UserAns;
  288.    int Result;
  289.    clrscr();
  290.    gotoxy(3,6); printf("ADD NEW ITEM");
  291.    main_header();
  292.    details();
  293.    PharmacyFile = fopen(PharmacyFileDir,"r");
  294.    fclose(PharmacyFile);
  295.    gotoxy(3,4); printf("Welcome, %s", UserRec.currentUser);
  296.    fflush(stdin); gotoxy(35,8); gets(DrugRec.ItemCode);
  297.    fflush(stdin); gotoxy(35,9); gets(DrugRec.Generic);
  298.    fflush(stdin); gotoxy(35,10); gets(DrugRec.BrandName);
  299.    fflush(stdin); gotoxy(35,11); gets(DrugRec.Indication);
  300.    fflush(stdin); gotoxy(35,12); gets(DrugRec.Description);
  301.    fflush(stdin); gotoxy(35,13); gets(DrugRec.Manufacturer);
  302.    fflush(stdin); gotoxy(37,15); scanf("%f", &DrugRec.Prices.UnitPrice);
  303.  
  304.    if (DrugRec.Prices.UnitPrice == 0)
  305.    {
  306.       gotoxy(23,20);printf("Some of the data that you have entered");
  307.       gotoxy(23,21);printf("are INVALID or some fields are EMPTY");
  308.       gotoxy(23,22);printf("Try again? [Y]es/[N]o or press any key to Exit");
  309.       UserAns = toupper(getche());
  310.       switch (UserAns)
  311.       {
  312.      case 'Y':
  313.         add_item();
  314.         break;
  315.      default:
  316.         menu();
  317.         break;
  318.       }
  319.    }
  320.    else{
  321.    //******* Calculates the discount ***************************************//
  322.  
  323.    DrugRec.Prices.Sum = DrugRec.Prices.UnitPrice * PIECES;
  324.    DrugRec.Prices.totDiscount = DrugRec.Prices.Sum * DISCOUNT;
  325.    DrugRec.Prices.BoxPrice = DrugRec.Prices.Sum - DrugRec.Prices.totDiscount;
  326.  
  327.    //******* End of Calculation *******************************************//
  328.  
  329.    fflush(stdin); gotoxy(37,16); printf("%0.2f", DrugRec.Prices.BoxPrice);
  330.    fflush(stdin); gotoxy(35,18); gets(DrugRec.ItemLoc);
  331.    gotoxy(23,21); printf("Save Current Item? [Y]es/[N]o");
  332.    gotoxy(23,22); printf("Or Press [C] to Clear All Fields");
  333.    UserAns = toupper(getche());
  334.  
  335.    if(UserAns == 'Y')
  336.    {
  337.     PharmacyFile = fopen(PharmacyFileDir,"a+");
  338.     if(PharmacyFile != NULL)
  339.     {
  340.       if(!FindItemCode(DrugRec.ItemCode,0))
  341.       {
  342.     if(fwrite(&DrugRec,sizeof(DrugRec),1,PharmacyFile)) {
  343.       gotoxy(23,22);clreol(); gotoxy(23,21); clreol();
  344.       gotoxy(25,21);cprintf("|| Item has been Saved!.||");
  345.     }
  346.     else
  347.     {
  348.       gotoxy(23,22);clreol(); gotoxy(23,21); clreol();
  349.       gotoxy(27,20);cprintf("Error: Item Cannot be Saved!.");
  350.        }
  351.       }
  352.       else
  353.       {
  354.        gotoxy(23,22);clreol(); gotoxy(23,21); clreol();
  355.        gotoxy(27,21);cprintf("Error: Item Code is already in use.");}
  356.       }
  357.       else
  358.       {
  359.       gotoxy(23,22);clreol(); gotoxy(23,21); clreol();
  360.       gotoxy(27,21);cprintf("Error: Cannot Open the File.");}
  361.    }
  362.    else
  363.       if (UserAns == 'C')
  364.       add_item();
  365.  
  366.    else  {
  367.       gotoxy(23,22);clreol(); gotoxy(23,21); clreol();
  368.       gotoxy(27,21);cprintf("|| Saving Canceled! ||");
  369.    }
  370.   }
  371.       pressany();
  372.       fclose(PharmacyFile);
  373.  }
  374.  /*End of Function*/
  375.  
  376.  
  377.   /** Function that searches a specific */
  378.   /** item by entering the brand name     */
  379.   void search_by_brand()
  380.   {
  381.     char UserAns,FindCode[10];
  382.     char UserChoice;
  383.     struct Drug UpdateDrugRec;
  384.     int EndOfFile,Found = 0;
  385.     clrscr();
  386.     main_header();
  387.     gotoxy(3,6); printf("SEARCH BY BRAND NAME (CaSe SenSiTivE)");
  388.     details();
  389.     gotoxy(3,4); printf("Welcome, %s", UserRec.currentUser);
  390.     fflush(stdin);gotoxy(35,10);gets(FindCode);
  391.     PharmacyFile = fopen(PharmacyFileDir,"r");
  392.     if(PharmacyFile != NULL)
  393.     {
  394.       fread(&DrugRec,sizeof(DrugRec),1,PharmacyFile);
  395.       while(!feof(PharmacyFile) && Found == 0 )
  396.       {
  397.     if (strcmp(FindCode,DrugRec.BrandName) == 0 )
  398.      {
  399.        gotoxy(35,8); printf(DrugRec.ItemCode);
  400.        gotoxy(35,9); printf(DrugRec.Generic);
  401.        gotoxy(35,11);printf(DrugRec.Indication);
  402.        gotoxy(35,12);printf(DrugRec.Description);
  403.        gotoxy(35,13);printf(DrugRec.Manufacturer);
  404.        gotoxy(37,15);printf("%0.2f", DrugRec.Prices.UnitPrice);
  405.        gotoxy(37,16);printf("%0.2f",DrugRec.Prices.BoxPrice);
  406.        gotoxy(35,18);printf(DrugRec.ItemLoc);
  407.        Found = 1;
  408.      }
  409.       fread(&DrugRec,sizeof(DrugRec),1,PharmacyFile);
  410.       }
  411.     }
  412.     fclose(PharmacyFile);
  413.     if (!Found)
  414.     {
  415.        gotoxy(27,21);printf("Item Cannot be Found!!!");
  416.        gotoxy(27,22); cprintf("Search Again? [Y]es/[N]o");
  417.        UserAns = toupper(getche());
  418.        if (UserAns == 'Y')  {
  419.      search_by_brand();
  420.        }
  421.        else {
  422.     menu();
  423.        }
  424.        }
  425.     if (Found)
  426.      {
  427.       gotoxy(27,22); cprintf("Search Again? [Y]es/[N]o");
  428.       UserAns = toupper(getche());
  429.       if (UserAns == 'Y')  {
  430.      search_by_brand();
  431.       }
  432.       else {
  433.     menu();
  434.       }
  435.  
  436.   }
  437.  }
  438.  /* End */
  439.  
  440.   /** Function that searches a specific */
  441.   /** item by entering the ItemCode     */
  442.   void search_item()
  443.   {
  444.     char UserAns,FindCode[10];
  445.     char UserChoice;
  446.     struct Drug UpdateDrugRec;
  447.     int EndOfFile,Found = 0;
  448.     clrscr();
  449.     main_header();
  450.     gotoxy(3,6); printf("SEARCH ITEM");
  451.     details();
  452.     gotoxy(3,4); printf("Welcome, %s", UserRec.currentUser);
  453.     fflush(stdin);gotoxy(35,8);gets(FindCode);
  454.     PharmacyFile = fopen(PharmacyFileDir,"r");
  455.     if(PharmacyFile != NULL)
  456.     {
  457.       fread(&DrugRec,sizeof(DrugRec),1,PharmacyFile);
  458.       while(!feof(PharmacyFile) && Found == 0 )
  459.       {
  460.     if (strcmp(FindCode,DrugRec.ItemCode) == 0 )
  461.      {
  462.        gotoxy(35,9); printf(DrugRec.Generic);
  463.        gotoxy(35,10); printf(DrugRec.BrandName);
  464.        gotoxy(35,11);printf(DrugRec.Indication);
  465.        gotoxy(35,12);printf(DrugRec.Description);
  466.        gotoxy(35,13);printf(DrugRec.Manufacturer);
  467.        gotoxy(37,15);printf("%0.2f", DrugRec.Prices.UnitPrice);
  468.        gotoxy(37,16);printf("%0.2f",DrugRec.Prices.BoxPrice);
  469.        gotoxy(35,18);printf(DrugRec.ItemLoc);
  470.        Found = 1;
  471.      }
  472.       fread(&DrugRec,sizeof(DrugRec),1,PharmacyFile);
  473.       }
  474.     }
  475.     fclose(PharmacyFile);
  476.     if (!Found)
  477.     {
  478.       gotoxy(28,21);printf("Item Cannnot be Found!!!"); /* displays when a certain*/
  479.       gotoxy(28,22);cprintf("Search Again? [Y]es/[N]o");/* item is not found      */
  480.       UserAns = toupper(getche());
  481.       if (UserAns == 'Y')  {
  482.      search_item();
  483.       }
  484.       else {
  485.     menu();
  486.       }
  487.     }
  488.     if (Found)
  489.      {
  490.       gotoxy(21,21); cprintf("What would you like to do with this record?");
  491.       gotoxy(21,22); cprintf("[U]pdate, [D]elete or press Any key to return to Main");
  492.       UserChoice = toupper(getche());
  493.       switch (UserChoice)
  494.       {
  495.     case 'U':
  496.       gotoxy(21,22);clreol(); gotoxy(21,21); clreol();
  497.       gotoxy(25,21);cprintf("   Update Item? [Y]es/[N]o:");
  498.       UserAns = toupper(getche());
  499.       if (UserAns == 'Y')
  500.       {
  501.         gotoxy(25,21);clreol();
  502.         fclose(PharmacyFile);
  503.         fflush(stdin);gotoxy(37,15);scanf("%f",&UpdateDrugRec.Prices.UnitPrice);
  504.         gotoxy(25,21);cprintf("Save?  [Y]es/[N]o   ");
  505.         UserAns = toupper(getche());
  506.         if(UserAns == 'Y')
  507.         { //ANKIT added a 0 not sure !
  508.         if(!FindItemCode(UpdateDrugRec.ItemCode,0))
  509.         {
  510.           PharmacyFile = fopen(PharmacyFileDir,"r");
  511.           TempFile = fopen(TempFileDir,"a+");
  512.           do{
  513.              fread(&DrugRec,sizeof(DrugRec),1,PharmacyFile);
  514.              if(!feof(PharmacyFile)){
  515.                if(strcmp(FindCode,DrugRec.ItemCode) != 0){
  516.              fwrite(&DrugRec,sizeof(DrugRec),1,TempFile);
  517.              EndOfFile = 1;
  518.                }else{
  519.             DrugRec.Prices.Sum = DrugRec.Prices.UnitPrice * PIECES;
  520.             DrugRec.Prices.totDiscount = DrugRec.Prices.Sum * DISCOUNT;
  521.             DrugRec.Prices.BoxPrice = DrugRec.Prices.Sum - DrugRec.Prices.totDiscount;
  522.  
  523.             /***Overwrites the Current Record  */
  524.             UpdateDrugRec.Prices.Sum = UpdateDrugRec.Prices.UnitPrice * PIECES;
  525.             UpdateDrugRec.Prices.totDiscount = UpdateDrugRec.Prices.Sum * DISCOUNT;
  526.             UpdateDrugRec.Prices.BoxPrice = UpdateDrugRec.Prices.Sum - DrugRec.Prices.totDiscount;
  527.  
  528.             DrugRec.Prices.UnitPrice = UpdateDrugRec.Prices.UnitPrice;
  529.             DrugRec.Prices.BoxPrice = UpdateDrugRec.Prices.BoxPrice;
  530.             fwrite(&DrugRec,sizeof(DrugRec),1,TempFile);
  531.                }
  532.               }else
  533.                EndOfFile = 0;
  534.         }while(EndOfFile);
  535.  
  536.         fcloseall();
  537.         if(remove(PharmacyFileDir)==0){
  538.              rename(TempFileDir,PharmacyFileDir);
  539.             gotoxy(25,21);clreol();gotoxy(22,21);cprintf(" || Item has been Updated! ||");
  540.         }
  541.         else{
  542.              gotoxy(22,21);printf("Error occurs during update..");
  543.         }
  544.            }
  545.            else
  546.         {  gotoxy(22,21);printf("ItemCode already in use.");}
  547.         }
  548.          else
  549.         {gotoxy(25,21);clreol();gotoxy(22,21);printf("   || Updating Cancelled. ||");}
  550.      }
  551.      else
  552.         {gotoxy(25,21);clreol();gotoxy(20,21);printf("   || Updating Cancelled ||");}
  553.  
  554.      pressany();
  555.     break;
  556.  
  557.     case 'D':
  558.     gotoxy(21,22);clreol(); gotoxy(21,21); clreol();
  559.     /*Function to Delete a specific item*/
  560.     gotoxy(21,21);printf("Delete this Item? [Y]es/[N]o: ");
  561.     UserAns = toupper(getche());
  562.     if (UserAns == 'Y')
  563.     {
  564.      PharmacyFile = fopen(PharmacyFileDir,"r");
  565.      TempFile = fopen(TempFileDir,"w");
  566.      do {
  567.       fread(&DrugRec,sizeof(DrugRec),1,PharmacyFile);
  568.       if(!feof(PharmacyFile)){
  569.        if(strcmp(FindCode,DrugRec.ItemCode) != 0)
  570.       fwrite(&DrugRec,sizeof(DrugRec),1,TempFile);
  571.     EndOfFile = 1;
  572.     }
  573.      else
  574.     EndOfFile = 0;
  575.      }while(EndOfFile);
  576.       fcloseall();
  577.       if(remove(PharmacyFileDir)==0){
  578.     rename(TempFileDir,PharmacyFileDir);
  579.     gotoxy(21,21);clreol();
  580.     gotoxy(23,21);printf("|| Item has been Deleted! ||");
  581.       }
  582.       else{
  583.       gotoxy(21,21);clreol();
  584.       gotoxy(23,21);printf("Error occurs during deletion..");
  585.       }
  586.      }
  587.      else
  588.      {
  589.        gotoxy(21,21);clreol();
  590.        gotoxy(23,21);printf("  Deletion Canceled.");}
  591.        pressany();
  592.        break;
  593.        default:
  594.        break;
  595.     }
  596.      }
  597.   }
  598.  
  599.  
  600.  
  601.  void reports()
  602.  {
  603.    int r,row = 7;
  604.    int page = 1;
  605.    clrscr();
  606.    for (r=3; r<=78; r++) {
  607.        gotoxy(r,4); printf("-");
  608.        gotoxy(r,6); printf("-");
  609.    }
  610.    gotoxy(3,5); printf("ItemCode"); gotoxy(15,5);printf("GenericName");
  611.    gotoxy(40,5); printf("BrandName"); gotoxy(55,5);printf("UnitPrice");
  612.    gotoxy(69,5); printf("Per Box");
  613.    main_header();
  614.    gotoxy(3,3); printf("³ List of all Items");
  615.    PharmacyFile = fopen(PharmacyFileDir,"r");
  616.    fread(&DrugRec,sizeof(DrugRec),1,PharmacyFile);
  617.    while(!feof(PharmacyFile))
  618.    {
  619.        gotoxy(3,row);printf(DrugRec.ItemCode);
  620.        gotoxy(15,row);printf(DrugRec.Generic);
  621.        gotoxy(40,row);printf(DrugRec.BrandName);
  622.        gotoxy(55,row);printf("P %0.2f", DrugRec.Prices.UnitPrice);
  623.        gotoxy(69,row);printf("P %0.2f", DrugRec.Prices.BoxPrice);
  624.        gotoxy(3,25);cprintf("Page %d", page);
  625.        row++;
  626.        if(row == 23)
  627.        {
  628.     pressany();
  629.     getch();
  630.     row = 7;
  631.     page++;
  632.     next_page();
  633.        }
  634.        fread(&DrugRec,sizeof(DrugRec),1,PharmacyFile);
  635.    }
  636.    
  637.    //ANKIT CHANGED (20,25) to ()
  638.    pressany();
  639.  
  640.  }
  641.  
  642.  void next_page()
  643.  {
  644.    int r;
  645.    clrscr();
  646.    for (r=3; r<=78; r++) {
  647.        gotoxy(r,4); printf("-");
  648.        gotoxy(r,6); printf("-");
  649.    }
  650.    gotoxy(3,5); printf("ItemCode"); gotoxy(15,5);printf("GenericName");
  651.    gotoxy(40,5); printf("BrandName"); gotoxy(55,5);printf("UnitPrice");
  652.    gotoxy(69,5); printf("Per Box");
  653.    main_header();
  654.    gotoxy(3,3); cprintf("³ List of all Items");
  655.  }
  656.  
  657.  int FindItemCode(char FindCode[10],int FindOp)
  658.  {
  659.    int CodeFound = 0;
  660.    struct Drug FindRec;
  661.    FILE *SearchFile;
  662.    SearchFile = fopen(PharmacyFileDir,"r");
  663.    if(SearchFile != NULL)
  664.    {
  665.      while(!feof(SearchFile) && CodeFound == 0)
  666.      {
  667.     fread(&FindRec,sizeof(FindRec),1,SearchFile);
  668.     if(!FindOp)
  669.        if(strcmp(FindCode,FindRec.ItemCode) == 0)
  670.           CodeFound = 1;
  671.     else
  672.        if(FindRec.ItemCode != FindCode)
  673.           if(strcmp(FindCode,FindRec.ItemCode) == 0)
  674.         CodeFound = 1;
  675.      }
  676.    }
  677.      return CodeFound;
  678.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement