unit U_CPManage_CX;

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, RM_BarCode,
  cxButtonEdit, cxTextEdit,jpeg,U_SLT,Math;

type
  TfrmCPManage_CX = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    DataSource1: TDataSource;
    ADOQueryTree: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Panel1: TPanel;
    Label2: TLabel;
    CYID: TEdit;
    ToolButton2: TToolButton;
    Label1: TLabel;
    CYName: TEdit;
    Label4: TLabel;
    CYEName: TEdit;
    Label5: TLabel;
    CYSpec: TEdit;
    DataSource2: TDataSource;
    ADOQueryMain: TADOQuery;
    CDS_Main: TClientDataSet;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    ODPat: TOpenDialog;
    IdFTP1: TIdFTP;
    SaveDialog1: TSaveDialog;
    Label3: TLabel;
    CYNO: TEdit;
    Panel2: TPanel;
    DSCYNO: TDataSource;
    CDS_CYNO: TClientDataSet;
    Edit1: TEdit;
    Label6: TLabel;
    Label7: TLabel;
    CYKZ: TEdit;
    Label8: TLabel;
    Label9: TLabel;
    CYCF: TEdit;
    CYECF: TEdit;
    Label10: TLabel;
    CYMF: TEdit;
    Label11: TLabel;
    CYHX: TEdit;
    Label12: TLabel;
    DefStr2: TEdit;
    RMBarCodeObject1: TRMBarCodeObject;
    MianLiao: TEdit;
    Label13: TLabel;
    defstr1: TEdit;
    Label14: TLabel;
    Panel3: TPanel;
    adoqueryPicture: TADOQuery;
    defstr10: TEdit;
    Label15: TLabel;
    DataSource3: TDataSource;
    Order_Sub: TClientDataSet;
    ADOQuery1: TADOQuery;
    ToolButton11: TToolButton;
    RMDB_Sub: TRMDBDataSet;
    RM2: TRMGridReport;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1CYNo: TcxGridDBColumn;
    v1CPName: TcxGridDBColumn;
    v1DefStr2: TcxGridDBColumn;
    v1DefStr10: TcxGridDBColumn;
    v1CYName: TcxGridDBColumn;
    v1CYEName: TcxGridDBColumn;
    v1CYCF: TcxGridDBColumn;
    v1CYECF: TcxGridDBColumn;
    v1CYSpec: TcxGridDBColumn;
    v1DefStr6: TcxGridDBColumn;
    v1CYMF: TcxGridDBColumn;
    v1CYKZ: TcxGridDBColumn;
    v1CYHX: TcxGridDBColumn;
    v1CYColor: TcxGridDBColumn;
    v1CYSeHao: TcxGridDBColumn;
    v1CYNote: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1XYPlace: TcxGridDBColumn;
    TSsel: TToolButton;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    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;
    cxGridDBColumn16: TcxGridDBColumn;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridDBColumn18: TcxGridDBColumn;
    cxGridDBColumn19: TcxGridDBColumn;
    cxGridDBColumn20: TcxGridDBColumn;
    cxGridDBColumn21: TcxGridDBColumn;
    cxGridDBColumn22: TcxGridDBColumn;
    cxGridDBColumn23: TcxGridDBColumn;
    cxGridDBColumn24: TcxGridDBColumn;
    cxGridDBColumn25: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    YP_FZ: TClientDataSet;
    DataSource4: TDataSource;
    ToolBar2: TToolBar;
    ToolButton9: TToolButton;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    Toyy: TToolButton;
    V2YYKuWei: TcxGridDBColumn;
    v1YYKuWei: TcxGridDBColumn;
    ADOQuery6: TADOQuery;
    ADOQuery3: TADOQuery;
    ADOQuery2: TADOQuery;
    ADOQuery8: TADOQuery;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure cxDBTreeList1DblClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure CYIDKeyPress(Sender: TObject; var Key: Char);
    procedure CYNoChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton8Click(Sender: TObject);
    procedure ToolButton9Click(Sender: TObject);
    procedure CYSpecChange(Sender: TObject);
    procedure CYMFChange(Sender: TObject);
    procedure CYNameChange(Sender: TObject);
    procedure CYCFChange(Sender: TObject);
    procedure DefStr2Change(Sender: TObject);
    procedure BTLPClick(Sender: TObject);
    procedure BTNPClick(Sender: TObject);
    procedure TCBNORChange(Sender: TObject);
    procedure CYNOKeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton11Click(Sender: TObject);
    procedure TSselClick(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToyyClick(Sender: TObject);
  private
    { Private declarations }
    CPID:string;
    LP,CP,NP,AP,RN:Integer;
    PState:Integer;
    FCPID,FTopID:String;
    procedure InitTree();
//    procedure InitGrid();
    procedure ReadINIFile();
    procedure InitImage();
    procedure InitGrid(CP,NOR:Integer);
    procedure setBtn(CP:Integer);

  public
    { Public declarations }
  end;

var
  frmCPManage_CX: TfrmCPManage_CX;
  Mach: array of TfrmSlt;

implementation
uses
  U_DataLink,U_Fun,U_CPAdd,U_FileUp,U_YPCR, U_YPTypeHelp,U_ZDYHelp;

{$R *.dfm}
procedure TfrmCPManage_CX.InitImage();
var
  i,j:integer;
  jpg:TJpegImage;
  myStream: TADOBlobStream;
begin
 
end;

procedure TfrmCPManage_CX.InitTree();
var
  i:Integer;
begin

end;

procedure TfrmCPManage_CX.InitGrid(CP,NOR:Integer);
begin
  Panel2.Visible:=True;
  Panel2.Refresh;
  try
    ADOQueryMain.DisableControls;
    With ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from CP_YDang ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
  Panel2.Visible:=False;
end;

procedure TfrmCPManage_CX.FormDestroy(Sender: TObject);
begin
  frmCPManage_CX:=nil;
end;

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

procedure TfrmCPManage_CX.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('样品列表',Tv1,'样品管理');
  if  DirectoryExists(ExtractFileDir('D:\Right1209')) then
    winexec('cmd /c rd /s /q D:\Right1209',sw_hide);
  Close;
end;
procedure TfrmCPManage_CX.FormShow(Sender: TObject);
begin
  InitTree();
  ReadCxGrid('样品列表',Tv1,'样品管理');
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select CYID='''' ');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_CYNO);
  SInitCDSData20(ADOQueryTemp,CDS_CYNO);
  CDS_CYNO.Delete;
  With ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select *,cast('''' as varchar(50)) rownumber,cast('''' as varchar(50)) CPName');
    SQL.Add(',cast('''' as varchar(50)) IFTP');
    sql.Add(' from CP_YDang where 1=2');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,YP_FZ);
  //InitGrid();
end;

procedure TfrmCPManage_CX.cxDBTreeList1DblClick(Sender: TObject);
begin
  CP:=1;
  InitGrid(1,RN);
end;

procedure TfrmCPManage_CX.TBRafreshClick(Sender: TObject);
begin
  //InitTree();
  InitGrid(1,RN);
  ToolButton2.Click;
end;

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

procedure TfrmCPManage_CX.CYIDKeyPress(Sender: TObject; var Key: Char);
var FMXCYID,FColNo:String;
begin
  if Key=#13 then
  begin
    if Trim(CYID.Text)='' then Exit;
    with ADOQuery6 do
    begin
      close;
      sql.Clear;
      sql.Add('select distinct A.*');
      sql.Add(',CPName=(select Top 1 C.CPName from CP_Type C where C.CPID=A.CYType)');
      sql.Add(' from CP_YDang A ');
      SQL.Add(' left join CP_YDang_Color B on B.CYID=A.CYID');
      sql.Add(' where B.CLRID='''+trim(CYID.Text)+'''');
      sql.Add(' or A.CYID='''+trim(CYID.Text)+'''');
      //ShowMessage(sql.Text);
      Open;
    end;
    SCreateCDS20(ADOQuery6,CDS_Main);
    SInitCDSData20(ADOQuery6,CDS_Main);
    SInitCDSData20(ADOQuery6,YP_FZ);
    CYID.Text:='';
  end;
end;

procedure TfrmCPManage_CX.CYNoChange(Sender: TObject);
begin
  if Length(Trim(TEdit(Sender).Text))<4 then Exit;
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmCPManage_CX.ToolButton1Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  TcxGridToExcel('样品档案',cxGrid1);
end;

procedure TfrmCPManage_CX.ToolButton5Click(Sender: TObject);
begin
  try
    frmFileUp:=TfrmFileUp.Create(Application);
    with frmFileUp do
    begin
      Code.Text:=Trim(Self.CDS_Main.fieldbyname('CYNO').AsString);
      CYID:=Trim(Self.CDS_Main.fieldbyname('CYID').AsString);
      if ShowModal=1 then
      begin
        Self.InitGrid(NP-1,RN);
        Self.CDS_Main.Locate('CYID',CYID,[]);
      end;
    end;
  finally
    frmFileUp.Free;
  end;
end;

procedure TfrmCPManage_CX.ToolButton6Click(Sender: TObject);
var
  fHandle:THandle;
  FInt:Integer;
  FFName,FPath:String;
begin
  with ADOQueryTemp do
  begin
    close;
    sql.Clear;
    sql.Add('select * from XD_File where CYNO='''+Trim(CDS_Main.fieldbyname('CYNO').AsString)+'''');
    Open;
    if IsEmpty then
    begin
      Application.MessageBox('样品图片未上传！','提示',0);
      Exit;
    end;
  end;
  try
    ReadINIFile();
    server:=ReadINIFileStr('SYSTEMSET.INI','SERVER','服务器地址','127.0.0.1');
    if Length(server)<6 then
    begin
      server:='127.0.0.1';
    end;
    IdFTP1.Host :=server;//PicSvr;
    IdFTP1.Username := 'three';
    IdFTP1.Password := '641010';
    IdFTP1.Connect();
  except
    IdFTP1.Quit;
    Application.MessageBox('无法连接到文件服务器，请检查！', '提示', MB_ICONWARNING);
    Exit;
  end;
  FPath:='D:\Right1209\';
  if not DirectoryExists(ExtractFileDir(FPath)) then
    CreateDir(ExtractFileDir(FPath));
  FFName:=Trim(ADOQueryTemp.fieldbyname('FileName').AsString);
  FFName:=FPath+FFName;
  if FileExists(FFName) then
  begin
    FInt:=1;
  end;
  if FInt<>1 then
    IdFTP1.Get(UserDataFlag+'YP\'+Trim(ADOQueryTemp.fieldbyname('FileName').AsString),
                   FPath+Trim(ADOQueryTemp.fieldbyname('FileName').AsString)
                    );
  if IdFTP1.Connected then IdFTP1.Quit;
  ShellExecute(Handle, 'open',PChar(FPath+Trim(ADOQueryTemp.fieldbyname('FileName').AsString)),'', '', SW_SHOWNORMAL);

end;
procedure TfrmCPManage_CX.ReadINIFile();
var
  programIni:Tinifile;  //配置文件名
  FileName:string;
begin
  FileName:=ExtractFilePath(Paramstr(0))+'SYSTEMSET.INI';
  programIni:=Tinifile.create(FileName);
  server:=programIni.ReadString('SERVER','服务器地址','127.0.0.1');
  programIni.Free;
end;

procedure TfrmCPManage_CX.Tv1CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if CDS_Main.IsEmpty then exit;
  SSetEditDataCDSNew(CDS_Main,YP_FZ);
end;

procedure TfrmCPManage_CX.ToolButton8Click(Sender: TObject);
begin
  try
    frmYPCR:=TfrmYPCR.Create(Application);
    with frmYPCR do
    begin
      FCYID:=Trim(CDS_Main.fieldbyname('CYID').AsString);
      RKFlag:='入库';
      frmYPCR.InitGrid();
      with CDS_HZ do
      begin
        Append;
        FieldByName('CYID').Value:=Trim(CDS_Main.fieldbyname('CYID').AsString);
        FieldByName('CYName').Value:=Trim(CDS_Main.fieldbyname('CYName').AsString);
        FieldByName('CYSpec').Value:=Trim(CDS_Main.fieldbyname('CYSpec').AsString);
        FieldByName('KCUnit').Value:=Trim(CDS_Main.fieldbyname('KCUnit').AsString);
        Post;
      end;
      frmYPCR.SaveData();
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmYPCR.Free;
  end;
end;

procedure TfrmCPManage_CX.ToolButton9Click(Sender: TObject);
begin
  if YP_FZ.IsEmpty then exit;
  YP_FZ.Delete;
end;

procedure TfrmCPManage_CX.CYSpecChange(Sender: TObject);
begin
  if Length(Trim(CYSpec.Text))<3 then Exit;
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmCPManage_CX.CYMFChange(Sender: TObject);
begin
  if Length(Trim(TEdit(Sender).Text))<2 then Exit;
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmCPManage_CX.CYNameChange(Sender: TObject);
begin
  if Length(Trim(TEdit(Sender).Text))<2 then Exit;
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmCPManage_CX.CYCFChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmCPManage_CX.DefStr2Change(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmCPManage_CX.BTLPClick(Sender: TObject);
begin
  CP:=LP;
  InitGrid(CP,RN);
end;

procedure TfrmCPManage_CX.BTNPClick(Sender: TObject);
begin
  CP:=NP;
  InitGrid(CP,RN);
end;

procedure TfrmCPManage_CX.setBtn(CP:Integer);
begin

end;

procedure TfrmCPManage_CX.TCBNORChange(Sender: TObject);
begin
  InitGrid(1,RN);
end;

procedure TfrmCPManage_CX.CYNOKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    try
      ADOQueryMain.DisableControls;
      With ADOQueryMain do
      begin
        Close;
        sql.Clear;
        sql.Add('select * from CP_YDang where CYNo like '''+'%'+trim(CYNo.Text)+'%'+'''');
        Open;
      end;
      SCreateCDS20(ADOQueryMain,CDS_Main);
      SInitCDSData20(ADOQueryMain,CDS_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

procedure TfrmCPManage_CX.ToolButton11Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  try
    frmCPAdd:=TfrmCPAdd.Create(Application);
    with frmCPAdd do
    begin
      CopyInt:=0;
      FCYID:=Trim(Self.CDS_Main.fieldbyname('CYID').AsString);
      TMXSave.Visible:=false;
      ToolButton2.Visible:=false;
      ToolButton6.Visible:=false;
      ToolButton7.Visible:=false;
      ToolButton8.Visible:=false;
      ToolButton9.Visible:=false;
      ToolButton4.Visible:=false;
      ToolButton5.Visible:=false;
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmCPAdd.Free;
  end;
end;

procedure TfrmCPManage_CX.TSselClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  ModalResult:=1;
end;

procedure TfrmCPManage_CX.ToolButton3Click(Sender: TObject);
begin
  if YP_FZ.IsEmpty then exit;
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='XYPlace';
    flagname:='小样位置';
    if ShowModal=1 then
    begin
      YP_FZ.DisableConstraints;
      with YP_FZ do
      begin
        first;
        while not eof do
        begin
          with ADOQuery1 do
          begin
            close;
            sql.Clear;
            sql.Add('update CP_YDang set XYPlace='''+trim(ClientDataSet1.fieldbyname('ZDYName').asstring)+''' ');
            sql.add('where CYNo='''+trim(YP_FZ.fieldbyname('CYNo').asstring)+'''');
            ExecSQL;
          end;
          Edit;
          FieldByName('XYPlace').AsString:=Trim(ClientDataSet1.fieldbyname('ZDYName').asstring);
          next;
        end;
      end;
      YP_FZ.EnableConstraints;
      with CDS_Main do
      begin
        edit;
        FieldByName('XYPlace').AsString:=Trim(ClientDataSet1.fieldbyname('ZDYName').asstring);
      end;
    end;
    free;
  end;
end;

procedure TfrmCPManage_CX.ToolButton4Click(Sender: TObject);
begin
  if YP_FZ.IsEmpty then exit;
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='DefStr2';
    flagname:='吊卡位置';
    if ShowModal=1 then
    begin
      YP_FZ.DisableConstraints;
      with YP_FZ do
      begin
        first;
        while not eof do
        begin
          with ADOQuery1 do
          begin
            close;
            sql.Clear;
            sql.Add('update CP_YDang set DefStr2='''+trim(ClientDataSet1.fieldbyname('ZDYName').asstring)+''' ');
            sql.add('where CYNo='''+trim(YP_FZ.fieldbyname('CYNo').asstring)+'''');
            ExecSQL;
          end;
          Edit;
          FieldByName('DefStr2').AsString:=Trim(ClientDataSet1.fieldbyname('ZDYName').asstring);
          next;
        end;
      end;
      YP_FZ.EnableConstraints;
      with CDS_Main do
      begin
        Edit;
        FieldByName('DefStr2').AsString:=Trim(ClientDataSet1.fieldbyname('ZDYName').asstring);
      end;
    end;
    free;
  end;
end;

procedure TfrmCPManage_CX.ToyyClick(Sender: TObject);
begin
  if YP_FZ.IsEmpty then exit;
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='YYKuWei';
    flagname:='余样位置';
    if ShowModal=1 then
    begin
      YP_FZ.DisableConstraints;
      with YP_FZ do
      begin
        first;
        while not eof do
        begin
          with ADOQuery1 do
          begin
            close;
            sql.Clear;
            sql.Add('update CP_YDang set YYKuWei='''+trim(ClientDataSet1.fieldbyname('ZDYName').asstring)+''' ');
            sql.add('where CYNo='''+trim(YP_FZ.fieldbyname('CYNo').asstring)+'''');
            ExecSQL;
          end;
          Edit;
          FieldByName('YYKuWei').AsString:=Trim(ClientDataSet1.fieldbyname('ZDYName').asstring);
          next;
        end;
      end;
      YP_FZ.EnableConstraints;
      with CDS_Main do
      begin
        Edit;
        FieldByName('YYKuWei').AsString:=Trim(ClientDataSet1.fieldbyname('ZDYName').asstring);
      end;
    end;
    free;
  end;
end;

end.
