/**********************************
* SGTSMS.C SOURCE LIST
* 教师工资管理系统v2.0 modify_ID05-110.源程序清单
* 开发人:殷圣鸽 编译系统TURBOC2.0
* Copyright (c) 2004-10-4 -2004-11-17
* SGPRO
与{
SGMOUSE.H 圣鸽鼠标函数库
SGCHN2_3.H 圣鸽中文服务系统v2.3(Interior_ID110.modify)
SGKEYDF.H 圣鸽键盘函数库
SGGRAPH 圣鸽图形制式库
SGBMP.H 圣鸽位图函数库
SGWINDOW.H 圣鸽窗体函数库
SGBUTTON.H 圣鸽按扭函数库
SGTXTBOX.H 圣鸽文本框函数库
}
一同编译
注 : 发布版的源程序不能编译,不提供上述运行库.
***********************************/
#ifndef __MEDIUM__
#error SGTSMS had better run in medium model
#endif /*保证系统正常运行,用中等内存模式编译*/
/*将圣鸽中文服务的主函数关闭 */
#include “sgmouse.h”
#include “sgkeydf.h”
#include “sgbmp.h”
#include “sggraph.h”
#include “sgchn2_3.h”
#include “sgwindow.h”
#include “sglabel.h”
#include “sgbutton.h” /*圣鸽按扭函数库,提供按扭操作,
*包含圣鸽鼠标函数库,圣鸽中文服务系统,圣鸽图形制式库,圣鸽窗体函数库*/
#include “sgtxtbox.h” 圣鸽文本框函数库 提供文本框操作*/
#define MAXRECORDNUM 500 /*设置内存可装载的最大记录数*/
typedef struct
{
int no;
char name[20];
char date[10];
int people;
long salary;
}teacher; /*定义教师记录*/
typedef enum
{
noMsg,
exitMsg,
displayMsg,
selectMsg,
addnewMsg,
updateMsg,
deleteMsg,
newsalaryMsg
}SGTSMSmsg; /*定义公共消息*/
typedef struct listnode
{
teacher data;
struct listnode *next;
}llist;
typedef struct
{
teacher data[MAXRECORDNUM];
int length;
}slist; /*定义数据表*/
llist *LTCH;
slist STCH;
Window *SGTSMSWIN; /*定义1主窗体 */
Command *display, /*定义7个操作按扭*/
*update,
*delete,
*addnew,
*exitsys,
*select,
*newsalary;
Label *nowtime;
textbox *pade; /*定义1个文本框*/
struct date cy; /*日期变量公用*/
char timestring[]=”现在”;
/*主程序的所有函数*/
void logo();
void desktop();
void loaddata();
SGTSMSmsg sendmessage();
void receivemessage(SGTSMSmsg);
void exitmod();
void displaymod();
void sort();
void addnewmod();
void selectmod();
void deletemod();
void updatemod();
void newsalarymod();
void newpassword();
void getcurrentdate();
int setpassword();
int calworkyear(char *);
int password();
/*系统主函数*/
void main()
{
SGTSMSmsg commonmsg=noMsg; /*初始化公共消息*/
logo();
if(!setpassword()) /*凭借密码登入系统*/
password();
newpassword();
sgworkpalette(7);
quikquitsgchn();
desktop(); /*创建显示操作界面*/
loaddata(); /*加载数据库*/
while(1) /*消息循环*/
{
commonmsg=sendmessage(); /*发送消息*/
receivemessage(commonmsg); /*处理消息*/
}
}
/*登入界面*/
void logo()
{
char c;
char password[16];
lp:initbmp();
drawbmp(0,0,”logo.ima”);
c=getch();
if(c==’\x1B’)
{
endbmp();
initbmp();
drawbmp(0,0,”help.ima”);
getch();
goto lp;
}
endbmp();
}
/*加载数据库*/
/* Function “loaddata” brief:
* load source data from file: “original.db”
* attain a Memory block named STCH (Gobal variable)
* imbark that source for operating.
*/
void loaddata()
{
FILE *datasource; /*disk file handle*/
long filelen; /*disk file length*/
int recordcnt; /*disk file’s recorde amount*/
int readcnt;
short recordlen; /*recorde length*/
short readstate; /*read disk state(success or fail)*/
char *databuffer; /*read disk IO stream buffer for read file*/
datasource=fopen(“original.db”,”rb”);
if(datasource==NULL) /*disk file not found*/
STCH.length=0;
else /*disk file exsist*/
{
databuffer=(char *)malloc(BUFSIZ*sizeof(char));/*request IO stream buffer*/
if(databuffer==NULL) /*request IO stram buffer fail system abnormal run*/
{
printf(“Memory overflow!”);
exit(0);
}
fseek(datasource,0,SEEK_END);
filelen = ftell(datasource);
recordlen = sizeof(teacher);
recordcnt = filelen/recordlen;
if(recordcnt>MAXRECORDNUM)
{
print(“数据量大,无法加载\n”);
exit(0);
}
rewind(datasource);
for(STCH.length=0;STCH.length<recordcnt;STCH.length++)
{ /*read record one by one */
readstate=fread(STCH.data+STCH.length,recordlen,1,datasource );
if(readstate!=1)
{
printf(“Read disk error!”);
exit(0);
}/*End read state test*/
}/*End (For) read disk*/
fclose(datasource);
free(databuffer);
}/*End (else) open file (data source)*/
getcurrentdate();/*Get system current date*/
}/*End module (loaddata)*/
sgworkpalette()
{
int i;
print(“\n你喜欢什么主色调:1.红 2.蓝 3.绿 4.灰 5.默认\n”);
lp:
if(scanformat(“%d”,&i)!=OK)
goto lp;
sgpalette(i);
}
/*桌面函数,创建并显示操作界面*/
void desktop()
{
SGTSMSWIN = (Window *)malloc(sizeof(Window));
if(SGTSMSWIN==NULL)
{
printf(“Memory overflow!”);
exit(0);
}
if(CreateWindow(SGTSMSWIN,1,1,638,460,LIGHTGRAY,WHITE,”£ 教师工资管理系统Ⅱ COPYRIGHT(C) 2004 SGPRO”)==YES)
ShowWindow(SGTSMSWIN);
else
printf(“Create window failure!”);
display = (Command *)malloc(sizeof(Command));
update = (Command *)malloc(sizeof(Command));
delete = (Command *)malloc(sizeof(Command));
addnew = (Command *)malloc(sizeof(Command));
exitsys = (Command *)malloc(sizeof(Command));
select = (Command *)malloc(sizeof(Command));
newsalary = (Command *)malloc(sizeof(Command));
pade = (textbox *)malloc(sizeof(textbox));
nowtime = (Label *)malloc(sizeof(Label));
if(display)
{
if(CreateCommand(display,10,40,90,64,”显 示”,SGTSMSWIN)==YES)
CommandShow(display);
else
printf(“Command create failure!”);
}
else
{
printf(“Memory overflow!”);
exit(0);
}
if(select)
{
if(CreateCommand(select,95,40,175,64,”查 询”,SGTSMSWIN)==YES)
CommandShow(select);
else
printf(“Command create failure!”);
}
else
{
printf(“Memory overflow!”);
exit(0);
}
if(addnew)
{
if(CreateCommand(addnew,180,40,260,64,”添 加”,SGTSMSWIN)==YES)
CommandShow(addnew);
else
printf(“Command create failure!”);
}
else
{
printf(“Memory overflow!”);
exit(0);
}
if(delete)
{
if(CreateCommand(delete,265,40,345,64,”删 除”,SGTSMSWIN)==YES)
CommandShow(delete);
else
printf(“Command create failure!”);
}
else {
printf(“Memory overflow!”);
exit(0);
}
if(update)
{
if(CreateCommand(update,350,40,430,64,”更 改”,SGTSMSWIN)==YES)
CommandShow(update);
else
printf(“Command create failure!”);
}
else
{
printf(“Memory overflow!”);
exit(0);
}
if(newsalary)
{
if(CreateCommand(newsalary,435,40,515,64,”更新工资”,SGTSMSWIN)==YES)
CommandShow(newsalary);
else
printf(“Command create failure!”);
}
else {
printf(“Memory overflow!”);
exit(0);
}
if(exitsys)
{
if(CreateCommand(exitsys,520,40,610,64,”退 出”,SGTSMSWIN)==YES)
CommandShow(exitsys);
else
printf(“Command create failure!”);
}
else {
printf(“Memory overflow!”);
exit(0);
}
if(pade)
{
if(Createtextbox(pade,
5,
90,
632,
454,
BLUE,
” “,
FALSE,
FALSE,
FALSE,
SGTSMSWIN)==TRUE)
Showtextbox(pade);
else printf(“Command create failure!”);
}
else {
printf(“Memory overflow!”);
exit(0);
}
if(nowtime&&Label_create(
nowtime,
timestring,
510,
5,
75,
16,
WHITE,
BLUE,
SGTSMSWIN)==TRUE)
Label_show(nowtime);
clearactiveview(1);
headline(“\n 教师工资管理系统Ⅱ \n Copyright (C) 2004-11- SGPRO\n\n ☆殷圣鸽★”);
settextstyle(10,0,5);
setcolor(LIGHTRED);
sgouttextxy(7,y+60,”WELLCOM SGTSMS”);
settextstyle(5,0,4);
setcolor(YELLOW);
sgouttextxy(x-80,y+200,”Yinshengge.sgpro.Juan.”);
separateline(3,34,616,34);
separateline(616,34,616,70);
separateline(616,70,3,70);
separateline(3,70,3,34);
}
/*发送消息函数 捕捉消息,并发送到消息处理函数*/
SGTSMSmsg sendmessage()
{
SGTSMSmsg tempmsg;
char asciikey;
int keycode;
if(CommandPress(exitsys)==TRUE)
tempmsg=exitMsg;
else if(CommandPress(display)==TRUE)
tempmsg=displayMsg;
else if(CommandPress(select)==TRUE)
tempmsg=selectMsg;
else if(CommandPress(addnew)==TRUE)
tempmsg=addnewMsg;
else if(CommandPress(delete)==TRUE)
tempmsg=deleteMsg;
else if(CommandPress(update)==TRUE)
tempmsg=updateMsg;
else if(CommandPress(newsalary)==TRUE)
tempmsg=newsalaryMsg;
else if(testcode()==F2CTRL)
{
remove(“work.sgp”);
savesgp(“work.sgp”,0,0,640,480);
flushkb();
}
else
tempmsg=noMsg;
return tempmsg;
}
/*接受消息,并启动响应*/
void receivemessage(SGTSMSmsg Msg)
{
switch(Msg)
{
case noMsg:
mousemove(&mousex,&mousey);
freshtime();
break;
case displayMsg:
displaymod();
break;
case addnewMsg:
addnewmod();
break;
case selectMsg:
selectmod();
break;
case deleteMsg:
deletemod();
break;
case updateMsg:
updatemod();
break;
case newsalaryMsg:
newsalarymod();
break;
case exitMsg:
exitmod();
break;
}
}
/*显示教师工资数据库的信息*/
void displaymod()
{
int num =0;
static int dbbrief=1;
clearactiveview(sggetpixel(x,y));
resetxy();
if(dbbrief==1)
{
print(“\n教师工资数据库共含5个字段描述如下: \n\
{\n\
序号 int 关键字,\n\
姓名 char(20),\n\
入校时间 date(yyyy-mm),\n\
赡养人数 int,\n\
工资 long,\n\
}\n\n”);
dbbrief=0;
}
print(“教师信息数据库共含 %d 条记录. 右击鼠标换页显示,左击撤消\n”,STCH.length);
print(” 序号 姓名 入校日期 赡养人数 工资\n”);
sort();
for(num=0;num<STCH.length;num++ )
{
if(print(” %-3d %-12s %-6s %-3d %-6ld\n”,
(STCH.data+num)->no,
(STCH.data+num)->name,
(STCH.data+num)->date,
(STCH.data+num)->people,
(STCH.data+num)->salary)==CANCELPRINT)
{
resetxy();
clearactiveview(15);
print(“撤消显示”);
break;
}
}
}
/*对数据库记录按序号字段排序*/
void sort()
{
int i,j;
teacher *temp=(teacher *)malloc(sizeof(teacher));
if(!temp)
{
print(“Memory overflow!”);
return;
}
for(i=0;i<STCH.length-1;i++)
for(j=0;j<STCH.length-i-1;j++)
if(STCH.data[j].no>STCH.data[j+1].no)
{
temp->no=STCH.data[j].no;
strcpy(temp->name,STCH.data[j].name);
strcpy(temp->date,STCH.data[j].date);
temp->people=STCH.data[j].people;
temp->salary=STCH.data[j].salary;
STCH.data[j].no=STCH.data[j+1].no;
strcpy(STCH.data[j].name,STCH.data[j+1].name);
strcpy(STCH.data[j].date,STCH.data[j+1].date);
STCH.data[j].people=STCH.data[j+1].people;
STCH.data[j].salary=STCH.data[j+1].salary;
STCH.data[j+1].no=temp->no;
strcpy(STCH.data[j+1].name,temp->name);
strcpy(STCH.data[j+1].date,temp->date);
STCH.data[j+1].people=temp->people;
STCH.data[j+1].salary=temp->salary;
}
free(temp);
}
/*向数据库插入新记录,以序号字段作为关键字段,具有唯一性约束*/
void addnewmod()
{
int num = 0;
int test =0;
int cnt=0;
int initlen=STCH.length;
int scanstate;
clearactiveview(sggetpixel(x,y));
resetxy();
if(STCH.length>MAXRECORDNUM)
{
print(“内存爆满,无法添加\n”);
exit(0);
}
print(” 请输入你添加的教师记录信息 输入的序号为-1表示输入结束\n”);
print(” 序号 姓名 入校日期 赡养人数 工资\n”);
print(“(整数<32767) (字符串) (yyyy-mm) (整数<128) (整数<21亿)\n”);
for(num=STCH.length;num<MAXRECORDNUM;num++)
{
if(scanformat(“%d”,&test)==NOOPERATE)
{
print(“插入了 %d 条记录”,STCH.length-initlen);
return;
}
if(test==-1)
break;
STCH.data[num].no=test;
scanstate=scanformat(“%s”,STCH.data[num].name);
if(scanstate==ERROR)
{
print(“操作无效\n”);
return;
}
else if(scanstate==NOOPERATE)
{
print(“操作取消”);
return;
}
scanstate=scanformat(“%s”,STCH.data[num].date);
if(scanstate==ERROR)
{
print(“操作无效\n”);
return;
}
else if(scanstate==NOOPERATE)
{
print(“操作取消”);
return;
}
scanstate=scanformat(“%d”,&(STCH.data[num].people));
if(scanstate==ERROR)
{
print(“操作无效\n”);
return;
}
else if(scanstate==NOOPERATE)
{
print(“操作取消”);
return;
}
scanstate=scanformat(“%ld”,&(STCH.data[num].salary));
if(scanstate==ERROR)
{
print(“操作无效\n”);
return;
}
else if(scanstate==NOOPERATE)
{
print(“操作取消”);
return;
}
STCH.length++;
if(STCH.data[num].people==0||STCH.data[num].salary==0)
{
print(” 操作无效\n”);
STCH.length–;
break;
}
if(STCH.data[num].no<1)
{
STCH.length–;
print(“序号应该为正整数! 添加失败\n”);
print(“\n’%d %s %s %d %ld‘在插入到数据库的动作无效。\n”,
(STCH.data+num)->no,
(STCH.data+num)->name,
(STCH.data+num)->date,
(STCH.data+num)->people,
(STCH.data+num)->salary);
goto show;}
for(cnt=0;cnt<STCH.length-1;cnt++)
{
if(STCH.data[num].no==STCH.data[cnt].no)
{
STCH.length–;
print(“存在序号为 %d 的记录,关键字‘序号’发生冲突,添加失败”,STCH.data[cnt].no);
print(“\n’%d %s %s %d %ld‘在插入到数据库的动作无效。\n”,
(STCH.data+num)->no,
(STCH.data+num)->name,
(STCH.data+num)->date,
(STCH.data+num)->people,
(STCH.data+num)->salary);
goto show;
}
}
if(STCH.data==NULL)
{
printf(“Memory overflow!”);
exit(0);
}
}
show:print(“成功添加 %d 条记录\n”,STCH.length-initlen);
}
/*条件查询,输入序号,显示整条记录*/
void selectmod()
{
int selectno;
int num=0;
int scanstate;
clearactiveview(sggetpixel(x,y));
resetxy();
print(“输入你查询的教师的序号:\n”);
scanstate=scanformat(“%d”,&selectno);
if(scanstate==NOOPERATE)
return;
else if(scanstate==ERROR)
return;
resetxy();
clearactiveview(sggetpixel(x,y));
print(“序号 姓名 入校日期 赡养人数 工资\n”);
for(num=0;num<STCH.length;num++)
if(STCH.data[num].no==selectno)
{
print(“%-3d %-12s %-6s %-3d %-6ld\n”,
(STCH.data+num)->no,
(STCH.data+num)->name,
(STCH.data+num)->date,
(STCH.data+num)->people,
(STCH.data+num)->salary);
break;
}
}
/*更新数据库个别记录,输入序号,更改对应记录*/
void updatemod()
{
int updateno;
int num=0;
int scanstate;
teacher *temp=(teacher *)malloc(sizeof(teacher));
if(!temp)
{
print(“Memory overflow!”);
return;
}
clearactiveview(sggetpixel(x,y));
resetxy();
print(“输入你要更改的教师的序号:\n”);
if(scanformat(“%d”,&updateno)!=OK)
return;
resetxy();
clearactiveview(sggetpixel(x,y));
print(“序号 姓名 入校日期 赡养人数 工资\n”);
for(num=0;num<STCH.length;num++)
if(STCH.data[num].no==updateno)
{
print(“%3d %-10s %-6s %-3d %-6ld\n”,
(STCH.data+num)->no,
(STCH.data+num)->name,
(STCH.data+num)->date,
(STCH.data+num)->people,
(STCH.data+num)->salary);
break;
}
if(num==STCH.length)
{
print(“无此记录,更新无法完成\n”);
return;
}
print(“\n\n\n输入新记录信息\n”);
print(” 姓名 入校日期 赡养人数 工资\n”);
print(” (字符串) (yyyy-mm) (整数<128) (整数<21亿)\n”);
scanstate=scanformat(“%s”,temp->name);
if(scanstate==ERROR)
{
print(“操作无效\n”);
return;
}
else if(scanstate==NOOPERATE)
{
print(“操作取消”);
return;
}
scanstate=scanformat(“%s”,temp->date);
if(scanstate==ERROR)
{
print(“操作无效\n”);
return;
}
else if(scanstate==NOOPERATE)
{
print(“操作取消”);
return;
}
scanstate=scanformat(“%d”,&(temp->people));
if(scanstate==ERROR)
{
print(“操作无效\n”);
return;
}
else if(scanstate==NOOPERATE)
{
print(“操作取消”);
return;
}
scanstate=scanformat(“%ld”,&(temp->salary));
if(scanstate==ERROR)
{
print(“操作无效\n”);
return;
}
else if(scanstate==NOOPERATE)
{
print(“操作取消”);
return;
}
if(temp->people==0||temp->salary==0)
{
print(“操作无效\n”);
STCH.length–;
return;
}
strcpy(STCH.data[num].name,temp->name);
strcpy(STCH.data[num].date,temp->date);
STCH.data[num].people=temp->people;
STCH.data[num].salary=temp->salary;
print(“更新成功!\n”);
free(temp);
}
/*从数据库删除指定序号的记录*/
void deletemod()
{
int deleteno;
int num;
int dptr;
clearactiveview(sggetpixel(x,y));
resetxy();
print(“输入你要删除的记录的序号值\n”);
if(scanformat(“%d”,&deleteno)!=OK)return;
for(num=0;num<STCH.length;num++)
if(deleteno==STCH.data[num].no)
break;
if(num==STCH.length)
{
print(“无此记录,删除无法完成\n”);
return;
}
for(dptr=num;dptr<STCH.length;dptr++)
{
STCH.data[dptr].no=STCH.data[dptr+1].no;
strcpy(STCH.data[dptr].name,STCH.data[dptr+1].name);
strcpy(STCH.data[dptr].date,STCH.data[dptr+1].date);
STCH.data[dptr].people=STCH.data[dptr+1].people;
STCH.data[dptr].salary=STCH.data[dptr+1].salary;
}
STCH.length–;
print(“\n删除成功!\n”);
}
/*更新工资字段,并存储教师基本信息和新工资*/
void newsalarymod()
{
FILE *newinfo=fopen(“newinfo.db”,”wb”);
char *writebuffer;
int num;
int wy;
long newsala[MAXRECORDNUM];
teacher *temp=(teacher *)malloc(sizeof(teacher));
if(temp==NULL)
{
printf(“Memory overflow!”);
exit(0);
}
writebuffer=(char *)malloc(BUFSIZ*sizeof(char));
if(writebuffer==NULL)
{
printf(“Memory overflow!”);
exit(0);
}
for(num=0;num<STCH.length;num++)
{
newsala[num]=STCH.data[num].salary;
if(newsala[num]<26000)
{
wy=calworkyear(STCH.data[num].date);
if(wy==-1)
{
resetxy();
clearactiveview(15-RED);
print(“\n错误:无法计算序号为%d的教师的工龄,可能的原因有:\n ①其入校日期为非指定格式\n ②存在非法数据\n ③日期越界如月份值>12,入校日期大于当前日期\n 〓请仔细核对数据,修改后重试”,
STCH.data[num].no);
fclose(newinfo);
free(temp);
free(writebuffer);
goto end;
}
newsala[num]+=(long)(STCH.data[num].people*100L+wy*50L);
if(newsala[num]>=26000)
newsala[num]=26000;/*调整算法*/
}
temp->no=STCH.data[num].no;
strcpy(temp->name,STCH.data[num].name);
strcpy(temp->date,STCH.data[num].date);
temp->people=STCH.data[num].people;
temp->salary=newsala[num];
fwrite(temp,sizeof(teacher),1,newinfo);
}
fclose(newinfo);
free(temp);
free(writebuffer);
resetxy();
clearactiveview(sggetpixel(x,y));
print(“教师信息数据库共含 %d 条记录. 右击鼠标换页显示,左击撤消\n”,STCH.length);
print(“教师工龄计算的截止时间为当前日期:%d-%d-%d \n”,cy.da_year,cy.da_mon,cy.da_day);
print(” 序号 姓名 入校日期 赡养人数 原工资 新工资\n”);
for(num=0;num<STCH.length;num++)
{
if(print(” %-3d %-12s %-6s %-3d %-6ld %-6ld\n”,
(STCH.data+num)->no,
(STCH.data+num)->name,
(STCH.data+num)->date,
(STCH.data+num)->people,
(STCH.data+num)->salary,
newsala[num])==CANCELPRINT )
{
resetxy();
clearactiveview(15);
print(“撤消显示”);
break;
}
}
end:;
}
/*计算教师工龄,返回教师入校日期和当前日期的差值*/
int calworkyear(char *d)
{
unsigned long int year,mon;
unsigned long int flag=0;
unsigned long int num=0;
char y[100];
if(strlen(d)>7)
return -1;
while(num<strlen(d))
{
if(d[num]==’-')
break;
if(d[num]<’0′||d[num]>’9′)
return -1;
num++;
}
strncpy(y,d,num);
if(!strcmp(d,”200198″))
print(” “);
*(y+num)=’\0′;
d=d+num+1;
mon=atoi(d);
year=atoi(y);
if(mon==0||year==0)
return -1;
if(mon>12||mon<0)
return -1;
if(year<0)
return -1;
if(mon>cy.da_mon)
flag=-1;
if(cy.da_year-year<0)
return -1;
if(cy.da_year==year&&cy.da_mon<mon)
return -1;
return (cy.da_year-year+flag);
}
/*获取系统的当前日期*/
void getcurrentdate()
{
getdate(&cy);
}
freshtime()
{
struct time *ct=NULL;
char thour[4]=”",tmin[4]=”",tsec[4]=”";
static char tstring[32]=”";
static char old[32];
gettime(ct);
itoa(ct->ti_hour,thour,10);
itoa(ct->ti_min,tmin,10);
itoa(ct->ti_sec,tsec,10);
strcpy(tstring,timestring);
strcat(tstring,thour);
strcat(tstring,”:”);
strcat(tstring,tmin);
strcat(tstring,”:”);
strcat(tstring,tsec);
if(strcmp(old,tstring))
Label_changecaption(nowtime,tstring);
strcpy(old,tstring);
}
/*维护数据库的安全 设置系统运行密码*/
int setpassword()
{
char *string=” “;
char passpath[64];
FILE *fp;
strcpy(passpath,getwindowspath());
strcat(passpath,”\\password.txt”);
fp=fopen(passpath,”r”);
if(!fp)
{
print(“为了数据库的安全,请输入登入密码!\n”);
fp=fopen(passpath,”w”);
scanformat(“%s”,string);
fputs(string,fp);
}
else return 0;
fclose(fp);
return 1;
}
/*更改密码*/
void newpassword()
{
char *string=” “;
char passpath[64];
FILE *fp;
strcpy(passpath,getwindowspath());
strcat(passpath,”\\password.txt”);
print(“\n是否设置新密码?(Y/N):\n”);
fflush(stdin);
if(getch()==’y')
{
fp=fopen(passpath,”w”);
print(“输入新密码!:\n”);
scanformat(“%s”,string);
fputs(string,fp);
fclose(fp);
print(“设置成功!\n按任意键继续…”);
getch();
}
}
/*输入系统登入密码*/
int password()
{
char c;
char a[20]=” “;
char passpath[64];
char *string=” “;
FILE *fp;
char *t=”%s”;
int i;
strcpy(passpath,getwindowspath());
strcat(passpath,”\\password.txt”);
fp=fopen(passpath,”r”);
lp:print(“输入登入密码.\n”);
for (i=0;i<20;i++)a=0;
for(i=0;(c=getch())!=’\r’;i++)
{
print(“●”);
*(a+i)=c;
}
flushall();
fscanf(fp,t,string);
if(strcmp(a,string))
{
print(“\n密码错误!\n重新输入?(Y/N)\n”);
fflush(stdin);
if(getch()==’y'){;goto lp;}
exit(0);
}
print(“\nOK!\n”);
fclose(fp);
}
/*退出系统,销毁界面,保存数据*/
void exitmod()
{
FILE *savedata=fopen(“original.db”,”wb”);
int num=0;
resetxy();
clearactiveview(sggetpixel(x,y));
print(“\n正在保存数据\n”);
for(num=0;num<STCH.length;num++)
fwrite(STCH.data+num,sizeof(teacher),1,savedata);
fclose(savedata);
print(“保存完毕”);
free(SGTSMSWIN);
free(display);
free(select);
free(addnew);
free(delete);
free(update);
free(newsalary);
free(exitsys);
free(pade);
exit(0);
}
/*殷圣鸽:2004-11-19 加补丁 考虑到查询,删除时产生的输入错误(ERROR)时,终止查询和删除*/
>> 本文固定链接: http://www.vcgood.com/archives/1128
我也想学C 能不能指导下我啊“` `
呵呵。学习都是靠自己的。如果你有什么问题。可以问大家的。。
圣鸽函数不懂啊,怎样变成C语言的函数呢?