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

📄 back.c

📁 linux平台下用C开发的一个超市管理系统(结合了ORACLE数据库)
💻 C
📖 第 1 页 / 共 2 页
字号:
#include"back.h"
#include"db.h"
#include"window.h"
#include"public.h"

/************************************************************************************
函数功能:打印菜单    参数:窗体 指针 菜单数 坐标 
返回值:选中菜单的值
*************************************************************************************/
int show_menu(WINDOW * win,char *memu[],int num,int y,int x)
{
		
		int i,key,cur=0;		
		for(i=0;i<num;i++)
		{
			mvwprintw(win,i+7,30,"%s",memu[i]);
		}
		wattron(win,A_BLINK|COLOR_PAIR(7));
		mvwprintw(win,y+cur,x,"%s",memu[cur]);
		wattroff(win,A_BLINK|COLOR_PAIR(7));
		wrefresh(win);
		endwin();
		do
		{
			   noecho();
			   cbreak();					
			   keypad(win,true );
			   key=wgetch(win);
				if(key==10)//CR
				{
						return cur;
				}
				else if(key==259) //UP
				{
						if(cur==0)
								continue;
						else
						{
							mvwprintw(win,y+cur,x,"%s",memu[cur]);						
							wattron(win,A_BLINK|COLOR_PAIR(7));
							cur=cur-2;
							mvwprintw(win,y+cur,x,"%s",memu[cur]);
							wattroff(win,A_BLINK|COLOR_PAIR(7));
							wrefresh(win);
						}
				}
				else if(key==258) //down 
				{
						if(cur==num-1)
								continue;
						else
						{
							mvwprintw(win,y+cur,x,"%s",memu[cur]);						
							wattron(win,A_BLINK|COLOR_PAIR(7));
							cur=cur+2;
							mvwprintw(win,y+cur,x,"%s",memu[cur]);
							wattroff(win,A_BLINK|COLOR_PAIR(7));
							wrefresh(win);
						}
				}
		}while(1);
}
/************************************************************************************
函数功能:后台主菜单    参数:无 
返回值:无 
*************************************************************************************/
void show_back()
{
	init_color_info();	
	refresh();		
	int res;	
	WIN backwin={25,80,0,0,2,"后台管理窗口",1};
	char *memu[7]={"1.商品管理","","2.帐户管理","","3.销售记录管理","","0.返回登录界面"};	
	while(1)
	{		
		WIN *w0=make_win(&backwin);
		w0->show_win(w0);
		res=show_menu(w0->win,memu,7,7,30);
		if(res==0)
		{			
			goods_manage();
					
		}
		if(res==2)
		{
			account_manage();
		}
		if(res==4)
		{
			 sale_manage();
		}
		if(res==6)
		{
			return;
		}

	}
	
}
/************************************************************************************
函数功能:商品管理    参数:无 
返回值:无  
*************************************************************************************/
void goods_manage()
{

	WIN backwin={25,80,0,0,2,"商品管理窗口",1};
	char *memu[9]={"1.查询商品","","2.添加商品","","3.修改商品","","4.删除商品","","0.返回后台管理界面"};	
	int res;	
	while(1)
	{
		WIN *w0=make_win(&backwin);
		w0->show_win(w0);
		res=show_menu(w0->win,memu,9,7,30);
		if(res==8)
		{
			w0->free_win(w0);
			touchwin(stdscr);
			refresh();
			return;
		}
		if(res==0)
		{
			C_CLASS LINKLIST list;
			link_init(&list);
			get_all_goods(&list);
			if(list.count==0)
			{
				show_msg("没有查到相应的记录",0);
				continue;
			}
			print_search(&list,1);
			link_clear(&list);
		}
		if(res==2)
		{
			operator_goods(1);
		}
		if(res==4)
		{
			operator_goods(2);
		}
		if(res==6)
		{
			operator_goods(3);
		}

	}
}
/************************************************************************************
函数功能:账户管理    参数:无 
返回值:无  
*************************************************************************************/
void account_manage()
{

	WIN accwin={25,80,0,0,2,"帐户管理窗口",1};
	char *memu[9]={"1.查询帐户","","2.添加帐户","","3.修改帐户","","4.删除帐户","","0.返回后台管理界面"};	
	int res;		
	while(1)
	{
		WIN *w0=make_win(&accwin);
		w0->show_win(w0);
		res=show_menu(w0->win,memu,9,7,30);
		if(res==0)
		{
			C_CLASS LINKLIST list;
			link_init(&list);
			get_all_accounts(&list);
			if(list.count==0)
			{
				show_msg("没有查到相应的记录",0);
				continue;
			}
			print_search(&list,2);
			link_clear(&list);
		}
		if(res==2)
		{
			operator_account(1);
		}
		if(res==4)
		{
			operator_account(2);
		}
		if(res==6)
		{
			operator_account(3);
		}
		if(res==8)
		{
			w0->free_win(w0);
			touchwin(stdscr);
			refresh();
			return;
		}
	}
}
/************************************************************************************
函数功能:销售管理    参数:无 
返回值:无  
*************************************************************************************/
void sale_manage()
{
	WIN salewin={25,80,0,0,2,"帐户管理窗口",1};
	char *memu[5]={"1.按销售日期查询","","2.按员工ID查询","","0.返回后台管理界面"};
	
	int res;
		
	while(1)
	{
		WIN *w0=make_win(&salewin);
		w0->show_win(w0);
		res=show_menu(w0->win,memu,5,7,30);
		if(res==4)
		{
			w0->free_win(w0);
			touchwin(stdscr);
			refresh();
			return;
		}
		if(res==2)
		{
			search_by_ID();
		}
		if(res==0)
		{
			search_by_date();
		}
	}
}
/************************************************************************************
函数功能:打印查询    参数:指针 模式 1-商品 2-账户 3-销售 
返回值:无  
*************************************************************************************/
void print_search(C_CLASS LINKLIST *link,int type)
{
	char str[4]="";
	int res,i=1,j,cur_page=1,total_page;
	WIN mianwin1={25,80,0,0,8,"商品信息查询",1};	
	WIN mianwin2={15,78,5,1,1,"",0};
	WIN mianwin3={25,80,0,0,8,"账户信息查询",1};
	WIN mianwin4={25,80,0,0,8,"销售信息查询",1};
	WIN *w1;
	if(type==1)
	{
		w1=make_win(&mianwin1);
		mvwprintw(w1->win,3,1,"%-5s%-9s%-20s%-7s%-7s%-9s%-9s%-6s%5s","序号","条形码","商品名称","规格","单位","销售价格","进货价格","数量","折扣");
		
	}
	if(type==2)
	{
		w1=make_win(&mianwin3);
		mvwprintw(w1->win,3,1,"%-6s%-9s%-18s%-15s%-20s%8s","序号","帐户ID","帐户名","帐户密码","备注","帐户类型");

	}
	if(type==3)
	{	
		w1=make_win(&mianwin4);
		mvwprintw(w1->win,3,1,"%-6s%-22s%-8s%-10s%-12s%-6s%10s","序号","销售ID","交易号","员工ID","销售日期","类型","销售金额");
	}

	WIN *w2=make_win(&mianwin2);
	TEXT text1={23,19,4,1,""};
	TEXT text2={23,41,5,1,""};
	TEXT *t1=make_textbox(&text1);
	TEXT *t2=make_textbox(&text2);
	draw_line(w1->win,2,80);
	draw_line(w1->win,4,80);
	draw_line(w1->win,20,80);	
	mvwprintw(w1->win,21,4,"%-19s%-21s%-17s%-18s","上一页(PageUp)","下一页(PageDown)","第一页(Home)","最后一页(End)");
	mvwprintw(w1->win,23,11,"%-12s%-13s%-10s%18s","跳转到第","页","页码:","退出(Esc)");
	w1->show_win(w1);
	w2->show_win(w2);
	t1->show_text(t1);
	t2->show_text(t2);
	if(link->count%15==0)
	{
		total_page=link->count/15;
	}
	else
	{
		total_page=link->count/15+1;
	}
	NODE *start,*cur;
	start=link->head->next;
	cur=start;
	do
	{
		werase(t2->win);
		wprintw(t2->win,"%d/%d",cur_page,total_page);
		wrefresh(t2->win);
		Print_Data(w2->win,link,start,cur,type);
		werase(t1->win);
		wrefresh(t1->win);
		res=GetString(t1->win,str,3,1);
		if(res==11)//下一页
		{
			if((i+14)>=link->count)
			{
				show_msg("当前是最后一页",0);				
			}
			else
			{
				i=i+15;
				start=link_get_node_by_index(link,i);
				cur=start;
				cur_page++;
			}
			continue;
		}
		if(res==12)//上一页
		{
			if(i==1)
			{
				show_msg("当前是第一页",0);
			}
			else
			{
				i=i-15;
				start=link_get_node_by_index(link,i);
				cur=start;
				cur_page--;
			}
			continue;
		}
		if(res==15)//Home
		{
			i=1;
			start=link->head->next;
			cur=start;
			cur_page=1;
			continue;
		}
		if(res==16)//End
		{
			i=(total_page-1)*15+1;
			start=link_get_node_by_index(link,i);
			cur=start;
			cur_page=total_page;
			continue;
		}
		if(res==2)//下
		{
			j=link->get_index_by_key(link,cur->data,(int (*)(void *,void *))Goods_Compare );
			if(j<i+14&&j<link->count)
			{
				cur=cur->next;
			}
			continue;
		}
		if(res==1)//上
		{
			j=link->get_index_by_key(link,cur->data,(int (*)(void *,void *))Goods_Compare );
			if(j>i)
			{
				cur=cur->prior;
			}
			continue;
		}
		if(res==0)//跳转
		{
			if(atoi(str)<=total_page)
			{
				if(atoi(str)>1)
				{
					i=(atoi(str)-1)*15+1;
					start=link_get_node_by_index(link,i);
				}
				else
				{
					start=link->head;
				}
				cur=start;
				cur_page=atoi(str);				
			}
			else
			{
				show_msg("输入的页数超过总页数",0);
				
			}
			str[0]='\0';
			continue;
		}
		if(res==14)
		{
			w1->free_win(w1);
			w2->free_win(w2);
			t1->free_text(t1);
			t2->free_text(t2);
			touchwin(stdscr);
			refresh();
			return;
		}
	}
	while (1);
}
/************************************************************************************
函数功能:操作账户    参数:模式  1 添加,2修改,3删除
返回值:无  
*************************************************************************************/
void operator_account(int type)// 1 添加,2修改,3删除
{
	WIN mianwin[3]={{25,80,0,0,8,"添加帐户",1},{25,80,0,0,8,"修改帐户",1},{25,80,0,0,8,"删除帐户",1}};
	STAFFS temp;
	char staff_id[7]="",staff_name[16]="",staff_pwd[17]="",remark[31]="",staff_type[2]="";	
	int  t_type,res,k=1;	
	TEXT text[5]={{6,32,25,1,""},{8,32,25,1,""},{10,32,25,1,""},{12,32,25,1,""},{14,32,25,1,""}};
	BUTTON but1={8,3,17,25,"确定",8,4};
	BUTTON but2={8,3,17,48,"退出",8,4};
	WIN *w1;
	if(type==1)
	{
		w1=make_win(&mianwin[0]);
	}
	if(type==2)
	{
		w1=make_win(&mianwin[1]);
	}
	if(type==3)
	{
		w1=make_win(&mianwin[2]);
	}
	mvwprintw(w1->win,6,24,"帐户ID:");
	mvwprintw(w1->win,8,24,"用户名:");
	mvwprintw(w1->win,10,26,"密码:");
	mvwprintw(w1->win,12,26,"身份:");
	mvwprintw(w1->win,14,26,"备注:");
	TEXT *t0=make_textbox(&text[0]);
	TEXT *t1=make_textbox(&text[1]);
	TEXT *t2=make_textbox(&text[2]);
	TEXT *t3=make_textbox(&text[3]);
	TEXT *t4=make_textbox(&text[4]);	
	BUTTON *b1=make_button(&but1);
	BUTTON *b2=make_button(&but2);
	if(type==2||type==3)
	{
		if(input_string(staff_id,6,2)==0)
		{
			return;
		}
		get_account(&temp,staff_id);
		TrimSpace(temp.staff_name);
		TrimSpace(temp.staff_pwd);
		TrimSpace(temp.remark);
		strcpy(staff_id,temp.staff_id);
		strcpy(staff_name,temp.staff_name);
		strcpy(staff_pwd,temp.staff_pwd);
		strcpy(remark,temp.remark);
		t_type=temp.staff_type;
		sprintf(staff_type,"%d",t_type);
		wprintw(t0->win,"%s",staff_id);
		wprintw(t1->win,"%s",staff_name);
		wprintw(t2->win,"%s",staff_pwd);
		wprintw(t3->win,"%s",staff_type);
		wprintw(t4->win,"%s",remark);
	}	
	w1->show_win(w1);
	t0->show_text(t0);
	t1->show_text(t1);
	t2->show_text(t2);
	t3->show_text(t3);
	t4->show_text(t4);
	b1->show_button(b1);
	b2->show_button(b2);
	if(type==3)
	{
		res=run_button(b1,b2,1);
		if(res==1)
		{
			Delete_Staff(staff_id);
			return;
		}
		if(res==2)
		{
			return;
		}
	}
	if(type==2)
	{
		k=2;
	}
	while(1)
	{
		if(k==1)
		{
			res=GetString(t0->win,staff_id,6,1);
			if(res==2||res==13||res==0)
			{
				k++;
				continue;
			}
			if(res==14)
			{
				return;
			}
			else
			{
				continue;
			}
		}
		if(k==2)
		{
			res=GetString(t1->win,staff_name,15,1);
			if(res==2||res==13||res==0)
			{
				k++;
				continue;
			}
			if(type==1)
			{
				if(res==1)
				{
					k--;
					continue;
				}
				if(res==14)
				{
					return;
				}
			}
		}
		if(k==3)
		{
			res=GetString(t2->win,staff_pwd,12,1);
			if(res==2||res==13||res==0)
			{
				k++;
				continue;
			}
			if(res==1)
			{
				k--;
				continue;
			}
			if(res==14)
			{
				return;
			}
		}
		if(k==4)
		{
			res=GetString(t3->win,staff_type,1,1);
			if(res==2||res==13||res==0)
			{
				k++;
				continue;
			}
			if(res==1)
			{
				k--;
				continue;
			}
			if(res==14)
			{
				return;
			}
		}
		if(k==5)
		{
			res=GetString(t4->win,remark,24,1);
			if(res==2||res==13||res==0)
			{
				k++;
				continue;
			}
			if(res==1)
			{
				k--;
				continue;
			}
			if(res==14)
			{
				return;
			}
		}
		if(k==6)
		{
			 res=run_button(b1,b2,0);
			 if(res==3)
			 {
				 k=5;
				 continue;
			 }
			 if(res==2)
			 {
				 return;
			 }
			 if(res==1)
			 {
				 if(strlen(staff_id)==0)
				 {
					 show_msg("账户ID不能为空",0);
					 k=1;
					 continue;
				 }
				 if(type==1)
				 {
					 if(get_account(&temp,staff_id)==0)
					 {
						 show_msg("该ID用户已经被占用",0);
						 k=1;
						 continue;
					 }
				 }
				 strcpy(temp.staff_id,staff_id);
				 strcpy(temp.staff_name,staff_name);
				 strcpy(temp.staff_pwd,staff_pwd);
				 temp.staff_type=atoi(staff_type);

⌨️ 快捷键说明

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