📄 posreckoningwindow.c
字号:
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 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,((BillID *)(p->node_data))->no);
p=p->next;
i++;
if(i>=lineCount || p==NULL)
{
i=0;
break;
}
}
wrefresh(lists);
ListOption_reverse(lists,cursorLocation,currentRecNo,billList);
wattron(lists,A_REVERSE);//反白显示下一行
mvwprintw(lists,0,0,"%3d,%3d",currentRecNo,cursorLocation);
//mvwprintw(lists,1,0,"%s",((BillID *)(firstRecPoint->node_data))->no);
wattroff(lists,A_REVERSE);
wrefresh(lists);
ch=GetChar(lists,0,0);
//当在第一行的时候按向上键的时候
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')
{
//当从第一个节点开始删除的时候
if(currentRecNo==1)
{
//当前节点等于尾节点也就只剩一个节点时
if((billList->head==billList->rearptr) && (1==billList->count) )
{
// wattron(lists,A_REVERSE);//反白显示下一行
// mvwprintw(lists,1,0,"1.%3d,%3d",currentRecNo,cursorLocation);
// wattroff(lists,A_REVERSE);
// wrefresh(lists);
// GetChar(lists,0,0);
del_head_link(billList);
return;
}
else
{
// wattron(lists,A_REVERSE);//反白显示下一行
// mvwprintw(lists,1,0,"2.%3d,%3d",currentRecNo,cursorLocation);
// wattroff(lists,A_REVERSE);
// wrefresh(lists);
// GetChar(lists,0,0);
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
{
//NODE * temp=get_node_by_index(billList,currentRecNo);
//firstRecPoint=temp->next;
del_link_index(billList,currentRecNo);
//firstRecPoint
}
}
// wattron(lists,A_REVERSE);//反白显示下一行
// mvwprintw(lists,1,0,"%3d,%3d",currentRecNo,cursorLocation);
// wattroff(lists,A_REVERSE);
// wrefresh(lists);
//GetChar(lists,0,0);
// 将lists这个窗口里边的内容清掉
wclear(lists);
//GetChar(lists,0,0);
}
free_list(billList);
scr_restore("save.scr");
getchar();
DestroyWindow(win);
DestroyWindow(lists);
return result;//返回选择的值,如确定就是0,返回就是1
}
//要封函数参数要 LINKList 交易号 员工号 时间 总金额 状态
//sale_state为1是收银,0是挂单,-1为退货
int Save_Sale_Result(LINKLIST * linklist,int trans_id,char *id,char *time,float totalMoney,int sale_state)//state为1是收银,0是挂单,-1为退货
{
char sale_id_str[20]={'\0'};//销售号
char trans_ids_str[10]={'\0'};//存放交易号
sprintf(trans_ids_str,"%d",trans_id);//将交易ID转成字符串
strcpy(sale_id_str,time);//将时间存放到销售号中去
strcat(sale_id_str,trans_ids_str);//再将交易号再加进去
//Message_Box(10,50,10,10,RED_BLACK,"测试",sale_id_str);
InsertIntoSale(sale_id_str,trans_ids_str,id,time,totalMoney,sale_state);//插入到销售表中
NODE * pNode=linklist->head;
while(pNode!=NULL)
{
saleProduct* pSaleProduct=(saleProduct *)pNode->node_data;
char bar_code[10];
char sale_id[20];
char detail_id[20];
int detail_seque=Get_Detail_Seque();
char detail_seque_str[10];
int count=0;
float sale_price;
//int sale_state;
strcpy(bar_code,pSaleProduct->bar_code);//商品条形码
strcpy(sale_id,sale_id_str);//销售ID号
//商品明细编号为 日期加交易号
strcpy(detail_id,time);//将日期给明细字段
sprintf(detail_seque_str,"%d",detail_seque);
strcat(detail_id,detail_seque_str);//将数据库序列产生的编号加进去
count=pSaleProduct->amount;//出售数量
sale_price=pSaleProduct->sale_price;//商品单价
//sale_state=1;//出售商品的状态 出售状态为1
Insert_To_Sale_Detail(detail_id,sale_id,bar_code,count,sale_price,sale_state);
if(sale_state==1)//结帐时候要更新库存
{
ReduceStock(pSaleProduct->bar_code,pSaleProduct->amount);
}
pNode=pNode->next;
}
}
//Pos机的结帐窗口
int CreatePosReckoningWindow()
{
//win=CreateWindow()
char title[]="欢迎光临XXX超市";
int scrY,scrX,strLength,i;
// strLength=strlen(title);
// getmaxyx(stdscr,scrY,scrX);
char time[20]={'\0'};
//画边框
WINDOW * win=CreateWindow(25,80,0,0,Yes,BLACK_WHITE);
//box(stdscr,0,0);
StringCenterPrint(win,0,"欢迎光临XXX超市");
//mvprintw(0,(scrX-strLength)/2,title); //打印标题
char * pName=(char *)malloc(100);
Get_Staff_Name(id,pName);
strcpy(name,pName);
free(pName);
//Trim(name);
mvwprintw(win,1,1,"收银员:%s",name);
mvwprintw(win,1,18,"等级:普通职员");
int trans_id;
trans_id=Get_Trans_Seque();//获得交易号这个号是由数据库的序列产生的
mvwprintw(win,1,35,"交易号: %d",trans_id);
GetSystemTime(time);
mvwprintw(win,1,51,"时间: %s",time);
printhline(win,2,1,78);
mvwprintw(win,3,1,"序号");
mvwprintw(win,3,7,"条形码");
mvwprintw(win,3,17,"商品名称");
mvwprintw(win,3,47,"规格");
mvwprintw(win,3,53,"单位");
mvwprintw(win,3,60,"单价");
mvwprintw(win,3,67,"数量");
mvwprintw(win,3,73,"金额");
printhline(win,4,1,78);
printhline(win,20,1,78);
mvwprintw(win,21,1,"条形码:");
mvwprintw(win,21,50,"销售状态:正常");
printhline(win,22,1,78);
mvwprintw(win,23,1,"F2:新增明细");
mvwprintw(win,23,13,"F3:删除明细");
mvwprintw(win,23,25,"F4:收银");
mvwprintw(win,23,33,"F5:挂单");
mvwprintw(win,23,41,"F6:取单");
mvwprintw(win,23,49,"F7:撤单");
mvwprintw(win,23,57,"F8:退货");
mvwprintw(win,23,65,"F9:退出");
printhline(win,26,1,78);
int ch;
char barcode[20]="CN";//存放输入的条形码
//画输入条形码的反白框
WINDOW * inputBarcode=CreateWindow(1,16,21,9,No,WHITE_BLACK);
mvwprintw(inputBarcode,0,0,"CN");
wrefresh(inputBarcode); //刷新窗口缓冲区
WINDOW * printRecordWin=CreateWindow(15,78,5,1,No,BLACK_WHITE);
int lineCount=15;//每页打印的条数
int cursorLocation=1;
int rollcursorLoaction;
int currentRecNo=1;
LINKLIST * printlist=(LINKLIST *)malloc(sizeof(LINKLIST));
link_init(printlist);
NODE * p=NULL;
NODE * firstRecPoint=NULL;
int count=0;
int number=1;//每页第一条记录的编号
int tempNumber;//每次要打印的
barcode[2]='\0';
start:
while(1)
{
Input_Barcode:
barcode[2]='\0';
ch=GetNumber(inputBarcode,0,2,&barcode[2],6);
//wclear(inputBarcode);
//mvwprintw(inputBarcode,0,0,"CN");
switch(ch)
{
case '\n':
//对输入的条形码进行校验
{
strLength=strlen(barcode);
// mvwprintw(printRecordWin,10,10,"%d",strLength);
// wrefresh(printRecordWin);
if(strLength!=8)
{
Message_Box(8,30,5,20,RED_BLACK,"提示","输入的条形码只能是6个数字");
wclear(inputBarcode);
mvwprintw(inputBarcode,0,0,"CN");
goto Input_Barcode;
}
//判断输入的条开码是否全是数字
for(i=2;i<strLength;i++)
{
if(!isdigit(barcode[i]))
{
Message_Box(8,30,5,20,RED_BLACK,"提示","输入的条形码只能是6个数字");
wclear(inputBarcode);
mvwprintw(inputBarcode,0,0,"CN");
goto Input_Barcode;
}
}
if(strLength==2) //即没有输入条形码
{
//wclear(inputBarcode);
goto Input_Barcode;
}
product * pro=(product *)malloc(sizeof(product));
saleProduct * salepro=(saleProduct *)malloc(sizeof(saleProduct));
int result;
result=Get_ProductInfo_By_Barcode(barcode,pro);
if(result!=0)
{
wclear(inputBarcode);
mvwprintw(inputBarcode,0,0,"CN");
goto Input_Barcode;
}
//mvwprintw(printRecordWin,0,40,"%d",result);
if(result!=0)
{
free(pro);// 释放掉读取出来的商品
goto Input_Barcode;
}
ConverToSaleRec(pro,salepro,1);
free(pro);// 释放掉读取出来的商品
insert_rear_link(printlist,salepro);
//判断是不是只有一条记录
currentRecNo=printlist->count;
if(printlist->count<=lineCount)
{
firstRecPoint=printlist->head;
}
else if(printlist->count>lineCount)
{
firstRecPoint=get_node_by_index(printlist,printlist->count-lineCount+1);
number=printlist->count-lineCount+1;
}
else
{
firstRecPoint=firstRecPoint->next;
number++;//每页记录号
}
p=firstRecPoint;
tempNumber=number;
saleProduct * pSaleProduct;//
wclear(printRecordWin);
while(p!=NULL)
{
//打印记录
pSaleProduct=(saleProduct *)(p->node_data);
if(tempNumber!=printlist->count)
{
mvwprintw(printRecordWin,count,0,"%-6d%-10s%-30s%-6s%-7s%-7.2f%-6d%-6.2f",tempNumber,pSaleProduct->bar_code,pSaleProduct->product_name,pSaleProduct->unit,pSaleProduct->spec,pSaleProduct->sale_price,pSaleProduct->amount,pSaleProduct->money);
}
else
{
wattron(printRecordWin,A_REVERSE);//反白显示上一行
mvwprintw(printRecordWin,count,0,"%-6d%-10s%-30s%-6s%-7s%-7.2f%-6d%-6.2f",tempNumber,pSaleProduct->bar_code,pSaleProduct->product_name,pSaleProduct->unit,pSaleProduct->spec,pSaleProduct->sale_price,pSaleProduct->amount,pSaleProduct->money);
wattroff(printRecordWin,A_REVERSE);
}
tempNumber++;
p=p->next;
count++;//记录当前页有多少条记录
if(count>=lineCount || p==NULL)
{
count=0;
break;
}
}
wclear(inputBarcode);
mvwprintw(inputBarcode,0,0,"CN");
wrefresh(printRecordWin);
// mvwprintw(printRecordWin,10,10,"%d",currentRecNo);
// wrefresh(printRecordWin);
// wgetch(printRecordWin);
if(cursorLocation<lineCount)
{
if(lineCount>printlist->count)
{
cursorLocation=printlist->count;
}
else
{
cursorLocation=lineCount;
}
// else
// {
// cursorLocation=lineCount-1;
// }
}
// mvwprintw(printRecordWin,14,0,"当前光标位置:%d当前记录号:%d",cursorLocation,currentRecNo);
// wrefresh(printRecordWin);
// //saleRecord_reverse(printRecordWin,currentRecNo,currentRecNo,printlist);
// wrefresh(printRecordWin);
//rollcursorLoaction=cursorLocation;//滚动光标位置等于当前位置;
}
break;
case KEY_UP:
{
if(printlist->head==NULL)
{
break;
}
wclear(printRecordWin);
saleProduct * pSaleProduct;
if(cursorLocation==1)
{
if(firstRecPoint->prior!=NULL)
{
firstRecPoint=firstRecPoint->prior;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -