?? sj_pplbwh.pas
字號:
Exit;
end;
if gb_LB1.Visible = True then
begin
qry_LB1.ApplyUpdates;
qry_LB1.CommitUpdates;
end
else
begin
qry_LB2.ApplyUpdates;
qry_LB2.CommitUpdates;
end;
Edit_State(0);
end;
{-------------------------------------------------------------------------------}
{取消編輯}
procedure TFrm_pplbwh.bbtn_CancelClick(Sender: TObject);
begin
if Sys_State = 0 then Exit;
if CHQMsgBox('確實要取消修改嗎', 2) = mrNo then
Exit;
if gb_LB1.Visible = True then
qry_LB1.CancelUpdates
else
qry_LB2.CancelUpdates;
Edit_State(0);
end;
{===============================================================================}
{測試是否已經填寫OK}
function TFrm_pplbwh.Test_Fit_Ok: Boolean;
begin
Result := True;
if gb_LB1.Visible = True then
begin
if Length(qry_LB1.FieldByName('JYPLDM').AsString) <> 1 then
begin
CHQMsgBox('必須輸入票品類代碼!');
dbe_JYPLDM1.SetFocus;
Result := False;
Exit;
end;
if qry_LB1.FieldByName('MC').AsString = '' then
begin
CHQMsgBox('必須輸入票品名稱!');
dbe_MC1.SetFocus;
Result := False;
Exit;
end;
end
else
begin
if Length(qry_LB2.FieldByName('JYPLDM').AsString) <> 3 then
begin
CHQMsgBox('必須輸入票品類代碼!');
dbe_JYPLDM2.SetFocus;
Result := False;
Exit;
end;
if qry_LB2.FieldByName('MC').AsString = '' then
begin
CHQMsgBox('必須輸入票品名稱!');
dbe_MC2.SetFocus;
Result := False;
Exit;
end;
end;
end;
{-------------------------------------------------------------------------------}
{測試是否能夠保存}
function TFrm_pplbwh.Test_Can_Save: Boolean;
var
l_pos: Pointer;
l_JYPLDM: string;
begin
Result := True;
if gb_LB1.Visible = True then
begin
with qry_LB1 do
begin
l_JYPLDM := FieldByName('JYPLDM').AsString;
l_pos := GetBookmark;
DisableControls;
Locate('JYPLDM', l_JYPLDM, [loCaseInsensitive]);
Next;
while not Eof do
begin
if l_JYPLDM = FieldByName('JYPLDM').AsString then
begin
GotoBookmark(l_pos);
Result := False;
EnableControls;
Exit;
end;
Next;
end;
GotoBookmark(l_pos);
EnableControls;
end;
end
else
begin
with qry_LB2 do
begin
DisableControls;
l_pos := GetBookmark;
l_JYPLDM := qry_LB2.FieldByName('JYPLDM').AsString;
Locate('JYPLDM', l_JYPLDM, [loCaseInsensitive]);
Next;
while not Eof do
begin
if l_JYPLDM = FieldByName('JYPLDM').AsString then
begin
Result := False;
GotoBookmark(l_pos);
EnableControls;
Exit;
end;
Next;
end;
GotoBookmark(l_pos);
EnableControls;
end;
end;
end;
{-------------------------------------------------------------------------------}
{設置界面狀態}
procedure TFrm_pplbwh.Edit_State(State: Integer);
begin
Sys_State := State; {將當前狀態對外顯露出來}
case State of
0: {瀏覽狀態} {}
begin
RXDBG_LB1.Enabled := True;
RXDBG_LB2.Enabled := True;
dbe_JYPLDM1.ReadOnly := True;
dbe_JYPLDM2.ReadOnly := True;
dbe_MC1.ReadOnly := True;
dbe_MC2.ReadOnly := True;
dbe_BH2.ReadOnly := True;
bbtn_Add.Enabled := True;
bbtn_Modify.Enabled := True;
bbtn_Delete.Enabled := True;
bbtn_Save.Enabled := False;
bbtn_Cancel.Enabled := False;
end;
1: {新增/修改大類狀態} {}
begin
RXDBG_LB1.Enabled := False;
RXDBG_LB2.Enabled := False;
gb_LB1.Visible := True;
gb_LB2.Visible := False;
dbe_JYPLDM1.ReadOnly := False;
dbe_MC1.ReadOnly := False;
bbtn_Add.Enabled := False;
bbtn_Modify.Enabled := False;
bbtn_Delete.Enabled := False;
bbtn_Save.Enabled := True;
bbtn_Cancel.Enabled := True;
end;
2: {新增小類} {}
begin
RXDBG_LB1.Enabled := False;
RXDBG_LB2.Enabled := False;
gb_LB1.Visible := False;
gb_LB2.Visible := True;
dbe_JYPLDM2.ReadOnly := False;
dbe_MC2.ReadOnly := False;
dbe_BH2.ReadOnly := False;
bbtn_Add.Enabled := False;
bbtn_Modify.Enabled := False;
bbtn_Delete.Enabled := False;
bbtn_Save.Enabled := True;
bbtn_Cancel.Enabled := True;
end;
3: {修改小類} {}
begin
RXDBG_LB1.Enabled := False;
RXDBG_LB2.Enabled := False;
gb_LB1.Visible := False;
gb_LB2.Visible := True;
dbe_JYPLDM2.ReadOnly := False;
dbe_MC2.ReadOnly := False;
dbe_BH2.ReadOnly := False;
bbtn_Add.Enabled := False;
bbtn_Modify.Enabled := False;
bbtn_Delete.Enabled := False;
bbtn_Save.Enabled := True;
bbtn_Cancel.Enabled := True;
end;
end;
end;
{===========================判斷是否允許修改、刪除的程序========================}
{數據是否允許被修改}{判斷是否為“基類”}
function TFrm_pplbwh.if_Can_Modify: Boolean;
begin
Result := True;
if gb_LB1.Visible = True then
begin
if qry_LB1.FieldByName('ZT').AsString = '0' then
Result := False;
end
else
begin
if qry_LB2.FieldByName('ZT').AsString = '0' then
Result := False;
end;
end;
{測試大類是否存在小類,如果存在,則不能修改}
function TFrm_pplbwh.Test_Exist_Sub: Boolean;
begin
Result := False;
if gb_LB1.Visible = True then
if qry_LB2.IsEmpty = False then
Result := True;
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
{測試是否允許對選擇的類進行修改}{判斷是否在其他表中存在關聯關系}
function TFrm_pplbwh.Test_Can_Modify: Boolean;
begin
if gb_LB1.Visible = True then
begin
Result := Sub_Test_Can_Modify(qry_LB1.FieldByName('JYPLDM').AsString,
qry_LB1.FieldByName('BH').AsString);
end
else
begin
Result := Sub_Test_Can_Modify(qry_LB2.FieldByName('JYPLDM').AsString,
qry_LB2.FieldByName('BH').AsString);
end;
end;
{-------------------------------------------------------------------------------}
{測試是否允許對選擇的類進行修改,實際執行判斷的子程序}{判斷是否在其他表中存在關聯關系}
function TFrm_pplbwh.Sub_Test_Can_Modify(l_lb, l_BH: string): Boolean;
begin
Result := True;
{判斷是否為大類,如果是,則需要循環判斷其小類是否允許修改}
if length(l_lb) = 1 then
begin
with qry_LB2 do
begin
DisableControls;
First;
while not Eof do
begin
if Sub_Test_Can_Modify(FieldByName('LB').AsString, FieldByName('BH').AsString) = False then
begin
Result := False;
EnableControls;
Exit;
end;
Next;
end;
EnableControls;
end;
Result := True;
Exit;
end;
with qry_Tmp do
begin
{測試在 集郵品類代碼表 中是否存在記錄}
Close;
SQL.Text := 'Select YPLB from TB_JYPTXXB where YPLB=''' + l_lb + '''';
Open;
if IsEmpty = False then
begin
Result := False;
exit;
end;
Close;
SQL.Text := 'Select ZH from TB_JYPMXXB where Substr(ZH,1,' + IntToStr(length(l_BH)) + ')=''' + l_BH + ''' and SubStr(ZH,' + IntToStr(length(l_BH) + 1) + ',1) in(''0'',''1'',''2'',''3'',''4'',''5'',''6'',''7'',''8'',''9'')';
Open;
if IsEmpty = False then
begin
Result := False;
exit;
end;
Close;
SQL.Text := 'Select ZH from TB_YZPPXXB where Substr(ZH,1,' + IntToStr(length(l_BH)) + ')=''' + l_BH + ''' and SubStr(ZH,' + IntToStr(length(l_BH) + 1) + ',1) in(''0'',''1'',''2'',''3'',''4'',''5'',''6'',''7'',''8'',''9'')';
Open;
if IsEmpty = False then
begin
Result := False;
exit;
end;
end;
end;
{===============================================================================}
procedure TFrm_pplbwh.FormClose(Sender: TObject; var Action: TCloseAction);
begin
SaveAllColWidth(Self);
end;
(*
procedure TFrmY_DPZDQXFP.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
{ with TDBGrid(Sender) do
begin
if DataSource.DataSet.FieldByName('LKJE').AsFloat < 0 then
AFont.Color := clRed
else
AFont.Color := clBlack;
end;
if Field.FieldName='FPDZTS' then
Background:=clInfoBk; }
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
if Qry_JJNFPDB1.FieldByName('LKJE').AsFloat < 0 then
DBGrid1.Canvas.Font.Color := clred;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end; *)
procedure TFrm_pplbwh.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case key of
VK_RETURN:
begin
if (self.activecontrol is TMEMO) or (self.activecontrol is TDBGrid) then
else
begin
postmessage(self.handle, WM_KEYDOWN, 9, 0);
postmessage(self.handle, WM_KEYUP, 9, 0);
end;
end;
Vk_Escape: Self.Close;
end;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -