📄 jhunit.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "JhUnit.h"
#include "DModUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TJhForm *JhForm;
//---------------------------------------------------------------------------
__fastcall TJhForm::TJhForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
//打开数据集 SQLStr 要执行的SQL语句 LQuery 打开数据集使用的Query ErrorStr 程序出现异常时的提示信息
void __fastcall TJhForm::DisplayData(AnsiString Cpbh,AnsiString ErrorStr)
{
try
{
TLocateOptions Opts;
Opts.Clear();
Opts << loPartialKey;
Variant locvalues[1];
locvalues[0] = Variant(Cpbh);
SQLStr = "select c.name,j.* from jhb j,cpxxb c where c.cpbh=j.cpbh";
DMod->Query1->Close();
DMod->Query1->SQL->Clear();
DMod->Query1->SQL->Add(SQLStr);
DMod->Query1->Open();
if (! DMod->Query1->Eof)
DMod->Query1->Locate("Cpbh", locvalues[0], Opts);
}
catch(...)
{
ShowMessage(ErrorStr);
}
}
void __fastcall TJhForm::FormShow(TObject *Sender)
{
CpbhList = new TStringList;
GetCpbhList();
DisplayData("","读取数据出错");
}
//---------------------------------------------------------------------------
void __fastcall TJhForm::DBGrid1CellClick(TColumn *Column)
{
try
{
if(!DMod->Query1->Eof){
SelCpbh = DMod->Query1->FieldByName("cpbh")->AsString;
SelRq = DMod->Query1->FieldByName("rq")->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"]));
EditJe->Text = Trim((AnsiString)(DMod->Query1->FieldValues["je"]));
EditDr->Text = Trim((AnsiString)(DMod->Query1->FieldValues["dr"]));
EditDj->Text = Trim((AnsiString)(DMod->Query1->FieldValues["dj"]));
}
}
catch(...)
{
ShowMessage("不能正确读取数据");
}
}
//---------------------------------------------------------------------------
void __fastcall TJhForm::FormClose(TObject *Sender, TCloseAction &Action)
{
delete CpbhList;
Close();
}
//---------------------------------------------------------------------------
void __fastcall TJhForm::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 TJhForm::BitBtn1Click(TObject *Sender)
{
try
{
AnsiString Str,T;
if(EditSl->Text == ""){
ShowMessage("数量不能为空");
return;
}
T = DateTimePicker1->Date.DateString();
Str = "insert into jhb (cpbh,sl,je,dr,dj,rq) values(";
Str = Str + "'%s',%d,%f,%d,%d,'%s')";
SQLStr = Format(Str,OPENARRAY(TVarRec,(CpbhList->Strings[ComboBox1->ItemIndex],
StrToInt(EditSl->Text),StrToFloat(EditJe->Text),
StrToInt(EditDr->Text),StrToInt(EditDj->Text),T)));
DMod->ExecuteSQL(SQLStr,"不能正确增加进货信息");
DisplayData(CpbhList->Strings[ComboBox1->ItemIndex],"不能正确显示数据");
}
catch(...)
{
ShowMessage("不能正确增加数据");
}
}
//---------------------------------------------------------------------------
void __fastcall TJhForm::EditSlKeyPress(TObject *Sender, char &Key)
{
if((Key < '0' || Key > '9') && Key != VK_BACK ) Key = 0;
}
//---------------------------------------------------------------------------
void __fastcall TJhForm::BitBtn4Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TJhForm::BitBtn2Click(TObject *Sender)
{
try
{
AnsiString Str,T;
if(SelCpbh == ""){
ShowMessage("没有选中要更新的记录");
return;
}
T = DateTimePicker1->Date.DateString();
Str = "update jhb set cpbh='%s',sl=%d,je=%f,dr=%d,dj=%d,rq='%s' ";
Str = Str + "where cpbh='%s' and rq='%s'";
SQLStr = Format(Str,OPENARRAY(TVarRec,(CpbhList->Strings[ComboBox1->ItemIndex],StrToInt(EditSl->Text),
StrToFloat(EditJe->Text),StrToInt(EditDr->Text),StrToInt(EditDj->Text),
T,SelCpbh,SelRq)));
DMod->ExecuteSQL(SQLStr,"不能正确修改信息");
DisplayData(CpbhList->Strings[ComboBox1->ItemIndex],"不能正确显示数据");
}
catch(...)
{
ShowMessage("不能正确修改数据");
}
}
//---------------------------------------------------------------------------
void __fastcall TJhForm::BitBtn3Click(TObject *Sender)
{
try
{
if(SelCpbh == ""){
ShowMessage("请选择要删除的记录");
return;
}
if(Application->MessageBox("真的要删除记录吗", "提示", MB_OKCANCEL)== IDOK){
SQLStr = Format("delete from jhb where cpbh='%s' and rq='%s'",OPENARRAY(TVarRec,(SelCpbh,SelRq)));
DMod->ExecuteSQL(SQLStr,"不能正确删除数据") ;
EditSl->Text = "";
EditJe->Text = "";
EditDr->Text = "";
EditDj->Text = "";
DateTimePicker1->Date = Now();
DisplayData("","不能正确显示数据");
}
}
catch(...)
{
ShowMessage("不能正确删除数据");
}
}
//---------------------------------------------------------------------------
void __fastcall TJhForm::EditJeKeyPress(TObject *Sender, char &Key)
{
if((Key < '0' || Key > '9') && Key != VK_BACK && Key != '.') Key = 0;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -