database.sarang.net
UserID
Passwd
Database
ㆍDBMS
MySQL
PostgreSQL
Firebird
Oracle
Informix
Sybase
MS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
DBMS Q&A 1058 게시물 읽기
No. 1058
뭐가 문제 인지..이거 참 난감하네요..
작성자
초보자
작성일
2004-12-12 14:16
조회수
11,427

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
#include <time.h>

HENV henv;
HDBC hdbc;
HSTMT hstmt;


int ConnecToDB ( unsigned char *id, unsigned char *pwd, unsigned char *dsn )
{
RETCODE retcode;

retcode = SQLAllocEnv(&henv);
if(retcode == SQL_SUCCESS) {
retcode = SQLAllocConnect(henv,&hdbc);
if(retcode == SQL_SUCCESS)
{
SQLSetConnectOption(hdbc,SQL_LOGIN_TIMEOUT,5);

retcode = SQLConnect(hdbc,dsn,SQL_NTS,id,SQL_NTS,pwd,SQL_NTS);
if(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
return 1;
}
return 0;
}
return 0;
}
return 0;
}

int DisconnectDB()
{
SQLDisconnect(hdbc);
SQLFreeConnect(hdbc);
SQLFreeEnv(henv);
return 1;
}

 

void get_new_account_num(char *num)
{
char query[1048];
RETCODE retcode;
SQLCHAR szA[1048];
SQLINTEGER cbA;
int NewNum;


if(ConnecToDB("","","bankdsn" ) == 0)
{
printf("db접속 에러");
return;
}


strcpy(query,"select max(num) from account");
SQLAllocStmt(hdbc,&hstmt);
retcode = SQLExecDirect(hstmt,query,SQL_NTS );

if(retcode == SQL_SUCCESS)
{
SQLFetch(hstmt);
SQLGetData(hstmt,1,SQL_CHAR,&szA,1048,&cbA);
NewNum = atoi(szA);
sprintf(num,"%d",++NewNum);
}

else
{
strcpy(num,"1");
}

DisconnectDB();

 

}

void get_current_time(char *create)
{
time_t timer;
struct tm *t;

time(&timer);

t= localtime(&timer);
sprintf(create,"%d-%d-%d %d:%d:%d",t -> tm_year + 1900, t -> tm_mon + 1,t -> tm_mday,t -> tm_hour,t -> tm_min, t-> tm_sec);

}

void account_open(void)
{
char num[14],create[20],name[20],branch[20],password[5],tel[30];
char query[1048];
RETCODE retcode;

printf("\n>>새로운 계좌를 생성합니다.\n>>");

get_new_account_num(num);
get_current_time(create);


printf("이름: ");
gets(name);

printf("지점: ");
gets(branch);

printf("비밀번호: ");
gets(password);

printf("전화번호: ");
gets(tel);

printf("\n>>새로운 계좌 번호 : %s\n\n",num);


if(ConnecToDB("","","bankdsn" ) == 0)
{
printf("db접속 에러");
return;
}


sprintf(query,"insert into account values ('%s','%s','%s','%s','%s','%s',0)",num,create,name,branch,password,tel);
SQLAllocStmt(hdbc,&hstmt);
retcode = SQLExecDirect(hstmt,query,SQL_NTS );

if( retcode == SQL_SUCCESS ) printf("입력 성공\n\n");
else printf("입력에 실패 하였습니다.\n\n");

DisconnectDB();

 

}

void account_search(void)
{
char num[13],password[5];
char query[1048];
RETCODE retcode;
SQLCHAR szA[100];
SQLINTEGER cbA;


printf("\n해당 계좌의 다른 정보를 검색합니다.\n");

printf("계좌번호:");
gets(num);

printf("비밀번호: ");
gets(password);

if(ConnecToDB("","","bankdsn" ) == 0)
{
printf("db접속 에러");
return;
}


sprintf(query,"select * from account where num=%s and password='%s'",num,password);
SQLAllocStmt(hdbc,&hstmt);
retcode = SQLExecDirect(hstmt,query,SQL_NTS );

retcode = SQLFetch(hstmt);

if(retcode != SQL_SUCCESS)
{
printf("해당 계좌 없거나 비밀번호가 일치 하지 않습니다.\n\n");
return;
}

SQLGetData(hstmt,1,SQL_CHAR,&szA,1048,&cbA);
printf("계좌번호:%s\n",szA);

SQLGetData(hstmt,2,SQL_CHAR,&szA,1048,&cbA);
printf("개설일시:%s\n",szA);

SQLGetData(hstmt,3,SQL_CHAR,&szA,1048,&cbA);
printf("Customer Name:%s\n",szA);

SQLGetData(hstmt,4,SQL_CHAR,&szA,1048,&cbA);
printf("지점명:%s\n",szA);

SQLGetData(hstmt,5,SQL_CHAR,&szA,1048,&cbA);
printf("전화번호:%s\n",szA);

SQLGetData(hstmt,6,SQL_CHAR,&szA,1048,&cbA);
printf("잔액:%s\n",szA);

 

DisconnectDB();

 

}


void account_close(void)
{
char num[13],password[5];
char query[1048];
RETCODE retcode;

printf("\n>>해당 계좌를 삭제합니다.\n>>");

printf("계좌번호:");
gets(num);

printf("비밀번호: ");
gets(password);

if(ConnecToDB("","","bankdsn" ) == 0)
{
printf("db접속 에러");
return;
}

sprintf(query,"delete * form account where num = '%s' and password ='%s'",num,password);


SQLAllocStmt(hdbc,&hstmt);
retcode = SQLExecDirect(hstmt,query,SQL_NTS );

if( retcode == SQL_SUCCESS ) printf("삭제 성공\n\n");
else printf("삭제 실패\n\n");

DisconnectDB();

}

void desposit(void)
{
char num[13],password[5],date[20];
char query[1048];
RETCODE retcode;
SQLCHAR szA[100];
SQLINTEGER cbA;
int balance;
int desposit;


printf("\n>>해당 계좌를 입급합니다.\n>>");

printf("계좌번호:");
gets(num);

printf("비밀번호: ");
gets(password);


if(ConnecToDB("","","bankdsn" ) == 0)
{
printf("db접속 에러");
return;
}


sprintf(query,"select * from account where num=%s and password='%s'",num,password);
SQLAllocStmt(hdbc,&hstmt);
retcode = SQLExecDirect(hstmt,query,SQL_NTS );

retcode = SQLFetch(hstmt);

if(retcode != SQL_SUCCESS)
{
printf("해당 계좌 없거나 비밀번호가 일치 하지 않습니다.\n\n");
DisconnectDB();
return;
}

get_current_time(date);
printf("입급액: ");
gets(balance);

balance=balance+desposit;

sprintf(query,"update account set balance = %d where num = '%s'",balance,num);

SQLAllocStmt(hdbc,&hstmt);
retcode = SQLExecDirect( hstmt,query,SQL_NTS );


if(retcode != SQL_SUCCESS)
{
printf("질의 구문에 오류가 있습니다.\n\n");
DisconnectDB();
return;
}

sprintf(query,"insert into transaction values ('%s','%s',%d,%d,%d)",num,date,desposit,0,balance);

SQLAllocStmt(hdbc,&hstmt);
retcode = SQLExecDirect( hstmt,query,SQL_NTS );


if( retcode != SQL_SUCCESS)
{
printf("질의구문에 오류가 있습니다.\n");
DisconnectDB();
return;
}

DisconnectDB();

}

void payment(void)
{
char num[13],password[5],date[20];
char query[1048];
RETCODE retcode;
SQLCHAR szA[100];
SQLINTEGER cbA;
int balance;
int desposit;

printf("\n>>해당 계좌에서 출금합니다.\n>>");

printf("계좌번호:");
gets(num);

printf("비밀번호: ");
gets(password);

if(ConnecToDB("","","bankdsn" ) == 0)
{
printf("db접속 에러");
return;
}

get_current_time(date);
sprintf(query,"select * from account where num=%s and password='%s'",num,password);
SQLAllocStmt(hdbc,&hstmt);
retcode = SQLExecDirect(hstmt,query,SQL_NTS );

retcode = SQLFetch(date);

if(retcode != SQL_SUCCESS)
{
printf("해당 계좌 없거나 비밀번호가 일치 하지 않습니다.\n\n");
DisconnectDB();
return;
}

 

printf("출금액: ");
gets(balance);

sprintf(query,"update account set balance=%d where num='%s'",balance,num);
SQLAllocStmt(hdbc,&hstmt);
retcode = SQLExecDirect(hstmt,query,SQL_NTS );

if(retcode !=SQL_SUCCESS)
{
printf("계좌 에 있는 금액보다 큽니다.\n");
DisconnectDB();
return;
}

sprintf(query,"insert into transction values('%s','%s',%d,%d,%d)",num,date,0,balance);

SQLAllocStmt(hdbc,&hstmt);
retcode = SQLExecDirect( hstmt,query,SQL_NTS );

 

if(retcode !=SQL_SUCCESS)
{
printf("질의문에 에러가 있습니다.\n");
return;
}


DisconnectDB();

}

void main(void)
{
char ch;

do
{
printf("\n####################################################\n");
printf("\n Bank Beta version #\n");
printf("\n####################################################\n");
printf("1.계좌개설,2.계좌검색,3.계좌해지,4.입급,5.출금,6.종료\n");

ch = getchar();

fflush(stdin);


switch(ch)
{
case '1': account_open();
break;

case '2': account_search();
break;

case '3': account_close();
break;

case '4': desposit();
break;

case '5': payment();
break;

case '6': break;

default : printf("올바른 메뉴가 아닙니다.\n");
}

}while(ch != '6');

}/*메인 프로그램 끝*/

 


[Top]
No.
제목
작성자
작성일
조회
1063관계디비나 XML디비의 cache관리에 관한 논문좀 알려주세요
veritas
2004-12-22
10644
1061DBMS의 접근 없이 처리에 대한 것만 카운트 하는 방법 [1]
김곤태
2004-12-22
10383
1060엑세스에서..
남용욱
2004-12-20
10406
1058뭐가 문제 인지..이거 참 난감하네요..
초보자
2004-12-12
11427
1056[질문]Er-Win에서는 검색 기능이 없나요? [2]
권용기
2004-12-06
10008
1055다시 질문드립니다.. [3]
수니
2004-12-05
10411
1054무선인터넷과 연동되어 사용할수 있는 Database에는 어떤것들이 있나요? [1]
수니
2004-12-03
11286
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2021 DSN, All rights reserved.
작업시간: 0.011초, 이곳 서비스는
	PostgreSQL v13.3으로 자료를 관리합니다