📄 clssupplier.cpp
字号:
/***********************************
* 模块名称:clsSupplier.cpp *
* 模块功能: clsSupplier 类 类体 *
* 作者:刘鑫锐 *
* 撰写日期:2005-9-15 *
***********************************/
#include <iostream.h>
#include <stdlib.h>
#include "head/clsSupplier.h" //调用 clsSupplier类声明 头文件
#include "head/clsConn.h" //调用 clsConn 类声明 头文件
#include "head/clsMain.h" //调用 clsMain 类声明 头文件
void clsSupplier::dispSupplierMenu() //Supplier 信息管理 主菜单
{
system("clear");
char choice; //定义接收选择的变量
while(1)
{
system("clear");
cout << endl << "\t\t **********************************************" << endl;
cout << endl << "\t\t * SUPPLIER MIS MAIN MENU *" << endl;
cout << endl << "\t\t **********************************************" << endl;
cout << endl << "\t\t *** 1) SUPPLIER INFORMATION LIST ***" << endl;
cout << endl << "\t\t *** 2) SUPPLIER INFORMATION INSERT ***" << endl;
cout << endl << "\t\t *** 3) SUPPLIER INFORMATION UPDATE/DELETE ***" << endl;
cout << endl << "\t\t *** 4) RETURN MAIN MENU ***" << endl;
cout << endl << "\t\t **********************************************" << endl;
cout << endl << "\t\t **********************************************" << endl;
cout << endl << "\t\t Please enter your choice : ";
cin >> choice; //输入选择
switch(choice) //根据选择,执行相关的操作
{
case '1':
{
system("clear");
clsSupplier obj; //创建对象
obj.listSupplierInfo(); //列表显示供应商信息主菜单
break;
}
case '2':
{
system("clear");
clsSupplier obj; //创建对象
obj.addSupplierInfo(); //添加供应商信息
break;
}
case '3':
{
system("clear");
clsSupplier obj; //创建对象
obj.querySupplierInfo(); //先查询供应商信息 ,再进行修改和删除操作
break;
}
case '4':
{
system("clear");
clsMain obj;
obj.mainlist(); //返回主菜单
break;
}
default:
{
system("clear");
clsMain obj;
obj.error(); //显示错误信息
break;
}
}
}
}
void clsSupplier::listSupplierInfo() //供应商信息列表
{
clsConn obj;
char ListString[1024];
sprintf(ListString,"select * from Supplier");
obj.ClistSupplierInfo(ListString);
}
void clsSupplier::addSupplierInfo() //添加供应商信息
{
system("clear");
cout << "\n\n";
clsConn obj;
char InsertString[1024];
cout << endl << "\t\t *****************************************";
cout << endl << "\t\t * INSERT BEGIN *";
cout << endl << "\t\t *****************************************";
cout << endl << endl << "\t\t Please enter Supplier Id:";
cin >> SupplierId;
cout << endl << "\t\t Please enter Supplier Name:";
cin >> SupplierName;
cout << endl << "\t\t Please enter Supplier Address:";
cin >> SupplierAddress;
cout << endl << "\t\t Please enter Supplier Phone:";
cin >> SupplierPhone;
cout << endl << "\t\t Please enter Product Id:";
cin >> ProductId;
sprintf(InsertString,"insert into Supplier values ('%s','%s','%s','%s',%d)",SupplierId,SupplierName,SupplierAddress,SupplierPhone,ProductId);
obj.Cwork(InsertString);//每个供应商提供一种产品
}
void clsSupplier::querySupplierInfo() //查询供应商信息
{
char choice;
system("clear");
cout << "\n\n\n\n";
cout << endl << "\t\t *****************************************";
cout << endl << "\t\t * QUERY,UPDATE,DELETE BEGIN *";
cout << endl << "\t\t *****************************************";
cout << endl << "\t\t ASK:" << endl;
cout << endl << "\t\t Your can use SupplierId or SupplierName for Query Supplier!\n";
cout << endl << "\t\t --Use ProductId Query,please enter A: \n"; //根据供应商的Id查询
cout << endl << "\t\t --Use SupplierName Query,please enter B:\n"; //根据供应商的Name查询
cout << endl << "\t\t --Other key will begin delete/update: \n"; //按其他键 则直接开始修改、删除操作
cout << endl << "\t\t ANSWER:";
cin >> choice;
cout << endl;
if(choice=='A' || choice=='a')
{
cout << "\t\t Please enter Product Id :";
cin >> ProductId;
clsConn obj;
char QueryString[1024];
sprintf(QueryString,"select * from Supplier where iProductId = %d",ProductId);
obj.ClistSupplierInfo(QueryString);
}
else if(choice=='B' || choice=='b')
{
cout << "\t\t Please enter Supplier Name :";
cin >> SupplierName;
clsConn obj;
char QueryString[1024];
sprintf(QueryString,"select * from Supplier where vSupplierName = '%s'",SupplierName);
obj.ClistSupplierInfo(QueryString);
}
else
{
clsMain obj;
obj.error(); //错误提示
}
cout << endl << "\t\t Will your begin Delete or Update operate?[Y/N]";
cout << endl << "\t\t **ANSWER:";
char answer;
cin >> answer;
if(answer=='Y' || answer=='y')
{
cout << endl << "\t\t *****************************************";
cout << endl << "\t\t --Begin Delete operate,please enter A:\n";
cout << endl << "\t\t --Begin Update operate,please enter B:\n";
cout << endl << "\t\t **ANSWER:";
char ch;
cin >> ch;
if(ch=='A' || ch=='a')
{
clsSupplier obj;
obj.deleteSupplierInfo(); //删除供应商信息
}
else if(ch=='B' || ch=='b')
{
clsSupplier obj;
obj.updateSupplierInfo(); //修改供应商信息
}
else
{
clsMain obj;
obj.error(); //错误提示
}
}
}
void clsSupplier::deleteSupplierInfo() //删除供应商信息
{
cout << "\n\n";
cout << endl << "\t\t *****************************************";
cout << endl << "\t\t * DELETE BEGIN *";
cout << endl << "\t\t *****************************************";
cout << endl << "\t\t IF your are will delete row,please enter SupplierId:";
cin >> SupplierId;
clsConn obj;
char DeleteString[1024];
sprintf(DeleteString,"delete Supplier where cSupplierId = '%s'",SupplierId);
obj.Cwork(DeleteString);
}
void clsSupplier::updateSupplierInfo() //修改供应商信息
{
cout << "\n\n";
cout << endl << "\t\t *****************************************";
cout << endl << "\t\t * UPDATE BEGIN *";
cout << endl << "\t\t *****************************************";
cout << endl << "\t\t --Please enter SupplierId for update:";
cin >> SupplierId;
cout << endl << "\t\t --Please enter will update field count:";
int count;
cin >> count;
int i;
for(i=1;i<=count;i++)
{
system("clear");
clsConn obj;
cout << endl << "\t\t *************************************";
cout << endl << "\t\t * You can update these fields *";
cout << endl << "\t\t * 1) SupplierName *";
cout << endl << "\t\t * 2) SupplierAddress *";
cout << endl << "\t\t * 3) SupplierPhone *";
cout << endl << "\t\t *************************************\n";
cout << endl << "\t\t --Please enter field number for update:";
char FieldNumber;
cin >>FieldNumber;
char *FieldName;
switch(FieldNumber)
{
case '1':
{
FieldName = "vSupplierName";
break;
}
case '2':
{
FieldName = "vSupplierAddress";
break;
}
case '3':
{
FieldName = "cSupplierPhone";
break;
}
default:
{
cout << endl << "\t\t * Without this Field *";
break;
}
}
cout << endl << "\t\t --Please enter new value:";
char NewValue[101];
cin >> NewValue;
char UpdateString[1024];
sprintf(UpdateString,"update Supplier set %s='%s' where cSupplierId='%s'",FieldName,NewValue,SupplierId);
obj.Cwork(UpdateString);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -