unit U_frameSampleInfo;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, StdCtrls, DBCtrls, DB, ADODB, ExtCtrls,Jpeg, cxControls, cxPC;

type
  TFrameSapleInfo = class(TFrame)
    ADOQuery1: TADOQuery;
    DataSource1: TDataSource;
    Label1: TLabel;
    Label2: TLabel;
    Image1: TImage;
    ADOQueryTmp: TADOQuery;
    Label3: TLabel;
    Label4: TLabel;
    cxTabControl1: TcxTabControl;
    ADOConnection1: TADOConnection;
    procedure DBText1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
  private
    function ToCreateConn():Boolean;
  public
    fPicType:string;
    fP_yhNo:string;
    procedure GetSampleData(mPlanNo:string);
    procedure GetSampleData_YH(mP_YHNO:string);
  end;

implementation
uses
  U_ADODBmd,U_global;
{$R *.dfm}

procedure TFrameSapleInfo.DBText1Click(Sender: TObject);
begin

end;
//===============================================================
  //函数功能：染整调用印花小样信息
//===============================================================
procedure TFrameSapleInfo.GetSampleData(mPlanNo:string);
var
  ghy:TADOBlobstream;
  pic:Tjpegimage;
begin
  if not ToCreateConn() then exit;
  with ADOQueryTmp do
  begin
    close;
    sql.Clear;
    sql.Add('select distinct P_YHNO from MD_Product_YH where planNo='''+mPlanNo+'''');
    open;
  end;
  Image1.Picture.assign(NIL);
  with ADOQuery1 do
  begin
    close;
    parameters.ParamByName('PP_YHNO').Value :=trim(ADOQueryTmp.fieldByName('P_YHNO').AsString);
    open;
    Label3.Caption := trim(fieldByName('P_YHNO').AsString) ;
    Label4.Caption := fieldByName('Plates').AsString ;
    if fieldByName('PatFile').AsString='' then
      exit;
   //////////////////////////////////////////////
   ghy := TADOBlobstream.Create(Adoquery1.fieldByName('picture') as TblobField, bmRead);
   try
     Pic:=TJpegImage.Create;
     try
       Pic.LoadFromStream(ghy);
       Image1.Picture.assign(pic);
     finally
       Pic.Free;
      end;
   finally
     ghy.Free ;
   end;

  end;
  ADOQuery1.Close;
  ADOQueryTmp.Close;


end;
//===============================================================
  //函数功能：印花配方调用印花小样信息
//===============================================================
procedure TFrameSapleInfo.GetSampleData_YH(mP_YHNO:string);
var
  ghy:TADOBlobstream;
  pic:Tjpegimage;
begin
  fP_yhNo:=mP_YHNO;
  if not ToCreateConn() then exit;
  if cxTabControl1.TabIndex=0 then
    fPicType:='SO'
  else if cxTabControl1.TabIndex=1 then
    fPicType:='KY'
  else
    fPicType:='DH';
  Image1.Picture.assign(NIL);
  with ADOQuery1 do
  begin
    close;
    sql.Clear ;
    sql.Add('select A.P_YHNO,A.Plates,C.picture,B.PatFile');
    sql.Add('from SD_Swplan A');
    sql.Add('inner join SD_SWDetail B on A.P_YHNO=B.P_YHNO');
    sql.Add('and A.P_YHNo='+quotedStr(mP_YHNO));
    if fPicType='SO' then
      sql.Add('inner join sd_swPicture c on C.patFile=B.patFile1')
    else if fPicType='KY' then
      sql.Add('inner join sd_swPicture c on C.patFile=B.patFile')
    //大货
    else
      sql.Add('inner join sd_swPicture c on C.patFile=B.patFile2');
    open;
    Label3.Caption := trim(fieldByName('P_YHNO').AsString) ;
    Label4.Caption := fieldByName('Plates').AsString ;

    if recordCount<=0 then exit;
    //if fieldByName('PatFile').AsString='' then
    //  exit;
   //////////////////////////////////////////////
   ghy := TADOBlobstream.Create(Adoquery1.fieldByName('picture') as TblobField, bmRead);
   IF ghy=nil then exit;
   try
     Pic:=TJpegImage.Create;
     try
       Pic.LoadFromStream(ghy);
       Image1.Picture.assign(pic);
     finally
       Pic.Free;
      end;
   finally
     ghy.Free ;
   end;

  end;
  ADOQuery1.Close;
  ADOQueryTmp.Close;


end;



procedure TFrameSapleInfo.cxTabControl1Change(Sender: TObject);
begin
  GetSampleData_YH(fP_yhNo);
end;
//////////////////////////////////////////////////////
  //函数功能：建立数据库连接
/////////////////////////////////////////////////////
function TFrameSapleInfo.ToCreateConn():Boolean;
begin
 try
   with ADOConnection1 do
   begin
    Connected:=false;
    ConnectionString:=gConString;
    Connected:=true;
   end;
   result:=true;
 except
   result:=false;
   application.MessageBox('数据库连接失败!','警告信息',0); 
 end;
end;

end.
