📄 ghbunit.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "GhbUnit.h"
#include "DModUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TGhbForm *GhbForm;
//---------------------------------------------------------------------------
__fastcall TGhbForm::TGhbForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TGhbForm::DisplayData(AnsiString Name,AnsiString Cpbh,AnsiString Rq,AnsiString ErrorStr)
{
try
{
TLocateOptions Opts;
Opts.Clear();
Opts << loPartialKey;
Variant locvalues[1];
locvalues[0] = Variant(Cpbh);
SQLStr = "select s.name sname,c.name cname,c.sj,c.jc,c.pv,shb.* from cpxxb c,sqb s,shb ";
SQLStr = SQLStr + "where c.cpbh=shb.cpbh and s.bh=shb.rybh and s.name='%s' and shb.rq='%s'";
SQLStr = Format(SQLStr,OPENARRAY(TVarRec,(Name,Rq)));
DMod->Query1->Close();
DMod->Query1->SQL->Clear();
DMod->Query1->SQL->Add(SQLStr);
DMod->Query1->Open();
if (! DMod->Query1->Eof){
PV = DMod->Query1->FieldByName("pv")->AsFloat;
DMod->Query1->Locate("Cpbh", locvalues[0], Opts);
}
SQLStr = Format("select sum(pvzxj)sl from shb where rybh='%s' and rq='%s'",
OPENARRAY(TVarRec,(EditBh->Text,Rq)));
EditPvhj->Text = IntToStr(DMod->GetSl(SQLStr));
SQLStr = Format("select sum(ssje)sl from shb where rybh='%s' and rq='%s'",
OPENARRAY(TVarRec,(EditBh->Text,Rq)));
EditJehj->Text = IntToStr(DMod->GetSl(SQLStr));
}
catch(...)
{
ShowMessage(ErrorStr);
}
}
void __fastcall TGhbForm::GetRyInfo(AnsiString FieldName,AnsiString FieldValue)
{
try
{
SQLStr = "select bh,name,phone from sqb where %s='%s' ";
SQLStr = Format(SQLStr,OPENARRAY(TVarRec,(FieldName,FieldValue)));
DMod->Query1->Close();
DMod->Query1->SQL->Clear();
DMod->Query1->SQL->Add(SQLStr);
DMod->Query1->Open();
if (! DMod->Query1->Eof){
Xm = DMod->Query1->FieldByName("name")->AsString;
Rybh = DMod->Query1->FieldByName("bh")->AsString;
Phone = DMod->Query1->FieldByName("phone")->AsString;
}
}
catch(...)
{
ShowMessage("不能正确读入申请人信息");
}
}
void __fastcall TGhbForm::EditNameExit(TObject *Sender)
{
try
{
Rybh = ""; Phone = "";
GetRyInfo("name",EditName->Text);
EditBh->Text = Rybh;
EditPhone->Text = Phone;
T = DateTimePicker1->Date.DateString();
DisplayData(EditName->Text,"",T,"不能正确显示数据");
}
catch(...)
{
;
}
}
//---------------------------------------------------------------------------
void __fastcall TGhbForm::EditBhExit(TObject *Sender)
{
try
{
Xm = ""; Phone = "";
GetRyInfo("bh",EditBh->Text);
EditName->Text = Xm;
EditPhone->Text = Phone;
T = DateTimePicker1->Date.DateString();
DisplayData(EditName->Text,"",T,"不能正确显示数据");
}
catch(...)
{
;
}
}
//---------------------------------------------------------------------------
void __fastcall TGhbForm::FormShow(TObject *Sender)
{
try
{
CpbhList = new TStringList;
GetCpbhList();
DateTimePicker1->Date = Now();
}
catch(...)
{
ShowMessage("程序异常");
}
}
//---------------------------------------------------------------------------
void __fastcall TGhbForm::FormClose(TObject *Sender, TCloseAction &Action)
{
delete CpbhList;
}
//---------------------------------------------------------------------------
void __fastcall TGhbForm::GetCpbhList(void)
{
try
{
ComboBox1->Clear();
DMod->QueryTemp->Close();
DMod->QueryTemp->SQL->Clear();
DMod->QueryTemp->SQL->Add("select name,cpbh from cpxxb order by xh");
DMod->QueryTemp->Open();
while(! DMod->QueryTemp->Eof){
CpbhList->Add(AnsiString(DMod->QueryTemp->FieldValues["cpbh"]));
ComboBox1->Items->Add(AnsiString(DMod->QueryTemp->FieldValues["name"]));
DMod->QueryTemp->Next();
}
if(ComboBox1->Items->Count > 0) ComboBox1->ItemIndex = 0;
}
catch(...)
{
ShowMessage("取产品编号信息出错");
}
}
void __fastcall TGhbForm::ComboBox1Click(TObject *Sender)
{
try
{
T = DateTimePicker1->Date.DateString();
SQLStr = "insert into shb (rybh,cpbh,rq) values('%s','%s','%s')";
SQLStr = Format(SQLStr,OPENARRAY(TVarRec,(Rybh,CpbhList->Strings[ComboBox1->ItemIndex],T)));
DMod->ExecuteSQL(SQLStr,"不能正确写入数据");
DisplayData( EditName->Text,CpbhList->Strings[ComboBox1->ItemIndex],T,"不能正确显示数据");
}
catch(...)
{
ShowMessage("不能正确写入数据");
}
}
//---------------------------------------------------------------------------
void __fastcall TGhbForm::BitBtn1Click(TObject *Sender)
{
try
{
AnsiString Str;
if(CpbhList->Strings[ComboBox1->ItemIndex] == ""){
ShowMessage("没有选中产品");
return;
}
T = DateTimePicker1->Date.DateString();
Str = "update shb set sl=%d,pvzxj=%f,ssje=%f,cfwz='%s', diaoc=%d,duic=%d ";
Str = Str + "where rybh='%s' and cpbh='%s' and rq='%s'";
SQLStr = Format(Str,OPENARRAY(TVarRec,(StrToInt(EditSl->Text),
PV * StrToInt(EditSl->Text),StrToFloat(EditSsje->Text),
EditCfwz->Text,StrToInt(EditDiaoC->Text),StrToInt(EditDuiC->Text),
EditBh->Text,CpbhList->Strings[ComboBox1->ItemIndex],T)));
DMod->ExecuteSQL(SQLStr,"不能正确写入数据");
DisplayData(EditName->Text,CpbhList->Strings[ComboBox1->ItemIndex],T,"不能正确显示数据");
}
catch(...)
{
ShowMessage("不能正确写入数据");
}
}
//---------------------------------------------------------------------------
void __fastcall TGhbForm::DBGrid1CellClick(TColumn *Column)
{
try
{
if(!DMod->Query1->Eof){
SelCpbh = DMod->Query1->FieldByName("cpbh")->AsString;
SelRq = DMod->Query1->FieldByName("rq")->AsString;
SelRybh = DMod->Query1->FieldByName("rybh")->AsString;
for(int i=0;i<CpbhList->Count-1;i++){
if(SelCpbh == CpbhList->Strings[i]){
ComboBox1->ItemIndex = i;
break;
}
}
DateTimePicker1->Date = DMod->Query1->FieldValues["rq"];
EditSl->Text = Trim((AnsiString)(DMod->Query1->FieldValues["sl"]));
EditSsje->Text = Trim((AnsiString)(DMod->Query1->FieldValues["ssje"]));
EditDiaoC->Text = Trim((AnsiString)(DMod->Query1->FieldValues["diaoc"]));
EditDuiC->Text = Trim((AnsiString)(DMod->Query1->FieldValues["duic"]));
}
}
catch(...)
{
ShowMessage("不能正确读取数据");
}
}
//---------------------------------------------------------------------------
void __fastcall TGhbForm::BitBtn2Click(TObject *Sender)
{
try
{
AnsiString Str,T;
if(SelCpbh == ""){
ShowMessage("没有选中要更新的记录");
return;
}
T = DateTimePicker1->Date.DateString();
Str = "update shb set cpbh='%s',sl=%d,pvzxj=%f,ssje=%f,cfwz='%s',diaoc=%d,duic=%d,rq='%s' ";
Str = Str + "where rybh='%s' and cpbh='%s' and rq='%s'";
SQLStr = Format(Str,OPENARRAY(TVarRec,(CpbhList->Strings[ComboBox1->ItemIndex],StrToInt(EditSl->Text),
PV * StrToInt(EditSl->Text),StrToFloat(EditSsje->Text),
EditCfwz->Text,StrToInt(EditDiaoC->Text),StrToInt(EditDuiC->Text),T ,
SelRybh,SelCpbh,SelRq)));
DMod->ExecuteSQL(SQLStr,"不能正确修改信息");
DisplayData(EditName->Text,"",SelRq,"不能正确显示数据");
}
catch(...)
{
ShowMessage("不能正确修改数据");
}
}
//---------------------------------------------------------------------------
void __fastcall TGhbForm::BitBtn3Click(TObject *Sender)
{
try
{
if(SelCpbh == ""){
ShowMessage("请选择要删除的记录");
return;
}
if(Application->MessageBox("真的要删除记录吗", "提示", MB_OKCANCEL)== IDOK){
SQLStr = Format("delete from shb where rybh='%s' and cpbh='%s' and rq='%s'",
OPENARRAY(TVarRec,(SelRybh,SelCpbh,SelRq)));
DMod->ExecuteSQL(SQLStr,"不能正确删除数据") ;
EditSl->Text = "";
EditSsje->Text = "";
EditDiaoC->Text = "";
EditDuiC->Text = "";
DateTimePicker1->Date = Now();
DisplayData(EditName->Text,"",SelRq,"不能正确显示数据");
}
}
catch(...)
{
ShowMessage("不能正确删除数据");
}
}
//---------------------------------------------------------------------------
void __fastcall TGhbForm::DateTimePicker1Change(TObject *Sender)
{
T = DateTimePicker1->Date.DateString();
DisplayData(EditName->Text,"",T,"不能正确显示数据");
}
//---------------------------------------------------------------------------
void __fastcall TGhbForm::BitBtn4Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TGhbForm::ComboBox1Change(TObject *Sender)
{
EditSl->Text = "";
EditSsje->Text = "";
EditDiaoC->Text = "";
EditDuiC->Text = "";
}
//---------------------------------------------------------------------------
void __fastcall TGhbForm::EditNameKeyPress(TObject *Sender, char &Key)
{
if(Key == VK_RETURN)EditNameExit(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TGhbForm::EditBhKeyPress(TObject *Sender, char &Key)
{
if(Key == VK_RETURN)EditBhExit(Sender);
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -