unit U_RTPTColor;

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,Math, Menus, cxCalendar,
  cxPC, Buttons;

type
  TfrmRTPTColor = class(TForm)
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ADOQuery6: TADOQuery;
    cxGridPopupMenu2: TcxGridPopupMenu;
    adoqueryPicture: TADOQuery;
    ScrollBox2: TScrollBox;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Panel2: TPanel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Panel3: TPanel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Panel4: TPanel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Panel5: TPanel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    Panel6: TPanel;
    Label21: TLabel;
    Label22: TLabel;
    Label23: TLabel;
    Label24: TLabel;
    Panel7: TPanel;
    Label25: TLabel;
    Label26: TLabel;
    Label27: TLabel;
    Label28: TLabel;
    Panel8: TPanel;
    Label29: TLabel;
    Label30: TLabel;
    Label31: TLabel;
    Label32: TLabel;
    Panel9: TPanel;
    Label33: TLabel;
    Label34: TLabel;
    Label35: TLabel;
    Label36: TLabel;
    Panel10: TPanel;
    Label37: TLabel;
    Label38: TLabel;
    Label39: TLabel;
    Label40: TLabel;
    Panel11: TPanel;
    Label41: TLabel;
    Label42: TLabel;
    Label43: TLabel;
    Label44: TLabel;
    Panel12: TPanel;
    Label45: TLabel;
    Label46: TLabel;
    Label47: TLabel;
    Label48: TLabel;
    Panel13: TPanel;
    Label49: TLabel;
    Label50: TLabel;
    Label51: TLabel;
    Label52: TLabel;
    Panel14: TPanel;
    Label53: TLabel;
    Label54: TLabel;
    Label55: TLabel;
    Label56: TLabel;
    Panel15: TPanel;
    Label57: TLabel;
    Label58: TLabel;
    Label59: TLabel;
    Label60: TLabel;
    Panel16: TPanel;
    Label61: TLabel;
    Label62: TLabel;
    Label63: TLabel;
    Label64: TLabel;
    Panel17: TPanel;
    Label65: TLabel;
    Label66: TLabel;
    Label67: TLabel;
    Label68: TLabel;
    Panel18: TPanel;
    Label69: TLabel;
    Label70: TLabel;
    Label71: TLabel;
    Label72: TLabel;
    Panel19: TPanel;
    Label73: TLabel;
    Label74: TLabel;
    Label75: TLabel;
    Label76: TLabel;
    Panel20: TPanel;
    Label77: TLabel;
    Label78: TLabel;
    Label79: TLabel;
    Label80: TLabel;
    Panel21: TPanel;
    Label81: TLabel;
    Label82: TLabel;
    Label83: TLabel;
    Label84: TLabel;
    Panel22: TPanel;
    Label85: TLabel;
    Label86: TLabel;
    Label87: TLabel;
    Label88: TLabel;
    Panel23: TPanel;
    Label89: TLabel;
    Label90: TLabel;
    Label91: TLabel;
    Label92: TLabel;
    Panel24: TPanel;
    Label93: TLabel;
    Label94: TLabel;
    Label95: TLabel;
    Label96: TLabel;
    Panel25: TPanel;
    Label97: TLabel;
    Label98: TLabel;
    Label99: TLabel;
    Label100: TLabel;
    Panel26: TPanel;
    Label101: TLabel;
    Label102: TLabel;
    Label103: TLabel;
    Label104: TLabel;
    Panel27: TPanel;
    Label105: TLabel;
    Label106: TLabel;
    Label107: TLabel;
    Label108: TLabel;
    Panel28: TPanel;
    Label109: TLabel;
    Label110: TLabel;
    Label111: TLabel;
    Label112: TLabel;
    Panel29: TPanel;
    Label113: TLabel;
    Label114: TLabel;
    Label115: TLabel;
    Label116: TLabel;
    Panel30: TPanel;
    Label117: TLabel;
    Label118: TLabel;
    Label119: TLabel;
    Label120: TLabel;
    Panel31: TPanel;
    Label121: TLabel;
    Label122: TLabel;
    Label123: TLabel;
    Label124: TLabel;
    Panel32: TPanel;
    Label125: TLabel;
    Label126: TLabel;
    Label127: TLabel;
    Label128: TLabel;
    Panel33: TPanel;
    Label129: TLabel;
    Label130: TLabel;
    Label131: TLabel;
    Label132: TLabel;
    Panel34: TPanel;
    Label133: TLabel;
    Label134: TLabel;
    Label135: TLabel;
    Label136: TLabel;
    Panel35: TPanel;
    Label137: TLabel;
    Label138: TLabel;
    Label139: TLabel;
    Label140: TLabel;
    Panel36: TPanel;
    Label141: TLabel;
    Label142: TLabel;
    Label143: TLabel;
    Label144: TLabel;
    Panel37: TPanel;
    Label145: TLabel;
    Label146: TLabel;
    Label147: TLabel;
    Label148: TLabel;
    Panel38: TPanel;
    Label149: TLabel;
    Label150: TLabel;
    Label151: TLabel;
    Label152: TLabel;
    Panel39: TPanel;
    Label153: TLabel;
    Label154: TLabel;
    Label155: TLabel;
    Label156: TLabel;
    Panel40: TPanel;
    Label157: TLabel;
    Label158: TLabel;
    Label159: TLabel;
    Label160: TLabel;
    Panel41: TPanel;
    Label161: TLabel;
    Label162: TLabel;
    Label163: TLabel;
    Label164: TLabel;
    Panel42: TPanel;
    Label165: TLabel;
    Label166: TLabel;
    Label167: TLabel;
    Label168: TLabel;
    Panel43: TPanel;
    Label169: TLabel;
    Label170: TLabel;
    Label171: TLabel;
    Label172: TLabel;
    Panel44: TPanel;
    Label173: TLabel;
    Label174: TLabel;
    Label175: TLabel;
    Label176: TLabel;
    Panel45: TPanel;
    Label177: TLabel;
    Label178: TLabel;
    Label179: TLabel;
    Label180: TLabel;
    Panel46: TPanel;
    Label181: TLabel;
    Label182: TLabel;
    Label183: TLabel;
    Label184: TLabel;
    Panel47: TPanel;
    Label185: TLabel;
    Label186: TLabel;
    Label187: TLabel;
    Label188: TLabel;
    Panel48: TPanel;
    Label189: TLabel;
    Label190: TLabel;
    Label191: TLabel;
    Label192: TLabel;
    Panel49: TPanel;
    Label193: TLabel;
    Label194: TLabel;
    Label195: TLabel;
    Label196: TLabel;
    Panel50: TPanel;
    Label197: TLabel;
    Label198: TLabel;
    Label199: TLabel;
    Label200: TLabel;
    Panel51: TPanel;
    Label201: TLabel;
    Label202: TLabel;
    Label203: TLabel;
    Label204: TLabel;
    Panel52: TPanel;
    Label205: TLabel;
    Label206: TLabel;
    Label207: TLabel;
    Label208: TLabel;
    Panel53: TPanel;
    Label209: TLabel;
    Label210: TLabel;
    Label211: TLabel;
    Label212: TLabel;
    Panel54: TPanel;
    Label213: TLabel;
    Label214: TLabel;
    Label215: TLabel;
    Label216: TLabel;
    Panel55: TPanel;
    Label217: TLabel;
    Label218: TLabel;
    Label219: TLabel;
    Label220: TLabel;
    Panel56: TPanel;
    Label221: TLabel;
    Label222: TLabel;
    Label223: TLabel;
    Label224: TLabel;
    Panel57: TPanel;
    Label225: TLabel;
    Label226: TLabel;
    Label227: TLabel;
    Label228: TLabel;
    Panel58: TPanel;
    Label229: TLabel;
    Label230: TLabel;
    Label231: TLabel;
    Label232: TLabel;
    Panel59: TPanel;
    Label233: TLabel;
    Label234: TLabel;
    Label235: TLabel;
    Label236: TLabel;
    Panel60: TPanel;
    Label237: TLabel;
    Label238: TLabel;
    Label239: TLabel;
    Label240: TLabel;
    Panel61: TPanel;
    Label241: TLabel;
    Label242: TLabel;
    Label243: TLabel;
    Label244: TLabel;
    Panel62: TPanel;
    Label245: TLabel;
    Label246: TLabel;
    Label247: TLabel;
    Label248: TLabel;
    Panel63: TPanel;
    Label249: TLabel;
    Label250: TLabel;
    Label251: TLabel;
    Label252: TLabel;
    Panel64: TPanel;
    Label253: TLabel;
    Label254: TLabel;
    Label255: TLabel;
    Label256: TLabel;
    Panel65: TPanel;
    Label257: TLabel;
    Label258: TLabel;
    Label259: TLabel;
    Label260: TLabel;
    Panel66: TPanel;
    Label261: TLabel;
    Label262: TLabel;
    Label263: TLabel;
    Label264: TLabel;
    Panel67: TPanel;
    Label265: TLabel;
    Label266: TLabel;
    Label267: TLabel;
    Label268: TLabel;
    Panel68: TPanel;
    Label269: TLabel;
    Label270: TLabel;
    Label271: TLabel;
    Label272: TLabel;
    Panel69: TPanel;
    Label273: TLabel;
    Label274: TLabel;
    Label275: TLabel;
    Label276: TLabel;
    Panel70: TPanel;
    Label277: TLabel;
    Label278: TLabel;
    Label279: TLabel;
    Label280: TLabel;
    Panel71: TPanel;
    Label281: TLabel;
    Label282: TLabel;
    Label283: TLabel;
    Label284: TLabel;
    Panel72: TPanel;
    Label285: TLabel;
    Label286: TLabel;
    Label287: TLabel;
    Label288: TLabel;
    Panel73: TPanel;
    Label289: TLabel;
    Label290: TLabel;
    Label291: TLabel;
    Label292: TLabel;
    Panel74: TPanel;
    Label293: TLabel;
    Label294: TLabel;
    Label295: TLabel;
    Label296: TLabel;
    Panel75: TPanel;
    Label297: TLabel;
    Label298: TLabel;
    Label299: TLabel;
    Label300: TLabel;
    Panel76: TPanel;
    Label301: TLabel;
    Label302: TLabel;
    Label303: TLabel;
    Label304: TLabel;
    Panel77: TPanel;
    Label305: TLabel;
    Label306: TLabel;
    Label307: TLabel;
    Label308: TLabel;
    Panel78: TPanel;
    Label309: TLabel;
    Label310: TLabel;
    Label311: TLabel;
    Label312: TLabel;
    Panel79: TPanel;
    Label313: TLabel;
    Label314: TLabel;
    Label315: TLabel;
    Label316: TLabel;
    Panel80: TPanel;
    Label317: TLabel;
    Label318: TLabel;
    Label319: TLabel;
    Label320: TLabel;
    Panel81: TPanel;
    Label321: TLabel;
    Label322: TLabel;
    Label323: TLabel;
    Label324: TLabel;
    Panel82: TPanel;
    Label325: TLabel;
    Label326: TLabel;
    Label327: TLabel;
    Label328: TLabel;
    Panel83: TPanel;
    Label329: TLabel;
    Label330: TLabel;
    Label331: TLabel;
    Label332: TLabel;
    Panel84: TPanel;
    Label333: TLabel;
    Label334: TLabel;
    Label335: TLabel;
    Label336: TLabel;
    Panel85: TPanel;
    Label337: TLabel;
    Label338: TLabel;
    Label339: TLabel;
    Label340: TLabel;
    Panel86: TPanel;
    Label341: TLabel;
    Label342: TLabel;
    Label343: TLabel;
    Label344: TLabel;
    Panel87: TPanel;
    Label345: TLabel;
    Label346: TLabel;
    Label347: TLabel;
    Label348: TLabel;
    Panel88: TPanel;
    Label349: TLabel;
    Label350: TLabel;
    Label351: TLabel;
    Label352: TLabel;
    Panel89: TPanel;
    Label353: TLabel;
    Label354: TLabel;
    Label355: TLabel;
    Label356: TLabel;
    Panel90: TPanel;
    Label357: TLabel;
    Label358: TLabel;
    Label359: TLabel;
    Label360: TLabel;
    Panel91: TPanel;
    Label361: TLabel;
    Label362: TLabel;
    Label363: TLabel;
    Label364: TLabel;
    Panel92: TPanel;
    Label365: TLabel;
    Label366: TLabel;
    Label367: TLabel;
    Label368: TLabel;
    Panel93: TPanel;
    Label369: TLabel;
    Label370: TLabel;
    Label371: TLabel;
    Label372: TLabel;
    Panel94: TPanel;
    Label373: TLabel;
    Label374: TLabel;
    Label375: TLabel;
    Label376: TLabel;
    Panel95: TPanel;
    Label377: TLabel;
    Label378: TLabel;
    Label379: TLabel;
    Label380: TLabel;
    Panel96: TPanel;
    Label381: TLabel;
    Label382: TLabel;
    Label383: TLabel;
    Label384: TLabel;
    Panel97: TPanel;
    Label385: TLabel;
    Label386: TLabel;
    Label387: TLabel;
    Label388: TLabel;
    Panel98: TPanel;
    Label389: TLabel;
    Label390: TLabel;
    Label391: TLabel;
    Label392: TLabel;
    Panel99: TPanel;
    Label393: TLabel;
    Label394: TLabel;
    Label395: TLabel;
    Label396: TLabel;
    Panel100: TPanel;
    Label397: TLabel;
    Label398: TLabel;
    Label399: TLabel;
    Label400: TLabel;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    Ord_SH: TClientDataSet;
    Panel201: TPanel;
    ScrollBox3: TScrollBox;
    Label521: TLabel;
    Label522: TLabel;
    BTLP: TButton;
    BTNP: TButton;
    Button1: TButton;
    PTID: TEdit;
    ColName: TEdit;
    Edit1: TEdit;
    LBCPAP: TLabel;
    Label553: TLabel;
    Label556: TLabel;
    ColNameKH: TEdit;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BTLPClick(Sender: TObject);
    procedure BTNPClick(Sender: TObject);
    procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure ColNameKeyPress(Sender: TObject; var Key: Char);
    procedure Panel1DblClick(Sender: TObject);
  private
    FColor:TColor;
    y,Z,my,mz:integer;
    { Private declarations }
  public
    FPTID,FColNameEng,FColName,FColNameKH:string;
    procedure initimageSH();
    procedure initimageSHSql();
    { Public declarations }
  end;
var
  frmRTPTColor: TfrmRTPTColor;
implementation
uses
  U_DataLink,U_RTFun;

{$R *.dfm}
procedure TfrmRTPTColor.initimageSH();
var
  i,j,x:Integer;
begin
  if y=20 then
  begin
    with ScrollBox2 do
    begin
      for x:=0 to ScrollBox2.ControlCount-1 do
      begin
        TPanel(Controls[x]).Visible:=false;
      end;
    end;
  end;

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from RT_PTColor ');
    sql.Add('where 1=1 ');
    if PTID.Text<>'' then
    begin
      sql.Add(' and PTID='''+trim(PTID.Text)+'''');
    end;
    if ColName.Text<>'' then
    begin
      sql.Add(' and ColName='''+trim(ColName.Text)+'''');
    end;
    if ColNameKH.Text<>'' then
    begin
      sql.Add(' and ColNameKH like'''+'%'+trim(ColNameKH.Text)+'%'+'''');
    end;
    if (PTID.Text='') and (ColName.Text='') then
    begin
      sql.Add(' and PTInt>'''+trim(IntToStr((y-1)*100))+'''');
      sql.Add(' and PTInt<='''+trim(IntToStr(y*100))+'''');
    end;
    sql.Add(' order by PTID ');
    Open;
  end;
  if ADOQueryTemp.IsEmpty then
  begin
    Application.MessageBox('数据不存在！','提示',0);
    Exit;
  end;
  ADOQueryTemp.DisableControls;
  with ADOQueryTemp do
  begin
    First;
    i:=0;
    while not Eof do
    begin
      with ScrollBox2 do
      begin
        TPanel(Controls[i]).Visible:=True;
        TPanel(Controls[i]).Hint:=Trim(ADOQueryTemp.Fieldbyname('PTID').AsString);
        TPanel(Controls[i]).Color:=StrToInt('$'+Trim(ADOQueryTemp.Fieldbyname('ColDaiMa').AsString));
        with TPanel(Controls[i]) do
        begin
          TLabel(Controls[0]).Caption:=Trim(ADOQueryTemp.Fieldbyname('PTID').AsString);
          TLabel(Controls[1]).Caption:=Trim(ADOQueryTemp.Fieldbyname('ColNameEng').AsString);
          TLabel(Controls[2]).Caption:=Trim(ADOQueryTemp.Fieldbyname('ColName').AsString);
          TLabel(Controls[3]).Caption:=Trim(ADOQueryTemp.Fieldbyname('ColNameKH').AsString);
          TLabel(Controls[0]).Visible:=False;
          TLabel(Controls[1]).Visible:=False;
          TLabel(Controls[2]).Visible:=False;
          TLabel(Controls[3]).Visible:=False;
        end;
      end;
      i:=i+1;
      Next;
    end;
  end;
  ADOQueryTemp.EnableControls;
end;

procedure TfrmRTPTColor.initimageSHSql();
var
  i,j,x:Integer;
begin
  with ScrollBox2 do
  begin
    for x:=0 to ScrollBox2.ControlCount-1 do
    begin
      TPanel(Controls[x]).Visible:=false;
    end;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from RT_PTColor ');
    sql.Add('where 1=1 ');
    if Trim(PTID.Text)<>'' then
    begin
      sql.Add(' and PTID='''+trim(PTID.Text)+'''');
    end;
    if Trim(ColName.Text)<>'' then
    begin
      sql.Add(' and ColName='''+trim(ColName.Text)+'''');
    end;
    if Trim(ColNameKH.Text)<>'' then
    begin
      sql.Add(' and ColNameKH like'''+'%'+trim(ColNameKH.Text)+'%'+'''');
    end;
    if (PTID.Text='') and (ColName.Text='') and (ColNameKH.Text='') then
    begin
      sql.Add(' and PTInt>'''+trim(IntToStr((y-1)*100))+'''');
      sql.Add(' and PTInt<='''+trim(IntToStr(y*100))+'''');
      z:=20;
    end else
    begin
      y:=1;
      z:=1;
    end;
    sql.Add(' order by PTID ');
    Open;
  end;
  if ADOQueryTemp.IsEmpty then
  begin
    Application.MessageBox('数据不存在！','提示',0);
    Exit;
  end;
  ADOQueryTemp.DisableControls;
  with ADOQueryTemp do
  begin
    First;
    i:=0;
    while not Eof do
    begin
      with ScrollBox2 do
      begin
        TPanel(Controls[i]).Visible:=True;
        TPanel(Controls[i]).Hint:=Trim(ADOQueryTemp.Fieldbyname('PTID').AsString);
        TPanel(Controls[i]).Color:=StrToInt('$'+Trim(ADOQueryTemp.Fieldbyname('ColDaiMa').AsString));
        with TPanel(Controls[i]) do
        begin
          TLabel(Controls[0]).Caption:=Trim(ADOQueryTemp.Fieldbyname('PTID').AsString);
          TLabel(Controls[1]).Caption:=Trim(ADOQueryTemp.Fieldbyname('ColNameEng').AsString);
          TLabel(Controls[2]).Caption:=Trim(ADOQueryTemp.Fieldbyname('ColName').AsString);
          TLabel(Controls[3]).Caption:=Trim(ADOQueryTemp.Fieldbyname('ColNameKH').AsString);
          TLabel(Controls[0]).Visible:=False;
          TLabel(Controls[1]).Visible:=False;
          TLabel(Controls[2]).Visible:=False;
          TLabel(Controls[3]).Visible:=False;
        end;
      end;
      i:=i+1;
      Next;
    end;
  end;
  ADOQueryTemp.EnableControls;
  LBCPAP.Caption:=IntToStr(y)+'/'+inttostr(Z);
end;



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

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

procedure TfrmRTPTColor.FormShow(Sender: TObject);
var
  x:Integer;
begin
  my:=1;
  y:=1;
  z:=20;
  LBCPAP.Caption:=inttostr(y)+'/'+inttostr(z);
  initimageSH();
end;

procedure TfrmRTPTColor.BTLPClick(Sender: TObject);
begin
  if y=1 then exit;
  y:=y-1;
  initimageSH();
  LBCPAP.Caption:=inttostr(y)+'/'+inttostr(z);
end;

procedure TfrmRTPTColor.BTNPClick(Sender: TObject);
begin
  if y=z then exit;
  y:=y+1;
  initimageSH();
  LBCPAP.Caption:=inttostr(y)+'/'+inttostr(z);
end;

procedure TfrmRTPTColor.Panel1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  i:Integer;
begin
  FColor:=TPanel(Sender).Color;
  with TPanel(Sender) do
  begin
    for i:=0 to 3 do
    begin
      if TLabel(Controls[i]).Visible=false then
        TLabel(Controls[i]).Visible:=True
      else
        TLabel(Controls[i]).Visible:=false;
      TLabel(Controls[i]).Color:=clWhite;
    end;
    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;
end;

procedure TfrmRTPTColor.ColNameKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    initimageSHSql();
  end;
end;

procedure TfrmRTPTColor.Panel1DblClick(Sender: TObject);
begin
  ModalResult:=1;
end;

end.
