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

📄 复件 pingzheng.cpp

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

#include <vcl.h>
#pragma hdrstop

#include "pingzheng.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "Parent"
#pragma resource "*.dfm"
TfmPingZheng *fmPingZheng;
//---------------------------------------------------------------------------
__fastcall TfmPingZheng::TfmPingZheng(TComponent* Owner)
    : TfmParent(Owner)
{
    this->szCondition1 = "凭证编号";
    this->szCondition2 = "会计期间";
    this->szCondition3 = "日期";
    // 设置查询条件的显示
    this->SetSeekEditStatus();
    lblCount->Caption = "记录数: " + IntToStr(Table1->RecordCount) ;
    // 设置分录输入GRid
    StringGrid1->ColWidths[0] = 80;
    StringGrid1->ColWidths[1] = 60;
    StringGrid1->ColWidths[2] = 137;
    StringGrid1->ColWidths[3] = 60;
    StringGrid1->ColWidths[4] = 60;
    StringGrid1->Cells[0][0] = "摘要";
    StringGrid1->Cells[1][0] = "科目代码";
    StringGrid1->Cells[2][0] = "科目名称";
    StringGrid1->Cells[3][0] = "借方";
    StringGrid1->Cells[4][0] = "贷方";
}
//---------------------------------------------------------------------------
void __fastcall TfmPingZheng::btNewClick(TObject *Sender)
{
    // 注意如何调用父类窗体的方法
    TfmParent::btNewClick(NULL);
    // 计算凭证编号(Primary key);
    AnsiString szID,szID1;
    AnsiString sql;
    Query1->SQL->Clear();
    Query1->SQL->Add("select max(凭证编号) as 编号 from 凭证表历史");
    Query1->Open();
    TField* pField = Query1->FieldByName("编号");
    if(pField->IsNull)
        szID = "000001";
    else
    {
        AnsiString szT = "000000";
        szID = pField->AsInteger + 1;
        szID = szT.SubString(1,6-szID.Length()) + szID;
    }
    Query1->SQL->Clear();
    Query1->SQL->Add("select max(凭证编号) as 编号 from 凭证表");
    Query1->Open();
    pField = Query1->FieldByName("编号");
    if(pField->IsNull)
        szID1 = "000001";
    else
    {
        AnsiString szT = "000000";
        szID1 = pField->AsInteger + 1;
        szID1 = szT.SubString(1,6-szID1.Length()) + szID1;
    }
    // 取最大值作为新凭证的ID
    if(szID < szID1)
        szID = szID1;
    EditDBEdit1->Text = szID;
    // 填写会计区间、凭证编号等信息
    DBComboBox1->SetFocus();
    DBComboBox1->ItemIndex = 0;
    // 日期
    TDateTime dt;
    dt = dt.CurrentDate();
    EditDBEdit4->SetFocus();
    EditDBEdit4->Text = dt.DateString();
    // 会计区间
    Query1->SQL->Clear();
    Query1->SQL->Add("select 取值 from 系统参数表 where 参数名称 = '当前会计期间'");
    Query1->Open();
    EditDBEdit3->Text = Query1->FieldByName("取值")->AsString;
    // 状态
    EditDBEdit7->Text = "未过";
    // 其他
    EditDBEdit2->Text = "";
    EditDBEdit5->Text = "";
    EditDBEdit6->Text = "";
    // 子表分录表
    Table2->Edit();
}
//---------------------------------------------------------------------------
void __fastcall TfmPingZheng::btEditClick(TObject *Sender)
{
    // 注意如何调用父类窗体的方法
    TfmParent::btEditClick(NULL);
    // 子表分录表
    Table2->Edit();
}
//---------------------------------------------------------------------------
void __fastcall TfmPingZheng::btDeleteClick(TObject *Sender)
{
    if (Application->MessageBox("是否删除记录?", "确定", MB_YESNO)
             == mrYes)
    {
        DataSource1->Edit();
        // 删除记录
        Table1->Delete();
    }
}
//---------------------------------------------------------------------------
void __fastcall TfmPingZheng::btSaveClick(TObject *Sender)
{
    // 提交凭证
    // 注意如何调用父类窗体的方法
    TfmParent::btSaveClick(NULL);    // 子表分录表
    try
    {
        Table1->ApplyUpdates();
        Table1->CommitUpdates();
        Table2->ApplyUpdates();
        Table2->CommitUpdates();
    }
    // 有问题
	catch (Exception &exception)
	{
		Application->ShowException(&exception);
        return;
	}
}
//---------------------------------------------------------------------------
void __fastcall TfmPingZheng::btCancelClick(TObject *Sender)
{
    // 子表分录表
    Table2->CancelUpdates();
    Table2->CommitUpdates();
    // 注意如何调用父类窗体的方法
    TfmParent::btCancelClick(NULL);
}
//---------------------------------------------------------------------------

void __fastcall TfmPingZheng::Table2BeforePost(TDataSet *DataSet)
{
    Table2->FieldByName("凭证编号")->AsString = EditDBEdit1->Text;
}
//---------------------------------------------------------------------------
void __fastcall TfmPingZheng::DBGrid2KeyUp(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
    // 计算汇总金额
    double fAmt1=0, fAmt2=0;
    for(int i=0; i< Table2->RecordCount; i++)
    {

        fAmt1 += Table2->FieldByName("借方")->AsInteger;
        fAmt2 += Table2->FieldByName("贷方")->AsInteger;
    }
    EditDBEdit5->Text = fAmt1;
    EditDBEdit6->Text = fAmt2;
    if( Key ==  VK_DELETE)
    {
        Table2->Delete();
        Table2->Edit();
    }
}
//---------------------------------------------------------------------------
void __fastcall TfmPingZheng::Table2AfterPost(TDataSet *DataSet)
{
    if(btSave->Visible == true)
    {
        Table2->Edit();
    }
}
//---------------------------------------------------------------------------

void __fastcall TfmPingZheng::Table2AfterScroll(TDataSet *DataSet)
{
    if(btSave->Visible == true)
    {
        Table2->Edit();
    }
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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