📄 posreckoningwindow.c
字号:
//////////////////////////////////////////////////////////////////////////
// Pos结帐窗口
//////////////////////////////////////////////////////////////////////////
#include <ncurses.h>
#include "PosSystem.h"
#include "OracleDB.h"
#include <stdlib.h>
extern char id[20];
extern char name[100];
//添加明细
int Add_List(int startY,int startX,saleProduct * salePro)
{
int result;
//int tempAmount=salePro->amount;
int tempAmount=1;
result=NewListWindow(10,20,"新增明细",salePro->bar_code,&tempAmount);
if(result==0)//确定返回0
{
salePro->amount+=tempAmount;
salePro->money=(salePro->amount)*(salePro->sale_price);
}
return result; //0返回添加成功 1为取消
}
//删除明细
int Del_List(int startY,int startX,saleProduct * salePro)
{
int result;
int tempAmount=salePro->amount;
result=DelListWindow(10,20,"删除明细",salePro,&tempAmount);
if(result==0)//确定返回0
{
if(tempAmount==salePro->amount)//删除数等于出售商品数量
{
return -1;
}
salePro->amount-=tempAmount;
salePro->money=(salePro->amount)*(salePro->sale_price);
return 0;
}
return 1; //0返回添加成功 1为取消
}
//撤消挂单
int Cancle_Hang_Bill_Dialog(int startY,int startX,LINKLIST *billList)
{
scr_dump("save2.scr");
int HangBillWinHight=11;
int HangBillWinWidth=36;
int ch,result=1;
WINDOW *win=CreateWindow(HangBillWinHight,HangBillWinWidth,startY,startX,Yes,RED_BLACK);
StringCenterPrint(win,1,"撤单");
printhline(win,2,1,HangBillWinWidth-2);//画水平线
wrefresh(win);
StringCenterPrint(win,3,"按Esc退出,上下键选择,回车撤单");
wrefresh(win);
//列表窗口
WINDOW *lists=CreateWindow(HangBillWinHight-5,HangBillWinWidth-2,startY+4,startX+1,No,RED_BLACK);
int lineCount=5;
int cursorLocation=1;
int currentRecNo=1;
//ch=GetChar(lists,0,0);
NODE * p;
NODE * firstRecPoint=billList->head;
int i=0;
int number=1;//每页第一条记录的编号
int tempNumber;//每次要打印的
while(1)
{
p=firstRecPoint;
tempNumber=number;
while(p!=NULL)
{
mvwprintw(lists,i,0,"%d",tempNumber++);
mvwprintw(lists,i,2,(char *)(p->node_data));
p=p->next;
i++;
if(i>=lineCount || p==NULL)
{
i=0;
break;
}
}
wrefresh(lists);
HandBillItem_reverse(lists,cursorLocation,currentRecNo,billList);
ch=GetChar(lists,0,0);
if(ch=='\e')
{
result=-1;
break;
}
//当在第一行的时候按向上键的时候
if(ch==KEY_UP )
{
if(cursorLocation==1)
{
if(firstRecPoint->prior!=NULL)
{
firstRecPoint=firstRecPoint->prior;
currentRecNo--;
number--;
}
//wclear(lists);
}
else
{
// 不在第一行的时候进行的处理
currentRecNo--;
cursorLocation--;
}
}
//当不是在最后一行按下向下键的时候的处理
if(ch==KEY_DOWN)
{
if( (cursorLocation<lineCount) && (currentRecNo<billList->count) )
{
currentRecNo++;
cursorLocation++;
}
else if((cursorLocation>=lineCount) && (currentRecNo<billList->count))
{
currentRecNo++;
firstRecPoint=firstRecPoint->next;
number++;
}
}
//模拟删除
if(ch=='\n')
{
int result;
result=DialogWindow(10,25,10,10,"您是否要撤单",RED_WHITE);
if(result!=0)
{
break;
}
Delete_Bill( (char *)(get_node_by_index(billList,currentRecNo)->node_data) );
//当从第一个节点开始删除的时候
if(currentRecNo==1)
{
//当前节点等于尾节点也就只剩一个节点时
if((billList->head==billList->rearptr) && (1==billList->count) )
{
del_head_link(billList);
break;
}
else
{
del_head_link(billList);
firstRecPoint=billList->head;
tempNumber=1;
}
}
else if(currentRecNo==billList->count) //当从尾节点开始删除的时候
{
int step=billList->count-lineCount; //计算出上一页第一条记录位置
NODE * temp=get_node_by_index(billList,step);//得到指定记录的指针
del_rear_link(billList); //将尾结点删掉
currentRecNo--; //当前记录号减一
cursorLocation--;//光标位置也减一
if(cursorLocation<1)//当光标位置小于1的时候说明要上翻一页
{
//当记录总数还大于每页显示的条数时
if(billList->count>lineCount)
{
cursorLocation=lineCount;
firstRecPoint=temp;
number-=5;
}
else
{
cursorLocation=billList->count;
firstRecPoint=billList->head;
number=1;
}
}
}
else if(cursorLocation==1)//当光标为第一位的时候
{
NODE * temp =get_node_by_index(billList,currentRecNo+1);
del_link_index(billList,currentRecNo);
firstRecPoint=temp;
}
else
{
del_link_index(billList,currentRecNo);
}
wclear(lists);
}
}
DestroyWindow(win);
DestroyWindow(lists);
scr_restore("save2.scr");
refresh();
return result;//返回选择的值,如确定就是0,返回就是1
}
//取单对话框
int HangBillDialog(int startY,int startX,LINKLIST *billList)
{
scr_dump("save.scr");
int HangBillWinHight=11;
int HangBillWinWidth=36;
int ch,result=1;
WINDOW *win=CreateWindow(HangBillWinHight,HangBillWinWidth,startY,startX,Yes,RED_BLACK);
StringCenterPrint(win,1,"取单");
printhline(win,2,1,HangBillWinWidth-2);//画水平线
StringCenterPrint(win,3,"按Esc退出,上下键选择,回车取单");
wrefresh(win);
//列表窗口
WINDOW *lists=CreateWindow(HangBillWinHight-5,HangBillWinWidth-2,startY+4,startX+1,No,RED_BLACK);
int lineCount=5;
int cursorLocation=1;
int currentRecNo=1;
//ch=GetChar(lists,0,0);
NODE * p;
NODE * firstRecPoint=billList->head;
int i=0;
int number=1;//每页第一条记录的编号
int tempNumber;//每次要打印的
while(1)
{
wclear(lists);
p=firstRecPoint;
tempNumber=number;
while(p!=NULL)
{
mvwprintw(lists,i,0,"%d",tempNumber++);
mvwprintw(lists,i,2,(char *)(p->node_data));
p=p->next;
i++;
if(i>=lineCount || p==NULL)
{
i=0;
break;
}
}
wrefresh(lists);
HandBillItem_reverse(lists,cursorLocation,currentRecNo,billList);
ch=GetChar(lists,0,0);
if(ch=='\e')
{
result=-1;
break;
}
//当在第一行的时候按向上键的时候
if(ch==KEY_UP )
{
if(cursorLocation==1)
{
if(firstRecPoint->prior!=NULL)
{
firstRecPoint=firstRecPoint->prior;
currentRecNo--;
number--;
}
//wclear(lists);
}
else
{
// 不在第一行的时候进行的处理
currentRecNo--;
cursorLocation--;
}
}
//当不是在最后一行按下向下键的时候的处理
if(ch==KEY_DOWN)
{
if( (cursorLocation<lineCount) && (currentRecNo<billList->count) )
{
currentRecNo++;
cursorLocation++;
}
else if((cursorLocation>=lineCount) && (currentRecNo<billList->count))
{
currentRecNo++;
firstRecPoint=firstRecPoint->next;
number++;
}
}
//模拟删除
if(ch=='\n')
{
result=currentRecNo;
break;
}
}
DestroyWindow(win);
DestroyWindow(lists);
scr_restore("save.scr");
return result;//返回选择的值,如确定就是0,返回就是1
}
//取单
int GetBill(int startY,int startX)
{
scr_dump("save.scr");
int HangBillWinHight=11;
int HangBillWinWidth=25;
int ch,result;
WINDOW *win=CreateWindow(HangBillWinHight,HangBillWinWidth,startY,startX,Yes,RED_BLACK);
StringCenterPrint(win,1,"取单");
printhline(win,2,1,HangBillWinWidth-2);//画水平线
wrefresh(win);
//列表窗口
WINDOW *lists=CreateWindow(HangBillWinHight-5,HangBillWinWidth-2,startY+4,startX+1,No,RED_BLACK);
//char no[][20]={"200801010101010001","200801010101010002","200801010101010003"};
BillID* no1=(BillID*)malloc(sizeof(BillID));
strcpy(no1->no,"200801010101010001");
BillID* no2=(BillID*)malloc(sizeof(BillID));
strcpy(no2->no,"200801010101010002");
BillID* no3=(BillID*)malloc(sizeof(BillID));
strcpy(no3->no,"200801010101010003");
BillID* no4=(BillID*)malloc(sizeof(BillID));
strcpy(no4->no,"200801010101010004");
BillID* no5=(BillID*)malloc(sizeof(BillID));
strcpy(no5->no,"200801010101010005");
BillID* no6=(BillID*)malloc(sizeof(BillID));
strcpy(no6->no,"200801010101010006");
BillID* no7=(BillID*)malloc(sizeof(BillID));
strcpy(no7->no,"200801010101010007");
BillID* no8=(BillID*)malloc(sizeof(BillID));
strcpy(no8->no,"200801010101010008");
BillID* no9=(BillID*)malloc(sizeof(BillID));
strcpy(no9->no,"200801010101010009");
BillID* no10=(BillID*)malloc(sizeof(BillID));
strcpy(no10->no,"200801010101010010");
BillID* no11=(BillID*)malloc(sizeof(BillID));
strcpy(no11->no,"200801010101010011");
BillID* no12=(BillID*)malloc(sizeof(BillID));
strcpy(no12->no,"200801010101010012");
LINKLIST *billList;//挂单列表
billList=(LINKLIST *)malloc(sizeof(LINKLIST));//链表分配空间
link_init(billList);
insert_rear_link(billList,no1);
insert_rear_link(billList,no2);
insert_rear_link(billList,no3);
insert_rear_link(billList,no4);
insert_rear_link(billList,no5);
insert_rear_link(billList,no6);
insert_rear_link(billList,no7);
insert_rear_link(billList,no8);
insert_rear_link(billList,no9);
insert_rear_link(billList,no10);
insert_rear_link(billList,no11);
insert_rear_link(billList,no12);
int lineCount=5;
int current=1;
//ch=GetChar(lists,0,0);
NODE * p=billList->head;
int i=0;
while(p!=NULL)
{
if(i>=lineCount)
{
break;
}
//node_data
mvwprintw(lists,i,0,((BillID *)(p->node_data))->no);
p=p->next;
i++;
}
wrefresh(lists);
while(1)
{
option_reverse(lists,lineCount,ch,¤t,billList);
ch=GetChar(lists,0,0);
}
//取单处理
free_list(billList);
scr_restore("save.scr");
getchar();
DestroyWindow(win);
DestroyWindow(lists);
return result;//返回选择的值,如确定就是0,返回就是1
}
//取单
int GetRollBill(int startY,int startX)
{
scr_dump("save.scr");
int HangBillWinHight=11;
int HangBillWinWidth=25;
int ch,result;
WINDOW *win=CreateWindow(HangBillWinHight,HangBillWinWidth,startY,startX,Yes,RED_BLACK);
StringCenterPrint(win,1,"取单");
printhline(win,2,1,HangBillWinWidth-2);//画水平线
wrefresh(win);
//列表窗口
WINDOW *lists=CreateWindow(HangBillWinHight-5,HangBillWinWidth-2,startY+4,startX+1,No,RED_BLACK);
//char no[][20]={"200801010101010001","200801010101010002","200801010101010003"};
BillID* no1=(BillID*)malloc(sizeof(BillID));
strcpy(no1->no,"200801010101010001");
BillID* no2=(BillID*)malloc(sizeof(BillID));
strcpy(no2->no,"200801010101010002");
BillID* no3=(BillID*)malloc(sizeof(BillID));
strcpy(no3->no,"200801010101010003");
BillID* no4=(BillID*)malloc(sizeof(BillID));
strcpy(no4->no,"200801010101010004");
BillID* no5=(BillID*)malloc(sizeof(BillID));
strcpy(no5->no,"200801010101010005");
BillID* no6=(BillID*)malloc(sizeof(BillID));
strcpy(no6->no,"200801010101010006");
BillID* no7=(BillID*)malloc(sizeof(BillID));
strcpy(no7->no,"200801010101010007");
BillID* no8=(BillID*)malloc(sizeof(BillID));
strcpy(no8->no,"200801010101010008");
BillID* no9=(BillID*)malloc(sizeof(BillID));
strcpy(no9->no,"200801010101010009");
BillID* no10=(BillID*)malloc(sizeof(BillID));
strcpy(no10->no,"200801010101010010");
BillID* no11=(BillID*)malloc(sizeof(BillID));
strcpy(no11->no,"200801010101010011");
BillID* no12=(BillID*)malloc(sizeof(BillID));
strcpy(no12->no,"200801010101010012");
LINKLIST *billList;//挂单列表
billList=(LINKLIST *)malloc(sizeof(LINKLIST));//链表分配空间
link_init(billList);
insert_rear_link(billList,no1);
insert_rear_link(billList,no2);
insert_rear_link(billList,no3);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -