📄 subscibe.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "PostMain.h"
#include "Subscibe.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TOrderForm *OrderForm;
static char cType[2]="~";
//---------------------------------------------------------------------------
__fastcall TOrderForm::TOrderForm(TComponent* Owner)
: TForm(Owner)
{
Sum=0.0;
}
//---------------------------------------------------------------------------
void __fastcall TOrderForm::LabeledEdit9KeyPress(TObject *Sender,
char &Key)
{
switch(Key)
{
case VK_RETURN:
if(atoi(LabeledEdit9->Text.c_str())>0)
SendMessage(this->Handle,WM_NEXTDLGCTL,0,0);
else Key=0;
break;
case VK_BACK:
break;
case VK_TAB:
break;
default:
if (!isdigit(char(Key)) ){
Key=0;
MainForm->WarnBeep();
}
}
}
//---------------------------------------------------------------------------
void __fastcall TOrderForm::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
TStringGrid * SG = dynamic_cast<TStringGrid *>(Sender);
if(SG){
try
{
if(ARow>=SG->FixedRows && ACol>=SG->FixedCols)
{
if(ARow%2 == 0)
{
SG->Canvas->Brush->Color=(TColor) 0x00E6FADC;
//0x00FECFFD;
//0x00E6FADC; 0x00FCE2EE
}
else
{
SG->Canvas->Brush->Color=(TColor) 0x00FBEFD5;
//0x00FBEFD5;
}
}
else{
SG->Canvas->Font->Color = clBlack;
SG->Canvas->Brush->Color=(TColor)0x00DDDDDD;
}
SG->Canvas->FillRect(Rect);
DrawText(SG->Canvas->Handle, SG->Cells[ACol][ARow].c_str(), -1, (RECT*)&Rect, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
}
catch(Exception &exception)
{
Application->ShowException(&exception);
return ;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TOrderForm::FormCreate(TObject *Sender)
{
StringGrid1->Cells[0][0]="序 号";
StringGrid1->Cells[1][0]="报刊名称";
StringGrid1->Cells[2][0]="报刊编号";
StringGrid1->Cells[3][0]="发行间隔期";
StringGrid1->Cells[4][0]="单 价";
StringGrid1->Cells[5][0]="份 数";
StringGrid1->Cells[6][0]="起始月";
StringGrid1->Cells[7][0]="期 限";
StringGrid1->Cells[8][0]=" 金 额";
StringGrid2->Cells[0][0]="报刊编号";
StringGrid2->Cells[1][0]="报刊名称";
StringGrid2->Cells[2][0]="发行间隔期";
StringGrid2->Cells[3][0]="单 价";
}
//---------------------------------------------------------------------------
void TOrderForm::ChangeName()
{
if(RadioGroup1->ItemIndex){
cType[0]='^';
cType[1]=0;
}
else{
cType[0]='~';
cType[1]=0;
}
}
//--------------------------------------------------------------
void __fastcall TOrderForm::RadioGroup1Click(TObject *Sender)
{
ChangeName();
LabeledEdit5Exit(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TOrderForm::LabeledEdit5Exit(TObject *Sender)
{
String Sql="select * from Newspaper where (jianpin like '" +
LabeledEdit5->Text + "%' Or name like '" + LabeledEdit5->Text + "%' ) and code like '"
+ cType + "%'";
StringGrid2->RowCount=2;
try{
if ( MainForm->ExecuteSQL( Sql, 1 ) > 0 ){
MainForm->ADOQuery1->DisableControls();
int i=1;
while(! MainForm->ADOQuery1->Eof ){
StringGrid2->Cells[0][i]=MainForm->ADOQuery1->FieldByName( "code" )->AsString.SubString(2,11);
StringGrid2->Cells[1][i]=MainForm->ADOQuery1->FieldByName( "name" )->AsString;
StringGrid2->Cells[2][i]=MainForm->ADOQuery1->FieldByName( "period" )->AsString.Trim();
StringGrid2->Cells[3][i]=MainForm->ADOQuery1->FieldByName( "price" )->AsString;
i++;
StringGrid2->RowCount++;
for(int i=1;i<StringGrid1->ColCount;i++) StringGrid1->Cells[i][StringGrid2->RowCount]="";
MainForm->ADOQuery1->Next();
}
MainForm->ADOQuery1->EnableControls();
}
}
catch (Exception &exception)
{
Application->ShowException(&exception);
return ;
}
for(int i=0;i<StringGrid2->ColCount;i++)
StringGrid2->Cells[i][StringGrid2->RowCount-1]="";
}
//---------------------------------------------------------------------------
void __fastcall TOrderForm::LabeledEdit6KeyPress(TObject *Sender,
char &Key)
{
if(Key==VK_RETURN){
LabeledEdit6Exit(Sender);
}
}
//---------------------------------------------------------------------------
void __fastcall TOrderForm::StringGrid2Click(TObject *Sender)
{
LabeledEdit5->Text=StringGrid2->Cells[1][StringGrid2->Row];
LabeledEdit6->Text=StringGrid2->Cells[0][StringGrid2->Row];
LabeledEdit7->Text=StringGrid2->Cells[2][StringGrid2->Row];
LabeledEdit8->Text=StringGrid2->Cells[3][StringGrid2->Row];
LabeledEdit9->Enabled=true;
LabeledEdit10->Enabled=true;
LabeledEdit11->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TOrderForm::SumAndAdd()
{
double p;
int n, m;
for(int i=0;i<ComponentCount;i++) //遍历所有的LabeledEdit控件
if (Components[i]->ClassNameIs("TLabeledEdit")){
if( ((TLabeledEdit *)Components[i])->Text.IsEmpty() ) {
((TLabeledEdit *)Components[i])->SetFocus();
ShowMessage("内容不能空!");
return;
}
}
p=LabeledEdit8->Text.ToDouble();
n=LabeledEdit9->Text.ToInt();
m=LabeledEdit11->Text.ToInt();
Sum +=p*n*m*3;
LabeledEdit12->Text=p*n*m*3;
StringGrid1->Cells[0][StringGrid1->RowCount-1]=StringGrid1->RowCount-1;
StringGrid1->Cells[1][StringGrid1->RowCount-1]=LabeledEdit5->Text;
StringGrid1->Cells[2][StringGrid1->RowCount-1]=cType+LabeledEdit6->Text;
StringGrid1->Cells[3][StringGrid1->RowCount-1]=LabeledEdit7->Text;
StringGrid1->Cells[4][StringGrid1->RowCount-1]=LabeledEdit8->Text;
StringGrid1->Cells[5][StringGrid1->RowCount-1]=LabeledEdit9->Text;
StringGrid1->Cells[6][StringGrid1->RowCount-1]=LabeledEdit10->Text;
StringGrid1->Cells[7][StringGrid1->RowCount-1]=LabeledEdit11->Text;
StringGrid1->Cells[8][StringGrid1->RowCount-1]=LabeledEdit12->Text;
StringGrid1->RowCount++;
LabeledEdit9->Enabled=false;
LabeledEdit10->Enabled=false;
LabeledEdit11->Enabled=false;
LabeledEdit5->Text="";
LabeledEdit6->Text="";
LabeledEdit7->Text="";
LabeledEdit8->Text="0.0";
LabeledEdit9->Text="1";
LabeledEdit10->Text="";
LabeledEdit11->Text="";
AddBitBtn->Enabled=true;
LabeledEdit5->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TOrderForm::LabeledEdit11KeyPress(TObject *Sender,
char &Key)
{
switch(Key)
{
case VK_RETURN:
if(atoi(LabeledEdit11->Text.c_str())>0){
SumAndAdd();
}
break;
case VK_BACK:
break;
case VK_TAB:
break;
default:
if (!isdigit(char(Key)) ){
Key=0;
MainForm->WarnBeep();
}
}
}
//---------------------------------------------------------------------------
void __fastcall TOrderForm::LabeledEdit10Exit(TObject *Sender)
{
if(LabeledEdit10->Text.Length()!=6){
ShowMessage("日期格式应该是:YYYYMM");
LabeledEdit10->SetFocus();
return;
}
if(LabeledEdit10->Text.SubString(5,6)>12){
ShowMessage("月份错!");
LabeledEdit10->SetFocus();
return;
}
if(LabeledEdit10->Text < MainForm->sToday){
ShowMessage("不能小于当前年月!");
LabeledEdit10->SetFocus();
return;
}
}
//---------------------------------------------------------------------------
void __fastcall TOrderForm::LabeledEdit5KeyPress(TObject *Sender,
char &Key)
{
if(Key==VK_RETURN)
SendMessage(this->Handle,WM_NEXTDLGCTL,0,0);
}
//---------------------------------------------------------------------------
void __fastcall TOrderForm::AddBitBtnClick(TObject *Sender)
{
int ret;
ret=Application->MessageBox( "请确认是否要订阅?" , String(String("应收现金:")+ Sum).c_str(), MB_YESNO);
if(ret==IDNO) return;
String Sql0="insert into orderform (client, address, postid, telephone,date1,newspapercode, newspapername, period, price, num, date2,timelimit, amount) values";
String Sql, Sql1, Sql2;
Sql1="('"+ LabeledEdit1->Text +"','" + LabeledEdit2->Text +"','" + LabeledEdit3->Text +"','" + LabeledEdit4->Text +"','"
+ MainForm->Today ;
for(int j=1; j<StringGrid1->RowCount-1; j++){
Sql2="";
for(int i=1; i<9; i++){
Sql2=Sql2+"','"+StringGrid1->Cells[i][j];
}
Sql2=Sql2+"')";
Sql=Sql0+Sql1+Sql2;
try{
if(MainForm->ExecuteSQL( Sql, 0 ) < 0 ){
Application->MessageBox( "入库失败 !", NULL, MB_OK | MB_ICONWARNING );
}
}//try
catch(Exception &exception){
Application->ShowException(&exception);
return;
}
}
Sum=0.0;
StringGrid1->RowCount=2;
for(int i=1;i<StringGrid1->ColCount;i++) StringGrid1->Cells[i][1]="";
AddBitBtn->Enabled=false;
}
//---------------------------------------------------------------------------
void __fastcall TOrderForm::LabeledEdit6Exit(TObject *Sender)
{
String Sql="select * from Newspaper where code = '"
+ String(cType) + LabeledEdit6->Text +"'";
if (ActiveControl == CloseBitBtn) return; //关闭就不检查CODE
if(!LabeledEdit6->Text.IsEmpty()){
try{
if ( MainForm->ExecuteSQL( Sql, 1 ) > 0 ){
MainForm->ADOQuery1->DisableControls();
if(MainForm->ADOQuery1->FieldByName( "name" )->AsString.IsEmpty()){
ShowMessage("无此报刊号!");
LabeledEdit6->SetFocus();
LabeledEdit9->Enabled=false;
LabeledEdit10->Enabled=false;
LabeledEdit11->Enabled=false;
return ;
}
LabeledEdit5->Text=MainForm->ADOQuery1->FieldByName( "name" )->AsString;
LabeledEdit7->Text=MainForm->ADOQuery1->FieldByName( "period" )->AsString.Trim();
LabeledEdit8->Text=MainForm->ADOQuery1->FieldByName( "price" )->AsString;
LabeledEdit9->Enabled=true;
LabeledEdit10->Enabled=true;
LabeledEdit11->Enabled=true;
LabeledEdit9->SetFocus();
MainForm->ADOQuery1->EnableControls();
}
}
catch (Exception &exception)
{
Application->ShowException(&exception);
return ;
}
}
else{
LabeledEdit9->Enabled=false;
LabeledEdit10->Enabled=false;
LabeledEdit11->Enabled=false;
}
}
//---------------------------------------------------------------------------
void __fastcall TOrderForm::LabeledEdit9Exit(TObject *Sender)
{
if(atoi(LabeledEdit9->Text.c_str())<=0) LabeledEdit9->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TOrderForm::LabeledEdit3KeyPress(TObject *Sender,
char &Key)
{
switch(Key)
{
case VK_RETURN:
if(LabeledEdit3->Text.Length()==6)//邮编6位
SendMessage(this->Handle,WM_NEXTDLGCTL,0,0);
else{
Key=0;
MainForm->WarnBeep();
}
break;
case VK_BACK:
break;
case VK_TAB:
break;
default:
if (!isdigit(char(Key)) ){
Key=0;
MainForm->WarnBeep();
}
}
}
//---------------------------------------------------------------------------
void __fastcall TOrderForm::LabeledEdit3Change(TObject *Sender)
{
if(LabeledEdit3->Text.Length()==6)//邮编6位
SendMessage(this->Handle,WM_NEXTDLGCTL,0,0);
}
//--------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -