unit U_YSFP_WXDJCI;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, ExtCtrls, StdCtrls, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData,
  cxCalendar, cxButtonEdit, cxTextEdit, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls,
  cxGridCustomView, cxGrid, cxGridBandedTableView, cxGridDBBandedTableView,
  DBClient, ADODB, BtnEdit, cxCheckBox, cxCurrencyEdit, cxDropDownEdit,
  cxContainer;

type
  TfrmYSFP_WXDJCI = class(TForm)
    Panel1: TPanel;
    Label2: TLabel;
    Label3: TLabel;
    Panel2: TPanel;
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    DataSource1: TDataSource;
    Order_PB: TClientDataSet;
    ADOQuery1: TADOQuery;
    ToolBar2: TToolBar;
    TADD: TToolButton;
    Tdel: TToolButton;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn3: TcxGridDBColumn;
    v2PS: TcxGridDBColumn;
    v2MQty: TcxGridDBColumn;
    v2JQty: TcxGridDBColumn;
    v2MMQty: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    VBZ: TcxGridDBColumn;
    v2KP: TcxGridDBColumn;
    v2khConNo: TcxGridDBColumn;
    v2P_CodeName: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    v2PRTColor: TcxGridDBColumn;
    v2Note: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    filltime: TDateTimePicker;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    MaiTou: TMemo;
    Label10: TLabel;
    DHMiao: TMemo;
    Label11: TLabel;
    CINote: TMemo;
    Label12: TLabel;
    v2StyleNo: TcxGridDBColumn;
    v2PRTMF: TcxGridDBColumn;
    v2PRTKZ: TcxGridDBColumn;
    v2HSCode: TcxGridDBColumn;
    ComTaiTou: TBtnEditA;
    KHName: TBtnEditA;
    Label13: TLabel;
    Label14: TLabel;
    GSTel: TBtnEditA;
    GSFax: TBtnEditA;
    ADOQuery2: TADOQuery;
    Label1: TLabel;
    LCDate: TDateTimePicker;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    BankName: TBtnEditA;
    BankNo: TBtnEditA;
    BankDaiMa: TBtnEditA;
    BankAddress: TBtnEditA;
    TKNote: TBtnEditA;
    toplace: TBtnEditA;
    fromplace: TBtnEditA;
    v2ZhenZhiSJFee: TcxGridDBColumn;
    v2YinHuaSJFee: TcxGridDBColumn;
    v2BaoGangFee: TcxGridDBColumn;
    v2ZhiWangZhiBanFee: TcxGridDBColumn;
    Label21: TLabel;
    ZHMiao: TBtnEditA;
    Label22: TLabel;
    HZConNo: TEdit;
    FPNo: TBtnEditA;
    LCNo: TBtnEditA;
    GSAddress: TBtnEditA;
    KHAddress: TBtnEditA;
    Label23: TLabel;
    Label24: TLabel;
    Label25: TLabel;
    TSDate: TDateTimePicker;
    Label26: TLabel;
    SJTSMoney: TcxCurrencyEdit;
    DQTSMoney: TcxCurrencyEdit;
    BGMoney: TcxCurrencyEdit;
    v2PINO: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TADDClick(Sender: TObject);
    procedure v2P_CodeNamePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2Column4PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2PRTColorPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2PRTMFPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2PRTKZPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2Column1PropertiesEditValueChanged(Sender: TObject);
    procedure ComTaiTouBtnClick(Sender: TObject);
    procedure KHNameBtnClick(Sender: TObject);
    procedure fromplaceBtnClick(Sender: TObject);
    procedure toplaceBtnClick(Sender: TObject);
    procedure GSTelBtnClick(Sender: TObject);
    procedure GSFaxBtnClick(Sender: TObject);
    procedure TKNoteBtnClick(Sender: TObject);
    procedure BankNameBtnClick(Sender: TObject);
    procedure BankNoBtnClick(Sender: TObject);
    procedure BankDaiMaBtnClick(Sender: TObject);
    procedure BankAddressBtnClick(Sender: TObject);
    procedure MaiTouDblClick(Sender: TObject);
    procedure DHMiaoDblClick(Sender: TObject);
    procedure CINoteDblClick(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure TdelClick(Sender: TObject);
    procedure ZHMiaoBtnClick(Sender: TObject);
    procedure FPNoBtnClick(Sender: TObject);
    procedure LCNoBtnClick(Sender: TObject);
    procedure GSAddressBtnClick(Sender: TObject);
    procedure KHAddressBtnClick(Sender: TObject);
    procedure v2khConNoPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2StyleNoPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure cxGridDBColumn3PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure cxGridDBColumn6PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure VBZPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2HSCodePropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
  private
    procedure initgrid();
    procedure SaveData();
    { Private declarations }
  public
    FMainid,FFPID,FromID: string;       //关联合同
    { Public declarations }
  end;

var
  frmYSFP_WXDJCI: TfrmYSFP_WXDJCI;

implementation
Uses
    U_DataLink,U_ZDYHelp,U_Fun,U_YSCR_CX, U_ZDYHelpSel,U_YSFP_WXCX;
{$R *.dfm}

procedure TfrmYSFP_WXDJCI.SaveData();
var
  maxno,maxsubNo:String;
begin
  if trim(FFPID)='' then
  begin
    if GetLSNo(ADOQuery1,maxno,'CI','JYOrderFPCI_Main',3,1)=False then
    begin
      Application.MessageBox('取最大号失败!','提示',0);
      Exit;
    end;
  end
  else
  begin
    maxno:=Trim(FFPID);
  end;
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    SQL.Add('select * from JYOrderFPCI_Main where CIID='''+Trim(maxno)+'''');
    Open;
  end;
  with ADOQuery1 do
  begin
    if isempty then
    begin
      Append;
    end
    else begin
      Edit;
    end;
    FieldByName('CIID').Value:=Trim(maxno);
    fieldbyname('Filler').Value:=trim(DName);
    SSetsaveSqlNew(ADOQuery1,'JYOrderFPCI_Main',panel1,2);
    post;
  end;
  with Order_PB do
  begin
    First;
    while not Eof do
    begin
      if Trim(Order_PB.fieldbyname('CISID').AsString)='' then
      begin
        if GetLSNo(ADOQuery1,maxSubno,'CS','JYOrderFPCI_Sub',4,1)=False then
        begin
          Application.MessageBox('取子流水号失败！','提示',0);
          Exit;
        end;
      end else
      begin
        maxSubno:=Trim(Order_PB.fieldbyname('CISID').AsString);
      end;
      with ADOQuery1 do
      begin
        Close;
        SQL.Clear;
        sql.Add('select * from JYOrderFPCI_Sub where CIID='''+Trim(maxno)+'''');
        sql.Add(' and CISID='''+Trim(maxSubno)+'''');
        Open;
      end;
      with ADOQuery1 do
      begin
        if isempty then
        Append
        else
          Edit;
          FieldByName('CIID').Value:=Trim(maxno);
          FieldByName('CISID').Value:=Trim(maxSubno);
          RTSetSaveDataCDS(ADOQuery1,Tv2,Order_PB,'JYOrderFPCI_Sub',0);
          fieldbyname('YFID').Value:=Order_PB.fieldbyname('YFID').AsString;
          fieldbyname('ConYFID').Value:=Order_PB.fieldbyname('ConYFID').AsString;
          fieldbyname('conSubid').Value:=Order_PB.fieldbyname('conSubid').AsString;
          fieldbyname('YFName').Value:=Order_PB.fieldbyname('YFName').AsString;
          fieldbyname('Qty').Value:=Order_PB.Fieldbyname('Qty').AsFloat;
          fieldbyname('Price').Value:=Order_PB.Fieldbyname('Price').AsFloat;
          fieldbyname('JQty').Value:=Order_PB.Fieldbyname('JQty').AsFloat;
          fieldbyname('MQty').Value:=Order_PB.Fieldbyname('MQty').AsFloat;
          fieldbyname('KPMoney').Value:=Order_PB.Fieldbyname('KPMoney').AsFloat;
          fieldbyname('PS').Value:=Order_PB.Fieldbyname('PS').AsFloat;
          fieldbyname('MMQty').Value:=Order_PB.Fieldbyname('MMQty').AsFloat;
          fieldbyname('ZhenZhiSJFee').AsFloat:=Order_PB.fieldbyname('ZhenZhiSJFee').AsFloat;
          fieldbyname('YinHuaSJFee').AsFloat:=Order_PB.fieldbyname('YinHuaSJFee').AsFloat;
          fieldbyname('BaoGangFee').AsFloat:=Order_PB.fieldbyname('BaoGangFee').AsFloat;
          fieldbyname('ZhiWangZhiBanFee').AsFloat:=Order_PB.fieldbyname('ZhiWangZhiBanFee').AsFloat;
          Post;
      end;
      Order_PB.Edit;
      Order_PB.FieldByName('CISID').Value:=Trim(maxSubno);
      Next;
    end;
  end;
  Application.MessageBox('保存成功！','提示',0);
  ModalResult:=1;
end;

procedure TfrmYSFP_WXDJCI.initgrid();
begin
  with ADOQuery1 DO
  begin
    close;
    sql.Clear;
    sql.Add('select * from JYOrderFPCI_Main ');
    sql.add('where CIID='''+Trim(FFPID)+'''');
    open;
  end;
  if ADOQuery1.IsEmpty=False then
  SCSHDataNew(ADOQuery1,panel1,2);
  if FromID='1' then
  FFPID:='';
  with Adoquery1 do
  begin
    close;
    sql.clear;
    sql.add('select * from JYOrderFPCI_Sub ');
    SQL.Add('where CIID='''+trim(FFPID)+'''');
    open;
  end;
  SCreateCDS20(Adoquery1,Order_PB);
  SInitCDSData20(Adoquery1,Order_PB);
end;

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

procedure TfrmYSFP_WXDJCI.FormDestroy(Sender: TObject);
begin
  frmYSFP_WXDJCI:=nil;
end;

procedure TfrmYSFP_WXDJCI.FormShow(Sender: TObject);
begin
  ReadCxGrid('外销CI发票1',Tv2,'财务管理');
  TSDate.DateTime:=now;
  filltime.Datetime:=now;
  LCDate.DateTime:=now;
  LCDate.Checked:=false;
  initgrid();
end;

procedure TfrmYSFP_WXDJCI.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('外销CI发票1',Tv2,'财务管理');
  Close;
end;

procedure TfrmYSFP_WXDJCI.TADDClick(Sender: TObject);
var FHZConNO: string;
begin
  frmYSCR_CX:=TfrmYSCR_CX.create(self);
  with frmYSCR_CX do
  begin
    formid:='1';
    if showmodal=1 then
    begin
      with CDS_HZ do
      begin
        first;
        while not eof do
        begin
          if fieldbyname('Ssel').AsBoolean=true then
          begin
            if FHZConNO='' then
            begin
              if self.HZConNO.Text='' then
              self.HZConNO.Text:=self.HZConNO.Text+CDS_HZ.fieldbyname('ConNoHZ').AsString
              else
              self.HZConNo.Text:=self.HZConNo.Text+','+CDS_HZ.fieldbyname('ConNoHZ').AsString;
              FHZConNO:=CDS_HZ.fieldbyname('ConNoHZ').AsString;
            end
            else
            begin
              if FHZConNo<>CDS_HZ.fieldbyname('ConNoHZ').AsString then
              begin
                FHZConNO:=CDS_HZ.fieldbyname('ConNoHZ').AsString;
                self.HZConNo.Text:=self.HZConNo.Text+','+CDS_HZ.fieldbyname('ConNoHZ').AsString;
              end;
            end;
            if FFPID='' then
            begin
            self.FPNo.Text:=CDS_HZ.fieldbyname('FPNo').AsString;
            self.ComTaiTou.Text:=CDS_HZ.fieldbyname('ComTaiTou').AsString;
            self.KHName.Text:=CDS_HZ.fieldbyname('MKHName').AsString;
            self.GSAddress.Text:=CDS_HZ.fieldbyname('MGSAddress').AsString;
            self.GSTel.Text:=CDS_HZ.fieldbyname('MGSTel').AsString;
            self.GSFax.Text:=CDS_HZ.fieldbyname('GSFax').AsString;
            self.TKNote.Text:=CDS_HZ.fieldbyname('TKNote').AsString;
            self.BankName.Text:=CDS_HZ.fieldbyname('MBankName').AsString;
            self.BankNo.Text:=CDS_HZ.fieldbyname('MBankNo').AsString;
            self.BankDaiMa.Text:=CDS_HZ.fieldbyname('MBankDaiMa').AsString;
            self.BankAddress.Text:=CDS_HZ.fieldbyname('MBankAddress').AsString;
            end;
            with ADOQuery1 do
            begin
              close;
              sql.Clear;
              sql.Add('select * from JYOrderCon_Sub ');
              sql.add('where Subid='''+trim(CDS_HZ.fieldbyname('ConID').AsString)+'''');
              open;
            end;
            with Order_PB do
            begin
            append;
            fieldbyname('KHConNo').AsString:=CDS_HZ.fieldbyname('KHConNo').AsString;
            fieldbyname('StyleNo').Value:=CDS_HZ.fieldbyname('StyleNo').AsString;
            fieldbyname('YFName').AsString:=CDS_HZ.fieldbyname('YFName').AsString;
            fieldbyname('PS').Value:=CDS_HZ.fieldbyname('PS').AsFloat;
            fieldbyname('MQty').Value:=CDS_HZ.fieldbyname('MaoQty').AsFloat;
            fieldbyname('JQty').Value:=CDS_HZ.fieldbyname('JZQty').AsFloat;
            fieldbyname('MMQty').Value:=CDS_HZ.fieldbyname('MQty').AsFloat;
            fieldbyname('Qty').Value:=CDS_HZ.fieldbyname('Qty').AsFloat;
            fieldbyname('KPMoney').Value:=CDS_HZ.fieldbyname('Money').AsFloat;
            fieldbyname('QtyUnit').AsString:=CDS_HZ.fieldbyname('QtyUnit').AsString;
            fieldbyname('Price').asfloat:=CDS_HZ.fieldbyname('Price').asfloat;
            fieldbyname('BZType').AsString:=CDS_HZ.fieldbyname('BZType').AsString;
            fieldbyname('P_CodeName').Value:=CDS_HZ.fieldbyname('MP_CodeName').AsString;
            fieldbyname('P_Spec').AsString:=CDS_HZ.fieldbyname('MP_Spec').AsString;
            fieldbyname('PRTColor').AsString:=CDS_HZ.fieldbyname('PrtColor').AsString;
            fieldbyname('PRTMF').AsString:=CDS_HZ.fieldbyname('PRTMF').AsString;
            fieldbyname('PRTKZ').AsString:=CDS_HZ.fieldbyname('PRTKZ').AsString;
            fieldbyname('ConYFID').AsString:=CDS_HZ.fieldbyname('YFID').AsString;
            fieldbyname('YFID').AsString:=CDS_HZ.fieldbyname('YFID').AsString;
            fieldbyname('conSubid').AsString:=CDS_HZ.fieldbyname('ConID').AsString;
            fieldbyname('PINo').AsString:=CDS_HZ.fieldbyname('ConNoHZ').AsString;
            fieldbyname('ZhenZhiSJFee').AsFloat:=ADOQuery1.fieldbyname('ZhenZhiSJFee').AsFloat;
            fieldbyname('YinHuaSJFee').AsFloat:=ADOQuery1.fieldbyname('YinHuaSJFee').AsFloat;
            fieldbyname('BaoGangFee').AsFloat:=ADOQuery1.fieldbyname('BaoGangFee').AsFloat;
            fieldbyname('ZhiWangZhiBanFee').AsFloat:=ADOQuery1.fieldbyname('ZhiWangZhiBanFee').AsFloat;
            post;
            end;
          end;
          next;
        end;
      end;
    end;
    free;
  end;
end;

procedure TfrmYSFP_WXDJCI.v2P_CodeNamePropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='P_CodeNamefp';
      flagname:='品名';
      if ShowModal=1 then
      begin
        Self.Order_PB.Edit;
        Self.Order_PB.FieldByName('P_CodeName').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSFP_WXDJCI.v2Column4PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='P_Specfp';
      flagname:='规格';
      if ShowModal=1 then
      begin
        Self.Order_PB.Edit;
        Self.Order_PB.FieldByName('P_Spec').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSFP_WXDJCI.v2PRTColorPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PRTColorfp';
      flagname:='颜色';
      if ShowModal=1 then
      begin
        Self.Order_PB.Edit;
        Self.Order_PB.FieldByName('PRTColor').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSFP_WXDJCI.v2PRTMFPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PRTMFfp';
      flagname:='门幅';
      if ShowModal=1 then
      begin
        Self.Order_PB.Edit;
        Self.Order_PB.FieldByName('PRTMF').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSFP_WXDJCI.v2PRTKZPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PRTKZfp';
      flagname:='克重';
      if ShowModal=1 then
      begin
        Self.Order_PB.Edit;
        Self.Order_PB.FieldByName('PRTKZ').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSFP_WXDJCI.v2Column1PropertiesEditValueChanged(
  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 Order_PB do
  begin
    Edit;
    FieldByName(FFieldName).Value:=Trim(mvalue);
  end;
  with order_PB do
  begin
    edit;
    fieldbyname('KPMoney').Value:=fieldbyname('Price').AsFloat*fieldbyname('Qty').AsFloat;
  end;
end;

procedure TfrmYSFP_WXDJCI.ComTaiTouBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='comTaiTouGS';
      flagname:='公司抬头';
      if ShowModal=1 then
      begin
        ComtaiTou.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
          with ADOQuery1 do
          begin
            Close;
            sql.Clear;
            sql.Add('select Top 1* from JYOrderFPCI_Main where ComTaiTou='''+Trim(ClientDataSet1.fieldbyname('ZDYName').AsString)+'''');
            sql.add(' order by FillTime desc');
            Open;
            Self.GSTel.Text:=Trim(ADOQuery1.fieldbyname('GSTel').AsString);
            Self.GSAddress.Text:=Trim(ADOQuery1.fieldbyname('GSAddress').AsString);
            Self.GSFax.Text:=Trim(ADOQuery1.fieldbyname('GSFax').AsString);
          end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSFP_WXDJCI.KHNameBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(Application);
  with frmZDYHelp do
  begin
    flag:='KHName1';
    flagname:='客户';
    if ShowModal=1 then
    begin
      KHName.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      with ADOQuery1 do
          begin
            Close;
            sql.Clear;
            sql.Add('select Top 1* from JYOrderFPCI_Main where KHName='''+Trim(ClientDataSet1.fieldbyname('ZDYName').AsString)+'''');
            sql.add(' order by FillTime desc');
            Open;
            Self.KHAddress.Text:=Trim(ADOQuery1.fieldbyname('KHAddress').AsString);
          end;
    end;
    free;
  end;
end;

procedure TfrmYSFP_WXDJCI.fromplaceBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(Application);
  with frmZDYHelp do
  begin
    flag:='fromplace';
    flagname:='出发地';
    if ShowModal=1 then
    begin
      fromplace.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmYSFP_WXDJCI.toplaceBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(Application);
  with frmZDYHelp do
  begin
    flag:='toplace';
    flagname:='目的地';
    if ShowModal=1 then
    begin
      toplace.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmYSFP_WXDJCI.GSTelBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(Application);
  with frmZDYHelp do
  begin
    flag:='GSTel';
    flagname:='公司电话';
    if ShowModal=1 then
    begin
      GSTel.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmYSFP_WXDJCI.GSFaxBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(Application);
  with frmZDYHelp do
  begin
    flag:='GSFax';
    flagname:='公司传真';
    if ShowModal=1 then
    begin
      GSFax.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmYSFP_WXDJCI.TKNoteBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(Application);
  with frmZDYHelp do
  begin
    flag:='TKNote';
    flagname:='条款信息';
    if ShowModal=1 then
    begin
      TKNote.Text:=trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmYSFP_WXDJCI.BankNameBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='BankNamePI';
      flagname:='银行名称';
      if ShowModal=1 then
      begin
        BankName.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
          with ADOQuery1 do
          begin
            Close;
            sql.Clear;
            sql.Add('select Top 1* from JYOrderFPCI_Main where BankName='''+Trim(ClientDataSet1.fieldbyname('ZDYName').AsString)+'''');
            sql.add(' order by FillTime desc');
            Open;
            Self.BankNo.Text:=Trim(ADOQuery1.fieldbyname('BankNo').AsString);
            Self.BankDaiMa.Text:=Trim(ADOQuery1.fieldbyname('BankDaiMa').AsString);
            Self.BankAddress.Text:=Trim(ADOQuery1.fieldbyname('BankAddress').AsString); 
          end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSFP_WXDJCI.BankNoBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(Application);
  with frmZDYHelp do
  begin
    flag:='BankNoPI';
    flagname:='银行账号';
    if ShowModal=1 then
    begin
      BankNo.Text:=trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmYSFP_WXDJCI.BankDaiMaBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(Application);
  with frmZDYHelp do
  begin
    flag:='BankDaiMaPI';
    flagname:='银行代码';
    if ShowModal=1 then
    begin
      BankDaiMa.Text:=trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmYSFP_WXDJCI.BankAddressBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(Application);
  with frmZDYHelp do
  begin
    flag:='BankAddressPI';
    flagname:='银行地址';
    if ShowModal=1 then
    begin
      BankAddress.Text:=trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmYSFP_WXDJCI.MaiTouDblClick(Sender: TObject);
var
  fsj:string;
  FWZ:Integer;
  i:integer;
begin
  fsj:=Trim(TMemo(Sender).Hint);
  FWZ:=Pos('/',fsj);
  i:=1;
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:=Copy(fsj,1,FWZ-1);
      flagname:=Copy(fsj,FWZ+1,Length(fsj)-fwz);
      if ShowModal=1 then
      begin
        MaiTou.Lines.Clear;
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean=True then
            begin
              MaiTou.Lines.Add(inttostr(i)+'.'+FieldByName('ZDYName').AsString);
              i:=i+1;
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmYSFP_WXDJCI.DHMiaoDblClick(Sender: TObject);
var
  fsj:string;
  FWZ:Integer;
  i:integer;
begin
  fsj:=Trim(TMemo(Sender).Hint);
  FWZ:=Pos('/',fsj);
  i:=1;
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:=Copy(fsj,1,FWZ-1);
      flagname:=Copy(fsj,FWZ+1,Length(fsj)-fwz);
      if ShowModal=1 then
      begin
        DHMiao.Lines.Clear;
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean=True then
            begin
              DHMiao.Lines.Add(inttostr(i)+'.'+FieldByName('ZDYName').AsString);
              i:=i+1;
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmYSFP_WXDJCI.CINoteDblClick(Sender: TObject);
var
  fsj:string;
  FWZ:Integer;
  i:integer;
begin
  fsj:=Trim(TMemo(Sender).Hint);
  FWZ:=Pos('/',fsj);
  i:=1;
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:=Copy(fsj,1,FWZ-1);
      flagname:=Copy(fsj,FWZ+1,Length(fsj)-fwz);
      if ShowModal=1 then
      begin
        CINote.Lines.Clear;
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if FieldByName('SSel').AsBoolean=True then
            begin
              CINote.Lines.Add(inttostr(i)+'.'+FieldByName('ZDYName').AsString);
              i:=i+1;
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmYSFP_WXDJCI.TBSaveClick(Sender: TObject);
begin
  toolbar1.SetFocus;
  if Trim(ComTaiTou.Text)='' then
  begin
    Application.MessageBox('公司抬头不能为空！','提示',0);
    Exit;
  end;
  if Trim(KHName.Text)='' then
  begin
    Application.MessageBox('客户不能为空！','提示',0);
    Exit;
  end;
  SaveData();
end;

procedure TfrmYSFP_WXDJCI.TdelClick(Sender: TObject);
begin
  if order_PB.IsEmpty then exit;
  if order_PB.FieldByName('CISID').AsString<>'' then
  begin
    if application.MessageBox('确定要删除吗','提示',1)=2 then exit;
    with ADOQuery2 do
    begin
      close;
      sql.Clear;
      sql.Add('delete from JYOrderFPCI_Sub ');
      sql.add('where CISID='''+trim(order_PB.FieldByName('CISID').AsString)+'''');
      execsql;
    end;
  end;
  Order_PB.Delete;
end;

procedure TfrmYSFP_WXDJCI.ZHMiaoBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(Application);
  with frmZDYHelp do
  begin
    flag:='ZHMiao';
    flagname:='主货描';
    if ShowModal=1 then
    begin
      ZHMiao.Text:=trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmYSFP_WXDJCI.FPNoBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(Application);
  with frmZDYHelp do
  begin
    flag:='FPNo';
    flagname:='发票号码';
    if ShowModal=1 then
    begin
      FPNo.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmYSFP_WXDJCI.LCNoBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(Application);
  with frmZDYHelp do
  begin
    flag:='LCNo';
    flagname:='LC/No';
    if ShowModal=1 then
    begin
      LCNo.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmYSFP_WXDJCI.GSAddressBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(Application);
  with frmZDYHelp do
  begin
    flag:='GSAddress';
    flagname:='公司地址';
    if ShowModal=1 then
    begin
      GSAddress.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmYSFP_WXDJCI.KHAddressBtnClick(Sender: TObject);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(Application);
  with frmZDYHelp do
  begin
    flag:='KHAddress';
    flagname:='客户地址';
    if ShowModal=1 then
    begin
      KHAddress.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
    end;
    free;
  end;
end;

procedure TfrmYSFP_WXDJCI.v2khConNoPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  frmZDYHelp:=TfrmZDYHelp.Create(Application);
  with frmZDYHelp do
  begin
    flag:='khConNofp';
    flagname:='客户合同号';
    if ShowModal=1 then
    begin
      with Order_PB do
      begin
        edit;
        fieldbyname('KHConNo').AsString:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
    free;
  end;
end;

procedure TfrmYSFP_WXDJCI.v2StyleNoPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='StyleNofp';
      flagname:='款号';
      if ShowModal=1 then
      begin
        Self.Order_PB.Edit;
        Self.Order_PB.FieldByName('StyleNo').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSFP_WXDJCI.cxGridDBColumn3PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='YFNamefp';
      flagname:='费用名称';
      if ShowModal=1 then
      begin
        Self.Order_PB.Edit;
        Self.Order_PB.FieldByName('YFName').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSFP_WXDJCI.cxGridDBColumn6PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='QtyUnitfp';
      flagname:='数量单位';
      if ShowModal=1 then
      begin
        Self.Order_PB.Edit;
        Self.Order_PB.FieldByName('QtyUnit').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSFP_WXDJCI.VBZPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='BZType';
      flagname:='币种';
      if ShowModal=1 then
      begin
        Self.Order_PB.Edit;
        Self.Order_PB.FieldByName('BZType').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSFP_WXDJCI.v2HSCodePropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='HSCode';
      flagname:='H.S.';
      if ShowModal=1 then
      begin
        Self.Order_PB.Edit;
        Self.Order_PB.FieldByName('HSCode').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

end.
