📄 shophelp.cpp
字号:
#include"PassWord.h"
#include"Query4_0.h"
#include"Query4_2.h"
#ifndef HIS
#include"../ClassHead/User.hpp"
#include"../ClassHead/Hospitalize.hpp"
#endif
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ShopHelp.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
extern void HISQuery(TQuery* qPtr,String& s,bool b);
extern void logout(User* u,TForm* form,TQuery* query);
extern const unsigned MedNum;
extern User* currentUser;
extern bool isInteger(AnsiString str,bool minus);
static TQueryForm4_0* QForm1=NULL;
static TQueryForm4_4* QForm2=NULL;
static Shoper currEmp;
static List* currList=NULL;
static TDataSet* DSPtr=NULL;
static int i=0;
static int flag=0;
static double pa[20];
void clearInfo(TShopHelpForm* ptr)
{
ptr->LabeledEdit1->Text="";
ptr->LabeledEdit2->Text="";
ptr->LabeledEdit3->Text="";
ptr->LabeledEdit4->Text="";
ptr->LabeledEdit6->Text="";
ptr->MemoRecipeH1->Text="";
ptr->MemoRecipeH3->Text="";
ptr->MemoRecipe->Text="";
ptr->MedNumList->ItemIndex=0;
ptr->LabeledPay->Text="";
}
TShopHelpForm *ShopHelpForm;
//---------------------------------------------------------------------------
__fastcall TShopHelpForm::TShopHelpForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TShopHelpForm::FormCreate(TObject *Sender)
{
QForm1=new TQueryForm4_0(this);
QForm2=new TQueryForm4_4(this);
}
//---------------------------------------------------------------------------
void __fastcall TShopHelpForm::FormActivate(TObject *Sender)
{
String sql,s1,s2,s3,sName;
currentUser->setStartTime();
if(currEmp.getEmpID()==0)
{
String name=currentUser->getName();
currEmp.setData(currentUser->getEmpID(),name);
showname->Caption=IntToStr(currentUser->getEmpID())+" "+name;
}
MemoRecipeH1->Text=" 校园小店 购物单";
MemoRecipeH3->Text=" 商品名 数量 单价";
LabeledEdit6->Visible=false;
Button3->Visible=false;
}
//---------------------------------------------------------------------------
void __fastcall TShopHelpForm::FormDestroy(TObject *Sender)
{
delete QForm1;
}
//---------------------------------------------------------------------------
void __fastcall TShopHelpForm::Timer1Timer(TObject *Sender)
{
showtime->Caption=Now().CurrentDateTime();
}
//---------------------------------------------------------------------------
void __fastcall TShopHelpForm::LabeledEdit1KeyDown(TObject *Sender,
WORD &Key, TShiftState Shift)
{
TField*f,*f1,*f2,*f3;
if(Key==13)
{
if(LabeledEdit1->Text!="")
{
if(isInteger(LabeledEdit1->Text,false))
{
String s1=LabeledEdit1->Text;
String sql="select*from Card where cardID="+s1;
HISQuery(Query4,sql,true);
if(Query4->IsEmpty())
{ShowMessage("无此学生!");Query4->Close();}
else
{
f=Query4->FieldByName("schoolID");
String s2=f->AsString;
sql="select*from Student where schoolID="+s2;
HISQuery(Query3,sql,true);
f1=Query3->FieldByName("name");
f2=Query3->FieldByName("sex");
f3=Query4->FieldByName("moneyLeft");
LabeledEdit2->Text=f1->AsString;
LabeledEdit3->Text=f2->AsString;
LabeledEdit4->Text=f3->AsString;
Query3->Close();
Query4->Close();
i=0;
int n1=(LabeledEdit1->Text).ToInt();
String n2=LabeledEdit2->Text;
currList=new List(n1,n2,currEmp.getEmpID());
}
}
else
{ShowMessage("卡号非法,必须是整型数!");}
}
else
{ShowMessage("请先输入卡号后按回车确定!");}
}
}
//---------------------------------------------------------------------------
void __fastcall TShopHelpForm::DBGrid1CellClick(TColumn *Column)
{
DSPtr=DBGrid1->DataSource->DataSet;
DSPtr->GotoBookmark((void*)DBGrid1->SelectedRows->Items[0].c_str());
int rows=DBGrid1->SelectedRows->Count;
if(rows>0)
{
if(LabeledEdit1->Text!="")
{
if(isInteger(LabeledEdit1->Text,false))
{
int max=currList->medMax,number,amountNum;
String s0,s1,s2,s3;
double pay;
if(i<max)
{
if(rows>0)
{
number=StrToInt(MedNumList->Text);
amountNum=DSPtr->Fields->Fields[3]->AsInteger;
if(number<amountNum)
{
s0=DSPtr->Fields->Fields[0]->AsInteger;
s1=DSPtr->Fields->Fields[1]->AsInteger;
s2=DSPtr->Fields->Fields[2]->AsInteger;
(currList->getMedPtr())[i].setData(s0,s1,number,s2);
pa[i]=DSPtr->Fields->Fields[4]->AsFloat;
pay=DSPtr->Fields->Fields[4]->AsFloat;
currList->setPay(currList->getPay()+number*pay);
LabeledPay->Text=currList->getPay();
int l=(currList->getMedPtr())[i].getName().Length();
for(s0=" ",l=60-1;l>0;--l)s0+=' ';
s0=" "+s1+s0+MedNumList->Text+" "+s2;
MemoRecipe->Lines->Add(s0);
++i;
}
else{ShowMessage("该商品的库存量已达最低警示,不能提供此商品!");}
}
}
else{ShowMessage("一张购物清单最多限定开"+IntToStr(currList->medMax)+"件商品!");}
}
else{ShowMessage("卡号非法,必须是整型数!");}
}
else{ShowMessage("请先输入卡号后按回车确定!");}
}
}
//---------------------------------------------------------------------------
void __fastcall TShopHelpForm::Button1Click(TObject *Sender)
{
TField*f;
if(LabeledEdit2->Text!="")
{
String s1=LabeledEdit1->Text;
String sql="select*from Card where cardID="+s1;
HISQuery(Query4,sql,true);
double num=(LabeledPay->Text).ToDouble();
f=Query4->FieldByName("moneyLeft");
double mon=f->AsFloat;
if(mon-num<0)
{ShowMessage("余额不足,请先充值!");}
else
{
if(num<50)
{
sql="update Card set moneyLeft=moneyLeft-("+LabeledPay->Text+") where cardID='"+s1+"'";
HISQuery(Query4,sql,false);
currEmp.addStudentSum();
currEmp.addMoneySum(num);
{ShowMessage("刷卡完成!");}
flag=0;
Button3->Visible=true;
MemoRecipe->Text="";
MedNumList->ItemIndex=0;
sql="select*from Card where cardID="+s1;
HISQuery(Query4,sql,true);
f=Query4->FieldByName("moneyLeft");
LabeledEdit4->Text=f->AsString;
String ql,id;
int max=currList->medMax,num,i;
for(i=0;i<max;++i)
{
id=(currList->getMedPtr()[i]).getID();
if(id==""){break;}
else
{
num=(currList->getMedPtr()[i]).getAmount();
ql="update StorageGoods set amount=amount-("+IntToStr(num)+") where ID='"+id+"'";
HISQuery(Query6,ql,false);
String a=currList->getMedPtr()[i].getID();
String b=currList->getMedPtr()[i].getName();
String c=currList->getMedPtr()[i].getAmount();
String d=pa[i];
sql="insert into Record(cardID,useTime,goodsNo,goodsname,amount,shop,inType,inMoney)values('"+LabeledEdit1->Text+"','"+Now().CurrentDateTime()+"','"+a+"','"+b+"','"+c+"','"+"1"+"','"+"3"+"','"+d+"')";
HISQuery(Query7,sql,false);
Query6->Close();
Query7->Close();
}
}
delete currList;
currList==NULL;
for(int i=0;i<20;i++)
{pa[i]=0;}
}
else
{
ShowMessage("请先在输入密码区域输入学生卡密码。");
LabeledEdit6->Visible=true;
}
}
}
else
{ShowMessage("请先输入卡号后按回车确定!");}
Query4->Close();
}
//---------------------------------------------------------------------------
void __fastcall TShopHelpForm::LabeledEdit6KeyDown(TObject *Sender,
WORD &Key, TShiftState Shift)
{
TField*f;
TField*f1;
if(Key==13)
{
if(LabeledEdit2->Text!="")
{
String s1=LabeledEdit1->Text;
String sql="select*from Card where cardID="+s1;
HISQuery(Query4,sql,true);
double num=(LabeledPay->Text).ToDouble();
f=Query4->FieldByName("moneyLeft");
double mon=f->AsFloat;
if(mon-num<0)
{ShowMessage("余额不足,请先充值!");}
else
{
f1=Query4->FieldByName("code");
double c1=f1->AsFloat;
double c2=(LabeledEdit6->Text).ToDouble();
if(c1==c2)
{
sql="update Card set moneyLeft=moneyLeft-("+LabeledPay->Text+") where cardID='"+s1+"'";
HISQuery(Query4,sql,false);
currEmp.addStudentSum();
currEmp.addMoneySum(num);
{ShowMessage("刷卡完成!");}
flag=0;
Button3->Visible=true;
LabeledEdit6->Visible=false;
MemoRecipe->Text="";
MedNumList->ItemIndex=0;
sql="select*from Card where cardID="+s1;
HISQuery(Query4,sql,true);
f=Query4->FieldByName("moneyLeft");
LabeledEdit4->Text=f->AsString;
String ql,id;
int max=currList->medMax,num,i;
for(i=0;i<max;++i)
{
id=(currList->getMedPtr()[i]).getID();
if(id==""){break;}
else
{
num=(currList->getMedPtr()[i]).getAmount();
ql="update StorageGoods set amount=amount-("+IntToStr(num)+") where ID='"+id+"'";
HISQuery(Query6,ql,false);
String a=currList->getMedPtr()[i].getID();
String b=currList->getMedPtr()[i].getName();
String c=currList->getMedPtr()[i].getAmount();
String d=pa[i];
sql="insert into Record(cardID,useTime,goodsNo,goodsname,amount,shop,inType,inMoney)values('"+LabeledEdit1->Text+"','"+Now().CurrentDateTime()+"','"+a+"','"+b+"','"+c+"','"+"1"+"','"+"3"+"','"+d+"')";
HISQuery(Query7,sql,false);
Query6->Close();
Query7->Close();
}
}
delete currList;
currList==NULL;
for(int i=0;i<20;i++)
{pa[i]=0;}
}
else
{
ShowMessage("密码错误,请重新输入!");
LabeledEdit6->Text="";
}
}
}
else
{ShowMessage("请先输入卡号后按回车确定!");}
Query4->Close();
}
}
//---------------------------------------------------------------------------
void __fastcall TShopHelpForm::Button3Click(TObject *Sender)
{
if(flag==0)
{
TField*f;
String sql;
String s1=LabeledEdit1->Text;
sql="update Card set moneyLeft=moneyLeft+("+LabeledPay->Text+") where cardID='"+s1+"'";
HISQuery(Query2,sql,false);
sql="insert into Record(cardID,useTime,shop,inType,inMoney)values('"+s1+"','"+Now().CurrentDateTime()+"','"+"2"+"','"+"0"+"','"+LabeledPay->Text+"')";
HISQuery(Query3,sql,false);
sql="select*from Card where cardID="+s1;
HISQuery(Query2,sql,true);
f=Query2->FieldByName("moneyLeft");
LabeledEdit4->Text=f->AsString;
ShowMessage("上次刷卡已撤销!");
flag=1;
String ql,id;
int max=currList->medMax,num,i;
for(i=0;i<max;++i)
{
id=(currList->getMedPtr()[i]).getID();
if(id==""){break;}
else
{
num=(currList->getMedPtr()[i]).getAmount();
ql="update StorageGoods set amount=amount+("+IntToStr(num)+") where ID='"+id+"'";
HISQuery(Query6,ql,false);
Query6->Close();
}
}
}
else
{ShowMessage("不能再次撤销!");}
}
//---------------------------------------------------------------------------
void __fastcall TShopHelpForm::N2Click(TObject *Sender)
{
currEmp.clearData();
clearInfo(this);
logout(currentUser,this,PassWordForm->Query1);
}
//---------------------------------------------------------------------------
void __fastcall TShopHelpForm::N14Click(TObject *Sender)
{
PassWordForm->Close();
}
//---------------------------------------------------------------------------
void __fastcall TShopHelpForm::N5Click(TObject *Sender)
{
QForm1->Visible=true;
}
//---------------------------------------------------------------------------
void __fastcall TShopHelpForm::N7Click(TObject *Sender)
{
ShowMessage("开始工作时间:"+currentUser->getStartTime().TimeString());
}
//---------------------------------------------------------------------------
void __fastcall TShopHelpForm::N9Click(TObject *Sender)
{
ShowMessage("刷卡人数:"+IntToStr(currEmp.getSSum()));
}
//---------------------------------------------------------------------------
void __fastcall TShopHelpForm::N13Click(TObject *Sender)
{
ShowMessage("刷卡总金额:"+String(currEmp.getMSum()));
}
//---------------------------------------------------------------------------
void __fastcall TShopHelpForm::N11Click(TObject *Sender)
{
Application->HelpContext(14);
}
//---------------------------------------------------------------------------
void __fastcall TShopHelpForm::N12Click(TObject *Sender)
{
Application->HelpContext(15);
}
//---------------------------------------------------------------------------
void __fastcall TShopHelpForm::N16Click(TObject *Sender)
{
Application->HelpContext(27);
}
//---------------------------------------------------------------------------
void __fastcall TShopHelpForm::N17Click(TObject *Sender)
{
QForm2->Show();
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -