📄 main.~cpp
字号:
//--------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Main.h"
#include "kemu.h"
#include "zhanghu.h"
#include "pingzheng.h"
#include "totalzb.h"
#include "detailzb.h"
#include "pingheng.h"
#include "reprotzich.h"
//---------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfmMain *fmMain;
// 数据库开发经典实例解析 清华大学出版社
//---------------------------------------------------------
__fastcall TfmMain::TfmMain(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------
TForm* TfmMain::FormExist(AnsiString szCaption)
{
for(int i=0; i<this->MDIChildCount; i++)
{
TForm *pForm = this->MDIChildren[i];
if(pForm->Caption == szCaption)
return pForm; // 已存在窗体,返回该窗体
}
return NULL; // 不存在窗体,返回空值
}
//---------------------------------------------------------
void __fastcall TfmMain::mnuExitClick(TObject *Sender)
{
Application->Terminate();
}
//-------------------------------------------------------------
void __fastcall TfmMain::Label1Click(TObject *Sender)
{
// 查找相应按钮对应的菜单,通过菜单执行相应的操作
for(int i = 0; i< MainMenu1->Items->Count; i++)
{
TMenuItem* pItem = MainMenu1->Items->Items[i];
TMenuItem* pItem1 = pItem->Find(
((TLabel*) Sender)->Caption);
if(pItem1) pItem1->Click();
}
}
//---------------------------------------------------------
void __fastcall TfmMain::mnukemuClick(TObject *Sender)
{
// 会计科目设置
TForm *pForm = FormExist("会计科目设置");
// 如果已存在则激活,否则新建一个字窗体
if(pForm)
pForm->SetFocus();
else
pForm = new TfmKeMu(Application);
pForm->Show();
}
//-------------------------------------------------------------
void __fastcall TfmMain::mnuzhanghuClick(TObject *Sender)
{
// 帐户设置(期初数据录入)
TForm *pForm = FormExist("帐户设置(期初数据录入)");
// 如果已存在则激活,否则新建一个字窗体
if(pForm)
pForm->SetFocus();
else
pForm = new TfmZhangHu(Application);
pForm->Show();
}
//-------------------------------------------------------------
void __fastcall TfmMain::mnuInputPZClick(TObject *Sender)
{
// 会计凭证输入
TForm *pForm = FormExist("会计凭证输入");
// 如果已存在则激活,否则新建一个字窗体
if(pForm)
pForm->SetFocus();
else
pForm = new TfmPingZheng(Application);
pForm->Show();
}
//-------------------------------------------------------------
void __fastcall TfmMain::mnuCerPZClick(TObject *Sender)
{
//凭证过帐
if (Application->MessageBox("凭证过帐后将不能再修改,是否进行凭证过帐操作?",
"确定", MB_YESNO | MB_ICONWARNING) == mrYes)
{
TQuery* pQuery = new TQuery(NULL);
pQuery->DatabaseName = "db";
try
{
pQuery->SQL->Add("begin tran");
pQuery->SQL->Add("exec sf_凭证过帐");
pQuery->ExecSQL();
}
catch(...)
{
Application->MessageBox("凭证过帐失败", "确定", MB_OK);
pQuery->SQL->Clear();
pQuery->SQL->Add("rollback");
pQuery->ExecSQL();
delete pQuery;
return;
}
// 过帐成功,提交事务
pQuery->SQL->Clear();
pQuery->SQL->Add("commit");
pQuery->ExecSQL();
// 统计汇总信息
AnsiString msg;
msg = "过帐成功\n\n";
pQuery->SQL->Clear();
pQuery->SQL->Add("select count(*) 记录数 from 凭证表");
pQuery->Open();
msg += "共有 " + pQuery->FieldByName("记录数")->AsString + " 张凭证\n";
pQuery->SQL->Clear();
pQuery->SQL->Add("select sum(借方) as 借, sum(贷方) as 贷 from 分录表");
pQuery->Open();
msg += "\n借方金额合计 " + pQuery->FieldByName("借")->AsString;
msg += "\n贷方金额合计 " + pQuery->FieldByName("贷")->AsString;
Application->MessageBox(msg.c_str(), "确定", MB_OK);
// 删除分录表和凭证表
pQuery->SQL->Clear();
pQuery->SQL->Add("delete from 分录表");
pQuery->SQL->Add("delete from 凭证表");
pQuery->ExecSQL();
// 释放空间
delete pQuery;
}
}
//-------------------------------------------------------------
void __fastcall TfmMain::mnuTotalZBClick(TObject *Sender)
{
TForm *pForm = FormExist("总分类账查询");
// 如果已存在则激活,否则新建一个字窗体
if(pForm)
pForm->SetFocus();
else
pForm = new TfmTotalZB(Application);
pForm->Show();
}
//-------------------------------------------------------------
void __fastcall TfmMain::mnuDetailZBClick(TObject *Sender)
{
TForm *pForm = FormExist("明细账查询");
// 如果已存在则激活,否则新建一个字窗体
if(pForm)
pForm->SetFocus();
else
pForm = new TfmDetailZB(Application);
pForm->Show();
}
//-------------------------------------------------------------
void __fastcall TfmMain::mnuTestCalClick(TObject *Sender)
{
TForm *pForm = FormExist("试算平衡表");
// 如果已存在则激活,否则新建一个字窗体
if(pForm)
pForm->SetFocus();
else
pForm = new TfmPingheng(Application);
((TfmPingheng*) pForm)->CalPingHeng(1);
pForm->Show();
}
//-------------------------------------------------------------
void __fastcall TfmMain::mnuJieZhangClick(TObject *Sender)
{
//期末结帐
if (Application->MessageBox("结帐后将进入下一会计期间,是否结帐?",
"确定", MB_YESNO | MB_ICONWARNING) == mrYes)
{
TQuery* pQuery = new TQuery(NULL);
pQuery->DatabaseName = "db";
try
{
pQuery->SQL->Add("begin tran");
pQuery->SQL->Add("exec sf_期末结帐");
pQuery->ExecSQL();
}
catch(...)
{
Application->MessageBox("期末结帐失败", "确定", MB_OK);
pQuery->SQL->Clear();
pQuery->SQL->Add("rollback");
pQuery->ExecSQL();
delete pQuery;
return;
}
// 过帐成功,提交事务
pQuery->SQL->Clear();
pQuery->SQL->Add("commit");
pQuery->ExecSQL();
Application->MessageBox("结帐成功", "确定", MB_OK);
// 释放空间
delete pQuery;
}
}
//-------------------------------------------------------------
void __fastcall TfmMain::mnuReport1Click(TObject *Sender)
{
// 输入统计的会计区间
int Index;
TQuery* pQuery = new TQuery(NULL);
pQuery->DatabaseName = "db";
pQuery->SQL->Add("select 取值 from 系统参数表 where 参数名称 = '当前会计期间'");
pQuery->Open();
Index = pQuery->FieldByName("取值")->AsInteger;
Index = StrToInt(InputBox("请输入统计的会计区间","会计区间",Index-1)) ;
// 计算
pQuery->SQL->Clear();
pQuery->SQL->Add("exec sf_计算资产负债表 " + IntToStr(Index));
pQuery->ExecSQL();
delete pQuery;
// 显示结果
TfmReportZiCh* pForm = new TfmReportZiCh(Application);
pForm->SetKJQJ(Index);
pForm->QuickRep1->Preview();
delete pForm;
}
//-------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -