Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.07 KB | None | 0 0
  1. #include <mysql.h>
  2. #include<stdio.h>
  3. #include<string.h>
  4.  
  5. ///Function We Use
  6. void Menu(void);
  7. void welcome(void);
  8. void choice(void);
  9. void add(void);
  10. void deletebooks(void);
  11. void editbooks(void);
  12. void closeapplication(void);
  13.  
  14.  
  15. void finish_with_error(MYSQL *con)
  16. {
  17. fprintf(stderr, "%s\n", mysql_error(con));
  18. mysql_close(con);
  19. exit(1);
  20. }
  21.  
  22.  
  23. ///Password Part
  24. void Password(void)
  25. {
  26. char password[10]= {"CHAMPION"};
  27. char input[50];
  28.  
  29. printf("\n\n\n\n\t\t\t \xB2\xDB\xB2\xDB\xB2 PASSWORD PROTECTED \xB2\xDB\xB2\xDB\n\n");
  30. printf("\t\t\t (Type 'CHAMPION' for Password) \n\n\n\n");
  31. printf(" \t\t Enter Password : ");
  32.  
  33. gets(input);
  34. if(strcmp(password,input)==0)
  35. {
  36. printf("\n\t\tPassword Match\n");
  37. printf("\n\t\tPress Any key to continue...");
  38. getch();
  39. }
  40. else
  41. {
  42. printf("\n\n\n\n\a\t\tWarning!! Incorrect Password\n");
  43. printf("\n\t\tPress Any key to Re-Enter your password...");
  44. getch();
  45. system("cls");
  46. Password();
  47. }
  48. }
  49.  
  50. ///Welcome Part
  51. void welcome(void)
  52. {
  53. printf("\n\n\n\n\t\t Welcome to Library Management System Time: %s\n",__TIME__);
  54. printf("\t\t\t\t\t\t\t Date: %s\n\n",__DATE__);
  55.  
  56. printf("\t\t * ** ** ******** \n");
  57. printf("\t\t * * * * * * * \n");
  58. printf("\t\t * * * * * * \n");
  59. printf("\t\t * * *** * ******** \n");
  60. printf("\t\t * * * * \n");
  61. printf("\t\t * * * * * * \n");
  62. printf("\t\t ******** * * ******** ...... \n");
  63.  
  64. printf("\n\n\n\n\t\t\t\t\t\t Developed by\n\n");
  65. printf("\t\t\t\t\t\tJannatul Naim - 161311028\n");
  66. printf("\t\t\t\t\t Sad Bin Sadian Mridha - 161311025\n");
  67. printf("\t\t\t\t\t Dept. Of C.S.E, Varendra University\n");
  68. printf("\n\n\t\tPress Any key to Continue...");
  69. getch();
  70. }
  71.  
  72.  
  73. ///Main Menu
  74. void Menu(void)
  75. {
  76. printf("\n\n\n\n\n");
  77. printf("\t\t\t\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2 MAIN MENU");
  78. printf(" \xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\n\n");
  79.  
  80. printf("\t\t\t\xDB\xDB\xDB\xDB\xB2 1. Add Books \n\n");
  81.  
  82. printf("\t\t\t\xDB\xDB\xDB\xDB\xB2 2. Delete Books\n\n");
  83.  
  84. printf("\t\t\t\xDB\xDB\xDB\xDB\xB2 3. Update Book's Record\n\n");
  85.  
  86. printf("\t\t\t\xDB\xDB\xDB\xDB\xB2 4. Close Application\n\n");
  87.  
  88. printf("\t\t\t----------------------------------------\n");
  89.  
  90. printf("\t\t\tEnter your choice:\n\n");
  91.  
  92. }
  93.  
  94. ///Main Function
  95. int main(int argc, char **argv)
  96. {
  97. int A,B,C,j;
  98.  
  99.  
  100. ///MYSQL Connection With Server
  101. char *server = "localhost";
  102. char *user = "root";
  103. char *password = "";
  104. char *database = "Library Management System";
  105.  
  106. MYSQL *conn = mysql_init(NULL);
  107.  
  108. if (conn == NULL)
  109. {
  110. fprintf(stderr, "%s\n", mysql_error(conn));
  111. exit(1);
  112. }
  113.  
  114. if (!mysql_real_connect(conn, server,
  115. user, password, database, 0, NULL, 0))
  116. {
  117. fprintf(stderr, "%s\n", mysql_error(conn));
  118. mysql_close(conn);
  119. exit(1);
  120. }
  121.  
  122.  
  123. Password();
  124. system("cls");
  125. welcome();
  126. system("cls");
  127. L3:
  128. Menu();
  129.  
  130. scanf("%d",&A);
  131. system("cls");
  132. switch(A)
  133. {
  134. ///Data Insert
  135. case 1:
  136. printf("\n\n\n\t\t\t\t 1. Create A Table\n");
  137. printf("\t\t\t\t\t or\n");
  138. printf("\t\t\t\t 2. Already Created \n\n");
  139. printf("\t\t\t\t Enter your Choice : ");
  140. scanf("%d",&B);
  141.  
  142. if(B==1)
  143. {
  144.  
  145. if (mysql_query(conn, "CREATE TABLE BookInfo (ID INT(10), BookName VARCHAR(255),AuthorsName VARCHAR(255),Quantity INT(30),Rack INT(20), Price INT(10))"))
  146.  
  147. fprintf(stderr, "%s\n", mysql_error(conn));
  148. printf("\n\n\t\t\t Table Created SuccessFully\n");
  149. L2:
  150. goto L1;
  151.  
  152. }
  153. else if(B==2)
  154. {
  155.  
  156. L1:
  157. printf("\n\n\t\t Please Wait Your Inserted Data in Progress....\n");
  158.  
  159. for(j=0; j<20; j++)
  160. {
  161. printf("\t\t\t\t........\n");
  162. }
  163.  
  164. if (mysql_query(conn, "INSERT INTO BookInfo VALUES(1,'Teach Yourself','Ashraful Islam',5,3,120)"));
  165. {
  166. fprintf(stderr, "%s\n", mysql_error(conn));
  167.  
  168. }
  169. if (mysql_query(conn, "INSERT INTO BookInfo VALUES(2,'Easy Programming','Sad Bin Sadian Mridha',6,4,95)"));
  170. {
  171. fprintf(stderr, "%s\n", mysql_error(conn));
  172.  
  173. }
  174. if (mysql_query(conn, "INSERT INTO BookInfo VALUES(3,'C++ Book ','Naim Noyon',9,6,125)"));
  175. {
  176. fprintf(stderr, "%s\n", mysql_error(conn));
  177.  
  178. }
  179. if (mysql_query(conn, "INSERT INTO BookInfo VALUES(4,'C# for Beginner','Sahrier Subin',7,2,165)"));
  180. {
  181. fprintf(stderr, "%s\n", mysql_error(conn));
  182.  
  183. }
  184. if (mysql_query(conn, "INSERT INTO BookInfo VALUES(5,'Learn Java','Herbart Sheld',5,3,120)"));
  185. {
  186. fprintf(stderr, "%s\n", mysql_error(conn));
  187.  
  188. }
  189. printf("\n\t\t Your Data Inserted SuccessFully\n\n\n");
  190. }
  191. printf("\n\t\t Do you want to Insert Again-Yes(1),No(2)\n");
  192. printf("\n\t\t Enter your Choice : ");
  193. scanf("%d",&C);
  194. if(C==1)
  195. {
  196. system("cls");
  197. goto L2;
  198. }
  199. else if (C==2)
  200. {
  201. system("cls");
  202. goto L3;
  203. }
  204. ///Data Delete
  205. case 2:
  206. if (mysql_query(conn, "DELETE FROM BookInfo WHERE ID=1"));
  207. {
  208. L4:
  209. printf("\n\n\t\t Please Wait Your Deleted Data in Progress....\n");
  210.  
  211. for(j=0; j<20; j++)
  212. {
  213. printf("\t\t\t\t........\n");
  214. }
  215. fprintf(stderr, "%s\n", mysql_error(conn));
  216. printf("\n\t\t Your Data Deleted SuccessFully\n\n\n");
  217.  
  218. }
  219. printf("\n\t\t Do you want to Delete Again-Yes(1),No(2)\n");
  220. printf("\n\t\t Enter your Choice : ");
  221. scanf("%d",&C);
  222. if(C==1)
  223. {
  224. system("cls");
  225. goto L4;
  226. }
  227. else if (C==2)
  228. {
  229. system("cls");
  230. goto L3;
  231. }
  232.  
  233. ///Data Update
  234. case 3:
  235. if (mysql_query(conn, "UPDATE BookInfo SET ID=6 WHERE ID=5"));
  236. {
  237. L5:
  238. printf("\n\n\t\t Please Wait Your Updated Data in Progress....\n");
  239.  
  240. for(j=0; j<20; j++)
  241. {
  242. printf("\t\t\t\t........\n");
  243. }
  244. fprintf(stderr, "%s\n", mysql_error(conn));
  245. printf("\n\t\t Your Data Updated SuccessFully\n\n\n");
  246.  
  247. }
  248. printf("\n\t\t Do you want to Update Again-Yes(1),No(2)\n");
  249. printf("\n\t\t Enter your Choice : ");
  250. scanf("%d",&C);
  251. if(C==1)
  252. {
  253. system("cls");
  254. goto L5;
  255. }
  256. else if (C==2)
  257. {
  258. system("cls");
  259. goto L3;
  260. }
  261.  
  262. ///Closing Application
  263. case 4:
  264. system("cls");
  265. printf("\n\n\n\t\t\t Thanks for using the Program..\n\n\n\n");
  266. break;
  267. }
  268.  
  269. mysql_close(conn);
  270. exit(0);
  271.  
  272.  
  273. return 0;
  274. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement