ODBCデータソース、Sql Server、VS 2019による図書管理システムの作成

174262 ワード

接続h
#pragma once
#include
#include
#include
#include
#include
#include
char Account[50], Password[50], a[50], p[50];
SQLRETURN   ret;
SQLHENV    henv;
SQLHDBC    hdbc;
SQLHSTMT  hstmt;
void lianjie()
{
     
	ret = SQLAllocHandle(SQL_HANDLE_ENV, NULL, &henv);//      
	ret = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER);
	ret = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);//         

	ret = SQLConnect(hdbc, (SQLCHAR*)"wb", SQL_NTS, (SQLCHAR*)"sa", SQL_NTS, (SQLCHAR*)"123456", SQL_NTS);
	/*data_test    ODBC     */
	if (!(ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO))
	{
     
		printf("       !
"
); } else { printf(" !
"
); } /* odbc , study */ ret = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt); }

接続を解除します.h
#pragma once
#include"  .h"
void duankai() {
     
	SQLFreeHandle(SQL_HANDLE_DBC, hdbc);//      
	SQLFreeHandle(SQL_HANDLE_ENV, henv);//      
}


main.c
#include"  .h"
#include"    .h"
#include
int main()
{
     
	system("color 70");
	int s;
	printf("*************************************************************
"
); printf("*************************************************************
"
); printf("****************** !********************
"
); printf("*************************************************************
"
); printf("*************************************************************
"
); printf(" :
1:
2:
3:
"
); scanf("%d", &s); switch (s) { case 1:// { lianjie(); printf(" :
"
); scanf("%s", Account); printf(" :
"
); scanf("%s", Password); SQLCHAR sql3[] = "use study"; SQLCHAR sql4[] = "select * from admin"; ret = SQLExecDirect(hstmt, sql3, SQL_NTS); ret = SQLExecDirect(hstmt, sql4, SQL_NTS); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { SQLCHAR str1[50], str2[50]; SQLINTEGER len_str1, len_str2; while (SQLFetch(hstmt) != SQL_NO_DATA) { SQLGetData(hstmt, 1, SQL_C_CHAR, str1, 50, &len_str1); // SQLGetData(hstmt, 2, SQL_C_CHAR, str2, 50, &len_str2); for (int i = 0; i < 8; i++) { a[i] = str1[i]; } for (int i = 0; i < 6; i++) { p[i] = str2[i]; } if (strcmp(Account, a) == 0 && strcmp(Password, p) == 0 || strcmp(Account, a) == 0 && strcmp(Password, p) == 0) { printf("
"
); int x; duankai(); printf(" :
1:
2:
3:
4:
5:
6:
"
); scanf("%d", &x); switch (x) { case 1: { lianjie(); SQLCHAR sql1[] = { "use study" }; SQLCHAR sql2[] = { "select * from book" }; ret = SQLExecDirect(hstmt, sql1, SQL_NTS); ret = SQLExecDirect(hstmt, sql2, SQL_NTS); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { SQLCHAR str1[50], str2[50], str3[50], str4[50], str5[50]; SQLINTEGER len_str1, len_str2, len_str3, len_str4, len_str5; while (SQLFetch(hstmt) != SQL_NO_DATA) { SQLGetData(hstmt, 1, SQL_C_CHAR, str1, 50, &len_str1); // SQLGetData(hstmt, 2, SQL_C_CHAR, str2, 50, &len_str2); SQLGetData(hstmt, 3, SQL_C_CHAR, str3, 50, &len_str3); SQLGetData(hstmt, 4, SQL_C_CHAR, str4, 50, &len_str4); SQLGetData(hstmt, 5, SQL_C_CHAR, str5, 50, &len_str5); printf("%s\t%s\t%s\t%s\t%s\t
"
, str1, str2, str3, str4, str5); } } } duankai(); break; case 2: { lianjie(); SQLCHAR sql1[] = { "use study" }; SQLCHAR sql2[] = { "select * from reader" }; ret = SQLExecDirect(hstmt, sql1, SQL_NTS); ret = SQLExecDirect(hstmt, sql2, SQL_NTS); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { SQLCHAR str1[50], str2[50], str3[50], str4[50], str5[50]; SQLINTEGER len_str1, len_str2, len_str3, len_str4, len_str5; while (SQLFetch(hstmt) != SQL_NO_DATA) { SQLGetData(hstmt, 1, SQL_C_CHAR, str1, 50, &len_str1); // SQLGetData(hstmt, 2, SQL_C_CHAR, str2, 50, &len_str2); SQLGetData(hstmt, 3, SQL_C_CHAR, str3, 50, &len_str3); SQLGetData(hstmt, 4, SQL_C_CHAR, str4, 50, &len_str4); SQLGetData(hstmt, 5, SQL_C_CHAR, str5, 50, &len_str5); printf("%s\t%s\t%s\t%s\t%s\t
"
, str1, str2, str3, str4, str5); } } }duankai(); break; case 3: { lianjie(); SQLCHAR sql1[] = { "use study" }; SQLCHAR sql2[] = { "select * from workman" }; ret = SQLExecDirect(hstmt, sql1, SQL_NTS); ret = SQLExecDirect(hstmt, sql2, SQL_NTS); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { SQLCHAR str1[50], str2[50], str3[50], str4[50]; SQLINTEGER len_str1, len_str2, len_str3, len_str4; while (SQLFetch(hstmt) != SQL_NO_DATA) { SQLGetData(hstmt, 1, SQL_C_CHAR, str1, 50, &len_str1); // SQLGetData(hstmt, 2, SQL_C_CHAR, str2, 50, &len_str2); SQLGetData(hstmt, 3, SQL_C_CHAR, str3, 50, &len_str3); SQLGetData(hstmt, 4, SQL_C_CHAR, str4, 50, &len_str4); printf("%s\t%s\t%s\t%s\t
"
, str1, str2, str3, str4); } } }duankai(); break; case 4: { lianjie(); int g; printf(" :
1:
2:
3:
"
); scanf("%d", &g); switch (g) { case 1: { char w[] = { " '," }; char b[] = { " ' " }; char i[] = { ")" }; SQLCHAR l[1000] = { "insert into dbo.book(b_no,b_name,author,publisher,price)values('" }; char d[50]; printf(" :
"
); scanf("%s", d); strcat((char*)l, d); strcat((char*)l, w); char e[50]; printf(" :
"
); scanf("%s", e); strcat((char*)l, b); strcat((char*)l, e); strcat((char*)l, w); char r[50]; printf(" :
"
); scanf("%s", r); strcat((char*)l, b); strcat((char*)l, r); strcat((char*)l, w); char y[50]; printf(" :
"
); scanf("%s", y); strcat((char*)l, b); strcat((char*)l, y); strcat((char*)l, w); char u[50]; printf(" :
"
); scanf("%s", u); strcat((char*)l, b); strcat((char*)l, u); strcat((char*)l, b); strcat((char*)l, i); ret = SQLExecDirect(hstmt, l, SQL_NTS); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { printf("
"
); } else { printf("
"
); } } case 2: { char w[] = { " '," }; char b[] = { " ' " }; char i[] = { ")" }; SQLCHAR l[1000] = { "insert into dbo.reader(r_no,r_name,enabled,tele,pwd)values('" }; char d[50]; printf(" :
"
); scanf("%s", d); strcat((char*)l, d); strcat((char*)l, w); char e[50]; printf(" :
"
); scanf("%s", e); strcat((char*)l, b); strcat((char*)l, e); strcat((char*)l, w); char r[50]; printf(" :(on off)
"
); scanf("%s", r); strcat((char*)l, b); strcat((char*)l, r); strcat((char*)l, w); char y[50]; printf(" :
"
); scanf("%s", y); strcat((char*)l, b); strcat((char*)l, y); strcat((char*)l, w); char u[50]; printf(" :
"
); scanf("%s", u); strcat((char*)l, b); strcat((char*)l, u); strcat((char*)l, b); strcat((char*)l, i); ret = SQLExecDirect(hstmt, l, SQL_NTS); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { printf("
"
); } else { printf("
"
); } } case 3: { char w[] = { " '," }; char b[] = { " ' " }; char i[] = { ")" }; SQLCHAR l[1000] = { "insert into dbo.workman(work_no,work_name,tele,pwd)values('" }; char d[50]; printf(" :
"
); scanf("%s", d); strcat((char*)l, d); strcat((char*)l, w); char e[50]; printf(" :
"
); scanf("%s", e); strcat((char*)l, b); strcat((char*)l, e); strcat((char*)l, w); char r[50]; printf(" :
"
); scanf("%s", r); strcat((char*)l, b); strcat((char*)l, r); strcat((char*)l, w); char u[50]; printf(" :
"
); scanf("%s", u); strcat((char*)l, b); strcat((char*)l, u); strcat((char*)l, b); strcat((char*)l, i); ret = SQLExecDirect(hstmt, l, SQL_NTS); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { printf("
"
); } else { printf("
"
); } } break; } duankai(); break; case 5: { lianjie(); int g; printf(" :
1:
2:
"
); scanf("%d", &g); switch (g) { case 1: { SQLCHAR l[1000] = { "update dbo.reader set pwd = " }; SQLCHAR k[1000] = { " where r_no = " }; char d[50]; printf(" :
"
); scanf("%s", d); strcat((char*)k, d); char e[50]; printf(" :
"
); scanf("%s", e); strcat((char*)l, e); strcat((char*)l, (char*)k); ret = SQLExecDirect(hstmt, l, SQL_NTS); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { printf("
"
); } else { printf("
"
); } }break; case 2: { SQLCHAR l[1000] = { "update dbo.workman set pwd = " }; SQLCHAR k[1000] = { " where work_no = " }; char d[50]; printf(" :
"
); scanf("%s", d); strcat((char*)k, d); char e[50]; printf(" :
"
); scanf("%s", e); strcat((char*)l, e); strcat((char*)l, (char*)k); ret = SQLExecDirect(hstmt, l, SQL_NTS); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { printf("
"
); } else { printf("
"
); } }break; } }duankai(); break; case 6: { lianjie(); int g; printf(" :
1:
2:
3:
"
); scanf("%d", &g); switch (g) { case 1: { SQLCHAR l[1000] = { "delete from dbo.book where b_no = " }; char d[50]; printf(" :
"
); scanf("%s", d); strcat((char*)l, d); ret = SQLExecDirect(hstmt, l, SQL_NTS); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { printf("
"
); } else { printf("
"
); } }break; case 2: { SQLCHAR l[1000] = { "delete from dbo.workman where work_no = " }; char d[50]; printf(" :
"
); scanf("%s", d); strcat((char*)l, d); ret = SQLExecDirect(hstmt, l, SQL_NTS); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { printf("
"
); } else { printf("
"
); } }break; case 3: { SQLCHAR l[1000] = { "delete from dbo.reader where r_no = " }; char d[50]; printf(" :
"
); scanf("%s", d); strcat((char*)l, d); ret = SQLExecDirect(hstmt, l, SQL_NTS); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { printf("
"
); } else { printf("
"
); } }break; } }duankai(); break; default:break; } } break; } } }; break; } case 2:// { lianjie(); printf(" :
"
); scanf("%s", Account); printf(" :
"
); scanf("%s", Password); SQLCHAR sql3[] = "use study"; SQLCHAR sql4[] = "select work_no,pwd from workman"; ret = SQLExecDirect(hstmt, sql3, SQL_NTS); ret = SQLExecDirect(hstmt, sql4, SQL_NTS); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { SQLCHAR str1[50], str2[50]; SQLINTEGER len_str1, len_str2; while (SQLFetch(hstmt) != SQL_NO_DATA) { SQLGetData(hstmt, 1, SQL_C_CHAR, str1, 50, &len_str1); // SQLGetData(hstmt, 2, SQL_C_CHAR, str2, 50, &len_str2); for (int i = 0; i < 8; i++) { a[i] = str1[i]; } for (int i = 0; i < 6; i++) { p[i] = str2[i]; } if (strcmp(Account, a) == 0 && strcmp(Password, p) == 0 || strcmp(Account, a) == 0 && strcmp(Password, p) == 0) { printf("
"
); int y; duankai(); printf(" :
1:
2:
3:
"
); scanf("%d", &y); switch (y) { case 1: { char w[] = { " '," }; char b[] = { " ' " }; char i[] = { ")" }; SQLCHAR l[1000] = { "insert into dbo.borrow(b_no,r_no,[borrow date],[due date])values('" }; char d[50]; printf(" :
"
); scanf("%s", d); strcat((char*)l, d); strcat((char*)l, w); char e[50]; printf(" :
"
); scanf("%s", e); strcat((char*)l, b); strcat((char*)l, e); strcat((char*)l, w); char r[50]; printf(" :( 1900-01-01)
"
); scanf("%s", r); strcat((char*)l, b); strcat((char*)l, r); strcat((char*)l, w); char u[50]; printf(" :( 1900-01-01)
"
); scanf("%s", u); strcat((char*)l, b); strcat((char*)l, u); strcat((char*)l, b); strcat((char*)l, i); ret = SQLExecDirect(hstmt, l, SQL_NTS); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { printf("
"
); } else { printf("
"
); } }break; case 2: { char w[] = { " '," }; char b[] = { " ' " }; char i[] = { ")" }; SQLCHAR l[1000] = { "insert into dbo.returnd(b_no,r_no,[return date]) values ('" }; char d[50]; printf(" :
"
); scanf("%s", d); strcat((char*)l, d); strcat((char*)l, w); char e[50]; printf(" :
"
); scanf("%s", e); strcat((char*)l, b); strcat((char*)l, e); strcat((char*)l, w); char u[50]; printf(" :( 1900-01-01)
"
); scanf("%s", u); strcat((char*)l, b); strcat((char*)l, u); strcat((char*)l, b); strcat((char*)l, i); ret = SQLExecDirect(hstmt, l, SQL_NTS); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { printf("
"
); } else { printf("
"
); } }break; case 3: { char w[] = { " '," }; char b[] = { " ' " }; char i[] = { ")" }; SQLCHAR l[1000] = { "insert into dbo.fine(b_no,r_no,[fine money]values('','','')" }; char d[50]; printf(" :
"
); scanf("%s", d); strcat((char*)l, d); strcat((char*)l, w); char e[50]; printf(" :
"
); scanf("%s", e); strcat((char*)l, b); strcat((char*)l, e); strcat((char*)l, w); char u[50]; printf(" :
"
); scanf("%s", u); strcat((char*)l, b); strcat((char*)l, u); strcat((char*)l, b); strcat((char*)l, i); ret = SQLExecDirect(hstmt, l, SQL_NTS); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { printf("
"
); } else { printf("
"
); } }break; default: break; } } } } }; break; case 3:// { lianjie(); printf(" :
"
); scanf("%s", Account); printf(" :
"
); scanf("%s", Password); SQLCHAR sql3[] = "use study"; SQLCHAR sql4[] = "select r_no,pwd from reader"; ret = SQLExecDirect(hstmt, sql3, SQL_NTS); ret = SQLExecDirect(hstmt, sql4, SQL_NTS); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { SQLCHAR str1[50], str2[50]; SQLINTEGER len_str1, len_str2; while (SQLFetch(hstmt) != SQL_NO_DATA) { SQLGetData(hstmt, 1, SQL_C_CHAR, str1, 50, &len_str1); // SQLGetData(hstmt, 2, SQL_C_CHAR, str2, 50, &len_str2); for (int i = 0; i < 8; i++) { a[i] = str1[i]; } for (int i = 0; i < 6; i++) { p[i] = str2[i]; } if (strcmp(Account, a) == 0 && strcmp(Password, p) == 0 || strcmp(Account, a) == 0 && strcmp(Password, p) == 0) { printf("
"
); int z; duankai(); printf(" :
1:
2:
3:
4:
"
); scanf("%d", &z); switch (z) { case 1: { lianjie(); SQLCHAR sql1[] = { "use study" }; SQLCHAR sql2[] = { "select * from book" }; ret = SQLExecDirect(hstmt, sql1, SQL_NTS); ret = SQLExecDirect(hstmt, sql2, SQL_NTS); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { SQLCHAR str1[50], str2[50], str3[50], str4[50], str5[50]; SQLINTEGER len_str1, len_str2, len_str3, len_str4, len_str5; while (SQLFetch(hstmt) != SQL_NO_DATA) { SQLGetData(hstmt, 1, SQL_C_CHAR, str1, 50, &len_str1); // SQLGetData(hstmt, 2, SQL_C_CHAR, str2, 50, &len_str2); SQLGetData(hstmt, 3, SQL_C_CHAR, str3, 50, &len_str3); SQLGetData(hstmt, 4, SQL_C_CHAR, str4, 50, &len_str4); SQLGetData(hstmt, 5, SQL_C_CHAR, str5, 50, &len_str5); printf("%s\t%s\t%s\t%s\t%s\t
"
, str1, str2, str3, str4, str5); } } }; duankai(); break; case 2: { lianjie(); SQLCHAR sql1[] = { "use study" }; SQLCHAR sql2[] = { "select * from borrow" }; ret = SQLExecDirect(hstmt, sql1, SQL_NTS); ret = SQLExecDirect(hstmt, sql2, SQL_NTS); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { SQLCHAR str1[50], str2[50], str3[50]; SQLINTEGER len_str1, len_str2, len_str3; while (SQLFetch(hstmt) != SQL_NO_DATA) { SQLGetData(hstmt, 1, SQL_C_CHAR, str1, 50, &len_str1); // SQLGetData(hstmt, 2, SQL_C_CHAR, str2, 50, &len_str2); SQLGetData(hstmt, 3, SQL_C_CHAR, str3, 50, &len_str3); printf("%s\t%s\t%s\t
"
, str1, str2, str3); } } }; duankai(); break; case 3: { char w[] = { " '," }; char b[] = { " ' " }; char i[] = { ")" }; SQLCHAR l[1000] = { "insert into dbo.borrow(b_no,r_no,[borrow date],[due date])values('" }; char d[50]; printf(" :
"
); scanf("%s", d); strcat((char*)l, d); strcat((char*)l, w); char e[50]; printf(" :
"
); scanf("%s", e); strcat((char*)l, b); strcat((char*)l, e); strcat((char*)l, w); char r[50]; printf(" :( 1900-01-01)
"
); scanf("%s", r); strcat((char*)l, b); strcat((char*)l, r); strcat((char*)l, w); char u[50]; printf(" :( 1900-01-01)
"
); scanf("%s", u); strcat((char*)l, b); strcat((char*)l, u); strcat((char*)l, b); strcat((char*)l, i); ret = SQLExecDirect(hstmt, l, SQL_NTS); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { printf("
"
); } else { printf("
"
); } }break; case 4: { char w[] = { " '," }; char b[] = { " ' " }; char i[] = { ")" }; SQLCHAR l[1000] = { "insert into dbo.returnd(b_no,r_no,[return date]) values ('" }; char d[50]; printf(" :
"
); scanf("%s", d); strcat((char*)l, d); strcat((char*)l, w); char e[50]; printf(" :
"
); scanf("%s", e); strcat((char*)l, b); strcat((char*)l, e); strcat((char*)l, w); char u[50]; printf(" :( 1900-01-01)
"
); scanf("%s", u); strcat((char*)l, b); strcat((char*)l, u); strcat((char*)l, b); strcat((char*)l, i); ret = SQLExecDirect(hstmt, l, SQL_NTS); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { printf("
"
); } else { printf("
"
); } }break; default: break; } } } } }; break; return 0; } }