unit U_WageList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin, StdCtrls,
  cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP, ShellAPI, IniFiles, cxCheckBox, cxCalendar, cxButtonEdit,
  cxTextEdit, cxDBLookupComboBox, cxPC, cxContainer, cxDropDownEdit, jpeg, U_SLT,
  cxTimeEdit, OleCtrls, SHDocVw;

type
  TfrmWageList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    v2Column5: TcxGridDBColumn;
    v2Column8: TcxGridDBColumn;
    v2Column10: TcxGridDBColumn;
    Label2: TLabel;
    Filler: TEdit;
    v2Column14: TcxGridDBColumn;
    v2Column15: TcxGridDBColumn;
    v2Column17: TcxGridDBColumn;
    Label4: TLabel;
    Label5: TLabel;
    BegDate: TcxDateEdit;
    EndDate: TcxDateEdit;
    v2Column1: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    cxgrdUpQty: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    Label1: TLabel;
    CarNo: TEdit;
    v2Column7: TcxGridDBColumn;
    v2Column11: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v2Column12: TcxGridDBColumn;
    v2Column9: TcxGridDBColumn;
    v2Column13: TcxGridDBColumn;
    v2Column16: TcxGridDBColumn;
    v2Column18: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    TBChuLi: TToolButton;
    tbChuLiCX: TToolButton;
    GroupBox1: TGroupBox;
    ScrollBox1: TScrollBox;
    adoqueryPicture: TADOQuery;
    v2Column19: TcxGridDBColumn;
    tbDel: TToolButton;
    tbDelCX: TToolButton;
    Label3: TLabel;
    ConNo: TEdit;
    tbqzxj: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure C_CodeNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure v2Column8PropertiesEditValueChanged(Sender: TObject);
    procedure v2Column17PropertiesEditValueChanged(Sender: TObject);
    procedure TBChuLiClick(Sender: TObject);
    procedure tbChuLiCXClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure Tv2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
    procedure tbDelClick(Sender: TObject);
    procedure tbDelCXClick(Sender: TObject);
    procedure Tv2MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure v2Column7PropertiesEditValueChanged(Sender: TObject);
    procedure tbqzxjClick(Sender: TObject);
  private

    { Private declarations }
    canshu1: string;
    procedure InitImage();
    procedure InitGrid();
    procedure SetStatus();
  public
    fkhType: string;
    Fmanage: string;
  end;

var
  frmWageList: TfrmWageList;
  Mach: array of TfrmSlt;

implementation

uses
  U_DataLink, U_Fun, U_RTFun, U_ZDYHelp, U_WageListInput, U_InspectionInfo,
  U_JTList;

{$R *.dfm}
procedure TfrmWageList.InitImage();
var
  i, j: integer;
  jpg: TJpegImage;
  myStream: TADOBlobStream;
begin
  j := length(Mach);
  if j > 0 then
  begin
    for i := 0 to j - 1 do
    begin
      Mach[i].free;
    end;
  end;
  SetLength(Mach, 0);
  if CDS_HZ.IsEmpty then
    exit;
  try
    with adoqueryPicture do
    begin
      close;
      sql.Clear;
      sql.Add(' select A.TFID,A.WBID,A.FilesOther,A.FileName from TP_File A  ');
      sql.add('where   A.WBID in(' + quotedstr(trim(CDS_HZ.fieldbyname('DetailId').AsString)) + ',' + quotedstr(trim(CDS_HZ.fieldbyname('UpDetailId').AsString)) + ')');
      open;
    end;
    j := adoqueryPicture.RecordCount;
    if j < 1 then
      exit;
    adoqueryPicture.DisableControls;
    adoqueryPicture.First;
    SetLength(Mach, j);
    jpg := TJpegImage.Create();
    for i := 0 to j - 1 do
    begin
      if triM(adoqueryPicture.fieldbyname('FilesOther').AsString) <> '' then
      begin
        myStream := tadoblobstream.Create(tblobfield(adoqueryPicture.fieldbyname('FilesOther')), bmread);
        jpg.LoadFromStream(myStream);
        Mach[i] := TfrmSlt.Create(Self);
        Mach[i].Name := trim(adoqueryPicture.fieldbyname('TFID').AsString);
        Mach[i].Parent := ScrollBox1;
        Mach[i].Left := 0 + i * 165;
        Mach[i].Init(adoqueryPicture.fieldbyname('TFID').AsString, adoqueryPicture.fieldbyname('FileName').AsString, jpg);
      end;
      adoqueryPicture.Next;
    end;
    adoqueryPicture.EnableControls;
  finally
    jpg.free;
    application.ProcessMessages;
  end;
end;

procedure TfrmWageList.SetStatus();
begin
  TBChuLi.Visible := False;
  tbChuLiCX.Visible := False;
  tbDel.Visible := False;
  tbDelCX.Visible := False;
  tbqzxj.Visible := False;
  case cxTabControl1.TabIndex of
    0:
      begin
        tbqzxj.Visible := True;
      end;
    1:
      begin
        TBChuLi.Visible := True;
        tbDel.Visible := True;
      end;
    2:
      begin
        tbChuLiCX.Visible := True;
      end;

    3:
      begin
        tbDelCX.Visible := True;
      end;
  end;
end;

procedure TfrmWageList.InitGrid();
begin
  try

    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add('select  A.*,MPMoney=A.WzPrice*A.Qty,C.ZhuanQty');
      sql.Add(',KGQty=(case when ZhuanQty>0 then Qty/ZhuanQty else 0 end)');
      sql.Add(',B.ConNo,C.C_Code,C.C_CodeName from Worker_WorkDetail A ');
      sql.Add('inner join Cloth_Main B on A.MainId=B.MainId');
      sql.Add('inner join Cloth_Sub C on A.SubId=C.SubId');
      sql.Add('where A.UpTime>' + quotedstr(Trim(BegDate.Text)));
      sql.Add(' and A.UpTime<=' + quotedstr(Trim(EndDate.Text)));
      case cxTabControl1.TabIndex of
        0:
          begin
            sql.Add(' and  A.CarStatus=''上机'' ');
            sql.Add(' and   A.Valid=''Y'' ');
          end;
        1:
          begin
            sql.Add(' and  A.CarStatus=''下机'' and   A.ChuLiFlag=0 ');
            sql.Add(' and   A.Valid=''Y'' ');
          end;
        2:
          begin
            sql.Add(' and   A.ChuLiFlag=1 ');
            sql.Add(' and   A.Valid=''Y'' ');
          end;
        3:
          begin
            sql.Add(' and   A.Valid=''N'' ');
          end;
        4:
          begin
            sql.Add(' and   A.Valid=''Y'' ');
          end;
      end;
      Open;
    end;

    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
    CDS_HZ.Last;
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmWageList.FormDestroy(Sender: TObject);
var
  i, j: integer;
begin
  j := length(Mach);
  if j > 0 then
  begin
    for i := 0 to j - 1 do
    begin
      Mach[i].free;
    end;
  end;
  SetLength(Mach, 0);
  frmWageList := nil;
end;

procedure TfrmWageList.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TfrmWageList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(trim(self.Caption), Tv2, '工资管理');
  Close;
end;

procedure TfrmWageList.FormShow(Sender: TObject);
begin
  ReadCxGrid(trim(self.Caption), Tv2, '工资管理');
  SetStatus();
  InitGrid();
end;

procedure TfrmWageList.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmWageList.ToolButton2Click(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, CDS_HZ);
    SInitCDSData20(ADOQueryMain, CDS_HZ);
  end;
end;

procedure TfrmWageList.C_CodeNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmWageList.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  TcxGridToExcel(self.Caption, cxgrid2);
 // SelExportData(Tv2,ADOQueryMain,'客户资料列表');
end;

procedure TfrmWageList.FormCreate(Sender: TObject);
begin
  EndDate.Text := FormatDateTime('yyyy-MM-dd', SGetServerDate10(ADOQueryTemp)) + ' 08:00:00';
  BegDate.Text := FormatDateTime('yyyy-MM-dd', SGetServerDate10(ADOQueryTemp) - 1) + ' 08:00:00';
  canshu1 := Trim(DParameters1);
end;

procedure TfrmWageList.v2Column8PropertiesEditValueChanged(Sender: TObject);
var
  FFieldName, mvalue: string;
  FUpQty, FDownQty, FQty, FWzPrice, FMPMoney: double;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);

  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value := strtofloatdef(mvalue, 0);
    Post;
    FUpQty := FieldByName('UpQty').asfloat;
    FDownQty := FieldByName('DownQty').asfloat;
    FQty := FieldByName('Qty').asfloat;
    FWzPrice := FieldByName('WzPrice').asfloat;
    FMPMoney := FieldByName('MPMoney').asfloat;

  end;
  if (FFieldName = 'UpQty') or (FFieldName = 'DownQty') then
  begin
    FQty := FDownQty - FUpQty;
  end;
  FMPMoney := RoundFloat(FWzPrice * FQty / 10000, 2);

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('update Worker_WorkDetail set UpQty=' + floattostr(FUpQty));
    sql.Add(' , DownQty=' + floattostr(FDownQty));
    sql.Add(' , Qty=' + floattostr(FQty));
    sql.Add(' , Editer=' + quotedstr(DName));
    sql.Add(' , Edittime=getdate()');
    sql.Add(' where DetailId=' + quotedstr(trim(Self.CDS_HZ.FieldByName('DetailId').AsString)));
    EXECSQL;
  end;
  with CDS_HZ do
  begin
    Edit;
    FieldByName('UpQty').Value := FUpQty;
    FieldByName('DownQty').Value := FDownQty;
    FieldByName('Qty').Value := FQty;
    FieldByName('MPMoney').Value := FMPMoney;
    FieldByName('Editer').Value := DName;
    FieldByName('Edittime').Value := Now;
    Post;
  end;
  tv2.Controller.EditingController.ShowEdit();
end;

procedure TfrmWageList.v2Column17PropertiesEditValueChanged(Sender: TObject);
var
  FFieldName, mvalue: string;
begin

  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('update Worker_WorkDetail set ' + FFieldName + ' =' + quotedstr(mvalue));
    sql.Add(' where DetailId=' + quotedstr(trim(Self.CDS_HZ.FieldByName('DetailId').AsString)));
    EXECSQL;
  end;
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value := mvalue;
    Post;
  end;
  tv2.Controller.EditingController.ShowEdit();
end;

procedure TfrmWageList.TBChuLiClick(Sender: TObject);
begin
  if CDS_HZ.Locate('ssel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要处理数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_HZ.DisableControls;
    with CDS_HZ do
    begin
      First;
      while CDS_HZ.Locate('SSel', True, []) do
      begin
        if CDS_HZ.FieldByName('SSel').AsBoolean = True then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add(' UPdate Worker_WorkDetail Set ChuLiFlag=1,ChuLiDate=getdate(),ChuLiPerson=''' + Trim(DName) + '''');
            sql.Add(' where DetailId=''' + Trim(CDS_HZ.fieldbyname('DetailId').AsString) + '''');
            ExecSQL;
          end;
          CDS_HZ.Delete;
        end;
      end;
    end;
    CDS_HZ.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!', '提示', 0);
  end;
end;

procedure TfrmWageList.tbChuLiCXClick(Sender: TObject);
begin
  if CDS_HZ.Locate('ssel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要撤销处理吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_HZ.DisableControls;
    with CDS_HZ do
    begin
      First;
      while CDS_HZ.Locate('SSel', True, []) do
      begin
        if CDS_HZ.FieldByName('SSel').AsBoolean = True then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add(' UPdate Worker_WorkDetail Set ChuLiFlag=0,ChuLiDate=getdate(),ChuLiPerson=''' + Trim(DName) + '''');
            sql.Add(' where DetailId=''' + Trim(CDS_HZ.fieldbyname('DetailId').AsString) + '''');
            ExecSQL;
          end;
          CDS_HZ.Delete;
        end;
      end;
    end;
    CDS_HZ.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!', '提示', 0);
  end;
end;

procedure TfrmWageList.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
  SetStatus();
end;

procedure TfrmWageList.Tv2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
  if CDS_HZ.IsEmpty then
    Exit;
  InitImage();
end;

procedure TfrmWageList.tbDelClick(Sender: TObject);
begin
  if CDS_HZ.Locate('ssel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要处理数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_HZ.DisableControls;
    with CDS_HZ do
    begin
      First;
      while CDS_HZ.Locate('SSel', True, []) do
      begin
        if CDS_HZ.FieldByName('SSel').AsBoolean = True then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add(' UPdate Worker_WorkDetail Set Valid= ''N'' ');
            sql.Add(' where DetailId=''' + Trim(CDS_HZ.fieldbyname('DetailId').AsString) + '''');
            ExecSQL;
          end;
          CDS_HZ.Delete;
        end;
      end;
    end;
    CDS_HZ.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!', '提示', 0);
  end;
end;

procedure TfrmWageList.tbDelCXClick(Sender: TObject);
begin
  if CDS_HZ.Locate('ssel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要处理数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_HZ.DisableControls;
    with CDS_HZ do
    begin
      First;
      while CDS_HZ.Locate('SSel', True, []) do
      begin
        if CDS_HZ.FieldByName('SSel').AsBoolean = True then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add(' UPdate Worker_WorkDetail Set Valid= ''Y'' ');
            sql.Add(' where DetailId=''' + Trim(CDS_HZ.fieldbyname('DetailId').AsString) + '''');
            ExecSQL;
          end;
          CDS_HZ.Delete;
        end;
      end;
    end;
    CDS_HZ.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!', '提示', 0);
  end;
end;

procedure TfrmWageList.Tv2MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  i: Integer;
begin
  case cxTabControl1.TabIndex of
    0:
      begin
        for i := 0 to tv2.ColumnCount - 1 do
        begin
          if uppercase(tv2.Columns[i].DataBinding.FieldName) <> 'SSEL' then
            tv2.Columns[i].Options.Editing := true;
        end;
      end;
    1:
      begin
        for i := 0 to tv2.ColumnCount - 1 do
        begin
          if uppercase(tv2.Columns[i].DataBinding.FieldName) <> 'SSEL' then
            tv2.Columns[i].Options.Editing := true;
        end;
      end;
    2:
      begin
        for i := 0 to tv2.ColumnCount - 1 do
        begin
          if uppercase(tv2.Columns[i].DataBinding.FieldName) <> 'SSEL' then
            tv2.Columns[i].Options.Editing := false;
        end;
      end;
    3:
      begin
        for i := 0 to tv2.ColumnCount - 1 do
        begin
          if uppercase(tv2.Columns[i].DataBinding.FieldName) <> 'SSEL' then
            tv2.Columns[i].Options.Editing := false;
        end;
      end;
    4:
      begin
        for i := 0 to tv2.ColumnCount - 1 do
        begin
          if uppercase(tv2.Columns[i].DataBinding.FieldName) <> 'SSEL' then
            tv2.Columns[i].Options.Editing := false;
        end;
      end;
  end;

end;

procedure TfrmWageList.v2Column7PropertiesEditValueChanged(Sender: TObject);
var
  FFieldName, mvalue: string;
begin

  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('update Worker_WorkDetail set ' + FFieldName + ' =' + QuotedStr(mvalue));
    sql.Add(' where DetailId=' + quotedstr(trim(Self.CDS_HZ.FieldByName('DetailId').AsString)));
    EXECSQL;
  end;
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value := mvalue;
    Post;
  end;
  tv2.Controller.EditingController.ShowEdit();
end;

procedure TfrmWageList.tbqzxjClick(Sender: TObject);
var
  maxno: string;
begin
  if GetLSNo(ADOQueryMain, maxno, 'WD', 'Worker_WorkDetail', 3, 1) = False then
  begin
    Application.MessageBox('取最大号失败!', '提示', 0);
    Exit;
  end;
  try

    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin 
      Close;
      SQL.Clear;
      sql.Add(' update Worker_WorkDetail set CarStatus=''下机''');
      sql.Add(' ,Note=' + quotedstr(trim(DName) + formatdateTime('yyyy-MM-dd', Now())));
      sql.Add('  where DetailId=' + quotedstr(trim(Self.CDS_HZ.FieldByName('DetailId').AsString)));

      sql.Add('insert into Worker_WorkDetail(');
      sql.Add('DetailId,MainId,SubId,APID,WzPrice,CarNo,CarStatus,Action,IsHandover,isOrcSuccess');
      sql.Add(',Qty,UpQtyOrc,DownQtyOrc,UpQty,DownQty,StaffName,Filler,FillerCode,FillerTime,UpTime');
      sql.Add(',DownTime,Editer,Edittime,Valid,UpDetailId,AllQty,MachineCountMode,PrevDownDetailId');
      sql.Add(',IsError,Note,ISCheck,Chker,ChkTime,ChuLiFlag,ChuLiDate,ChuLiPerson)');
      sql.Add('select ' + quotedstr(maxno) + ',MainId,SubId,APID,WzPrice,CarNo,CarStatus,''下机'',IsHandover,isOrcSuccess');
      sql.Add(',Qty,UpQtyOrc,DownQtyOrc,UpQty,DownQty,StaffName,Filler,FillerCode,FillerTime,UpTime');
      sql.Add(',DownTime,Editer,Edittime,Valid,DetailId,AllQty,MachineCountMode,PrevDownDetailId');
      sql.Add(',IsError,Note,ISCheck,Chker,ChkTime,1,getdate(),' + quotedstr(Trim(DName)));
      sql.Add(' from Worker_WorkDetail where DetailId=' + quotedstr(trim(Self.CDS_HZ.FieldByName('DetailId').AsString)));
      ExecSQL;                   
    end;
    CDS_HZ.Delete;

  finally
    ADOQueryMain.EnableControls;
  end;
end;

end.

