⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loginwindow.c

📁 福建博洋教育C/C++软件项目实战:POS收银系统
💻 C
📖 第 1 页 / 共 5 页
字号:
	int cnt=0;
	int res=0;	
	PRODUCT *pro_info=(PRODUCT *)malloc(sizeof(PRODUCT));
	WINDOW *barcode,*num;
	WINDOW *dialog[3]={NULL};	
	print_dialog_box(10,40,"退货商品",1,dialog);
	mvwprintw(dialog[0],2,2,"商品条形码:");
	mvwprintw(dialog[0],4,8,"数量:");
	wrefresh(dialog[0]);
	keypad(dialog[1],TRUE);
	keypad(dialog[2],TRUE);
	//打印商品条形码窗口
	barcode=create_win(1,16,9,34);
	keypad(barcode,TRUE);
	wbkgd(barcode,COLOR_PAIR(4));
	wprintw(barcode,bar_code);
	wrefresh(barcode);
	//打印退货数量窗口
	num=create_win(1,16,11,34);
	keypad(num,TRUE);
	wbkgd(num,COLOR_PAIR(4));
	wrefresh(num);
	scr_dump("tuihuo.scr");
	BARCODE:
		wmove(barcode,0,0);
		wprintw(barcode,bar_code);
		wrefresh(barcode);		
		while (1)
		{
			ch=wgetch(barcode);
			switch (ch)
			{
			case  KEY_BACKSPACE:  //按退格键盘
				if (cnt1>2)
				{
					getyx(barcode,now_col1,now_row1);
					mvwaddch(barcode,now_col1,--now_row1,' ');				
					bar_code[--cnt1]='\0';
					wmove(barcode,0,now_row1);
					wrefresh(barcode);
				}				
				break;
			case KEY_F(1):			
				return;				
			case KEY_DOWN:
			case '\n':
				goto NUMBER;
			default:			
				if ( (ch>='0'&&ch<='9') && cnt1<8 )
				{
					now_row1++;
					waddch(barcode,ch);
					bar_code[cnt1]=ch;
					bar_code[++cnt1]='\0';
					wrefresh(barcode);				
					break;
				}	
			}
		}
	NUMBER:
		wmove(num,0,0);			
		while (1)
		{
			ch=wgetch(num);
			switch (ch)
			{
			case  KEY_BACKSPACE:  //按退格键盘
				if (cnt)
				{
					getyx(num,now_col,now_row);
					mvwaddch(num,now_col,--now_row,' ');				
					numberStr[--cnt]='\0';
					wmove(num,0,now_row);
					wrefresh(num);
				}				
				break;
			case KEY_F(1):			
				return;
			case KEY_UP:
				goto BARCODE;								
			case KEY_DOWN:
			case '\n':
				goto ENSURE;
			default:		
				if ( cnt<5 && (ch>='1'&&ch<='9') || (ch=='0'&&cnt!=0))
				{
					now_row++;
					waddch(num,ch);
					numberStr[cnt]=ch;
					numberStr[++cnt]='\0';
					wrefresh(num);				
					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;
			case KEY_UP:
				wattroff(dialog[1],A_REVERSE);
				mvwprintw(dialog[1],1,2, "确定");
				wrefresh(dialog[1]);					
				goto NUMBER;
			case KEY_RIGHT:
				wattroff(dialog[1],A_REVERSE);
				mvwprintw(dialog[1],1,2, "确定");
				wrefresh(dialog[1]);			
				goto CANCEL;
			case '\n':	
				//首先要判断输入的条形码是否存在,然后判断输入的数量是否超过原购买数量
				if (cnt==0)
				{
					Message("请输入数量",8,36);
					touchwin(dialog[0]);				
					wrefresh(dialog[0]);
					touchwin(dialog[1]);
					wrefresh(dialog[1]);
					touchwin(dialog[2]);
					wrefresh(dialog[2]);				
					touchwin(barcode);
					wrefresh(barcode);
					touchwin(num);
					wrefresh(num);					
					goto NUMBER;
				}
				strcpy(pro_info->bar_code,bar_code);
				res=code_in_saleid(sale_id,pro_info);
				if (res==-1)
				{
					Message("数据库出错",10,40);
					endwin();
					exit(1);					
				}
				if (res==0)
				{
					Message("没有购买此商品",10,40);
					now_col=0;
					now_row=0;
					bar_code[2]='\0';
					numberStr[0]='\0';
					number=0;
					cnt1=2;
					now_col1=0;
					now_row1=2;
					cnt=0;
					scr_restore("tuihuo.scr");	
					goto BARCODE;
				}
				if (pro_info->count==0)
				{
					Message("此单中这种商品已经退光",10,40);
					now_col=0;
					now_row=0;
					bar_code[2]='\0';
					numberStr[0]='\0';
					number=0;
					cnt1=2;
					now_col1=0;
					now_row1=2;
					cnt=0;
					scr_restore("tuihuo.scr");	
					goto BARCODE;
				}
				//判断输入数量是否超过原购买数量				
				number=atoi(numberStr);
				if (number>pro_info->count)
				{
					Message("输入数量大于原购买数量",10,40);
					now_col=0;
					now_row=0;
					bar_code[2]='\0';
					numberStr[0]='\0';
					number=0;
					cnt1=2;
					now_col1=0;
					now_row1=2;
					cnt=0;
					scr_restore("tuihuo.scr");	
					goto BARCODE;
				}
				//插入链表				
				res=get_product_info(pro_info);	
				if (res==-1)
				{
					Message("数据库出错",10,40);
					endwin();
					exit(1);
				}				
				if (res==0)
				{					
					Message("没有这种商品",10,40);
					now_col=0;
					now_row=0;
					bar_code[2]='\0';
					numberStr[0]='\0';
					number=0;
					cnt1=2;
					now_col1=0;
					now_row1=2;
					cnt=0;
					scr_restore("tuihuo.scr");				
					goto BARCODE;
				}					
				//先判断商品条形码是否输入过;
				res=code_in_list(bar_code);
				if ( res )
				{				
					NODE *n = salelist.get_node_by_index(&salelist,res);
					PRODUCT *pro = (PRODUCT *)malloc(sizeof(PRODUCT));
					pro = (PRODUCT *)n->data;
					pro->count = number;
					salelist.replace_node_by_index(&salelist,res,pro,sizeof(PRODUCT));					
					return res;
				}
				else
				{
					Trim(pro_info->product_name);
					Trim(pro_info->spec);
					Trim(pro_info->unit);	
					pro_info->count = number;				
					salelist.insert_rear(&salelist,(void *)pro_info,sizeof(PRODUCT));				
					return salelist.count;
				}	
			}			
		}
	CANCEL:	
		wattron(dialog[2],A_REVERSE);
		mvwprintw(dialog[2],1,2, "取消");		
		wrefresh(dialog[2]);
		  
		while (1)
		{
			ch=wgetch(dialog[2]);
			switch (ch)
			{
			case KEY_F(1):			
				return;
			case KEY_LEFT:		
				wattroff(dialog[2],A_REVERSE);
				mvwprintw(dialog[2],1,2, "取消");
				wrefresh(dialog[2]);
				goto ENSURE;		
			case '\n':	
				return;						
			}
		}
}

/*==============================================================================
function:F4退货功能主要实现
================================================================================*/
int return_ware_win(SALE *sale_info,SALE_ID *update_id)
{
	if (!salelist.count)
	{
		Message("没有退货记录",10,40);
		return 0;
	}
	int ch;
	int now_col1=0,now_row1=0;
	int now_col2=0,now_row2=0;
	char secondStr[9] = {'\0'};
	char thirdStr[9] = {'\0'};
	float cashReceive = -real_cash();//购买商品的总价格
	float cashTotal = 0;//实际付款数
	float cashGive = 0;//找零
	int cnt1=0;
	int cnt2=0;
	int radixPoint=0;
	NODE* n=NULL;	
	int i=0;
	int j=0;
	int res=0;
	WINDOW *real,*given,*change;
	WINDOW *dialog[3]={NULL};	
	print_dialog_box(12,40,"退货",1,dialog);
	mvwprintw(dialog[0],2,8,"应收:");
	mvwprintw(dialog[0],4,8,"实收:");
	mvwprintw(dialog[0],6,8,"找零:");
	wrefresh(dialog[0]);
	keypad(dialog[1],TRUE);
	keypad(dialog[2],TRUE);
	real=create_win(1,16,8,34);
	keypad(real,TRUE);
	wbkgd(real,COLOR_PAIR(4));
	wprintw(real,"%.2f",cashReceive);
	wrefresh(real);
	given=create_win(1,16,10,34);
	keypad(given,TRUE);
	wbkgd(given,COLOR_PAIR(4));
	wrefresh(given);
	change=create_win(1,16,12,34);
	keypad(change,TRUE);
	wbkgd(change,COLOR_PAIR(4));
	wrefresh(change);	
	scr_dump("returnware.scr");
	MONEY:
		wmove(given,0,0);
		wprintw(given,secondStr);
		wrefresh(given);		
		while (1)
		{
			ch=wgetch(given);
			switch (ch)
			{
			case  KEY_BACKSPACE:  //按退格键盘
				if (cnt1)
				{
					if (secondStr[cnt1-1]=='.')
					{
						radixPoint--;
					}	
					getyx(given,now_col1,now_row1);
					mvwaddch(given,now_col1,--now_row1,' ');		
					secondStr[--cnt1]='\0';
					wmove(given,0,now_row1);
					wrefresh(given);
				}
				break;
			case KEY_F(1):			
				return;			
			case KEY_DOWN:
				goto ENSURE;
			case '\n':
				//字符串转float并做判断
				cashTotal=atof(secondStr);					
				cashGive=cashTotal-cashReceive;
				wprintw(change,"%.2f",cashGive);
				wrefresh(change);
				goto ENSURE;
			default:				
				if ( (ch>='0'&&ch<='9') || (ch=='.'&&radixPoint==0) && (cnt1<12) )
				{				
					if (ch=='.')
					{
						radixPoint++;
					}	
					now_row1++;
					waddch(given,ch);								
					secondStr[cnt1]=ch;
					secondStr[++cnt1]='\0';
					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;
			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':				
				sale_info->given_sum=cashReceive;
				sale_info->real_sum=cashTotal;
				sale_info->change=cashGive;
				sale_info->sale_money=cashReceive;
				sale_info->sale_state=1;//1代表退货
				res=insert_sale(sale_info);
				if (res==-1)
				{
					Message("数据库出错",10,40);
					endwin();
					exit(1);
				}	
				if (res==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));			
				link_init(&update_salelist);
				//修改原销售表
				res=update_sale(sale_info,update_id);
				if (res==-1)
				{
					Message("数据库出错",10,40);
					endwin();
					exit(1);
				}	
				if (res==0)
				{
					Message("更新销售信息的时候出错",10,40);
					endwin();
					exit(1);
				}
				//获得原销售明细
				res=get_saledetail_saleid(update_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++)
				{
					//数据库修改加库存			
					n=salelist.get_node_by_index(&salelist,i);	
					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);
					}		
					//消费明细表添加					
					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);
					}	
					SALE_DETAIL *update_sale_detail=(SALE_DETAIL *)malloc(sizeof(SALE_DETAIL));
					for ( j=1; j<=update_salelist.count; j++)
					{
						NODE *updatenode=update_salelist.get_node_by_index(&update_salelist,j);						
						update_sale_detail=(SALE_DETAIL *)updatenode->data;
						if ( strcmp(update_sale_detail->bar_code,sale_detail->bar_code)==0 )
						{
							update_sale_detail->count=sale_detail->count;
							res=update_salelist.replace_node_by_index(&update_salelist,j,update_sale_detail,sizeof(SALE_DETAIL));							
							if (res==0)
							{
								Message("获取数量的时候出错",10,40);
								endwin();
								exit(1);
							}	
							break;
						}					
					}
				}
				salelist.clear_link(&salelist);			
				SALE_DETAIL *update_sale_detail=(SALE_DETAIL *)malloc(sizeof(SALE_DETAIL));
				for ( i=1; i<=update_salelist.count; i++)
				{
					n=update_salelist.get_node_by_index(&update_salelist,i);						
					update_sale_detail=(SALE_DETAIL *)n->data;
					res=update_saledetail(update_sale_detail);
					if (res==-1)
					{
						Message("数据库出错",10,40);
						endwin();
						exit(1);
					}
					if (res==0)
					{
						Message("更新销售明细的时候出错",10,40);
						endwin();
						exit(1);
					}
				}
				update_salelist.clear_link(&update_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_F(1):			
				return;
			case KEY_LEFT:		
				wattroff(dialog[2],A_REVERSE);
				mvwprintw(dialog[2],1,2, "取消");
				wrefresh(dialog[2]);
				goto ENSURE;		
			case '\n':
				return 0;						
			}
		}
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -