unit U_XiaoShouDataNewListQB;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, DBClient, cxCheckBox, cxCalendar, cxSplitter, RM_Dataset, RM_System,
  RM_Common, RM_Class, RM_GridReport, RM_e_Xls, Menus, cxButtonEdit,
  cxDropDownEdit, cxPC, Buttons, BtnEdit, cxTextEdit, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu, dxSkinsCore,
  dxSkinDarkRoom, dxSkinOffice2013White, dxSkinSharpPlus, dxSkinSpringTime,
  dxSkinsDefaultPainters, dxSkinscxPCPainter, dxSkinBlack, dxSkinBlue,
  dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkSide,
  dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinFoggy,
  dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian,
  dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMetropolis,
  dxSkinMetropolisDark, dxSkinMoneyTwins, dxSkinOffice2007Black,
  dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink,
  dxSkinOffice2007Silver, dxSkinOffice2010Black, dxSkinOffice2010Blue,
  dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
  dxSkinOffice2013LightGray, dxSkinPumpkin, dxSkinSeven,
  dxSkinSevenClassic, dxSkinSharp, dxSkinSilver, dxSkinStardust,
  dxSkinSummer2008, dxSkinTheAsphaltWorld, dxSkinValentine, dxSkinVS2010,
  dxSkinWhiteprint, dxSkinXmas2008Blue;

type
  TfrmXiaoShouDataNewListQB = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Order_Main: TClientDataSet;
    Panel1: TPanel;
    v1Column1: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    Label3: TLabel;
    Label4: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    v1Column17: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    Label2: TLabel;
    MPRTCodeName: TEdit;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    Label5: TLabel;
    PRTColor: TEdit;
    labMYType: TLabel;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    Label6: TLabel;
    PRTHX: TEdit;
    v1Column8: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    v1Column2: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    ToolButton1: TToolButton;
    v1SSel: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    CDS_Sub: TClientDataSet;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    DataSource2: TDataSource;
    ADOQuery1: TADOQuery;
    ToolButton2: TToolButton;
    Panel3: TPanel;
    Panel2: TPanel;
    Label1: TLabel;
    KHName: TBtnEditC;
    Label7: TLabel;
    CustomerNoName: TEdit;
    ToolButton3: TToolButton;
    Button1: TButton;
    Panel10: TPanel;
    Image2: TImage;
    Label8: TLabel;
    KHDept: TComboBox;
    Label9: TLabel;
    KHLXR: TComboBox;
    v1Column18: TcxGridDBColumn;
    Label10: TLabel;
    KHLXFS: TEdit;
    Label11: TLabel;
    RadioGroup1: TRadioGroup;
    ToolButton4: TToolButton;
    RM1: TRMGridReport;
    RMDBHZ: TRMDBDataSet;
    CDS_PRT: TClientDataSet;
    RMXLSExport2: TRMXLSExport;
    v1Column19: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    Panel4: TPanel;
    Label12: TLabel;
    MDName: TBtnEditA;
    ADOQueryPrint1: TADOQuery;
    ADOQueryPrint: TADOQuery;
    RMDBHZ1: TRMDBDataSet;
    ADOQuery2: TADOQuery;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure CustomerNoNameChange(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ZJStatusChange(Sender: TObject);
    procedure Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure v1SSelPropertiesEditValueChanged(Sender: TObject);
    procedure KHNameBtnUpClick(Sender: TObject);
    procedure KHNameBtnDnClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure Image2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Panel10MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure KHLXRChange(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure MDNameBtnClick(Sender: TObject);
  private
    canshu1: string;
    DQdate: TDateTime;
    procedure InitGrid();
    procedure InitForm();
    function SaveData(): Boolean;
    procedure initDataMX(FCKNO: string);
    function YFData(): Boolean;
    { Private declarations }
  public
    FKHName: string;
    { Public declarations }
  end;

var
  frmXiaoShouDataNewListQB: TfrmXiaoShouDataNewListQB;

implementation

uses
  U_DataLink, U_RTFun, U_KHListSelJJ, U_ZDYHelp;

{$R *.dfm}

procedure TfrmXiaoShouDataNewListQB.FormDestroy(Sender: TObject);
begin
  frmXiaoShouDataNewListQB := nil;
end;

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

procedure TfrmXiaoShouDataNewListQB.FormCreate(Sender: TObject);
begin
  cxgrid1.Align := alClient;
  canshu1 := Trim(DParameters1);
end;

procedure TfrmXiaoShouDataNewListQB.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('老系统销售信息QBYX', Tv1, '贸易生产管理');
  Close;
end;

procedure TfrmXiaoShouDataNewListQB.InitGrid();
begin
  Panel2.Visible := True;
  Panel2.Refresh;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      SQL.Add('select CRTime=B.FHDate,ConNo=D.MLConNo,CustomerNoName=B.SHDanWei,A.FeeName,OrderNo=D.MLOrderNo,');
      sql.Add('YWY=B.Salesman,MPRTCodeName=A.MXPrtName,PRTColor=A.MXPrtColor,SOrdDefStr1=isnull(C.MLColorNoKH,C.MLColorNo),');
      sql.Add('PRTHX=A.MXPrtHX,PS=A.FHPS'); //,Qty=A.FHMQty
      sql.Add(',CASE WHEN( (select X.QtyUnit from ML_ConSub X where X.CSID=C.ConSubId ) in (''KG'' , ''千克'') ) THEN FHKgQty ELSE FHMQty END AS Qty');
      sql.Add(',CASE WHEN(isnull(D.MLConNo,'''') <> '''') THEN (select X.QtyUnit from ML_ConSub X where X.CSID=C.ConSubId ) ELSE ''M'' END AS QtyUnit');
      sql.Add(',BZType=isnull(D.BZType,''￥''),PRTPrice=C.MLPrice,');
      sql.Add('HZFee=isnull(A.FeeMoney,0),');
      sql.Add('FHMoney=isnull(C.MLPrice,0)'); //*isnull(A.FHMQty,0)
      sql.Add('* isnull(CASE WHEN( (select X.QtyUnit from ML_ConSub X where X.CSID=C.ConSubId ) in (''KG'' , ''千克'') ) THEN FHKgQty ELSE FHMQty END ,0)');
      sql.Add('+ isnull(A.FeeMoney,0),B.KHNO ');
      sql.Add(',SPID=A.SSID,CKOrdNo=B.FSID,A.FSID,A.SSID');
      sql.Add(' from FHSQ_Sub A');
      sql.Add(' inner join FHSQ_Main B on A.FSID=B.FSID');
      SQL.Add(' inner join ML_OrderSubidNew C on A.SubId=C.NewSubId');
      SQL.Add(' inner join ML_OrderMainNew D on A.MainId=D.NewMLID');
      if cxTabControl1.TabIndex = 0 then
      begin
        sql.Add('where A.CWFlag=0 and isnull(A.FHMQty,0)<>0 and CRType not in (''加工出库'') ');
      end
      else
      begin
        sql.Add('where B.FHDate>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.Date)) + '''');
        sql.Add('and B.FHDate<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.Date + 1)) + '''');
        sql.Add('and CWFlag=1');
      end;

      sql.Add(' UNION all ');
      sql.Add(' select CRTime,conno=ToConNo,CustomerNoName=custName,FeeName=''单面料'',OrderNo=ToOrderNo  ');
      sql.Add(' ,YWY=Filler,MPRTCodeName=P_CodeName,PRTColor=isnull(P_Color,KHColor),sehao COLLATE DATABASE_DEFAULT AS SOrdDefStr1   ');
      sql.Add(' ,PRTHX='''',PS=1,qty,QtyUnit=''M'',BZType=''￥'',PRTPrice=Price,HZFee=null,FHMoney=money,KHNO=CustNo,SPID=CRID,CKOrdNo=CRNO,FSID=CRNO,SSID=CRID  ');
      sql.Add(' from YP_InOut2    ');
      sql.Add('  where CRFlag=''出库'' and CRType =''销售出库'' and  valid=''Y'' ');
      if cxTabControl1.TabIndex = 0 then
      begin
        sql.Add('and isnull(CWFlag,0)=0 ');
      end
      else
      begin
        sql.Add('and CRTime>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.Date)) + '''');
        sql.Add('and CRTime<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.Date + 1)) + '''');
        sql.Add('and isnull(CWFlag,0)=1');
      end;
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
  TBFind.Click;
  Panel2.Visible := False;
end;

procedure TfrmXiaoShouDataNewListQB.InitForm();
begin
  BegDate.Date := SGetServerDate(ADOQueryTemp);
  EndDate.Date := BegDate.Date;
  ReadCxGrid('老系统销售信息QBYX', Tv1, '贸易生产管理');
  MDName.Text := Trim('销售码单新');
  InitGrid();
end;

procedure TfrmXiaoShouDataNewListQB.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
end;

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

procedure TfrmXiaoShouDataNewListQB.FormShow(Sender: TObject);
begin
  InitForm();
end;

procedure TfrmXiaoShouDataNewListQB.CheckBox1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmXiaoShouDataNewListQB.CheckBox2Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmXiaoShouDataNewListQB.CustomerNoNameChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
end;

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

procedure TfrmXiaoShouDataNewListQB.ZJStatusChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmXiaoShouDataNewListQB.Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if cxTabControl1.TabIndex = 0 then
  begin
    if CustomerNoName.Text = '' then
    begin
      v1SSel.Options.Focusing := False;
    end
    else
    begin
      v1SSel.Options.Focusing := True;
    end;
  end;

end;

procedure TfrmXiaoShouDataNewListQB.v1SSelPropertiesEditValueChanged(Sender: TObject);
var
  mvalue, Fmvalue: Boolean;
  FCKOrdNo: string;
begin
  mvalue := TcxCheckBox(Sender).EditingValue;
  if mvalue = True then
  begin
    with Order_Main do
    begin
      Edit;
      FieldByName('SSel').Value := True;
    end;
    Fmvalue := False;
  end
  else
  begin
    with Order_Main do
    begin
      Edit;
      FieldByName('SSel').Value := False;
    end;
    mvalue := False;
    Fmvalue := True;
  end;
  FCKOrdNo := Trim(Order_Main.fieldbyname('CKOrdNo').AsString);
  with Order_Main do
  begin
    First;
    while Locate('CKOrdNo;SSel', VarArrayOf([FCKOrdNo, Fmvalue]), [loPartialKey]) do
    begin
      Edit;
      FieldByName('SSel').Value := mvalue;
    end;
  end;
end;

procedure TfrmXiaoShouDataNewListQB.KHNameBtnUpClick(Sender: TObject);
var
  fsj: string;
begin
  try
    frmKHListSelJJ := TfrmKHListSelJJ.Create(Application);
    with frmKHListSelJJ do
    begin
      frmKHListSelJJ.canshu2 := '高权限';
      if ShowModal = 1 then
      begin
        Self.KHName.Text := Trim(frmKHListSelJJ.CDS_HZ.fieldbyname('KHNameJC').AsString);
        Self.KHName.TxtCode := Trim(frmKHListSelJJ.CDS_HZ.fieldbyname('KHLXR').AsString);
        Self.KHName.Hint := Trim(frmKHListSelJJ.CDS_HZ.fieldbyname('KHNo').AsString);
        Self.KHDept.Clear;
        Self.KHLXR.Clear;
      end;
    end;
  finally
    frmKHListSelJJ.Free;
  end;
  fsj := 'select Name=KHDept from CK_YCL_CR_Main where isnull(FactoryName,'''')=''' + Trim(KHName.Text) + ''' and isnull(KHDept,'''')<>''''  Group by KHDept';
  SInitComBoxBySql(ADOQueryTemp, KHDept, False, fsj);
  fsj := 'select Name=KHLXR from CK_YCL_CR_Main where isnull(FactoryName,'''')=''' + Trim(KHName.Text) + ''' and isnull(KHLXR,'''')<>''''  Group by KHLXR';
  SInitComBoxBySql(ADOQueryTemp, KHLXR, False, fsj);
  if KHLXR.Items.Count < 1 then
  begin
    KHLXR.Text := Trim(KHName.TxtCode);
  end;
end;

procedure TfrmXiaoShouDataNewListQB.KHNameBtnDnClick(Sender: TObject);
begin
  KHName.Text := '';
  KHName.TxtCode := '';
end;

procedure TfrmXiaoShouDataNewListQB.N1Click(Sender: TObject);
begin
  if cxTabControl1.TabIndex = 0 then
  begin
    if CustomerNoName.Text = '' then
      Exit;
  end;
  SelOKNo(Order_Main, True);
end;

procedure TfrmXiaoShouDataNewListQB.N2Click(Sender: TObject);
begin
  if cxTabControl1.TabIndex = 0 then
  begin
    if CustomerNoName.Text = '' then
      Exit;
  end;
  SelOKNo(Order_Main, False);
end;

procedure TfrmXiaoShouDataNewListQB.initDataMX(FCKNO: string);
begin
  with ADOQueryTemp do
  begin
    Filtered := False;
    Close;
    sql.Clear;
    SQL.Add('select CRTime=B.FHDate,ConNo=D.MLConNo,CustomerNoName=B.SHDanWei,A.FeeName,');
    sql.Add('YWY=B.Salesman,SPName=A.MXPrtName,SPColor=A.MXPrtColor,SPColorNo=isnull(C.MLColorNoKH,C.MLColorNo),');
    sql.Add('SPHX=A.MXPrtHX,JQty=A.FHPS'); //,HSQty=A.FHMQty
    sql.Add(',CASE WHEN( (select X.QtyUnit from ML_ConSub X where X.CSID=C.ConSubId ) in (''KG'' , ''千克'') ) THEN FHKgQty ELSE FHMQty END AS HSQty');
    sql.Add(',CASE WHEN(isnull(D.MLConNo,'''') <> '''') THEN (select X.QtyUnit from ML_ConSub X where X.CSID=C.ConSubId ) ELSE ''M'' END AS QtyUnit');
    sql.Add(',BZType=isnull(D.BZType,''￥''),Price=C.MLPrice,');
    sql.Add('HZFee=isnull(A.FeeMoney,0),');
    sql.Add('Money=isnull(C.MLPrice,0)'); //*isnull(A.FHMQty,0)
    sql.Add('* isnull(CASE WHEN( (select X.QtyUnit from ML_ConSub X where X.CSID=C.ConSubId ) in (''KG'' , ''千克'') ) THEN FHKgQty ELSE FHMQty END ,0)');
    sql.Add('+ isnull(A.FeeMoney,0),B.KHNO ');
    sql.Add(',SPID=A.SSID,CKOrdNo=B.FSID,A.FSID,A.SSID');
    sql.Add(' from FHSQ_Sub A');
    sql.Add(' inner join FHSQ_Main B on A.FSID=B.FSID');
    SQL.Add(' inner join ML_OrderSubidNew C on A.SubId=C.NewSubId');
    SQL.Add(' inner join ML_OrderMainNew D on A.MainId=D.NewMLID');
    sql.Add(' where B.FSID=''' + Trim(FCKNO) + '''');
    sql.Add(' and A.CWFlag=0 and isnull(FHMQty,0)<>0 ');
    sql.Add(' UNION all ');
    sql.Add(' select CRTime,conno=Toconno,CustomerNoName=custName,FeeName=''单面料''  ');
    sql.Add(' ,YWY=Filler,SPName=P_CodeName,SPColor=isnull(P_Color,KHColor),sehao COLLATE DATABASE_DEFAULT AS SOrdDefStr1   ');
    sql.Add(' ,SPHX='''',JQty=1,HSQty=qty,QtyUnit=''M'',BZType=''￥'',Price=Price,HZFee=null,FHMoney=money,KHNO=CustNo  ');
    sql.Add(' ,SPID=CRID,CKOrdNo=CRNO,FSID=CRNO,SSID=CRID');
    sql.Add(' from YP_InOut2    ');
    sql.Add('  where CRFlag=''出库'' and  valid=''Y'' ');
    sql.Add(' and CRNO=''' + Trim(FCKNO) + '''');
    sql.Add('and isnull(CWFlag,0)=0 ');

//    ShowMessage(sql.Text);
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_Sub);
  SInitCDSData20(ADOQueryTemp, CDS_Sub);
end;

function TfrmXiaoShouDataNewListQB.SaveData(): Boolean;
var
  FCRID, Maxno, FFSPID, MMaxNo, FFStr: string;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    with Order_Main do
    begin
      First;

      while not eof do
      begin
        if FieldByName('Ssel').AsBoolean = true then
        begin
          Maxno := Trim(Order_Main.fieldbyname('FSID').AsString);
          with ADOQuery1 do
          begin
            Close;
            sql.Clear;
            sql.Add('select * from CK_YCL_CR_Main where CKNO=''' + Trim(Maxno) + '''');
            Open;
          end;
          if ADOQuery1.IsEmpty = False then
          begin
            Order_Main.Delete;
          end
          else
          begin
            with ADOQueryCmd do
            begin
              Close;
              sql.Clear;
              sql.Add('select * from CK_YCL_CR_Main where SMID=''' + Trim(Maxno) + '''');
              Open;
            end;
            with ADOQueryCmd do
            begin
              Append;
              FieldByName('Filler').Value := Trim(DName);
              FieldByName('SMID').Value := Trim(Maxno);
              FieldByName('CKName').Value := '销售出库';
              FieldByName('CRFlag').Value := '出库';
              FieldByName('CRType').Value := '新系统销售';
              FieldByName('CRQtyFlag').Value := -1;
              FieldByName('FactoryName').Value := Trim(KHName.Text);
              FieldByName('FactoryNo').Value := Trim(KHName.Hint);
              FieldByName('KHLXR').Value := Trim(KHLXR.Text);
              FieldByName('KHDept').Value := Trim(KHDept.Text);
              FieldByName('KHLXFS').Value := Trim(KHLXFS.Text);
              FieldByName('KHNameOld').Value := Trim(Order_Main.fieldbyname('CustomerNoName').AsString);
              FieldByName('YWYOld').Value := Trim(Order_Main.fieldbyname('YWY').AsString);
              FieldByName('CKNO').Value := Order_Main.fieldbyname('CKOrdNo').Value;
              FieldByName('CRTime').Value := Order_Main.fieldbyname('CRTime').Value;
              Post;
            end;
            with ADOQueryCmd do
            begin
              Close;
              sql.Clear;
              sql.Add('Update CK_YCL_CR_Main Set YWY=(select YWY from KH_Main where KHNO=''' + Trim(KHName.Hint) + ''')');
              sql.Add(' where SMID=''' + Trim(Maxno) + '''');
              ExecSQL;
            end;
          end;
          initDataMX(Maxno);
          CDS_Sub.DisableControls;
          with CDS_Sub do
          begin
            First;
            while not eof do
            begin
              MMaxNo := Trim(CDS_Sub.fieldbyname('SSID').AsString);
              with ADOQueryCmd do
              begin
                Close;
                sql.Clear;
                sql.Add('select * from CK_YCL_CR where SPID=''' + Trim(MMaxNo) + '''');
                Open;
              end;
              FFStr := Trim(ADOQueryCmd.fieldbyname('SPID').AsString);
              with ADOQueryCmd do
              begin
                if Trim(FFStr) = '' then
                  Append
                else
                  Edit;
                FieldByName('SMID').Value := Trim(Maxno);
                FieldByName('SPID').Value := Trim(MMaxNo);
                RTSetSaveDataCDS(ADOQueryCmd, Tv2, CDS_Sub, 'CK_YCL_CR', 2);
                if RadioGroup1.ItemIndex = 0 then
                begin
                  FieldByName('HanShui').Value := '含税';
                end
                else
                begin
                  FieldByName('HanShui').Value := '不含税';
                end;
                FieldByName('Filler').Value := Trim(DName);
                Post;
              end;

              Edit;
              FieldByName('SPID').Value := Trim(MMaxNo);
              Post;
              YFData();
              Next;
            end;
          end;
          CDS_Sub.EnableControls;
        end;
        next;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Result := True;
  except
    Result := False;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存异常!', '提示', 0);
  end;
end;

procedure TfrmXiaoShouDataNewListQB.ToolButton1Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    exit;
  end;
  if Trim(KHName.Text) = '' then
  begin
    Application.MessageBox('指定客户不能为空!', '提示', 0);
    exit;
  end;
  if Trim(KHName.Hint) = '' then
  begin
    KHName.Enabled := True;
    Application.MessageBox('请重新选择客户!', '提示', 0);
    exit;
  end;
  ///保存时比较 KHName框里的客户和打钩的客户是否一致
  with Order_Main do
  begin
    First;
    while not eof do
    begin
      if FieldByName('Ssel').AsBoolean = true then
      begin
        if Trim(Order_Main.fieldbyname('CustomerNoName').AsString) <> Trim(KHName.Text) then
        begin
          Application.MessageBox('客户不正确!', '提示', 0);
          exit;
        end;
      end;
      Next;
    end;
  end;
    ///保存时比较 KHName框里的客户和打钩的客户是否一致
  if Trim(KHLXR.Text) = '' then
  begin
    Application.MessageBox('联系人不能为空!', '提示', 0);
    exit;
  end;
  //if Order_Main.Locate('FHMoney',NULL,[])=true then   是否打印码单
  if Order_Main.Locate('SSel;FHMoney', VarArrayOf(['True', null]), [loPartialKey]) then
  begin
    Application.MessageBox('金额不能为空!', '提示', 0);
    exit;
  end;

//  if Order_Main.Locate('SSel;PRTPrice', VarArrayOf(['True', null]), [loPartialKey]) then
//  begin
//    Application.MessageBox('单价不能为空!', '提示', 0);
//    exit;
//  end;
//
//  if Order_Main.Locate('SSel;PRTPrice', VarArrayOf(['True', 0]), [loPartialKey]) then
//  begin
//    Application.MessageBox('单价不能为0!', '提示', 0);
//    exit;
//  end;
//  if Order_Main.Locate('SSel;FHMoney', VarArrayOf(['True', 0]), [loPartialKey]) then
//  begin
//    Application.MessageBox('金额不能为0!', '提示', 0);
//    exit;
//  end;
  if Application.MessageBox('确定要登记数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  Panel2.Visible := True;
  Panel2.Refresh;
  if SaveData() then
  begin
    Panel2.Visible := False;
    KHName.Text := '';
    KHName.TxtCode := '';
    KHName.Hint := '';
    Panel3.Visible := False;
    Application.MessageBox('登记成功!', '提示', 0);
    Exit;
  end;
end;

function TfrmXiaoShouDataNewListQB.YFData(): Boolean;
var
  CRID, OrdMainId, YFID, FComTaiTou, FCRID, FFactoryName, FFactoryNo: string;
begin
  Result := False;
  FFactoryName := Trim(KHName.Text);
  FFactoryNo := Trim(KHName.Hint);
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from YS_Money_KC where FactoryName=' + quotedstr(Trim(FFactoryName)));
    sql.Add(' and KCType=''KH'' ');
    Open;
  end;
  if ADOQueryTemp.IsEmpty = False then
  begin
    CRID := ADOQueryTemp.fieldbyname('CRID').AsString;
  end
  else
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from YS_Money_CRID');
      Open;
    end;
    if ADOQueryTemp.IsEmpty = False then
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('Update YS_Money_CRID set CRID=CRID+1');
        sql.Add('select * from YS_Money_CRID ');
        Open;
      end;
    end
    else
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('insert into YS_Money_CRID select 0 ');
        sql.Add('select * from YS_Money_CRID ');
        Open;
      end;
    end;

    CRID := ADOQueryCmd.fieldbyname('CRID').AsString;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from YS_Money_KC where 1<>1');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('CRID').Value := StrToInt(CRID);
      FieldByName('FactoryName').Value := Trim(FFactoryName);
      FieldByName('FactoryNo').Value := Trim(FFactoryNo);
      FieldByName('ZdyStr1').Value := '应收收';
      FieldByName('KCType').Value := 'KH';
      Post;
    end;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from YS_Money_CR where FactoryNo=' + quotedstr(Trim(FFactoryNo)));
    sql.Add(' and YFTypeId=''' + Trim(CDS_Sub.fieldbyname('SSID').AsString) + '''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty then
  begin
    if GetLSNo(ADOQueryCmd, YFID, 'YS', 'YS_Money_CR', 4, 1) = False then
    begin
      Application.MessageBox('取应收最大号失败!', '提示', 0);
      Exit;
    end;
  end
  else
  begin
    YFID := Trim(ADOQueryTemp.fieldbyname('YFID').AsString);
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from YS_Money_CR where YFID=''' + Trim(YFID) + '''');
    Open;
  end;
  with ADOQueryCmd do
  begin
    if ADOQueryTemp.IsEmpty then
    begin
      Append;
      FieldByName('SCQty').Value := CDS_Sub.fieldbyname('HSQty').AsFloat;
      FieldByName('SCPS').Value := CDS_Sub.fieldbyname('JQty').AsFloat;
    end
    else
      Edit;
    FieldByName('YFID').Value := Trim(YFID);
    FieldByName('YFTypeId').Value := Trim(CDS_Sub.fieldbyname('SSID').AsString);
    FieldByName('CRID').Value := StrToInt(CRID);
    FieldByName('Filler').Value := Trim(DName);
    FieldByName('CRType').Value := '应收款登记';
    FieldByName('CRFlag').Value := '应收收';
    FieldByName('ChkStatusP').Value := '未审核';
    FieldByName('ChkStatusQ').Value := '未审核';
    FieldByName('QtyFlag').Value := 1;
    FieldByName('FactoryName').Value := Trim(FFactoryName);
    FieldByName('FactoryNo').Value := Trim(FFactoryNo);
    FieldByName('CRTime').Value := Order_Main.fieldbyname('CRTime').AsDateTime;
    FieldByName('Qty').Value := CDS_Sub.fieldbyname('HSQty').AsFloat;
    FieldByName('PS').Value := CDS_Sub.fieldbyname('JQty').AsFloat;
    FieldByName('ConNo').Value := CDS_Sub.fieldbyname('ConNo').Value;
    FieldByName('YFType').Value := '自动生成';
    FieldByName('Price').Value := CDS_Sub.fieldbyname('Price').Value;
    FieldByName('HSPrice').Value := CDS_Sub.fieldbyname('Price').Value;
    //FieldByName('JSPrice').Value:=CDS_Sub.fieldbyname('Price').Value;
    if RadioGroup1.ItemIndex = 0 then
    begin
      FieldByName('HanShui').Value := '含税'
    end
    else
    begin
      FieldByName('HanShui').Value := '不含税'
    end;
    FieldByName('CKNO').Value := Order_Main.fieldbyname('CKOrdNo').Value;
    FieldByName('SJQty').Value := CDS_Sub.fieldbyname('HSQty').Value;
    FieldByName('HZFee').Value := CDS_Sub.fieldbyname('HZFee').Value;
    FieldByName('Note').Value := CDS_Sub.fieldbyname('FeeName').Value;
    FieldByName('money').Value := CDS_Sub.fieldbyname('money').Value;
    FieldByName('JSMoney').Value := CDS_Sub.fieldbyname('money').Value;
    FieldByName('HSMoney').Value := CDS_Sub.fieldbyname('money').Value;
    FieldByName('QtyUnit').Value := Trim(CDS_Sub.fieldbyname('QtyUnit').AsString);
    FieldByName('P_CodeName').Value := Trim(CDS_Sub.fieldbyname('SPName').AsString);
    FieldByName('P_Color').Value := Trim(CDS_Sub.fieldbyname('SPColor').AsString);
    FieldByName('P_HX').Value := Trim(CDS_Sub.fieldbyname('SPHX').AsString);
    FieldByName('BZType').Value := Trim(CDS_Sub.fieldbyname('BZType').AsString);
    FieldByName('status').Value := '0';
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update FHSQ_Sub Set YFID=''' + Trim(YFID) + ''',CWFlag=1');
    sql.Add('where SSID=''' + Trim(CDS_Sub.fieldbyname('SSID').AsString) + '''');
    ExecSQL;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update YP_InOut2 Set YFID=''' + Trim(YFID) + ''',CWFlag=1');
    sql.Add('where CRID=''' + Trim(CDS_Sub.fieldbyname('SSID').AsString) + '''');
    ExecSQL;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update YS_Money_KC Set KCMoney=(select isnull(Sum(HSMoney*QtyFlag),0) from YS_Money_CR A where A.CRID=YS_Money_KC.CRID)');
    sql.Add(' where CRID=' + CRID);
    ExecSQL;
  end;
  Result := True;
end;

procedure TfrmXiaoShouDataNewListQB.ToolButton2Click(Sender: TObject);
var
  FSMID: string;
begin
  if Order_Main.IsEmpty then
    Exit;
  if cxTabControl1.TabIndex <> 1 then
    Exit;
  if Order_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据!', '提示', 0);
    exit;
  end;
  if Application.MessageBox('确定要撤销数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin
      while Locate('SSel', True, []) do
      begin

        if Trim(Order_Main.fieldbyname('FeeName').AsString) = '单面料' then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add(' Update YP_InOut2 Set CWFlag=0,YFID=Null ');
            sql.Add(' where CRNO=''' + Trim(Order_Main.fieldbyname('CKOrdNo').AsString) + '''');
            sql.Add(' DELETE from YS_Money_CR where YFTypeID =''' + Trim(Order_Main.fieldbyname('CKOrdNo').AsString) + '''');
            ExecSQL;
          end;
        end;

        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from CK_YCL_CR_Main where CKNO=''' + Trim(Order_Main.fieldbyname('CKOrdNo').AsString) + '''');
          Open;
        end;
        FSMID := Trim(ADOQueryTemp.fieldbyname('SMID').AsString);
        ADOQueryTemp.Close;
        if Trim(FSMID) <> '' then
        begin
          with ADOQueryTemp do
          begin
            Close;
            sql.Clear;
            sql.Add('select * from YS_Money_CR where YFTypeId in');
            sql.Add('(select SPID from CK_YCL_CR where SMID=''' + Trim(FSMID) + ''')');
            sql.Add(' and (isnull(ChkerP,'''')<>'''' ');
            sql.Add(' or isnull(ChkerQ,'''')<>'''') ');
            Open;
          end;
          if ADOQueryTemp.IsEmpty then
          begin
            with ADOQueryCmd do
            begin
              Close;
              sql.Clear;
              sql.Add(' Update FHSQ_Sub Set CWFlag=0,YFID=Null where SSID in');
              sql.Add('(select SPID from CK_YCL_CR where SMID=''' + Trim(FSMID) + ''')');
              sql.Add(' delete YS_Money_CR where YFTypeId in');
              sql.Add('(select SPID from CK_YCL_CR where SMID=''' + Trim(FSMID) + ''')');
              sql.Add(' delete CK_YCL_CR where SMID=''' + Trim(FSMID) + '''');
              sql.Add(' delete CK_YCL_CR_Main where SMID=''' + Trim(FSMID) + '''');
              ExecSQL;
            end;
          end
          else
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            application.MessageBox('财务应收已审核,不能撤销', '提示');
            exit;
          end;
        end;
        Order_Main.Delete;
      end;
    end;
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('撤销异常!', '提示', 0);
  end;
end;

procedure TfrmXiaoShouDataNewListQB.Image2Click(Sender: TObject);
begin
  Panel3.Visible := False;
end;

procedure TfrmXiaoShouDataNewListQB.ToolButton3Click(Sender: TObject);
var
  fsj: string;
begin
  if Order_Main.Locate('ssel', True, []) = false then
  begin
    application.MessageBox('没有选择数据', '提示');
    exit;
  end;
  Self.KHDept.Clear;
  Self.KHLXR.Clear;
  Panel3.Visible := True;
  Panel3.Refresh;
  if Order_Main.Locate('SSel', True, []) then
  begin
    KHName.Enabled := False;
    KHName.Text := Trim(Order_Main.fieldbyname('CustomerNoName').AsString);
    KHName.Hint := Trim(Order_Main.fieldbyname('KHNo').AsString);
    //获取合同的是否含税
    with ADOQueryTemp do
    begin
      Close;
      SQL.Clear;
      sql.Add('select IFHS,IFBHS from ML_ConMain where ConNo=''' + Trim(Order_Main.fieldbyname('ConNo').AsString) + '''');
      Open;
    end;
    if ADOQueryTemp.fieldbyname('IFHS').AsBoolean = True then
    begin
      RadioGroup1.ItemIndex := 0;
    end;
    if ADOQueryTemp.fieldbyname('IFBHS').AsBoolean = True then
    begin
      RadioGroup1.ItemIndex := 1;
    end;
  end;
  if Trim(KHName.Text) <> '' then
  begin
    fsj := 'select Name=KHDept from CK_YCL_CR_Main where isnull(FactoryName,'''')=''' + Trim(KHName.Text) + ''' and isnull(KHDept,'''')<>''''  Group by KHDept';
    SInitComBoxBySql(ADOQueryTemp, KHDept, False, fsj);
    fsj := 'select Name=KHLXR from CK_YCL_CR_Main where isnull(FactoryName,'''')=''' + Trim(KHName.Text) + ''' and isnull(KHLXR,'''')<>''''  Group by KHLXR';
    SInitComBoxBySql(ADOQueryTemp, KHLXR, False, fsj);
    if KHLXR.Items.Count < 1 then
    begin
      KHLXR.Text := Trim(KHName.TxtCode);
    end;
  end;
end;

procedure TfrmXiaoShouDataNewListQB.Button1Click(Sender: TObject);
begin
  ToolButton1.Click;
  if application.MessageBox('是否打印码单', '提示', 1) = 2 then
  begin
    InitGrid();
    exit;
  end
  else
  begin
    ToolButton4.Click;
    InitGrid();
  end;
end;

procedure TfrmXiaoShouDataNewListQB.Panel10MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture;
  TWinControl(Panel3).Perform(WM_SYSCOMMAND, $F012, 0);
end;

procedure TfrmXiaoShouDataNewListQB.KHLXRChange(Sender: TObject);
begin
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select Top 1* from CK_YCL_CR_Main where isnull(FactoryName,'''')=''' + Trim(KHName.Text) + '''');
    sql.Add(' and isnull(KHLXR,'''')=''' + Trim(KHLXR.Text) + '''');
    sql.Add(' order by CRTime desc ');
    Open;
  end;
  KHLXFS.Text := Trim(ADOQueryTemp.fieldbyname('KHLXFS').AsString);
end;

procedure TfrmXiaoShouDataNewListQB.ToolButton4Click(Sender: TObject);
var
  fPrintFile, FCKNO: string;
begin
  if Order_Main.IsEmpty then
    Exit;
 { if CustomerNoName.Text = '' then
  begin
    application.MessageBox('查询条件客户不能为空', '提示');
    exit;
  end; }
  if Order_Main.Locate('ssel', True, []) = false then
  begin
    application.MessageBox('没有选择数据', '提示');
    exit;
  end;
  if Trim(MDName.Text) = '' then
  begin
    Application.MessageBox('码单名称不能为空!', '提示', 0);
    Exit;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('delete TBSubID where DName=''' + Trim(DCode) + '''');
    ExecSQL;
  end;
  {if CheckBox1.Checked=False then
  begin
    fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\销售码单新.rmf';
  end else
  begin
    fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\销售码单新无单价.rmf';
  end;     }
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(MDName.Text) + '.rmf';

  RMXLSExport2 := TRMXLSExport.Create(RMXLSExport2);
  FCKNO := '';
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('delete TbForBatch where DName=' + quotedstr(Trim(DName)));
    SQL.Add('and MainType=' + quotedstr('样品码单'));
    ExecSQL;
  end;
  with Order_Main do
  begin
    first;
    while not Eof do
    begin
      if FieldByName('Ssel').AsBoolean = true then
      begin
        if Trim(FCKNO) = '' then
        begin
          FCKNO := Trim(Order_Main.fieldbyname('CKOrdNo').AsString);
        end
        else
        begin
          if FCKNO <> Trim(Order_Main.fieldbyname('CKOrdNo').AsString) then
          begin
            if Trim(Order_Main.fieldbyname('FeeName').AsString) <> '单面料' then
            begin
              Application.MessageBox('不能选择不同出库单号!', '提示', 0);
              Exit;
            end;
          end;
        end;
        with ADOQuery1 do
        begin
          Filtered := False;
          Close;
          sql.Clear;
          sql.Add(' select distinct D.MJID');
          sql.Add(' from CK_YCL_CR A ');
          sql.Add(' inner join CK_YCL_CR_Main B on A.SMID=B.SMID ');
          sql.Add(' left join CK_MLCP_CR D on D.CKOrdNo=B.CKNo');
          sql.add(' where B.CKNO=''' + Trim(FCKNO) + '''');
          Open;
        end;
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('SELECT * FROM TBSubID where 1=2 ');
          open;
        end;
        with ADOQuery1 do
        begin
          first;
          while not eof do
          begin
            ADOQueryTemp.append;
            ADOQueryTemp.fieldbyname('SubId').Value := Trim(ADOQuery1.fieldbyname('MJID').AsString);
            ADOQueryTemp.fieldbyname('Dname').Value := Trim(DCode);
            ADOQueryTemp.post;
            next;
          end;
        end;

        if Trim(Order_Main.fieldbyname('FeeName').AsString) = '单面料' then
        begin
          with ADOQuery2 do
          begin
            Close;
            sql.Clear;
            sql.Add(' insert into TbForBatch(DName,MainType,Value1,Filltime) ');
            sql.Add(' values( ' + quotedstr(Trim(DName)) + ',' + quotedstr('样品码单') + ',' + quotedstr(Trim(Order_Main.fieldbyname('SPID').AsString)) + ',getdate()' + ')');
            ExecSQL;
          end;
        end;
      end;
      next;
    end;
  end;
  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.add('exec P_Print_CKMD4 ');
    sql.add('@mainID=' + quotedstr(Trim('')));
    sql.add(',@DName=' + quotedstr(Trim(DCode)));
    sql.add(',@CKOrdNO=' + quotedstr(Trim(FCKNO)));
    Open;
  end;
  with ADOQueryPrint1 do
  begin
    Close;
    sql.Clear;
    sql.add('exec P_Print_CKMD7 ');
    sql.add('@DName=' + quotedstr(Trim(DName)));
    Open;
  end;
//  SCreateCDS20(ADOQueryTemp, CDS_PRT);
//  SInitCDSData20(ADOQueryTemp, CDS_PRT);
  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RMVariables['ZJJE'] := ADOQueryPrint.FIELDBYNAME('sumMoney').ASFLOAT + ADOQueryPrint1.FIELDBYNAME('MoneyHZ').ASFLOAT;
    RMVariables['ZJQty'] := ADOQueryPrint.FIELDBYNAME('sumQty').ASFLOAT + ADOQueryPrint1.FIELDBYNAME('QtyHZ').ASFLOAT;
    RM1.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + ExtractFilePath(Application.ExeName) + 'Report\销售码单新.rmf'), '提示', 0);
  end;
end;

procedure TfrmXiaoShouDataNewListQB.MDNameBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'MDName';
      flagname := '码单名称';
      if ShowModal = 1 then
      begin
        Self.MDName.Text := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

end.

