📄 loginwindow.c
字号:
wrefresh(given);
break;
}
}
}
ENSURE:
wattron(dialog[1],A_REVERSE);
mvwprintw(dialog[1],1,2, "确定");
wrefresh(dialog[1]);
while (1)
{
ch=wgetch(dialog[1]);
switch (ch)
{
case KEY_F(1):
return 0;
case KEY_UP:
wattroff(dialog[1],A_REVERSE);
mvwprintw(dialog[1],1,2, "确定");
wrefresh(dialog[1]);
goto MONEY;
case KEY_RIGHT:
wattroff(dialog[1],A_REVERSE);
mvwprintw(dialog[1],1,2, "确定");
wrefresh(dialog[1]);
goto CANCEL;
case '\n':
if (cnt1==0)
{
Message("请您输入的金额",10,40);
scr_restore("finish.scr");
cnt1=0;
now_row1=0;
secondStr[0]='\0';
goto MONEY;
}
if(is_float(secondStr)==0)
{
Message("输入金额格式错误",10,40);
scr_restore("finish.scr");
cnt1=0;
now_row1=0;
secondStr[0]='\0';
goto MONEY;
}
cashTotal=atof(secondStr);
if (cashTotal<cashReceive)
{
Message("实收金额小于应收金额",10,40);
scr_restore("finish.scr");
cnt1=0;
now_row1=0;
secondStr[0]='\0';
goto MONEY;
}
cashGive=cashTotal-cashReceive;
wprintw(change,"%.2f",cashGive);
wrefresh(change);
wgetch(dialog[1]);
//修改数据库数据
sale_info->given_sum=cashReceive;//购买商品的总价格
sale_info->real_sum=cashTotal;//实际付款数
sale_info->change=cashGive;//找零
sale_info->sale_money=cashReceive;
sale_info->sale_state=0;//0代表正常销售
if (insert_sale(sale_info)==-1)
{
Message("数据库出错",10,40);
endwin();
exit(1);
}
if (insert_sale(sale_info)==0)
{
Message("插入销售信息的时候出错",10,40);
endwin();
exit(1);
}
SALE_DETAIL *sale_detail=(SALE_DETAIL *)malloc(sizeof(SALE_DETAIL));
DETAILID *detail=(DETAILID *)malloc(sizeof(DETAILID));
PRODUCT *pro_info=(PRODUCT *)malloc(sizeof(PRODUCT));
for ( i=1; i<=salelist.count; i++)
{
n=salelist.get_node_by_index(&salelist,i);
pro_info=(PRODUCT *)n->data;
int res=update_product_count(pro_info);
if (res==-1)
{
Message("数据库出错",10,40);
endwin();
exit(1);
}
if (res==0)
{
Message("没有找到相应的商品",10,40);
endwin();
exit(1);
}
//消费明细表添加
if (get_seq_detail_id(detail)!=1)
{
Message("数据库出错",10,40);
endwin();
exit(1);
}
strcpy(sale_detail->detail_id,sale_info->sale_date);
strcat(sale_detail->detail_id,detail->seq_detail_id);
strcpy(sale_detail->sale_id,sale_info->sale_id);
strcpy(sale_detail->bar_code,pro_info->bar_code);
sale_detail->count=pro_info->count;
sale_detail->sale_price=pro_info->sale_price;
sale_detail->sale_state=0;//0代表正常销售
res=insert_sale_detail(sale_detail);
if (res==-1)
{
Message("数据库出错",10,40);
endwin();
exit(1);
}
if (res==0)
{
Message("插入销售明细的时候出错",10,40);
endwin();
exit(1);
}
}
salelist.clear_link(&salelist);
return 1;
}
}
CANCEL:
wattron(dialog[2],A_REVERSE);
mvwprintw(dialog[2],1,2, "取消");
wrefresh(dialog[2]);
while (1)
{
ch=wgetch(dialog[2]);
switch (ch)
{
case KEY_LEFT:
wattroff(dialog[2],A_REVERSE);
mvwprintw(dialog[2],1,2, "取消");
wrefresh(dialog[2]);
goto ENSURE;
case KEY_F(1):
case '\n':
return 0;
}
}
}
/*===============================================================
function:挂单窗口与功能实现
================================================================*/
int suspend_deal_win(SALE *sale_info)
{
if (salelist.count)
{
if (save_sale_count>=3)
{
Message("已有3个挂单",10,40);
return 0;
}
if (message_botton("是否要挂单",10,40))
{
strcpy(save_sale_id[save_sale_count++],sale_info->sale_id);
int i=1;
sale_info->given_sum=0;
sale_info->real_sum=0;
sale_info->sale_money=0;
sale_info->change=0;
sale_info->sale_state=-1;//-1代表销售状态为挂单
//插入销售表
int res=insert_sale(sale_info);
if (res==-1)
{
Message("数据库出错",10,40);
endwin();
exit(1);
}
if (res==0)
{
Message("插入销售信息的时候出错",10,40);
endwin();
exit(1);
}
PRODUCT *pro_info=(PRODUCT *)malloc(sizeof(PRODUCT));
SALE_DETAIL *sale_detail=(SALE_DETAIL *)malloc(sizeof(SALE_DETAIL));
DETAILID *detail=(DETAILID *)malloc(sizeof(DETAILID));
for ( i=1; i<=salelist.count; i++)
{
NODE *n=salelist.get_node_by_index(&salelist,i);
pro_info=(PRODUCT *)n->data;
res=update_product_count(pro_info);
if (res==-1)
{
Message("数据库出错",10,40);
endwin();
exit(1);
}
if (res==0)
{
Message("没有找到相应的商品",10,40);
endwin();
exit(1);
}
//消费明细表添加
if (get_seq_detail_id(detail)!=1)
{
Message("数据库出错",10,40);
endwin();
exit(1);
}
strcpy(sale_detail->detail_id,sale_info->sale_date);
strcat(sale_detail->detail_id,detail->seq_detail_id);
strcpy(sale_detail->sale_id,sale_info->sale_id);
strcpy(sale_detail->bar_code,pro_info->bar_code);
sale_detail->count=pro_info->count;
sale_detail->sale_price=pro_info->sale_price;
sale_detail->sale_state=-1;//-1代表挂单
res=insert_sale_detail(sale_detail);
if (res==-1)
{
Message("数据库出错",10,40);
endwin();
exit(1);
}
if (res==0)
{
Message("插入销售明细的时候出错",10,40);
endwin();
exit(1);
}
}
salelist.clear_link(&salelist);
return 1;
}
return 0;
}
Message("没有销售商品",10,40);
return 0;
}
/*====================================================
function:取单窗口与功能实现
===================================================*/
void fetch_deal_win()
{
if(salelist.count)
{
Message("有销售单没有结算",10,40);
return;
}
if(save_sale_count==0)
{
Message("没有挂单信息",10,40);
return;
}
WINDOW *dialog;
dialog=create_win(10,40,6,20);
keypad(dialog,TRUE);
wbkgd(dialog,COLOR_PAIR(7));
box(dialog,0,0);
mvwprintw(dialog,7,10,"按ENTER键取单F1键返回");
wrefresh(dialog);
mvwprintw(dialog,0,19,"取单");
int cur=0;
print_save_sale_id(dialog,cur);
wrefresh(dialog);
int ch=0;
SALE_ID *save_id=(SALE_ID *)malloc(sizeof(SALE_ID));
while (1)
{
int i=1;
int res=0;
ch=wgetch(dialog);
switch (ch)
{
case KEY_F(1):
return;
case KEY_UP:
if (cur>0)
{
print_save_sale_id(dialog,--cur);
}
break;
case KEY_DOWN:
if (cur<=save_sale_count-2)
{
print_save_sale_id(dialog,++cur);
}
break;
case '\n':
//根据单号取单
strcpy(save_id->sale_id,save_sale_id[cur]);
res=get_sale_detail(save_id);
if (res==-1)
{
Message("数据库出错",10,40);
endwin();
exit(1);
}
if (salelist.count==0)
{
Message("取单的时候数据库出错,没找到相应的数据",10,40);
endwin();
exit(1);
}
for ( i=1; i<=salelist.count; i++)
{
//数据库修改返回相应商品的库存
NODE *n=salelist.get_node_by_index(&salelist,i);
PRODUCT * pro_info=(PRODUCT *)n->data;
res=fetch_product_count(pro_info);
if (res==-1)
{
Message("数据库出错",10,40);
endwin();
exit(1);
}
if (res==0)
{
Message("没有找到相应的商品",10,40);
endwin();
exit(1);
}
}
//把消费表及消费明细表中的挂单消息进行删除
res=del_sale_detail(save_id);
if (res==-1)
{
Message("数据库出错",10,40);
endwin();
exit(1);
}
if (res==0)
{
Message("删除销售明细的时候数据出错",10,40);
endwin();
exit(1);
}
//删除原数据中提取单号;
for ( i=cur+1; i<=save_sale_count-1; i++)
{
strcpy(save_sale_id[cur],save_sale_id[i]);
}
save_sale_count--;
return;
}
}
}
/*=====================================================
function:打印取单窗口中的单号
=====================================================*/
void print_save_sale_id(WINDOW *print_window,int cur)
{
if (save_sale_count==0)
{
return;
}
int i=0;
for (; i<=save_sale_count-1; i++)
{
if (i==cur)
{
wstandout(print_window);
}
mvwprintw(print_window,1+i,10,"%d.%s",i+1,save_sale_id[i]);
if (i==cur)
{
wstandend(print_window);
}
}
wrefresh(print_window);
}
/*==========================================================
function:撤单窗口与功能的实现
===========================================================*/
void remove_deal_win()
{
//先判断当前有无销售单,有销售单的话按F7进行撤单
if (salelist.count)
{
if (message_botton("您确定要删除当前销售记录",10,40))
{
salelist.clear_link(&salelist);
}
return;
}
if (save_sale_count==0)
{
Message("无挂单",10,40);
return;
}
WINDOW *dialog;
dialog=create_win(10,40,6,20);
keypad(dialog,TRUE);
wbkgd(dialog,COLOR_PAIR(7));
box(dialog,0,0);
wrefresh(dialog);
mvwprintw(dialog,0,19,"撤单");
mvwprintw(dialog,7,10,"按ENTER键撤单F1键返回");
int cur=0;
print_save_sale_id(dialog,cur);
wrefresh(dialog);
int ch=0;
SALE_ID *save_id=(SALE_ID *)malloc(sizeof(SALE_ID));
while (1)
{
int i=1;
int res=0;
ch=wgetch(dialog);
switch (ch)
{
case KEY_F(1):
return;
case KEY_UP:
if (cur>0)
{
print_save_sale_id(dialog,--cur);
}
break;
case KEY_DOWN:
if (cur<=save_sale_count-2)
{
print_save_sale_id(dialog,++cur);
}
break;
case '\n':
//根据单号取单
if ( message_botton("是否确定要撤单",10,36)==0 )
{
return;
}
strcpy(save_id->sale_id,save_sale_id[cur]);
res=get_sale_detail(save_id);
if (res==-1)
{
Message("数据库出错",10,40);
endwin();
exit(1);
}
if (salelist.count==0)
{
Message("取单的时候数据库出错,没找到相应的数据",10,40);
endwin();
exit(1);
}
for ( i=1; i<=salelist.count; i++)
{
//数据库修改返回商品库存
NODE *n=salelist.get_node_by_index(&salelist,i);
PRODUCT * pro_info=(PRODUCT *)n->data;
res=fetch_product_count(pro_info);
if (res==-1)
{
Message("数据库出错",10,40);
endwin();
exit(1);
}
if (res==0)
{
Message("没有找到相应的商品",10,40);
endwin();
exit(1);
}
}
//撤单的时候把消费表及消费明细表中挂单的信息进行删除
res=del_sale_detail(save_id);
if (res==-1)
{
Message("数据库出错",10,40);
endwin();
exit(1);
}
if (res==0)
{
Message("删除销售明细的时候数据出错",10,40);
endwin();
exit(1);
}
//删除原数据中提取单号;
for ( i=cur+1; i<=save_sale_count-1; i++)
{
strcpy(save_sale_id[cur],save_sale_id[i]);
}
save_sale_count--;
salelist.clear_link(&salelist);
return;
}
}
}
/*==================================================
function:退货功能
===================================================*/
void return_purchase()
{
if (salelist.count)
{
Message("有销售单未结算",10,40);
return;
}
account_log_win();
return;
}
/*=====================================================
function:超级帐户登陆退货窗口与超级帐户验证
=======================================================*/
void account_log_win()
{
char user[7]={'\0'};//账户帐号
char pwd[13]={'\0'};//账户密码
int ch,res;
int now_col,now_row;
int now_col1,now_row1;
int cnt=0;
int cnt1=0;
int l=0;
int i=0;
WINDOW *dialog[3]={NULL};
print_dialog_box(10,40,"退货",1,dialog);
mvwprintw(dialog[0],2,4,"超级账户帐号:");
mvwprintw(dialog[0],4,4,"超级账户密码:");
wrefresh(dialog[0]);
keypad(dialog[1],TRUE);
keypad(dialog[2],TRUE);
WINDOW *account=create_win(1,16,9,38);
keypad(account,TRUE);
wbkgd(account,COLOR_PAIR(4));
wrefresh(account);
WINDOW *passwd=create_win(1,16,11,38);
keypad(passwd,TRUE);
wbkgd(passwd,COLOR_PAIR(4));
wrefresh(passwd);
scr_dump("superadmin.scr");
ACCOUNT:
wmove(account,0,0);
wprintw(account,user);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -