Repository navigation
Expand file tree
/
Copy pathfinal.c
More file actions
196 lines (179 loc) · 5.82 KB
/
Copy pathfinal.c
File metadata and controls
196 lines (179 loc) · 5.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#include <stdio.h>
#include <windows.h>
#include <string.h>
#include "heads.h"
typedef struct {
char name[50];
char address[100];
char phone[15];
} Shop;
// Function to set console text color
void setColor(int color) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, color);
}
void clear() {
system("cls || clear");
}
void printShopDetails(char *title)
{
Shop shop;
const char *filename = "shop_details.txt";
loadShopDetails(&shop, filename);
clear();
// Get console handle
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
if (hConsole == NULL) {
printf("Error getting console handle\n");
return;
}
// Get console screen buffer info
CONSOLE_SCREEN_BUFFER_INFO csbi;
if (!GetConsoleScreenBufferInfo(hConsole, &csbi)) {
printf("Error getting console buffer info\n");
return;
}
// Calculate the console width
int consoleWidth = csbi.srWindow.Right - csbi.srWindow.Left + 1;
// Print top border
setColor(10); // Green color for borders
for (int i = 0; i < consoleWidth; i++) {
printf("-");
}
printf("\n");
// Center the title
int strLength = strlen(title);
int xPosition = (consoleWidth - strLength) / 2;
COORD coord;
coord.X = xPosition;
coord.Y = 1;
SetConsoleCursorPosition(hConsole, coord);
setColor(14); // Yellow color for the title
printf("%s %s\n", "Welcome to", shop.name);
int startY = 2; // Start printing below the title
coord.X = 0; // Left alignment
coord.Y = startY;
SetConsoleCursorPosition(hConsole, coord);
setColor(11); // Light blue for address lines
printf("%s", shop.address);
coord.X = consoleWidth - strlen(shop.phone) - 1; // Right-align phone number
SetConsoleCursorPosition(hConsole, coord);
setColor(13); // Pink for phone number
printf("%s", shop.phone);
// Print bottom border
coord.X = 0;
coord.Y = startY + 1;
SetConsoleCursorPosition(hConsole, coord);
setColor(10); // Green color for borders
for (int i = 0; i < consoleWidth; i++) {
printf("-");
}
printf("\n");
// Reset color to default
setColor(7); // White
}
void showMenu() {
clear();
int t = 0;
printShopDetails("Welcome to The Green Basket Grocery Shop");
setColor(14); // Yellow for the menu title
printf("Choose:\n");
setColor(11); // Light blue for menu options
printf("1 for seeing the inventory\n");
printf("2 for seeing a particular group of items\n");
printf("3 for adding an item in inventory\n");
printf("4 for deleting an item from inventory\n");
printf("5 for edit price of an Item\n");
printf("6 for edit quantity of item\n");
printf("7 for Placing Order and Generate Bill\n");
printf("8 for editing shop details\n");
printf("9 for seeing the Sales Report\n");
printf("10 for seeing the Order history\n");
printf("0 for Exit\n");
setColor(14); // Yellow for input prompt
printf("Enter your choice: ");
int p = scanf("%d", &t);
if (p != 1)
{
char ch;
while ((ch = getchar()) != '\n' && ch != EOF); // Clear input buffer
showMenu();
}
switch (t)
{
case 0 : clear(); return; break;
case 1 : showInventory(); break;
case 2 : showGroup(); break;
case 3 : addItem(); break;
case 4 : removeItem(); break;
case 5 : editPrice(); break;
case 6 : editQuantity(); break;
case 7 : order(); break;
case 8 : editDetails(); break;
case 9 : report(); break;
case 10: history(); break;
default: showMenu();
}
}
int main(int argc, char *argv[])
{
if (argc == 2) {
if (strcasecmp(argv[1], "-i") == 0)
{
printShopDetails("Welcome to The Green Basket Grocery Shop");
setColor(14); // Yellow for specific outputs
showInventory();
}
else if (strcasecmp(argv[1], "-o") == 0)
{
printShopDetails("Welcome to The Green Basket Grocery Shop");
setColor(11); // Light blue
order();
}
else if (strcasecmp(argv[1], "-h") == 0)
{
printShopDetails("Welcome to The Green Basket Grocery Shop");
setColor(11); // Light blue
history();
}
else if (strcasecmp(argv[1], "-g") == 0)
{
printShopDetails("Welcome to The Green Basket Grocery Shop");
setColor(10); // Green
showGroup();
}
else if (strcasecmp(argv[1], "-a") == 0 || strcasecmp(argv[1], "--add") == 0)
{
printShopDetails("Welcome to The Green Basket Grocery Shop");
setColor(10); // Green
addItem();
}
else if (strcasecmp(argv[1], "-ep") == 0)
{
printShopDetails("Welcome to The Green Basket Grocery Shop");
setColor(13); // Pink
editPrice();
}
else if (strcasecmp(argv[1], "-eq") == 0)
{
printShopDetails("Welcome to The Green Basket Grocery Shop");
setColor(13); // Pink
editQuantity();
}
else if (strcasecmp(argv[1], "--rem") == 0 || strcasecmp(argv[1], "-r") == 0)
{
printShopDetails("Welcome to The Green Basket Grocery Shop");
setColor(13); // Pink
removeItem();
}
else
{
setColor(12); // Red for errors
fprintf(stderr, "Enter Valid Command!\n");
}
} else if (argc == 1)
showMenu();
// Reset to default color
setColor(7);
return 0;
}