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

📄 sj_pplbwh.pas

📁 省级集邮品管理ERP
💻 PAS
📖 第 1 页 / 共 2 页
字号:
    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 + -