unit U_BPZdy_PanelCX;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, ToolWin, ComCtrls,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGridLevel,
  cxClasses, cxControls, cxGridCustomView, cxGrid, DBClient, ADODB, ImgList,
  StdCtrls, ExtCtrls, cxTextEdit, cxGridCustomPopupMenu, cxGridPopupMenu,
  cxButtonEdit, BtnEdit, cxTL, cxMaskEdit, cxInplaceContainer, cxDBTL,
  cxTLData, cxContainer, cxCurrencyEdit, cxCheckBox, cxSplitter,jpeg,U_SLT_PBSK,U_SLT_BF1,Math, Menus, cxCalendar,
  cxPC, Buttons, RM_Dataset, RM_System, RM_Common, RM_Class, RM_GridReport;

type
  TfrmBPZDY_PanelCX = class(TForm)
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQuery6: TADOQuery;
    cxGridPopupMenu2: TcxGridPopupMenu;
    adoqueryPicture: TADOQuery;
    PanelTop: TPanel;
    Button1: TButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    Ord_SH: TClientDataSet;
    Edit1: TEdit;
    Panel26: TPanel;
    ScrollBox1: TScrollBox;
    Panel101: TPanel;
    Label401: TLabel;
    Label402: TLabel;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    V1GYLXName: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Panel27: TPanel;
    ScrollBox2: TScrollBox;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridDBGYLXName: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Ord_GXSel: TClientDataSet;
    Ord_GX: TClientDataSet;
    DataSource1: TDataSource;
    DataSource2: TDataSource;
    Ord_SHSel: TClientDataSet;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Panel2: TPanel;
    Label3: TLabel;
    Label4: TLabel;
    Panel3: TPanel;
    Label5: TLabel;
    Label6: TLabel;
    Panel4: TPanel;
    Label7: TLabel;
    Label8: TLabel;
    Panel5: TPanel;
    Label9: TLabel;
    Label10: TLabel;
    Panel6: TPanel;
    Label11: TLabel;
    Label12: TLabel;
    Panel7: TPanel;
    Label13: TLabel;
    Label14: TLabel;
    Panel8: TPanel;
    Label15: TLabel;
    Label16: TLabel;
    Panel9: TPanel;
    Label17: TLabel;
    Label18: TLabel;
    Panel10: TPanel;
    Label19: TLabel;
    Label20: TLabel;
    Panel11: TPanel;
    Label21: TLabel;
    Label22: TLabel;
    Panel12: TPanel;
    Label23: TLabel;
    Label24: TLabel;
    Panel13: TPanel;
    Label25: TLabel;
    Label26: TLabel;
    Panel14: TPanel;
    Label27: TLabel;
    Label28: TLabel;
    Panel15: TPanel;
    Label29: TLabel;
    Label30: TLabel;
    Panel16: TPanel;
    Label31: TLabel;
    Label32: TLabel;
    Panel17: TPanel;
    Label33: TLabel;
    Label34: TLabel;
    Panel18: TPanel;
    Label35: TLabel;
    Label36: TLabel;
    Panel19: TPanel;
    Label37: TLabel;
    Label38: TLabel;
    Panel20: TPanel;
    Label39: TLabel;
    Label40: TLabel;
    Panel21: TPanel;
    Label41: TLabel;
    Label42: TLabel;
    Panel22: TPanel;
    Label43: TLabel;
    Label44: TLabel;
    Panel23: TPanel;
    Label45: TLabel;
    Label46: TLabel;
    Panel24: TPanel;
    Label47: TLabel;
    Label48: TLabel;
    Panel25: TPanel;
    Label49: TLabel;
    Label50: TLabel;
    Panel28: TPanel;
    Label51: TLabel;
    Label52: TLabel;
    Panel29: TPanel;
    Label53: TLabel;
    Label54: TLabel;
    Panel30: TPanel;
    Label55: TLabel;
    Label56: TLabel;
    Panel31: TPanel;
    Label57: TLabel;
    Label58: TLabel;
    Panel32: TPanel;
    Label59: TLabel;
    Label60: TLabel;
    Panel33: TPanel;
    Label61: TLabel;
    Label62: TLabel;
    Panel34: TPanel;
    Label63: TLabel;
    Label64: TLabel;
    Panel35: TPanel;
    Label65: TLabel;
    Label66: TLabel;
    Panel36: TPanel;
    Label67: TLabel;
    Label68: TLabel;
    Panel37: TPanel;
    Label69: TLabel;
    Label70: TLabel;
    Panel38: TPanel;
    Label71: TLabel;
    Label72: TLabel;
    Panel39: TPanel;
    Label73: TLabel;
    Label74: TLabel;
    Panel40: TPanel;
    Label75: TLabel;
    Label76: TLabel;
    Panel41: TPanel;
    Label77: TLabel;
    Label78: TLabel;
    Panel42: TPanel;
    Label79: TLabel;
    Label80: TLabel;
    Panel43: TPanel;
    Label81: TLabel;
    Label82: TLabel;
    Panel44: TPanel;
    Label83: TLabel;
    Label84: TLabel;
    Panel45: TPanel;
    Label85: TLabel;
    Label86: TLabel;
    Panel46: TPanel;
    Label87: TLabel;
    Label88: TLabel;
    Panel47: TPanel;
    Label89: TLabel;
    Label90: TLabel;
    Panel48: TPanel;
    Label91: TLabel;
    Label92: TLabel;
    Panel49: TPanel;
    Label93: TLabel;
    Label94: TLabel;
    Panel50: TPanel;
    Label95: TLabel;
    Label96: TLabel;
    Panel51: TPanel;
    Label97: TLabel;
    Label98: TLabel;
    Panel52: TPanel;
    Label99: TLabel;
    Label100: TLabel;
    Panel53: TPanel;
    Label101: TLabel;
    Label102: TLabel;
    Panel54: TPanel;
    Label103: TLabel;
    Label104: TLabel;
    Panel55: TPanel;
    Label105: TLabel;
    Label106: TLabel;
    Panel56: TPanel;
    Label107: TLabel;
    Label108: TLabel;
    Panel57: TPanel;
    Label109: TLabel;
    Label110: TLabel;
    Panel58: TPanel;
    Label111: TLabel;
    Label112: TLabel;
    Panel59: TPanel;
    Label113: TLabel;
    Label114: TLabel;
    Panel60: TPanel;
    Label115: TLabel;
    Label116: TLabel;
    Panel61: TPanel;
    Label117: TLabel;
    Label118: TLabel;
    Panel62: TPanel;
    Label119: TLabel;
    Label120: TLabel;
    Panel63: TPanel;
    Label121: TLabel;
    Label122: TLabel;
    Panel64: TPanel;
    Label123: TLabel;
    Label124: TLabel;
    Panel65: TPanel;
    Label125: TLabel;
    Label126: TLabel;
    Panel66: TPanel;
    Label127: TLabel;
    Label128: TLabel;
    Panel67: TPanel;
    Label129: TLabel;
    Label130: TLabel;
    Panel68: TPanel;
    Label131: TLabel;
    Label132: TLabel;
    Panel69: TPanel;
    Label133: TLabel;
    Label134: TLabel;
    Panel70: TPanel;
    Label135: TLabel;
    Label136: TLabel;
    Panel71: TPanel;
    Label137: TLabel;
    Label138: TLabel;
    Panel72: TPanel;
    Label139: TLabel;
    Label140: TLabel;
    Panel73: TPanel;
    Label141: TLabel;
    Label142: TLabel;
    Panel74: TPanel;
    Label143: TLabel;
    Label144: TLabel;
    Panel75: TPanel;
    Label145: TLabel;
    Label146: TLabel;
    Panel76: TPanel;
    Label147: TLabel;
    Label148: TLabel;
    Panel77: TPanel;
    Label149: TLabel;
    Label150: TLabel;
    Panel78: TPanel;
    Label151: TLabel;
    Label152: TLabel;
    Panel79: TPanel;
    Label153: TLabel;
    Label154: TLabel;
    Panel80: TPanel;
    Label155: TLabel;
    Label156: TLabel;
    Panel81: TPanel;
    Label157: TLabel;
    Label158: TLabel;
    ADOQueryPrint: TADOQuery;
    CDS_Print: TClientDataSet;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    Panel82: TPanel;
    Label159: TLabel;
    Label160: TLabel;
    Panel83: TPanel;
    Label161: TLabel;
    Label162: TLabel;
    Panel84: TPanel;
    Label163: TLabel;
    Label164: TLabel;
    Panel85: TPanel;
    Label165: TLabel;
    Label166: TLabel;
    Panel86: TPanel;
    Label167: TLabel;
    Label168: TLabel;
    Panel87: TPanel;
    Label169: TLabel;
    Label170: TLabel;
    Panel88: TPanel;
    Label171: TLabel;
    Label172: TLabel;
    Panel89: TPanel;
    Label173: TLabel;
    Label174: TLabel;
    Panel90: TPanel;
    Label175: TLabel;
    Label176: TLabel;
    Panel91: TPanel;
    Label177: TLabel;
    Label178: TLabel;
    Panel123: TPanel;
    Label239: TLabel;
    Label240: TLabel;
    Panel124: TPanel;
    Label241: TLabel;
    Label242: TLabel;
    Panel125: TPanel;
    Label243: TLabel;
    Label244: TLabel;
    Panel126: TPanel;
    Label245: TLabel;
    Label246: TLabel;
    Panel127: TPanel;
    Label247: TLabel;
    Label248: TLabel;
    Panel128: TPanel;
    Label249: TLabel;
    Label250: TLabel;
    Panel129: TPanel;
    Label251: TLabel;
    Label252: TLabel;
    Panel130: TPanel;
    Label253: TLabel;
    Label254: TLabel;
    Panel131: TPanel;
    Label255: TLabel;
    Label256: TLabel;
    Panel132: TPanel;
    Label257: TLabel;
    Label258: TLabel;
    LBCPAP: TLabel;
    Label553: TLabel;
    BTLP: TButton;
    BTNP: TButton;
    SY: TButton;
    XY: TButton;
    Label554: TLabel;
    ComboBox1: TComboBox;
    Label179: TLabel;
    V1GYLX: TcxGridDBColumn;
    Button2: TButton;
    Button3: TButton;
    V2GYLX: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure Panel1DblClick(Sender: TObject);
    procedure Panel101DblClick(Sender: TObject);
    procedure TV1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure TV2CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure Panel28DblClick(Sender: TObject);
    procedure Panel101MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Panel42MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Button1Click(Sender: TObject);
    procedure SYClick(Sender: TObject);
    procedure BTLPClick(Sender: TObject);
    procedure BTNPClick(Sender: TObject);
    procedure XYClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    FCPID,FCPNo,Fint1,FCPName,FColNoZ,FColNameKHZ:string;
    FColName,FColNameKH,Canshu1,FColNo,FColEng,FPTNo,FCYID:string;
    FColor:TColor;
    y,Z,my,mz:integer;
    procedure SaveData();
    procedure InitSHByOrdBP_SH();
    procedure InitSHByOrdBP_SHSel();
    { Private declarations }
  public
    flag,flagname,snote,MainType,FGYName,Fint,FColorFlag,FBPID,FMLID:string;
    procedure initimageSH();
    procedure initPanel();
    procedure initPL();
    procedure SavePrint(var CP,TP,FBQName:string);
    { Public declarations }
  end;
var
  frmBPZDY_PanelCX: TfrmBPZDY_PanelCX;
implementation
uses
  U_DataLink,U_Fun10,U_BPZdy_YT;

{$R *.dfm}
procedure TfrmBPZDY_PanelCX.SavePrint(var CP,TP,FBQName:string);
var maxno,MaxSub:string;
   fPrintFile,Txt,fImagePath:string;
   Porderno:string;
   i,j:Integer;
   Moudle: THandle;
   Makebar:TMakebar;
   Mixtext:TMixtext;
begin
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    SQL.Add('select * from BP_DY ');
    sql.Add('where MLID='''+trim(CP)+'''');
    sql.Add(' and TFID='''+trim(TP)+'''');
    //ShowMessage(sql.Text);
    Open;
  end;
  if ADOQueryCmd.IsEmpty then
  begin
    if GetLSNo(ADOQueryTemp,maxno,'DY','BP_DY',3,1)=False then
    begin
      Application.MessageBox('取最大号失败!','提示',0);
      Exit;
    end;
  end
  else
  begin
    maxno:=Trim(ADOQueryCmd.fieldbyname('DYID').AsString);
  end;
  with ADOQueryCmd do
  begin
    if IsEmpty then
    begin
      Append;
      FieldByName('filler').Value:=Trim(DName);
      FieldByName('DYID').Value:=Trim(maxno);
    end
    else
    begin
      edit;
      FieldByName('laster').Value:=Trim(DName);
      FieldByName('lasttime').Value:=SGetServerDate(ADOQueryTemp);
    end;
    FieldByName('MLID').Value:=Trim(CP);
    FieldByName('TFID').Value:=Trim(TP);
    FieldByName('DYType').Value:='染色';
    FieldByName('DYColNo').Value:=Trim(Ord_SHSel.fieldbyname('ColNo').AsString);
    FieldByName('DYColName').Value:=Trim(Ord_SHSel.fieldbyname('ColNameKH').AsString);
    FieldByName('BQType').Value:=Trim(FBQName);
    //ShowMessage(Ord_SHSel.fieldbyname('ColNo').AsString);
    post;
  end;
  //////////记录
  if GetLSNo(ADOQueryTemp,MaxSub,'JL','BP_DY_JL',3,1)=False then
  begin
    Application.MessageBox('取最大号失败!','提示',0);
    Exit;
  end;
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    SQL.Add('select * from BP_DY_JL ');
    sql.Add('where 1=2');
    Open;
  end;
  with ADOQueryCmd do
  begin
    Append;
    FieldByName('filler').Value:=Trim(DName);
    FieldByName('JLID').Value:=Trim(MaxSub);
    FieldByName('DYID').Value:=Trim(maxno);
    FieldByName('MLID').Value:=Trim(CP);
    FieldByName('TFID').Value:=Trim(TP);
    FieldByName('DYColNo').Value:=Trim(Ord_SHSel.fieldbyname('ColNo').AsString);
    FieldByName('DYColName').Value:=Trim(Ord_SHSel.fieldbyname('ColNameKH').AsString);
    FieldByName('BQType').Value:=Trim(FBQName);
    post;
  end;
  //打印
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\'+trim(FBQName)+'.rmf';
  with ADOQueryPrint do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.*,C.DYID,D.ColNo colorNo,D.ColNameKH colorName,B.ColNameEng colorNameEng ');
    sql.Add('from BP_DY C ');
    sql.Add('inner join ML_Manage A on A.MLID=C.MLID ');
    sql.add('inner join BP_ZDY BP on A.MBPID=BP.BPID ');
    sql.Add('inner join BP_ColZDY D on D.PTID=C.TFID and BP.SKID=D.SKID ');
    sql.Add('inner join RT_PTColor B on B.PTID=D.PTID ');
    sql.Add(' Where C.DYID='''+Trim(maxno)+'''');
    //ShowMessage(sql.Text);
    Open;
  end;
  SCreateCDS20(ADOQueryPrint,CDS_Print);
  SInitCDSData20(ADOQueryPrint,CDS_Print);
  try
    Moudle:=LoadLibrary('MakeQRBarcode.dll');
    @Makebar:=GetProcAddress(Moudle,'Make');
    @Mixtext:=GetProcAddress(Moudle,'MixText');
    Txt:=Trim(CDS_Print.fieldbyname('DYID').AsString);
    fImagePath:=ExtractFilePath(Application.ExeName)+'image\temp.bmp';
    if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName)+'image')) then
      CreateDirectory(pchar(ExtractFilePath(Application.ExeName)+'image'),nil);
    if FileExists(fImagePath) then DeleteFile(fImagePath);
    Makebar(pchar(Txt),Length(Txt),3,3,0,PChar(fImagePath),3);
  except
    application.MessageBox('条形码生成失败！','提示信息',MB_ICONERROR);
    exit;
  end;
  if FileExists(fPrintFile) then
  begin
    RMVariables['QRBARCODE']:=fImagePath;
    RM1.LoadFromFile(fPrintFile);
    //RM1.ShowReport;
    RM1.PrintReport;
  end else
  begin
    Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\'+trim(FBQName)+'.rmf'),'提示',0);
    exit;
  end;
end;

procedure TfrmBPZDY_PanelCX.initPL();
var i:integer;
begin
  i:=0;
  with Ord_SH do
  begin
    first;
    while not Eof do
    begin
      with Self.ScrollBox1 do
      begin
        TPanel(Controls[i]).Visible:=true;
        TPanel(Controls[i]).Color:=StrToInt('$'+Ord_SH.fieldbyname('ColDaiMa').Value);
        with TPanel(Controls[i]) do
        begin
          TLabel(Controls[0]).Caption:=Trim(Ord_SH.fieldbyname('PTID').AsString);
          TLabel(Controls[1]).Caption:=Trim(Ord_SH.fieldbyname('ColNameEng').AsString);
          TLabel(Controls[2]).Caption:=Trim(Ord_SH.fieldbyname('ColName').AsString);
          TLabel(Controls[3]).Caption:=Trim(Ord_SH.fieldbyname('ColNameKH').AsString);
        end;
      end;
      i:=i+1;
      Next;
    end;
  end;
  with Self.ScrollBox1 do
  begin
    TPanel(Controls[i]).Visible:=false;
    TPanel(Controls[i]).Color:=clBtnFace;
    with TPanel(Controls[i]) do
    begin
      TLabel(Controls[0]).Caption:='';
      TLabel(Controls[1]).Caption:='';
      TLabel(Controls[2]).Caption:='';
      TLabel(Controls[3]).Caption:='';
    end;
  end;
end;

procedure TfrmBPZDY_PanelCX.initPanel();
var i:integer;
begin
  {with ScrollBox1 do
  begin
    for i:=0 to ScrollBox1.ControlCount-1 do
    begin
      if TPanel(Controls[i]).Visible=False then
      begin
        TPanel(Controls[i]).Visible:=True;
        TPanel(Controls[i]).Color:=FColor;
        TPanel(Controls[i]).Hint:=FPTID;
        with TPanel(Controls[i]) do
        begin
          TLabel(Controls[0]).Caption:=Trim(FPTID);
          TLabel(Controls[1]).Caption:=Trim(FColNameEng);
          TLabel(Controls[2]).Caption:=Trim(FColName);
          TLabel(Controls[3]).Caption:=Trim(FColNameKH);
          TLabel(Controls[0]).Visible:=False;
          TLabel(Controls[1]).Visible:=False;
          TLabel(Controls[2]).Visible:=False;
          TLabel(Controls[3]).Visible:=False;
        end;
        Exit;
      end;
    end;
  end; }
end;

procedure TfrmBPZDY_PanelCX.initimageSH();
begin

end;

procedure TfrmBPZDY_PanelCX.SaveData();
begin

end;

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

procedure TfrmBPZDY_PanelCX.TBCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmBPZDY_PanelCX.FormShow(Sender: TObject);
var
  x:Integer;
begin
  Button2.Visible:=false;
  Button3.Visible:=false;
  if Canshu1<>'查询' then
  begin
    Button2.Visible:=True;
    Button1.Caption:='单面料打印';
  end
  else
  begin
    button3.Visible:=true;
    Button1.Caption:='客户标签打印';
  end;
  with ScrollBox1 do
  begin
    for x:=0 to ScrollBox1.ControlCount-1 do
    begin
      TPanel(Controls[x]).Visible:=false;
    end;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.* ');
    SQL.Add(',MXGS=(select count(C.PTID) from BP_ColZDY C where C.SKID=B.SKID and isnull(C.SKID,'''')<>'''') ');
    sql.add('from RT_PTColor A ');
    sql.Add('inner join BP_ColZDY B on B.PTID=A.PTID ');
    sql.Add('where B.SKID='''+trim(FColorFlag)+''' and isnull(B.SKID,'''')<>''''');
    sql.Add(' order by cast(B.ColNo as int)');
    Open;
  end;
  y:=1;
  my:=1;
  mz:=1;
  z:=ceil(ADOQueryTemp.fieldbyname('MXGS').AsInteger/50);
  LBCPAP.Caption:=inttostr(y)+'/'+inttostr(z);
  Label554.Caption:='1/1';
  SCreateCDS20(ADOQueryTemp,Ord_SH);
  SInitCDSData20(ADOQueryTemp,Ord_SH);
  SCreateCDS20(ADOQueryTemp,Ord_SHSel);
  InitSHByOrdBP_SH();
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.* from ML_Manage A ');
    sql.Add('where A.MBPID='''+trim(FBPID)+''' ');
    if FMLID<>'' then
    begin
      sql.Add(' and A.MLID='''+trim(FMLID)+''' ');
    end;
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,Ord_GX);
  SInitCDSData20(ADOQueryTemp,Ord_GX);
  SCreateCDS20(ADOQueryTemp,Ord_GXSel);
  if FMLID<>'' then
  begin
    SInitCDSData20(ADOQueryTemp,Ord_GXSel);
  end;
end;

procedure TfrmBPZDY_PanelCX.InitSHByOrdBP_SHSel();
var
  i,x,q:Integer;
begin
  with ScrollBox2 do
  begin
    for x:=0 to ScrollBox2.ControlCount-1 do
    begin
      TPanel(Controls[x]).Visible:=false;
    end;
  end;
  Ord_SHSel.DisableControls;
  with Ord_SHSel do
  begin
    First;
    i:=0;
    q:=1;
    while not Eof do
    begin
      if (q>(my-1)*50) and (q<=my*50) then
      begin
        with ScrollBox2 do
        begin
          TPanel(Controls[i]).Visible:=True;
          TPanel(Controls[i]).Hint:=Trim(Ord_SHSel.Fieldbyname('PTID').AsString);
          TPanel(Controls[i]).Color:=StrToInt('$'+Trim(Ord_SHSel.Fieldbyname('ColDaiMa').AsString));
          with TPanel(Controls[i]) do
          begin
            TLabel(Controls[0]).Caption:=Trim(Ord_SHSel.Fieldbyname('ColNo').AsString);
            TLabel(Controls[1]).Caption:=Trim(Ord_SHSel.Fieldbyname('ColNameKH').AsString);
            TLabel(Controls[0]).Visible:=true;
            TLabel(Controls[1]).Visible:=true;
            TLabel(Controls[0]).Color:=clWhite;
            TLabel(Controls[1]).Color:=clWhite;
          end;
        end;
        i:=i+1;
      end;
      q:=q+1;
      Next;
    end;
  end;
  Ord_SHSel.EnableControls;
end;

procedure TfrmBPZDY_PanelCX.InitSHByOrdBP_SH();
var
  i,x,q:Integer;
begin
  with ScrollBox1 do
  begin
    for x:=0 to ScrollBox1.ControlCount-1 do
    begin
      TPanel(Controls[x]).Visible:=false;
    end;
  end;
  Ord_SH.DisableControls;
  with Ord_SH do
  begin
    First;
    i:=0;
    q:=1;
    while not Eof do
    begin
      if (q>(y-1)*50) and (q<=y*50) then
      begin
        with ScrollBox1 do
        begin
          TPanel(Controls[i]).Visible:=True;
          TPanel(Controls[i]).Hint:=Trim(Ord_SH.Fieldbyname('PTID').AsString);
          TPanel(Controls[i]).Color:=StrToInt('$'+Trim(Ord_SH.Fieldbyname('ColDaiMa').AsString));
          with TPanel(Controls[i]) do
          begin
            TLabel(Controls[0]).Caption:=Trim(Ord_SH.Fieldbyname('ColNo').AsString);
            TLabel(Controls[1]).Caption:=Trim(Ord_SH.Fieldbyname('ColNameKH').AsString);
            TLabel(Controls[0]).Visible:=true;
            TLabel(Controls[1]).Visible:=true;
            TLabel(Controls[0]).Color:=clWhite;
            TLabel(Controls[1]).Color:=clWhite;
          end;
        end;
        i:=i+1;
      end;
      q:=q+1;
      Next;
    end;
  end;
  Ord_SH.EnableControls;
end;

procedure TfrmBPZDY_PanelCX.N1Click(Sender: TObject);
begin
  FrmBPZdy_YT:=TFrmBPZdy_YT.create(Self);
  with FrmBPZdy_YT do
  begin
    if Fint1='0' then
    begin
      Panel1.Color:=StrToInt('$'+Ord_SH.fieldbyname('ColDaiMa').asstring);
      Label1.Caption:=Ord_SH.fieldbyname('PTID').asstring;
      Label2.Caption:=Ord_SH.fieldbyname('ColNameEng').asstring;
      Label3.Caption:=Ord_SH.fieldbyname('ColName').asstring;
      Label4.Caption:=Ord_SH.fieldbyname('ColNameKH').asstring;
      Label5.Caption:=Ord_SH.fieldbyname('ColNo').asstring;
    end
    else
    begin
      Panel1.Color:=StrToInt('$'+Ord_SHSel.fieldbyname('ColDaiMa').asstring);
      Label1.Caption:=Ord_SHSel.fieldbyname('PTID').asstring;
      Label2.Caption:=Ord_SHSel.fieldbyname('ColNameEng').asstring;
      Label3.Caption:=Ord_SHSel.fieldbyname('ColName').asstring;
      Label4.Caption:=Ord_SHSel.fieldbyname('ColNameKH').asstring;
      Label5.Caption:=Ord_SHSel.fieldbyname('ColNo').asstring;
    end;
    if showmodal=1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmBPZDY_PanelCX.Panel1DblClick(Sender: TObject);
var i:Integer;
begin
  {with TPanel(Sender) do
  begin
    FPTID:=Trim(TLabel(Controls[0]).Caption);
    FColNameEng:=Trim(TLabel(Controls[1]).Caption);
    FColName:=Trim(TLabel(Controls[2]).Caption);
    FColNameKH:=Trim(TLabel(Controls[3]).Caption);
  end;
  if Ord_SH.Locate('PTID',FPTID,[])=False then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from RT_PTColor where PTID='''+Trim(FPTID)+'''');
      Open;
    end;
    with Ord_SH do
    begin
      Append;
      FieldByName('ColDaiMa').Value:=Trim(ADOQueryTemp.fieldbyname('ColDaiMa').AsString);
      FieldByName('PTID').Value:=FPTID;
      FieldByName('ColNameEng').Value:=FColNameEng;
      FieldByName('ColName').Value:=FColName;
      FieldByName('ColNameKH').Value:=FColNameKH;
      post;
    end;
  end;
  InitSHByOrdBP_SH();}
 // initPanel();
end;

procedure TfrmBPZDY_PanelCX.Panel101DblClick(Sender: TObject);
var i:Integer;
begin
  with TPanel(Sender) do
  begin
    FColNoZ:=Trim(TLabel(Controls[0]).Caption);  //色号
    FColNameKHZ:=Trim(TLabel(Controls[1]).Caption);   //客户颜色
  end;
  if Ord_SHSel.Locate('PTID',TPanel(Sender).Hint,[])=False then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from RT_PTColor where PTID='''+Trim(TPanel(Sender).Hint)+'''');
      Open;
    end;
    with Ord_SHSel do
    begin
      Append;
      FieldByName('ColDaiMa').Value:=Trim(ADOQueryTemp.fieldbyname('ColDaiMa').AsString);
      FieldByName('PTID').Value:=Trim(ADOQueryTemp.fieldbyname('PTID').AsString);
      FieldByName('ColNo').Value:=FColNoZ;
      FieldByName('ColNameKH').Value:=FColNameKHZ;
      post;
    end;
    i:=Ord_SHSel.RecordCount;
    mz:=ceil(i/50);
    label554.Caption:=inttostr(my)+'/'+inttostr(mz);
  end;
  Ord_SH.Locate('PTID',TPanel(Sender).Hint,[]);
  Ord_SH.Delete;
  InitSHByOrdBP_SH();
  InitSHByOrdBP_SHSel();
end;

procedure TfrmBPZDY_PanelCX.TV1CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if Ord_GXSel.IsEmpty then
  begin
    with Ord_GXSel do
    begin
      append;
      FieldByName('MLID').Value:=Trim(Ord_GX.fieldbyname('MLID').AsString);
      FieldByName('GYLXName').Value:=Trim(Ord_GX.fieldbyname('GYLXName').AsString);
      post;
    end;
  end
  else
  begin
    with Ord_GXSel do
    begin
      edit;
      FieldByName('MLID').Value:=Trim(Ord_GX.fieldbyname('MLID').AsString);
      FieldByName('GYLXName').Value:=Trim(Ord_GX.fieldbyname('GYLXName').AsString);
      post;
    end;
  end;
end;

procedure TfrmBPZDY_PanelCX.TV2CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if Ord_GXSel.IsEmpty then exit;
  Ord_GXSel.Delete;
end;

procedure TfrmBPZDY_PanelCX.Panel28DblClick(Sender: TObject);
var i:Integer;
begin
  with TPanel(Sender) do
  begin
    FColNoZ:=Trim(TLabel(Controls[0]).Caption);  //色号
    FColNameKHZ:=Trim(TLabel(Controls[1]).Caption);   //客户颜色
  end;
  if Ord_SH.Locate('PTID',TPanel(Sender).Hint,[])=False then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from RT_PTColor where PTID='''+Trim(TPanel(Sender).Hint)+'''');
      Open;
    end;
    with Ord_SH do
    begin
      Append;
      FieldByName('ColDaiMa').Value:=Trim(ADOQueryTemp.fieldbyname('ColDaiMa').AsString);
      FieldByName('PTID').Value:=TPanel(Sender).Hint;
      FieldByName('ColNo').Value:=FColNoZ;
      FieldByName('ColNameKH').Value:=FColNameKHZ;
      post;
    end;
    i:=Ord_SH.RecordCount;
    z:=ceil(i/50);
    LBCPAP.Caption:=inttostr(y)+'/'+inttostr(z);
  end;
  Ord_SHSel.Locate('PTID',TPanel(Sender).Hint,[]);
  Ord_SHSel.Delete;
  InitSHByOrdBP_SH();
  InitSHByOrdBP_SHSel();
end;

procedure TfrmBPZDY_PanelCX.Panel101MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Fint1:='0';
  Ord_SH.Locate('PTID',TPanel(Sender).Hint,[]);
end;

procedure TfrmBPZDY_PanelCX.Panel42MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Fint1:='1';
  Ord_SHSel.Locate('PTID',TPanel(Sender).Hint,[]);
end;

procedure TfrmBPZDY_PanelCX.Button1Click(Sender: TObject);
var
  maxno,BQName:string;
  j,i:Integer;
begin
  PanelTop.SetFocus;
  if Ord_GXSel.IsEmpty then exit;
  FCYID:=trim(Ord_GXSel.fieldbyname('MLID').asstring);
  with ScrollBox2 do
  begin
    for i:=0 to ScrollBox2.ControlCount-1 do
    begin
      if Controls[i] is TPanel then
      begin
        if TPanel(Controls[i]).Visible=True then
        begin
          maxno:=TPanel(Controls[i]).Hint;
          Ord_SHSel.Locate('PTID',maxno,[]);
          for j:=0 to StrToInt(ComboBox1.text)-1 do
          begin
            if Canshu1<>'查询' then
            begin
              BQName:='单面料标签染色';
              SavePrint(FCYID,maxno,BQName);
            end
            else
            begin
              BQName:='客户标签';
              SavePrint(FCYID,maxno,BQName);
            end;
          end;
        end;
      end;
    end;
  end;
  //Application.MessageBox('打印成功','提示');
end;

procedure TfrmBPZDY_PanelCX.SYClick(Sender: TObject);
var x:integer;
begin
  if my=1 then exit;
  SY.Enabled:=False;
  my:=my-1;
  if my<mz then
  begin
    XY.Enabled:=True;
  end
  else
  begin
    XY.Enabled:=False;
  end;
  label554.Caption:=inttostr(my)+'/'+inttostr(mz);
  InitSHByOrdBP_SHSel();
  SY.Enabled:=true;
end;

procedure TfrmBPZDY_PanelCX.BTLPClick(Sender: TObject);
var x:integer;
begin
  if y=1 then exit;
  BTLP.Enabled:=False;
  y:=y-1;
  if y<z then
  begin
    BTNP.Enabled:=True;
  end
  else
  begin
    BTNP.Enabled:=False;
  end;
  LBCPAP.Caption:=inttostr(y)+'/'+inttostr(z);
  InitSHByOrdBP_SH();
  BTLP.Enabled:=true;
end;

procedure TfrmBPZDY_PanelCX.BTNPClick(Sender: TObject);
var x:integer;
begin
  if y=z then exit;
  BTNP.Enabled:=False;
  y:=y+1;
  if y>0 then
  begin
    BTLP.Enabled:=True;
  end
  else
  begin
    BTLP.Enabled:=False;
  end;
  LBCPAP.Caption:=inttostr(y)+'/'+inttostr(z);
  InitSHByOrdBP_SH();
  BTNP.Enabled:=true;
end;

procedure TfrmBPZDY_PanelCX.XYClick(Sender: TObject);
var x:integer;
begin
  if my=mz then exit;
  XY.Enabled:=False;
  my:=my+1;
  if my>0 then
  begin
    SY.Enabled:=True;
  end
  else
  begin
    SY.Enabled:=False;
  end;
  label554.Caption:=inttostr(my)+'/'+inttostr(mz);
  InitSHByOrdBP_SHSel();
  XY.Enabled:=true;
end;

procedure TfrmBPZDY_PanelCX.FormCreate(Sender: TObject);
begin
  Canshu1:=Trim(DParameters1);
end;

procedure TfrmBPZDY_PanelCX.Button2Click(Sender: TObject);
var
  maxno,BQName:string;
  j,i:Integer;
begin
  PanelTop.SetFocus;
  if Ord_GXSel.IsEmpty then exit;
  FCYID:=trim(Ord_GXSel.fieldbyname('MLID').asstring);
  with ScrollBox2 do
  begin
    for i:=0 to ScrollBox2.ControlCount-1 do
    begin
      if Controls[i] is TPanel then
      begin
        if TPanel(Controls[i]).Visible=True then
        begin
          maxno:=TPanel(Controls[i]).Hint;
          Ord_SHSel.Locate('PTID',maxno,[]);
          for j:=0 to StrToInt(ComboBox1.text)-1 do
          begin
            BQName:='小色标';
            SavePrint(FCYID,maxno,BQName);
          end;
        end;
      end;
    end;
  end;
end;

procedure TfrmBPZDY_PanelCX.Button3Click(Sender: TObject);
var
  maxno,BQName:string;
  j,i:Integer;
begin
  PanelTop.SetFocus;
  if Ord_GXSel.IsEmpty then exit;
  FCYID:=trim(Ord_GXSel.fieldbyname('MLID').asstring);
  with ScrollBox2 do
  begin
    for i:=0 to ScrollBox2.ControlCount-1 do
    begin
      if Controls[i] is TPanel then
      begin
        if TPanel(Controls[i]).Visible=True then
        begin
          maxno:=TPanel(Controls[i]).Hint;
          Ord_SHSel.Locate('PTID',maxno,[]);
          for j:=0 to StrToInt(ComboBox1.text)-1 do
          begin
            BQName:='英标';
            SavePrint(FCYID,maxno,BQName);
          end;
        end;
      end;
    end;
  end;
end;

end.
