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

📄 5_2.cpp

📁 物品存放的管理C++源程序 用于管理物品的小软件 适合课程设计
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	switch(option)
	{
	case 1:
		if(lgwg==1) cout<<"\nEnter Item name  ";
		else cout<<"\n请输入物品名称 :";
		cin.ignore();
		cin.getline(name1,10);
		code=0;
		break;
	case 2:
		if(lgwg==1) cout<<"\nEnter Item Code ";
		else cout<<"\n请输入物品编码 :";
		cin>>code;
		cin.ignore();
		break;
	case 3:
		if(lgwg==1) cout<<"Really Delete All The Data ?\tYes(y)/No(n)";
		else cout<<"确定删除所有记录 ?\t是(y)/否(n)";
		cin.ignore();cin>>dlt;
		if(dlt=='y') clear("TIS.DAT");
		goto node2;
	case 4:
		system("cls");
		return;
	default:
		goto node2;
	}
	ifstream file( "TIS.DAT" ,ios::in );
	ofstream temp( "delete.DAT", ios::trunc);
	if(!file||!temp)
	{
		if(lgwg==1) cout<<"Error Could Not Open File.\n\nPress Enter to continue.";
		else cout<<"错误!无法打开文件。\n\n按回车继续";
		cin.ignore();cin.get(pause);
		exit(1);
	}
	file.seekg(0);
	temp.seekp(0);
	Item p1;
	file.read(reinterpret_cast<char *> (&p1),sizeof(Item));
	pause='a';
	while(!file.eof())
	{
		if((strcmp(name1,p1.Item_name)==0)||(code==p1.Item_code))
		{
			if(lgwg==1) cout<<"Do You Want to Refresh The IES ?\tYes(y)/No(n)";
			else cout<<"\n是否更新进出口统计表 ?\t是(y)/否(n)";
			char chc;
			cin>>chc;
			if(chc=='y')
			{
				IE t1;
				t1.IEport(p1,2);
				ofstream file1( "IES.DAT", ios::out |ios::ate );
				file1.write(reinterpret_cast <const char *> (&t1),sizeof(IE) );
			}
			pause='z';
			file.read(reinterpret_cast<char *> (&p1),sizeof(Item));
			
		}
		else
		{
			temp.write(reinterpret_cast<char *> (&p1),sizeof(Item));
			file.read(reinterpret_cast<char *> (&p1),sizeof(Item));
        }
	}
	file.close();
	temp.close();
	ifstream temp1("delete.DAT",ios::in);
	ofstream file1("TIS.DAT", ios::trunc);
    temp1.seekg(0);
    file1.seekp(0);
    temp1.read(reinterpret_cast<char *> (&p1),sizeof(Item));
    while(!temp1.eof())
	{
        file1.write(reinterpret_cast<char *> (&p1),sizeof(Item) );
		temp1.read(reinterpret_cast<char *> (&p1),sizeof(Item) );
	}
    temp1.close();
	file1.close();
	if(pause=='z')
	{
		if(lgwg==1) cout<<"Deleted.\n\nPress Enter to continue.";
		else cout<<"已删除。\n\n按回车继续";
		cin.get(pause);
	}
	else
	{
		if(lgwg==1) cout<<"Item Not Found.\n\nPress Enter to continue.";
		else cout<<"未找到匹配档案。\n\n按回车继续";
		cin.get(pause);
	}
	goto node2;
}


void Trade::getdata()
{
	switch(lgwg)
	{
	case 1:
		cout<<"\n\nEnter Item Name   ";
		cin.ignore();
		cin.getline(item,20);
		cout<<"\nEnter Trade Code ";
		cin>>Trade_code;
		cout<<"\nEnter Item Quantity ";
		cin>>quantity;
		break;
    case 2:
		cout<<"\n\n请输入物品名称: ";
		cin.ignore();
		cin.getline(item,20);
		cout<<"\n请输入物品编号: ";
		cin>>Trade_code;
		cout<<"\n请输入物品数量: ";
		cin>>quantity;
	}
}

void Trade::showdata()
{
	switch(lgwg)
	{
	case 1:
		cout<<"\n\nItem Name        :  "; cout<<item;
		cout<<"\n\nTrade Code       :  "; cout<<Trade_code;
		cout<<"\n\nItem Quantity    :  "; cout<<quantity<<endl;
		break;
	case 2:
		cout<<"\n\n物品名称      :  "; cout<<item;
		cout<<"\n\n物品编号      :  "; cout<<Trade_code;
		cout<<"\n\n物品数量      :  "; cout<<quantity<<endl;
	}
}

void Guest::getdata()	
{
	switch(lgwg)
	{
	case 1:
		cout<<"\nEnter Guest Name  ";
		cin.ignore();
		cin.getline(Guest_name,10);
		cout<<"\nEnter Guest Code  ";
		cin>>Guest_code;
		cout<<"\nEnter Phone Number ";
		cin.ignore();
		cin.getline(Phone_NO,10);
		cout<<"\nEnter The Quantity of Traded Item  ";
		cin>>quantity;
		cout<<"\nEnter The Number of Sort (Less than nine) ";
		cin>>num;
		for(i=0;i<num;i++)
		{
			cout<<"\n\nEnter Item "<<i+1;
			trd[i].getdata();
		}
		i=0;
		break;
	case 2:
		cout<<"\n请输入客户名称: ";
		cin.ignore();
		cin.getline(Guest_name,10);
		cout<<"\n请输入客户序号: ";
		cin>>Guest_code;
		cout<<"\n请输入联系电话: ";
		cin.ignore();
		cin.getline(Phone_NO,10);
		cout<<"\n请输入交易物品总数: ";
		cin>>quantity;
		cout<<"\n请输入种类个数(九个以内): ";
		cin>>num;
		for(i=0;i<num;i++)
		{
			cout<<"\n\n请输入第"<<i+1<<"种物品数据: ";
			trd[i].getdata();
		}
		i=0;
	}
}

void Guest::showdata()	
{
	switch(lgwg)
	{
	case 1:
		cout<<"\n\n\t\tGuest Data";
		cout<<"\n\nGuest Name    :  ";
		cout<<Guest_name;
		cout<<"\n\nGuest Code    :  ";
		cout<<Guest_code;
		cout<<"\n\nPhone Number  :  ";
		cout<<Phone_NO;
		cout<<"\n\nQuantity of Traded Item:  ";
		cout<<quantity;
		cout<<"\n\nPress Enter to continue.";cin.get(pause);
		while(*trd[i].rtnname())
		{
			cout<<"\n\nItem "<<i+1<<endl; trd[i].showdata();
			i++;
			cout<<"\n\nPress Enter to continue.";cin.get(pause);
		}
		i=0;
		break;
	case 2:
		cout<<"\n\n\t\t客户数据";
		cout<<"\n\n客户名称     :  ";
		cout<<Guest_name;
		cout<<"\n\n客户序号     :  ";
		cout<<Guest_code;
		cout<<"\n\n联系电话     :  ";
		cout<<Phone_NO;
		cout<<"\n\n交易物品总数 :  ";
		cout<<quantity;
		cout<<"\n\n按回车继续";cin.get(pause);
		while(*trd[i].rtnname())
		{
			cout<<"\n\n第"<<i+1<<"种物品\n"; trd[i].showdata();
			i++;
			cout<<"\n\n按回车继续";cin.get(pause);
		}
		i=0;
	}
}

void Guest::add()	
{

	ofstream file( "TGS.DAT", ios::out |ios::ate ); 
	if(!file)   
	{
		if(lgwg==1) cout<<"Error Could Not Open File.\n\nPress Enter to continue.";
		else cout<<"错误!无法打开文件。\n\n按回车继续";
		cin.ignore();cin.get(pause);
		exit(1);
	}
	Guest p1;
	p1.getdata();   
    file.write(reinterpret_cast <const char *> (&p1),sizeof(Guest) );
}

void Guest::showag()  	
{
	system("cls");
	ifstream file( "TGS.DAT" ,ios::in);  
	if(!file)   
	{
		if(lgwg==1) cout<<"Error Could Not Open File.\n\nPress Enter to continue.";
		else cout<<"错误!无法打开文件。\n\n按回车继续";
		cin.ignore();cin.get(pause);
		exit(1);
	}
	Guest p1;
	file.read(reinterpret_cast<char *>(&p1),sizeof(Guest));
	cin.ignore();
	while(!file.eof()) 
	{

		p1.showdata() ;  
		file.read(reinterpret_cast<char *> (&p1),sizeof(Guest)); 
	}
}


void Guest::search()   	
{
node3:	
	char name1[10]={NULL};
	int code=-1;
	int option;
	system("cls");
	if(lgwg==1) cout<<"\n(1)Search By Name\n(2)Search By Code\n(3)Search By Phone Number\n(4)Back  ";
	else cout<<"\n(1)按客户名称搜索\n(2)按客户序号搜索\n(3)按联系电话搜索\n(4)返回   ";
	cin>>option;
	cin.ignore();
	switch(option)
	{
	case 1:
		if(lgwg==1) cout<<"\nEnter Guest name ";
		else cout<<"\n请输入客户名称 :";
		cin.getline(name1,10);
		break;
	case 2:
		if(lgwg==1) cout<<"\nEnter Guest Code ";
		else cout<<"\n请输入客户序号 : ";
		cin>>code;
		cin.ignore();
		break;
	case 3:
		if(lgwg==1) cout<<"\nEnter The Price ";
		else cout<<"\n请输入联系电话 : ";
		cin.getline(name1,10);
		break;
	case 4:
		system("cls");
		return;
	default:
		goto node3;

	}
	fstream file( "TGS.DAT" ,ios::in);  
	if(!file)  
	{
		if(lgwg==1) cout<<"Error Could Not Open File.\n\nPress Enter to continue.";
		else cout<<"错误!无法打开文件。\n\n按回车继续";
		cin.ignore();cin.get(pause);
		exit(1);
	}
	char flag='a';  
	Guest p1;
	file.read(reinterpret_cast<char *>(&p1),sizeof(Guest));	
	while(!file.eof()) 
	{
		if((strcmp(p1.Guest_name,name1)==0)||(p1.Guest_code==code)||(strcmp(p1.Phone_NO,name1)==0)) 
		{
			p1.showdata();
			flag='z';   
			break; 
		}
		file.read(reinterpret_cast<char *> (&p1),sizeof(Guest));
	}
	if(flag !='z')  
	{
		if(lgwg==1) cout<<"Guest Not Found.\n\nPress Enter to continue.";
		else cout<<"未找到匹配档案。\n\n按回车继续";
		cin.get(pause);
	}
	goto node3;
}
  
void Guest::remove()
{
node4:
	char name1[10]={NULL};
	int code;
	int option;
	system("cls");
	if(lgwg==1) cout<<"\n(1)Delete By Name\n(2)Delete By Code\n(3)Delete All The Data\n(4)Back  ";
	else cout<<"\n(1)按名称清除\n(2)按序号清除\n(3)清楚所有客户\n(4)返回  ";
	cin>>option;
	switch(option)
	{
	case 1:
		if(lgwg==1) cout<<"\nEnter Guest name  ";
		else cout<<"\n请输入客户名称 :";
		cin.ignore();
		cin.getline(name1,10);
		code=0;
		break;
	case 2:
		if(lgwg==1) cout<<"\nEnter Guest Code ";
		else cout<<"\n请输入客户序号 :";
		cin>>code;
		cin.ignore();
		break;
	case 3:
		char dlt;
		if(lgwg==1) cout<<"Really Clear All The Data ?\tYes(y)/No(n)";
		else cout<<"确定清空所有记录 ?\t是(y)/否(n)";
		cin.ignore();cin>>dlt;
		if(dlt=='y') clear("TGS.DAT");
		goto node4;
	case 4:
		system("cls");
		return;
	default:
		goto node4;
	}
	ifstream file( "TGS.DAT" ,ios::in );
	ofstream temp( "delete.DAT", ios::trunc);
	if(!file||!temp)
	{
		if(lgwg==1) cout<<"Error Could Not Open File.\n\nPress Enter to continue.";
		else cout<<"错误!无法打开文件。\n\n按回车继续";
		cin.ignore();cin.get(pause);
		exit(1);
	}
	file.seekg(0);
	temp.seekp(0);
	Guest p1;
	file.read(reinterpret_cast<char *> (&p1),sizeof(Guest));
	char flag='a';
	while(!file.eof())
	{
		if((strcmp(name1,p1.Guest_name)==0)||(code==p1.Guest_code))
		{
			file.read(reinterpret_cast<char *> (&p1),sizeof(Guest));
			flag='z';
		}
		else
		{
			temp.write(reinterpret_cast<char *> (&p1),sizeof(Guest));
			file.read(reinterpret_cast<char *> (&p1),sizeof(Guest));
        }
	}
	file.close();
	temp.close();
	ifstream temp1("delete.DAT",ios::in);
	ofstream file1("TGS.DAT", ios::trunc);
    temp1.seekg(0);
    file1.seekp(0);
    temp1.read(reinterpret_cast<char *> (&p1),sizeof(Guest));
    while(!temp1.eof())
	{
        file1.write(reinterpret_cast<char *> (&p1),sizeof(Guest) );
		temp1.read(reinterpret_cast<char *> (&p1),sizeof(Guest) );
	}
    temp1.close();
	file1.close();
	if(flag=='z')
	{
		if(lgwg==1) cout<<"Deleted.\n\nPress Enter to continue.";
		else cout<<"已删除。\n\n按回车继续";
		cin.get(pause);
	}
	else
	{
		if(lgwg==1) cout<<"Guest Not Found.\n\nPress Enter to continue.";
		else cout<<"未找到匹配档案。\n\n按回车继续";
		cin.get(pause);
	}
	goto node4;
}

void IE::showdata()
{
	char iore[10];
	if(lgwg==1&&condition==1) strcpy(iore,"Import");
	if(lgwg==1&&condition==2) strcpy(iore,"Export");
	if(lgwg==2&&condition==1) strcpy(iore,"进口");
	if(lgwg==2&&condition==2) strcpy(iore,"出口");
	cout.setf(ios::left);
	cout<<setw(2)<<date_month<<"."<<setw(2)<<date_day<<"."<<setw(10)<<date_year<<setw(16)<<item_name<<setw(16)<<item_code<<setw(16)<<item_quantity<<setw(16)<<iore<<endl;

⌨️ 快捷键说明

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