Advertisement
Guest User

Untitled

a guest
Nov 27th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.94 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. #define LINESIZE 200
  7. #define SIZE 40
  8. #define repricing_col 4
  9. #define opportunity_col 9
  10.  
  11.  
  12. int login_input(char* connected_as);
  13. int login(char* user, char* password);
  14. void make_array(char*** array, char* database_name, int database_columns);
  15.  
  16. /*EMPLOYEE MENU*/
  17. void employee_menu(char* connected_as); // Print Employee-Menu
  18. void print_database(char* db_name); // Open the Opportunity-Table Database and print it
  19. int search_existing_customer(); // return 0 / 1 if customer dose exist / dose not exist in the database
  20. void update_existing_customer(); // if customer dose existing in the database >> call this function
  21. void assign_new_customer(char* connected_as); // if customer dose not existing in the database >> call this function
  22. void todo_list_database(); // TODO-List Database
  23. void self_reports(char* name); // Employee Self-Reports
  24.  
  25. /*MANAGER MENU*/
  26. void manager_menu(char* connected_as);
  27. void print_database(char* db_name); // Open the Opportunity-Table Database and print it
  28. int search_existing_customer(); // return 0 / 1 if customer dose exist / dose not exist in the database
  29. void update_existing_customer(); // if customer dose existing in the database >> call this function
  30. void assign_new_customer(char* connected_as); // if customer dose not existing in the database >> call this function
  31. void todo_list_database(); // TODO-List Database
  32. void all_reports_menu(); // All Reports Menu to choose specific report
  33. void repricing_products(); // Repricing products in the database
  34.  
  35. /*All REPORTS MENU FOR MANAGER ONLY!*/
  36. void report_by_name(); // { scanf char* name->calls self_reports function }
  37. void new_customers_last_month(); // from Opportunity Table (MAYBE WE HAVE TO ADD 'DATE OF JOIN' IN THE CUSTOMER DETAILS)
  38. void new_customers_last_year();// from Opportunity Table (MAYBE WE HAVE TO ADD 'DATE OF JOIN' IN THE CUSTOMER DETAILS)
  39. void successful_deals_last_month(); // from Opportunity Table, Status: "Win"
  40. void successful_deals_last_year(); // from Opportunity Table, Status: "Win"
  41.  
  42.  
  43. int main() {
  44. // connected_as = (char*)malloc(SIZE * sizeof(char));
  45. // int log = login_input(connected_as);
  46. char* connected_as = NULL;
  47.  
  48. int log = 0;
  49. printf("check: 1 - employee /// 2 - manager: ");
  50. scanf("%d", &log);
  51. if (log == 1)
  52. employee_menu(connected_as);
  53. if (log == 2)
  54. manager_menu(connected_as);
  55. return 0;
  56. }
  57.  
  58. /*NOT COMPLITED!*/
  59. void all_reports_menu(char* connected_as) {
  60. int report_choice;
  61.  
  62. printf("%30.s");
  63. printf("**************************************************\n");
  64. printf("%30.s");
  65. printf("**************** ALL REPORTS MENU ****************\n");
  66. printf("%30.s");
  67. printf("**************************************************\n");
  68. printf("%30.s");
  69. printf("** 1. Report By Name of Employee **\n");
  70. printf("%30.s");
  71. printf("** 2. Last Month New Customers **\n");
  72. printf("%30.s");
  73. printf("** 3. Last Year New Customers **\n");
  74. printf("%30.s");
  75. printf("** 4. Last Month Successful Deals **\n");
  76. printf("%30.s");
  77. printf("** 5. Last Year Successful Deals **\n");
  78. printf("%30.s");
  79. printf("** 0. Go Back To Previous Menu **\n");
  80. printf("%30.s");
  81. printf("**************************************************\n\n");
  82.  
  83. printf("Enter Your Choice: ");
  84. scanf("%d", &report_choice);
  85.  
  86. while (report_choice < 0 || report_choice > 5 && (report_choice <= '/' || report_choice >= ':')) {
  87. printf("Wrong choice - Enter Your Choice: ");
  88. fseek(stdin, 0, SEEK_END);
  89. scanf("%d", &report_choice);
  90. }
  91. switch (report_choice) {
  92. case 1:
  93. /// report_by_name();
  94. break;
  95. case 2:
  96. /// new_customers_last_month();
  97. break;
  98. case 3:
  99. /// new_customers_last_year();
  100. break;
  101. case 4:
  102. /// successful_deals_last_month();
  103. break;
  104. case 5:
  105. /// successful_deals_last_year();
  106. break;
  107. case 0:
  108. manager_menu(connected_as);
  109. break;
  110. default:
  111.  
  112. break;
  113. }
  114. }
  115.  
  116. /*NOT COMPLITED!*/
  117. void manager_menu(char* connected_as) {
  118. int manager_choice;
  119. int customer_ID = 0;
  120. char*** database_array = NULL;
  121.  
  122.  
  123. printf("%30.s");
  124. printf("**************************************************\n");
  125. printf("%30.s");
  126. printf("****************** MANAGER MENU ******************\n");
  127. printf("%30.s");
  128. printf("**************************************************\n");
  129. printf("%30.s");
  130. printf("** 1. Print Opportunity Table **\n");
  131. printf("%30.s");
  132. printf("** 2. Search existing customer **\n");
  133. printf("%30.s");
  134. printf("** 3. TO-DO List **\n");
  135. printf("%30.s");
  136. printf("** 4. All Reports **\n");
  137. printf("%30.s");
  138. printf("** 5. Print Price List **\n");
  139. printf("%30.s");
  140. printf("** 6. Repricing Products **\n");
  141. printf("%30.s");
  142. printf("** 0. Exit **\n");
  143. printf("%30.s");
  144. printf("**************************************************\n\n");
  145.  
  146. printf("Enter Your Choice: ");
  147. scanf("%d", &manager_choice);
  148. while (manager_choice < 0 || manager_choice > 6 && (manager_choice <= '/' || manager_choice >= ':'))
  149. {
  150. printf("Wrong choice - Enter Your Choice: ");
  151. fseek(stdin, 0, SEEK_END);
  152. scanf("%d", &manager_choice);
  153. }
  154. switch (manager_choice) {
  155. case 0:
  156. printf("Good Bye");
  157. exit(0);
  158. break;
  159. case 1:
  160. print_database("opportunity_table.csv");
  161. break;
  162. case 2:
  163. /// printf("Enter customer's ID: ");
  164. /// scanf("%d", &customer_ID);
  165. /// if (search_existing_customer(customer_ID)) {
  166. /// update_customer_details(customer_ID);
  167. /// }
  168. /// assign_new_customer(char* connected_as);
  169. break;
  170. case 3:
  171. /// todo_list_database();
  172. break;
  173. case 4:
  174. all_reports_menu(connected_as);
  175. break;
  176. case 5:
  177. print_database("data_base_repricing.csv");
  178. break;
  179. case 6:
  180. /// repricing_products();
  181. break;
  182. default:
  183. break;
  184. }
  185.  
  186. }
  187.  
  188. /*NOT COMPLITED!*/
  189. void employee_menu() {
  190. int employee_choice;
  191. int customer_ID = 0;
  192. char*** database_array = NULL;
  193.  
  194. printf("%30.s");
  195. printf("***************************************************\n");
  196. printf("%30.s");
  197. printf("****************** EMPLOYEE MENU ******************\n");
  198. printf("%30.s");
  199. printf("***************************************************\n");
  200. printf("%30.s");
  201. printf("** 1. Opportunity Table **\n");
  202. printf("%30.s");
  203. printf("** 2. Search existing customer **\n");
  204. printf("%30.s");
  205. printf("** 3. TO-DO List **\n");
  206. printf("%30.s");
  207. printf("** 4. Self Reports **\n");
  208. printf("%30.s");
  209. printf("** 5. Print Price List **\n");
  210. printf("%30.s");
  211. printf("** 0. Exit **\n");
  212. printf("%30.s");
  213. printf("***************************************************\n\n");
  214.  
  215. printf("Enter Your Choice: ");
  216. scanf("%d", &employee_choice);
  217.  
  218. while (employee_choice < 0 || employee_choice > 5 && (employee_choice <= '/' || employee_choice >= ':')) {
  219. printf("Wrong choice - Enter Your Choice: ");
  220. fseek(stdin, 0, SEEK_END);
  221. scanf("%d", &employee_choice);
  222. }
  223. switch (employee_choice) {
  224. case 0:
  225. printf("Good Bye");
  226. exit(0);
  227. break;
  228. case 1:
  229. print_database("opportunity_table.csv");
  230. break;
  231. case 2:
  232. /// printf("Enter customer's ID: ");
  233. /// scanf("%d", &customer_ID);
  234. /// if (search_existing_customer(customer_ID)) {
  235. /// update_customer_details(customer_ID);
  236. /// }
  237. /// assign_new_customer(char* connected_as);
  238. break;
  239. case 3:
  240. /// todo_list_database();
  241. break;
  242. case 4:
  243. /// self_reports(/*employee name*/);
  244. break;
  245. case 5:
  246. print_database("data_base_repricing.csv");
  247. break;
  248. default:
  249. break;
  250. }
  251. }
  252.  
  253.  
  254. /*customize this function*/
  255. void print_database(char* db_name)
  256. {
  257. int i = 0;
  258. int numofrows = 0;
  259. char line[LINESIZE] = "";
  260. char *item, *comma = NULL;
  261. char info_matrix[50][LINESIZE] = { "" };
  262. FILE* fp = fopen(db_name, "r");
  263.  
  264. if (!fp) {
  265. printf("File failed to open!\n");
  266. exit(1);
  267. }
  268.  
  269. for (int u = 0; u < 3; ++u)
  270. fscanf(fp, "%c");
  271.  
  272. while (fgets(line, LINESIZE, fp)) {
  273. strcpy(info_matrix[i], line);
  274. ++i;
  275. ++numofrows;
  276. }
  277.  
  278. if (db_name == "opportunity_table.csv") {
  279. int width[opportunity_col] = { 25,16,26,16,23,18,23,23,23 };
  280. for (int loop = 0; loop < numofrows; ++loop) {
  281. int field = 0;
  282. item = info_matrix[loop];
  283. while (*item && (comma = strpbrk(item, ",\n"))) {//pointer to each comma and the newline
  284. printf("%-*.*s", width[field], comma - item, item);
  285. item = comma + 1;//skip the comma or newline
  286. field++;
  287. }
  288. printf("\n");
  289. }
  290. }
  291.  
  292. if (db_name == "data_base_repricing.csv") {
  293. int width[opportunity_col] = { 25,16,26,16 };
  294.  
  295. for (int loop = 0; loop < numofrows; ++loop) {
  296. int field = 0;
  297. item = info_matrix[loop];
  298. while (*item && (comma = strpbrk(item, ",\n"))) {//pointer to each comma and the newline
  299. printf("%-*.*s", width[field], comma - item, item);
  300. item = comma + 1;//skip the comma or newline
  301. field++;
  302. }
  303. printf("\n");
  304. }
  305. }
  306. printf("\n\n");
  307. }
  308.  
  309. /*THOSE FuNCTIONS WORKS FINE!*/
  310. void make_array(char*** db_array, char* db_name, int db_columns) {
  311. int i = 0, j = 3, k = 0, l = 0, m = 0;
  312. char temp[250];
  313. int linesnum = 0;
  314. FILE* fp;
  315. char line[LINESIZE];
  316. fp = fopen(db_name, "r");
  317. if (!fp) {
  318. printf("File failed to open!\n");
  319. exit(1);
  320. }
  321. while (fgets(line, LINESIZE, fp))
  322. linesnum++;
  323. db_array = (char *)malloc(sizeof(char*)*linesnum);
  324. rewind(fp);
  325. for (i; i < linesnum; ++i) {
  326. db_array[i] = (char*)malloc(sizeof(char*)*db_columns);
  327. }
  328. while (fgets(line, LINESIZE, fp)) {
  329.  
  330. for (i = 0; i < db_columns; ++i) {
  331.  
  332. while (line[j] != ','&& line[j] != '\n')
  333. {
  334. temp[k] = line[j];
  335. ++k;
  336. ++j;
  337. }
  338. ++j;
  339. temp[k] = '\0';
  340. k = 0;
  341. db_array[l][i] = malloc(strlen(temp) + 1);
  342. strcpy(db_array[l][i], temp);
  343. }
  344. l++;
  345. j = 0;
  346. }
  347.  
  348. for (i = 0; i < linesnum; ++i) {
  349. for (j = 0; j < db_columns; ++j)
  350. printf("%s\t", db_array[i][j]);
  351. printf("\n");
  352. }
  353.  
  354. fclose(fp);
  355. }
  356.  
  357. int login(char* user, char* password) {
  358. /*
  359. The function gets char* of username and password.
  360. The function returns: 1 if the user is a employee, 2 if manager,0 if there is a wrong login details.
  361. there needs to be a csv file where each row conatins 3 clumns: username,password and employee type.
  362. */
  363. FILE* fp;
  364. int i = 0;
  365. int j = 0;
  366. char line[LINESIZE];
  367. char fUser[LINESIZE];
  368. char fPassword[LINESIZE];
  369. char type[LINESIZE];
  370. fp = fopen("data_base_log_in.csv", "r");
  371. if (!fp) {
  372. printf("File failed to open!\n");
  373. exit(1);
  374. }
  375. while (fgets(line, LINESIZE, fp)) {//gets a row each time every clumn separated by comas
  376. i = 0;
  377. j = 0;
  378. while (line[i] != ',')
  379. {
  380. if ((line[i] >= 'a' && line[i] <= 'z') || (line[i] >= 'A' && line[i] <= 'Z') || (line[i] >= '0'&&line[i] <= '9')) {//gets username and clears junk
  381. fUser[j] = line[i];
  382. ++j;
  383. }
  384. ++i;
  385. }
  386. fUser[j] = '\0';
  387. if (strcmp(user, fUser) == 0)
  388. {
  389. j = 0;
  390. ++i;
  391. while (line[i] != ',') {//gets password from line
  392. fPassword[j] = line[i];
  393. ++j;
  394. ++i;
  395. }
  396. fPassword[j] = '\0';
  397.  
  398. if (strcmp(password, fPassword) == 0) {
  399. j = 0;
  400. ++i;
  401. while (line[i] != '\n') {//gets type from line
  402. type[j] = line[i];
  403. ++j;
  404. ++i;
  405. }
  406. type[j] = '\0';
  407. if (strcmp(type, "manager") == 0) {
  408. return 2;
  409. }
  410. if (strcmp(type, "employee") == 0) {
  411. return 1;
  412. }
  413. }
  414. }
  415. }
  416. return 0;
  417. }
  418.  
  419. int login_input(char* connected_as) {
  420. int log = 0;
  421. char user[LINESIZE];
  422. char password[LINESIZE];
  423. do
  424. {
  425. puts("Enter username:");
  426. gets(user);
  427. puts("Enter password:");
  428. gets(password);
  429. log = login(user, password);
  430. if (log == 0)
  431. puts("Wrong username or password try again");
  432. } while (log == 0);
  433. strcpy(connected_as, user);
  434. return log;
  435. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement