📄 sellfunction.c
字号:
#include "extern.h"
#include "struct.h"
/*======================销售函数=====================*/
/*=================添加明细==============*/
void AddDetail()
{
struct Sell * buf;
int i,j,temp,mer_amount;
char bar_code[15],num[15];
i=0;
j=0;
temp=0;
mer_amount= 0;
WINDOW *add_sell_win = newwin(8,30,8,25);
WINDOW *bar_code_win = subwin(add_sell_win,1,15,10,33);
WINDOW *num_win = subwin(add_sell_win,1,15,13,33);
wbkgd(add_sell_win,COLOR_PAIR(2));
box(add_sell_win,0,0);
mvwprintw(add_sell_win,0,10,"添加明细");
mvwprintw(add_sell_win,2,1,"条形码:");
mvwprintw(add_sell_win,5,3,"数量:");
wbkgd(bar_code_win,COLOR_PAIR(10));
touchwin(add_sell_win);
wrefresh(add_sell_win);
wrefresh(bar_code_win);
wbkgd(num_win,COLOR_PAIR(10));
touchwin(add_sell_win);
wrefresh(add_sell_win);
wrefresh(num_win);
//要求输入条形码
do
{
memset(bar_code,0,sizeof(bar_code));
mvwgetnstr(bar_code_win,0,0,bar_code,15);
if(bar_code[0] != 'C')
{
ShowMessage(" 输入错误第一个必须为“C”");
touchwin(sell_main_win);
wrefresh(sell_main_win);
touchwin(add_sell_win);
wrefresh(add_sell_win);
wclrtoeol(bar_code_win);
continue;
}
if(bar_code[1] != 'N')
{
ShowMessage(" 输入错误,第2个必须为“N”");
touchwin(sell_main_win);
wrefresh(sell_main_win);
touchwin(add_sell_win);
wrefresh(add_sell_win);
wclrtoeol(bar_code_win);
continue;
}
if(strlen(bar_code) > 8)
{
ShowMessage(" 输入的字符太长了,必须为8位");
touchwin(sell_main_win);
wrefresh(sell_main_win);
touchwin(add_sell_win);
wrefresh(add_sell_win);
wclrtoeol(bar_code_win);
continue;
}
for(i=2;i<=7;i++)
{
if(isdigit(bar_code[i]))
{
continue;
}
temp=1;
ShowMessage(" 输入错误,后面6位必须为数字");
touchwin(sell_main_win);
wrefresh(sell_main_win);
touchwin(add_sell_win);
wrefresh(add_sell_win);
wclrtoeol(bar_code_win);
continue;
}
if(1 == temp)
{
temp = 0;
continue;
}
//当输入的条形码正确的时候
//查询输入的条形码是否存在
if(!SearchBarCode(bar_code,MER_NAME,MER_UNIT,MER_SPEC,&MER_PRICE,&MER_STOCK))
{
ShowMessage(" 你输入的条形码不存在,请重新输入");
touchwin(sell_main_win);
wrefresh(sell_main_win);
touchwin(add_sell_win);
wrefresh(add_sell_win);
wclrtoeol(bar_code_win);
continue;
}
break;
}while (1);
//要求输入数量
do
{
memset(num,0,sizeof(num));
mvwgetnstr(num_win,0,0,num,15);
for(i=0;i<strlen(num);i++)
{
if(!isdigit(num[i]))
{
temp = 1;
ShowMessage(" 输入错误,必须输入整数");
touchwin(sell_main_win);
wrefresh(sell_main_win);
touchwin(add_sell_win);
wrefresh(add_sell_win);
wclrtoeol(num_win);
break;
}
}
if(1 == temp)
{
temp = 0;
continue;
}
//判断输入的数字是否超过库存
mer_amount = atoi(num);
if(mer_amount > MER_STOCK)
{
ShowMessage(" 库存不足,请重新输入");
touchwin(sell_main_win);
wrefresh(sell_main_win);
touchwin(add_sell_win);
wrefresh(add_sell_win);
wclrtoeol(num_win);
continue;
}
break;
}while (1);
//销售列表里面有相同的商品,只要进行相加就可以了
buf = IsTheSameMer(bar_code);
if(buf != NULL)
{
buf->mer_amount = buf->mer_amount + mer_amount;
buf->total_money = buf->mer_amount * buf->sell_price;
//删除当前窗口
delwin(add_sell_win);
ShowMessage(" 添加商品成功");
touchwin(sell_main_win);
wrefresh(sell_main_win);
PrintSellInfo();
}
//销售列表为空
else
{
MER_AMOUNT = mer_amount;
TOTAL_MONEY = MER_PRICE * mer_amount;
InputDateToStruct(bar_code,MER_NAME,MER_UNIT,MER_SPEC,MER_PRICE,MER_AMOUNT,TOTAL_MONEY);
//删除当前窗口
delwin(add_sell_win);
ShowMessage(" 添加商品成功");
PrintSellInfo();
}
}
/*=================删除明细===============*/
void DelDetail()
{
//判断有没有数据,如果没有的话,不可以收银
if(head->next == NULL)
{
ShowMessage(" 没有数据,不允许删除");
touchwin(sell_main_win);
wrefresh(sell_main_win);
return;
}
struct Sell * buf;
char bar_code[15],num[15];
int i,j,temp,mer_amount;
i=0;
j=0;
temp=0;
WINDOW *del_win = newwin(8,30,8,25);
WINDOW *bar_code_win = subwin(del_win,1,15,10,33);
WINDOW *num_win = subwin(del_win,1,15,13,33);
wbkgd(del_win,COLOR_PAIR(2));
box(del_win,0,0);
mvwprintw(del_win,0,10,"删除明细");
mvwprintw(del_win,2,1,"条形码:");
mvwprintw(del_win,5,3,"数量:");
wrefresh(del_win);
wbkgd(bar_code_win,COLOR_PAIR(10));
touchwin(del_win);
wrefresh(del_win);
wrefresh(bar_code_win);
wbkgd(num_win,COLOR_PAIR(10));
touchwin(del_win);
wrefresh(del_win);
wrefresh(num_win);
//要求输入条形码
do
{
memset(bar_code,0,sizeof(bar_code));
mvwgetnstr(bar_code_win,0,0,bar_code,15);
if(bar_code[0] != 'C')
{
ShowMessage(" 输入错误第一个必须为“C”");
touchwin(sell_main_win);
wrefresh(sell_main_win);
touchwin(del_win);
wrefresh(del_win);
wclrtoeol(bar_code_win);
wrefresh(bar_code_win);
continue;
}
if(bar_code[1] != 'N')
{
ShowMessage(" 输入错误,第2个必须为“N”");
touchwin(sell_main_win);
wrefresh(sell_main_win);
touchwin(del_win);
wrefresh(del_win);
wclrtoeol(bar_code_win);
wrefresh(bar_code_win);
continue;
}
if(strlen(bar_code) > 8)
{
ShowMessage(" 输入的字符太长了,必须为8位");
touchwin(sell_main_win);
wrefresh(sell_main_win);
touchwin(del_win);
wrefresh(del_win);
wclrtoeol(bar_code_win);
wrefresh(bar_code_win);
continue;
}
for(i=2;i<=7;i++)
{
if(isdigit(bar_code[i]))
{
continue;
}
temp=1;
ShowMessage(" 输入错误,后面6位必须为数字");
touchwin(sell_main_win);
wrefresh(sell_main_win);
touchwin(del_win);
wrefresh(del_win);
wclrtoeol(bar_code_win);
wrefresh(bar_code_win);
continue;
}
if(1 == temp)
{
temp = 0;
continue;
}
//查询输入的条形码在销售表是总否存在
buf = IsTheSameMer(bar_code);
if(buf == NULL)
{
ShowMessage(" 条形码不再销售列表,不能删除");
touchwin(sell_main_win);
wrefresh(sell_main_win);
touchwin(del_win);
wrefresh(del_win);
wclrtoeol(bar_code_win);
wrefresh(bar_code_win);
continue;
}
break;
}while (1);
//要求输入数量
do
{
memset(num,0,sizeof(num));
mvwgetnstr(num_win,0,0,num,15);
for(i=0;i<strlen(num);i++)
{
if(!isdigit(num[i]))
{
temp = 1;
ShowMessage(" 输入错误,必须输入整数");
touchwin(sell_main_win);
wrefresh(sell_main_win);
touchwin(del_win);
wrefresh(del_win);
wclrtoeol(num_win);
wrefresh(num_win);
break;
}
}
if(1 == temp)
{
temp = 0;
continue;
}
if(0 == strlen(num))
{
ShowMessage(" 输入不允许为空,请重新输入");
touchwin(sell_main_win);
wrefresh(sell_main_win);
touchwin(del_win);
wrefresh(del_win);
wclrtoeol(num_win);
wrefresh(num_win);
continue;
}
//判断输入的数字是否超过库存
mer_amount = atoi(num);
if(mer_amount > buf->mer_amount)
{
ShowMessage(" 输入的数量太大,请重新输入");
touchwin(sell_main_win);
wrefresh(sell_main_win);
touchwin(del_win);
wrefresh(del_win);
wclrtoeol(num_win);
wrefresh(num_win);
continue;
}
break;
}while (1);
//用户要删除一种的商品的情况
if(mer_amount == buf->mer_amount)
{
p1 = head;
while(p1->next != NULL)
{
p2=p1;
p1=p1->next;
//判断是否有相同的条形码
if(!strncmp(buf->bar_code,p1->bar_code, strlen(buf->bar_code)))
{
p2->next = p1->next;
free(buf);
break;
}
}
}
//用户要删除部分商品
else
{
buf->mer_amount = buf->mer_amount - mer_amount;
buf->total_money = buf->mer_amount * buf->sell_price;
}
//删除窗口
delwin(del_win);
ShowMessage(" 删除商品成功");
touchwin(sell_main_win);
wrefresh(sell_main_win);
PrintSellInfo();
}
/*=================收银============*/
void GetMoney()
{
//判断有没有数据,如果没有的话,不可以收银
if(head->next == NULL)
{
ShowMessage(" 没有数据,不允许收银");
touchwin(sell_main_win);
wrefresh(sell_main_win);
return;
}
struct Sell * buf;
char user_pay[15],ch,SELL_DETAIL_NO[20];
float get_money,pay,zhaoling,fact_pay,f;
int i,j,temp,business_no,p,alter_state,save_sell_detail_state,sell_detail_no;
business_no=0;
temp=0;
i=0;
j=0;
get_money = 0 ;
alter_state = 1;
save_sell_detail_state = 1;
strncpy(SELL_DETAIL_NO,"0001",strlen("0001"));
WINDOW *get_money_win = newwin(10,30,7,25);
WINDOW *user_pay_win = subwin(get_money_win,1,15,9,38);//用户付款 50
WINDOW *should_pay_win = subwin(get_money_win,1,15,11,38);//实际要付的,比如20.15
WINDOW *fact_pay_win = subwin(get_money_win,1,15,13,38);//实际收的,实际收20.2
WINDOW *zhaoling_win = subwin(get_money_win,1,15,15,38);//找零钱 29.8
wbkgd(get_money_win,COLOR_PAIR(10));
box(get_money_win,0,0);
mvwprintw(get_money_win,0,13,"收银:");
mvwprintw(get_money_win,2,2,"用户付款:");
mvwprintw(get_money_win,4,7,"应收:");
mvwprintw(get_money_win,6,7,"实收:");
mvwprintw(get_money_win,8,7,"找零:");
wrefresh(get_money_win);
wbkgd(user_pay_win,COLOR_PAIR(2));
wrefresh(user_pay_win);
wbkgd(should_pay_win,COLOR_PAIR(2));
wrefresh(should_pay_win);
wbkgd(fact_pay_win,COLOR_PAIR(2));
wrefresh(fact_pay_win);
wbkgd(zhaoling_win,COLOR_PAIR(2));
wrefresh(zhaoling_win);
buf = head->next;
while (buf != NULL)
{
get_money = get_money + buf->total_money;
buf = buf->next;
}
//打印出用户付的和实际要付的
mvwprintw(should_pay_win,0,0,"%.2f",get_money);
wrefresh(should_pay_win);
//实际收的钱进行四舍五入
fact_pay =0;
p = (int)(get_money*10 + 0.5);
f =(float)p/10;
fact_pay = f;
mvwprintw(fact_pay_win,0,0,"%.1f",fact_pay);
wrefresh(fact_pay_win);
//要求输入用户付款金额
do
{
memset(user_pay,0,sizeof(fact_pay));
mvwgetnstr(user_pay_win,0,0,user_pay,15);
for(i=0;i<strlen(user_pay);i++)
{
if(user_pay[i] == '.')
{
j++;
continue;
}
if(!isdigit(user_pay[i]))
{
temp = 1;
break;
}
}
if(1 == temp)
{
ShowMessage(" 输入错误,输入的必须为数字");
touchwin(sell_main_win);
wrefresh(sell_main_win);
touchwin(get_money_win);
wrefresh(get_money_win);
wclrtoeol(user_pay_win);
wrefresh(user_pay_win);
continue;
}
if( 2 == j)
{
ShowMessage(" 您输入了2个小数点,请重新输入");
touchwin(sell_main_win);
wrefresh(sell_main_win);
touchwin(get_money_win);
wrefresh(get_money_win);
wclrtoeol(user_pay_win);
wrefresh(user_pay_win);
continue;
}
pay = atof(user_pay);//把用户付的款转换成FLOAT型
if(pay < get_money)
{
ShowMessage(" 您输入的金额不够,请重新输入");
touchwin(sell_main_win);
wrefresh(sell_main_win);
touchwin(get_money_win);
wrefresh(get_money_win);
wclrtoeol(user_pay_win);
wrefresh(user_pay_win);
continue;
}
break;
}while (1);
//打印出实收金额
mvwprintw(user_pay_win,0,0,"%.1f",pay);
wrefresh(user_pay_win);
//打印出找零金额
zhaoling = pay-fact_pay;
mvwprintw(zhaoling_win,0,0,"%.1f",zhaoling);
wrefresh(zhaoling_win);
ch = '\0';
noecho();
ch = mvwgetch(get_money_win,8,14);
echo();
//首先,把销售单号求出来
char tmp[100];
strncpy(tmp,System_Time,100);
strcpy(SELL_NO,strcat(tmp,BUSINESS_NO));
//保存销售记录到销售表
if(SaveSellInfoToDb(SELL_NO,BUSINESS_NO,ACCOUNTID,System_Time,pay,fact_pay,get_money,zhaoling,SELL_STATE) )
{
ShowMessage(" 保存销售记录成功 ");
touchwin(sell_main_win);
wrefresh(sell_main_win);
}
else
{
ShowMessage(" 保存销售记录失败...... ");
touchwin(sell_main_win);
wrefresh(sell_main_win);
}
//保存销售明细到销售明细表
buf = head->next;
sell_detail_no = atoi(SELL_DETAIL_NO);
sprintf(SELL_DETAIL_NO,"%04d",sell_detail_no);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -