unit U_PieceSampleKcHZList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, StdCtrls, ExtCtrls, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData,
  cxButtonEdit, cxDropDownEdit, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls, cxGridCustomView,
  cxGrid, DBClient, ADODB, cxGridCustomPopupMenu, cxGridPopupMenu, cxCheckBox,
  RM_Common, RM_Class, RM_GridReport, RM_System, RM_Dataset, MMSystem, Menus,
  BtnEdit, U_SLT, jpeg, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmPieceSampleKcHZList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1P_CodeName: TcxGridDBColumn;
    v1P_SPEC: TcxGridDBColumn;
    v1Qty: TcxGridDBColumn;
    v1QtyUnit: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label3: TLabel;
    P_CodeName: TEdit;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    DataSource1: TDataSource;
    CDS_Main: TClientDataSet;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label7: TLabel;
    P_Color: TEdit;
    Label8: TLabel;
    Label9: TLabel;
    kuwei: TEdit;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    ADOQueryPrint: TADOQuery;
    RMDB_Main: TRMDBDataSet;
    RM1: TRMGridReport;
    v1Column8: TcxGridDBColumn;
    ADOQueryMain: TADOQuery;
    Label13: TLabel;
    P_Code: TEdit;
    Label18: TLabel;
    Label31: TLabel;
    FactoryName: TEdit;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    v1Column3: TcxGridDBColumn;
    ToolButton2: TToolButton;
    GroupBox1: TGroupBox;
    ScrollBox1: TScrollBox;
    v1Column7: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    adoqueryPicture: TADOQuery;
    Tv1Column1: TcxGridDBColumn;
    Label1: TLabel;
    yptype: TEdit;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure P_CodeNameChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
  private
    procedure InitGrid();
    procedure SetStatus();
    procedure InitImage();
    { Private declarations }
  public
    fType: integer;
    fCKName: string;
    
    { Public declarations }
  end;

var
  frmPieceSampleKcHZList: TfrmPieceSampleKcHZList;

var
  Mach: array of TfrmSlt;

implementation

uses
  U_DataLink, U_Fun10, U_ZDYHelp;
{$R *.dfm}

procedure TfrmPieceSampleKcHZList.InitImage();
var
  i, j: integer;
  jpg: TJpegImage;
  myStream: TADOBlobStream;
begin

  j := length(Mach);
  if j > 0 then
  begin
    for i := 0 to j - 1 do
    begin
      Mach[i].free;
    end;
  end;
  SetLength(Mach, 0);
  if CDS_Main.IsEmpty then
    exit;
  try
    with adoqueryPicture do
    begin
      close;
      sql.Clear;
      sql.Add(' select A.TFID,A.WBID,A.FilesOther,B.FileName from TP_File A,XD_File B  where A.TFID =B.XFID ');
      if CDS_Main.IsEmpty = False then
      begin
        sql.Add('and A.WBID=' + quotedstr(trim(CDS_Main.fieldbyname('MJID').AsString)));
      end
      else
      begin
        sql.add(' and 1=2');
      end;
      open;
    end;
    j := adoqueryPicture.RecordCount;
    if j < 1 then
      exit;
    adoqueryPicture.DisableControls;
    adoqueryPicture.First;
    SetLength(Mach, j);
    jpg := TJpegImage.Create();
    for i := 0 to j - 1 do
    begin
      if triM(adoqueryPicture.fieldbyname('FilesOther').AsString) <> '' then
      begin
        myStream := tadoblobstream.Create(tblobfield(adoqueryPicture.fieldbyname('FilesOther')), bmread);
        jpg.LoadFromStream(myStream);
        Mach[i] := TfrmSlt.Create(Self);
        Mach[i].Name := trim(adoqueryPicture.fieldbyname('TFID').AsString);
        Mach[i].Parent := ScrollBox1;
        Mach[i].Left := 0 + i * 165;
        Mach[i].Init(adoqueryPicture.fieldbyname('TFID').AsString, adoqueryPicture.fieldbyname('FileName').AsString, jpg);
      end;
      adoqueryPicture.Next;
    end;
    adoqueryPicture.EnableControls;
  finally
    jpg.free;
    application.ProcessMessages;
  end;
end;

procedure TfrmPieceSampleKcHZList.SetStatus();
begin

end;

procedure TfrmPieceSampleKcHZList.InitGrid();
begin
  try
    with adoqueryMain do
    begin
      close;
      sql.Clear;
      sql.Add(' select A.P_Code,A.P_CodeName,A.P_spec,A.P_MF,A.P_KZ,A.P_Color,A.QtyUnit,yptype  ');
      sql.Add('  ,count(A.KCRollNum) KCRollNum,sum(A.KCQty) KCQty ');
      SQL.Add(' from CK_Sample_CR A ');
      sql.Add(' where A.kcQty<>0 and CKName=' + quotedstr(trim(fCKName)));
      sql.ADD(' and  A.Valid=''Y'' and A.CRFlag=''入库'' ');
      sql.Add('and yptype like ' + QuotedStr('%' + Trim(yptype.Text) + '%'));
      sql.Add(' group by A.P_Code,A.P_CodeName,A.P_spec,A.P_MF,A.P_KZ,A.P_Color,A.QtyUnit,yptype');
      open;
    end;
    SCreateCDS20(adoqueryMain, CDS_Main);
    SInitCDSData20(adoqueryMain, CDS_Main);
  finally
  end;
end;

procedure TfrmPieceSampleKcHZList.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  writeCxGrid(self.Caption + tv1.Name, Tv1, '面料仓库');
  if fType = 10 then
    Action := cahide
  else
    Action := cafree;
end;

procedure TfrmPieceSampleKcHZList.FormDestroy(Sender: TObject);
begin
  frmPieceSampleKcHZList := nil;
end;

procedure TfrmPieceSampleKcHZList.P_CodeNameChange(Sender: TObject);
begin
  if adoqueryMain.Active = False then
    Exit;
  SDofilter(adoqueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(adoqueryMain, CDS_Main);
  SInitCDSData20(adoqueryMain, CDS_Main);
end;

procedure TfrmPieceSampleKcHZList.FormShow(Sender: TObject);
begin
  readCxGrid(self.Caption + tv1.Name, Tv1, '面料仓库');
  SetStatus();
  InitGrid();
end;

procedure TfrmPieceSampleKcHZList.TBCloseClick(Sender: TObject);
begin
  close;
end;

procedure TfrmPieceSampleKcHZList.TBRafreshClick(Sender: TObject);
begin
  initGrid();
end;

procedure TfrmPieceSampleKcHZList.TBExportClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    Exit;
  TcxGridToExcel(self.Caption, cxgrid1);
end;

procedure TfrmPieceSampleKcHZList.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, true);
end;

procedure TfrmPieceSampleKcHZList.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, false);

end;

procedure TfrmPieceSampleKcHZList.ToolButton2Click(Sender: TObject);
begin
  if adoqueryMain.Active = False then
    Exit;
  SDofilter(adoqueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(adoqueryMain, CDS_Main);
  SInitCDSData20(adoqueryMain, CDS_Main);
end;

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

end.

