unit U_ZdyAttachCP_CX;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, ComObj,
  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, Menus, cxLookAndFeelPainters, cxButtons,
  cxContainer, cxImage, cxDBEdit;

type

  FdDy=record
               inc: integer; //客户端套接字句柄
               FDdys:string[32]; //客户端套接字
               FdDysName:string[32]; //客户端套接字
       end;
  TfrmZdyAttachCP_CX = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    Label3: TLabel;
    defNote3: TEdit;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    Label1: TLabel;
    ZdyName: TEdit;
    Label2: TLabel;
    OpenDialog1: TOpenDialog;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2Column2: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v2Column12: TcxGridDBColumn;
    v2DEFstr3: TcxGridDBColumn;
    v2Column16: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    v2Mrate: TcxGridDBColumn;
    v2Column9: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    v2defflt1: TcxGridDBColumn;
    v2Note: TcxGridDBColumn;
    v2Column14: TcxGridDBColumn;
    v2Column15: TcxGridDBColumn;
    v2Column8: TcxGridDBColumn;
    v2Column10: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Pan_image: TPanel;
    Picture4: TcxDBImage;
    DSImage: TDataSource;
    ADOQueryImage: TADOQuery;
    v2defstr9: TcxGridDBColumn;
    v2Price1: TcxGridDBColumn;
    v2CPrice2: TcxGridDBColumn;
    v2Price3: TcxGridDBColumn;
    Label5: TLabel;
    Label6: TLabel;
    fengge: TEdit;
    CCShiChang: TEdit;
    v2CCShiChang: TcxGridDBColumn;
    v2KHMaiTou: TcxGridDBColumn;
    v2KHDaiMa: TcxGridDBColumn;
    vZJSName: TcxGridDBColumn;
    v2HTOrdDate: TcxGridDBColumn;
    v2TouJu: TcxGridDBColumn;
    v2ZhenQty: TcxGridDBColumn;
    v2FengGe: TcxGridDBColumn;
    v2QDJGName: TcxGridDBColumn;
    v2QDPrice: TcxGridDBColumn;
    v2HDJGName: TcxGridDBColumn;
    v2HDPrice: TcxGridDBColumn;
    v2FLNote: TcxGridDBColumn;
    DEFstr3: TEdit;
    Label7: TLabel;
    HDFengGe: TEdit;
    v2HDFengGe: TcxGridDBColumn;
    Label8: TLabel;
    Note: TEdit;
    Label9: TLabel;
    defstr9: TEdit;
    v2DBName: TcxGridDBColumn;
    v2DateNote: TcxGridDBColumn;
    v2RKQty: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    v2QDMoney: TcxGridDBColumn;
    v2HDMoney: TcxGridDBColumn;
    cxStyle2: TcxStyle;
    v2CPNote: TcxGridDBColumn;
    v2DBPrice: TcxGridDBColumn;
    v2DBUnit: TcxGridDBColumn;
    v2ColQty: TcxGridDBColumn;
    v2YPPlace: TcxGridDBColumn;
    v2Ssel: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ToolButton3: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure defNote3Change(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Tv2CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure FormResize(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
  private
    fFlileFlag:string;
    procedure InitImage();
    { Private declarations }
    procedure InitGrid();

  public
    canshu1:string;
    fkhType:string;
    dFdDy: array[0..20] of FdDy; 
  end;

var
  frmZdyAttachCP_CX: TfrmZdyAttachCP_CX;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp;

{$R *.dfm}
procedure TfrmZdyAttachCP_CX.InitImage();
begin
  with ADOQueryImage do
  begin
    close;
    sql.Clear;
    sql.Add('select * from TP_File A');
    sql.Add('where WBID='+quotedstr(trim(CDS_HZ.fieldbyname('ATID').AsString)));
    open;
  end;
end;

procedure TfrmZdyAttachCP_CX.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      SQL.Clear;
      sql.Add('select AA.* ');
      sql.Add(',QDMoney=RKQty*QDPrice,HDMoney=RKQty*HDPrice');
      sql.Add(' from (select A.* ');
      sql.Add(',RKQty=(select Sum(B.Qty) from CK_BanCP_CR B where B.CRFlag=''入库'' and B.C_Color=A.DEFstr3 ');
      sql.Add(' and (B.C_CodeName=A.ZdyName or B.C_CodeName=A.defNote3) and B.CRType=''检验入库'' and convert(varchar(4),B.CRTime,120)=convert(varchar(4),getdate(),120))');
      sql.Add(' from KH_Zdy_Attachment A where A.Type=''CP'') AA');
      sql.Add(' where isnull(AA.khType,'''')='+quotedstr(trim(fkhType)));
      sql.Add(' order by zdyName,dbo.getNum(Defstr3) ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
  end;
end;


procedure TfrmZdyAttachCP_CX.FormDestroy(Sender: TObject);
begin
  frmZdyAttachCP_CX:=nil;
end;

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

procedure TfrmZdyAttachCP_CX.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('产品资料132',Tv2,'客户自定义');
  Close;
end;
procedure TfrmZdyAttachCP_CX.FormShow(Sender: TObject);
begin
  ReadCxGrid('产品资料132',Tv2,'客户自定义');
  fFlileFlag:=UserDataFlag+'YP';
  //InitGrid();
end;

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

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

procedure TfrmZdyAttachCP_CX.defNote3Change(Sender: TObject);
begin
  ToolButton2.Click;
end;


procedure TfrmZdyAttachCP_CX.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
  TcxGridToExcel(self.Caption,cxgrid2);
//  SelExportData(Tv2,ADOQueryMain,'产品资料列表');
end;

procedure TfrmZdyAttachCP_CX.Tv2CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  InitImage();
end;

procedure TfrmZdyAttachCP_CX.FormResize(Sender: TObject);
begin
  Pan_image.Left:=self.Width-Pan_image.Width-30;
  Pan_image.Top:=self.Height-Pan_image.Height-80;
end;

procedure TfrmZdyAttachCP_CX.FormCreate(Sender: TObject);
begin
  canshu1:=Trim(DParameters1);
end;

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

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

procedure TfrmZdyAttachCP_CX.ToolButton3Click(Sender: TObject);
begin
  if CDS_HZ.locate('Ssel',true,[])=False then
  begin
    application.messagebox('没有选择数据','提示');
    exit;
  end;
  ModalResult:=1;
end;

end.


