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

📄 functionlib.c

📁 linux环境下结合ncurse库
💻 C
📖 第 1 页 / 共 5 页
字号:
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
					主要函数定义
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
#include <time.h>
#include "BaseEnvInit.h"
#include "TextBox.h"
#include "Button.h"
#include "MyWindow.h"
#include "FunctionLib.h"
#include "OperationDB.h"
#include "DuLink.h"


char savesaleid_arr[3][19]={"","",""}; // 保存销售ID
C_CLASS LINKLIST * listarr[3]={NULL,NULL,NULL}; // 保存挂单指针

/******************************************************************
Function:	获取系统本地时间
Param:	存时间的地址
return:	无
*******************************************************************/
void GetTime(char *str)
{	
	memset(str,0,15);
	struct tm *ptm;
	time_t the_time;
	time(&the_time);
	ptm=localtime(&the_time);
	sprintf(str,"%04d%02d%02d%02d%02d%02d",ptm->tm_year+1900,ptm->tm_mon+1,ptm->tm_mday,ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
}


/******************************************************************
Function: 超级管理员登入函数
Param:	帐户信息结构体指针
return:	1 确定键 0 取消键
*******************************************************************/
int MgrLoginWin(StaffInfo * pstaff)
{
	scr_dump("SaveScr2.scr");
	
	MyWindow * pLoginWindow=NULL;
	pLoginWindow=MakeMyWindow(pLoginWindow);
	pLoginWindow->m_px=24;
	pLoginWindow->m_py=7;
	pLoginWindow->m_sizex=30;
	pLoginWindow->m_sizey=11;
	pLoginWindow->m_color=WHITE_BLUE;
	pLoginWindow->ChangeMyWindow(&pLoginWindow);

	// 下列函数均测试成功
	pLoginWindow->DrawWords(pLoginWindow,0,3,"输入管理员密码");
	pLoginWindow->DrawWords(pLoginWindow,2,1,"管理员帐号:");
	pLoginWindow->DrawWords(pLoginWindow,4,1,"管理员密码:");
	pLoginWindow->ShowMyWindow(pLoginWindow);
	
	// 帐号框
	TextBox * pUserText=NULL;
	pUserText=MakeTextBox(pUserText);
	pUserText->m_strmaxlen=6;
	pUserText->m_strminlen=6;
	pUserText->m_isInteger=TRUE;
	pUserText->m_isPasswd=FALSE;
	pUserText->m_isFn2_9=FALSE;
	ChangeTextBox(&pUserText);
	
	// 密码框
	TextBox * pPasswdText=NULL;
	pPasswdText=MakeTextBox(pPasswdText);
	pPasswdText->m_strmaxlen=12;
	pPasswdText->m_strminlen=6;
	pPasswdText->m_isInteger=FALSE;
	pPasswdText->m_isPasswd=TRUE;
	pPasswdText->m_isFn2_9=FALSE;
	ChangeTextBox(&pPasswdText);
	
	//确定按妞
	Button * pButton1=NULL;
	pButton1=MakeButton(pButton1);
	strcpy(pButton1->m_name,"确定");
	pButton1->m_color_foot=WHITE_BLUE;
	pButton1->m_kind=YESBUTTON;
	pButton1->m_buttonid=BUTTONID+1;
	pButton1->ChangeButton(&pButton1);
	
	// 取消按妞
	Button * pButton2=NULL;
	pButton2=MakeButton(pButton2);
	strcpy(pButton2->m_name,"取消");
	pButton2->m_color_foot=WHITE_BLUE;
	pButton2->m_buttonid=BUTTONID+2;
	pButton2->m_kind=NOBUTTON;
	pButton2->ChangeButton(&pButton2);

	pLoginWindow->AddActiveElement(pLoginWindow,pUserText,ISTEXT,2,12);
	pLoginWindow->AddActiveElement(pLoginWindow,pPasswdText,ISTEXT,4,12);
	pLoginWindow->AddActiveElement(pLoginWindow,pButton1,ISBUTTON,6,4);
	pLoginWindow->AddActiveElement(pLoginWindow,pButton2,ISBUTTON,6,18);

	UserInfo userinfo;
	StaffInfo staff;
	memset(&userinfo,0,sizeof(UserInfo));
	memset(&staff,0,sizeof(StaffInfo));
	int presskey=0;
	do
	{
		pLoginWindow->ShowMyWindow(pLoginWindow);
		presskey=pLoginWindow->RunMyWindow(pLoginWindow);
		if(presskey==BUTTONID+1)
		{
			// 按了确定按妞
			if ( (pUserText->m_strmaxlen)!= ( strlen(pUserText->m_str) ))
			{
				MessageBox("请输入6位数字帐号.","任意键返回",NOBTN);
				continue;
			}
			if (pPasswdText->m_strminlen>strlen(pPasswdText->m_str))
			{
				MessageBox("密码为6-12位.","任意键返回",NOBTN);
				continue;
			}
			// 密码帐号格式正确
				strcpy(userinfo.username,pUserText->m_str);
				strcpy(userinfo.password,pPasswdText->m_str);
				if(1==LoginValidate(&userinfo,&staff))
				{
						if(staff.staff_type!=0)
						{
							memset(pUserText->m_str,0,512);
							memset(pPasswdText->m_str,0,512);
							pUserText->m_str[0]='\0';
							pPasswdText->m_str[0]='\0';
							MessageBox("该用户没有权限","按任意键返回.",NOBTN);
							continue;
						}
						else
						{
							break;
						}
				}
				else
				{
					memset(pUserText->m_str,0,512);
					memset(pPasswdText->m_str,0,512);
					pUserText->m_str[0]='\0';
					pPasswdText->m_str[0]='\0';
					continue;
				}
		}
		else // 按了取消按钮
		{
			memset(pUserText->m_str,0,512);
			memset(pPasswdText->m_str,0,512);
			pUserText->m_str[0]='\0';
			pPasswdText->m_str[0]='\0';
			scr_restore("SaveScr2.scr");
			DelMyWindow(pLoginWindow);
			return 0;
		}
	}
	while (1);
	scr_restore("SaveScr2.scr");
	DelMyWindow(pLoginWindow);
	return 1;
}

/************************************************************
	Function:登入函数
	Param: 无
	return : 登入者的身份类型
*************************************************************/
int LoginWin(StaffInfo * pstaff)
{
	werase(stdscr);
	refresh();
	int i=0;
	attron(A_REVERSE);
	for(i=0;i<80;i++)
	{
		mvaddch(0,i,' '|A_REVERSE);
	}
	for(i=0;i<80;i++)
	{
		mvaddch(24,i,' '|A_REVERSE);
	}
	mvprintw(0,0,"超市收银系统");
	mvprintw(24,0,"Linux pos version 1.2  Author:Laizwen.");
	attroff(A_REVERSE);
	refresh();

	//pMyWindow->ShowMyWindow(pMyWindow);
	MyWindow * pLoginWindow=NULL;
	pLoginWindow=MakeMyWindow(pLoginWindow);
	pLoginWindow->m_px=24;
	pLoginWindow->m_py=7;
	pLoginWindow->m_sizex=30;
	pLoginWindow->m_sizey=11;
	pLoginWindow->m_color=BLACK_WHITE;
	pLoginWindow->ChangeMyWindow(&pLoginWindow);

	// 下列函数均测试成功
	pLoginWindow->ShowMyWindow(pLoginWindow);
	pLoginWindow->DrawWords(pLoginWindow,0,10,"登入窗口");
	pLoginWindow->DrawWords(pLoginWindow,2,3,"帐号:");
	pLoginWindow->DrawWords(pLoginWindow,4,3,"密码:");
	pLoginWindow->ShowMyWindow(pLoginWindow);
	
	// 帐号框
	TextBox * pUserText=NULL;
	pUserText=MakeTextBox(pUserText);
	pUserText->m_strmaxlen=6;
	pUserText->m_strminlen=6;
	pUserText->m_isInteger=TRUE;
	pUserText->m_isPasswd=FALSE;
	pUserText->m_isFn2_9=FALSE;
	ChangeTextBox(&pUserText);

	
	// 密码框
	TextBox * pPasswdText=NULL;
	pPasswdText=MakeTextBox(pPasswdText);
	pPasswdText->m_strmaxlen=12;
	pPasswdText->m_strminlen=6;
	pPasswdText->m_isInteger=FALSE;
	pPasswdText->m_isPasswd=TRUE;
	pPasswdText->m_isFn2_9=FALSE;
	ChangeTextBox(&pPasswdText);
	
	//确定按妞
	Button * pButton1=NULL;
	pButton1=MakeButton(pButton1);
	strcpy(pButton1->m_name,"确定");
	pButton1->m_kind=YESBUTTON;
	pButton1->m_buttonid=BUTTONID+1;
	pButton1->ChangeButton(&pButton1);
	
	// 取消按妞
	Button * pButton2=NULL;
	pButton2=MakeButton(pButton2);
	strcpy(pButton2->m_name,"取消");
	pButton2->m_buttonid=BUTTONID+2;
	pButton2->m_kind=NOBUTTON;
	pButton2->ChangeButton(&pButton2);

	pLoginWindow->AddActiveElement(pLoginWindow,pUserText,ISTEXT,2,8);
	pLoginWindow->AddActiveElement(pLoginWindow,pPasswdText,ISTEXT,4,8);
	pLoginWindow->AddActiveElement(pLoginWindow,pButton1,ISBUTTON,6,4);
	pLoginWindow->AddActiveElement(pLoginWindow,pButton2,ISBUTTON,6,18);

	UserInfo userinfo;
	StaffInfo staff;
	memset(&userinfo,0,sizeof(UserInfo));
	memset(&staff,0,sizeof(StaffInfo));
	int presskey=0;
	do
	{
		pLoginWindow->ShowMyWindow(pLoginWindow);
		presskey=pLoginWindow->RunMyWindow(pLoginWindow);
		if(presskey==BUTTONID+1)
		{
			// 按了确定按妞
			if ( (pUserText->m_strmaxlen)!= ( strlen(pUserText->m_str) ))
			{
				MessageBox("请输入6位数字帐号.","任意键返回",NOBTN);
				continue;
			}
			
			if (pPasswdText->m_strminlen>strlen(pPasswdText->m_str))
			{
				MessageBox("密码为6-12位.","任意键返回",NOBTN);
				continue;
			}
			
			// 密码帐号格式正确
				
				strcpy(userinfo.username,pUserText->m_str);
				strcpy(userinfo.password,pPasswdText->m_str);
				if(1==LoginValidate(&userinfo,&staff))
				{
						if(staff.staff_type==0)
						{
							memset(pUserText->m_str,0,512);
							memset(pPasswdText->m_str,0,512);
							pUserText->m_str[0]='\0';
							pPasswdText->m_str[0]='\0';
							MessageBox("超级用户没有该权限","按任意键返回.",NOBTN);
							continue;
						}
						else
						{
							break;
						}
				}
				else
				{
					memset(pUserText->m_str,0,512);
					memset(pPasswdText->m_str,0,512);
					pUserText->m_str[0]='\0';
					pPasswdText->m_str[0]='\0';
					continue;
				}
		}
		else // 按了取消按钮
		{
			memset(pUserText->m_str,0,512);
			memset(pPasswdText->m_str,0,512);
			pUserText->m_str[0]='\0';
			pPasswdText->m_str[0]='\0';

			if((BUTTONID+1)==MessageBox("提示","您要退出系统吗?",YESNO))
			{// 退出系统
				// 调用安全退出函数

				//  做一个数据库保存的工作

				endwin();
				exit(1);
			}
			else
			{
			// 不退出系统
			}
		}
	}
	while (1);

	DelMyWindow(pLoginWindow);
	wclear(stdscr);
	refresh();
	
	MoveRightSpace(staff.staff_id);
	MoveRightSpace(staff.staff_name);
	MoveRightSpace(staff.staff_pwd);
	MoveRightSpace(staff.staff_remark);

	strcpy(pstaff->staff_id,staff.staff_id);
	strcpy(pstaff->staff_name,staff.staff_name);
	strcpy(pstaff->staff_pwd,staff.staff_pwd);
	pstaff->staff_type=staff.staff_type;
	strcpy(pstaff->staff_remark,staff.staff_remark);
	return staff.staff_type;
}

/************************************************************
	Function:增加删除明细
	Param: 区别 增加 删除
	return : 无
*************************************************************/
void AddDelDetail(C_CLASS LINKLIST * link,int current,enum DETAILMODE mode)
{
	scr_dump("SaveScr.scr");
	// 主窗口
	MyWindow * pDetailWin=NULL;
	pDetailWin=MakeMyWindow(pDetailWin);
	pDetailWin->m_color=WHITE_BLUE;
	pDetailWin->m_sizex=32; // 30
	pDetailWin->m_sizey=12; // 12
	pDetailWin->m_px=25;
	pDetailWin->m_py=7;
	ChangeMyWindow(&pDetailWin);
	int sizex=pDetailWin->m_sizex;
	int sizey=pDetailWin->m_sizey;

	if(mode==ADDMODE)
	{
		DrawWords(pDetailWin,1,(sizex-strlen("新增明细"))/2,"新增明细");
	}
	else
	{
		DrawWords(pDetailWin,1,(sizex-strlen("删除明细"))/2,"删除明细");
	}
	// 画画
	DrawHline(pDetailWin,2,1);
	DrawHline(pDetailWin,4,1);
	DrawHline(pDetailWin,6,1);
	DrawWords(pDetailWin,3,1,"商品条形码:");
	if(mode==ADDMODE)
	{
		DrawWords(pDetailWin,5,3,"增加数量:");
	}
	else
	{
		DrawWords(pDetailWin,5,3,"删除数量:");
	}
	
	DUNODE * pnode=link_get_node_by_index(link,current);
	int num=(((SellGoods *)(pnode->data))->product_count);
	char temp[5]={0};
	sprintf(temp,"%d",num);
	DrawWords(pDetailWin,5,18,"已购数量:");
	DrawWords(pDetailWin,5,27,temp);

	wattron(pDetailWin->m_window,A_REVERSE);
	DrawWords(pDetailWin,3,12,((SellGoods *)(pnode->data))->bar_code);
	wattroff(pDetailWin->m_window,A_REVERSE);
	// 数量文本
	TextBox * pCountText=NULL;
	pCountText=MakeTextBox(pCountText);
	pCountText->m_strmaxlen=3;
	if(mode==ADDMODE)
	{
		strcpy(pCountText->m_str,"5");
	}
	else
	{
		int num=(((SellGoods *)(pnode->data))->product_count);
		char temp[5]={0};
		sprintf(temp,"%d",num);
		strcpy(pCountText->m_str,temp);
	}
	pCountText->m_spc.s_sizex=4;
	pCountText->m_isInteger=TRUE;
	pCountText->m_isPasswd=FALSE;
	pCountText->m_isFn2_9=FALSE;
	ChangeTextBox(&pCountText);

	// 确定按扭
	Button * pButton1=NULL;
	pButton1=MakeButton(pButton1);
	strcpy(pButton1->m_name,"确定");
	pButton1->m_kind=YESBUTTON;
	pButton1->m_buttonid=BUTTONID+1;
	pButton1->m_sizey=3;
	pButton1->m_color_foot=WHITE_BLUE;
	pButton1->ChangeButton(&pButton1);

	//返回按扭
	Button * pButton2=NULL;
	pButton2=MakeButton(pButton2);
	strcpy(pButton2->m_name,"返回");
	pButton2->m_buttonid=BUTTONID+2;
	pButton2->m_kind=NOBUTTON;
	pButton2->m_color_foot=WHITE_BLUE;
	pButton2->m_sizey=3;
	pButton2->ChangeButton(&pButton2);

	// 添加元素
	pDetailWin->AddActiveElement(pDetailWin,pCountText,ISTEXT,5,12);
	pDetailWin->AddActiveElement(pDetailWin,pButton1,ISBUTTON,7,4);
	pDetailWin->AddActiveElement(pDetailWin,pButton2,ISBUTTON,7,18);

		int keyres=-1;

		if(mode==ADDMODE)
		{

			ShowMyWindow(pDetailWin);
			keyres=RunMyWindow(pDetailWin);
			if (BUTTONID+1==keyres)
			{// 确定
				int num=atoi(pCountText->m_str);
				(((SellGoods *)(pnode->data))->product_count)+=num;
			}
		}else
		{
			ShowMyWindow(pDetailWin);
			keyres=RunMyWindow(pDetailWin);
			if((BUTTONID+1)==keyres)
			{
					do
					{
							int num=atoi(pCountText->m_str);
							if (num> ((((SellGoods *)(pnode->data))->product_count)))
							{
								MessageBox("超出已购数量","按任意键返回",NOBTN);
								continue;
							}
							else
							{
								(((SellGoods *)(pnode->data))->product_count)-=num;
								if((((SellGoods *)(pnode->data))->product_count)==0)
								{ // 如果数量全部删掉的话,应该在连表中除去
									link_delete_node_by_index(link,current);
								}
								break;
							}
					}while (1);
			}
		}
	DelMyWindow(pDetailWin);
	scr_restore("SaveScr.scr");
}

/*******************************************************
	Funciton:去除商品信息空格
	Param:商品信息指针
	return: 无
********************************************************/
void MoveGoodsSpace(Goods * goods)
{
	MoveRightSpace(goods->bar_code);
	MoveRightSpace(goods->product_name);
	MoveRightSpace(goods->spec);
	MoveRightSpace(goods->unit);
}
/*******************************************************
	Funciton:比较函数 条形码
	Param:VOID 数据类型指针  void 指向 barcode 
	return: 0 匹配 1 不匹配
********************************************************/
int CmpBarCode(void * pdata,void  * barcode)
{
	if(strcmp(((SellGoods *)pdata)->bar_code,((char *)barcode))==0)
	{
		return 0; // 匹配
	}
	else

⌨️ 快捷键说明

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