unit U_ZdyAttInputCP_CB;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, cxPC, cxControls, ComCtrls, ToolWin, StdCtrls, Menus,
  cxTextEdit, cxCurrencyEdit, BtnEdit, cxContainer, cxEdit, cxImage, DB, ADODB,
  cxDBEdit, cxLookAndFeelPainters, cxButtons, IdBaseComponent, IdComponent,
  IdTCPConnection, IdTCPClient, IdFTP, ShellAPI, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxDBData, cxGridLevel, cxClasses,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, DBClient, cxButtonEdit, cxLookAndFeels, cxNavigator, dxSkinsCore,
  dxSkinBlack, dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee,
  dxSkinDarkRoom, dxSkinDarkSide, dxSkinDevExpressDarkStyle,
  dxSkinDevExpressStyle, dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast,
  dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky,
  dxSkinMcSkin, dxSkinMetropolis, dxSkinMetropolisDark, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
  dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin, dxSkinSeven,
  dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus, dxSkinSilver,
  dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008, dxSkinTheAsphaltWorld,
  dxSkinsDefaultPainters, dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint,
  dxSkinXmas2008Blue, dxSkinscxPCPainter, cxDropDownEdit;

type
  TfrmZdyAttInputCP_CB = class(TForm)
    ToolBar1: TToolBar;
    Tsave: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    zdyCode: TEdit;
    Label2: TLabel;
    zdyName: TEdit;
    Label3: TLabel;
    Label6: TLabel;
    defstr1: TEdit;
    Label13: TLabel;
    Label17: TLabel;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    ADOQueryImage: TADOQuery;
    ADOQuerymain: TADOQuery;
    Picture4: TcxDBImage;
    FileName: TcxButton;
    IdFTP1: TIdFTP;
    DataSource1: TDataSource;
    Label12: TLabel;
    defstr2: TEdit;
    Label39: TLabel;
    defnote2: TEdit;
    defstr8: TEdit;
    Label4: TLabel;
    defstr7: TEdit;
    Label5: TLabel;
    note: TMemo;
    Label7: TLabel;
    defstr5: TComboBox;
    Panel2: TPanel;
    Panel3: TPanel;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    TV1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    CDS1: TClientDataSet;
    CDS2: TClientDataSet;
    CDS3: TClientDataSet;
    V1Column1: TcxGridDBColumn;
    V1Column2: TcxGridDBColumn;
    V1Column3: TcxGridDBColumn;
    V1Column4: TcxGridDBColumn;
    V1Column5: TcxGridDBColumn;
    Panel4: TPanel;
    ToolBar3: TToolBar;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Panel5: TPanel;
    ToolBar4: TToolBar;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    Panel6: TPanel;
    Panel7: TPanel;
    Panel8: TPanel;
    Label8: TLabel;
    DefFlt1: TEdit;
    Label9: TLabel;
    Label10: TLabel;
    DS3: TDataSource;
    DS2: TDataSource;
    DS1: TDataSource;
    DefFlt2: TEdit;
    V1Column6: TcxGridDBColumn;
    Panel9: TPanel;
    ToolBar5: TToolBar;
    ToolButton7: TToolButton;
    ToolButton8: TToolButton;
    Panel10: TPanel;
    cxGrid4: TcxGrid;
    TV4: TcxGridDBTableView;
    cxGridLevel3: TcxGridLevel;
    DS4: TDataSource;
    TV4Column1: TcxGridDBColumn;
    TV4Column2: TcxGridDBColumn;
    TV4Column3: TcxGridDBColumn;
    TV4Column4: TcxGridDBColumn;
    CDS4: TClientDataSet;
    TV1Column1: TcxGridDBColumn;
    TV1Column2: TcxGridDBColumn;
    ToolButton9: TToolButton;
    ADOQuery1: TADOQuery;
    ToolButton10: TToolButton;
    ToolButton11: TToolButton;
    ToolButton12: TToolButton;
    DataSource2: TDataSource;
    ClientDataSet1: TClientDataSet;
    TV1Column3: TcxGridDBColumn;
    Label11: TLabel;
    Label14: TLabel;
    fprice: TEdit;
    sprice: TEdit;
    Label15: TLabel;
    tprice: TEdit;
    Label16: TLabel;
    DZprice: TEdit;
    Label18: TLabel;
    seprice: TEdit;
    CYColor: TBtnEditA;
    Label19: TLabel;
    Panel11: TPanel;
    ToolBar6: TToolBar;
    ToolButton13: TToolButton;
    ToolButton14: TToolButton;
    ToolButton15: TToolButton;
    Panel12: TPanel;
    cxGrid5: TcxGrid;
    TV5: TcxGridDBTableView;
    cxGridLevel4: TcxGridLevel;
    CDS5: TClientDataSet;
    DS5: TDataSource;
    TV5Column1: TcxGridDBColumn;
    TV5Column2: TcxGridDBColumn;
    CYColorno: TEdit;
    TV1Column4: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TsaveClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure cxDBImage1DblClick(Sender: TObject);
    procedure FileNameClick(Sender: TObject);
    procedure MTypeBtnDnClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure V1Column3PropertiesEditValueChanged(Sender: TObject);
    procedure cxGridDBColumn3PropertiesEditValueChanged(Sender: TObject);
    procedure cxGridDBColumn8PropertiesEditValueChanged(Sender: TObject);
    procedure V1Column6PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ToolButton7Click(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
    procedure V1Column2PropertiesEditValueChanged(Sender: TObject);
    procedure V1Column4PropertiesEditValueChanged(Sender: TObject);
    procedure TV1Column1PropertiesEditValueChanged(Sender: TObject);
    procedure TV1Column2PropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton9Click(Sender: TObject);
    procedure ToolButton10Click(Sender: TObject);
    procedure ToolButton11Click(Sender: TObject);
    procedure ToolButton12Click(Sender: TObject);
    procedure TV1Column3PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure CYColorBtnClick(Sender: TObject);
    procedure ToolButton13Click(Sender: TObject);
    procedure ToolButton14Click(Sender: TObject);
  private
    function savedata(): Boolean;
    function savedatacb(): Boolean;
    function savedataFZ(): Boolean;
    procedure InitGrid();
    procedure InitImage();
    procedure Jscb();
    { Private declarations }
  public
    PState, CopyInt: Integer;
    FATID: string;
    p, FZcode, FZname, fzmk: string;
    { Public declarations }
  end;

var
  frmZdyAttInputCP_CB: TfrmZdyAttInputCP_CB;

implementation

uses
  U_DataLink, U_Fun10, U_ZDYHelp, getpic, U_ZdyAttachCPcbfz, U_ZDYHelpSel,
  U_ZdyAttachGYS_help, U_ZdyYS_Sel, U_ZdyCMZ_help;
{$R *.dfm}

procedure TfrmZdyAttInputCP_CB.Jscb();
var
  fcrcb, frtcb: double;
begin
  fcrcb := 0;
  frtcb := 0;
  if not varisnull(tv1.DataController.Summary.FooterSummaryValues[0]) then
    fcrcb := fcrcb + tv1.DataController.Summary.FooterSummaryValues[0];
  if not varisnull(tv1.DataController.Summary.FooterSummaryValues[1]) then
    frtcb := frtcb + tv1.DataController.Summary.FooterSummaryValues[1];
  if not varisnull(tv2.DataController.Summary.FooterSummaryValues[0]) then
  begin
    fcrcb := fcrcb + tv2.DataController.Summary.FooterSummaryValues[0];
    frtcb := frtcb + tv2.DataController.Summary.FooterSummaryValues[0];
  end;
  if not varisnull(tv3.DataController.Summary.FooterSummaryValues[0]) then
  begin
    fcrcb := fcrcb + tv3.DataController.Summary.FooterSummaryValues[0];
    frtcb := frtcb + tv3.DataController.Summary.FooterSummaryValues[0];
  end;
  DefFlt1.Text := floattostr(fcrcb);
  DefFlt2.Text := floattostr(frtcb);
end;

function TfrmZdyAttInputCP_CB.savedatacb(): Boolean;
begin
  result := false;
  ADOQueryCmd.Connection.BeginTrans;
  try
    if trim(FATID) = '' then
    begin
      if GetLSNo(ADOQueryCmd, FATID, 'AT', 'KH_Zdy_Attachment', 4, 1) = False then
      begin
        Result := False;
        Application.MessageBox('取最大号失败！', '提示', 0);
        Exit;
      end;

      with ADOQueryCmd do
      begin
        Close;
        SQL.Clear;
        sql.Add('select * from KH_Zdy_Attachment where ATID=''' + Trim(FATID) + '''');
        Open;
        if IsEmpty then
        begin
          append;
          FieldByName('Filler').Value := Trim(DName);
        end
        else
        begin
          Edit;
          FieldByName('Editer').Value := Trim(DName);
          FieldByName('Edittime').Value := SGetServerDateTime(ADOQueryTmp);
        end;
        SSetsaveSqlNew(ADOQueryCmd, 'KH_Zdy_Attachment', GroupBox1, 2);
        //          fieldbyname('fprice').Value := strtofloatdef(trim(DefFlt1.Text), 0);
//        fieldbyname('Sprice').Value := strtofloatdef(trim(DefFlt2.Text), 0);
//        fieldbyname('Tprice').Value := strtofloatdef(trim(DefFlt1.Text), 0);
//        FieldByName('defflt3').Value := strtofloatdef(Trim(defflt3.text), 1);
//        FieldByName('defflt4').Value := strtofloatdef(Trim(defflt4.text), 0);
        FieldByName('ATID').Value := Trim(FATID);
        FieldByName('Type').Value := 'CP';
        post;
      end;
    end;

    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from KH_Zdy_Attachment where ATID=''' + Trim(FATID) + '''');
      open;
      if not ADOQueryCmd.IsEmpty then
      begin
        edit;
        fieldbyname('DefFlt1').Value := strtofloatdef(trim(DefFlt1.Text), 0);
        fieldbyname('DefFlt2').Value := strtofloatdef(trim(DefFlt2.Text), 0);
        fieldbyname('fprice').Value := strtofloatdef(trim(fprice.Text), 0);
        fieldbyname('Sprice').Value := strtofloatdef(trim(Sprice.Text), 0);
        fieldbyname('Seprice').Value := strtofloatdef(trim(Seprice.Text), 0);
        fieldbyname('Tprice').Value := strtofloatdef(trim(Tprice.Text), 0);
        fieldbyname('DZprice').Value := strtofloatdef(trim(DZprice.Text), 0);
        FieldByName('CYColorno').Value := Trim(CYColorno.text);
        FieldByName('CYColor').Value := Trim(CYColor.text);
        post;
      end;
    end;

    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('delete from KH_Zdy_CPCB where zdyCode=''' + Trim(zdyCode.Text) + '''');
      execsql;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from KH_Zdy_CPCB where 1=2 ');
      Open;
    end;
    with cds1 do
    begin
      First;
      while not eof do                 
      begin
        ADOQueryCmd.Append;
        ADOQueryCmd.FieldByName('CBID').Value := trim(FATID) + 'MF' + inttostr(recno);
        ADOQueryCmd.FieldByName('ATID').Value := trim(FATID);
        ADOQueryCmd.FieldByName('zdyCode').Value := trim(zdyCode.Text);
        ADOQueryCmd.FieldByName('zdyName').Value := trim(zdyName.Text);
        ADOQueryCmd.FieldByName('cbType').Value := 'CPCBMF';
        ADOQueryCmd.FieldByName('defstr1').Value := trim(fieldbyname('defstr1').AsString);
        ADOQueryCmd.FieldByName('defstr2').Value := trim(fieldbyname('defstr2').AsString);
        ADOQueryCmd.FieldByName('defstr3').Value := trim(fieldbyname('defstr3').AsString);
        ADOQueryCmd.FieldByName('defstr4').Value := trim(fieldbyname('defstr4').AsString);
        ADOQueryCmd.FieldByName('DefFlt4').Value := fieldbyname('DefFlt4').AsFloat;
        ADOQueryCmd.FieldByName('DefFlt5').Value := fieldbyname('DefFlt5').AsFloat;

        ADOQueryCmd.fieldbyname('DefFlt1').Value := strtofloatdef(trim(DefFlt1.Text), 0);
        ADOQueryCmd.fieldbyname('DefFlt2').Value := strtofloatdef(trim(DefFlt2.Text), 0);
        ADOQueryCmd.fieldbyname('CBdj').Value := fieldbyname('CBdj').AsFloat;
        ADOQueryCmd.fieldbyname('Cbsh').Value := fieldbyname('cbsh').AsFloat;
        ADOQueryCmd.fieldbyname('CBColor').Value := trim(fieldbyname('CBColor').AsString);
        ADOQueryCmd.fieldbyname('BLtype').Value := trim(fieldbyname('BLtype').AsString);
        ADOQueryCmd.Post;
        next;
      end;
    end;
    with cds2 do
    begin
      First;
      while not eof do
      begin
        ADOQueryCmd.Append;
        ADOQueryCmd.FieldByName('CBID').Value := trim(FATID) + 'GY' + inttostr(recno);
        ADOQueryCmd.FieldByName('ATID').Value := trim(FATID);
        ADOQueryCmd.FieldByName('zdyCode').Value := trim(zdyCode.Text);
        ADOQueryCmd.FieldByName('zdyName').Value := trim(zdyName.Text);
        ADOQueryCmd.FieldByName('cbType').Value := 'CPCBGY';
        ADOQueryCmd.FieldByName('defstr1').Value := trim(fieldbyname('defstr1').AsString);
        ADOQueryCmd.FieldByName('defstr2').Value := trim(fieldbyname('defstr2').AsString);
        ADOQueryCmd.FieldByName('defstr3').Value := trim(fieldbyname('defstr3').AsString);
        ADOQueryCmd.FieldByName('DefFlt4').Value := fieldbyname('DefFlt4').AsFloat;
        ADOQueryCmd.FieldByName('DefFlt5').Value := fieldbyname('DefFlt5').AsFloat;
        ADOQueryCmd.fieldbyname('DefFlt1').Value := strtofloatdef(trim(DefFlt1.Text), 0);
        ADOQueryCmd.fieldbyname('DefFlt2').Value := strtofloatdef(trim(DefFlt2.Text), 0);
        ADOQueryCmd.Post;
        next;
      end;
    end;
    with cds3 do
    begin
      First;
      while not eof do
      begin
        ADOQueryCmd.Append;
        ADOQueryCmd.FieldByName('CBID').Value := trim(FATID) + 'FY' + inttostr(recno);
        ADOQueryCmd.FieldByName('ATID').Value := trim(FATID);
        ADOQueryCmd.FieldByName('zdyCode').Value := trim(zdyCode.Text);
        ADOQueryCmd.FieldByName('zdyName').Value := trim(zdyName.Text);
        ADOQueryCmd.FieldByName('cbType').Value := 'CPCBFY';
        ADOQueryCmd.FieldByName('defstr1').Value := trim(fieldbyname('defstr1').AsString);
        ADOQueryCmd.FieldByName('defstr2').Value := trim(fieldbyname('defstr2').AsString);
        ADOQueryCmd.FieldByName('defstr3').Value := trim(fieldbyname('defstr3').AsString);
        ADOQueryCmd.FieldByName('DefFlt4').Value := fieldbyname('DefFlt4').AsFloat;
        ADOQueryCmd.FieldByName('DefFlt5').Value := fieldbyname('DefFlt5').AsFloat;
        ADOQueryCmd.fieldbyname('DefFlt1').Value := strtofloatdef(trim(DefFlt1.Text), 0);
        ADOQueryCmd.fieldbyname('DefFlt2').Value := strtofloatdef(trim(DefFlt2.Text), 0);
        ADOQueryCmd.Post;
        next;
      end;
    end;
    with cds4 do
    begin
      First;
      while not eof do
      begin
        ADOQueryCmd.Append;
        ADOQueryCmd.FieldByName('CBID').Value := trim(FATID) + 'XY' + inttostr(recno);
        ADOQueryCmd.FieldByName('ATID').Value := trim(FATID);
        ADOQueryCmd.FieldByName('zdyCode').Value := trim(zdyCode.Text);
        ADOQueryCmd.FieldByName('zdyName').Value := trim(zdyName.Text);
        ADOQueryCmd.FieldByName('cbType').Value := 'CPCBXY';
        ADOQueryCmd.FieldByName('defstr1').Value := trim(fieldbyname('defstr1').AsString);
        ADOQueryCmd.FieldByName('defstr2').Value := trim(fieldbyname('defstr2').AsString);
        ADOQueryCmd.FieldByName('defstr3').Value := trim(fieldbyname('defstr3').AsString);
        ADOQueryCmd.FieldByName('DefFlt4').Value := fieldbyname('DefFlt4').AsFloat;
        ADOQueryCmd.FieldByName('DefFlt5').Value := fieldbyname('DefFlt5').AsFloat;
        ADOQueryCmd.fieldbyname('DefFlt1').Value := strtofloatdef(trim(DefFlt1.Text), 0);
        ADOQueryCmd.fieldbyname('DefFlt2').Value := strtofloatdef(trim(DefFlt2.Text), 0);
        ADOQueryCmd.FieldByName('CBzxjs').Value := fieldbyname('CBzxjs').AsFloat;
        ADOQueryCmd.FieldByName('CBzdjs').Value := fieldbyname('CBzdjs').AsFloat;
        ADOQueryCmd.fieldbyname('CBfrf').Value := fieldbyname('CBfrf').AsFloat;
        ADOQueryCmd.fieldbyname('CBcjf').Value := fieldbyname('CBcjf').AsFloat;
        ADOQueryCmd.Post;
        next;
      end;
    end;
    with cds5 do
    begin
      First;
      while not eof do
      begin
        ADOQueryCmd.Append;
        ADOQueryCmd.FieldByName('CBID').Value := trim(FATID) + 'CM' + inttostr(recno);
        ADOQueryCmd.FieldByName('ATID').Value := trim(FATID);
        ADOQueryCmd.FieldByName('zdyCode').Value := trim(zdyCode.Text);
        ADOQueryCmd.FieldByName('zdyName').Value := trim(zdyName.Text);
        ADOQueryCmd.FieldByName('cbType').Value := 'CPCBCM';
        ADOQueryCmd.FieldByName('defstr1').Value := trim(fieldbyname('defstr1').AsString);
        ADOQueryCmd.FieldByName('defstr2').Value := trim(fieldbyname('defstr2').AsString);
//        ADOQueryCmd.FieldByName('defstr3').Value := trim(fieldbyname('defstr3').AsString);
//        ADOQueryCmd.FieldByName('DefFlt4').Value := fieldbyname('DefFlt4').AsFloat;
//        ADOQueryCmd.FieldByName('DefFlt5').Value := fieldbyname('DefFlt5').AsFloat;
        ADOQueryCmd.fieldbyname('DefFlt1').Value := strtofloatdef(trim(DefFlt1.Text), 0);
        ADOQueryCmd.fieldbyname('DefFlt2').Value := strtofloatdef(trim(DefFlt2.Text), 0);

        ADOQueryCmd.Post;
        next;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    result := true;
  except
    ADOQueryCmd.Connection.RollbackTrans;
  end;
end;

function TfrmZdyAttInputCP_CB.savedata(): Boolean;
begin
  result := false;
  try
    if trim(FATID) = '' then
    begin
      if GetLSNo(ADOQueryCmd, FATID, 'AT', 'KH_Zdy_Attachment', 4, 1) = False then
      begin
        Result := False;
        Application.MessageBox('取最大号失败！', '提示', 0);
        Exit;
      end;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from KH_Zdy_Attachment where ATID=''' + Trim(FATID) + '''');
      Open;
      if IsEmpty then
      begin
        append;
        FieldByName('Filler').Value := Trim(DName);
      end
      else
      begin
        Edit;
        FieldByName('Editer').Value := Trim(DName);
        FieldByName('Edittime').Value := SGetServerDateTime(ADOQueryTmp);
      end;
      SSetsaveSqlNew(ADOQueryCmd, 'KH_Zdy_Attachment', GroupBox1, 2);
      FieldByName('ATID').Value := Trim(FATID);
      FieldByName('Type').Value := 'CP';
      post;
    end;

    result := true;
  except
  end;
end;

procedure TfrmZdyAttInputCP_CB.InitGrid();
begin
  with ADOQueryMain do
  begin
    close;
    sql.Clear;
    sql.Add('select * from KH_Zdy_Attachment A');
    sql.Add('where ATID=' + quotedstr(trim(FATID)));
    open;
  end;
  if not ADOQueryMain.IsEmpty then
  begin
    GroupBox1.Enabled := true;
    zdyCode.Enabled := false;
    zdyName.Enabled := False;
    DefFlt1.Enabled := False;
    DefFlt2.Enabled := False;
    SCSHDataNew(ADOQueryMain, GroupBox1, 2);
    SCSHDataNew(ADOQueryMain, GroupBox1, 0);

  end;
  if PState = 1 then
  begin
    GroupBox1.Enabled := true;
    zdyCode.Enabled := true;
    zdyCode.text := '';
  end;
  with ADOQueryMain do
  begin
    close;
    sql.Clear;
    sql.Add('select * from KH_Zdy_CPCB A');
    sql.Add('where ATID=' + quotedstr(trim(FATID)));
    sql.Add('and CBType=''CPCBMF''');
    open;
    SCreateCDS20(ADOQueryMain, CDS1);
    SInitCDSData20(ADOQueryMain, CDS1);
  end;
  with ADOQueryMain do
  begin
    close;
    sql.Clear;
    sql.Add('select * from KH_Zdy_CPCB A');
    sql.Add('where ATID=' + quotedstr(trim(FATID)));
    sql.Add('and CBType=''CPCBGY''');
    open;
    SCreateCDS20(ADOQueryMain, CDS2);
    SInitCDSData20(ADOQueryMain, CDS2);
  end;
  with ADOQueryMain do
  begin
    close;
    sql.Clear;
    sql.Add('select * from KH_Zdy_CPCB A');
    sql.Add('where ATID=' + quotedstr(trim(FATID)));
    sql.Add('and CBType=''CPCBFY''');
    open;
    SCreateCDS20(ADOQueryMain, CDS3);
    SInitCDSData20(ADOQueryMain, CDS3);
  end;
  with ADOQueryMain do
  begin
    close;
    sql.Clear;
    sql.Add('select * from KH_Zdy_CPCB A');
    sql.Add('where ATID=' + quotedstr(trim(FATID)));
    sql.Add('and CBType=''CPCBXY''');
    open;
    SCreateCDS20(ADOQueryMain, CDS4);
    SInitCDSData20(ADOQueryMain, CDS4);
  end;
  with ADOQueryMain do
  begin
    close;
    sql.Clear;
    sql.Add('select * from KH_Zdy_CPCB A');
    sql.Add('where ATID=' + quotedstr(trim(FATID)));
    sql.Add('and CBType=''CPCBCM''');
    open;
    SCreateCDS20(ADOQueryMain, CDS5);
    SInitCDSData20(ADOQueryMain, CDS5);
  end;
end;

procedure TfrmZdyAttInputCP_CB.InitImage();
begin
  with ADOQueryImage do
  begin
    close;
    sql.Clear;
    sql.Add('select * from TP_File A');
    sql.Add('where TFid=' + quotedstr(trim(zdyCode.Text)));
    open;
  end;
end;

procedure TfrmZdyAttInputCP_CB.FormDestroy(Sender: TObject);
begin
  frmZdyAttInputCP_CB := nil;
end;

procedure TfrmZdyAttInputCP_CB.TBCloseClick(Sender: TObject);
begin
  if Application.MessageBox('确定要关闭吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  close;
end;

procedure TfrmZdyAttInputCP_CB.FormCreate(Sender: TObject);
begin
  Panel1.Align := alclient;
  clearControl(GroupBox1, 2);
end;

procedure TfrmZdyAttInputCP_CB.TsaveClick(Sender: TObject);
begin
//  zdyName.SetFocus;
  cxgrid1.SetFocus;
  if trim(zdyCode.Text) = '' then
  begin
    application.MessageBox('产品编号不能为空！', '提示信息', MB_ICONERROR);
    exit;
  end;

  if FATID = '' then
  begin
    with adoqueryTmp do
    begin
      close;
      sql.Clear;
      sql.Add('select * from KH_Zdy_Attachment X');
      sql.Add('where zdyCode=' + quotedstr(trim(zdyCode.Text)));
      sql.Add('and ATID<>' + quotedstr(trim(FATID)));
      sql.Add('and Type=''CP'' ');
      open;
      if not IsEmpty then
      begin
        application.MessageBox('产品编号重复！', '提示信息', MB_ICONERROR);
        exit;
      end;
    end;
  end;

  try
    if not savedataCB() then
    begin
      application.MessageBox('数据保存失败！', '提示信息', MB_ICONERROR);
    end
    else
    begin
      application.MessageBox('数据保存成功！', '提示信息');
      self.ModalResult := 1;
    end;

  except

  end;
end;

procedure TfrmZdyAttInputCP_CB.FormShow(Sender: TObject);
var
  fzdyCode: string;
begin
  if trim(FATID) = '' then
  begin
    if GetLSNo(ADOQueryCmd, fzdyCode, 'CP', 'KH_Zdy_Attachment', 3, 1) = False then
    begin
      Application.MessageBox('取最大号失败！', '提示', 0);
      Exit;
    end;
    zdyCode.Text := trim(fzdyCode);
  end;
  InitGrid();

  if CopyInt = 99 then
  begin
    FATID := '';
    zdyCode.Text := '';
    zdycode.ReadOnly := False;
//    with ADOQueryMain do
//    begin
//      First;
//      while not Eof do
//      begin
//        Edit;
//        FieldByName('ATID').Value := '';
//        Post;
//        Next;
//      end;
//    end;
  end;
  InitImage();
end;

procedure TfrmZdyAttInputCP_CB.cxDBImage1DblClick(Sender: TObject);
var
  sFieldName: string;
  fileName: string;
begin
{
  IF TcxDBImage(Sender).Picture.Height=0 then exit;

  sFieldName:='D:\图片查看';

  if not DirectoryExists(pchar(sFieldName)) then
  CreateDirectory(pchar(sFieldName),nil);

  fileName:=adoqueryImage.fieldbyname(TcxDBImage(Sender).Hint).asstring;

  sFieldName:=sFieldName+'\'+trim(fileName);
  try
    IdFTP1.Host := PicSvr;
    IdFTP1.Username := 'three';
		IdFTP1.Password := '641010';
    IdFTP1.Connect();
  except
    ;
  end;

  if IdFTP1.Connected then
  begin
    try
      IdFTP1.Get('TP\'+ Trim(fileName), sFieldName,false, true);
    except
      Application.MessageBox('客户图样文件不存在', '提示', MB_ICONWARNING);
      IdFTP1.Quit;
      Exit;
    end;
  end
  else
  begin
    Application.MessageBox('无法连接文件服务器', '提示', MB_ICONWARNING);
    IdFTP1.Quit;
    Exit;
  end;
   if IdFTP1.Connected then IdFTP1.Quit;
  ShellExecute(Handle, 'open',PChar(sFieldName),'', '', SW_SHOWNORMAL);    }
end;

procedure TfrmZdyAttInputCP_CB.FileNameClick(Sender: TObject);
begin
  if trim(zdyCode.Text) = '' then
  begin
    application.MessageBox('产品编号不能为空！', '提示信息', MB_ICONERROR);
    exit;
  end;

  try
    FormGetPic := TFormGetPic.Create(Application);
    with FormGetPic do
    begin
      fkeyNO := trim(zdyCode.Text);
      pat1 := TCXbutton(Sender).Name;
      pic1 := TCXbutton(Sender).Hint;
      FTFType := '产品';
 //   pat1:='PatFile1';
//   pic1:='Picture1';
      if ShowModal = 1 then
      begin
     // self.Timage(Tbutton(Sender).Hint).Picture.Assign(FormGetPic.Image2.Picture.Bitmap);
        zdycode.Enabled := false;
      end;

      Release;
    end;
    Initimage();
  except
    if FormGetPic <> nil then
      FormGetPic.Release;
  end;
end;

procedure TfrmZdyAttInputCP_CB.MTypeBtnDnClick(Sender: TObject);
begin
  TBtnEditC(Sender).Text := '';
  TBtnEditC(Sender).TxtCode := '';
end;

procedure TfrmZdyAttInputCP_CB.ToolButton2Click(Sender: TObject);
begin
  if CDS1.IsEmpty then
    exit;
  CDS1.Delete;
  jscb();
end;

procedure TfrmZdyAttInputCP_CB.ToolButton1Click(Sender: TObject);
begin
  frmZDYHelpSel := TfrmZDYHelpSel.create(self);
  with frmZDYHelpSel do
  begin
    flag := 'CPCBMF';
    if showmodal = 1 then
    begin
      ClientDataSet1.First;
      while not ClientDataSet1.Eof do
      begin
        if ClientDataSet1.fieldbyname('ssel').AsBoolean then
        begin
          cds1.Append;
          cds1.FieldByName('DEFstr1').Value := trim(ClientDataSet1.fieldbyname('zdyName').AsString);
          cds1.post;
        end;
        ClientDataSet1.Next;
      end;
      tv1.Controller.EditingController.ShowEdit();
      free;
    end;
  end;
end;

procedure TfrmZdyAttInputCP_CB.ToolButton3Click(Sender: TObject);
begin
  frmZDYHelpSel := TfrmZDYHelpSel.create(self);
  with frmZDYHelpSel do
  begin
    flag := 'CPCBGY';
    if showmodal = 1 then
    begin
      ClientDataSet1.First;
      while not ClientDataSet1.Eof do
      begin
        if ClientDataSet1.fieldbyname('ssel').AsBoolean then
        begin
          cds2.Append;
          cds2.FieldByName('DEFstr1').Value := trim(ClientDataSet1.fieldbyname('zdyName').AsString);
          cds2.post;
        end;
        ClientDataSet1.Next;
      end;
      tv2.Controller.EditingController.ShowEdit();
      free;
    end;
  end;
end;

procedure TfrmZdyAttInputCP_CB.ToolButton5Click(Sender: TObject);
begin
  frmZDYHelpSel := TfrmZDYHelpSel.create(self);
  with frmZDYHelpSel do
  begin
    flag := 'CPCBFY';
    if showmodal = 1 then
    begin
      ClientDataSet1.First;
      while not ClientDataSet1.Eof do
      begin
        if ClientDataSet1.fieldbyname('ssel').AsBoolean then
        begin
          cds3.Append;
          cds3.FieldByName('DEFstr1').Value := trim(ClientDataSet1.fieldbyname('zdyName').AsString);
          cds3.post;
        end;
        ClientDataSet1.Next;
      end;
      tv3.Controller.EditingController.ShowEdit();
      free;
    end;
  end;
end;

procedure TfrmZdyAttInputCP_CB.ToolButton4Click(Sender: TObject);
begin
  if CDS2.IsEmpty then
    exit;
  CDS2.Delete;
  jscb();
end;

procedure TfrmZdyAttInputCP_CB.ToolButton6Click(Sender: TObject);
begin
  if CDS3.IsEmpty then
    exit;
  CDS3.Delete;
  jscb();
end;

procedure TfrmZdyAttInputCP_CB.V1Column3PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;
  FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with cds1 do
  begin
    Edit;
    FieldByName(FFieldName).Value := Trim(mvalue);
    Post;
  end;
  tv1.Controller.EditingController.ShowEdit();
  jscb();
end;

procedure TfrmZdyAttInputCP_CB.cxGridDBColumn3PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;
  FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with cds2 do
  begin
    Edit;
    FieldByName(FFieldName).Value := Trim(mvalue);
    Post;
  end;
  tv2.Controller.EditingController.ShowEdit();
  jscb();

end;

procedure TfrmZdyAttInputCP_CB.cxGridDBColumn8PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;
  FFieldName := Trim(Tv3.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with cds3 do
  begin
    Edit;
    FieldByName(FFieldName).Value := Trim(mvalue);
    Post;
  end;
  tv3.Controller.EditingController.ShowEdit();
  jscb();

end;

procedure TfrmZdyAttInputCP_CB.V1Column6PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  frmZdyAttachGYS_help := TfrmZdyAttachGYS_help.create(self);
  with frmZdyAttachGYS_help do
  begin
    if showmodal = 1 then
    begin
      CDS1.Edit;
      cds1.FieldByName('defstr4').Value := trim(cds_hz.fieldbyname('zdyName').asstring);
      CDS1.Post;
    end;
    free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmZdyAttInputCP_CB.ToolButton7Click(Sender: TObject);
begin

  cds4.Append;
  cds4.post;
  tv4.Controller.EditingController.ShowEdit();

end;

procedure TfrmZdyAttInputCP_CB.ToolButton8Click(Sender: TObject);
begin
  if CDS4.IsEmpty then
    exit;
  CDS4.Delete;
end;

procedure TfrmZdyAttInputCP_CB.V1Column2PropertiesEditValueChanged(Sender: TObject);
var
  Fieldname: string;
begin
  Fieldname := Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  with CDS1 do
  begin
    edit;
    fieldbyname(Fieldname).Value := TcxTextEdit(Sender).EditingText;
    FieldByName('DefFlt4').Value := StrToFloatDef((Fieldbyname('defstr2').AsString), 0) * StrToFloatDef((Fieldbyname('CBdj').AsString), 0) * (((Fieldbyname('Cbsh').AsFloat) + 100) / 100);
    post;
  end;
  Tv1.Controller.EditingController.ShowEdit();
  jscb();
end;

procedure TfrmZdyAttInputCP_CB.V1Column4PropertiesEditValueChanged(Sender: TObject);
var
  Fieldname: string;
begin
  Fieldname := Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  with CDS1 do
  begin
    edit;
    fieldbyname(Fieldname).Value := TcxTextEdit(Sender).EditingText;
    FieldByName('DefFlt5').Value := StrToFloatDef((Fieldbyname('defstr3').AsString), 0) * StrToFloatDef((Fieldbyname('CBdj').AsString), 0) * (((Fieldbyname('Cbsh').AsFloat) + 100) / 100);
    post;
  end;
  Tv1.Controller.EditingController.ShowEdit();
  jscb();
end;

procedure TfrmZdyAttInputCP_CB.TV1Column1PropertiesEditValueChanged(Sender: TObject);
var
  Fieldname: string;
begin
  Fieldname := Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  with CDS1 do
  begin
    edit;
    fieldbyname(Fieldname).Value := TcxTextEdit(Sender).EditingText;
    FieldByName('DefFlt4').Value := StrToFloatDef((Fieldbyname('defstr2').AsString), 0) * StrToFloatDef((Fieldbyname('CBdj').AsString), 0) * (((Fieldbyname('Cbsh').AsFloat) + 100) / 100);
    FieldByName('DefFlt5').Value := StrToFloatDef((Fieldbyname('defstr3').AsString), 0) * StrToFloatDef((Fieldbyname('CBdj').AsString), 0) * (((Fieldbyname('Cbsh').AsFloat) + 100) / 100);
    post;
  end;
  Tv1.Controller.EditingController.ShowEdit();
  jscb();
end;

procedure TfrmZdyAttInputCP_CB.TV1Column2PropertiesEditValueChanged(Sender: TObject);
var
  Fieldname: string;
begin
  Fieldname := Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  with CDS1 do
  begin
    edit;
    fieldbyname(Fieldname).Value := TcxTextEdit(Sender).EditingText;
    FieldByName('DefFlt4').Value := StrToFloatDef((Fieldbyname('defstr2').AsString), 0) * StrToFloatDef((Fieldbyname('CBdj').AsString), 0) * (((Fieldbyname('Cbsh').AsFloat) + 100) / 100);
    FieldByName('DefFlt5').Value := StrToFloatDef((Fieldbyname('defstr3').AsString), 0) * StrToFloatDef((Fieldbyname('CBdj').AsString), 0) * (((Fieldbyname('Cbsh').AsFloat) + 100) / 100);
    post;
  end;
  Tv1.Controller.EditingController.ShowEdit();
  jscb();
end;

procedure TfrmZdyAttInputCP_CB.ToolButton9Click(Sender: TObject);
begin
  frmZdyAttachCPcbfz := TfrmZdyAttachCPcbfz.create(self);
  with frmZdyAttachCPcbfz do
  begin
    fType := '10';
    if showmodal = 1 then
    begin
      with ADOQuery1 do
      begin
        Close;
        SQL.Clear;
        sql.Add(' select * from KH_Zdy_CPCB where 1=1 ');
        sql.Add(' and atid=''' + trim(CDS_HZ.fieldbyname('ATID').asstring) + ''' and cbtype=''CPCBMF''');
        Open;
      end;
      with ADOQuery1 do
      begin
        First;
        while not eof do
        begin
          with cds1 do
          begin
            Append;
            FieldByName('AtId').Value := '';
            FieldByName('cbId').Value := '';
            FieldByName('zdycode').Value := Trim(ADOQuery1.fieldbyname('zdycode').AsString);
            FieldByName('zdyname').Value := Trim(ADOQuery1.fieldbyname('zdyname').AsString);
            FieldByName('cbtype').Value := Trim(ADOQuery1.fieldbyname('cbtype').AsString);
            FieldByName('defstr1').Value := Trim(ADOQuery1.fieldbyname('defstr1').AsString);
            FieldByName('defstr2').Value := Trim(ADOQuery1.fieldbyname('defstr2').AsString);
            FieldByName('defstr3').Value := Trim(ADOQuery1.fieldbyname('defstr3').AsString);
            FieldByName('defstr4').Value := Trim(ADOQuery1.fieldbyname('defstr4').AsString);
            FieldByName('DefFlt4').Value := Trim(ADOQuery1.fieldbyname('DefFlt4').AsString);
            FieldByName('DefFlt5').Value := Trim(ADOQuery1.fieldbyname('DefFlt5').AsString);
            FieldByName('DefFlt1').Value := Trim(ADOQuery1.fieldbyname('DefFlt1').AsString);
            FieldByName('DefFlt2').Value := Trim(ADOQuery1.fieldbyname('DefFlt2').AsString);
            FieldByName('CBdj').Value := StrToFloatDef(ADOQuery1.fieldbyname('CBdj').asstring, 0);
            FieldByName('Cbsh').Value := StrToFloatDef(ADOQuery1.fieldbyname('Cbsh').asstring, 0);
            FieldByName('CBColor').Value := Trim(ADOQuery1.fieldbyname('CBColor').AsString);
            Post;
          end;

          next;
        end;
      end;
      jscb();
    end;
    frmZdyAttachCPcbfz.free;
  end;
end;

function TfrmZdyAttInputCP_CB.savedataFZ(): Boolean;
var
  i, j: Integer;
begin
  result := false;
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from KH_Zdy_CPCB where 1=1 ');
    sql.Add(' and atid=''' + Trim(p) + ''' and cbtype=''CPCBMF''');
//    ShowMessage(sql.text);
    Open;
  end;
//  SCreateCDS20(ADOQuery1, cds1);
//  SInitCDSData20(ADOQuery1, cds1);

  with cds1 do
  begin

    for i := 0 to ADOQuery1.RecordCount - 1 do
    begin

      Edit;
      FieldByName('AtId').Value := '';
      FieldByName('cbId').Value := '';
      FieldByName('zdycode').Value := Trim(ADOQuery1.fieldbyname('zdycode').AsString);
      FieldByName('zdyname').Value := Trim(ADOQuery1.fieldbyname('zdyname').AsString);
      FieldByName('cbtype').Value := Trim(ADOQuery1.fieldbyname('cbtype').AsString);
      FieldByName('defstr1').Value := Trim(ADOQuery1.fieldbyname('defstr1').AsString);
      FieldByName('defstr2').Value := Trim(ADOQuery1.fieldbyname('defstr2').AsString);
      FieldByName('defstr3').Value := Trim(ADOQuery1.fieldbyname('defstr3').AsString);
      FieldByName('defstr4').Value := Trim(ADOQuery1.fieldbyname('defstr4').AsString);
      FieldByName('DefFlt4').Value := Trim(ADOQuery1.fieldbyname('DefFlt4').AsString);
      FieldByName('DefFlt5').Value := Trim(ADOQuery1.fieldbyname('DefFlt5').AsString);
      FieldByName('DefFlt1').Value := Trim(ADOQuery1.fieldbyname('DefFlt1').AsString);
      FieldByName('DefFlt2').Value := Trim(ADOQuery1.fieldbyname('DefFlt2').AsString);
      FieldByName('CBdj').Value := Trim(ADOQuery1.fieldbyname('CBdj').AsString);
      FieldByName('Cbsh').Value := Trim(ADOQuery1.fieldbyname('Cbsh').AsString);
      Post;
//      Next;
    end;
  end;

//
//  result := false;
//  ADOQueryCmd.Connection.BeginTrans;
//  try
//    with ADOQueryCmd do
//    begin
//      Close;
//      SQL.Clear;
//      sql.Add('select * from KH_Zdy_CPCB where 1=2 ');
//      Open;
//    end;
//    if fzmk = '1' then
//    begin
//      with cds1 do
//      begin
//        First;
//        while not eof do
//        begin
//          ADOQueryCmd.Append;
//          ADOQueryCmd.FieldByName('CBID').Value := trim(p) + 'MF' + inttostr(recno);
//          ADOQueryCmd.FieldByName('ATID').Value := trim(P);
//          ADOQueryCmd.FieldByName('zdyCode').Value := Trim(FZcode);      // trim(zdyCode.Text);
//          ADOQueryCmd.FieldByName('zdyName').Value := Trim(FZname); // trim(zdyName.Text);
//          ADOQueryCmd.FieldByName('cbType').Value := 'CPCBMF';
//          ADOQueryCmd.FieldByName('defstr1').Value := trim(fieldbyname('defstr1').AsString);
//          ADOQueryCmd.FieldByName('defstr2').Value := trim(fieldbyname('defstr2').AsString);
//          ADOQueryCmd.FieldByName('defstr3').Value := trim(fieldbyname('defstr3').AsString);
//          ADOQueryCmd.FieldByName('defstr4').Value := trim(fieldbyname('defstr4').AsString);
//          ADOQueryCmd.FieldByName('DefFlt4').Value := fieldbyname('DefFlt4').AsFloat;
//          ADOQueryCmd.FieldByName('DefFlt5').Value := fieldbyname('DefFlt5').AsFloat;
//          ADOQueryCmd.fieldbyname('DefFlt1').Value := strtofloatdef(trim(DefFlt1.Text), 0);
//          ADOQueryCmd.fieldbyname('DefFlt2').Value := strtofloatdef(trim(DefFlt2.Text), 0);
//          ADOQueryCmd.fieldbyname('CBdj').Value := fieldbyname('CBdj').AsFloat;
//          ADOQueryCmd.fieldbyname('Cbsh').Value := fieldbyname('cbsh').AsFloat;
//          ADOQueryCmd.Post;
//          next;
//        end;
//      end;
//    end;
//
//    ADOQueryCmd.Connection.CommitTrans;
  result := true;
//  except
//    ADOQueryCmd.Connection.RollbackTrans;
//  end;
end;

procedure TfrmZdyAttInputCP_CB.ToolButton10Click(Sender: TObject);
begin
  frmZdyAttachCPcbfz := TfrmZdyAttachCPcbfz.create(self);
  with frmZdyAttachCPcbfz do
  begin
    fType := '10';
    if showmodal = 1 then
    begin
      with ADOQuery1 do
      begin
        Close;
        SQL.Clear;
        sql.Add(' select * from KH_Zdy_CPCB where 1=1 ');
        sql.Add(' and atid=''' + trim(CDS_HZ.fieldbyname('ATID').asstring) + ''' and cbtype=''CPCBGY''');
        Open;
      end;
      with ADOQuery1 do
      begin
        First;
        while not eof do
        begin
          with cds2 do
          begin
            Append;
            FieldByName('AtId').Value := '';
            FieldByName('cbId').Value := '';
            FieldByName('zdycode').Value := Trim(ADOQuery1.fieldbyname('zdycode').AsString);
            FieldByName('zdyname').Value := Trim(ADOQuery1.fieldbyname('zdyname').AsString);
            FieldByName('cbtype').Value := Trim(ADOQuery1.fieldbyname('cbtype').AsString);
            FieldByName('defstr1').Value := Trim(ADOQuery1.fieldbyname('defstr1').AsString);
            FieldByName('defstr2').Value := Trim(ADOQuery1.fieldbyname('defstr2').AsString);
            FieldByName('defstr3').Value := Trim(ADOQuery1.fieldbyname('defstr3').AsString);
            FieldByName('DefFlt4').Value := Trim(ADOQuery1.fieldbyname('DefFlt4').AsString);
            FieldByName('DefFlt5').Value := Trim(ADOQuery1.fieldbyname('DefFlt5').AsString);
            FieldByName('DefFlt1').Value := Trim(ADOQuery1.fieldbyname('DefFlt1').AsString);
            FieldByName('DefFlt2').Value := Trim(ADOQuery1.fieldbyname('DefFlt2').AsString);
            Post;
          end;

          next;
        end;
      end;
      jscb();
    end;
    frmZdyAttachCPcbfz.free;
  end;
end;

procedure TfrmZdyAttInputCP_CB.ToolButton11Click(Sender: TObject);
begin
  frmZdyAttachCPcbfz := TfrmZdyAttachCPcbfz.create(self);
  with frmZdyAttachCPcbfz do
  begin
    fType := '10';
    if showmodal = 1 then
    begin
      with ADOQuery1 do
      begin
        Close;
        SQL.Clear;
        sql.Add(' select * from KH_Zdy_CPCB where 1=1 ');
        sql.Add(' and atid=''' + trim(CDS_HZ.fieldbyname('ATID').asstring) + ''' and cbtype=''CPCBFY''');
        Open;
      end;
      with ADOQuery1 do
      begin
        First;
        while not eof do
        begin
          with cds3 do
          begin
            Append;
            FieldByName('AtId').Value := '';
            FieldByName('cbId').Value := '';
            FieldByName('zdycode').Value := Trim(ADOQuery1.fieldbyname('zdycode').AsString);
            FieldByName('zdyname').Value := Trim(ADOQuery1.fieldbyname('zdyname').AsString);
            FieldByName('cbtype').Value := Trim(ADOQuery1.fieldbyname('cbtype').AsString);
            FieldByName('defstr1').Value := Trim(ADOQuery1.fieldbyname('defstr1').AsString);
            FieldByName('defstr2').Value := Trim(ADOQuery1.fieldbyname('defstr2').AsString);
            FieldByName('defstr3').Value := Trim(ADOQuery1.fieldbyname('defstr3').AsString);
            FieldByName('DefFlt4').Value := Trim(ADOQuery1.fieldbyname('DefFlt4').AsString);
            FieldByName('DefFlt5').Value := Trim(ADOQuery1.fieldbyname('DefFlt5').AsString);
            FieldByName('DefFlt1').Value := Trim(ADOQuery1.fieldbyname('DefFlt1').AsString);
            FieldByName('DefFlt2').Value := Trim(ADOQuery1.fieldbyname('DefFlt2').AsString);
            Post;
          end;

          next;
        end;
      end;
      jscb();
    end;
    frmZdyAttachCPcbfz.free;
  end;
end;

procedure TfrmZdyAttInputCP_CB.ToolButton12Click(Sender: TObject);
begin
  frmZdyAttachCPcbfz := TfrmZdyAttachCPcbfz.create(self);
  with frmZdyAttachCPcbfz do
  begin
    fType := '10';
    if showmodal = 1 then
    begin
      with ADOQuery1 do
      begin
        Close;
        SQL.Clear;
        sql.Add(' select * from KH_Zdy_CPCB where 1=1 ');
        sql.Add(' and atid=''' + trim(CDS_HZ.fieldbyname('ATID').asstring) + ''' and cbtype=''CPCBXY''');
        Open;
      end;
      with ADOQuery1 do
      begin
        First;
        while not eof do
        begin
          with cds4 do
          begin
            Append;
            FieldByName('AtId').Value := '';
            FieldByName('cbId').Value := '';
            FieldByName('zdycode').Value := Trim(ADOQuery1.fieldbyname('zdycode').AsString);
            FieldByName('zdyname').Value := Trim(ADOQuery1.fieldbyname('zdyname').AsString);
            FieldByName('cbtype').Value := Trim(ADOQuery1.fieldbyname('cbtype').AsString);
            FieldByName('defstr1').Value := Trim(ADOQuery1.fieldbyname('defstr1').AsString);
            FieldByName('defstr2').Value := Trim(ADOQuery1.fieldbyname('defstr2').AsString);
            FieldByName('defstr3').Value := Trim(ADOQuery1.fieldbyname('defstr3').AsString);
            FieldByName('defstr4').Value := Trim(ADOQuery1.fieldbyname('defstr4').AsString);
            FieldByName('DefFlt4').Value := Trim(ADOQuery1.fieldbyname('DefFlt4').AsString);
            FieldByName('DefFlt5').Value := Trim(ADOQuery1.fieldbyname('DefFlt5').AsString);
            FieldByName('DefFlt1').Value := Trim(ADOQuery1.fieldbyname('DefFlt1').AsString);
            FieldByName('DefFlt2').Value := Trim(ADOQuery1.fieldbyname('DefFlt2').AsString);
            FieldByName('CBzxjs').Value := Trim(ADOQuery1.fieldbyname('CBzxjs').AsString);
            FieldByName('CBzdjs').Value := Trim(ADOQuery1.fieldbyname('CBzdjs').AsString);
            FieldByName('CBfrf').Value := Trim(ADOQuery1.fieldbyname('CBfrf').AsString);
            FieldByName('CBcjf').Value := Trim(ADOQuery1.fieldbyname('CBcjf').AsString);
            Post;
          end;

          next;
        end;
      end;
      jscb();
    end;
    frmZdyAttachCPcbfz.free;
  end;
end;

procedure TfrmZdyAttInputCP_CB.TV1Column3PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  frmZdyYS_sel := TfrmZdyYS_sel.create(self);
  with frmZdyYS_sel do
  begin
    if showmodal = 1 then
    begin

      with CDS1 do
      begin
        Edit;
        FieldByName('CBColor').value := frmZdyYS_sel.Edit1.Text;
        Post;
      end;
    end;
    free;
  end;
end;

procedure TfrmZdyAttInputCP_CB.CYColorBtnClick(Sender: TObject);
begin

  frmZdyYS_sel := TfrmZdyYS_sel.create(self);
  with frmZdyYS_sel do
  begin
    if ShowModal = 1 then
    begin

      CYColor.text := trim(CDS_HZ.fieldbyname('CodeName').AsString);
      CYColorno.text := trim(CDS_HZ.fieldbyname('Colorno').AsString);
//        Self.Order_Sub.FieldByName('SOrddefstr4').Value := Trim(ClientDataSet1.fieldbyname('Note').AsString);
    end;
//    if showmodal = 1 then
//    begin
//      CDS_HZ.First;
//      while not CDS_HZ.Eof do
//      begin
//        if CDS_HZ.fieldbyname('ssel').AsBoolean then
//        begin
////          Self.CDS_Sub.Edit;
////          Self.CDS_Sub.FieldByName('cyys').Value := trim(CDS_HZ.fieldbyname('CodeName').AsString);
//          CDS_Sub.Append;
//          CDS_Sub.FieldByName('cyys').Value := trim(CDS_HZ.fieldbyname('CodeName').AsString);
//          CDS_Sub.post;
//        end;
//        CDS_HZ.Next;
//      end;
//      tv2.Controller.EditingController.ShowEdit();
//      free;
//    end;
  end;
end;

procedure TfrmZdyAttInputCP_CB.ToolButton13Click(Sender: TObject);
begin
  frmZdyCMZ_help := TfrmZdyCMZ_help.create(self);
  with frmZdyCMZ_help do
  begin
//    flag := 'CPCBGY';
    if showmodal = 1 then
    begin
      CDSsub.First;
      while not CDSsub.Eof do
      begin
        if CDSsub.fieldbyname('SizeSpec').AsString <> '' then
        begin
          cds5.Append;
          cds5.FieldByName('DEFstr1').Value := trim(CDSsub.fieldbyname('SizeSpec').AsString);
          cds5.post;
        end;
        CDSsub.Next;
      end;
      tv5.Controller.EditingController.ShowEdit();
      frmZdyCMZ_help.free;
    end;
  end;
end;

procedure TfrmZdyAttInputCP_CB.ToolButton14Click(Sender: TObject);
begin
  if CDS5.IsEmpty then
    exit;
  CDS5.Delete;
  jscb();
end;

end.

