/*************************************************************************
> File Name: operationFunctions.c
> Author: Hippyll
> Mail: hippyll@foxmail.com
> Created Time: 2021年08月06日 星期五 21时49分56秒
************************************************************************/
#include "../include/smsServer.h"
/*
int insertNewUser(sqlite3 *pdb,char *username,char *password);
int addNewStaffInfo(sqlite3 *pdb);
int deleteStaffByName(sqlite3 *pdb,char *staffname);
int modifyUserPassword(sqlite3 *pdb,char *username,char *password);
int modifyStaffInfo(sqlite3 *pdb,char *staffname);
int printUserTable(sqlite3 *pdb);
int printStaffInfoTable(sqlite3 *pdb);
struct acceptStaffInfo *printStaffInfoTableByName(sqlite3 *pdb,char *staffname);
int printHistoryTableByName(sqlite3 *pdb,char *staffname);
int insertHistoryRecord(sqlite3 *pdb,char *staffname,char *operation);
int checkLogin(sqlite3 *pdb,char *username,char *password);
int updateUserFlag(sqlite3 *pdb,char *username);
*/
static int inputStaffInfo(struct staffInfo *staff);
/*向user表中添加新记录*/
int insertNewUser(sqlite3 *pdb,char *username,char *password)
{
int ret = 0;
char sqlstr[1024] = "";
char **ppret = NULL;
int rows = 0,cols = 0;
char *perr = NULL;
/*比较姓名*/
sprintf(sqlstr,"SELECT * FROM user WHERE name LIKE '%s'",username);
ret = my_sqlite3_get_table(pdb,sqlstr,&ppret,&rows,&cols,&perr);
if(ret != SQLITE_OK){
PrintServerError("get_table %s failed:%s\n",sqlstr,perr);
sqlite3_free(perr);
perr = NULL;
sqlite3_close(pdb);
pdb = NULL;
return -1;
}else if(strcmp(*(ppret+3),username) == 0){
/*该用户已存在*/
// printf("the username %s is exist!\n",username);
return 0;
}else{
/*向user表中添加信息*/
memset(sqlstr,0,1024);
sprintf(sqlstr,"INSERT INTO user(Name,Password,Flag) VALUES('%s','%s',0)",username,password);
ret = my_sqlite3_exec(pdb,sqlstr,NULL,NULL,&perr);
if(ret != SQLITE_OK){
PrintServerError("exec %s failed:%s\n",sqlstr,perr);
sqlite3_free(perr);
perr = NULL;
return -1;
}
}
return 0;
}
/*向staffInfo表中添加新记录*/
int addNewStaffInfo(sqlite3 *pdb)
{
int ret = 0;
char sqlstr[1024] = "";
char *perr = NULL;
struct staffInfo *staff = NULL;
staff = (struct staffInfo *)malloc(sizeof(struct staffInfo));
memset(staff,0,sizeof(struct staffInfo));
/*向staffInfo表中插入数据*/
inputStaffInfo(staff);
memset(sqlstr,0,1024);
sprintf(sqlstr,"INSERT INTO staffInfo(Name,Address,Age,level,ID,Salary,Phone,Email) VALUES('%s','%s','%d','%d','%d','%f','%s','%s')",
staff->name,staff->address,staff->age,staff->level,staff->id,staff->salary,staff->phone,staff->email);
ret = my_sqlite3_exec(pdb,sqlstr,NULL,NULL,&perr);
if(ret != SQLITE_OK){
PrintServerError("exec %s failed:%s\n",sqlstr,perr);
sqlite3_free(perr);
perr = NULL;
return -1;
}
/*同时在user表中添加相关信息*/
memset(sqlstr,0,1024);
sprintf(sqlstr,"INSERT INTO user(Name,Password,Flag) VALUES('%s','%s',0)",staff->name,STAFF_INITIAL_PASSWD);
ret = my_sqlite3_exec(pdb,sqlstr,NULL,NULL,&perr);
if(ret != SQLITE_OK){
PrintServerError("exec %s failed:%s\n",sqlstr,perr);
sqlite3_free(perr);
perr = NULL;
return -1;
}
return 0;
}
/*通过名字删除成员信息*/
int deleteStaffByName(sqlite3 *pdb,char *staffname)
{
int ret = 0;
char sqlstr[1024] = "";
char **ppret = NULL;
int rows = 0,cols = 0;
char *perr = NULL;
memset(sqlstr,0,1024);
sprintf(sqlstr,"SELECT count(*) FROM user");
ret = my_sqlite3_get_table(pdb,sqlstr,&ppret,&rows,&cols,&perr);
if(ret != SQLITE_OK){
PrintServerError("my_sqlite3_get_table %s failed:%s\n",sqlstr,perr);
sqlite3_free(perr);
perr = NULL;
return -1;
}
sscanf(*(ppret+1),"%d",&ret);
if(0 == ret){
printf("The user Name:%s has no record in Tables!\n",staffname);
return -1;
}else{
/*删除user表中的信息*/
memset(sqlstr,0,1024);
sprintf(sqlstr,"DELETE FROM user WHERE name='%s'",staffname);
ret = my_sqlite3_exec(pdb,sqlstr,NULL,NULL,&perr);
if(ret != SQLITE_OK){
PrintServerError("exec %s failed:%s\n",sqlstr,perr);
sqlite3_free(perr);
perr = NULL;
return -1;
}
/*删除staffInfo表中的信息*/
memset(sqlstr,0,1024);
sprintf(sqlstr,"DELETE FROM staffInfo WHERE name='%s'",staffname);
ret = my_sqlite3_exec(pdb,sqlstr,NULL,NULL,&perr);
if(ret != SQLITE_OK){
PrintServerError("exec %s failed:%s\n",sqlstr,perr);
sqlite3_free(perr);
perr = NULL;
return -1;
}
}
return 0;
}
/*更改user表的登入密码*/
int modifyUserPassword(sqlite3 *pdb,char *username,char *password)
{
int ret = 0;
char sqlstr[1024] = "";
char operation[OPERATION_LENGTH] = "Modify password";
char **ppret = NULL;
int rows = 0,cols = 0;
char *perr = NULL;
memset(sqlstr,0,1024);
sprintf(sqlstr,"SELECT count(*) FROM user WHERE name='%s'",username);
ret = my_sqlite3_get_table(pdb,sqlstr,&ppret,&rows,&cols,&perr);
if(ret != SQLITE_OK){
PrintServerError("my_sqlite3_get_table %s failed:%s\n",sqlstr,perr);
sqlite3_free(perr);
perr = NULL;
return -1;
}
sscanf(*(ppret+1),"%d",&ret);
if(0 == ret){
printf("The user Name:%s has no record in Tables!\n",username);
return -1;
}else{
memset(sqlstr,0,1024);
sprintf(sqlstr,"UPDATE user SET Password='%s' WHERE Name='%s'",password,username);
ret = my_sqlite3_exec(pdb,sqlstr,NULL,NULL,&perr);
if(ret != SQLITE_OK){
PrintServerError("exec %s failed:%s\n",sqlstr,perr);
sqlite3_free(perr);
perr = NULL;
return -1;
}
ret = insertHistoryRecord(pdb,username,operation);
if(ret != 0){
PrintServerError("Insert history records failed\n");
return -1;
}
}
return 0;
}
/*更改staffInfo表中的信息*/
int modifyStaffInfo(sqlite3 *pdb,char *staffname)
{
int ret = 0;
char sqlstr[1024] = "";
char **ppret = NULL;
int rows = 0,cols = 0;
char *perr = NULL;
char column[NORMAL_LENGTH] = "";
int i = 0;
memset(sqlstr,0,1024);
sprintf(sqlstr,"SELECT count(*) FROM StaffInfo WHERE Name='%s'",staffname);
ret = my_sqlite3_get_table(pdb,sqlstr,&ppret,&rows,&cols,&perr);
if(ret != SQLITE_OK){
PrintServerError("my_sqlite3_get_table %s failed:%s\n",sqlstr,perr);
sqlite3_free(perr);
perr = NULL;
return -1;
}
sscanf(*(ppret+1),"%d",&ret);
if(0 == ret){
printf("The user Name:%s has no record in the Tables!\n",staffname);
return -1;
}else{
printf("please input the column which want to modify:");
myGetString(column,NORMAL_LENGTH);
/*
*判断选择的column是字符串型还是整型或浮点型
*/
if(strncasecmp(column,"name",(int)sizeof("name")) == 0 ||strncasecmp(column,"address",(int)sizeof("address")) == 0 ||
strncasecmp(column,"phone",(int)sizeof("phone")) == 0 ||strncasecmp(column,"email",(int)sizeof("email")) == 0){
char value[NORMAL_LENGTH] = ""; //字符串型数据,用char[]接收
printf("please input the value which want to modify:");
myGetString(value,NORMAL_LENGTH);
memset(sqlstr,0,1024);
sprintf(sqlstr,"UPDATE staffInfo SET %s='%s' WHERE Name='%s'",column,value,staffname);
ret = my_sqlite3_exec(pdb,sqlstr,NULL,NULL,&perr);
if(ret != SQLITE_OK){
PrintServerError("exec %s failed:%s\n",sqlstr,perr);
sqlite3_free(perr);
perr = NULL;
return -1;
}
}else if(strncasecmp(column,"age",(int)sizeof("age")) == 0 ||strncasecmp(column,"level",(int)sizeof("level")) == 0 ||
strncasecmp(column,"id",(int)sizeof("id")) == 0){
int val = 0; //整型数据,用int接收
printf("please input the value which want to modify:");
scanf("%d",&val);
getchar();
memset(sqlstr,0,1024);
sprintf(sqlstr,"UPDATE staffInfo SET %s=%d WHERE Name='%s'",column,val,staffname);
ret = my_sqlite3_exec(pdb,sqlstr,NULL,NULL,&perr);
if(ret != SQLITE_OK){
PrintServerError("exec %s failed:%s\n",sqlstr,perr);
sqlite3_free(perr);
perr = NULL;
return -1;
}
}else if(strncasecmp(column,"salary",(int)sizeof("salary")) == 0){
float val = 0.0; //浮点型数据,用float接收
pri
没有合适的资源?快使用搜索试试~ 我知道了~
基于Linux C编程+TCP/IP协议、多线程的方式+SQLite3数据库实现的员工管理系统+项目源码+文档说明
共15个文件
c:8个
h:4个
makefile:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 29 浏览量
2024-11-08
17:20:27
上传
评论
收藏 20KB ZIP 举报
温馨提示
<项目介绍> - 基于Linux C编程,基于TCP/IP协议、多线程的方式,基于SQLite3数据库实现的员工管理系统 - 不懂运行,下载完可以私聊问,可远程教学 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 --------
资源推荐
资源详情
资源评论
收起资源包目录
基于SQLite3数据库实现的员工管理系统.zip (15个子文件)
StaffManagementSystem-main
include
smsServer.h 2KB
smsClient.h 1KB
smsDebug.h 2KB
smsPublic.h 2KB
README 2KB
client
handleServer.c 6KB
cliMain.c 6KB
Makefile 595B
public
myGetString.c 586B
smsProtocal.c 5KB
server
Makefile 902B
handleClient.c 5KB
operationFunctions.c 20KB
createSqlTables.c 5KB
serMain.c 8KB
共 15 条
- 1
资源评论
程序员无锋
- 粉丝: 3677
- 资源: 2181
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功