📄 bjwj.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ShFwMain.h"
#include "BjWj.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "ColorButton"
#pragma resource "*.dfm"
TBjWjForm *BjWjForm;
//---------------------------------------------------------------------------
__fastcall TBjWjForm::TBjWjForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TBjWjForm::FormClose(TObject *Sender, TCloseAction &Action)
{
MainForm->ADOConnection1->Close();
}
//---------------------------------------------------------------------------
void __fastcall TBjWjForm::FormCreate(TObject *Sender)
{
MainForm->ADOConnection1->Open();
RadioButton1->Checked = true;
GroupBox5->Visible = false;
Button1->Enabled = false;
ADOQuery1->Close();
ADOQuery2->Close();
ADOTable1->Close();
ADOTable1->Open();
if(ADOTable1->RecordCount > 0) {
DBLookupComboBox1->KeyValue = ADOTable1->FieldByName("flbh")->AsString;
ADOQuery2->Open();
if(ADOQuery2->RecordCount > 0) {
DBLookupComboBox2->KeyValue = ADOQuery2->FieldByName("pzbh")->AsString;
ADOQuery1->Open();
}
}
}
//---------------------------------------------------------------------------
void __fastcall TBjWjForm::DBLookupComboBox1Click(TObject *Sender)
{
ADOQuery1->Close();
ADOQuery2->Close();
if( DBLookupComboBox1->Text.Trim()=="")
Abort();
ADOQuery2->Open();
if(ADOQuery2->RecordCount > 0)
ADOQuery1->Open();
MaskEdit1->Text = "";
}
//---------------------------------------------------------------------------
void __fastcall TBjWjForm::Button1Click(TObject *Sender)
{
AnsiString str;
if(MaskEdit1->Text.Trim() == "" || MaskEdit1->Text.ToInt() < 1 ) {
Application->MessageBox("请输入数量","错误",MB_OK+MB_ICONERROR);
Abort();
}
if(RadioButton1->Checked == true) {
str="当前库存数量为"+ADOQuery1->FieldByName("kcsl")->AsString+",外借"+MaskEdit1->Text+"吗?";
if( Application->MessageBox(str.c_str(),"确认",MB_OKCANCEL+MB_ICONERROR)!=IDOK)
Abort();
if(ADOQuery1->FieldByName("kcsl")->AsString.ToInt() - MaskEdit1->Text.ToInt() < 0) {
Application->MessageBox("库存数量不足","错误",MB_OK+MB_ICONERROR);
Abort();
}
ADOQuery1->Edit();
ADOQuery1->FieldByName("kcsl")->Value = ADOQuery1->FieldByName("kcsl")->AsString.ToInt() - MaskEdit1->Text.ToInt();
ADOQuery1->FieldByName("wjsl")->Value = ADOQuery1->FieldByName("wjsl")->AsString.ToInt() + MaskEdit1->Text.ToInt();
ADOQuery1->Post();
} else {
ADOQuerytmp->Close();
ADOQuerytmp->SQL->Clear();
ADOQuerytmp->SQL->Add("select * from wxpjxx where dabh='0' and pjbh =:P_pjbh and gsfl=:P_gsfl and gspz=:P_gspz and endflag='否' and cllx='外借' order by slrq");
ADOQuerytmp->Parameters->ParamByName("P_pjbh")->Value = ADOQuery1->FieldByName("pjbh")->AsString;
ADOQuerytmp->Parameters->ParamByName("P_gsfl")->Value = ADOQuery1->FieldByName("flbh")->AsString;
ADOQuerytmp->Parameters->ParamByName("P_gspz")->Value = ADOQuery1->FieldByName("pzbh")->AsString;
ADOQuerytmp->Open();
if(ADOQuerytmp->RecordCount < 1) {
ADOQuerytmp->Close();
Application->MessageBox("没有找到该配件的外借记录","错误",MB_OK+MB_ICONERROR);
Abort();
}
GroupBox5->Visible = true;
GroupBox2->Enabled = false;
GroupBox4->Enabled = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TBjWjForm::ADOQuery1AfterPost(TDataSet *DataSet)
{
AnsiString sql;
if( RadioButton1->Checked == true ) {
ADOQuerytmp->Close();
ADOQuerytmp->SQL->Clear();
sql = "insert into wxpjxx values(:P_dabh,:P_khbh,:P_rybh,:P_clrm,:P_pjbh,:P_pjmc,:P_gsfl,:P_flmc,:P_gspz,:P_pzmc,";
sql += ":P_lx,:P_dj,:P_sl,:P_je,:P_clrq,:P_slrq,:P_cllx,:P_bz,:P_endflag,:P_sjsl,:P_cbdj,:P_lsdj)";
ADOQuerytmp->SQL->Add(sql);
ADOQuerytmp->Parameters->ParamByName("P_dabh")->Value = 0;
ADOQuerytmp->Parameters->ParamByName("P_khbh")->Value = 0;
ADOQuerytmp->Parameters->ParamByName("P_rybh")->Value = MainForm->MyLoginBh;
ADOQuerytmp->Parameters->ParamByName("P_clrm")->Value = MainForm->MyLoginName;
ADOQuerytmp->Parameters->ParamByName("P_pjbh")->Value = ADOQuery1->FieldByName("pjbh")->AsString;
ADOQuerytmp->Parameters->ParamByName("P_pjmc")->Value = ADOQuery1->FieldByName("mc")->AsString;
ADOQuerytmp->Parameters->ParamByName("P_gsfl")->Value = ADOQuery1->FieldByName("flbh")->AsString;
ADOQuerytmp->Parameters->ParamByName("P_flmc")->Value = DBLookupComboBox1->Text;
ADOQuerytmp->Parameters->ParamByName("P_gspz")->Value = ADOQuery1->FieldByName("pzbh")->AsString;
ADOQuerytmp->Parameters->ParamByName("P_pzmc")->Value = DBLookupComboBox2->Text;
ADOQuerytmp->Parameters->ParamByName("P_lx")->Value = "保修";
ADOQuerytmp->Parameters->ParamByName("P_dj")->Value = ADOQuery1->FieldByName("bxdj")->AsString;
ADOQuerytmp->Parameters->ParamByName("P_sl")->Value = MaskEdit1->Text;
ADOQuerytmp->Parameters->ParamByName("P_je")->Value = MaskEdit1->Text.ToInt() * ADOQuery1->FieldByName("bxdj")->AsFloat;
ADOQuerytmp->Parameters->ParamByName("P_clrq")->Value = Date();
ADOQuerytmp->Parameters->ParamByName("P_slrq")->Value = Date();
ADOQuerytmp->Parameters->ParamByName("P_cllx")->Value = "外借";
ADOQuerytmp->Parameters->ParamByName("P_bz")->Value = Edit1->Text;
ADOQuerytmp->Parameters->ParamByName("P_sjsl")->Value = MaskEdit1->Text;
ADOQuerytmp->Parameters->ParamByName("P_endflag")->Value = "否";
ADOQuerytmp->Parameters->ParamByName("P_cbdj")->Value = ADOQuery1->FieldByName("bxdj")->AsString;
ADOQuerytmp->Parameters->ParamByName("P_lsdj")->Value = ADOQuery1->FieldByName("lsdj")->AsString;
ADOQuerytmp->ExecSQL();
}
MaskEdit1->Text ="";
Edit1->Text ="";
}
//---------------------------------------------------------------------------
void __fastcall TBjWjForm::Button2Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TBjWjForm::Button3Click(TObject *Sender)
{
AnsiString str;
if(ADOQuerytmp->FieldByName("sl")->AsInteger < MaskEdit1->Text.ToInt()) {
Application->MessageBox("归还数量不应大于实借数","错误",MB_OK+MB_ICONWARNING);
Abort();
}
str="实借数量为"+ADOQuerytmp->FieldByName("sl")->AsString+",归还"+MaskEdit1->Text+"吗?";
if( Application->MessageBox(str.c_str(),"确认",MB_OKCANCEL+MB_ICONERROR)!=IDOK) {
GroupBox5->Visible = false;
Abort();
}
ADOQuerytmp->Edit();
if ( ADOQuerytmp->FieldByName("sl")->AsInteger == MaskEdit1->Text.ToInt() )
ADOQuerytmp->FieldByName("endflag")->AsString = "是";
ADOQuerytmp->FieldByName("sl")->AsInteger = ADOQuerytmp->FieldByName("sl")->AsInteger - MaskEdit1->Text.ToInt();
ADOQuerytmp->FieldByName("je")->AsFloat = ADOQuerytmp->FieldByName("je")->AsFloat - ADOQuery1->FieldByName("bxdj")->AsFloat * MaskEdit1->Text.ToInt();
ADOQuerytmp->FieldByName("clrq")->AsString = FormatDateTime("yyyy-mm-dd",Date());
ADOQuerytmp->Post();
ADOQuery1->Edit();
ADOQuery1->FieldByName("kcsl")->Value = ADOQuery1->FieldByName("kcsl")->AsString.ToInt() + MaskEdit1->Text.ToInt();
ADOQuery1->FieldByName("wjsl")->Value = ADOQuery1->FieldByName("wjsl")->AsString.ToInt() - MaskEdit1->Text.ToInt();
ADOQuery1->Post();
ADOQuerytmp->Close();
GroupBox5->Visible = false;
GroupBox2->Enabled = true;
GroupBox4->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TBjWjForm::Button4Click(TObject *Sender)
{
ADOQuerytmp->Close();
GroupBox5->Visible = false;
GroupBox2->Enabled = true;
GroupBox4->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TBjWjForm::DBLookupComboBox2Click(TObject *Sender)
{
ADOQuery1->Close();
if( DBLookupComboBox1->Text.Trim()=="")
Abort();
if( DBLookupComboBox2->Text.Trim()=="")
Abort();
ADOQuery1->Open();
MaskEdit1->Text = "";
}
//---------------------------------------------------------------------------
void __fastcall TBjWjForm::DataSource4StateChange(TObject *Sender)
{
if(ADOQuery1->State == dsBrowse ) {
if(ADOQuery1->RecordCount > 0)
Button1->Enabled = true;
else
Button1->Enabled = false;
} else
Button1->Enabled = false;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -