📄 clstrade.cpp
字号:
/***********************************
* 模块名称:clsTrade.cpp *
* 模块功能: clsTrade 类 类体 *
* 作者:刘鑫锐 *
* 撰写日期:2005-9-15 *
***********************************/
#include <iostream.h>
#include <stdlib.h>
#include "head/clsTrade.h" //调用 clsTrade类声明 头文件
#include "head/clsConn.h" //调用 clsConn 类声明 头文件
#include "head/clsMain.h" //调用 clsMain 类声明 头文件
void clsTrade::dispTradeMenu() //Trade 信息管理 主菜单
{
system("clear");
char choice; //定义接收选择的变量
while(1)
{
system("clear");
cout << endl << "\t\t ********************************************" << endl;
cout << endl << "\t\t * TRADE MIS MAIN MENU *" << endl;
cout << endl << "\t\t ********************************************" << endl;
cout << endl << "\t\t *** 1) TRADE INFORMATION LIST ***" << endl;
cout << endl << "\t\t *** 2) TRADE INFORMATION INSERT ***" << endl;
cout << endl << "\t\t *** 3) TRADE 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");
clsTrade obj; //创建对象
obj.listTradeInfo(); //列表显示交易信息主菜单
break;
}
case '2':
{
system("clear");
clsTrade obj; //创建对象
obj.addTradeInfo(); //添加交易信息记录
break;
}
case '3':
{
system("clear");
clsTrade obj; //创建对象
obj.queryTradeInfo(); //先查询交易信息 ,再进行修改和删除操作
break;
}
case '4':
{
system("clear");
clsMain obj;
obj.mainlist(); //返回主菜单
break;
}
default:
{
system("clear");
clsMain obj;
obj.error(); //显示错误信息
break;
}
}
}
}
void clsTrade::listTradeInfo() //交易信息列表
{
clsConn obj;
char listString[1024];
sprintf(listString,"select iTradeId,cTradeType,iProductId,mPrice,fProductCount from Trade");
obj.ClistInfo(listString);
}
void clsTrade::addTradeInfo() //添加交易信息记录
{
system("clear");
cout << "\n\n";
clsConn obj;
cout << endl << "\t\t *****************************************";
cout << endl << "\t\t * INSERT BEGIN *";
cout << endl << "\t\t *****************************************";
cout << endl << "\t\t Please enter Trade Type [IN / OUT]:";
cin >> TradeType;
cout << endl << "\t\t Please enter Trade Time [exp:2005-01-10]:";
cin >> TradeTime;
cout << endl << "\t\t Please enter Other Name:";
cin >> OtherName;
cout << endl << "\t\t Please enter Other Phone:";
cin >> OtherPhone;
cout << endl << "\t\t Please enter ProductId:";
cin >> ProductId;
cout << endl << "\t\t Please enter Product Price:";
cin >> Price;
cout << endl << "\t\t Please enter Product Count:";
cin >> ProductCount;
PriceSum = Price * ProductCount;
char InsertString[1024];
char a[5]="in";
char b[5]="out";
if(strcmp(a,TradeType)==0)
{
sprintf(InsertString,"insert into Trade values('%s','%s','%s','%s',%d,%f,%f,%f)",TradeType,TradeTime,OtherName,OtherPhone,ProductId,Price,ProductCount,PriceSum);
}
else if(strcmp(b,TradeType)==0)
{
sprintf(InsertString,"insert into Trade values('%s','%s','%s','%s',%d,%f,-%f,-%f)",TradeType,TradeTime,OtherName,OtherPhone,ProductId,Price,ProductCount,PriceSum);
}
else
{
cout << endl << "\t\t **************ERROR**********************";
}
obj.Cwork(InsertString);
}
void clsTrade::queryTradeInfo() //查询交易信息
{
char choice;
system("clear");
cout << "\n\n";
cout << endl << "\t\t *****************************************";
cout << endl << "\t\t * QUERY,UPDATE,DELETE BEGIN *";
cout << endl << "\t\t *****************************************";
cout << endl << "\t\t ASK:";
cout << endl << "\t\t Your can use ProductId or TradeTime for Query Trade!\n";
cout << endl << "\t\t --Use ProductId Query,please enter A: \n"; //根据交易的Id查询
cout << endl << "\t\t --Use TradeType Query,please enter B: \n"; //根据交易的Type查询
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 Trade where iProductId = %d",ProductId);
obj.ClistTradeInfo(QueryString);
}
else if(choice=='B' || choice=='b')
{
cout << "\t\t Please enter Trade Type :";
cin >> TradeType;
clsConn obj;
char QueryString[1024];
sprintf(QueryString,"select * from Trade where cTradeType = '%s'",TradeType);
obj.ClistTradeInfo(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')
{
clsTrade obj;
obj.deleteTradeInfo(); //删除交易信息
}
else if(ch=='B' || ch=='b')
{
clsTrade obj;
obj.updateTradeInfo(); //修改交易信息
}
else
{
clsMain obj;
obj.error(); //错误提示
}
}
}
void clsTrade::deleteTradeInfo() //删除交易信息
{
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 TradeId:";
cin >> TradeId;
clsConn obj;
char DeleteString[1024];
sprintf(DeleteString,"delete Trade where iTradeId = %d",TradeId);
obj.Cwork(DeleteString);
}
void clsTrade::updateTradeInfo() //修改交易记录
{
cout << "\n\n";
cout << endl << "\t\t *****************************************";
cout << endl << "\t\t * UPDATE BEGIN *";
cout << endl << "\t\t *****************************************";
cout << endl << "\t\t --Please enter TradeId for update:";
cin >> TradeId;
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) OtherSideName *";
cout << endl << "\t\t * 2) OtherSidePhone *";
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 = "vOtherName";
break;
}
case '2':
{
FieldName = "cOtherPhone";
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 Trade set %s='%s' where iTradeId=%d",FieldName,NewValue,TradeId);
obj.Cwork(UpdateString);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -