Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**********************************************************************************************************************
- This is to certify that this project is my own work, based on my personal efforts in studying and applying the concepts
- learned. I have constructed the functions and their respective algorithms and corresponding code by myself. The program
- was run, tested, and debugged by my own efforts. I further certify that I have not copied in part or whole or otherwise
- plagiarized the work of other students and/or persons.
- Rivera, Miguel Fernando Cua, 11610794
- **********************************************************************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #define MAX_CART 100
- #define MAX_CATEG 10
- typedef char string15[16];
- typedef char string20[21];
- typedef char string50[51];
- typedef char string8[9];
- typedef struct {
- string20 first,middle,last;
- }nameType; //Structure for the user's name
- typedef struct{
- nameType name;
- string50 address;
- }userInfoType; //Structure for user information
- typedef struct{
- string8 code;
- int qty;
- }prodBoughtType; //Structure for the cart
- typedef struct stockTag{
- string8 productcode;
- string15 supplier,
- product;
- int quantityavailable,
- quantitysold;
- float purchaseprice,
- unitsellingprice,
- discountrate;
- struct stockTag *pNext;
- }z; //Product List structure
- typedef struct stockTag stockType;
- typedef stockType * ptrStock;
- typedef struct{
- string15 category;
- ptrStock pFirstStock;
- } categoryType;
- typedef categoryType aStocks[10];
- //typedef struct stockTag stockType;
- //typedef stockType * ptrStock; //Stocks Structure
- typedef prodBoughtType arrBought[MAX_CART];
- struct userTag{
- string15 username,
- password;
- userInfoType info;
- char type;
- float creditlimit,
- outstanding;
- arrBought cart;
- int nItems,
- nLocked,
- nLoggedin,
- nCheckedout;
- struct userTag *pNext;
- };
- typedef struct userTag userType;
- typedef userType * ptrUser; //User Information Structure
- /*Function prodcode has 1 use:
- 1. Generates a product code
- @param i: index variable
- @param categoryinitial: holds first letter of category
- @param supplierinitial: holds first letter of supplier
- @param productinitial: holds first letter of product
- */
- stockType* prodcode (categoryType *pStock, aStocks *aCategories, int index)
- {
- int i;
- char categoryinitial = aCategories[index]->category[0];
- char supplierinitial = aCategories[index]->pFirstStock->supplier[0];
- char productinitial = aCategories[index]->pFirstStock->product[0];
- if (aCategories[index]->category==NULL)
- categoryinitial = 0;
- if (aCategories[index]->pFirstStock->supplier == NULL)
- supplierinitial = 0;
- if (aCategories[index]->pFirstStock->product == NULL)
- productinitial = 0;
- aCategories[index]->pFirstStock->productcode[0] = categoryinitial;
- aCategories[index]->pFirstStock->productcode[1] = supplierinitial;
- aCategories[index]->pFirstStock->productcode[2] = productinitial;
- for (i=3;i<8;i++)
- aCategories[index]->pFirstStock->productcode[i] = (rand() % 9) + '0';
- for (i=0;i<=2;i++){
- if (aCategories[index]->pFirstStock->productcode[i] > 'a' && aCategories[index]->pFirstStock->productcode[i] < 'z')
- aCategories[index]->pFirstStock->productcode[i] -= 32;
- }
- aCategories[index]->pFirstStock->productcode[8] = '\0';
- }
- /*Function search has 1 use:
- 1. Check if username exists
- @param i: index variable
- @param pRun: variable that runs through linked list
- */
- userType* search (userType* pFirst, string15 username)
- {
- ptrUser pRun;
- pRun = pFirst;
- while (pRun != NULL && strcmp(username, pRun->username)!=0)
- pRun = pRun->pNext;
- return pRun;
- }
- /*Function searchStock has 1 use:
- 1. Check if stock exists
- @param i: index variable
- */
- categoryType * searchStock (categoryType *pFirst, string15 product, aStocks *aCategories, int currCateg)
- {
- categoryType * pTemp;
- int i;
- pTemp->pFirstStock = aCategories[i]->pFirstStock;
- while (strcmp(pTemp->pFirstStock->product, product) != 0 && i < currCateg){
- pTemp->pFirstStock = pTemp->pFirstStock->pNext;
- if (pTemp->pFirstStock == NULL){
- i++;
- pTemp = aCategories[i];
- }
- }
- return pTemp;
- }
- /*Function searchCategory has 1 use:
- 1. Check if category exists
- @param i: index variable
- @param pRun: variable that runs through linked list
- */
- categoryType * searchCategory (string15 category, aStocks *aCategories, int currCateg)
- {
- categoryType * pRun;
- int i=0;
- pRun->pFirstStock = aCategories[i]->pFirstStock;
- while (i < currCateg && strcmp(category, pRun->category)!=0){
- pRun->pFirstStock = pRun->pFirstStock->pNext;
- if (pRun->pFirstStock == NULL){
- i++;
- pRun = aCategories[i];
- }
- }
- return pRun;
- }
- /*Function searchSupplier has 1 use:
- 1. Check if supplier exists
- @param i: index variable
- */
- categoryType * searchSupplier (string15 supplier, aStocks *aCategories, int currCateg)
- {
- int i = 0;
- categoryType* pRun;
- pRun->pFirstStock = aCategories[i]->pFirstStock;
- while (i < currCateg && strcmp(supplier, aCategories[i]->pFirstStock->supplier)!=0){
- pRun->pFirstStock = pRun->pFirstStock->pNext;
- if (pRun->pFirstStock == NULL){
- i++;
- pRun->pFirstStock = aCategories[i]->pFirstStock;
- }
- }
- return pRun;
- }
- /*Function searchProductCode has 1 use:
- 1. Check if product code exists
- @param pRun: variable that runs through linked list
- @param i: index variable
- */
- categoryType* searchProductCode (aStocks* aCategories, string8 productcode, int currCateg)
- {
- categoryType *pRun;
- int i = 0;
- pRun->pFirstStock = aCategories[i]->pFirstStock;
- while (strcmp(pRun->pFirstStock->productcode, productcode)!=0 && i < currCateg){
- pRun->pFirstStock = pRun->pFirstStock->pNext;
- if (pRun->pFirstStock == NULL){
- i++;
- pRun->pFirstStock = aCategories[i]->pFirstStock;
- }
- }
- return pRun;
- }
- /*Function InUnique has 1 use:
- 1. Check if username is unique
- @param pRun: variable that runs through linked list
- */
- int IsUnique (userType *pUsers, string15 username)
- {
- ptrUser pRun;
- pRun = pUsers;
- while (pRun != NULL && strcmp(username, pRun->username)!=0)
- pRun = pRun->pNext;
- if (pRun == NULL)
- return 1;
- else
- return 0;
- }
- /*Function InUniqueStock has 1 use:
- 1. Check if stock is unique
- @param i: index variable
- @param pRun: variable that runs through linked list
- */
- int IsUniqueStock (string15 product, aStocks *aCategories, int currCateg)
- {
- int i = 0;
- ptrStock pRun;
- pRun = aCategories[i]->pFirstStock;
- while (i <= currCateg && strcmp (product, pRun->product)!=0){
- pRun = pRun->pNext;
- if (pRun->pNext == NULL){
- i++;
- pRun = aCategories[i]->pFirstStock;
- }
- }
- if (i > currCateg)
- return 1;
- else if (strcmp (product, aCategories[i]->pFirstStock->product)==0)
- return 0;
- }
- /*Function AdminSaveInventory has 1 use:
- 1. Save Inventory to Text File
- @param i: index variable
- @param pText: file pointer
- @param strName: Name for file to be saved to
- @param pRun: variable that runs through linked list
- */
- void AdminSaveInventory (aStocks *aCategories)
- {
- FILE * pText;
- string20 strName;
- categoryType* pRun;
- int i;
- if (aCategories[i]->pFirstStock == NULL)
- printf("Nothing to save \n");
- else {
- printf("Enter file name");
- scanf("%s", strName);
- pRun = aCategories[i];
- pText = fopen(strName, "wt");
- if (pText != NULL){
- while (pRun != NULL){
- fprintf(pText, "%15s %8s %15s\n", pRun->category, pRun->pFirstStock->productcode,
- pRun->pFirstStock->product);
- //fprintf: file formated printing, for printing to a secondary memory
- fprintf(pText, "%d %.2f %15s \n", pRun->pFirstStock->quantityavailable,
- pRun->pFirstStock->purchaseprice, pRun->pFirstStock->supplier);
- fprintf(pText, "%.2f %.2f %d \n", pRun->pFirstStock->unitsellingprice,
- pRun->pFirstStock->discountrate, pRun->pFirstStock->quantitysold);
- pRun->pFirstStock = pRun->pFirstStock->pNext;
- if (pRun->pFirstStock->pNext == NULL)
- pRun = aCategories[i++];
- }
- fclose(pText);
- }
- else
- printf("Error creating file \n");
- }
- }
- /*Function AdminUpdateInventory has 1 use:
- 1. Load from Text File
- @param i: index variable
- @param pText: file pointer
- @param strName: Name for file to be saved to
- @param pRun: variable that runs through linked list
- @param category: temporary string input for category
- @param product: temporary string input for product
- @param supplier: temporary string input for supplier
- @param productcode: temporary string input for product code
- @param qtysold: temporary integer input for quantity sold
- @param qtyav: temporary integer input for quantity available
- @param pprice: temporary float input for purchase price
- @param usprice: temporary float input for unit selling price
- @param discount: temporary float input for discount
- @param cDump: character variable for dump
- @param pNew, pFirst, pRun: variables for cycling through linked list
- */
- void AdminUpdateInventory (string20 strFile, aStocks* aCategories, int currCateg)
- {
- FILE * pFile;
- string15 category, product, supplier;
- string8 productcode;
- int qtysold, qtyav, i = 0;
- float pprice, usprice, discount;
- char cDump;
- categoryType* pNew, *pFirst, *pRun;
- if ((pFile = fopen (strFile, "rt"))!= NULL){
- while(fscanf(pFile, "%s%s%s%d%f%s%f%c%f%d", category, prodcode, product, &qtyav,
- &pprice, supplier, &usprice, &discount, &qtysold)==10){
- //printf("%s %s\n", user, pass);
- //pRun = aCategories[i];
- //while (strcmp(pRun->pFirstStock->productcode, prodcode)!=0)
- // pRun->pFirstStock = pRun->pFirstStock->pNext;
- //creation of the linked list
- pNew = malloc(sizeof(categoryType));
- strcpy(pNew->category, category);
- strcpy(pNew->pFirstStock->product, product);
- // always insert at head of list
- pNew->pFirstStock->pNext = pFirst->pFirstStock;
- pFirst->pFirstStock = pNew->pFirstStock;
- }
- fclose(pFile);
- }
- else printf("Error opening file \n");
- }
- void saveToTextFile (ptrUser pFirst)
- {
- FILE * pText;
- string20 strName;
- if (pFirst == NULL)
- printf("Nothing to save");
- else{
- printf("Enter file name");
- scanf("%s", strName);
- pText = fopen(strName, "wt");
- //syntax: fopen(file name [string], file mode[string][r, w, a])
- //r: reading, w: writing, a: append (edit)
- //fopen returns address where new or existing text file is
- //if the file exists, and using "w", it will overwrite everything
- if (pText != NULL){
- while (pFirst != NULL){
- fprintf(pText, "%s %s\n", pFirst->username, pFirst->password);
- //fprintf: file formated printing, for printing to a secondary memory
- pFirst = pFirst->pNext;
- }
- fclose(pText);
- }
- else
- printf("Error creating file \n");
- }
- }
- void loadFromText (string20 strFile, ptrUser * pFirst)
- {
- FILE * pFile;
- string20 user, pass;
- ptrUser pNew;
- if ((pFile = fopen (strFile, "rt"))!= NULL){
- while(fscanf(pFile, "%s %s", user, pass)==2){
- //fscanf(pFile, "%s%s", user, pass);
- printf("%s %s\n", user, pass);
- //creation of the linked list
- pNew = malloc(sizeof(userType));
- strcpy(pNew->username, user);
- strcpy(pNew->password, pass);
- // always insert at head of list
- pNew->pNext = *pFirst;
- *pFirst = pNew;
- }
- fclose(pFile);
- }
- else printf("Error opening file \n");
- }
- /*Function AddStock has 1 use:
- 1. Add Stock
- @param i: index variable
- @param strikes: determines whether the added stock exists
- @param exit: character variable that determines if do while loop will end
- @param cDump: character variable that holds dump
- @param tempinteger: temporary integer to be copied to stocks structure
- @param tempfloat: temporary float value to be copied to stocks structure
- @param comparecode, comparecategory, comparesupplier: temporary strings to be
- used to compare with existing
- */
- void AddStock (categoryType *pNewStock, categoryType *pStock, aStocks *aCategories, int currCateg)
- {
- int exit = 1, strikes = 0, tempinteger = 0, i=0;
- float tempfloat = 0;
- char cDump;
- string15 tempcategory, tempsupplier, tempproduct;
- do {
- printf("Input the Category: ");
- //fgets(tempcategory,16,stdin);
- fgets(tempcategory,16,stdin);
- if (aCategories[currCateg] != NULL)
- if (searchCategory (tempcategory, aCategories, currCateg) != NULL)
- strikes++;
- strcpy (aCategories[currCateg]->category, tempcategory);
- printf("Input the Supplier: ");
- scanf("%s%c", tempsupplier, &cDump);
- if (searchSupplier(aCategories[currCateg]->pFirstStock->supplier, aCategories, currCateg)!=NULL)
- strikes++;
- strcpy (aCategories[currCateg]->pFirstStock->supplier, tempsupplier);
- printf("Input the Product Name: ");
- scanf("%s%c", tempproduct, &cDump);
- if (IsUniqueStock(aCategories[currCateg]->pFirstStock->product, aCategories, currCateg)==0)
- strikes++;
- strcpy (aCategories[currCateg]->pFirstStock->product, tempproduct);
- if (strikes > 4){
- printf("This product already exists. \n Use the Modify, Restock or Add New Stock with a different name \n");
- exit = 1;
- }
- printf("Input the Quantity Available for this product: ");
- scanf("%d%c", &tempinteger, &cDump);
- aCategories[currCateg]->pFirstStock->quantityavailable = tempinteger;
- printf("Input the Purchase Price for this product: ");
- scanf("%f%c", &tempfloat, &cDump);
- aCategories[currCateg]->pFirstStock->quantityavailable = tempfloat;
- printf("Input the Unit Selling Price for this product: ");
- scanf("%f%c", &tempfloat, &cDump);
- aCategories[currCateg]->pFirstStock->quantityavailable = tempfloat;
- printf("Input the Discount Rate for this product: ");
- scanf("%f%c", &tempfloat, &cDump);
- aCategories[currCateg]->pFirstStock->quantityavailable = tempfloat;
- aCategories[currCateg]->pFirstStock->quantitysold = 0;
- prodcode (pNewStock, aCategories, currCateg);
- printf("Product Code of this Item: %s \n", aCategories[currCateg]->pFirstStock->productcode);
- currCateg++;
- printf("Press [1] to add new stock or [0] to return to manage stocks menu: ");
- scanf("%d%c", &exit, &cDump);
- if(exit>1||exit<0)
- {
- printf("Invalid input. Returning to manage stocks menu");
- exit = 1;
- }
- }while(exit == 1);
- }
- /*Function AdminModifyStockMenu has 8 uses:
- 1. Modify Category
- 2. Modify Supplier
- 3. Modify Product
- 4. Modify Purchase Price
- 5. Modify Selling Price
- 6. Modify Discount
- 7. Finish Modifications of Product
- 8. Return to Administrator Menu
- @param i: index variable
- @param exit: character variable that determines if do while loop will end
- @param cDump: character variable that holds dump
- @param comparecode, comparecategory, comparesupplier: temporary strings to be
- used to compare with existing
- */
- void AdminModifyStockMenu (categoryType *pStock, aStocks *aCategories, int currCateg)
- {
- int choice, exit, i=0;
- char cDump;
- string8 comparecode, comparecategory, comparesupplier;
- ptrStock pRun;
- do {
- printf("Input product code of product to be modified \n");
- printf("Input: "); scanf("%s%c", comparecode, &cDump);
- while (strcmp(aCategories[i]->pFirstStock->productcode, comparecode)!=0 && i<currCateg)
- i++;
- if (i>currCateg){
- printf("Product Code not found, please try again. \n");
- AdminModifyStockMenu (pStock, aCategories, currCateg);
- }
- printf("MODIFY STOCK INFO \n");
- printf("Product code: %s \n", aCategories[i]->pFirstStock->productcode);
- printf("[1] Modify Category \n");
- printf("[2] Modify Supplier \n");
- printf("[3] Modify Product \n");
- printf("[4] Modify Purchase Price \n");
- printf("[5] Modify Selling Price \n");
- printf("[6] Modify Discount \n");
- printf("[7] Finish Modifications of Product %s \n", aCategories[i]->pFirstStock->productcode);
- printf("[0] Return to Administrator Menu");
- printf("Input: ");
- scanf("%d%c", &choice, &cDump);
- switch (choice){
- case 1: do{
- printf("Input new category for this product: ");
- scanf("%s%c", comparecategory, &cDump);
- if (searchCategory (comparecategory, aCategories, currCateg)== NULL){
- printf("Category not found. Creating a new one. \n");
- strcpy(aCategories[i]->category, comparecategory);
- printf("New category for this product is %s.\n", aCategories[i]->category);
- }
- printf("Modified category for this product is %s. \n", aCategories[i]->category);
- printf("[1] Modify Category \n");
- printf("[0] Return to Modify Stocks Info Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- if(exit>1||exit<0)
- {
- printf("Invalid input! returning you to main menu");
- exit = 0;
- }
- }while(exit==1);
- break;
- case 2: do {
- printf("Input new supplier for this product: ");
- scanf("%s%c", comparesupplier, &cDump);
- if (searchSupplier (comparesupplier, aCategories, currCateg)==NULL){
- printf("Supplier not found. Creating a new one. \n");
- strcpy(aCategories[i]->pFirstStock->supplier, comparesupplier);
- printf("New supplier for this product is %s.\n", aCategories[i]->pFirstStock->supplier);
- }
- printf("Modified supplier for this product is %s. \n", aCategories[i]->pFirstStock->supplier);
- printf("[1] Modify Supplier \n");
- printf("[0] Return to Modify Stocks Info Menu: \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- if(exit>1||exit<0)
- {
- printf("Invalid input! returning you to main menu");
- exit = 0;
- }
- }while (exit== 1);
- break;
- case 3: do {
- printf("Input new product name for this item: ");
- scanf("%s%c", comparesupplier, &cDump);
- printf("Modified product name for this product is %s. \n", aCategories[i]->pFirstStock->product);
- printf("[1] Modify Product Name \n");
- printf("[0] Return to Modify Stocks Info Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- if(exit>1||exit<0)
- {
- printf("Invalid input! returning you to main menu");
- exit = 0;
- }
- }while (exit==1);
- break;
- case 4: do {
- printf("Input new purchase price for product: ");
- scanf("%f%c", &aCategories[i]->pFirstStock->purchaseprice, &cDump);
- printf("New purchase price: %.2f \n", pStock->pFirstStock->purchaseprice);
- printf("[1] Modify Purchase Price \n");
- printf("[0] Return to Modify Stocks Info Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- if(exit>1||exit<0)
- {
- printf("Invalid input! returning you to main menu");
- exit = 0;
- }
- }while (exit == 1);
- break;
- case 5: do {
- printf("Input new selling price: ");
- scanf("%f%c", aCategories[i]->pFirstStock->unitsellingprice, &cDump);
- printf("New selling price: %.2f \n", aCategories[i]->pFirstStock->unitsellingprice);
- printf("[1] Modify Selling Price \n");
- printf("[0] Return to Modify Stocks Info Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- if(exit>1||exit<0)
- {
- printf("Invalid input! returning you to main menu");
- exit = 0;
- }
- }while (exit==1);
- break;
- case 6: do {
- printf("Input new discount: ");
- scanf("%f%c", aCategories[i]->pFirstStock->discountrate, &cDump);
- printf("New discount for this product: %f % ", aCategories[i]->pFirstStock->discountrate);
- printf("[1] Modify Selling Price \n");
- printf("[0] Return to Modify Stocks Info Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- if(exit>1||exit<0)
- {
- printf("Invalid input! returning you to main menu");
- exit = 0;
- }
- }while (exit==1);
- break;
- case 7: do {
- printf("Finishing Modification of Product.. \n");
- prodcode (pStock, aCategories, i);
- printf("Press [0] return to main menu");
- scanf("%d", &exit);
- if(exit>1||exit<0)
- {
- printf("Invalid input! returning you to main menu");
- exit = 0;
- }
- }while (exit==1);
- break;
- default:
- break;
- }
- }while(choice > 0 && choice < 8 );
- }
- /*Function AdminPrepareDelivery has 1 use:
- 1. Prepare Delivery Receipt
- @param i: index variable
- @param index: another index variable
- @param fileindex: another index variable for file pointer
- @param compareindex: index to be compared
- @param exit: character variable that determines if do while loop will end
- @param cDump: character variable that holds dump
- @param itemsubtotal: holds item subtotal for display
- @param totalprice: calculated by quantity * item price
- @param totaldiscount: total discounted amount
- @param billamout: total amount to be paid
- @param page: variable that controls how many entries appear
- @param pRun, pTrail, pTemp: variables that run through the linked list
- @param pRunFile: for file saving
- @param pText: file pointer
- @param strname: name of file
- @param foundproduct: name of product given product code
- */
- void AdminPrepareDelivery (userType *pUsers, userInfoType *pInfo, aStocks *aCategories)
- {
- int i = 0, index = 0, fileindex = 0, compareindex = 0;
- char exit, cDump;
- float itemsubtotal, totalprice, totaldiscount, billamount;
- ptrStock pRun, pTrail, pTemp;
- ptrUser pBought;
- categoryType * pRunFile;
- FILE * pText;
- string20 strName;
- string15 foundproduct;
- do {
- if (pTrail == NULL)
- pRun = aCategories[index]->pFirstStock;
- if (pRun != NULL){
- printf("User ID: %s \n", pUsers->username);
- printf("Customer Name: %s, %s, %s \n", (*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
- printf("Delivery Address: %s \n", (*pInfo).address);
- printf("Product Code Product Quantity Unit Price Total Price Discount Rate Item Subtotal \n");
- pTemp = aCategories[index]->pFirstStock;
- while (strcmp (pUsers->cart[compareindex].code, pTemp->productcode)!=0){
- if (strcmp (pUsers->cart[compareindex].code, pTemp->productcode)==0)
- strcpy (foundproduct, pTemp->product);
- pTemp = pTemp -> pNext;
- compareindex++;
- }
- while (i <= pUsers->nItems && pRun->pNext != NULL){
- totalprice = (pUsers->cart[i].qty)*(pRun->unitsellingprice);
- itemsubtotal = ((pRun->unitsellingprice) - (pRun->discountrate/100)) * (pUsers->cart[i].qty);
- totaldiscount += pRun->unitsellingprice - (pRun->unitsellingprice * (pRun->discountrate/100));
- billamount += itemsubtotal;
- printf("%15s %15s %d %.2f %.2f %.2f %.2f \n", pUsers->cart[i].code, pRun->product, pUsers->cart[i].qty, pRun->unitsellingprice,totalprice, pRun->discountrate, itemsubtotal);
- i++;
- pRun = pRun->pNext;
- if (pRun->pNext == NULL){
- index++;
- pRun = aCategories[index]->pFirstStock;
- }
- }
- i = 0;
- printf("Number of Items: %d \n", pUsers->nItems);
- printf("Total Discount: Php %d \n", totaldiscount);
- printf("Bill Amount: Php %.2f \n", billamount);
- printf("Total Outstanding: Php %.2f \n", pUsers->outstanding + billamount);
- pTrail = pRun;
- printf("Enter file name to save to");
- scanf("%s", strName);
- pRunFile = aCategories[fileindex];
- pText = fopen(strName, "wt");
- if (pText != NULL){
- while (pRunFile != NULL){
- fprintf(pText, "%15s %d \n", pUsers->username, pUsers->nItems);
- //fprintf: file formated printing, for printing to a secondary memory
- fprintf(pText, "%d %f %s \n", pUsers->cart[fileindex].qty, pUsers->cart[fileindex].code, pRun->supplier);
- fprintf(pText, "%f %f %d \n", pRun->unitsellingprice, pRun->discountrate, pRun->quantitysold);
- pRun = pRun->pNext;
- }
- fclose(pText);
- }
- else
- printf("Error creating file \n");
- printf("[B] Previous User \n");
- printf("[N] Next User \n");
- printf("[X] Return to Manage Stocks Menu \n");
- printf("Input: "); scanf("%c%c", &exit, &cDump);
- if (exit == 'b' || exit == 'B'){
- pRun = pTrail;
- if (pTrail == NULL)
- printf("No previous user. \n");
- }
- if (exit == 'n' || exit == 'N'){
- pRun = pRun->pNext;
- }
- if (exit == 'x' || exit == 'X')
- printf("Exit function");
- }
- }while (exit == 'B' || exit == 'b'|| exit == 'n' || exit == 'N' && (exit != 'x' || exit != 'X'));
- }
- /*Function viewAllStocks has 1 use:
- 1. View all stocks
- @param page: variable that controls how many entries appear
- @param pRun: variable that runs through the linked list
- */
- void viewAllStocks (categoryType *pStock, aStocks *aCategories, int currCateg)
- {
- categoryType *pRun;
- int page = 0;
- printf("Viewing All Stocks \n");
- pRun = pStock;
- printf("Category Supplier Product Qty Available Purchase Price Selling Price Qty Sold Product Code \n");
- while (pRun != NULL && page < 20){
- printf("%s %s %s %d %f %f %d %s \n",
- pRun->category, pRun->pFirstStock->supplier, pRun->pFirstStock->product, pRun->pFirstStock->quantityavailable, pRun->pFirstStock->purchaseprice, pRun->pFirstStock->unitsellingprice, pRun->pFirstStock->quantitysold, pRun->pFirstStock->productcode);
- pRun->pFirstStock = pRun->pFirstStock->pNext;
- page++;
- }
- page = 0;
- }
- /*Function viewByCategory has 1 use:
- 1. View stocks by category
- @param TempCategory: string that temporary holds input category
- @param index: index variable
- @param choice: character variable which determines if the function ends or goes to next page
- @param cDump: character variable to serve as dump
- @param pRun: variable that runs through the linked list
- */
- void viewByCategory (categoryType *pStock, aStocks *aCategories, int currCateg)
- {
- string15 TempCategory;
- categoryType *pRun;
- char cDump;
- int index, page = 0;
- printf("Input the category");
- printf("Input: ");scanf("%s%c",TempCategory, &cDump);
- if (searchCategory (TempCategory, aCategories, currCateg)== NULL)
- printf("Category not found \n");
- else if (searchCategory (TempCategory, aCategories, currCateg)!= NULL){
- pRun = searchCategory(TempCategory, aCategories, currCateg);
- printf("Viewing Stocks by Category \n");
- printf("Category Supplier Product Quantity Available Purchase Price Unit Selling Price Quantity Sold Product Code \n");
- while (pRun->pFirstStock != NULL){
- printf("%15s %15s %15s %d %.2f %.2f %d %15s \n",
- pRun->category, pRun->pFirstStock->supplier, pRun->pFirstStock->product,pRun->pFirstStock->quantityavailable,
- pRun->pFirstStock->purchaseprice, pRun->pFirstStock->unitsellingprice, pRun->pFirstStock->quantitysold,
- pRun->pFirstStock->productcode);
- pRun->pFirstStock = pRun->pFirstStock->pNext;
- }
- }
- }
- /*Function viewStockReorder has 1 use:
- 1. View stocks that have quantity = 0
- @param page: variable that limits number of displayed entries
- @param i: index variable
- @param choice: character variable which determines if the function ends or goes to next page
- @param cDump: character variable to serve as dump
- @param pRun: variable that runs through the linked list
- */
- void viewStockReorder (categoryType* pStock, aStocks *aCategories, int currCateg)
- {
- int page = 0, i = 0;
- char choice = '\0', cDump;
- categoryType *pRun;
- printf("Viewing Stocks to Reorder \n");
- pRun = aCategories[i];
- while (choice == '\0'){
- while (pRun->pFirstStock != NULL && pRun->pFirstStock->quantityavailable == 0 && page <= 20){
- printf("%15s %15s %15s %d %.2f %.2f %d %s",
- pRun->category, pRun->pFirstStock->supplier, pRun->pFirstStock->product, pRun->pFirstStock->quantityavailable,
- pRun->pFirstStock->purchaseprice, pRun->pFirstStock->unitsellingprice, pRun->pFirstStock->quantitysold, pRun->pFirstStock->productcode);
- pRun->pFirstStock = pRun->pFirstStock->pNext;
- page++;
- if (pRun->pFirstStock->pNext == NULL)
- pRun = aCategories[i++];
- }
- printf("Press ENTER for next page or 0 to exit: ");
- scanf("%c%c", &choice, &cDump);
- }
- }
- /*Function restock has 1 use:
- 1. Restock product given a product code
- @param addqty: quantity to add
- @param cDump: character variable to serve as dump
- @param TempProdCode: product code inputted to be compared
- @param pRun: variable that runs through the linked list
- */
- void restock (categoryType *pStock, aStocks *aCategories, int currCateg)
- {
- int addqty = 0;
- char cDump;
- categoryType *pRun;
- string8 TempProdCode;
- printf("Restock \n");
- pRun = pStock;
- printf("Category Supplier Product Quantity Available Purchase Price Unit Selling Price Quantity Sold Product Code \n");
- while (pRun != NULL){
- printf("%s %s %s %d %f %f %d %s",
- pRun->category, pRun->pFirstStock->supplier, pRun->pFirstStock->product, pRun->pFirstStock->quantityavailable, pRun->pFirstStock->purchaseprice, pRun->pFirstStock->unitsellingprice, pRun->pFirstStock->quantitysold, pRun->pFirstStock->productcode);
- pRun->pFirstStock = pRun->pFirstStock->pNext;
- }
- printf("Input the product code of the product that will be restocked: ");
- scanf("%s%c",TempProdCode, &cDump);
- pRun = pStock;
- while (pRun != NULL && strcmp(TempProdCode, pRun->pFirstStock->productcode)!=0){
- pRun->pFirstStock = pRun->pFirstStock->pNext;
- if (pRun == NULL){
- printf("Last input product code not found. Not restocked. Returning to Manage Stocks Menu \n");
- }
- if (pRun != NULL && strcmp(TempProdCode, pRun->pFirstStock->productcode)==0){
- printf("Additional Quantity for this item: ");
- scanf("%d%c", &addqty, &cDump);
- pRun->pFirstStock->quantityavailable += addqty;
- printf("This product has been restocked and has %d quantity available. \n", pRun->pFirstStock->quantityavailable);
- }
- }
- }
- /*Function AdminManageStocks has 8 uses:
- 1. Add New Stock
- 2. View All Stocks
- 3. View Stocks by Category
- 4. View Stocks to Reorder
- 5. Modify Stock Info
- 6. Restock
- 7. Update Inventory from File
- 8. Return to Administrator Menu
- @param choice: variable for switch statement to navigate through menu
- @param exit: variable to exit menu choice
- @param page: variable that controls how many entries appear
- @param cExit: like exit, but is a character
- @param pRun: variable that runs through the linked list
- */
- void AdminManageStocks (userType *pUsers, categoryType *pStock, categoryType *pNewStock, categoryType *pEnd, aStocks *aCategories, int currCateg)
- {
- int choice, exit, page = 0;
- char cDump, cExit = '\0';
- categoryType* pRun;
- string20 strFile;
- pStock = NULL;
- pNewStock = NULL;
- pEnd = NULL;
- do {
- printf("MANAGE STOCKS MENU \n");
- printf("[1] Add New Stock \n");
- printf("[2] View All Stocks \n");
- printf("[3] View Stocks by Category \n");
- printf("[4] View Stocks to Reorder \n");
- printf("[5] Modify Stock Info \n");
- printf("[6] Restock \n");
- printf("[7] Save Inventory \n");
- printf("[8] Update Inventory from File \n");
- printf("[0] Return to Administrator Menu \n");
- printf("Input: ");
- scanf("%d%c", &choice, &cDump);
- switch (choice){
- case 1: do{
- aCategories[currCateg]->pFirstStock = malloc(sizeof(categoryType));
- AddStock(pNewStock, pStock, aCategories, currCateg);
- aCategories[currCateg]->pFirstStock->pNext = NULL;
- if (pStock == NULL) //if initially empty
- pStock = pNewStock; //pNew is the first node
- else //connect nodes to the list
- pEnd->pFirstStock->pNext = pNewStock->pFirstStock;
- pEnd = pNewStock;
- }while(exit==0);
- break;
- case 2: do {
- viewAllStocks (pStock, aCategories, currCateg);
- printf("Press [N] return to main menu or ENTER to view next page. \n");
- scanf("%c%c", &cExit, &cDump);
- }while (cExit=='\0');
- break;
- case 3: do {
- viewByCategory (pStock, aCategories, currCateg);
- printf("Press [0] return to main menu");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- break;
- case 4: do {
- viewStockReorder (pStock, aCategories, currCateg);
- printf("Press [N] return to main menu or ENTER to view next page. \n");
- scanf("%c%c", &cExit, &cDump);
- }while (cExit=='\0');
- break;
- case 5: do {
- viewAllStocks(pStock, aCategories, currCateg);
- printf("Modify Stock Info \n");
- AdminModifyStockMenu(pStock, aCategories, currCateg);
- printf("Press [0] return to main menu");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- break;
- case 6: do {
- restock(pStock, aCategories, currCateg);
- printf("Press [0] return to main menu");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- break;
- case 7: do {
- AdminSaveInventory (aCategories);
- printf("Press [0] return to main menu");
- scanf("%d", &exit);
- }while (exit==1);
- break;
- case 8: do {
- printf("Input filename: ");
- scanf("%s%c", strFile, &cDump);
- AdminUpdateInventory (strFile, aCategories, currCateg);
- }while (exit == 1);
- default: choice = 0;
- break;
- }
- }while(choice > 0 && choice < 9 );
- }
- /*Function AdminManageAccounts has 5 uses:
- 1. View Locked Accounts
- 2. Unlock a specific account given the username
- 3. Unlock all accounts that have the nLocked
- 4. View accounts with outstanding balance
- 5. Return to Administrator Menu
- @param choice: variable for switch statement to navigate through menu
- @param exit: variable to exit menu choice
- @param yesorno: confirmation for unlock all locked accounts
- @param CompareUser: variable that takes user input username, to be compared to existing
- @param pLock: variable that holds the value of search
- @param cDump: character variable for dump
- */
- void AdminManageAccounts (userType *pUsers, userInfoType *pInfo)
- {
- int choice = 0, exit;
- char cDump, yesorno;
- string15 CompareUser;
- userType *pLock;
- ptrUser pRun;
- pRun = pUsers;
- do {
- printf("Welcome, %s, %s, %s. \n",(*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
- printf("MANAGE ACCOUNTS MENU \n");
- printf("[1] View Locked Accounts \n");
- printf("[2] Unlock Specific Account \n");
- printf("[3] Unlock All Locked Accounts \n");
- printf("[4] View Accounts with Outstanding Balance \n");
- printf("[0] Return to Administrator Menu \n");
- printf("Input: ");
- scanf("%d%c", &choice, &cDump);
- switch (choice) {
- case 1: do {
- while (pRun != NULL && pRun->nLocked == 1){
- pRun = pRun->pNext;
- printf("Username: %s \n", pRun->username);
- printf("Name: %s, %s ,%s",(*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
- if (pRun->username == NULL)
- printf("No account is locked. \n");
- }
- printf("[0] Return to Manage Accounts Menu \n");
- printf("[1] View All Locked Accounts \n");
- printf("Input: ");scanf("%d", &exit);
- if(exit>1||exit<0)
- {
- printf("Invalid input. Returning to Manage Accounts Menu \n");
- exit = 1;
- }
- } while(exit == 1);
- pRun = NULL;
- break;
- case 2: do {
- printf("Input username of locked account. \n");
- printf("Input: ");scanf("%s%c", CompareUser, &cDump);
- pLock = search (pUsers, CompareUser);
- if (pLock != NULL)
- pLock->nLocked = 0;
- printf("[0] Return to Manage Accounts Menu \n");
- printf("[1] Unlock Another Account\n");
- printf("Input: ");scanf("%d", &exit);
- if(exit>1||exit<0)
- {
- printf("Invalid input. Returning to Manage Accounts Menu \n");
- exit = 1;
- }
- } while(exit == 1);
- break;
- case 3: do {
- printf("Would you like to unlock all locked accounts? [Y]es | [N]o \n");
- scanf("%c%c",&yesorno, &cDump);
- if (yesorno == 'y' || yesorno == 'Y'){
- while (pRun != NULL ){
- if (pRun->nLocked == 1)
- pRun->nLocked = 0;
- pRun = pRun->pNext;
- }
- }
- printf("[0] Return to Manage Accounts Menu \n");
- printf("Input: ");scanf("%d%c", &exit, &cDump);
- if(exit>1||exit<0)
- {
- printf("Invalid input. Returning to Manage Accounts Menu \n");
- exit = 1;
- }
- } while(exit == 1);
- break;
- case 4: do {
- printf("Diplaying Accounts with Outstanding Balance \n");
- while (pRun != NULL){
- if (pRun->outstanding>0){
- printf("%s \n", pRun->username);
- printf("%s \n", (*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
- printf("%f \n", pRun->outstanding);
- }
- }
- printf("[0] Return to Manage Accounts Menu \n");
- printf("Input: ");scanf("%d", &exit);
- if(exit>1||exit<0)
- {
- printf("Invalid input. Returning to Manage Accounts Menu \n");
- exit = 1;
- }
- }while (exit == 1);
- break;
- default: printf("Returning to Administrator Menu.. \n");
- break;
- }
- } while (choice > 0 && choice < 5);
- }
- /*Function signUp has 1 use:
- 1. Allows user to create an account, either admin or shopper
- @param unique: integer variable determines if username is unique
- @param exit: variable to exit menu choice
- @param cTempType: variable that hold user inputted user type
- @param TempUsername: variable that takes user input username, to be pass to IsUnique
- @param arrInputCode: variable that holds user input code
- @param cDump: character variable for dump
- @param arrCompareCode: temporary string that holds authorization code
- */
- void signUp (userType *pUser, userType *pUsers)
- {
- int unique = 0;
- char cDump, cTempType = '\0';
- char arrInputCode[9];
- char arrCompareCode[9] = {'D','L','S','U','2','0','1','7'};
- string15 TempUsername;
- do{
- printf("Enter username: ");
- scanf("%s%c", (*pUser).username /*TempUsername*/,&cDump); //placing the information directly within the container. Username is inside pUser
- if (IsUnique (pUsers, pUser->username) == 0){
- printf("Username taken, please input a unique username. \n");
- unique = 0;
- }
- else if (IsUnique (pUsers, pUser->username) == 1){
- unique = 1;
- printf("Username is unique, proceeding. \n");
- }
- }while (strlen((*pUser).username)<3 || strlen((*pUser).username)>15 || unique != 1);
- do{
- printf("Enter password: ");
- scanf("%s%c", (*pUser).password,&cDump); //placing the information directly within the container. Username is inside pUser
- if (strlen((*pUser).password)<6){
- printf("Password too short, please try again. \n");
- printf("Enter password: ");
- scanf("%s%c", (*pUser).password,&cDump);
- }
- if (strlen((*pUser).password)>15){
- printf("Password too long, please try again. \n");
- printf("Enter password: ");
- scanf("%s%c", (*pUser).password,&cDump);
- }
- if (ValidPass(pUser)==1)
- printf("Password is valid. \n");
- else{
- printf("Error, password must contain non-letter character.\n");
- printf("Enter password: ");
- scanf("%s%c", (*pUser).password,&cDump);
- }
- }while (strlen((*pUser).password)<6 || strlen((*pUser).password)>15);
- printf("Create [S]hopper or [A]dministrator account? \n");
- printf("Input: ");
- scanf("%c%c", &cTempType, &cDump);
- if(cTempType != 's' && cTempType != 'S' && cTempType != 'a' && cTempType != 'A'){
- printf("Invalid input, please try again: \n");
- while (cTempType != 's' && cTempType != 'S' && cTempType != 'a' && cTempType != 'A'){
- printf("Input: ");
- scanf("%c%c",&cTempType, &cDump);
- }
- }
- if (cTempType == 's' || cTempType == 'S'){
- (*pUser).type = 'S';
- printf("Account Type: Shopper \n");
- (*pUser).creditlimit = 5000.00;
- printf("Your current Credit Limit is Php 5000.00. \n");
- (*pUser).outstanding = 0.00;
- printf("Your current Outstanding Balance is Php 0.00. \n");
- }
- else if (cTempType == 'a' || cTempType == 'A'){
- do {
- printf("Input authorization code: ");
- scanf("%s%c", arrInputCode,&cDump);
- if (strcmp(arrInputCode,arrCompareCode)==0){
- (*pUser).type = 'A';
- //AdminChoice();
- printf("Account Type: Admin \n");
- }
- else
- printf("Invalid authorization code, try again. Please try again. \n");
- }while (strcmp(arrInputCode,arrCompareCode)!=0);
- }
- }
- /*Function modifyUserInfo has 4 uses:
- 1. Allows user to edit their first name, middle name or last name
- 2. Allows user to change their address
- 3. Allows user to change their password
- 4. Return to Shopper Menu
- @param choice: variable to naviage through menu
- @param exit: variable to exit menu choice
- @param nChoice: variable to control
- @param cDump: character variable for dump
- @param arrComparepass: temporary string to compare input password with user's password
- */
- void modifyUserInfo (userType *pUser, userInfoType *pInfo)
- {
- int choice = 0, exit = 0, nChoice = 0;
- char cDump;
- char arrComparePass[16];
- do {
- printf("Hello, %s, %s, %s. \n",(*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
- printf("What would you like to change? \n");
- printf("[1] Change Name \n");
- printf("[2] Change Address \n");
- printf("[3] Change Password \n");
- printf("[0] Return to Shopper Menu \n");
- printf("Input: ");
- scanf("%d%c", &choice, &cDump);
- switch (choice) {
- case 1: do {
- while (nChoice > 3 || nChoice < 0){
- printf("What would you like to change \n?");
- printf("[1] First \n");
- printf("[2] Middle \n");
- printf("[3] Last \n");
- printf("Input: "); scanf("%d", &nChoice);
- if (nChoice < 0 || nChoice > 3)
- printf("Invalid Input \n");
- }
- if (nChoice == 1){
- printf("Change First Name: ");
- fgets((*pInfo).name.first,21,stdin);
- if ((*pInfo).name.first[0] > 'a' && (*pInfo).name.first[0] < 'z' )
- (*pInfo).name.first[0] -= 32;
- }
- if (nChoice == 2){
- printf("Change Middle Name: ");
- fgets((*pInfo).name.middle,21,stdin);
- if ((*pInfo).name.middle[0] > 'a' && (*pInfo).name.middle[0] < 'z' )
- (*pInfo).name.middle[0] -= 32;
- }
- if (nChoice == 3){
- printf("Change Last Name: ");
- fgets((*pInfo).name.last,51,stdin);
- if ((*pInfo).name.last[0] > 'a' && (*pInfo).name.last[0] < 'z' )
- (*pInfo).name.last[0] -= 32;
- }
- printf("Your new name is: %s,%s,%s \n", (*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
- printf("[0] Return to Modify User Info Menu \n");
- printf("[1] Reinput Name \n");
- printf("Input: ");scanf("%d%c", &exit, &cDump);
- if(exit>1||exit<0)
- {
- printf("Invalid input! returning you to main menu");
- exit = 1;
- }
- } while(exit == 1);
- break;
- case 2: do {
- printf("Input your new Address: ");
- fgets((*pInfo).address,51,stdin);
- (*pInfo).address[strlen((*pInfo).address)-1]='\0';
- printf("Your new Address is: %s \n",(*pInfo).address);
- printf("[0] Return to Modify User Info Menu \n");
- printf("[1] Reinput Address\n");
- printf("Input: ");scanf("%d%c", &exit, &cDump);
- if(exit>1||exit<0)
- {
- printf("Invalid input! returning you to main menu");
- exit = 1;
- }
- } while(exit == 1);
- break;
- case 3: do {
- while (strcmp((*pUser).password, arrComparePass)!=0){
- printf("Input your current password. \n");
- scanf("%s%c",arrComparePass,&cDump);
- if(strcmp((*pUser).password, arrComparePass)!=0){
- printf("Password does not match, please try again. \n");
- printf("Input: "); scanf("%s%c", arrComparePass,&cDump);
- }
- }
- printf("Input your new Password: ");
- scanf("%s%c", (*pUser).password,&cDump); //placing the information directly within the container. Username is inside pUser
- if (strlen((*pUser).password)<6){
- printf("Password too short, please try again. \n");
- printf("Enter password: ");
- scanf("%s%c", (*pUser).password,&cDump);
- }
- if (strlen((*pUser).password)>15){
- printf("Password too short, please try again. \n");
- printf("Enter password: ");
- scanf("%s%c", (*pUser).password,&cDump);
- }
- if (ValidPass(pUser)==1)
- printf("Password is valid. \n");
- else{
- printf("Error, password must contain non-letter character.\n");
- printf("Enter password: ");
- scanf("%s%c", (*pUser).password,&cDump);
- }
- printf("Your new Password is %s. \n", (*pUser).password);
- printf("[0] Return to Modify User Info Menu \n");
- printf("[1] Reinput Address\n");
- printf("Input: ");scanf("%d", &exit);
- if(exit>1||exit<0)
- {
- printf("Invalid input! returning you to main menu");
- exit = 1;
- }
- } while(exit == 1);
- break;
- default: choice = 0;
- }
- } while (choice == 1 || choice == 2 || choice == 3);
- }
- /*Function getUserInfo has 1 use:
- 1. Allows user to input their user information
- */
- void getUserInfo (userInfoType *pInfo)
- {
- printf("Enter name: \n");
- printf("First Name: ");
- fgets((*pInfo).name.first,21,stdin);
- if ((*pInfo).name.first[0] > 'a' && (*pInfo).name.first[0] < 'z' )
- (*pInfo).name.first[0] -= 32;
- printf("Middle Name: ");
- fgets((*pInfo).name.middle,21,stdin);
- if ((*pInfo).name.middle[0] > 'a' && (*pInfo).name.middle[0] < 'z' )
- (*pInfo).name.middle[0] -= 32;
- printf("Last Name: ");
- fgets((*pInfo).name.last,51,stdin);
- if ((*pInfo).name.last[0] > 'a' && (*pInfo).name.last[0] < 'z' )
- (*pInfo).name.last[0] -= 32;
- printf("%s,%s,%s \n", (*pInfo).name.last,(*pInfo).name.first,(*pInfo).name.middle);
- printf("Enter address: ");
- fgets((*pInfo).address,51,stdin);
- (*pInfo).address[strlen((*pInfo).address)-1]='\0';
- (*pInfo).name.first[strlen((*pInfo).name.first)-1]='\0';
- (*pInfo).name.middle[strlen((*pInfo).name.middle)-1]='\0';
- (*pInfo).name.last[strlen((*pInfo).name.last)-1]='\0';
- }
- /*Function ValidPass has 1 use:
- 1. Allows user to sign in an exisiting account
- @param i: index variable
- @param valid: integer value that determines whether or not the password is valid
- */
- int ValidPass (userType *pUser)
- {
- int i, valid=0;
- for(i=0;i<(strlen(pUser->password));i++){
- if (pUser->password[i] < 'a' || pUser->password[i] >'z')
- if (pUser->password[i] < 'A' || pUser->password[i] >'Z')
- valid=1;
- }
- return valid;
- }
- /*Function displayAll has 1 use:
- 1. Displays all users
- */
- void displayAll (userType *pUsers)
- {
- while (pUsers!=NULL){ //stop traversing when there is no more new address
- printf("%s\n", pUsers->username);
- pUsers = pUsers->pNext; //node traversal
- }
- }
- /*Function signIn has 1 use:
- 1. Allows user to sign in an exisiting account
- @param i: index variable
- @param loggedin: determine whether user is logged in or not
- @param tries: number of tries before account is locked
- @param exit: variable to do while statement
- @param AccountType: integer variable to be passed into the linked list of user
- @param arrTempuser: temporary string for username to be compared
- @param arrTempPw: temporary string for password to be compared
- @param arrInputCode: temporary string for authorization code
- @param authcode: string that holds the authorization code
- @param cDump: character variable for dump
- @param pLogin: temporary pointer variable for username
- @param pPassword: temporary pointer variable for password
- */
- int signIn (userType *pUsers, userInfoType *pInfo, userType *pNew, userType *pLast)
- {
- int loggedin=0, tries=3, exit = 0, AccountType = 0;
- char arrTempUser[16], arrTempPW[16], arrInputCode[9], authcode[9]={'D','L','S','U','2','0','1','7'};
- char cDump;
- userType *pLogin, *pPassword;
- do{
- printf("Enter username: ");
- scanf("%s", arrTempUser);fflush(stdin);
- printf("Enter password: ");
- scanf("%s", arrTempPW);fflush(stdin);
- if(pUsers!=NULL)
- {
- pLogin = search(pUsers, arrTempUser);
- pPassword = search(pUsers, pUsers->username);
- if (pLogin == NULL){
- printf("Not found address\n");
- signIn (pUsers, pInfo, pNew, pLast);
- }
- }
- else if (pUsers == NULL)
- {
- printf("Not found was null\n");
- signIn (pUsers, pInfo, pNew, pLast);
- }
- if (pUsers->nLocked == 1)
- printf("This account is locked, contact an administrator, returning to main menu. \n");
- if (strcmp(pLogin->username, arrTempUser)==0){
- if (strcmp(pPassword->password, arrTempPW)==0){
- pUsers->nLoggedin = 1;
- }
- else{
- while (strcmp(pPassword->password, arrTempPW)!=0 && pUsers->nLocked != 1){
- printf("Incorrect password, please try again. %d tries remaining: \n", tries);
- tries--;
- scanf("%s%c", arrTempPW, &cDump);
- if (tries == 0){
- printf("This account has been locked. Contact Administrator. Returning to main menu. \n");
- pUsers->nLocked = 1;
- exit = 1;
- }
- }
- }
- }
- else {
- printf("Incorrect username or password, please try again. %d tries remaining: \n", tries);
- printf("%s", arrTempUser);
- printf("%d", strcmp(pLogin->username, arrTempUser));
- tries--;
- }
- if (pUsers->type == 'A' && pUsers->nLocked == 0){
- printf("Input authorization code: ");
- scanf("%s%c", arrInputCode, &cDump);
- if (strcmp(arrInputCode,authcode)==0){
- AccountType = 2;
- return AccountType;
- pUsers->nLoggedin = 1;
- }
- else if (strcmp(arrInputCode,authcode)!=0) {
- while (strcmp(arrInputCode,authcode)!=0){
- printf("Incorrect code, please try again.\n");
- printf("Input: "); scanf("%s%c", arrInputCode, &cDump);
- }
- }
- }
- else if (pUsers->type == 'S' && pUsers->nLocked == 0){
- printf("Welcome, %s \n", (*pInfo).name.first);
- //pUsers->loggedin = 1;
- //modifyUserInfo (pUsers, pInfo);
- AccountType = 1;
- return AccountType;
- pUsers->nLoggedin = 1;
- }
- }while (loggedin == 0 && tries > 0 && exit == 0 && pUsers->nLocked != 1);
- }
- /*Function freeAll has 1 use:
- 1. Frees the linked list of users
- @param i: index variable
- @param pDel: node to be deleted
- @param pTemp: temporary variable used to run throught linked list
- */
- void freeAll (ptrUser *pFirst)
- {
- userType *pDel;
- while(*pFirst != NULL){
- pDel = *pFirst;
- *pFirst = (*pFirst)->pNext;
- free(pDel);
- }
- }
- /*Function freeAllStock has 1 use:
- 1. Frees the linked list of stocks
- @param i: index variable
- @param pDel: node to be deleted
- @param pTemp: temporary variable used to run throught linked list
- */
- void freeAllStock (categoryType **pFirst, aStocks *aCategories, int currCateg)
- {
- ptrStock pTemp, pDel;
- int i;
- for (i=0; i<currCateg; i++){
- pTemp = aCategories[i]->pFirstStock;
- while (aCategories[i]->pFirstStock != NULL){
- pDel = pTemp;
- pTemp = pTemp->pNext;
- free(pDel);
- }
- }
- }
- /*Function ViewCart has 1 use:
- 1. View all items added to user's cart
- @param i: index variable
- @param index: alternate index variable
- @param arrayindex: index for array
- @param itemsubtotal: total to be calculated in the function
- @param pTemp: variable used to run throught linked list
- */
- void ViewCart (userType *pUsers, aStocks* aCategories, int currCateg)
- {
- categoryType * pTemp;
- int i = 0, index = 0, arrayindex = 0;
- float itemsubtotal;
- if (pUsers->cart == NULL)
- printf("Cart is empty \n");
- pTemp = aCategories[i];
- printf("Product Code Product Quantity Unit Price Total Price Discount Rate Item Subtotal \n");
- while (i < pUsers->nItems){
- while (strcmp(pTemp->pFirstStock->productcode, pUsers->cart[index].code)!=0){
- pTemp->pFirstStock = pTemp->pFirstStock->pNext;
- index++;
- }
- printf ("%15s %15s %d %f %f %f %f \n", pUsers->cart[i].code, pTemp->pFirstStock->product, pUsers->cart[i].qty,
- pTemp->pFirstStock->unitsellingprice, pTemp->pFirstStock->discountrate, itemsubtotal);
- i++;
- if (pTemp->pFirstStock == NULL){
- pTemp = aCategories[arrayindex];
- arrayindex++;
- }
- }
- }
- /*Function AddtoCart has 1 use:
- 1. Add a product to the cart given a product code
- @param quantity: temp quantity to be placed in the linked list
- @param i: index variable
- @param index: alternate index variable
- @param choice: to exit the loop
- @param cChoice: to exit the loop, but uses a character
- @param cDump: character variable that acts as a dump
- @param tempcode: temporary string to compare
- @param pRun: variable used to run throught linked list
- */
- void AddtoCart (userType *pUsers, aStocks* aCategories, int currCateg)
- {
- int quantity = 0, choice = 1, index, i = 0;
- char cDump, cChoice = 'y';
- string8 tempcode;
- categoryType* pRun;
- do {
- printf("Input product code of item to add: ");
- scanf("%s%c", tempcode, &cDump);
- if (searchProductCode (aCategories, tempcode, currCateg) == NULL){
- printf("Product not found, please try again. \n");
- printf("[0] Exit \n");
- printf("[1] Add to Cart");
- scanf("%d",&choice);
- }
- else if (searchProductCode (aCategories, tempcode, currCateg) != NULL){
- pRun = searchProductCode (aCategories, tempcode, currCateg);
- while (strcmp(pRun->pFirstStock->productcode, tempcode) != 0){
- pRun->pFirstStock = pRun->pFirstStock->pNext;
- }
- if (pRun->pFirstStock->quantityavailable == 0){
- printf("Out of Stock \n");
- }
- printf("Input quantity: ");
- scanf("%d", &quantity);
- strcpy (pUsers->cart[i].code, tempcode);
- pUsers->cart[i].qty = quantity;
- printf("Would you like to add another item to the cart?");
- scanf("%c%c", &cChoice, cDump);
- if (cChoice != 'y' || cChoice != 'Y' || cChoice != 'N' || cChoice != 'n'){
- printf("Invalid input, returning to shopper menu. \n");
- choice = 0;
- }
- i++;
- pUsers->nItems++;
- }
- }while (choice == 1 || cChoice == 'y' || cChoice == 'Y');
- }
- /*Function EditCart has 2 uses:
- 1. Remove items from cart
- 2. Update quantity
- @param i: index variable
- @param page: limits the number of entries shown so the items do not simply flash
- @param cDump: character variable that acts as a dump
- @param cExit: similar to exit, for option that requires a character input
- @param tempcode: temporary storage for product code
- */
- void EditCart (userType *pUsers, aStocks* aCategories, int currCateg)
- {
- int exit = 0, choice, nExit = 1, i, newamount = 0;
- char cDump;
- string8 tempcode;
- do {
- switch (choice){
- case 1:
- do {
- printf("Input product code of item to be removed: ");
- scanf("%s%c",tempcode, &cDump);
- if (pUsers->nItems == 0)
- printf("No items in cart \n");
- while (pUsers->cart[i].code != NULL && i < pUsers->nItems
- && strcmp (tempcode, pUsers->cart[i].code)!=0) {
- i++;
- }
- if (strcmp(tempcode, pUsers->cart[i].code) == 0){
- pUsers->cart[i].qty = 0;
- printf("Item removed. \n");
- }
- if (i>pUsers->nItems){
- printf("Product code not found, returning to edit cart menu");
- nExit = 0;
- }
- }while (nExit == 1);
- break;
- case 2: do {
- printf("Input product code of item to update quantity: ");
- scanf("%s%c",tempcode, &cDump);
- if (pUsers->nItems == 0)
- printf("No items in cart \n");
- while (pUsers->cart[i].code != NULL && i < pUsers->nItems
- && strcmp (tempcode, pUsers->cart[i].code)!=0) {
- i++;
- }
- if (strcmp(tempcode, pUsers->cart[i].code) == 0){
- printf("Input amount to update to: ");
- scanf("%d%c",&newamount, cDump);
- pUsers->cart[i].qty = newamount;
- if (newamount == 0){
- printf("New amount is zero, removing item. \n");
- }
- }
- if (i>pUsers->nItems){
- printf("Product code not found, returning to edit cart menu");
- nExit = 0;
- }
- }while (nExit == 1);
- break;
- default: exit = 0;
- break;
- }
- }while (exit == 1);
- }
- /*Function browseProducts has 1 use:
- 1. Display products
- @param i: index variable
- @param page: limits the number of entries shown so the items do not simply flash
- @param cDump: character variable that acts as a dump
- @param cExit: similar to exit, for option that requires a character input
- @param *pRun: variable that goes through the list to find what is needed
- */
- void browseProducts (aStocks *aCategories)
- {
- int i = 0, page = 0;
- char cDump, cExit = '\0';
- categoryType * pRun;
- pRun = aCategories[i];
- printf("Category Brand Product Code Product Quantity Available Quantity Sold Unit Price Discount Rate \n");
- do {
- if (aCategories[i]->pFirstStock->quantityavailable >= 1){
- printf("%15s%15s%8s%15s %d %d %.2f %.2f \n",
- pRun->category, pRun->pFirstStock->supplier, pRun->pFirstStock->productcode, pRun->pFirstStock->product,
- pRun->pFirstStock->quantityavailable, pRun->pFirstStock->quantitysold, pRun->pFirstStock->unitsellingprice,
- pRun->pFirstStock->discountrate);
- }
- if (pRun->pFirstStock->pNext == NULL){
- i++;
- pRun = aCategories[i];
- }
- page++;
- }while (pRun->pFirstStock != NULL && page < 20);
- }
- /*Function browsebyCategory has 1 use:
- 1. Display products by Category
- @param i: index variable
- @param index: another index variable
- @param page: limits the number of entries shown so the items do not simply flash
- @param cDump: character variable that acts as a dump
- @param cExit: similar to exit, for option that requires a character input
- @param TempCategory: temporary string to compare to existing ones
- @param *pRun: variable that goes through the list to find what is needed
- */
- void browsebyCategory (aStocks *aCategories, int currCateg)
- {
- string15 TempCategory;
- char cDump, cExit = '0';
- int i = 0, index = 0, page = 0;
- categoryType * pRun;
- printf("Input the category");
- printf("Input: ");scanf("%s%c",TempCategory, &cDump);
- searchCategory (TempCategory, aCategories, currCateg);
- if (searchCategory (TempCategory, aCategories, currCateg)==NULL)
- printf("Category not found \n");
- else if (searchCategory (TempCategory, aCategories, currCateg)!=NULL){
- printf("Browsing Products by Category \n");
- pRun = searchCategory (TempCategory, aCategories, currCateg);
- printf("Category Brand Product Code Product Quantity Available Quantity Sold Unit Price Discount Rate \n");
- do {
- printf("%15s %15s %8s %15s %d% d% .2f %.2f \n",pRun->category, pRun->pFirstStock->supplier, pRun->pFirstStock->productcode, pRun->pFirstStock->product,
- pRun->pFirstStock->quantityavailable, pRun->pFirstStock->quantitysold, pRun->pFirstStock->unitsellingprice,
- pRun->pFirstStock->discountrate);
- pRun->pFirstStock = pRun->pFirstStock->pNext;
- page++;
- if (pRun->pFirstStock->pNext == NULL){
- index++;
- pRun = aCategories[index];
- }
- if (page = 20){
- printf("Press ENTER to go to next page or [0] to return to Shopper Menu \n");
- printf("Input: "); scanf("%c%c", &cExit, &cDump);
- }
- }while (page <= 20 && index <= currCateg && cExit != '\0');
- }
- }
- /*Function browseOnSale has 1 use:
- 1. Display products on sale
- @param i: index variable
- @param page: limits the number of entries shown so the items do not simply flash
- @param cDump: character variable that acts as a dump
- @param cExit: similar to exit, for option that requires a character input
- @param TempCategory: temporary string to compare to existing ones
- @param *pRun: variable that goes through the list to find what is needed
- */
- void browseOnSale (aStocks *aCategories, int currCateg)
- {
- int i = 0, page = 0;
- char cExit = '\0', cDump;
- categoryType * pRun;
- printf("Browsing Products on Sale \n");
- pRun = aCategories[i];
- printf("Category Brand Product Code Product Quantity Available Quantity Sold Unit Price Discount Rate \n");
- if (pRun->pFirstStock == NULL)
- printf("Stocks is empty \n");
- do{
- if (pRun->pFirstStock->discountrate > 0){
- printf("%15s %15s %8s %15s %d %d %f %f \n",
- pRun->category, pRun->pFirstStock->supplier, pRun->pFirstStock->productcode, pRun->pFirstStock->product,
- pRun->pFirstStock->quantityavailable, pRun->pFirstStock->quantitysold, pRun->pFirstStock->unitsellingprice,
- pRun->pFirstStock->discountrate);
- }
- page++;
- if (pRun->pFirstStock->pNext == NULL){
- i++;
- pRun = aCategories[i];
- }
- if (page = 20){
- printf("Press ENTER to go to next page or [0] to return to Shopper Menu \n");
- printf("Input: "); scanf("%c%c", &cExit, &cDump);
- if (cExit == '\0')
- page = 0;
- }
- if (i > currCateg){
- printf("End of List \n");
- cExit = '0';
- }
- }
- while (pRun->pFirstStock != NULL && cExit != '0');
- }
- /*Function checkOut has 1 use:
- 1. Checkout user cart
- @param i: index variable
- @param index: alternate index variable
- @param cChoice: for the switch case, but uses a character
- @param cDump: character variable that acts as a dump
- */
- void checkOut (userType *pUsers, aStocks *aCategories, int currCateg)
- {
- int index = 0, i = 0;
- char cDump, cChoice;
- categoryType * pRun;
- printf("Check Out \n");
- printf("Are you sure you would like to check out? [Y]/[N] \n");
- printf("Input: "); scanf("%s%c", cChoice, &cDump);
- do {
- if (cChoice == 'Y' || cChoice == 'y'){
- for (i=0;i<pUsers->nItems;i++)
- pUsers->cart[i].qty = 0;
- printf("Check out successful \n");
- printf("Adding to cart is now disabled for this account until items are delivered \n");
- printf("Returning to Shopper Menu");
- pUsers->nCheckedout == 1;
- }
- if (cChoice == 'N' || cChoice == 'n')
- printf("Returning to Shopper Menu \n");
- }while (cChoice == 'Y' || cChoice == 'y' || cChoice == 'n' || cChoice == 'N');
- }
- /*Function settleOutstanding has 1 use:
- 1. Settle User Outstanding
- @param settle: amount input by user to remove outstanding
- @param cDump: character variable that acts as a dump
- @param creditcardinfo: input by user
- */
- void settleOutstanding (userType *pUsers)
- {
- int exit = 1;
- float settle = 0.0;
- string15 creditcardinfo;
- char cDump;
- do {
- printf("Your outstanding balance is: %.2f \n", pUsers->outstanding);
- printf("Input credit card information \n");
- printf("Input: "); scanf("%s%c", creditcardinfo, &cDump);
- printf("Input amount to settle: "); scanf("%f", &settle);
- if (settle <= pUsers->outstanding){
- pUsers->outstanding -= settle;
- printf("Your new outstanding is %f", pUsers->outstanding);
- exit = 0;
- }
- if (settle > pUsers->outstanding){
- printf("Error, input amount is greater than outstanding \n");
- printf("Please input amount less or equal to outstanding \n");
- printf("Returning to Shopper Menu \n");
- exit = 0;
- }
- }while (exit == 0);
- }
- /*Function ShopperMenu has 9 uses:
- 1. Modify User Info
- 2. Browse All Products
- 3. Browse Products by Category
- 4. Browse Products on Sale
- 5. Add to Cart
- 6. View Cart
- 7. Check Out
- 8. Edit Cart Items
- 9. Settle Outstanding Balance
- @param choice: for the switch case, allows user to navigate throught menu
- @param page: limits the number of entries shown so the items do not simply flash
- @param cDump: character variable that acts as a dump
- @param exit: an exit for the do while loop to go back to the main menu when after choosing an option
- @param cExit: similar to exit, for option that requires a character input
- @param TempCategory: temporary string to compare to existing ones
- @param *pRun: variable that goes through the list to find what is needed
- */
- void ShopperMenu (userType *pUsers, userType *pNew, userType *pLast, userInfoType *pInfo, categoryType *pStock, aStocks* aCategories, int currCateg)
- {
- int choice = 0, page = 20;
- char cDump, cExit = '\0';
- int exit;
- string15 TempCategory;
- categoryType* pRun;
- do {
- printf("SHOPPER MENU \n");
- printf("[1] Modify User Info \n");
- printf("[2] Browse All Products \n");
- printf("[3] Browse Products by Category \n");
- printf("[4] Browse Products on Sale \n");
- if (pUsers->outstanding > 0 && pUsers->nCheckedout != 1);
- printf("[5] Add to Cart \n");
- if (pUsers->nItems > 0)
- printf("[6] View Cart \n");
- printf("[7] Check Out \n");
- printf("[8] Edit Cart Items \n");
- if (pUsers->outstanding > 0)
- printf("[9] Settle Outstanding Balance \n");
- printf("[0] Return to Main Menu \n");
- printf("Input: ");
- scanf("%d%c", &choice, &cDump);
- switch (choice){
- case 1: do {
- modifyUserInfo (pUsers, &pUsers->info);
- printf("Press [0] to Return to Shopper Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- //view locked
- break;
- case 2: do {
- browseProducts (aCategories);
- printf("Press [N] return to main menu or ENTER to view next page. \n");
- scanf("%c%c", &cExit, &cDump);
- }while (cExit=='\0');
- break;
- case 3: do {
- browsebyCategory (aCategories, currCateg);
- printf("Press [0] to Return to Shopper Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- break;
- case 4: do {
- browseOnSale (aCategories, currCateg);
- printf("Press [0] to Return to Shopper Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- break;
- case 5: if (pUsers->nCheckedout == 1){
- printf("Error, items not yet cleared \n");
- exit = 0;
- }
- else if (pUsers->nCheckedout != 1){
- do {
- AddtoCart (pUsers, aCategories, currCateg);
- printf("Press [0] to Return to Shopper Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- }
- break;
- case 6: do {
- printf("Viewing Cart \n");
- ViewCart (pUsers, aCategories, currCateg);
- printf("Press [0] to Return to Shopper Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- break;
- case 7: do {
- checkOut(pUsers, aCategories, currCateg);
- printf("Press [0] to Return to Shopper Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- break;
- case 8: do {
- EditCart (pUsers, aCategories, currCateg);
- printf("Press [0] to Return to Shopper Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- }while (exit==1);
- break;
- case 9: do {
- settleOutstanding(pUsers);
- printf("Press [0] to Return to Shopper Menu \n");
- printf("Input: ");
- scanf("%d%c", &exit, &cDump);
- }while (exit ==1);
- break;
- default: printf("Your account has been successfully logged out. \n");
- pUsers->nLoggedin = 0;
- choice = 0;
- break;
- }
- }while (choice > 0 && choice < 9);
- }
- /*Function AdminMenu has 5 uses:
- 1. Access manage accounts menu
- 2. Access manage stocks menu
- 3. Prepare Delivery Receipt for Shopper
- 4. Shutdown the kiosk, end the program
- 5. Log out the administrator, returning to the main menu
- @param choice: for the switch case, allows user to navigate throught menu
- @param cDump: character variable that acts as a dump
- @param exit: an exit for the do while loop to go back to the main menu when after choosing an option
- */
- int AdminMenu (userType *pUsers, userType *pNew, userType *pLast, userInfoType *pInfo, categoryType *pStock, categoryType *pNewStock, categoryType *pEnd, aStocks* aCategories, int currCateg)
- {
- int choice, exit = 1;
- char cDump;
- do {
- printf("ADMINISTRATOR MENU \n");
- printf("[1] Manage Accounts Menu \n");
- printf("[2] Manage Stocks Menu \n");
- printf("[3] Prepare Delivery Receipt \n");
- printf("[4] Shutdown Kiosk \n");
- printf("[5] Log Out \n");
- printf("Input: ");
- scanf("%d%c", &choice, &cDump);
- switch (choice){
- case 1: do {
- AdminManageAccounts (pUsers, &pUsers->info);
- printf("Press [0] to return to Administrator Menu: ");
- scanf("%d", &exit);
- }while (exit==1);
- return 1;
- break;
- case 2: do {
- AdminManageStocks (pUsers, pStock, pNewStock, pEnd, aCategories, currCateg);
- printf("Press [0] to return to Administrator Menu: ");
- scanf("%d", &exit);
- }while (exit==1);
- return 1;
- break;
- case 3: do {
- AdminPrepareDelivery (pUsers, &pUsers->info, aCategories);
- printf("Press [0] to return to Administrator Menu: ");
- scanf("%d", &exit);
- }while (exit==1);
- return 1;
- break;
- case 4:
- printf("Kiosk Shutdown. \n");
- freeAll(&pUsers);
- freeAllStock(&pStock, aCategories, currCateg);
- choice = 0;
- return 0;
- break;
- case 5:
- pUsers->nLoggedin == 0;
- printf("Your account has been successfully logged out. \n");
- return 1;
- break;
- default: printf("Invalid Input. Returning to Main Menu. \n");
- return 1;
- break;
- }
- }while (choice > 0 && choice < 5 && choice != 4);
- }
- /*Function menu has 2 uses:
- 1. Sign up new users
- 2. Log in an existing user
- @param choice: for the switch case, allows user to navigate throught menu
- @param cDump: character variable that acts as a dump
- @param exit: an exit for the do while loop to go back to the main menu when after choosing an option
- */
- void menu (userType *pUsers, userType *pNew, userType *pLast, categoryType *pStock, categoryType *pNewStock, categoryType *pEnd, aStocks *aCategories, int currCateg)
- {
- int choice=0;
- char cDump;
- int exit;
- pUsers = NULL;
- pNew = NULL;
- pLast = NULL;
- ptrUser pRun, pTrail;
- do {
- printf("MAIN MENU \n");
- printf("[1] Sign Up \n");
- printf("[2] Log In \n");
- //printf("[0] Shutdown Kiosk \n");
- printf("Choice: ");
- scanf("%d%c", &choice,&cDump);
- if (choice > 2 || choice < 0){
- printf("INVALID INPUT \n \n");
- menu (pUsers, pNew, pLast, pStock, pNewStock, pEnd, aCategories, currCateg);
- }
- switch (choice){
- case 1:
- do{
- pNew = malloc(sizeof(userType));
- signUp(pNew, pUsers);
- pNew -> pNext = NULL;
- if (pUsers == NULL) //if list is empty
- pUsers = pNew;
- else if (strcmp(pUsers -> username, pNew -> username) > 0){ //conect as first node
- pNew -> pNext = pUsers;
- pUsers = pNew;
- }
- else { //modifying middle of list
- pRun = pUsers;
- while (pRun != NULL && strcmp(pRun -> username, pNew -> username) < 0){
- pTrail = pRun;
- pRun = pRun -> pNext;
- }
- pTrail -> pNext = pNew;
- pNew -> pNext = pRun;
- }
- getUserInfo (&pUsers->info);
- printf("Press [0] to create a new user or [1] to return to main menu: ");
- scanf("%d%c", &exit, &cDump);
- if(exit>1||exit<0)
- {
- printf("Invalid input! returning you to main menu");
- exit = 1;
- }
- }while(exit==0);
- break;
- case 2:
- if (signIn(pUsers, &pUsers->info , pNew, pLast)==1)
- ShopperMenu (pUsers, pNew, pLast, &pUsers->info, pStock, aCategories, currCateg);
- else if (signIn(pUsers, &pUsers->info , pNew, pLast)==2)
- if (AdminMenu (pUsers, pNew, pLast, &pUsers->info, pStock, pNewStock, pEnd, aCategories, currCateg)==0)
- choice = 0;
- break;
- default:freeAll(&pUsers);
- freeAllStock(&pStock, aCategories, currCateg);
- break;
- }
- }while (choice == 1||choice == 2);
- freeAll(&pUsers);
- freeAllStock(&pStock, aCategories, currCateg);
- }
- int main ()
- {
- categoryType *pFirst,
- *pNewStock,
- *pEnd;
- userType *pUsers,
- *pNew,
- *pLast;
- ptrUser pRun, pTrail;
- aStocks aCategories;
- int currCateg = 0;
- menu (pUsers, pNew, pLast, pFirst, pNewStock, pEnd, &aCategories, currCateg);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement