⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parent.cpp

📁 全面剖析财务管理的内容
💻 CPP
字号:
//-----------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Parent.h"
//-----------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfmParent *TfmParent;
//-----------------------------------------------------------------
__fastcall TfmParent::TfmParent(TComponent* Owner)
    : TForm(Owner)
{
    this->SetButtonEnable(0); 
}
//-----------------------------------------------------------------
void __fastcall TfmParent::FormClose(TObject *Sender, TCloseAction &Action)
{
    // 删除窗体并回收空间
    Action = caFree;
}
//-----------------------------------------------------------------
void __fastcall TfmParent::btFirstClick(TObject *Sender)
{
    // 到首记录
    Table1->First();
}
//-----------------------------------------------------------------
void __fastcall TfmParent::btPriorClick(TObject *Sender)
{
    // 到前一记录
    Table1->Prior();
}
//-----------------------------------------------------------------
void __fastcall TfmParent::btNextClick(TObject *Sender)
{
    // 到下一记录
    Table1->Next();
}
//-----------------------------------------------------------------
void __fastcall TfmParent::btLastClick(TObject *Sender)
{
    // 到尾记录
    Table1->Last();
}
//-----------------------------------------------------------------
void __fastcall TfmParent::btNewClick(TObject *Sender)
{
    // 设置按钮状态
    SetButtonEnable(1);
    // 新增记录
    Table1->Append();
}
//-----------------------------------------------------------------
void __fastcall TfmParent::btEditClick(TObject *Sender)
{
    // 设置按钮状态
    SetButtonEnable(1);
    // 编辑记录
    Table1->Edit();
}
//-----------------------------------------------------------------
void __fastcall TfmParent::btDeleteClick(TObject *Sender)
{
    if (Application->MessageBox("是否删除记录?", "确定", MB_YESNO)
             == mrYes)
    {
        DataSource1->Edit();
        // 删除记录
        Table1->Delete();
    }
}
//-----------------------------------------------------------------
void __fastcall TfmParent::btSaveClick(TObject *Sender)
{
    // 保存记录
    Table1->Post();
    // 设置按钮状态
    SetButtonEnable(0);
}
//-----------------------------------------------------------------
void __fastcall TfmParent::btCancelClick(TObject *Sender)
{
    // 取消编辑
    Table1->Cancel();
    // 设置按钮状态
    SetButtonEnable(0);
}
//-----------------------------------------------------------------
void __fastcall TfmParent::btExitClick(TObject *Sender)
{
    this->Close();
}
//-----------------------------------------------------------------
// 设置各种按钮的状态
void TfmParent::SetButtonEnable(int nStatus)
{
    if(nStatus == 1)
    {
        // 编辑状态
        btFirst->Enabled = false;
        btPrior->Enabled = false;
        btNext->Enabled = false;
        btLast->Enabled = false;
        btNew->Enabled = false;
        btEdit->Enabled = false;
        btDelete->Enabled = false;
        btSave->Enabled = true;
        btCancel->Enabled = true;
        // Panel2的所有控件都是可输入的
        Panel2->Enabled = true;
        DBGrid1->Enabled = false;
    }
    else
    {
        // 浏览状态
        btFirst->Enabled = true;
        btPrior->Enabled = true;
        btNext->Enabled = true;
        btLast->Enabled = true;
        btNew->Enabled = true;
        btEdit->Enabled = true;
        btDelete->Enabled = true;
        btSave->Enabled = false;
        btCancel->Enabled = false;
        // Panel2的所有控件都是不可输入的
        Panel2->Enabled = false;
        DBGrid1->Enabled = true;
    }
}
//-----------------------------------------------------------------
// 回车查询
void __fastcall TfmParent::Edit1KeyPress(TObject *Sender, char &Key)
{
    if(Key == 13)
        BitBtn1->Click() ;
}
//-------------------------------------------------------------
// 搜索按钮对应查询功能
void __fastcall TfmParent::BitBtn1Click(TObject *Sender)
{
    Table1->Filter = "";
    AnsiString szFilter;
    // 设置条件
    AnsiString szType;
    TField* pField;
    if(!Edit1->Text.IsEmpty() && !szCondition1.IsEmpty())
    {
        pField = Table1->FieldByName(szCondition1);
	    if( pField->DataType == ftSmallint ||
	        	pField->DataType == ftInteger  ||
       		    pField->DataType == ftWord     ||
	            pField->DataType == ftBoolean ||
       		    pField->DataType == ftFloat   ||
	            pField->DataType == ftCurrency ||
                pField->DataType == ftDate)
            szFilter = szCondition1 + " = " + Edit1->Text + " and ";
        else
            szFilter = szCondition1 + " = '" + Edit1->Text + "*' and ";
    }
    if(!Edit2->Text.IsEmpty() && !szCondition2.IsEmpty())
    {
        pField = Table1->FieldByName(szCondition2);
	    if( pField->DataType == ftSmallint ||
	        	pField->DataType == ftInteger  ||
       		    pField->DataType == ftWord     ||
	            pField->DataType == ftBoolean ||
       		    pField->DataType == ftFloat   ||
	            pField->DataType == ftCurrency ||
                pField->DataType == ftDate)
            szFilter = szCondition2 + " = " + Edit2->Text + " and ";
        else
            szFilter = szCondition2 + " = '" + Edit2->Text + "*' and ";
    }
    if(!Edit3->Text.IsEmpty() && !szCondition3.IsEmpty())
    {
        pField = Table1->FieldByName(szCondition3);
	    if( pField->DataType == ftSmallint ||
	        	pField->DataType == ftInteger  ||
       		    pField->DataType == ftWord     ||
	            pField->DataType == ftBoolean ||
       		    pField->DataType == ftFloat   ||
	            pField->DataType == ftCurrency ||
                pField->DataType == ftDate)
            szFilter = szCondition3 + " = " + Edit3->Text + " and ";
        else
            szFilter = szCondition3 + " = '" + Edit3->Text + "*' and ";
    }
    // 清除最后多余的and
    szFilter = szFilter.SubString(1,szFilter.Length()-5);
    Table1->Filtered = false;
    Table1->Filter = szFilter;
    Table1->Filtered = true;
    lblCount->Caption = "记录数: " + IntToStr(Table1->RecordCount) ;
}
//-------------------------------------------------------------
// 隐藏不用的查询edit和lable
void TfmParent::SetSeekEditStatus()
{    if(!szCondition1.IsEmpty())
    {
        Label1->Visible = true;
        Edit1->Visible = true;
        Label1->Caption = szCondition1;
    }
    if(!szCondition2.IsEmpty())
    {
        Label2->Visible = true;
        Edit2->Visible = true;
        Label2->Caption = szCondition2;
    }
    if(!szCondition3.IsEmpty())
    {
        Label3->Visible = true;
        Edit3->Visible = true;
        Label3->Caption = szCondition3;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -