unit U_BanCpRkOutPut;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxCalendar, cxDropDownEdit,
  ComCtrls, ToolWin, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, ADODB, DBClient, cxButtonEdit;

type
  TfrmBanCpRkOutPut = class(TForm)
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column2: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    ToolBar1: TToolBar;
    TBAdd: TToolButton;
    TBDel: TToolButton;
    TBSave: TToolButton;
    TBClose: TToolButton;
    v1Column4: TcxGridDBColumn;
    DataSource3: TDataSource;
    CDS_Sub: TClientDataSet;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    cxGridPopupMenu2: TcxGridPopupMenu;
    v1Column6: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    v1Column22: TcxGridDBColumn;
    v1Column23: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBAddClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure v1Column15PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1Column16PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
  private
    { Private declarations }
    function SaveCKData():Boolean;
    function YSData(Order_Main10:TClientDataSet):Boolean;
  public
    { Public declarations }
    FBCId:String;
  end;

var
  frmBanCpRkOutPut: TfrmBanCpRkOutPut;

implementation
uses
  U_OrderSel,U_DataLink,U_Fun,U_ZDYHelp;

{$R *.dfm}
function TfrmBanCpRkOutPut.YSData(Order_Main10:TClientDataSet):Boolean;
var
  CRID,YFID,Price,PriceUnit,OrderUnit,FComTaiTou,khName:String;
  flag:integer;
//  Price:double;
begin
  Result:=False;
  with Order_Main10 do
  begin
    begin
      with ADOQueryTemp do
      begin
        Close;
        SQL.Clear;
        sql.Add('select X1.customerNoName,X3.OrderUnit,X3.PRTPrice,X2.OrdconPrcUnit from JYOrder_main X1,JYOrdercon_main X2,JYOrdercon_Sub X3 Where X1.consubID=X3.subID and X2.mainID=X3.mainID and X1.Mainid='''+Trim(Order_Main10.fieldbyname('MainId').AsString)+'''');
        Open;
      end;
      if ADOQueryTemp.IsEmpty then
      begin
        application.MessageBox('没有合同或指示单没有定位,不能出库','提示');
        exit;
      end;
      OrderUnit:=Trim(ADOQueryTemp.fieldbyname('OrderUnit').AsString);
      khName:=Trim(ADOQueryTemp.fieldbyname('customerNoName').AsString);
      Price:=Trim(ADOQueryTemp.fieldbyname('PRTPrice').AsString);
      PriceUnit:=Trim(ADOQueryTemp.fieldbyname('OrdconPrcUnit').AsString);
      flag:=0;
      IF  OrderUnit= trim(Order_Main10.FieldByName('QtyUnit').AsString) then
      begin
       flag:=1;
      end
      else
      if OrderUnit= trim(Order_Main10.FieldByName('FZUnit').AsString) then
      begin
        flag:=2;
      end
      else IF trim(Order_Main10.FieldByName('FZUnit').AsString)='Kg' then
      begin
        flag:=3;
      end;
      IF Flag=0 then
      begin
        application.MessageBox('出库单位和合同单位不一致，不能出库！','提示信息',0);
        exit;
      end;

      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('delete  from YF_Money_CR where YfID='+quotedstr(trim(Order_Main10.fieldbyname('fYFID').AsString)));
        execsql;
      end;

      with ADOQueryTemp do
      begin
        Close;
        SQL.Clear;
        sql.Add('select * from YF_Money_KC where FactoryName='''+Trim(khName)+'''');
        Open;
      end;
      if ADOQueryTemp.IsEmpty=False then
      begin
        CRID:=ADOQueryTemp.fieldbyname('CRID').AsString;
      end else
      begin
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update YF_Money_CRID set CRID=CRID+1');
          sql.Add('select * from YF_Money_CRID ');
          Open;
        end;
        CRID:=ADOQueryCmd.fieldbyname('CRID').AsString;
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from YF_Money_KC where 1<>1');
          Open;
        end;
        with ADOQueryCmd do
        begin
          Append;
          FieldByName('CRID').Value:=StrToInt(CRID);
          FieldByName('FactoryName').Value:=Trim(khName);
          FieldByName('ZdyStr1').Value:='应收收';
          Post;
        end;
      end;
      with ADOQueryTemp do
      begin
        Close;
        sql.Clear;
        sql.Add('select * from YF_Money_CR where FactoryName='''+Trim(khName)+''' ');
        sql.Add('and YFTypeId='''+Trim(Order_Main10.fieldbyname('Mainid').AsString)+''' ');
        sql.Add('and CRTime='''+formatdateTime('yyyy-MM-dd',Order_Main10.fieldbyname('CRTime').AsDateTime)+'''');
        Open;
      end;
      if ADOQueryTemp.IsEmpty then
      begin
        if GetLSNo(ADOQueryCmd,YFID,'CS','YF_Money_CR',3,1)=False then
        begin
          Application.MessageBox('取成品应收最大号失败!','提示',0);
          Exit;
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from YF_Money_CR where 1<>1');
          Open;
        end;
        with ADOQueryCmd do
        begin
          Append;
          FieldByName('YFID').Value:=Trim(YFID);
          FieldByName('YFTypeId').Value:=Trim(Order_Main10.fieldbyname('MainId').AsString);
          FieldByName('CRID').Value:=StrToInt(CRID);
          FieldByName('Filler').Value:=Trim(DName);
          FieldByName('CRType').Value:='应收款登记';
          FieldByName('CRFlag').Value:='应收收';
          FieldByName('QtyFlag').Value:=1;
          FieldByName('FactoryName').Value:=Trim(KHName);
          FieldByName('CRTime').Value:=Trim(FormatDateTime('yyyy-MM-dd',Order_Main10.fieldbyname('CRTime').AsDateTime));
          FieldByName('YFType').Value:='自动生成';
          FieldByName('Price').Value:=Price;
          FieldByName('HuiLv').Value:=1;

          FieldByName('BZType').Value:=Trim(PriceUnit);
          FieldByName('QtyUnit').Value:=Trim(OrderUnit);
          FieldByName('ComTaiTou').Value:=Trim(KHName);
          FieldByName('YFName').Value:='销售金额';
          FieldByName('MainId').Value:=Trim(Order_Main10.fieldbyname('Mainid').AsString);
          Post;
        end;
      end
      else
      begin
        YFID:=Trim(ADOQueryTemp.fieldbyname('YFID').AsString);
      end;
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        if flag=1 then
        begin
          sql.Add('update YF_Money_CR Set Qty=(select isnull(Sum(A.Qty),0) from CK_BanCP_CR A  ');
        end
        else IF flag=2 then
        begin
          sql.Add('update YF_Money_CR Set Qty=(select isnull(Sum(A.FZQty),0) from CK_BanCP_CR A  ');
        end
        else if flag=3 then
        begin
           sql.Add('update YF_Money_CR Set Qty=(select isnull(Sum(A.KGQtyJ),0) from CK_BanCP_CR A  ');
        end;
        SQL.Add(' where A.MainId=YF_Money_CR.YFTypeId and A.CRTime=YF_Money_CR.CRTime and A.MJID=A.BCID and A.CRType=''正常出库''   ');
        SQL.Add(' )');
        sql.Add(',PS=(select isnull(sum(JQty),0) from CK_BanCP_CR A  ');
        SQL.Add(' where A.MainId=YF_Money_CR.YFTypeId and A.CRTime=YF_Money_CR.CRTime and A.MJID=A.BCID and A.CRType=''正常出库''   ');
        SQL.Add(' )');
        sql.Add(' where YFTypeId='''+Trim(Order_Main10.fieldbyname('Mainid').AsString)+'''');
        ExecSQL;
      end;

      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('Update YF_Money_CR Set Money=Price*Qty,BBMoney=Price*Qty*HuiLv');
        sql.Add(' where YFID='''+Trim(YFID)+'''');
        ExecSQL;
      end;
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('Update YF_Money_KC Set KCMoney=(select isnull(Sum(Money*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID)');
        sql.Add(',KCBBMoney=(select isnull(Sum(BBMoney*QtyFlag),0) from YF_Money_CR A where A.CRID=YF_Money_KC.CRID)');
        sql.Add(' where CRID='+CRID);
        ExecSQL;
      end;
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('Update CK_BanCp_CR Set FYFID='''+Trim(YFID)+''' ');
        sql.Add(' where BCID='''+Trim(Order_Main10.fieldbyname('BCID').AsString)+'''');
        ExecSQL;
      end;
    end;
  end;
  Result:=True;
end;

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

procedure TfrmBanCpRkOutPut.TBAddClick(Sender: TObject);
begin
  try
    frmOrderSel:=TfrmOrderSel.Create(Application);
    with frmOrderSel do
    begin
      if ShowModal=1 then
      begin
        CDS_OrderSel.DisableControls;
        with CDS_OrderSel do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').Value=True then
            begin
              with Self.CDS_Sub do
              begin
                Append;
                FieldByName('MainId').Value:=Trim(CDS_OrderSel.fieldbyname('MainId').AsString);
                FieldByName('SubId').Value:=Trim(CDS_OrderSel.fieldbyname('SubId').AsString);
                FieldByName('OrderNo').Value:=Trim(CDS_OrderSel.fieldbyname('OrderNo').AsString);
                FieldByName('MPRTCodeName').Value:=Trim(CDS_OrderSel.fieldbyname('MPRTCodeName').AsString);
                FieldByName('PRTColor').Value:=Trim(CDS_OrderSel.fieldbyname('PRTColor').AsString);
                FieldByName('PRTHX').Value:=Trim(CDS_OrderSel.fieldbyname('PRTHX').AsString);
                FieldByName('MPRTMF').Value:=Trim(CDS_OrderSel.fieldbyname('MPRTMF').AsString);
                FieldByName('MPRTKZ').Value:=Trim(CDS_OrderSel.fieldbyname('MPRTKZ').AsString);
                FieldByName('Qty').Value:=CDS_OrderSel.fieldbyname('KCQty').Value;
                FieldByName('KgQty').Value:=CDS_OrderSel.fieldbyname('KCKgQty').Value;
                FieldByName('JQty').Value:=CDS_OrderSel.fieldbyname('KCJQty').Value;
                FieldByName('KgQtyJ').Value:=CDS_OrderSel.fieldbyname('KCKgQtyJ').Value;
                FieldByName('BQty').Value:=CDS_OrderSel.fieldbyname('KCBQty').Value;
                FieldByName('QtyUnit').Value:=CDS_OrderSel.fieldbyname('KCQtyUnit').Value;
                FieldByName('MJID').Value:=CDS_OrderSel.fieldbyname('CRID').Value;
                FieldByName('APID').Value:=CDS_OrderSel.fieldbyname('CRID').Value;
                FieldByName('CRID').Value:=CDS_OrderSel.fieldbyname('CRID').Value;
                FieldByName('QtyUnit').Value:=CDS_OrderSel.fieldbyname('KCQtyUnit').Value;
                FieldByName('ComPRTName').Value:=CDS_OrderSel.fieldbyname('ComPRTName').Value;
                FieldByName('CRType').Value:='正常出库';
                FieldByName('CRTime').Value:=FormatDateTime('yyyy-MM-dd',Now);
                Post;
              end;
            end;
            Next;
          end;
        end;
        CDS_OrderSel.EnableControls;
      end;
    end;
  finally
    frmOrderSel.Free;
  end;
end;

function TfrmBanCpRkOutPut.SaveCKData():Boolean;
var
  FCRID,Maxno:string;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Sub.DisableControls;
    with CDS_Sub do
    begin
      First;
      while not eof do
      begin
        FCRID:=CDS_Sub.fieldbyname('CRID').AsString;
        if Trim(CDS_Sub.fieldbyname('BCID').AsString)='' then
        begin
          if GetLSNo(ADOQueryCmd,Maxno,'BC','CK_BanCP_CR',3,1)=False then
          begin
            Result:=False;
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取入库编号失败!','提示',0);
            Exit;
          end;
        end else
        begin
          Maxno:=Trim(CDS_Sub.fieldbyname('BCID').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from CK_BanCP_CR where BCID='''+Trim(Maxno)+'''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(CDS_Sub.fieldbyname('BCID').AsString)='' then
          begin
            Append;
          end else
          begin
            Edit;
          end;
          FieldByName('BCID').Value:=Trim(Maxno);
          FieldByName('MJID').Value:=Trim(Maxno);
          FieldByName('APID').Value:=Trim(Maxno);
          FieldByName('MainID').Value:=Trim(CDS_Sub.fieldbyname('MainID').AsString);
          FieldByName('SubID').Value:=Trim(CDS_Sub.fieldbyname('SubID').AsString);
          FieldByName('CRFlag').Value:='出库';
          FieldByName('CRType').Value:=Trim(CDS_Sub.fieldbyname('CRType').AsString);
          FieldByName('CRID').Value:=FCRID;
          FieldByName('CRTime').Value:=CDS_Sub.fieldbyname('CRTime').AsString;
          FieldByName('QtyUnit').Value:=CDS_Sub.fieldbyname('QtyUnit').AsString;
          FieldByName('ComPRTName').Value:=CDS_Sub.fieldbyname('ComPRTName').AsString;
          FieldByName('BGQtyUnit').Value:=CDS_Sub.fieldbyname('BGQtyUnit').AsString;
          FieldByName('FZQty').Value:=CDS_Sub.fieldbyname('FZQty').AsFloat;
          FieldByName('FZUnit').Value:=CDS_Sub.fieldbyname('FZUnit').AsString;
          FieldByName('BGName').Value:=CDS_Sub.fieldbyname('BGName').AsString;
          FieldByName('BoxSpec').Value:=CDS_Sub.fieldbyname('BoxSpec').AsString;
          FieldByName('JGFactory').Value:=CDS_Sub.fieldbyname('JGFactory').AsString;
          FieldByName('Note').Value:=CDS_Sub.fieldbyname('Note').AsString;
          FieldByName('NoteG').Value:=CDS_Sub.fieldbyname('NoteG').AsString;
          //FieldByName('GangNo').Value:=CDS_Sub.fieldbyname('GangNo').AsString;
          FieldByName('QtyFlag').Value:=-1;
          if Trim(CDS_Sub.fieldbyname('BGQty').AsString)<>'' then
          begin
            FieldByName('BGQty').Value:=CDS_Sub.fieldbyname('BGQty').Value;
          end else
          begin
            FieldByName('BGQty').Value:=0;
          end;
          if Trim(CDS_Sub.fieldbyname('BGJZ').AsString)<>'' then
          begin
            FieldByName('BGJZ').Value:=CDS_Sub.fieldbyname('BGJZ').Value;
          end else
          begin
            FieldByName('BGJZ').Value:=0;
          end;
          if Trim(CDS_Sub.fieldbyname('BGMZ').AsString)<>'' then
          begin
            FieldByName('BGMZ').Value:=CDS_Sub.fieldbyname('BGMZ').Value;
          end else
          begin
            FieldByName('BGMZ').Value:=0;
          end;
          if Trim(CDS_Sub.fieldbyname('JQty').AsString)<>'' then
          begin
            FieldByName('JQty').Value:=CDS_Sub.fieldbyname('JQty').Value;
          end else
          begin
            FieldByName('JQty').Value:=0;
          end;
          if Trim(CDS_Sub.fieldbyname('KGQty').AsString)<>'' then
          begin
            FieldByName('KGQty').Value:=CDS_Sub.fieldbyname('KGQty').Value;
          end else
          begin
            FieldByName('KGQty').Value:=0;
          end;
          if Trim(CDS_Sub.fieldbyname('BQty').AsString)<>'' then
          begin
            FieldByName('BQty').Value:=CDS_Sub.fieldbyname('BQty').Value;
          end else
          begin
            FieldByName('BQty').Value:=0;
          end;
          if Trim(CDS_Sub.fieldbyname('KGQtyJ').AsString)<>'' then
          begin
            FieldByName('KGQtyJ').Value:=CDS_Sub.fieldbyname('KGQtyJ').Value;
          end else
          begin
            FieldByName('KGQtyJ').Value:=0;
          end;
          if Trim(CDS_Sub.fieldbyname('Qty').AsString)<>'' then
          begin
            FieldByName('Qty').Value:=CDS_Sub.fieldbyname('Qty').Value;
          end else
          begin
            FieldByName('Qty').Value:=0;
          end;

          if Trim(CDS_Sub.fieldbyname('BCID').AsString)='' then
            FieldByName('Filler').Value:=Trim(DName)
          else
          begin
            FieldByName('Editer').Value:=Trim(DName);
            FieldByName('EditTime').Value:=SGetServerDate(ADOQueryTemp);
          end;
          Post;
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('Update CK_BanCP_KC Set KCQty=(select sum(Qty*QtyFlag) from CK_BanCP_CR A where A.CRID=CK_BanCP_KC.CRID)');
          sql.Add(',KCKgQty=(select sum(KgQty*QtyFlag) from CK_BanCP_CR A where A.CRID=CK_BanCP_KC.CRID)');
          sql.Add(',KCJQty=(select sum(JQty*QtyFlag) from CK_BanCP_CR A where A.CRID=CK_BanCP_KC.CRID)');
          sql.Add(',KCKgQtyJ=(select sum(KgQtyJ*QtyFlag) from CK_BanCP_CR A where A.CRID=CK_BanCP_KC.CRID)');
          sql.Add(',KCBQty=(select sum(BQty*QtyFlag) from CK_BanCP_CR A where A.CRID=CK_BanCP_KC.CRID)');
          sql.Add(' where CRID='+FCRID);
          ExecSQL;
        end;
        CDS_Sub.Edit;
        CDS_Sub.FieldByName('BCID').Value:=trim(maxNO);
        CDS_Sub.post;
        IF not YSData(CDS_Sub) then
        begin
          application.MessageBox('应收款保存失败','提示信息',0);
          ADOQueryCmd.Connection.RollbackTrans;
          CDS_Sub.EnableControls;
          exit;
        end;
        Next;
      end;
    end;
    CDS_Sub.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存异常!','提示',0);
  end;
end;

procedure TfrmBanCpRkOutPut.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('成品出库S',Tv1,'成品仓库');
  Close;
end;

procedure TfrmBanCpRkOutPut.FormShow(Sender: TObject);
begin
  ReadCxGrid('成品出库S',Tv1,'成品仓库');
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.OrderNo,B.MPRTCodeName,B.MPRTMF,B.MPRTKZ,C.PRTColor,C.SOrddefstr1,C.PRTHX from CK_BanCp_CR A ');
    sql.Add(' inner join JYOrder_Main B on A.MainId=B.MainId');
    sql.Add(' inner join JYOrder_Sub C on A.SubId=C.SubId');
    sql.Add(' where A.BCID='''+Trim(FBCId)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_Sub);
  SInitCDSData20(ADOQueryTemp,CDS_Sub);
end;

procedure TfrmBanCpRkOutPut.TBDelClick(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then Exit;
  CDS_Sub.Delete;
end;

procedure TfrmBanCpRkOutPut.TBSaveClick(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then Exit;
  if CDS_Sub.Locate('CRTime',null,[])=True then
  begin
    Application.MessageBox('出库时间不能为空!','提示',0);
    Exit;
  end;
  if CDS_Sub.Locate('CRType',null,[])=True then
  begin
    Application.MessageBox('出库类型不能为空!','提示',0);
    Exit;
  end;
  {if CDS_Sub.Locate('QtyUnit',null,[])=True then
  begin
    Application.MessageBox('单位不能为空!','提示',0);
    Exit;
  end; }
  if SaveCKData() then
  begin
    Application.MessageBox('保存成功!','提示',0);
    ModalResult:=1;
    Exit;
  end;
end;

procedure TfrmBanCpRkOutPut.v1Column15PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='BoxSpec';
      flagname:='纸箱规格';
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('BoxSpec').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmBanCpRkOutPut.v1Column16PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='JGFactory';
      flagname:='加工单位';
      if ShowModal=1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('JGFactory').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

end.
