?? untpub.pas
字號:
_bmpUnitLogoS.Free;
_bmpUnitLogoL.Free;
_icnUnitLogo.Free;
_bmpTimeSoftLogoS.Free;
_bmpTimeSoftLogoL.Free;
_icnTimeSoftLogo.Free;
except
on E:exception do ErrorHandler(E,'PubEnd');
end;
//-- 釋放系統數據模塊
Application.ProcessMessages;
AddSysLog('釋放', ' ', ' '); // 日志
end;
// ★★★
//---- 系統配置
// 讀取:
// 系統配置文件到全程變量.
procedure SysCfgRead;
var
iniSys: TIniFile;
slTmp: TStringList;
iC: integer;
begin
try
iniSys := TIniFile.Create(_sAppPath+_sSysCfgFile);
slTmp := TStringList.Create;
try
//-- 1. 系統配置文件到全程變量.
// Database
_sDatabase := iniSys.ReadString('數據庫', '設備', '');
// _sServerName := iniSys.ReadString('數據庫', '服務器', '');
_sDBSUserName := iniSys.ReadString('數據庫', '用戶', '');
_sDBSPassword := iniSys.ReadString('數據庫', '口令', '');
// 異常
_bShowSysError := iniSys.ReadBool('系統', '顯示內部異常', true);
// 編譯器附加代碼
iniSys.ReadSection('過程參數', slTmp);
for iC:=0 to slTmp.Count-1 do
_sSQLParam := _sSQLParam+#13+
iniSys.ReadString('過程參數', slTmp[iC], '');
iniSys.ReadSection('變量定義', slTmp);
for iC:=0 to slTmp.Count-1 do
_sSQLVar := _sSQLVar+#13+
iniSys.ReadString('變量定義', slTmp[iC], '');
iniSys.ReadSection('初始化', slTmp);
for iC:=0 to slTmp.Count-1 do
_sSQLStart := _sSQLStart+#13+
iniSys.ReadString('初始化', slTmp[iC], '');
iniSys.ReadSection('報表結束', slTmp);
for iC:=0 to slTmp.Count-1 do
_sSQLREnd := _sSQLREnd+#13+
iniSys.ReadString('報表結束', slTmp[iC], '');
iniSys.ReadSection('政策結束', slTmp);
for iC:=0 to slTmp.Count-1 do
_sSQLPEnd := _sSQLPEnd+#13+
iniSys.ReadString('政策結束', slTmp[iC], '');
except
On E: Exception do ErrorHandler(E, 'SysCfgRead');
end;
finally
iniSys.Free;
slTmp.Free;
end;
end;
// ★★★
//---- 系統注冊
// 輸入參數:
// iType:0:普通用戶;1:管理員
// 返回值:
// 0:注冊成功;1:失敗
// ★★★
//---- 應用程序啟動窗口
// 顯示窗口
// 關閉窗口
// ★★★
//---- 系統日志
// 加入一條日志記錄
// 返回值:
// 0:成功
// 其他:錯誤號
function AddSysLog(const sType, sModule, sContent: string): integer;
begin
end;
// ★★★
//---- 打開 MDI 子窗口
// 輸入參數:
// TfrmMDIChild:子窗體類名
// frmMDIChild:子窗體實例變量
// 必要條件:
// _frmMain 已初始化
procedure OpenMDIChild(TfrmMDIChild: TComponentClass; var frmMDIChild: TForm);
var
iLoop: integer;
begin
//-- 1. 查詢子窗體是否已經存在
for iLoop:=_frmMain.MDIChildCount-1 downto 0 do
if _frmMain.MDIChildren[iLoop]=frmMDIChild then
begin
frmMDIChild.Icon.Assign(_icnTimeSoftLogo);
frmMDIChild.Show; // 已經存在, 推到前面
exit; // 退出
end;
//-- 2. 不存在則創建
Application.CreateForm(TfrmMDIChild, frmMDIChild);
frmMDIChild.Show;
end;
// ★★★
//---- 聯機業務幫助
// 輸入參數:
// sTaxID: 稅種代碼 char(2) 取全局變量 _sTaxID
// sBaseItemType: 基礎數據類別代碼 char(1)
// sBaseItemID: 基礎數據指標代碼 char(16) 前四位有用
function ShowOnlineHelp(const sTaxID, sBaseItemType, sBaseItemID: string): integer;
var
iH, iL: integer;
begin
Result := 0;
if _frmHint = nil then
exit;
try
iH := StrToInt(sTaxID) shl 16 + StrToInt(sBaseItemType);
iL := StrToInt(sBaseItemID);
if not PostMessage(_frmHint.Handle, WM_HELP, iH, iL) then
raise EHelpMsg.Create('請求聯機業務幫助失敗. 錯誤號='+IntToStr(GetLastError()));
except
on E:Exception do
begin
Result := 1;
ErrorHandler(E, 'ShowOnlineHelp');
end;
end;
end;
// ★★★
//---- 聯機主窗口提示
// 輸入參數:
// sHint: 提示信息
function ShowOnlineHint(const sHint: string): integer;
begin
Result := 0;
if _frmMain = nil then
exit;
try
_sHint := sHint;
if not PostMessage(_frmMain.Handle, WM_HINT, 0, 0) then
raise EHintMsg.Create('請求聯機主窗口提示失敗. 錯誤號='+IntToStr(GetLastError()));
except
on E:Exception do
begin
Result := 1;
ErrorHandler(E, 'ShowOnlineHint');
end;
end;
end;
//---- 進程指示
//-- 1. 由調用程序驅動的指示桿的編程接口
// 1.1. 初始化,創建窗口
// 輸入參數:
// sFixedMsg: 固定的顯示信息
// iMax: 指示桿的最大值
// bCanCancel:是否允許用戶取消當前進程
// 1.2. 改變顯示,移動指示桿的位置
// 輸入參數:
// sChangingMsg: 動態的顯示信息
// iPosition: 指示桿的當前位置
// 返回值:
// true:用戶未取消當前進程
// false:用戶取消當前進程
// 1.3. 結束,關閉窗口
//-- 2. 自動移動指示桿的編程接口
// 2.1. 初始化,創建窗口
// 輸入參數:
// sFixedMsg: 固定的顯示信息
// bCanCancel:是否允許用戶取消當前進程
// 2.2. 改變顯示,移動指示桿的位置
// 輸入參數:
// sChangingMsg: 動態的顯示信息
// 返回值:
// true:用戶未取消當前進程
// false:用戶取消當前進程
// 2.3. 結束,關閉窗口
//---- 自動設定窗體的寬度和高度
procedure SetWinSize(var frmShow: TForm; const poWhich: TPosition; const bDock: boolean);
var
iCC, iMinW, iMinH, iMaxW, iMaxH: integer;
ctrlTmp: TControl;
begin
// 處理所有構件
iMinW := 1000;
iMinH := 1000;
iMaxW := 0;
iMaxH := 0;
for iCC:=0 to frmShow.ControlCount-1 do
begin
ctrlTmp := frmShow.Controls[iCC];
if ctrlTmp.Left < iMinW then
iMinW := ctrlTmp.Left;
if ctrlTmp.Top < iMinH then
iMinH := ctrlTmp.Top;
if ctrlTmp.Left + ctrlTmp.Width > iMaxW then
iMaxW := ctrlTmp.Left + ctrlTmp.Width;
if ctrlTmp.Top + ctrlTmp.Height > iMaxH then
iMaxH := ctrlTmp.Top + ctrlTmp.Height;
end;
frmShow.Scaled := True;
frmShow.Position := poWhich;
if bDock then
frmShow.Height := iMaxH + 6
else
frmShow.ClientHeight := iMaxH + 6;
frmShow.Width := iMaxW + iMinW;
end;
//---- 顯示全局變量
procedure ShowGlobalAppVars;
begin
ShowMessage(' 系統使用單位名稱 _sUnitName = ' + _sUnitName + #13 +
' 系統使用單位類型 _sUnitType = ' + _sUnitType + #13 + #13 + //
' 被審企業代碼 _iEnpID = ' + IntToStr(_iEnpID) + #13 +
' 被審企業名稱 _sEnpName = ' + _sEnpName + #13 +
' 被審企業地址 _sEnpAddr = ' + _sEnpAddr + #13 +
' 被審企業行業代碼 _sTradeID = ' + _sTradeID + #13 +
' 被審企業行業名稱 _sTradeName = ' + _sTradeName + #13 +
' 被審企業經濟類型代碼 _sEconType = ' + _sEconType + #13 +
' 被審企業經濟類型名稱 _sEconName = ' + _sEconName + #13 +
' 被審企業所得稅率 _dIncomeTaxRate = ' + FloatToStr(_dIncomeTaxRate) + #13 +
' 被審企業城建稅率 _dCityTaxRate = ' + FloatToStr(_dCityTaxRate) + #13 + #13 +
' 當前約定書號 _sContractID = ' + _sContractID + #13 +
' 項目經理姓名 _sProjectMngName = ' + _sProjectMngName + #13 +
' 項目經理工號 _sProjectMngID = ' + _sProjectMngID + #13 +
' 項目經理內部代碼 _iProjectMngID = ' + IntToStr(_iProjectMngID) + #13 + #13 +
' 當前被審稅種內部號 _iTaxID = ' + IntToStr(_iTaxID) + #13 +
' 當前被審稅種號 _sTaxID = ' + _sTaxID + #13 +
' 代理稅種名稱 _sTaxName = ' + _sTaxName + #13 +
' 代理內容 _sAgent = ' + _sAgent + #13 +
' 數據錄入方法 _iDataFrom = ' + IntToStr(_iDataFrom) + #13 +
' 當前工作所使用的申報表代碼 _sRptID = ' + _sRptID + #13 +
' 當前執行的總體工作計劃號 _sPlanID = ' + _sPlanID + #13 +
' 當前計劃年度 _iPlanYear = ' + IntToStr(_iPlanYear) + #13 +
' 當前個人工作計劃號 _iPerPlanID = ' + IntToStr(_iPerPlanID) + #13 +
' 當前個人計劃所屬會計期間 _sAccSession = ' + _sAccSession + #13 + #13 +
' 操作員姓名 _sUserName = ' + _sUserName + #13 +
' 操作員工號 _sUserID = ' + _sUserID + #13 +
' 操作員內部代碼 _iUserID = ' + IntToStr(_iUserID) + #13 +
' 操作員口令 _sPassWord = ' + _sPassWord + #13 +
' 操作員所在部門代碼 _iDptID = ' + IntToStr(_iDptID) + #13 +
' 操作員所在部門名稱 _sDptName = ' + _sDptName + #13 +
' 操作員權限 _sRight = ' + _sRight);
end;
procedure ShowGlobalSysVars;
begin
ShowMessage(' 當前工作站名稱 _sMachineName = ' + _sMachineName + #13 +
' 系統安裝目錄 _sAppPath = ' + _sAppPath + #13 +
' 系統臨時目錄 _sAppTmpPath = ' + _sAppTmpPath + #13 +
' 系統運行地點 _iRunSite = ' + IntToStr(_iRunSite) + #13 +
' 提示窗口標題 _sAppTitle = ' + _sAppTitle + #13 +
' 系統數據庫 _sDatabase = ' + _sDatabase + #13 +
// ' 數據庫服務器 _sServerName = ' + _sServerName + #13 +
' 顯示邏輯錯誤信息 _bShowSysError = ' + IntToStr(integer(_bShowSysError)) + #13 + #13 +
' 過程參數 _sSQLParam = ' + _sSQLParam + #13 + #13 +
' 變量定義 _sSQLVar = ' + _sSQLVar + #13 + #13 +
' 初始化 _sSQLStart = ' + _sSQLStart + #13 + #13 +
' 報表結束 _sSQLREnd = ' + _sSQLREnd + #13 + #13 +
' 政策結束 _sSQLPEnd = ' + _sSQLPEnd );
end;
// ★★★
// 將回車鍵轉換為TAB鍵
// 調用方式:將Form的KeyPreviw設為True,在KeyDown事件中加語句
// ConvertKey(ActiveControl,HANDLE,Key,Shift);
procedure ConvertKey(ActiveControl:TWinControl ;HANDLE: HWND;var Key: Word;Shift: TShiftState);
begin
if (ord(Key)=13) then
begin
if ((ActiveControl is TComboBox) ) then
begin
if SendMessage(ActiveControl.HANDLE,CB_GETDROPPEDSTATE ,0,0)=0 then
begin
if SendMessage(ActiveControl.HANDLE,CB_GETCURSEL,0,0)= CB_ERR then
SendMessage(ActiveControl.HANDLE,CB_SETCURSEL,0,0);
PostMessage(ActiveControl.HANDLE,CB_SHOWDROPDOWN,-1,0);
end
else
begin
PostMessage(HANDLE,WM_KEYDOWN,vk_TAB,0);
Key :=0;
end;
exit;
end;
if ((ActiveControl is TCheckBox)) then
begin
PostMessage(HANDLE,WM_KEYDOWN,vk_TAB,0);
Key := 0; // 32
exit;
end;
if ((ActiveControl is TEdit)
or (ActiveControl is TMaskEdit)
or (ActiveControl is TRadioButton)
or (ActiveControl is TDBImage)
or (ActiveControl is TDBComboBox)
or (ActiveControl is TDBEdit)) then
begin
PostMessage(HANDLE,WM_KEYDOWN,vk_TAB,0);
Key :=0;
end;
end;
if (ord(Key)=9) then
begin
if (ActiveControl is TDbgrid) then
begin
PostMessage(HANDLE,WM_KEYDOWN,vk_TAB,0);
Key :=0;
end;
end;
end;
// ★★★
// 錯誤處理程序,供異常處理調用
procedure ErrorHandler(expWhich:Exception; sProcedure:string);
var
F1: TextFile;
iNum,iLoop: integer;
sEM: string;
begin
try
// 2. 記入錯誤日志
_sErrorMsg := '計算機: '+_sMachineName+
' 發生日期: '+DateTimeToStr(Now)+#13+
' 錯誤程序: '+sProcedure+
' 錯誤信息: ';
// 2.1. 判斷錯誤日志文件是否存在
AssignFile(F1, _sErrorFile);
if FileExists(_sErrorFile)=false then
begin
rewrite(F1); // 創建并打開
end
else
append(F1); // 打開并追加
// 2.2. 判斷是否為BDE錯誤
if (expWhich is EDBEngineError) then
begin
iNum:=(expWhich as EDBEngineError).ErrorCount; // 取錯誤的總數
// 循環取每個錯誤的號和信息
for iLoop:=0 to iNum-1 do
begin
_iErrorCode := (expWhich as EDBEngineError).Errors[iLoop].Errorcode; //取錯誤號
sEM := IntToStr(_iErrorCode) + ' ' +
(expWhich as EDBEngineError).Errors[iLoop].message; //取錯誤信息
_sErrorMsg := _sErrorMsg+#13+' '+sEM;
end;
end
// 2.3. 非BDE錯誤處理
else
begin
_iErrorCode:=1; //非BDE錯誤則所有錯誤號都為'1'
_sErrorMsg := _sErrorMsg + #13 + ' ' + expWhich.Message;
end;
// 2.4. 寫入日志
Writeln(F1, _sErrorMsg);
CloseFile(F1); // 關閉文件
if _bShowSysError then
Application.MessageBox(PChar(_sErrorMsg),
pchar(_sAppTitle),
mb_IconError+mb_ok);
except
Application.MessageBox('記錄系統錯誤時出錯.',
pchar(_sAppTitle),
mb_IconError+mb_ok);
end;
end;
// ★★★
// 取錯誤號和錯誤信息
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -