unit U_DeptType;

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, cxPC, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator;

type
  TfrmDeptType = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ADOQueryMain: TADOQuery;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    Panel2: TPanel;
    ToolBar2: TToolBar;
    ToolButton10: TToolButton;
    ToolButton11: TToolButton;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2Column6: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Panel3: TPanel;
    Panel4: TPanel;
    ToolBar3: TToolBar;
    ToolButton7: TToolButton;
    ToolButton8: TToolButton;
    cxGrid1: TcxGrid;
    Tv21: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    Panel5: TPanel;
    ToolBar4: TToolBar;
    ToolButton13: TToolButton;
    ToolButton14: TToolButton;
    cxGrid3: TcxGrid;
    Tv23: TcxGridDBTableView;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    cxGrid4: TcxGrid;
    Tv22: TcxGridDBTableView;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridLevel4: TcxGridLevel;
    Tv23Column1: TcxGridDBColumn;
    ToolButton15: TToolButton;
    ToolButton16: TToolButton;
    CDS_21: TClientDataSet;
    DS_21: TDataSource;
    CDS_22: TClientDataSet;
    DS_22: TDataSource;
    CDS_23: TClientDataSet;
    DS_23: TDataSource;
    ToolButton1: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure v2Column1PropertiesEditValueChanged(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure v2Column6PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure cxGridDBColumn3PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ToolButton7Click(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
    procedure cxGridDBColumn1PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ToolButton13Click(Sender: TObject);
    procedure ToolButton14Click(Sender: TObject);
    procedure ToolButton15Click(Sender: TObject);
    procedure cxGridDBColumn2PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure Tv23Column1PropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton16Click(Sender: TObject);
    procedure Tv22MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Tv2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure ToolButton1Click(Sender: TObject);
  private
    { Private declarations }

    procedure InitGrid();
    procedure InitGrid21();
    procedure InitGrid22();
    procedure InitGrid23();
    function  SaveData():Boolean;
    function  SaveData21():Boolean;
    function  SaveData22():Boolean;
    function  SaveData23():Boolean;

  public
    canshu1:string;

  end;

var
  frmDeptType: TfrmDeptType;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp,U_RTFun;

{$R *.dfm}



procedure TfrmDeptType.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      SQL.Clear;
      sql.Add(' select A.* ');
      sql.Add('  from BX_FeeType A');
      sql.Add(' where A.Valid=''Y'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
  end;
end;
procedure TfrmDeptType.InitGrid21();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      SQL.Clear;
      sql.Add(' select A.* ');
      sql.Add('  from BX_FeeName A');
      sql.Add(' where A.Valid=''Y'' and A.BTID='''+Trim(CDS_HZ.fieldbyname('BTID').asstring)+'''');
      if CDS_HZ.IsEmpty then
      begin
        sql.Add(' and 1=2');
      end else
      begin
        sql.Add(' and A.BTID='''+Trim(CDS_HZ.fieldbyname('BTID').asstring)+'''');
      end;

      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_21);
    SInitCDSData20(ADOQueryMain,CDS_21);
  finally
    ADOQueryMain.EnableControls;

  end;
end;
procedure TfrmDeptType.InitGrid22();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      SQL.Clear;
      sql.Add(' select A.* ');
      sql.Add('  from BX_ChkLiu_Main A');
      sql.Add(' where A.Valid=''Y'' ');
      if CDS_HZ.IsEmpty then
      begin
        sql.Add(' and 1=2');
      end else
      begin
        sql.Add(' and A.BTID='''+Trim(CDS_HZ.fieldbyname('BTID').asstring)+'''');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_22);
    SInitCDSData20(ADOQueryMain,CDS_22);
  finally
    ADOQueryMain.EnableControls;
  end;
end;
procedure TfrmDeptType.InitGrid23();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      SQL.Clear;
      sql.Add(' select A.* ');
      sql.Add('  from BX_ChkLiu_Sub A');
      sql.Add(' where A.Valid=''Y'' ');
      if CDS_22.IsEmpty then
      begin
        sql.Add(' and 1=2');
      end else
      begin
        sql.Add(' and A.BMID='''+Trim(CDS_22.fieldbyname('BMID').asstring)+'''');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_23);
    SInitCDSData20(ADOQueryMain,CDS_23);
  finally
    ADOQueryMain.EnableControls;
  end;
end;


procedure TfrmDeptType.FormDestroy(Sender: TObject);
begin
  frmDeptType:=nil;
end;

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

procedure TfrmDeptType.TBCloseClick(Sender: TObject);
begin
  Close;
end;
procedure TfrmDeptType.TBDelClick(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then Exit;
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add(' Update BX_FeeType Set DelTime=getdate(),Deler='''+Trim(DName)+''',Valid=''N'' ');
      sql.Add(' where BTID='''+Trim(CDS_HZ.fieldbyname('BTID').AsString)+'''');
      execsql;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    CDS_HZ.Delete;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('删除失败!','提示',0);
  end;
  InitGrid21();
  InitGrid22();
end;

procedure TfrmDeptType.FormShow(Sender: TObject);
begin
  InitGrid();
end;

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

function TfrmDeptType.SaveData():Boolean;
var
  maxId,CRID:String;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    if GetLSNo(ADOQueryCmd,maxId,'BT','BX_FeeType',4,1)=False then
    begin
      Result:=False;
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取最大号失败！','提示',0);
      Exit;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from BX_FeeType where 1<>1');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('BTID').Value:=Trim(maxId);
      FieldByName('Filler').Value:=Trim(DName);
      FieldByName('Valid').Value:='Y';
      Post;
    end;
    with CDS_HZ do
    begin
      Edit;
      FieldByName('BTID').Value:=Trim(maxId);
      Post;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=True;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作失败!','提示',0);
  end;
end;
function TfrmDeptType.SaveData21():Boolean;
var
  maxId,CRID:String;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    if GetLSNo(ADOQueryCmd,maxId,'BF','BX_FeeName',4,1)=False then
    begin
      Result:=False;
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取最大号失败！','提示',0);
      Exit;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from BX_FeeName where 1<>1');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('BTID').Value:=Trim(CDS_HZ.fieldbyname('BTID').AsString);
      FieldByName('BFID').Value:=Trim(maxId);
      FieldByName('Filler').Value:=Trim(DName);
      FieldByName('Valid').Value:='Y';
      Post;
    end;
    with CDS_21 do
    begin
      Edit;
      FieldByName('BFID').Value:=Trim(maxId);
      Post;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=True;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作失败!','提示',0);
  end;
end;

function TfrmDeptType.SaveData22():Boolean;
var
  maxId,CRID:String;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    if GetLSNo(ADOQueryCmd,maxId,'BM','BX_ChkLiu_Main',4,1)=False then
    begin
      Result:=False;
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取最大号失败！','提示',0);
      Exit;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from BX_ChkLiu_Main where 1<>1');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('BTID').Value:=Trim(CDS_HZ.fieldbyname('BTID').AsString);
      FieldByName('BMID').Value:=Trim(maxId);
      FieldByName('Filler').Value:=Trim(DName);
      FieldByName('Valid').Value:='Y';
      Post;
    end;
    with CDS_22 do
    begin
      Edit;
      FieldByName('BMID').Value:=Trim(maxId);
      Post;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=True;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作失败!','提示',0);
  end;
end;
function TfrmDeptType.SaveData23():Boolean;
var
  maxId,CRID:String;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    if GetLSNo(ADOQueryCmd,maxId,'BS','BX_ChkLiu_Sub',4,1)=False then
    begin
      Result:=False;
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取最大号失败！','提示',0);
      Exit;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from BX_ChkLiu_Sub where 1<>1');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('BMID').Value:=Trim(CDS_22.fieldbyname('BMID').AsString);
      FieldByName('BSID').Value:=Trim(maxId);
      FieldByName('Filler').Value:=Trim(DName);
      FieldByName('Valid').Value:='Y';
      
      Post;
    end;
    with CDS_23 do
    begin
      Edit;
      FieldByName('BSID').Value:=Trim(maxId);
      Post;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=True;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作失败!','提示',0);
  end;
end;

procedure TfrmDeptType.ToolButton3Click(Sender: TObject);
begin
  with Self.CDS_HZ do
  begin
    Append;
    FieldByName('Filler').Value:=Trim(DName);
    Post;
  end;
  Self.SaveData();
  InitGrid21();
  InitGrid22();
  InitGrid23();
end;

procedure TfrmDeptType.v2Column1PropertiesEditValueChanged(Sender: TObject);
var
  mvalue,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value:=Trim(mvalue);
    Post;
  end;

end;

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

procedure TfrmDeptType.v2Column6PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='BXDeptName';
      flagname:='部门';
      if ShowModal=1 then
      begin
        with CDS_HZ do
        begin
          edit;
          FieldByName('DeptName').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
          Post;
        end;
        with Self.ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update BX_FeeType Set DeptName='''+Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
          sql.Add(' where BTID='''+Trim(Self.CDS_HZ.fieldbyname('BTID').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmDeptType.cxGridDBColumn3PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='BXFeeType';
      flagname:='费用类型';
      if ShowModal=1 then
      begin
        with CDS_HZ do
        begin
          edit;
          FieldByName('FeeType').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
          Post;
        end;
        with Self.ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update BX_FeeType Set FeeType='''+Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
          sql.Add(' where BTID='''+Trim(Self.CDS_HZ.fieldbyname('BTID').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmDeptType.ToolButton7Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then Exit;
  with Self.CDS_21 do
  begin
    Append;
    FieldByName('Filler').Value:=Trim(DName);
    Post;
  end;
  Self.SaveData21();
end;

procedure TfrmDeptType.ToolButton8Click(Sender: TObject);
begin
  if CDS_21.IsEmpty then Exit;
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add(' Update BX_FeeName Set DelTime=getdate(),Deler='''+Trim(DName)+''',Valid=''N'' ');
      sql.Add(' where BFID='''+Trim(CDS_21.fieldbyname('BFID').AsString)+'''');
      execsql;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    CDS_21.Delete;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('删除失败!','提示',0);
  end;
end;

procedure TfrmDeptType.cxGridDBColumn1PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='BXFeeName';
      flagname:='费用名称';
      if ShowModal=1 then
      begin
        with CDS_21 do
        begin
          edit;
          FieldByName('FeeName').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
          Post;
        end;
        with Self.ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update BX_FeeName Set FeeName='''+Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
          sql.Add(' where BFID='''+Trim(Self.CDS_21.fieldbyname('BFID').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmDeptType.ToolButton13Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then Exit;
  with Self.CDS_22 do
  begin
    Append;
    FieldByName('Filler').Value:=Trim(DName);
    Post;
  end;
  Self.SaveData22();
  InitGrid23();
end;

procedure TfrmDeptType.ToolButton14Click(Sender: TObject);
begin
  if CDS_22.IsEmpty then Exit;
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add(' Update BX_ChkLiu_Main Set DelTime=getdate(),Deler='''+Trim(DName)+''',Valid=''N'' ');
      sql.Add(' where BMID='''+Trim(CDS_22.fieldbyname('BMID').AsString)+'''');
      execsql;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    CDS_22.Delete;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('删除失败!','提示',0);
  end;
  InitGrid23();
end;

procedure TfrmDeptType.ToolButton15Click(Sender: TObject);
var
  FChkInt:Integer;
begin
  FChkInt:=CDS_23.RecordCount;
  if CDS_22.IsEmpty then Exit;
  with Self.CDS_23 do
  begin
    Append;
    FieldByName('Filler').Value:=Trim(DName);
    FieldByName('ChkInt').Value:=FChkInt+1;
    Post;
  end;
  Self.SaveData23();
end;

procedure TfrmDeptType.cxGridDBColumn2PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='BXChker';
      flagname:='费用名称';
      if ShowModal=1 then
      begin
        with CDS_23 do
        begin
          edit;
          FieldByName('Chker').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
          Post;
        end;
        with Self.ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update BX_ChkLiu_Sub Set Chker='''+Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
          if Trim(Self.CDS_23.fieldbyname('ChkInt').AsString)<>'' then
          begin
            sql.Add(',ChkInt='+Self.CDS_23.fieldbyname('ChkInt').AsString);
          end else
          begin
            sql.Add(',ChkInt=Null');
          end;

          sql.Add(' where BSID='''+Trim(Self.CDS_23.fieldbyname('BSID').AsString)+'''');
          ExecSQL;
        end;
        with Self.ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update BX_ChkLiu_Main Set ');

          Sql.Add(' ChkerHZ=[dbo].[F_Get_Order_SubStr_PB](BX_ChkLiu_Main.BMID,''ChkerHZ'')');

          sql.Add(' where BMID='''+Trim(Self.CDS_22.fieldbyname('BMID').AsString)+'''');
          ExecSQL;
        end;
        with Self.ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from BX_ChkLiu_Main');
          sql.Add(' where BMID='''+Trim(Self.CDS_22.fieldbyname('BMID').AsString)+'''');
          Open;
        end;
        with CDS_22 do
        begin
          Edit;
          FieldByName('ChkerHZ').Value:=Trim(Self.ADOQueryTemp.fieldbyname('ChkerHZ').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmDeptType.Tv23Column1PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  if Trim(mvalue)='' then
  begin
    with CDS_23 do
    begin
      Edit;
      FieldByName('ChkInt').Value:=null;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update BX_ChkLiu_Sub Set ChkInt=Null where BSID='''+Trim(CDS_23.fieldbyname('BSID').AsString)+'''');
      ExecSQL;
    end;
  end else
  begin
    with CDS_23 do
    begin
      Edit;
      FieldByName('ChkInt').Value:=mvalue;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update BX_ChkLiu_Sub Set ChkInt='+mvalue+' where BSID='''+Trim(CDS_23.fieldbyname('BSID').AsString)+'''');
      ExecSQL;
    end;
  end;
  with Self.ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update BX_ChkLiu_Main Set ');

    Sql.Add(' ChkerHZ=[dbo].[F_Get_Order_SubStr_PB](BX_ChkLiu_Main.BMID,''ChkerHZ'')');

    sql.Add(' where BMID='''+Trim(Self.CDS_22.fieldbyname('BMID').AsString)+'''');
    ExecSQL;
  end;
  with Self.ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from BX_ChkLiu_Main');
    sql.Add(' where BMID='''+Trim(Self.CDS_22.fieldbyname('BMID').AsString)+'''');
    Open;
  end;
  with CDS_22 do
  begin
    Edit;
    FieldByName('ChkerHZ').Value:=Trim(Self.ADOQueryTemp.fieldbyname('ChkerHZ').AsString);
  end;
end;

procedure TfrmDeptType.ToolButton16Click(Sender: TObject);
begin
  if CDS_23.IsEmpty then Exit;
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add(' Update BX_ChkLiu_Sub Set DelTime=getdate(),Deler='''+Trim(DName)+''',Valid=''N'' ');
      sql.Add(' where BSID='''+Trim(CDS_23.fieldbyname('BSID').AsString)+'''');
      execsql;
    end;

    CDS_23.Delete;
    with Self.ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update BX_ChkLiu_Main Set ');

      Sql.Add(' ChkerHZ=[dbo].[F_Get_Order_SubStr_PB](BX_ChkLiu_Main.BMID,''ChkerHZ'')');

      sql.Add(' where BMID='''+Trim(Self.CDS_22.fieldbyname('BMID').AsString)+'''');
      ExecSQL;
    end;
    with Self.ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from BX_ChkLiu_Main');
      sql.Add(' where BMID='''+Trim(Self.CDS_22.fieldbyname('BMID').AsString)+'''');
      Open;
    end;
    with CDS_22 do
    begin
      Edit;
      FieldByName('ChkerHZ').Value:=Trim(Self.ADOQueryTemp.fieldbyname('ChkerHZ').AsString);
    end;
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('删除失败!','提示',0);
  end;
end;

procedure TfrmDeptType.Tv22MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  InitGrid23();
end;

procedure TfrmDeptType.Tv2MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  InitGrid21();
  InitGrid22();
end;

procedure TfrmDeptType.ToolButton1Click(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='BXName';
      flagname:='对方单位';
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

end.
