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

📄 untdeletedata.pas

📁 简要说明:对医院幼儿心理情况做的一个调查,统计系统.
💻 PAS
字号:
unit untDeleteData;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, untBaseDialog, StdCtrls, Buttons, ExtCtrls, Mask, DBCtrlsEh,
  DBLookupEh, DBCtrls, DB, ADODB, fcButton, fcImgBtn;

type
  TfrmDeleteData = class(TfrmBaseDialog)
    adsSchool: TADODataSet;
    adsClass: TADODataSet;
    dsClass: TDataSource;
    dsSchool: TDataSource;
    cboSchool: TDBLookupComboBox;
    cboClass: TDBLookupComboboxEh;
    Label1: TLabel;
    Label2: TLabel;
    chkXL: TCheckBox;
    chkQZ: TCheckBox;
    chkXW: TCheckBox;
    chkStudent: TCheckBox;
    Label3: TLabel;
    Label4: TLabel;
    procedure FormShow(Sender: TObject);
    procedure btnOKClick(Sender: TObject);
    procedure adsSchoolAfterScroll(DataSet: TDataSet);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmDeleteData: TfrmDeleteData;

const
  strSQLFirst = 'declare @Classid int '
                +' set @classid = :Classid ';
  strSQLXL = ' delete from tChildrenResult_Mx '+
             ' where checkresultid in (select iAutoID from tChildrenResult '+
             '       where MeasureCode = ''0000000003'' '+
             '         and ChildrenID in (select iAutoID from tChildren where classid=@classid)) '+
             ' delete from tChildrenResult '+
             ' where MeasureCode = ''0000000003'' '+
             '   and ChildrenID in (select iAutoID from tChildren where classid=@classid) '+
             ' delete from tXLResult where childrenid in (select iAutoID from tChildren where classid=@classid) ';
  strSQLQZ = ' delete from tChildrenResult_Mx '+
             ' where checkresultid in (select iAutoID from tChildrenResult '+
             '       where MeasureCode = ''0000000002'' '+
             '         and ChildrenID in (select iAutoID from tChildren where classid=@classid)) '+
             ' delete from tChildrenResult '+
             ' where MeasureCode = ''0000000002'' '+
             '   and ChildrenID in (select iAutoID from tChildren where classid=@classid) '+
             ' delete from tqzresult where childrenid in (select iAutoID from tChildren where classid=@classid) '+
             ' delete from tqztableresult where childrenid in (select iAutoID from tChildren where classid=@classid)';
  strSQLXW = ' delete from tChildrenResult_Mx '+
             ' where checkresultid in (select iAutoID from tChildrenResult '+
             '       where MeasureCode = ''0000000001'' '+
             '         and ChildrenID in (select iAutoID from tChildren where classid=@classid)) '+
             ' delete from tChildrenResult '+
             ' where MeasureCode = ''0000000001'' '+
             '   and ChildrenID in (select iAutoID from tChildren where classid=@classid) '+
             ' delete from txwresult where childrenid in (select iAutoID from tChildren where classid=@classid)';
  strSQLChildren = ' delete from tChildren where classid=@classid';
implementation

uses untGlobalFun, untDM;

{$R *.dfm}

procedure TfrmDeleteData.FormShow(Sender: TObject);
begin
  inherited;
  with adsSchool do begin
    if not active then Active:= True;
  end;
  with adsClass do begin
    if not Active then Active := true;
  end;
end;

procedure TfrmDeleteData.btnOKClick(Sender: TObject);
var
  strSQL: string;
begin
  inherited;
  if VarIsNull(cboSchool.KeyValue) then begin
    MsgOK('请选择学校!');
    cboSchool.SetFocus;
    Exit;
  end;
  if VarIsNull(cboClass.KeyValue) then begin
    MsgOK('请选择班级!');
    cboClass.SetFocus;
    Exit;
  end;
  if (not chkXL.Checked) and (not chkQZ.Checked) and (not chkXW.Checked) then
  begin
    MsgOK('请选择数据类型!');
    Exit;
  end;
  strSQL := strSQLFirst;
  if chkXL.Checked then strSQL := strSQL + strSQLXL;
  if chkQZ.Checked then strSQL := strSQL + strSQLQZ;
  if chkXW.Checked then strSQL := strSQL + strSQLXW;
  if chkStudent.Checked then strSQL := strSQL + strSQLChildren;
  DM.cnn.BeginTrans;
  try
    with TADOCommand.Create(nil) do begin
      Connection := DM.cnn;
      CommandText := strSQL;
      Prepared := true;
      Prepared := False;
      Parameters.ParamByName('ClassID').Value := cboClass.KeyValue;
      Execute;
      Free;
    end;
    DM.cnn.CommitTrans;
    MsgOK('数据删除成功! ');
  except
    DM.cnn.RollbackTrans;
    MsgOK('删除数据失败,请联系管理员');
  end;
end;

procedure TfrmDeleteData.adsSchoolAfterScroll(DataSet: TDataSet);
begin
  inherited;
  with adsClass do begin
    if Active then Active := false;
    Active := true;
    if Filtered then Filtered := false;
    Filter := 'SchoolID='+DataSet.FieldByName('iAutoID').AsString;
    Filtered := true;
  end;
end;

end.

⌨️ 快捷键说明

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