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

📄 dcmodul.pas

📁 delphi renyuanguanlixinxioxitong
💻 PAS
字号:
unit DCModul;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB, ComCtrls, ToolWin, Grids, DBGrids;

type
  TfrmDCModul = class(TForm)
    DBGrid1: TDBGrid;
    CoolBar1: TCoolBar;
    ToolBar1: TToolBar;
    tbtnNew: TToolButton;
    tbtnDelete: TToolButton;
    tbtnVoid: TToolButton;
    tbtnSave: TToolButton;
    tbtnExit: TToolButton;
    atbDictionary: TADOTable;
    dsDictionary: TDataSource;
    atbDictionaryVoidName: TStringField;
    procedure atbDictionaryCalcFields(DataSet: TDataSet);
    procedure atbDictionaryAfterInsert(DataSet: TDataSet);
    procedure tbtnNewClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    function funCheckTableOpen() :boolean;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmDCModul: TfrmDCModul;

implementation
uses DataModual;
{$R *.dfm}
//判断数据库表是否激活
function TfrmDCModul.funCheckTableOpen() :boolean;
begin
   if not atbDictionary.Active then
   begin
      application.MessageBox('表没有打开','错误',mb_ok);
      Result := False;
      exit;
   end
   else
     Result :=True;
end;
//计算机字段的使用
procedure TfrmDCModul.atbDictionaryCalcFields(DataSet: TDataSet);
begin
   if atbDictionary.FieldByName('IfVoid').Value = 0 then
      atbDictionary.FieldByName('VoidName').AsString :=''
   else
      atbDictionary.FieldByName('VoidName').AsString :='已作废' ;
end;
//单击新增按钮自动设置作废标志为未作废
procedure TfrmDCModul.atbDictionaryAfterInsert(DataSet: TDataSet);
begin
   atbDictionary.FieldByName('IfVoid').AsInteger :=0; //未被作废
end;
//数据字典维护程序
procedure TfrmDCModul.tbtnNewClick(Sender: TObject);
begin
   Case ((Sender as TComponent).Tag) of
     10: begin //新增
           if not funCheckTableOpen() then exit;
           atbDictionary.Append ;
         end;
     20: begin //删除
           if not funCheckTableOpen() then exit;
           try
             if application.MessageBox('是否确信删除?','提示',MB_YESNO) =
                            IDNO then exit;
                atbDictionary.Delete ;
           except
             atbDictionary.Cancel ;
           end;
         end;
     30: begin //作废
           if not funCheckTableOpen() then exit;
           //数据集处在浏览状态必须改变为编辑状态
           if atbDictionary.State = dsBrowse then
              atbDictionary.Edit ;
           try
              atbDictionary.FieldByName('IfVoid').AsInteger :=1 ;
           except
              atbDictionary.Cancel ;
           end;
         end;
     40: begin //保存
           if not funCheckTableOpen() then exit;
           if atbDictionary.State = dsBrowse then exit; //在浏览状态不要保存
           try
             atbDictionary.Post ;
           except
             application.MessageBox('保存数据出错','错误',mb_ok);
             atbDictionary.Cancel ;
           end;
         end;
     50: begin //退出
           close;
         end;
    end;
end;
//表单创建时将相应的数据字典表内容检索出来
procedure TfrmDCModul.FormShow(Sender: TObject);
begin
   if atbDictionary.Active then atbDictionary.Close ;
   try
     atbDictionary.Open;
   except
     application.MessageBox('打开表出错','错误',mb_ok);
     close;
   end;
end;
//表单关闭时断开与数据库表的连接
procedure TfrmDCModul.FormClose(Sender: TObject; var Action: TCloseAction);
begin
   if atbDictionary.Active then
      atbDictionary.Close ;
end;

end.

⌨️ 快捷键说明

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