📄 unit1.~cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMain *Main;
//---------------------------------------------------------------------------
__fastcall TMain::TMain(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMain::N2Click(TObject *Sender)
{
int i;
int Exist=0;
for(i=0;i<MDIChildCount;i++)
{
if(MDIChildren[i]->Caption=="连接")
{
Exist=1;
break;
}
}
if(Exist==1||this->ADOConnection1->Connected==true)
{
MessageBox(this->Handle,"你已经登陆或已打开!","提示信息",MB_OK);
return;
}
TLink *wnd;
wnd=new TLink(Application);
wnd->Left=172;
wnd->Top=172;
wnd->Height=103;
wnd->Width=256;
wnd->Show();
}
//---------------------------------------------------------------------------
void __fastcall TMain::N3Click(TObject *Sender)
{
this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TMain::btnMLOOKClick(TObject *Sender)
{
if(this->edtDATEF->Text!=""&&this->edtDATEL->Text!="")
{
String sql="select * from 客户资料 where 1=1";
sql=sql+" and 翻修日期>='"+this->edtDATEF->Text+"'and 翻修日期<='"+this->edtDATEL->Text+"'";
//sql=sql+" and 日期='"+this->edtDATEF->Text+"'";
this->ADOQuery1->SQL->Clear();
this->ADOQuery1->SQL->Add(sql);
this->ADOQuery1->ExecSQL();
this->ADOQuery1->Close();
this->ADOQuery1->Open();
this->ADOQuery1->First();
this->ADOQuery1->Active=true;
this->Caption="客户管理 当前记录共 "+IntToStr(this->ADOQuery1->RecordCount)+"条";
}
else
{
ShowMessage("日期范围不能为空 ^_^ ");
}
}
//---------------------------------------------------------------------------
void __fastcall TMain::btnLOOKClick(TObject *Sender)
{
String sql="";
sql="select * from 客户资料 where 1=1";
if(this->cbCARN->Text!="")sql=sql + " and 车牌号 like '%"+this->cbCARN->Text+"%'";
if(this->cbDATE->Text!="")sql=sql + " and 轮胎品牌 like '%"+this->cbDATE->Text+"%'";
this->ADOQuery1->SQL->Clear();
this->ADOQuery1->SQL->Add(sql);
try
{
this->ADOQuery1->ExecSQL();
this->ADOQuery1->Close();
this->ADOQuery1->Open();
this->Caption="客户管理 当前记录共 "+IntToStr(this->ADOQuery1->RecordCount)+"条";
}
catch(...)
{
this->cbCARN->Text="";
this->cbDATE->Text="";
this->cbCARN->SetFocus();
MessageBox(this->Handle,"查询信息有误","信息提示",MB_OK);
}
}
//---------------------------------------------------------------------------
void __fastcall TMain::dtp_DateFChange(TObject *Sender)
{
String Date=this->dtp_DateF->Date;
if(Date.SubString(6,2)=="10"||Date.SubString(6,2)=="11"||Date.SubString(6,2)=="12")
{
if(Date.SubString(9,1)<="9"&&Date.Length()==9)
this->edtDATEF->Text=Date.SubString(0,4)+Date.SubString(6,2)+"0"+Date.SubString(9,1);
else
this->edtDATEF->Text=Date.SubString(0,4)+Date.SubString(6,2)+Date.SubString(9,2);
}
else
{
if(Date.SubString(8,1)<="2")
{
if(Date.SubString(8,1)=="1"&&Date.Length()==8||Date.SubString(8,1)=="2"&&Date.Length()==8)
this->edtDATEF->Text=Date.SubString(0,4)+"0"+Date.SubString(6,1)+"0"+Date.SubString(8,1);
else
this->edtDATEF->Text=Date.SubString(0,4)+"0"+Date.SubString(6,1)+Date.SubString(8,2);
}
else
{
if(Date.SubString(8,1)=="3"&&Date.Length()==9)
this->edtDATEF->Text=Date.SubString(0,4)+"0"+Date.SubString(6,1)+Date.SubString(8,2);
else
this->edtDATEF->Text=Date.SubString(0,4)+"0"+Date.SubString(6,1)+"0"+Date.SubString(8,1);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TMain::dtp_DateLChange(TObject *Sender)
{
String Date=this->dtp_DateL->Date;
if(Date.SubString(6,2)=="10"||Date.SubString(6,2)=="11"||Date.SubString(6,2)=="12")
{
if(Date.SubString(9,1)<="9"&&Date.Length()==9)
this->edtDATEL->Text=Date.SubString(0,4)+Date.SubString(6,2)+"0"+Date.SubString(9,1);
else
this->edtDATEL->Text=Date.SubString(0,4)+Date.SubString(6,2)+Date.SubString(9,2);
}
else
{
if(Date.SubString(8,1)<="2")
{
if(Date.SubString(8,1)=="1"&&Date.Length()==8||Date.SubString(8,1)=="2"&&Date.Length()==8)
this->edtDATEL->Text=Date.SubString(0,4)+"0"+Date.SubString(6,1)+"0"+Date.SubString(8,1);
else
this->edtDATEL->Text=Date.SubString(0,4)+"0"+Date.SubString(6,1)+Date.SubString(8,2);
}
else
{
if(Date.SubString(8,1)=="3"&&Date.Length()==9)
this->edtDATEL->Text=Date.SubString(0,4)+"0"+Date.SubString(6,1)+Date.SubString(8,2);
else
this->edtDATEL->Text=Date.SubString(0,4)+"0"+Date.SubString(6,1)+"0"+Date.SubString(8,1);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TMain::Button8Click(TObject *Sender)
{
try
{
this->ADOQuery1->First();
}
catch(...)
{
ShowMessage("请先连接数据库!");
}
}
//---------------------------------------------------------------------------
void __fastcall TMain::Button7Click(TObject *Sender)
{
try
{
if(this->ADOQuery1->Bof==true)
{
this->ADOQuery1->Last();
}
else
{
this->ADOQuery1->Prior();
}
}
catch(...)
{
ShowMessage("请先连接数据库!");
}
}
//---------------------------------------------------------------------------
void __fastcall TMain::Button5Click(TObject *Sender)
{
try
{
if(this->ADOQuery1->Eof==true)
{
this->ADOQuery1->First();
}
else
{
this->ADOQuery1->Next();
}
}
catch(...)
{
ShowMessage("请先连接数据库!");
}
}
//---------------------------------------------------------------------------
void __fastcall TMain::Button6Click(TObject *Sender)
{
try
{
this->ADOQuery1->Last();
}
catch(...)
{
ShowMessage("请先连接数据库!");
}
}
//---------------------------------------------------------------------------
void __fastcall TMain::Button10Click(TObject *Sender)
{
this->ADOQuery1->SQL->Clear();
this->ADOQuery1->SQL->Add("select * from 客户资料");
this->ADOQuery1->ExecSQL();
this->ADOQuery1->Close();
this->ADOQuery1->Open();
this->Caption="客户管理 当前记录共 "+IntToStr(this->ADOQuery1->RecordCount)+"条";
this->ADOQuery1->First();
}
//---------------------------------------------------------------------------
void __fastcall TMain::Button1Click(TObject *Sender)
{
try
{
this->ADOQuery1->Cancel();
this->DBEdit1->Text="";
this->DBEdit2->Text="";
this->DBEdit3->Text="";
this->DBEdit4->Text="";
this->DBEdit5->Text="";
this->DBEdit6->Text="";
this->DBEdit7->Text="";
this->DBEdit8->Text="";
this->DBEdit1->SetFocus();
this->Button3->Caption="保存";
this->ADOQuery1->Insert();
String date=FormatDateTime("yyyymmdd",Date());
this->DBEdit8->Text=date;
}
catch(...)
{
ShowMessage("请先连接数据库!");
}
}
//---------------------------------------------------------------------------
void __fastcall TMain::Button2Click(TObject *Sender)
{
try
{
this->ADOQuery1->Delete();
this->Caption="客户管理 当前记录共 "+IntToStr(this->ADOQuery1->RecordCount)+"条";
ShowMessage("删除成功!");
}
catch(...)
{
ShowMessage("请先连接数据库!");
}
}
//---------------------------------------------------------------------------
void __fastcall TMain::Button4Click(TObject *Sender)
{
try
{
this->Button3->Caption="修改";
this->ADOQuery1->Cancel();
}
catch(...)
{
ShowMessage("请先连接数据库!");
}
}
//---------------------------------------------------------------------------
void __fastcall TMain::Button3Click(TObject *Sender)
{
try
{
this->Button3->Caption="修改";
this->ADOQuery1->Post();
ShowMessage("保存成功!");
this->Caption="客户管理 当前记录共 "+IntToStr(this->ADOQuery1->RecordCount)+"条";
}
catch(...)
{
ShowMessage("请先连接数据库!");
}
}
void __fastcall TMain::FormCreate(TObject *Sender)
{
//this->ADOQuery1->Active=true;
//this->Caption="客户管理 当前记录共 "+IntToStr(this->ADOQuery1->RecordCount)+"条";
}
//---------------------------------------------------------------------------
void __fastcall TMain::cbDATEDropDown(TObject *Sender)
{
String sql="select * from 客户资料";
this->ADOQuery1->SQL->Clear();
this->ADOQuery1->SQL->Add(sql);
this->ADOQuery1->ExecSQL();
this->ADOQuery1->Close();
this->ADOQuery1->Open();
this->ADOQuery1->First();
this->cbDATE->Items->Clear();
for(int i=0;i<this->ADOQuery1->RecordCount;i++)
{
String mode=this->ADOQuery1->FieldValues["轮胎品牌"];
this->cbDATE->Items->Add(mode);
this->ADOQuery1->Next();
}
}
//---------------------------------------------------------------------------
void __fastcall TMain::cbCARNDropDown(TObject *Sender)
{
String sql="select * from 客户资料";
this->ADOQuery1->SQL->Clear();
this->ADOQuery1->SQL->Add(sql);
this->ADOQuery1->ExecSQL();
this->ADOQuery1->Close();
this->ADOQuery1->Open();
this->ADOQuery1->First();
this->cbCARN->Items->Clear();
for(int i=0;i<this->ADOQuery1->RecordCount;i++)
{
String mode=this->ADOQuery1->FieldValues["车牌号"];
this->cbCARN->Items->Add(mode);
this->ADOQuery1->Next();
}
}
//---------------------------------------------------------------------------
void __fastcall TMain::cbDATEChange(TObject *Sender)
{
this->cbCARN->Text="";
}
//---------------------------------------------------------------------------
void __fastcall TMain::cbCARNChange(TObject *Sender)
{
this->cbDATE->Text="";
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -