unit U_YSFP_WXCI;

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, cxCalendar,
  cxButtonEdit, cxTextEdit, cxDropDownEdit, Menus, RM_e_Xls;

type
  TfrmYSFP_WXCI = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBDel: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel3: TPanel;
    ToolButton2: TToolButton;
    Label1: TLabel;
    fromplace: TEdit;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    Label3: TLabel;
    KHName: TEdit;
    Label2: TLabel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    TADD: TToolButton;
    Label4: TLabel;
    FPNo: TEdit;
    Label5: TLabel;
    HZConNo: TEdit;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    TUpdate: TToolButton;
    TPrint: TToolButton;
    Panel2: TPanel;
    ComboBox1: TComboBox;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2FPNo: TcxGridDBColumn;
    v2HZConNo: TcxGridDBColumn;
    v2SumKPMoney: TcxGridDBColumn;
    v2Note: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    v2KHName: TcxGridDBColumn;
    v2filltime: TcxGridDBColumn;
    Label6: TLabel;
    ToPlace: TEdit;
    TSel: TToolButton;
    TFZ: TToolButton;
    v2ComTaiTou: TcxGridDBColumn;
    v2fromplace: TcxGridDBColumn;
    v2ToPlace: TcxGridDBColumn;
    RMXLSExport1: TRMXLSExport;
    RMDB_Main: TRMDBDataSet;
    RMCD: TRMGridReport;
    Order_Print: TClientDataSet;
    ADOQuery1: TADOQuery;
    cxSplitter1: TcxSplitter;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    v2PS: TcxGridDBColumn;
    v2MQty: TcxGridDBColumn;
    v2JQty: TcxGridDBColumn;
    v2MMQty: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridDBColumn16: TcxGridDBColumn;
    v2ZhenZhiSJFee: TcxGridDBColumn;
    v2YinHuaSJFee: TcxGridDBColumn;
    v2BaoGangFee: TcxGridDBColumn;
    v2ZhiWangZhiBanFee: TcxGridDBColumn;
    v2HSCode: TcxGridDBColumn;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    ADOQuery2: TADOQuery;
    v2ZHMiao: TcxGridDBColumn;
    CDS_WXPT: TClientDataSet;
    V1PINo: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure KHNameChange(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure cxGridDBColumn8PropertiesEditValueChanged(Sender: TObject);
    procedure cxGridDBColumn5PropertiesEditValueChanged(Sender: TObject);
    procedure cxGridDBColumn1PropertiesEditValueChanged(Sender: TObject);
    procedure cxGridDBColumn3PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure cxGridDBColumn6PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2Column3PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ToolButton1Click(Sender: TObject);
    procedure v2Column7PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v2Column2PropertiesEditValueChanged(Sender: TObject);
    procedure v2PSPropertiesEditValueChanged(Sender: TObject);
    procedure v2BatchNoPropertiesEditValueChanged(Sender: TObject);
    procedure v2PayMentPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure FPNoChange(Sender: TObject);
    procedure VKPNOPropertiesEditValueChanged(Sender: TObject);
    procedure v2KPDMNoPropertiesEditValueChanged(Sender: TObject);
    procedure v2ZFTTPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure cxGridDBColumn3PropertiesEditValueChanged(Sender: TObject);
    procedure v2P_SpecPropertiesEditValueChanged(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure v2SselPropertiesChange(Sender: TObject);
    procedure TADDClick(Sender: TObject);
    procedure TUpdateClick(Sender: TObject);
    procedure TSelClick(Sender: TObject);
    procedure TFZClick(Sender: TObject);
    procedure TPrintClick(Sender: TObject);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure Tv2CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
  private
    { Private declarations }

    procedure InitGridHZ();
    procedure InitGrid();
    function  SaveData():Boolean;
    procedure WXFPData();
  public
    { Public declarations }
    RKFlag,FCYID:String;

  end;

var
  frmYSFP_WXCI: TfrmYSFP_WXCI;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp, U_ProductOrderList, U_ProductOrderNewList,U_YSFP_WXDJCI,
  U_ZdyAttachment;

{$R *.dfm}
procedure TfrmYSFP_WXCI.WXFPData();
var
  j,z,i,x:Integer;
  FSumQty,FSumMoney,ZQty,ZMoney: Double;
  FGangNo,FHZ,FKHConNO:String;
begin
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.add('select A.*,B.*, ');
    sql.add('SumPS=(Select Sum(C.ps) from JYorderFPCI_Sub C where C.CIID=A.CIID)');
    sql.add(',DJ=(select Sum(R.RLMoney) from JYOrderYSK R inner join JYOrderCon_Sub C on R.Mainid=C.Mainid where C.Subid=B.ConSubid and R.FeeName=''定金'') ');
    sql.add('from JYOrderFPCI_Main A ');
    sql.add('inner join JYOrderFPCI_Sub B on A.CIID=B.CIID ');
    sql.add('where A.CIID='''+trim(CDS_HZ.fieldbyname('CIID').AsString)+''' ');
    sql.add('order by A.FPNo,B.KHConNo,B.StyleNo,B.P_CodeName,B.P_Spec,B.PRTMF,B.PRTKZ');
    Open;
  end;
  SCreateCDS20(ADOQueryCmd,CDS_WXPT);
  SInitCDSData20(ADOQueryCmd,CDS_WXPT);
  with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('select ComTaiTou=Cast('''' as varchar(100)),GSAddress=Cast('''' as varchar(500)),BankNo=Cast('''' as varchar(80)),KHName=Cast('''' as varchar(100)),');
    sql.Add(' KHAddress=Cast('''' as varchar(500)),filltime=Cast(NULL as datetime),fromplace=Cast('''' as varchar(300)),');
    sql.add(' LCNo=Cast('''' as varchar(50)),toplace=Cast('''' as varchar(300)),LCDate=Cast(NULL as datetime),');
    sql.add(' ZHMiao=Cast('''' as varchar(50)),QtyUnit=Cast('''' as varchar(50)),MaiTou=Cast('''' as varchar(500)),');
    sql.add(' TKNote=Cast('''' as varchar(90)),BZType=Cast('''' as varchar(50)),FPNo=Cast('''' as varchar(50)),');
    sql.add(' KHConNO=Cast('''' as varchar(500)),PRTColor=Cast('''' as varchar(50)),PINo=cast('''' as varchar(70)),');
    sql.Add(' Qty=Cast(0 as decimal(18,2)),Price=Cast(0 as decimal(18,2)),KPMoney=Cast('''' as varchar(60)),');
    sql.Add(' SumPS=Cast(0 as decimal(18,2)),ZQty=Cast(0 as decimal(18,2)),ZMoney=Cast(0 as decimal(18,2))');
    Open;
  end;
  SCreateCDS20(ADOQueryCmd,Order_Print);
  SInitCDSData20(ADOQueryCmd,Order_Print);
  if Order_Print.IsEmpty=False then
  begin
    Order_Print.Delete;
  end;
  j:=0;z:=0;i:=0;x:=0;FGangNo:='';
  FSumQty:=0;FSumMoney:=0;
  CDS_WXPT.DisableControls;
  Order_Print.DisableControls;
  with CDS_WXPT do
  begin
    First;
    while not Eof do
    begin
      with Order_Print do
      begin
        if Order_Print.IsEmpty then
        begin
          Order_Print.Append;
          Order_Print.FieldByName('ComTaiTou').Value:=CDS_WXPT.fieldbyname('ComTaiTou').Value;
          Order_Print.FieldByName('GSAddress').Value:=CDS_WXPT.fieldbyname('GSAddress').Value;
          Order_Print.FieldByName('BankNo').Value:=CDS_WXPT.fieldbyname('BankNo').Value;
          Order_Print.FieldByName('KHName').Value:=CDS_WXPT.fieldbyname('KHName').Value;
          Order_Print.FieldByName('KHAddress').Value:=CDS_WXPT.fieldbyname('KHAddress').Value;
          Order_Print.FieldByName('khConNo').Value:='PO NO: '+trim(CDS_WXPT.fieldbyname('khConNO').ASstring)+', '+'STYLES: '+trim(CDS_WXPT.fieldbyname('StyleNo').ASstring)+#13
                                                     +'INVOICE NO: '+trim(CDS_WXPT.fieldbyname('PINo').ASstring)+#13
                                                     +trim(CDS_WXPT.fieldbyname('P_CodeName').ASstring)+' '+trim(CDS_WXPT.fieldbyname('P_Spec').ASstring)+#13
                                                     +'WEIGHT: '+trim(CDS_WXPT.fieldbyname('PRTKZ').ASstring)+'WIDTH: '+trim(CDS_WXPT.fieldbyname('PRTMF').ASstring);
          Order_Print.FieldByName('filltime').Value:=CDS_WXPT.fieldbyname('filltime').Value;
          Order_Print.FieldByName('fromplace').Value:=CDS_WXPT.fieldbyname('fromplace').Value;
          Order_Print.FieldByName('LCNo').Value:=CDS_WXPT.fieldbyname('LCNo').Value;
          Order_Print.FieldByName('toplace').Value:=CDS_WXPT.fieldbyname('toplace').Value;
          Order_Print.FieldByName('LCDate').Value:=CDS_WXPT.fieldbyname('LCDate').Value;
          Order_Print.FieldByName('ZHMiao').Value:=CDS_WXPT.fieldbyname('ZHMiao').Value;
          Order_Print.FieldByName('QtyUnit').Value:=CDS_WXPT.fieldbyname('QtyUnit').Value;
          Order_Print.FieldByName('MaiTou').Value:=CDS_WXPT.fieldbyname('MaiTou').Value;
          Order_Print.FieldByName('TKNote').Value:=CDS_WXPT.fieldbyname('TKNote').Value;
          Order_Print.FieldByName('BZType').Value:=CDS_WXPT.fieldbyname('BZType').AsString;
          Order_Print.FieldByName('PRTColor').Value:=CDS_WXPT.fieldbyname('PRTColor').AsString;
          Order_Print.FieldByName('FPNo').Value:=CDS_WXPT.fieldbyname('FPNo').AsString;

          Order_Print.FieldByName('Qty').Value:=CDS_WXPT.fieldbyname('Qty').AsFloat;
          Order_Print.FieldByName('Price').Value:=CDS_WXPT.fieldbyname('Price').AsFloat;
          Order_Print.FieldByName('KPMoney').Value:=floattostr(CDS_WXPT.fieldbyname('KPMoney').AsFloat);
          Order_Print.FieldByName('SumPS').Value:=CDS_WXPT.fieldbyname('SumPS').AsFloat;
          FSumQty:=CDS_WXPT.fieldbyname('Qty').AsFloat;
          FSumMoney:=CDS_WXPT.fieldbyname('KPMoney').AsFloat;
          ZQty:=CDS_WXPT.fieldbyname('Qty').AsFloat;
          ZMoney:=CDS_WXPT.fieldbyname('KPMoney').AsFloat;
          Order_Print.FieldByName('ZQty').Value:=ZQty;
          Order_Print.FieldByName('ZMoney').Value:=ZMoney;
          Order_Print.Post;
          FKHConNO:=trim(CDS_WXPT.fieldbyname('KHConNo').AsString);
          FGangNo:=trim(CDS_WXPT.fieldbyname('FPNo').AsString)+trim(CDS_WXPT.fieldbyname('KHConNo').AsString)+trim(CDS_WXPT.fieldbyname('P_Spec').AsString)
              +trim(CDS_WXPT.fieldbyname('StyleNo').AsString)+trim(CDS_WXPT.fieldbyname('P_CodeName').AsString)+trim(CDS_WXPT.fieldbyname('PRTMF').AsString);
        end
        else
        begin
          if FGangNo<>trim(CDS_WXPT.fieldbyname('FPNo').AsString)+trim(CDS_WXPT.fieldbyname('KHConNo').AsString)+trim(CDS_WXPT.fieldbyname('P_Spec').AsString)
              +trim(CDS_WXPT.fieldbyname('StyleNo').AsString)+trim(CDS_WXPT.fieldbyname('P_CodeName').AsString)+trim(CDS_WXPT.fieldbyname('PRTMF').AsString) then
          begin
            Order_Print.Append;
            Order_Print.FieldByName('ComTaiTou').Value:=CDS_WXPT.fieldbyname('ComTaiTou').Value;
            Order_Print.FieldByName('GSAddress').Value:=CDS_WXPT.fieldbyname('GSAddress').Value;
            Order_Print.FieldByName('BankNo').Value:=CDS_WXPT.fieldbyname('BankNo').Value;
            Order_Print.FieldByName('KHName').Value:=CDS_WXPT.fieldbyname('KHName').Value;
            Order_Print.FieldByName('KHAddress').Value:=CDS_WXPT.fieldbyname('KHAddress').Value;
            Order_Print.FieldByName('khConNo').Value:='TOTAL PO NO '+trim(FKHConNO);
            Order_Print.FieldByName('filltime').Value:=CDS_WXPT.fieldbyname('filltime').Value;
            Order_Print.FieldByName('fromplace').Value:=CDS_WXPT.fieldbyname('fromplace').Value;
            Order_Print.FieldByName('LCNo').Value:=CDS_WXPT.fieldbyname('LCNo').Value;
            Order_Print.FieldByName('toplace').Value:=CDS_WXPT.fieldbyname('toplace').Value;
            Order_Print.FieldByName('FPNo').Value:=CDS_WXPT.fieldbyname('FPNo').AsString;
            Order_Print.FieldByName('LCDate').Value:=CDS_WXPT.fieldbyname('LCDate').Value;
            Order_Print.FieldByName('ZHMiao').Value:=CDS_WXPT.fieldbyname('ZHMiao').Value;
            Order_Print.FieldByName('QtyUnit').Value:=CDS_WXPT.fieldbyname('QtyUnit').Value;
            Order_Print.FieldByName('MaiTou').Value:=CDS_WXPT.fieldbyname('MaiTou').Value;
            Order_Print.FieldByName('TKNote').Value:=CDS_WXPT.fieldbyname('TKNote').Value;
            Order_Print.FieldByName('BZType').Value:=CDS_WXPT.fieldbyname('BZType').Value;
            Order_Print.FieldByName('PRTColor').Value:='';
            Order_Print.FieldByName('Qty').AsFloat:=0;
            Order_Print.FieldByName('Price').Value:=FSumQty;
            Order_Print.FieldByName('KPMoney').Value:=CDS_WXPT.fieldbyname('QtyUnit').AsString;
            Order_Print.FieldByName('SumPS').Value:=CDS_WXPT.fieldbyname('SumPS').AsFloat;
            Order_Print.Post;

            Order_Print.Append;
            Order_Print.FieldByName('ComTaiTou').Value:=CDS_WXPT.fieldbyname('ComTaiTou').Value;
            Order_Print.FieldByName('GSAddress').Value:=CDS_WXPT.fieldbyname('GSAddress').Value;
            Order_Print.FieldByName('BankNo').Value:=CDS_WXPT.fieldbyname('BankNo').Value;
            Order_Print.FieldByName('KHName').Value:=CDS_WXPT.fieldbyname('KHName').Value;
            Order_Print.FieldByName('KHAddress').Value:=CDS_WXPT.fieldbyname('KHAddress').Value;
            Order_Print.FieldByName('khConNo').Value:='TOTAL AMOUNT PO NO '+trim(FKHConNO);
            Order_Print.FieldByName('filltime').Value:=CDS_WXPT.fieldbyname('filltime').Value;
            Order_Print.FieldByName('fromplace').Value:=CDS_WXPT.fieldbyname('fromplace').Value;
            Order_Print.FieldByName('LCNo').Value:=CDS_WXPT.fieldbyname('LCNo').Value;
            Order_Print.FieldByName('toplace').Value:=CDS_WXPT.fieldbyname('toplace').Value;
            Order_Print.FieldByName('LCDate').Value:=CDS_WXPT.fieldbyname('LCDate').Value;
            Order_Print.FieldByName('ZHMiao').Value:=CDS_WXPT.fieldbyname('ZHMiao').Value;
            Order_Print.FieldByName('QtyUnit').Value:=CDS_WXPT.fieldbyname('QtyUnit').Value;
            Order_Print.FieldByName('MaiTou').Value:=CDS_WXPT.fieldbyname('MaiTou').Value;
            Order_Print.FieldByName('TKNote').Value:=CDS_WXPT.fieldbyname('TKNote').Value;
            Order_Print.FieldByName('BZType').Value:=CDS_WXPT.fieldbyname('BZType').Value;
            Order_Print.FieldByName('PRTColor').Value:='';
            Order_Print.FieldByName('Qty').AsFloat:=0;
            Order_Print.FieldByName('Price').Value:=FSumMoney;
            Order_Print.FieldByName('KPMoney').Value:=CDS_WXPT.fieldbyname('BZType').AsString;
            Order_Print.FieldByName('SumPS').Value:=CDS_WXPT.fieldbyname('SumPS').AsFloat;
            Order_Print.Post;

            Order_Print.Append;
            Order_Print.FieldByName('ComTaiTou').Value:=CDS_WXPT.fieldbyname('ComTaiTou').Value;
            Order_Print.FieldByName('GSAddress').Value:=CDS_WXPT.fieldbyname('GSAddress').Value;
            Order_Print.FieldByName('BankNo').Value:=CDS_WXPT.fieldbyname('BankNo').Value;
            Order_Print.FieldByName('KHName').Value:=CDS_WXPT.fieldbyname('KHName').Value;
            Order_Print.FieldByName('KHAddress').Value:=CDS_WXPT.fieldbyname('KHAddress').Value;
            Order_Print.FieldByName('khConNo').Value:='PO NO: '+CDS_WXPT.fieldbyname('khConNO').ASstring+', '+'STYLES: '+CDS_WXPT.fieldbyname('StyleNo').ASstring+#13
                                                   +'INVOICE NO: '+trim(CDS_WXPT.fieldbyname('PINo').ASstring)+#13
                                                   +CDS_WXPT.fieldbyname('P_CodeName').ASstring+' '+CDS_WXPT.fieldbyname('P_Spec').ASstring+#13
                                                   +'WEIGHT: '+CDS_WXPT.fieldbyname('PRTKZ').ASstring+'WIDTH: '+CDS_WXPT.fieldbyname('PRTMF').ASstring;
            Order_Print.FieldByName('filltime').Value:=CDS_WXPT.fieldbyname('filltime').Value;
            Order_Print.FieldByName('fromplace').Value:=CDS_WXPT.fieldbyname('fromplace').Value;
            Order_Print.FieldByName('LCNo').Value:=CDS_WXPT.fieldbyname('LCNo').Value;
            Order_Print.FieldByName('toplace').Value:=CDS_WXPT.fieldbyname('toplace').Value;
            Order_Print.FieldByName('LCDate').Value:=CDS_WXPT.fieldbyname('LCDate').Value;
            Order_Print.FieldByName('ZHMiao').Value:=CDS_WXPT.fieldbyname('ZHMiao').Value;
            Order_Print.FieldByName('QtyUnit').Value:=CDS_WXPT.fieldbyname('QtyUnit').Value;
            Order_Print.FieldByName('MaiTou').Value:=CDS_WXPT.fieldbyname('MaiTou').Value;
            Order_Print.FieldByName('TKNote').Value:=CDS_WXPT.fieldbyname('TKNote').Value;
            Order_Print.FieldByName('BZType').Value:=CDS_WXPT.fieldbyname('BZType').Value;
            Order_Print.FieldByName('PRTColor').Value:=CDS_WXPT.fieldbyname('PRTColor').Value;
            Order_Print.FieldByName('Qty').Value:=CDS_WXPT.fieldbyname('Qty').AsFloat;
            Order_Print.FieldByName('Price').Value:=CDS_WXPT.fieldbyname('Price').AsFloat;
            Order_Print.FieldByName('KPMoney').Value:=floattostr(CDS_WXPT.fieldbyname('KPMoney').AsFloat);
            Order_Print.FieldByName('SumPS').Value:=CDS_WXPT.fieldbyname('SumPS').AsFloat;
            FSumQty:=CDS_WXPT.fieldbyname('Qty').AsFloat;
            FSumMoney:=CDS_WXPT.fieldbyname('KPMoney').AsFloat;
            ZQty:=ZQty+CDS_WXPT.fieldbyname('Qty').AsFloat;
            ZMoney:=ZMoney+CDS_WXPT.fieldbyname('KPMoney').AsFloat;
            Order_Print.FieldByName('ZQty').Value:=ZQty;
            Order_Print.FieldByName('ZMoney').Value:=ZMoney;
            Order_Print.Post;
            i:=0;
            j:=0;
            FKHConNO:=trim(CDS_WXPT.fieldbyname('KHConNo').AsString);
            FGangNo:=trim(CDS_WXPT.fieldbyname('FPNo').AsString)+trim(CDS_WXPT.fieldbyname('KHConNo').AsString)+trim(CDS_WXPT.fieldbyname('P_Spec').AsString)
                +trim(CDS_WXPT.fieldbyname('StyleNo').AsString)+trim(CDS_WXPT.fieldbyname('P_CodeName').AsString)+trim(CDS_WXPT.fieldbyname('PRTMF').AsString);
          end
          else
          begin
            Order_Print.Append;
            Order_Print.FieldByName('ComTaiTou').Value:=CDS_WXPT.fieldbyname('ComTaiTou').Value;
            Order_Print.FieldByName('GSAddress').Value:=CDS_WXPT.fieldbyname('GSAddress').Value;
            Order_Print.FieldByName('BankNo').Value:=CDS_WXPT.fieldbyname('BankNo').Value;
            Order_Print.FieldByName('KHName').Value:=CDS_WXPT.fieldbyname('KHName').Value;
            Order_Print.FieldByName('KHAddress').Value:=CDS_WXPT.fieldbyname('KHAddress').Value;
            Order_Print.FieldByName('khConNo').Value:='PO NO: '+CDS_WXPT.fieldbyname('khConNO').ASstring+', '+'STYLES: '+CDS_WXPT.fieldbyname('StyleNo').ASstring+#13
                                                       +'INVOICE NO: '+trim(CDS_WXPT.fieldbyname('PINo').ASstring)+#13
                                                       +CDS_WXPT.fieldbyname('P_CodeName').ASstring+' '+CDS_WXPT.fieldbyname('P_Spec').ASstring+#13
                                                       +'WEIGHT: '+CDS_WXPT.fieldbyname('PRTKZ').ASstring+'WIDTH: '+CDS_WXPT.fieldbyname('PRTMF').ASstring;
            Order_Print.FieldByName('filltime').Value:=CDS_WXPT.fieldbyname('filltime').Value;
            Order_Print.FieldByName('FPNo').Value:=CDS_WXPT.fieldbyname('FPNo').AsString;
            Order_Print.FieldByName('fromplace').Value:=CDS_WXPT.fieldbyname('fromplace').Value;
            Order_Print.FieldByName('LCNo').Value:=CDS_WXPT.fieldbyname('LCNo').Value;
            Order_Print.FieldByName('toplace').Value:=CDS_WXPT.fieldbyname('toplace').Value;
            Order_Print.FieldByName('LCDate').Value:=CDS_WXPT.fieldbyname('LCDate').Value;
            Order_Print.FieldByName('ZHMiao').Value:=CDS_WXPT.fieldbyname('ZHMiao').Value;
            Order_Print.FieldByName('QtyUnit').Value:=CDS_WXPT.fieldbyname('QtyUnit').Value;
            Order_Print.FieldByName('MaiTou').Value:=CDS_WXPT.fieldbyname('MaiTou').Value;
            Order_Print.FieldByName('TKNote').Value:=CDS_WXPT.fieldbyname('TKNote').Value;
            Order_Print.FieldByName('BZType').Value:=CDS_WXPT.fieldbyname('BZType').Value;
            Order_Print.FieldByName('PRTColor').Value:=CDS_WXPT.fieldbyname('PRTColor').Value;
            Order_Print.FieldByName('Qty').Value:=CDS_WXPT.fieldbyname('Qty').AsFloat;
            Order_Print.FieldByName('Price').Value:=CDS_WXPT.fieldbyname('Price').AsFloat;
            Order_Print.FieldByName('KPMoney').Value:=CDS_WXPT.fieldbyname('KPMoney').Value;
            Order_Print.FieldByName('SumPS').Value:=CDS_WXPT.fieldbyname('SumPS').AsFloat;
            FSumQty:=FSumQty+CDS_WXPT.fieldbyname('Qty').AsFloat;
            FSumMoney:=FSumMoney+CDS_WXPT.fieldbyname('KPMoney').AsFloat;
            ZQty:=ZQty+CDS_WXPT.fieldbyname('Qty').AsFloat;
            ZMoney:=ZMoney+CDS_WXPT.fieldbyname('KPMoney').AsFloat;
            Order_Print.FieldByName('ZQty').Value:=ZQty;
            Order_Print.FieldByName('ZMoney').Value:=ZMoney;
            Order_Print.Post;
            i:=0;
            j:=0;
            FKHConNO:=trim(CDS_WXPT.fieldbyname('KHConNo').AsString);
          end;
        end
      end;
      Next;
    end;
  end;
  Order_Print.Append;
  Order_Print.FieldByName('ComTaiTou').Value:=CDS_WXPT.fieldbyname('ComTaiTou').Value;
  Order_Print.FieldByName('GSAddress').Value:=CDS_WXPT.fieldbyname('GSAddress').Value;
  Order_Print.FieldByName('BankNo').Value:=CDS_WXPT.fieldbyname('BankNo').Value;
  Order_Print.FieldByName('KHName').Value:=CDS_WXPT.fieldbyname('KHName').Value;
  Order_Print.FieldByName('KHAddress').Value:=CDS_WXPT.fieldbyname('KHAddress').Value;
  Order_Print.FieldByName('khConNo').Value:='TOTAL PO NO '+CDS_WXPT.fieldbyname('KHConNo').AsString;
  Order_Print.FieldByName('filltime').Value:=CDS_WXPT.fieldbyname('filltime').Value;
  Order_Print.FieldByName('fromplace').Value:=CDS_WXPT.fieldbyname('fromplace').Value;
  Order_Print.FieldByName('LCNo').Value:=CDS_WXPT.fieldbyname('LCNo').Value;
  Order_Print.FieldByName('toplace').Value:=CDS_WXPT.fieldbyname('toplace').Value;
  Order_Print.FieldByName('FPNo').Value:=CDS_WXPT.fieldbyname('FPNo').AsString;
  Order_Print.FieldByName('LCDate').Value:=CDS_WXPT.fieldbyname('LCDate').Value;
  Order_Print.FieldByName('ZHMiao').Value:=CDS_WXPT.fieldbyname('ZHMiao').Value;
  Order_Print.FieldByName('QtyUnit').Value:=CDS_WXPT.fieldbyname('QtyUnit').Value;
  Order_Print.FieldByName('MaiTou').Value:=CDS_WXPT.fieldbyname('MaiTou').Value;
  Order_Print.FieldByName('TKNote').Value:=CDS_WXPT.fieldbyname('TKNote').Value;
  Order_Print.FieldByName('BZType').Value:=CDS_WXPT.fieldbyname('BZType').Value;
  Order_Print.FieldByName('PRTColor').Value:='';
  Order_Print.FieldByName('Qty').AsFloat:=0;
  Order_Print.FieldByName('Price').Value:=FSumQty;
  Order_Print.FieldByName('KPMoney').Value:=CDS_WXPT.fieldbyname('QtyUnit').AsString;
  Order_Print.FieldByName('SumPS').Value:=CDS_WXPT.fieldbyname('SumPS').AsFloat;
  Order_Print.FieldByName('ZQty').Value:=ZQty;
  Order_Print.FieldByName('ZMoney').Value:=ZMoney;
  Order_Print.Post;

  Order_Print.Append;
  Order_Print.FieldByName('ComTaiTou').Value:=CDS_WXPT.fieldbyname('ComTaiTou').Value;
  Order_Print.FieldByName('GSAddress').Value:=CDS_WXPT.fieldbyname('GSAddress').Value;
  Order_Print.FieldByName('BankNo').Value:=CDS_WXPT.fieldbyname('BankNo').Value;
  Order_Print.FieldByName('KHName').Value:=CDS_WXPT.fieldbyname('KHName').Value;
  Order_Print.FieldByName('KHAddress').Value:=CDS_WXPT.fieldbyname('KHAddress').Value;
  Order_Print.FieldByName('khConNo').Value:='TOTAL AMOUNT PO NO '+CDS_WXPT.fieldbyname('KHConNo').AsString;
  Order_Print.FieldByName('filltime').Value:=CDS_WXPT.fieldbyname('filltime').Value;
  Order_Print.FieldByName('fromplace').Value:=CDS_WXPT.fieldbyname('fromplace').Value;
  Order_Print.FieldByName('LCNo').Value:=CDS_WXPT.fieldbyname('LCNo').Value;
  Order_Print.FieldByName('toplace').Value:=CDS_WXPT.fieldbyname('toplace').Value;
  Order_Print.FieldByName('LCDate').Value:=CDS_WXPT.fieldbyname('LCDate').Value;
  Order_Print.FieldByName('ZHMiao').Value:=CDS_WXPT.fieldbyname('ZHMiao').Value;
  Order_Print.FieldByName('QtyUnit').Value:=CDS_WXPT.fieldbyname('QtyUnit').Value;
  Order_Print.FieldByName('MaiTou').Value:=CDS_WXPT.fieldbyname('MaiTou').Value;
  Order_Print.FieldByName('TKNote').Value:=CDS_WXPT.fieldbyname('TKNote').Value;
  Order_Print.FieldByName('BZType').Value:=CDS_WXPT.fieldbyname('BZType').Value;
  Order_Print.FieldByName('PRTColor').Value:='';
  Order_Print.FieldByName('Qty').AsFloat:=0;
  Order_Print.FieldByName('Price').Value:=FSumMoney;
  Order_Print.FieldByName('KPMoney').Value:=CDS_WXPT.fieldbyname('BZType').AsString;
  Order_Print.FieldByName('SumPS').Value:=CDS_WXPT.fieldbyname('SumPS').AsFloat;
  Order_Print.FieldByName('ZQty').Value:=ZQty;
  Order_Print.FieldByName('ZMoney').Value:=ZMoney;
  Order_Print.Post;
  CDS_WXPT.EnableControls;
  Order_Print.EnableControls;
end;

procedure TfrmYSFP_WXCI.InitGrid();
begin
  Toolbar1.SetFocus;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select A.*,SumKPMoney=(select Sum(KPMoney) from JYOrderFPCI_Sub B where B.CIID=A.CIID)');
      sql.Add(' from JYOrderFPCI_Main A');
      sql.Add(' where A.filltime>='''+Trim(FormatDateTime('yyyy-MM-dd',begdate.DateTime))+''' ');
      sql.add(' and A.filltime<'''+Trim(FormatDateTime('yyyy-MM-dd',Enddate.DateTime+1))+''' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmYSFP_WXCI.InitGridHZ();
begin
end;

procedure TfrmYSFP_WXCI.FormDestroy(Sender: TObject);
begin
  frmYSFP_WXCI:=nil;
end;

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

procedure TfrmYSFP_WXCI.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('应收款发票1',Tv2,'财务管理');
  
  Close;
end;
procedure TfrmYSFP_WXCI.TBDelClick(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then Exit;
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  if Trim(CDS_HZ.fieldbyname('CIID').AsString)<>'' then
  begin
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('delete JYOrderFPCI_Main where CIID='''+Trim(CDS_HZ.fieldbyname('CIID').AsString)+'''');
      ExecSQL;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('delete JYOrderFPCI_Sub where CIID='''+Trim(CDS_HZ.fieldbyname('CIID').AsString)+'''');
      ExecSQL;
    end;
  end;
  initGrid();
end;

procedure TfrmYSFP_WXCI.FormShow(Sender: TObject);
var
  fsj:string;
begin
  ReadCxGrid('应收款发票1',Tv2,'财务管理');
  Enddate.DateTime:=SGetServerDate(ADOQueryTemp);
  begdate.DateTime:=Enddate.DateTime-7;
  InitGrid();
  RMCD.CanExport:=true;
end;

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

procedure TfrmYSFP_WXCI.ToolButton2Click(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel3,1,2));
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  end;
end;

procedure TfrmYSFP_WXCI.KHNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmYSFP_WXCI.Button2Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then Exit;
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  if Trim(CDS_HZ.fieldbyname('SubID').AsString)<>'' then
  begin
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('delete YCL_SG_HZ where SubID='''+Trim(CDS_HZ.fieldbyname('SubID').AsString)+'''');
      ExecSQL;
    end;
  end;
  CDS_HZ.Delete;
end;

function TfrmYSFP_WXCI.SaveData():Boolean;
var
  maxId,CRID:String;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    if GetLSNo(ADOQueryCmd,maxId,'YF','YF_Money_CR',4,1)=False then
    begin
      Result:=False;
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取最大号失败！','提示',0);
      Exit;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from YF_Money_KC where FactoryName='''+Trim(CDS_HZ.fieldbyname('FactoryName').AsString)+'''');
      Open;
    end;
    if ADOQueryCmd.IsEmpty=False then
    begin
      CRID:=ADOQueryCmd.fieldbyname('CRID').AsString;
    end else
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('Update YF_Money_CRID set CRID=CRID+1');
        sql.Add('select * from YF_Money_CRID ');
        Open;
      end;
      CRID:=ADOQueryCmd.fieldbyname('CRID').AsString;
      with ADOQueryCmd do
      begin
        Close;
        SQL.Clear;
        sql.Add('select * from YF_Money_KC where 1<>1');
        Open;
      end;
      with ADOQueryCmd do
      begin
        Append;
        FieldByName('CRID').Value:=StrToInt(CRID);
        FieldByName('FactoryNo').Value:=Trim(CDS_HZ.fieldbyname('FactoryNo').AsString);
        FieldByName('FactoryName').Value:=Trim(CDS_HZ.fieldbyname('FactoryName').AsString);
        FieldByName('ZdyStr1').Value:='应收收';
        Post;
      end;
    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from YF_Money_CR where 1<>1');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('YFID').Value:=Trim(maxId);
      FieldByName('CRID').Value:=StrToInt(CRID);
      //SSetSaveDataCDSNew(ADOQueryCmd,Tv2,CDS_HZ,'YF_Money_CR',3);
      FieldByName('Filler').Value:=Trim(DName);
      FieldByName('CRType').Value:='应收款发票登记';
      FieldByName('CRFlag').Value:='应收收';
      FieldByName('QtyFlag').Value:=1;
      FieldByName('FactoryNo').Value:=Trim(CDS_HZ.fieldbyname('FactoryNo').AsString);
      FieldByName('FactoryName').Value:=Trim(CDS_HZ.fieldbyname('FactoryName').AsString);
      FieldByName('CRTime').Value:=SGetServerDate(ADOQueryTemp);
      fieldbyname('HuiLV').Value:=1;
      Post;
    end;
    with CDS_HZ do
    begin
      Edit;
      FieldByName('YFId').Value:=Trim(maxId);
      FieldByName('CRID').Value:=StrToInt(CRID);
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=True;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('增行失败!','提示',0);
  end;
end;

procedure TfrmYSFP_WXCI.cxGridDBColumn8PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value:=Trim(mvalue);
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YCL_SG_HZ ');
    if Trim(mvalue)<>'' then
    begin
      sql.Add(' Set '+FFieldName+'='''+Trim(mvalue)+'''');
    end else
    begin
      sql.Add(' Set '+FFieldName+'=NULL');
    end;
    SQL.Add(',Editer='''+Trim(DName)+'''');
    SQL.Add(',Edittime=getdate() ');
    SQL.Add(' where SubId='''+Trim(CDS_HZ.fieldbyname('SubId').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmYSFP_WXCI.cxGridDBColumn5PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,FQty,FPrice,FMoney,FHuiLv,FKPMoney,FKPNow,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  if Trim(mvalue)='' then
  begin
    mvalue:='0';
  end;
  FFieldName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value:=Trim(mvalue);
    if Trim(DParameters2)='人民币' then
    begin
      FieldByName('HuiLv').Value:=1;
    end;
    Post;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select isnull(KPMoney,0) KPMoney from YF_Money_CR where YFID='''+cds_hz.fieldbyname('YFID').AsString+'''');
    Open;
  end;
  FKPMoney:=ADOQueryTemp.fieldbyname('KPMoney').AsString;

  FQty:=Trim(CDS_HZ.fieldbyname('Qty').AsString);
  if Trim(FQty)='' then FQty:='0';

  FPrice:=Trim(CDS_HZ.fieldbyname('Price').AsString);
  if Trim(FPrice)='' then FPrice:='0';
  FQty:=Trim(CDS_HZ.fieldbyname('Qty').AsString);
  if Trim(FQty)='' then FQty:='0';
  FHuiLv:=Trim(CDS_HZ.fieldbyname('HuiLv').AsString);
  if Trim(FHuiLv)='' then FHuiLv:='1';
  if Trim(FFieldName)<>'KPMoney' then
  begin
    FKPNow:=FloatToStr(StrToFloat(FQty)*StrToFloat(FPrice)*StrToFloat(FHuiLv));
  end else
  begin
    FKPNow:=CDS_HZ.fieldbyname('KPMoney').AsString;
  end;
  with CDS_HZ do
  begin
    Edit;
    FieldByName('KPMoney').Value:=StrToFloat(FKPNow);
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    sql.Add(' Set '+FFieldName+'='+Trim(mvalue));
    if Trim(FFieldName)<>'KPMoney' then
    begin
      sql.Add(',KPMoney='+FKPNow);
    end;
    SQL.Add(',Editer='''+Trim(DName)+'''');
    SQL.Add(',Edittime=getdate() ');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');

    SQL.Add('Update YF_Money_KC Set KCKPMoney=KCKPMoney-'+FKPMoney+'+'+FKPNow);
    sql.Add(' where CRID='''+Trim(CDS_HZ.fieldbyname('CRID').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmYSFP_WXCI.cxGridDBColumn1PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value:=Trim(mvalue);
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    if Trim(mvalue)<>'' then
    begin
      sql.Add(' Set '+FFieldName+'='''+Trim(mvalue)+'''');
    end else
    begin
      sql.Add(' Set '+FFieldName+'=NULL');
    end;
    SQL.Add(',Editer='''+Trim(DName)+'''');
    SQL.Add(',Edittime=getdate() ');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmYSFP_WXCI.cxGridDBColumn3PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='YFName';
      flagname:='项目及摘要';
      if Trim(DParameters3)='项目分开' then
        MainType:='收款';
      if ShowModal=1 then
      begin
        with Self.CDS_HZ do
        begin
          Edit;
          FieldByName('YFCode').Value:=Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString);
          FieldByName('YFName').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR ');
          sql.Add(' Set YFCode='''+Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString)+'''');
          sql.Add(' ,YFName='''+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
          SQL.Add(',Editer='''+Trim(DName)+'''');
          SQL.Add(',Edittime=getdate() ');
          SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSFP_WXCI.cxGridDBColumn6PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='OrderUnit';
      flagname:='数量单位';
      if ShowModal=1 then
      begin
        Self.CDS_HZ.Edit;
        Self.CDS_HZ.FieldByName('QtyUnit').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR ');
          sql.Add(' Set QtyUnit='''+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
          SQL.Add(',Editer='''+Trim(DName)+'''');
          SQL.Add(',Edittime=getdate() ');
          SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSFP_WXCI.v2Column3PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='BZType';
      flagname:='币种';
      if ShowModal=1 then
      begin
        Self.CDS_HZ.Edit;
        Self.CDS_HZ.FieldByName('BZType').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR ');
          sql.Add(' Set BZType='''+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
          SQL.Add(',Editer='''+Trim(DName)+'''');
          SQL.Add(',Edittime=getdate() ');
          SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSFP_WXCI.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  SelExportData(Tv2,ADOQueryMain,'应付款列表');
end;

procedure TfrmYSFP_WXCI.v2Column7PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmProductOrderNewList:=TfrmProductOrderNewList.Create(Application);
    with frmProductOrderNewList do
    begin
      DParameters1:='高权限';
      //frmProductOrderList.v1Column4.Visible:=True;
      if ShowModal=1 then
      begin
        with Self.CDS_HZ do
        begin
          Edit;
          FieldByName('MainId').Value:=Trim(frmProductOrderNewList.Order_Main.fieldbyname('MainId').AsString);
          FieldByName('OrderNo').Value:=Trim(frmProductOrderNewList.Order_Main.fieldbyname('OrderNo').AsString);
          FieldByName('ComTaiTou').Value:=Trim(frmProductOrderNewList.Order_Main.fieldbyname('OrdDefStr2').AsString);
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('UPdate YF_Money_CR ');
            sql.Add(' Set MainId='''+Trim(frmProductOrderNewList.Order_Main.fieldbyname('MainId').AsString)+'''');
            SQL.Add(',ComTaiTou='''+Trim(frmProductOrderNewList.Order_Main.fieldbyname('OrdDefStr2').AsString)+'''');
            //sql.Add(' ,SubId='''+Trim(frmProductOrderList.Order_Main.fieldbyname('SubId').AsString)+'''');
            SQL.Add(',Editer='''+Trim(DName)+'''');
            SQL.Add(',Edittime=getdate() ');
            SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
            ExecSQL;
          end;
        end;
      end;
    end;
  finally
    frmProductOrderNewList.Free;
  end;
end;

procedure TfrmYSFP_WXCI.v2Column2PropertiesEditValueChanged(Sender: TObject);
var
  mvalue,FBBMoney,FKCBB,FPrice,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  if Trim(mvalue)='' then
  begin
    mvalue:='0';
  end;
  FFieldName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value:=Trim(mvalue);
    Post;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select isnull(KPMoney,0) KPMoney from YF_Money_CR where YFID='''+cds_hz.fieldbyname('YFID').AsString+'''');
    Open;
  end;
  FKCBB:=ADOQueryTemp.fieldbyname('KPMoney').AsString;
  FBBMoney:=CDS_HZ.fieldbyname('KPMoney').AsString;
  if CDS_HZ.fieldbyname('Qty').AsCurrency<>0 then
  FPrice:=currtostr(Strtocurr(FBBMoney)/CDS_HZ.fieldbyname('Qty').AsCurrency)
  else
  FPrice:='0';
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    sql.Add(' Set '+FFieldName+'='+Trim(mvalue));
    SQL.ADD(',Price='''+trim(FPrice)+'''');
    SQL.Add(',Editer='''+Trim(DName)+'''');
    SQL.Add(',Edittime=getdate() ');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
    SQL.Add('Update YF_Money_KC Set KCKPMoney=KCKPMoney-'+FKCBB+'+'+FBBMoney);
    sql.Add(' where CRID='''+Trim(CDS_HZ.fieldbyname('CRID').AsString)+'''');
    ExecSQL;
  end;
  with cds_HZ do
  begin
    edit;
    fieldbyname('price').Value:=trim(FPrice);
  end;
end;

procedure TfrmYSFP_WXCI.v2PSPropertiesEditValueChanged(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 CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value:=Trim(mvalue);
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    sql.Add(' Set '+FFieldName+'='+Trim(mvalue));
    SQL.Add(',Editer='''+Trim(DName)+'''');
    SQL.Add(',Edittime=getdate() ');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmYSFP_WXCI.v2BatchNoPropertiesEditValueChanged(Sender: TObject);
var
  mvalue,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  FFieldName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_HZ do
  begin
    Edit;
    FieldByName(FFieldName).Value:=Trim(mvalue);
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    sql.Add(' Set '+FFieldName+'='''+Trim(mvalue)+'''');
    SQL.Add(',Editer='''+Trim(DName)+'''');
    SQL.Add(',Edittime=getdate() ');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmYSFP_WXCI.v2PayMentPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PayMent';
      flagname:='支付方式';
      if ShowModal=1 then
      begin
        with Self.CDS_HZ do
        begin
          Edit;
          FieldByName('PayMent').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR ');
          sql.Add(' Set PayMent='''+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
          SQL.Add(',Editer='''+Trim(DName)+'''');
          SQL.Add(',Edittime=getdate() ');
          SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSFP_WXCI.FPNoChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmYSFP_WXCI.VKPNOPropertiesEditValueChanged(Sender: TObject);
var
  mvalue,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with CDS_HZ do
  begin
    Edit;
    FieldByName('KPNO').Value:=trim(mvalue);
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    sql.Add(' Set KPNO='''+Trim(mvalue)+''' ');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmYSFP_WXCI.v2KPDMNoPropertiesEditValueChanged(Sender: TObject);
var
  mvalue,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with CDS_HZ do
  begin
    Edit;
    FieldByName('KPDMNo').Value:=trim(mvalue);
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    sql.Add(' Set KPDMNo='''+Trim(mvalue)+''' ');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmYSFP_WXCI.v2ZFTTPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='ComTaiTou';
      flagname:='公司抬头';
      if ShowModal=1 then
      begin
        with Self.CDS_HZ do
        begin
          Edit;
          FieldByName('ComTaiTou').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPdate YF_Money_CR ');
          sql.Add(' Set ComTaiTou='''+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString)+'''');
          SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
          ExecSQL;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYSFP_WXCI.cxGridDBColumn3PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with CDS_HZ do
  begin
    Edit;
    FieldByName('P_CodeName').Value:=trim(mvalue);
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    sql.Add(' Set P_CodeName='''+Trim(mvalue)+''' ');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmYSFP_WXCI.v2P_SpecPropertiesEditValueChanged(Sender: TObject);
var
  mvalue,FFieldName:String;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with CDS_HZ do
  begin
    Edit;
    FieldByName('P_Spec').Value:=trim(mvalue);
    Post;
  end;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate YF_Money_CR ');
    sql.Add(' Set P_Spec='''+Trim(mvalue)+''' ');
    SQL.Add(' where YFId='''+Trim(CDS_HZ.fieldbyname('YFId').AsString)+'''');
    ExecSQL;
  end;
end;

procedure TfrmYSFP_WXCI.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_HZ,True);
end;

procedure TfrmYSFP_WXCI.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_HZ,false);
end;

procedure TfrmYSFP_WXCI.v2SselPropertiesChange(Sender: TObject);
begin
  Toolbar1.SetFocus;
  //HJ(CDS_HZ,Label12,CDS_HZ.fieldbyname('KPMoney').AsCurrency);
end;

procedure TfrmYSFP_WXCI.TADDClick(Sender: TObject);
begin
  frmYSFP_WXDJCI:=TfrmYSFP_WXDJCI.Create(self);
  with frmYSFP_WXDJCI do
  begin
    FFPID:='';
    if showmodal=1 then
    begin
      Initgrid();
    end;
    free;
  end;
end;

procedure TfrmYSFP_WXCI.TUpdateClick(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then exit;
  frmYSFP_WXDJCI:=TfrmYSFP_WXDJCI.Create(self);
  with frmYSFP_WXDJCI do
  begin
    FFPID:=trim(CDS_HZ.fieldbyname('CIID').AsString);
    if showmodal=1 then
    begin
      Initgrid();
    end;
    free;
  end;
end;

procedure TfrmYSFP_WXCI.TSelClick(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then exit;
  frmYSFP_WXDJCI:=TfrmYSFP_WXDJCI.Create(self);
  with frmYSFP_WXDJCI do
  begin
    TBSave.Visible:=false;
    ToolBar2.Visible:=false;
    FFPID:=trim(CDS_HZ.fieldbyname('CIID').AsString);
    if showmodal=1 then
    begin
      Initgrid();
    end;
    free;
  end;
end;

procedure TfrmYSFP_WXCI.TFZClick(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then exit;
  frmYSFP_WXDJCI:=TfrmYSFP_WXDJCI.Create(self);
  with frmYSFP_WXDJCI do
  begin
    FromID:='1';
    FFPID:=trim(CDS_HZ.fieldbyname('CIID').AsString);
    if showmodal=1 then
    begin
      Initgrid();
    end;
    free;
  end;
end;

procedure TfrmYSFP_WXCI.TPrintClick(Sender: TObject);
var
  fPrintFile,fZMFile:string;
begin
  if CDS_HZ.IsEmpty then Exit;
  if ComboBox1.Text='外销发票CI3' then
  begin
    WXFPData();
  end;
  if (ComboBox1.Text='外销发票CI1') or (ComboBox1.Text='外销发票CI2') or (ComboBox1.Text='外销发票CI4') then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.add('select A.*,B.*, ');
      sql.add('SumPS=(Select Sum(C.ps) from JYorderFPCI_Sub C where C.CIID=A.CIID)');
      sql.add(',DJ=(select Sum(R.RLMoney/D.Money*D.KHDKMoney) from JYOrderYSK R inner join JYOrderCon_Sub C on R.Mainid=C.Mainid ');
      sql.add(' inner join YF_Money_CR D on D.YFID=R.YFID where C.Subid=B.ConSubid and R.FeeName=''定金'') ');
      sql.add('from JYOrderFPCI_Main A ');
      sql.add('inner join JYOrderFPCI_Sub B on A.CIID=B.CIID ');
      sql.add('where A.CIID='''+trim(CDS_HZ.fieldbyname('CIID').AsString)+''' ');
      //sql.add('order by B.P_CodeName');           //有些输入品名，有些没输入，输入就自动跳到后面
      Open;
    end;
    SCreateCDS20(ADOQueryTemp,Order_Print);
    SInitCDSData20(ADOQueryTemp,Order_Print);
  end;
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.add('select isnull(Sum(AA.RLMoney),0) SumRLMoney from (select distinct A.Mainid,RLMoney=(C.RLMoney/D.Money*D.KHDKMoney) ');
    sql.add('from JYOrderCon_Sub A ');
    sql.add('inner join JYOrderYSK C on A.Mainid=C.Mainid ');
    sql.add('inner join JYOrderFPCI_Sub B on A.Subid=B.ConSubid ');
    sql.add('inner join YF_Money_CR D on D.YFID=C.YFID ');
    sql.add('where C.FeeName=''定金'' and B.CIID='''+trim(CDS_HZ.fieldbyname('CIID').AsString)+''') AA ');
    Open;
  end;
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\'+Trim(ComboBox1.Text)+'.rmf' ;
  if FileExists(fPrintFile) then
  begin
    if RMCD.CanExport=true then
    begin
      fZMFile:='C:\Users\Administrator\Desktop';
      if not DirectoryExists(fZMFile) then
      begin
        fZMFile:='C:\Documents and Settings\Administrator\桌面\'+trim(CDS_HZ.fieldbyname('FPNo').AsString)+'.xls';
      end
      else
      begin
        fZMFile:='C:\Users\Administrator\Desktop\'+trim(CDS_HZ.fieldbyname('FPNo').AsString)+'.XLS';
      end;
      RMCD.ExportTo(RMXLSExport1,fZMFile);
    end;
    RMCD.CanExport:=true;
    RMVariables['SumRLMoney']:=ADOQuery1.fieldbyname('SumRLMoney').AsCurrency;
    RMVariables['SumPS']:=UpperCase(num2ceng(floattostr(Order_Print.fieldbyname('SumPS').AsFloat)));
    RMCD.LoadFromFile(fPrintFile);
    RMCD.ShowReport;
    RMCD.CanExport:=False;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\外销发票CI.rmf'),'提示',0);
  end;
end;

procedure TfrmYSFP_WXCI.Tv2CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  TSel.Click;
end;

procedure TfrmYSFP_WXCI.Tv2CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  try
    ADOQueryCmd.DisableControls;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select A.*');
      sql.Add(' from JYOrderFPCI_Sub A');
      sql.Add(' where A.CIID='''+Trim(CDS_HZ.fieldbyname('CIID').AsString)+'''');
      Open;
    end;
    SCreateCDS20(ADOQueryCmd,Order_Sub);
    SInitCDSData20(ADOQueryCmd,Order_Sub);
  finally
    ADOQueryCmd.EnableControls;
  end;
end;

end.
