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

📄 front.c

📁 linux平台下用C开发的一个超市管理系统(结合了ORACLE数据库)
💻 C
📖 第 1 页 / 共 2 页
字号:
***********************************************************************/
int cash_money(C_CLASS LINKLIST *link)
{
	scr_dump("front.scr");
	SALE sale;
	DETAIL detail;
	float total_money=0.0,real_money,change_money;
	double mon;
	char money[13]="",sale_detailID[5]="";
	int i,res,k=1,j;	
	NODE *p=link->head->next;	
	WIN mainatt1={13,40,7,20,4,"结帐",1};
	TEXT box1={9,35,13,1,""};
    TEXT box2={11,35,13,1,""};
	TEXT box3={9,30,5,4,"应收:"};
	TEXT box4={11,30,5,4,"实收:"};
	TEXT box5={13,30,5,4,"找零:"};
	TEXT box6={13,35,13,1,""};    
	BUTTON but1={8,3,15,29,"确定",4,4};
	BUTTON but2={8,3,15,40,"返回",4,4};	
	if(link->count==0)
	{
		return 1;
	}
	for(i=1;i<=link->count;i++)
	{
		total_money+=(((GOD *)p->data)->sale_price)*(((GOD *)p->data)->num)*(((GOD *)p->data)->discount);
		p=p->next;
	}	
	WIN *w1=make_win(&mainatt1);
	TEXT *t1=make_textbox(&box1);
	TEXT *t2=make_textbox(&box2);
	TEXT *t3=make_textbox(&box3);
	TEXT *t4=make_textbox(&box4);
	TEXT *t5=make_textbox(&box5);
	TEXT *t6=make_textbox(&box6);	
	BUTTON *b1=make_button(&but1);
	BUTTON *b2=make_button(&but2);
	wprintw(t1->win,"%.2f",total_money);
	w1->show_win(w1);	
	t1->show_text(t1);
	t2->show_text(t2);
	t3->show_text(t3);
	t4->show_text(t4);
	t5->show_text(t5);
	t6->show_text(t6);
	b1->show_button(b1);
	b2->show_button(b2);	
	do
	{
		if(k==1)
		{			
			
			werase(t2->win);
			wrefresh(t2->win);
			werase(t6->win);
			wrefresh(t6->win);
			res=GetString(t2->win,money,12,1);
			if(res==0||res==2||res==13)
			{				
				k=2;				
			}
			if(res==14)
			{
				scr_restore("front.scr");
				return 1;//取消
			}
			continue;
			
		}
		if(k==2)
		{
			if(strlen(money)==0)
			{
				show_msg("实际金额不能为空",0);
				k=1;
				continue;
			}
			j=check_float(money);
			if(j==1)
			{
				show_msg("金额只能是数字或小数点",0);
				money[0]='\0';
				k=1;
				continue;
			}
			if(j==2)
			{
				show_msg("金额格式不正确",0);
				money[0]='\0';
				k=1;
				continue;
			}
			if(j==3)
			{
				show_msg("金额不能大于2位小数",0);
				money[0]='\0';
				k=1;
				continue;
			}
			real_money=atof(money);
			if(real_money<total_money)
			{
				show_msg("实际金额不能小于应付金额",0);
				money[0]='\0';
				k=1;
				continue;
			}
			change_money=real_money-total_money;
			wprintw(t6->win,"%.2f",change_money);
			wrefresh(t6->win);
			res=run_button(b1,b2,0);
			if(res==3)
			{
				money[0]='\0';
				k=1;
				continue;
			}
			if(res==2)
			{
				scr_restore("front.scr");
				return 1;//取消
			}
			if(res==1)
			{
				scr_restore("front.scr");				
				//插入数据库中销售表,状态设为0
				strcpy(sale.sale_id,s_time);
				strcat(sale.sale_id,sale_id);
				strcpy(sale.trans_id,sale_id);
				strcpy(sale.staff_id,login.staff_id);
				strcpy(sale.sale_date,s_time);
				sale.give_sum=real_money;
				sale.real_sum=total_money;
				sale.sale_money=total_money;
				sale.change=real_money - total_money;
				sale.sale_state=0;
				Insert_Sale(&sale); 
				//插入数据库中销售明细表,状态设为0
				p=link->head->next;
				strcpy(detail.sale_id,sale.sale_id);
				for(i=1;i<=link->count;i++)
				{
					get_sale_detailID(sale_detailID);
					strcpy(detail.detail_id,s_time);
					strcat(detail.detail_id,sale_detailID);
					strcpy(detail.goods_id,((GOD *)p->data)->bar_code);
					detail.num=((GOD *)p->data)->num;
					detail.sale_price=((GOD *)p->data)->sale_price*((GOD *)p->data)->discount;
					detail.sale_state=0;
					Insert_Sale_Detail(&detail);
					sale_goods(detail.goods_id,detail.num);
					p=p->next;
				}
				return 0;//确定
			}
		}
	}while(1);
}
/**********************************************************************
功能:挂单
参数:链表 
返回值:0成功 非0失败
***********************************************************************/
int  hang_list(C_CLASS LINKLIST *link)
{
	int res,i;
	SALE sale;
	DETAIL detail;
	char sale_detailID[5]="";
	float total_money=0.0;
	NODE *p=link->head->next;
	res=show_msg("请确认是否将此单据挂起",1);
	if(res==0)//确定
	{
		for(i=1;i<=link->count;i++)
		{
			total_money+=(((GOD *)p->data)->sale_price)*(((GOD *)p->data)->num)*(((GOD *)p->data)->discount);
			p=p->next;
		}				
		//插入数据库中销售表,状态设为1
		strcpy(sale.sale_id,s_time);
		strcat(sale.sale_id,sale_id);
		strcpy(sale.trans_id,sale_id);
		strcpy(sale.staff_id,login.staff_id);
		strcpy(sale.sale_date,s_time);
		sale.give_sum=0;
		sale.real_sum=total_money;
		sale.sale_money=total_money;
		sale.change=0;
		sale.sale_state=1;
		Insert_Sale(&sale);	
		//插入数据库中销售明细表,状态设为1		
		p=link->head->next;
		strcpy(detail.sale_id,sale.sale_id);
		for(i=1;i<=link->count;i++)
		{
			get_sale_detailID(sale_detailID);
			strcpy(detail.detail_id,s_time);
			strcat(detail.detail_id,sale_detailID);
			strcpy(detail.goods_id,((GOD *)p->data)->bar_code);
			detail.num=((GOD *)p->data)->num;
			detail.sale_price=((GOD *)p->data)->sale_price*((GOD *)p->data)->discount;
			detail.sale_state=1;
			Insert_Sale_Detail(&detail);			
			p=p->next;
		}
		return 0;//确定

	}
	else
	{
		return 1;//取消
		
	}
}
/**********************************************************************
功能:取单 
参数:链表 
返回值:1成功 0失败
***********************************************************************/
int get_list(C_CLASS LINKLIST *link)
{
	scr_dump("front.scr");
	NODE *p;
	WIN mainatt1={13,40,7,20,4,"取单",1};
	WIN *w1=make_win(&mainatt1);	
	w1->show_win(w1);	
	p=print_list(w1->win);
	if(p==NULL)
	{
		scr_restore("front.scr");
		return 0;//取消
	}
	getgoods_by_saleID(link,((SALE *)p->data)->sale_id);
	Delete_sales_detail(((SALE *)p->data)->sale_id);
	Delete_sale(((SALE *)p->data)->sale_id);
	scr_restore("front.scr");
	return 1;
}
/**********************************************************************
功能:撤单 
参数:链表 
返回值:0成功 非0失败
***********************************************************************/
int delete_list(C_CLASS LINKLIST *link)
{
	int res;
	res=show_msg("请确认撤销此单据",1);
	if(res==0)
	{
		return 0;//确定
	}
	else
	{
		return 1;//取消
	}
}
/**********************************************************************
功能:退货
参数:链表 
返回值:1成功 0失败
***********************************************************************/
int back_products(C_CLASS LINKLIST *link)
{
	int res,k=1,i=0;
	char sale_id[19]="",bar_code[9]="",str[7]="",num[3]="",msg[30]="";
	float money;
	DETAIL temp;
	WIN mainatt1={13,40,7,20,4,"退货",1};
	TEXT box1={9,35,18,1,""};
    TEXT box2={11,37,16,1,""};
	TEXT box3={9,26,9,4,"销售单号:"};
	TEXT box4={11,28,7,4,"条形码:"};
	TEXT box5={13,30,5,4,"数量:"};
	TEXT box6={13,35,18,1,""};
	TEXT box7={11,35,2,1,"CN"};
	BUTTON but1={8,3,15,29,"确定",4,4};
	BUTTON but2={8,3,15,44,"返回",4,4};
	scr_dump("front.scr");
	if(show_login(2)==-1)
	{
		scr_restore("front.scr");
		return 0;
	}
	else
	{
		WIN *w1=make_win(&mainatt1);
		TEXT *t1=make_textbox(&box1);
		TEXT *t2=make_textbox(&box2);
		TEXT *t3=make_textbox(&box3);
		TEXT *t4=make_textbox(&box4);
		TEXT *t5=make_textbox(&box5);
		TEXT *t6=make_textbox(&box6);
		TEXT *t7=make_textbox(&box7);
		BUTTON *b1=make_button(&but1);
		BUTTON *b2=make_button(&but2);
		w1->show_win(w1);	
		t1->show_text(t1);
		t2->show_text(t2);
		t3->show_text(t3);
		t4->show_text(t4);
		t5->show_text(t5);
		t6->show_text(t6);
		t7->show_text(t7);
		b1->show_button(b1);
		b2->show_button(b2);
		while(1)
		{
			if(k==1)
			{
				res=GetString(t1->win,sale_id,18,1);
				if(res==2||res==13||res==0)
				{
					k++;
					continue;
				}
				else
				{
					continue;
				}
			}
			if(k==2)
			{
				res=GetString(t2->win,str,6,1);
				if(res==2||res==13||res==0)
				{
					bar_code[0]='C';
					bar_code[1]='N';
					bar_code[2]='\0';
					strcat(bar_code,str);					
					k++;
					continue;
				}
				if(res==1)
				{
					k--;
					continue;
				}
				else
				{
					continue;
				}
			}
			if(k==3)
			{
				res=GetString(t6->win,num,2,1);
				if(res==2||res==13||res==0)
				{
					k++;
					continue;
				}
				if(res==1)
				{
					k--;
					continue;
				}
				else
				{
					continue;
				}
			}
			if(k==4)
			{
				res=run_button(b1,b2,0);
				if(res==3)
				{
					k--;
					continue;
				}
				if(res==2)
				{
					scr_restore("front.scr");
					return -1;
				}
				if(res==1)
				{
					if(check_saleID(sale_id)!=0)
					{
						show_msg("此交易单号不存在",0);
						sale_id[0]='\0';
						werase(t1->win);
						wrefresh(t1->win);
						k=1;
						continue;
					}					
					if(check_barCode(&temp,sale_id,bar_code)!=0)
					{
						show_msg("此条形码在该交易中不存在",0);
						str[0]='\0';
						werase(t2->win);
						wrefresh(t2->win);
						k=2;
						continue;
					}
					i=1;
					if(temp.num<atoi(num))
					{
						show_msg("退货数量大于售出数量",0);
						num[0]='\0';
						werase(t6->win);
						wrefresh(t6->win);
						k=3;
						continue;
					}
					money=temp.sale_price*atoi(num);
					sprintf(msg,"%s%.2f","退钱:",money);
					show_msg(msg,0);
					change_sale(sale_id, money);//更新销售
					change_sale_detail(sale_id,bar_code,atoi(num));//更新销售明细
					back_goods(bar_code,atoi(num));//更新库存
					scr_restore("front.scr");
					return 1;
					
				}
			}
		}

	}

}
/**********************************************************************
功能:打印挂单号 
参数:窗口指针
返回值:选中单号的节点指针
***********************************************************************/
NODE * print_list(WINDOW *win)
{
	NODE *p,*cur;			
	p=hang.head->next;
	cur=p;
	int i,ch;
	mvwprintw(win,2,4,"%-6s%-16s","序号","销售单号");
	mvwhline(win,3,3,ACS_HLINE,26);
	mvwprintw(win,11,4,"%s","上下键选择 回车取单 ESC返回");
	while(1)
	{	
		int k=1,m=4;
		p=hang.head->next;
		for(i=1;p&&i<=hang.count;i++)
		{
			if(p==cur)
			{
				wattron(win,A_BLINK|COLOR_PAIR(7));
				mvwprintw(win,m,4,"%-6d%-16s",k,((SALE *)p->data)->sale_id);
				wattroff(win,A_BLINK|COLOR_PAIR(7));
			}
			else
			{
				mvwprintw(win,m,4,"%-6d%-16s",k,((SALE *)p->data)->sale_id);
			}
			p=p->next;
			m++;
			k++;
		}
		wrefresh(win);
		noecho();
		cbreak();					
		keypad(win,true );
		ch=wgetch(win);
		if(ch==259)
		{
			if(cur=hang.head->next)
			{
				continue;
			}
			else
			{
				cur=cur->prior;
				continue;
			}
		}
		if(ch==258)
		{
			if(cur->next)
			{
				cur=cur->next;				
			}
			continue;
		}
		if(ch==10)
		{
			return cur;
		}
		if(ch==27)
		{
			return NULL;
		}
	}
}






⌨️ 快捷键说明

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