unit U_BPZdy_LRSHK;

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

type
  TfrmBPZDY_LRSHK = class(TForm)
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DataSource1: TDataSource;
    ClientDataSet1: TClientDataSet;
    ADOConnection1: TADOConnection;
    ThreeImgList: TImageList;
    DataSource2: TDataSource;
    ML_GYS: TClientDataSet;
    DataSource3: TDataSource;
    ML_GX: TClientDataSet;
    ADOQuery3: TADOQuery;
    Panel2: TPanel;
    Panel4: TPanel;
    Panel5: TPanel;
    DataSource4: TDataSource;
    ADOQueryTree: TADOQuery;
    Order_Tree: TClientDataSet;
    cxGridPopupMenu1: TcxGridPopupMenu;
    cxGridPopupMenu2: TcxGridPopupMenu;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyleRepository2: TcxStyleRepository;
    cxStyle2: TcxStyle;
    cxSplitter1: TcxSplitter;
    ScrollBox1: TScrollBox;
    ToolBar2: TToolBar;
    ToolBar1: TToolBar;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    BPNameM: TEdit;
    BPCodeM: TEdit;
    TBClose: TToolButton;
    adoqueryPicture: TADOQuery;
    ScrollBox2: TScrollBox;
    Panel3: TPanel;
    Button1: TButton;
    THB: TToolButton;
    TCF: TToolButton;
    ToolButton1: TToolButton;
    TXZCol: TToolButton;
    Panel101: TPanel;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    Panel9: TPanel;
    Panel11: TPanel;
    Panel12: TPanel;
    Label5: TLabel;
    Edit5: TEdit;
    Edit6: TEdit;
    Panel13: TPanel;
    Panel14: TPanel;
    Label6: TLabel;
    Edit7: TEdit;
    Edit8: TEdit;
    Panel15: TPanel;
    Panel16: TPanel;
    Label7: TLabel;
    Edit9: TEdit;
    Edit10: TEdit;
    Panel17: TPanel;
    Panel18: TPanel;
    Label8: TLabel;
    Edit11: TEdit;
    Edit12: TEdit;
    Panel19: TPanel;
    Panel20: TPanel;
    Label9: TLabel;
    Edit13: TEdit;
    Edit14: TEdit;
    Panel21: TPanel;
    Panel22: TPanel;
    Label10: TLabel;
    Edit15: TEdit;
    Edit16: TEdit;
    Panel23: TPanel;
    Panel24: TPanel;
    Label11: TLabel;
    Edit17: TEdit;
    Edit18: TEdit;
    Panel25: TPanel;
    Panel26: TPanel;
    Label12: TLabel;
    Edit19: TEdit;
    Edit20: TEdit;
    Panel27: TPanel;
    Panel28: TPanel;
    Label13: TLabel;
    Edit21: TEdit;
    Edit22: TEdit;
    Panel29: TPanel;
    Panel30: TPanel;
    Label14: TLabel;
    Edit23: TEdit;
    Edit24: TEdit;
    Panel31: TPanel;
    Panel32: TPanel;
    Label15: TLabel;
    Edit25: TEdit;
    Edit26: TEdit;
    Panel33: TPanel;
    Panel34: TPanel;
    Label16: TLabel;
    Edit27: TEdit;
    Edit28: TEdit;
    Panel35: TPanel;
    Panel36: TPanel;
    Label17: TLabel;
    Edit29: TEdit;
    Edit30: TEdit;
    Panel37: TPanel;
    Panel38: TPanel;
    Label18: TLabel;
    Edit31: TEdit;
    Edit32: TEdit;
    Panel39: TPanel;
    Panel40: TPanel;
    Label19: TLabel;
    Edit33: TEdit;
    Edit34: TEdit;
    Panel41: TPanel;
    Panel42: TPanel;
    Label20: TLabel;
    Edit35: TEdit;
    Edit36: TEdit;
    Panel43: TPanel;
    Panel44: TPanel;
    Label21: TLabel;
    Edit37: TEdit;
    Edit38: TEdit;
    Panel45: TPanel;
    Panel46: TPanel;
    Label22: TLabel;
    Edit39: TEdit;
    Edit40: TEdit;
    Panel47: TPanel;
    Panel48: TPanel;
    Label23: TLabel;
    Edit41: TEdit;
    Edit42: TEdit;
    Panel49: TPanel;
    Panel50: TPanel;
    Label24: TLabel;
    Edit43: TEdit;
    Edit44: TEdit;
    Panel51: TPanel;
    Panel52: TPanel;
    Label25: TLabel;
    Edit45: TEdit;
    Edit46: TEdit;
    Panel53: TPanel;
    Panel54: TPanel;
    Label26: TLabel;
    Edit47: TEdit;
    Edit48: TEdit;
    Panel55: TPanel;
    Panel56: TPanel;
    Label27: TLabel;
    Edit49: TEdit;
    Edit50: TEdit;
    Panel57: TPanel;
    Panel58: TPanel;
    Label28: TLabel;
    Edit51: TEdit;
    Edit52: TEdit;
    Panel59: TPanel;
    Panel60: TPanel;
    Label29: TLabel;
    Edit53: TEdit;
    Edit54: TEdit;
    Panel61: TPanel;
    Panel62: TPanel;
    Label30: TLabel;
    Edit55: TEdit;
    Edit56: TEdit;
    Panel63: TPanel;
    Panel64: TPanel;
    Label31: TLabel;
    Edit57: TEdit;
    Edit58: TEdit;
    Panel65: TPanel;
    Panel66: TPanel;
    Label32: TLabel;
    Edit59: TEdit;
    Edit60: TEdit;
    Panel67: TPanel;
    Panel68: TPanel;
    Label33: TLabel;
    Edit61: TEdit;
    Edit62: TEdit;
    Panel69: TPanel;
    Panel70: TPanel;
    Label34: TLabel;
    Edit63: TEdit;
    Edit64: TEdit;
    Panel71: TPanel;
    Panel72: TPanel;
    Label35: TLabel;
    Edit65: TEdit;
    Edit66: TEdit;
    Panel73: TPanel;
    Panel74: TPanel;
    Label36: TLabel;
    Edit67: TEdit;
    Edit68: TEdit;
    Panel75: TPanel;
    Panel76: TPanel;
    Label37: TLabel;
    Edit69: TEdit;
    Edit70: TEdit;
    OrdBP_SHWH: TClientDataSet;
    Panel10: TPanel;
    Label4: TLabel;
    Edit3: TEdit;
    Edit4: TEdit;
    Panel8: TPanel;
    Label3: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    N2: TMenuItem;
    cxStyle3: TcxStyle;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    V1Ssel: TcxGridDBColumn;
    V1BPCode: TcxGridDBColumn;
    V1BPName: TcxGridDBColumn;
    V1BPKZ: TcxGridDBColumn;
    V1BPJS: TcxGridDBColumn;
    V1BPID: TcxGridDBColumn;
    V1Column2: TcxGridDBColumn;
    V1SKID: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    cxDBTreeList1: TcxDBTreeList;
    treeName1: TcxDBTreeListColumn;
    Panel6: TPanel;
    Panel7: TPanel;
    Label38: TLabel;
    Edit71: TEdit;
    Edit72: TEdit;
    Panel77: TPanel;
    Panel78: TPanel;
    Label39: TLabel;
    Edit73: TEdit;
    Edit74: TEdit;
    Panel79: TPanel;
    Panel80: TPanel;
    Label40: TLabel;
    Edit75: TEdit;
    Edit76: TEdit;
    Panel81: TPanel;
    Panel82: TPanel;
    Label41: TLabel;
    Edit77: TEdit;
    Edit78: TEdit;
    Panel83: TPanel;
    Panel84: TPanel;
    Label42: TLabel;
    Edit79: TEdit;
    Edit80: TEdit;
    Panel85: TPanel;
    Panel86: TPanel;
    Label43: TLabel;
    Edit81: TEdit;
    Edit82: TEdit;
    Panel87: TPanel;
    Panel88: TPanel;
    Label44: TLabel;
    Edit83: TEdit;
    Edit84: TEdit;
    Panel89: TPanel;
    Panel90: TPanel;
    Label45: TLabel;
    Edit85: TEdit;
    Edit86: TEdit;
    Panel91: TPanel;
    Panel92: TPanel;
    Label46: TLabel;
    Edit87: TEdit;
    Edit88: TEdit;
    Panel93: TPanel;
    Panel94: TPanel;
    Label47: TLabel;
    Edit89: TEdit;
    Edit90: TEdit;
    Panel95: TPanel;
    Panel96: TPanel;
    Label48: TLabel;
    Edit91: TEdit;
    Edit92: TEdit;
    Panel97: TPanel;
    Panel98: TPanel;
    Label49: TLabel;
    Edit93: TEdit;
    Edit94: TEdit;
    Panel99: TPanel;
    Panel100: TPanel;
    Label50: TLabel;
    Edit95: TEdit;
    Edit96: TEdit;
    Panel102: TPanel;
    Panel103: TPanel;
    Label51: TLabel;
    Edit97: TEdit;
    Edit98: TEdit;
    Panel104: TPanel;
    Panel105: TPanel;
    Label52: TLabel;
    Edit99: TEdit;
    Edit100: TEdit;
    Panel106: TPanel;
    label554: TLabel;
    Label555: TLabel;
    SY: TButton;
    XY: TButton;
    TDY: TToolButton;
    Panel107: TPanel;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    DataSource5: TDataSource;
    Ord_Sel: TClientDataSet;
    Label53: TLabel;
    SKID: TEdit;
    V2SKID: TcxGridDBColumn;
    Button2: TButton;
    Panel108: TPanel;
    BClose: TButton;
    Label54: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBSaveClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BPNamehange(Sender: TObject);
    procedure V1NotePropertiesEditValueChanged(Sender: TObject);
    procedure V1HelpTypePropertiesEditValueChanged(Sender: TObject);
    procedure v1note1PropertiesEditValueChanged(Sender: TObject);
    procedure V1BPCodePropertiesEditValueChanged(Sender: TObject);
    procedure V1BPNamePropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure BPCodeMChange(Sender: TObject);
    procedure Tv3CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure TPBLBClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure cxDBTreeList1Click(Sender: TObject);
    procedure TSHClick(Sender: TObject);
    procedure TV1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Button1Click(Sender: TObject);
    procedure THBClick(Sender: TObject);
    procedure TCFClick(Sender: TObject);
    procedure TXZColClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure Panel101MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure TDYClick(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure Edit1Exit(Sender: TObject);
    procedure Edit2Exit(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure XYClick(Sender: TObject);
    procedure SYClick(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure BCloseClick(Sender: TObject);
    procedure TV2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    FSKID,FCPID,FCPNo,FCPName,FInt,FBPIDSel:string;
    my,mz:integer;
    procedure InitGrid();
    procedure SaveData();
    procedure initTree();
    procedure SSetEditDataCDSNew(yClientDataset:TclientDataSet; mClientDataset:TclientDataSet );
    procedure initimage();
    procedure initimageSH();
    procedure InitSHByOrdBP_SH();
    { Private declarations }
  public
    flag,flagname,snote,MainType,FGYName,FBPIDSH,canshu1,FBPID:string;
    Formid:string;
    fnote,fnote1,forderno,fZdyFlag,ViewFlag,fHelpType:Boolean;
    PPSTE:integer;

    { Public declarations }
  end;
var
  frmBPZDY_LRSHK: TfrmBPZDY_LRSHK;
  Mach: array of TfrmSLT_PBSK;
  Mach1: array of TfrmSlt;
implementation
uses
  U_DataLink,U_Fun10,U_Fun,U_BPZdy_SH, U_BPZdy_HXK,U_CPTypePB,U_FileUp_TP,
  U_FileUp,U_FileUp_PB,U_FileUp_TPSH,U_BPZdy_Panel,U_BPZdy_PanelCX,U_BPZdy_YT;

{$R *.dfm}
procedure TfrmBPZDY_LRSHK.SSetEditDataCDSNew(yClientDataset:TclientDataSet; mClientDataset:TclientDataSet );
var
  i:integer;
  k:integer;
  mfieldName:string;
begin
  if yClientDataset.IsEmpty then exit;
  K:=1;
  try
    mClientDataset.DisableControls;
    mClientDataset.Filtered:=false;
    with mClientDataset do
    begin
      Append;
      for i:=0 to yClientDataset.FieldCount-1 do
      begin
        mfieldName:=trim(yClientDataset.fields[i].FieldName);
        fieldbyname(mfieldName).Value:=yClientDataset.Fields[i].Value;
      end;
      post;
      inc(k);
    end;
    if not mClientDataset.IsEmpty then
    begin
      mClientDataset.First;
    end;
  finally
    mClientDataset.First;
    mClientDataset.EnableControls;
  end;
end;
procedure TfrmBPZDY_LRSHK.initTree();
begin
  with ADOQueryTree do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select *');
    sql.Add(', Case when isnull(CPNo,'''')<>'''' then RTrim(CPNo)+''/''+CPName else CPName end as CP ');
    SQL.Add('from CP_TypePB order by CPlevel,CPOrder,CPName');
    Open;
  end;
  SCreateCDS20(ADOQueryTree,Order_Tree);
  SInitCDSData20(ADOQueryTree,Order_Tree);
  cxDBTreeList1.Items[0].Expand(true);
end;

procedure TfrmBPZDY_LRSHK.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;
    //Finalize(Mach);
  end;
  SetLength(Mach, 0);
  IF ClientDataSet1.IsEmpty then exit;
  try
    with adoqueryPicture do
    begin
      close;
      sql.Clear;
      sql.Add(' select A.TFID,A.WBID,B.XFID,A.FilesOther,B.FileName,C.* from BP_ZDY C ');
      sql.Add(' inner join XD_File_TP B on C.SKID =B.SKID');
      SQL.Add(' inner join TP_File_TP A on B.CYID=A.WBID ');
      sql.Add(' where C.BPID='+quotedstr(trim(ClientDataSet1.fieldbyname('BPID').AsString)));
      //ShowMessage(sql.Text);
      open;
    end;
    j:=adoqueryPicture.RecordCount;
    if j<1 then exit;
    adoqueryPicture.DisableControls;
    adoqueryPicture.First;
    SetLength(Mach, j);
    with adoqueryPicture do
    begin
      First;
      i:=0;
      while not eof do
      begin
        if triM(adoqueryPicture.fieldbyname('TFID').AsString)<>'' then
        begin
          jpg:=TJpegImage.Create();
          myStream:=tadoblobstream.Create(tblobfield(adoqueryPicture.fieldbyname('FilesOther')),bmread);
          jpg.LoadFromStream(myStream);
        end;
        Mach[i] := TfrmSLT_PBSK.Create(Self);
        Mach[i].Name:=trim(adoqueryPicture.fieldbyname('XFID').AsString);
        Mach[i].Parent := ScrollBox1;
        Mach[I].Left:=0+410*i;
        if triM(adoqueryPicture.fieldbyname('TFID').AsString)<>'' then
        begin
          Mach[i].Init(adoqueryPicture.fieldbyname('TFID').AsString,adoqueryPicture.fieldbyname('FileName').AsString,jpg);
        end;
        i:=i+1;
        Next;
      end;
    end;
    adoqueryPicture.EnableControls;
  finally
    jpg.free;
    //application.ProcessMessages;
  end;
end;

procedure TfrmBPZDY_LRSHK.initimageSH();
var
  i,j,x:Integer;
begin
  with ScrollBox2 do
  begin
    for x:=0 to ScrollBox2.ControlCount-1 do
    begin
      if Controls[x] is TPanel then
      begin
        if TPanel(Controls[x]).Ctl3D=False then
        begin
          TPanel(Controls[x]).Visible:=false;
          ScrollBox2.Refresh;
        end;
      end;
    end;
  end;
  ScrollBox2.Refresh;
  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 BP_ColZDY B ');
    sql.Add('inner join RT_PTColor A on B.PTID=A.PTID ');
    sql.Add('where B.SKID='''+trim(FBPIDSH)+''' and isnull(B.SKID,'''')<>'''' ');
    sql.Add(' order by cast(B.ColNo as int)');
    //ShowMessage(sql.Text);
    Open;
  end;
  mz:=ceil(ADOQueryTemp.fieldbyname('MXGS').AsInteger/50);
  label554.Caption:=inttostr(my)+'/'+inttostr(mz);
  SCreateCDS20(ADOQueryTemp,OrdBP_SHWH);
  SInitCDSData20(ADOQueryTemp,OrdBP_SHWH);
  if OrdBP_SHWH.IsEmpty then
  begin
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update BP_ZDY set SKID='''' ');
      sql.Add('where SKID='''+trim(FBPIDSH)+'''');
      ExecSQL;
    end;
    with ClientDataSet1 do
    begin
      edit;
      fieldbyname('SKID').Value:='';
    end;
  end
  else
  begin
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update BP_ZDY set SKID='''+trim(FBPIDSH)+''' ');
      sql.Add('where BPID='''+trim(FBPIDSel)+'''');
      ExecSQL;
    end;
    with ClientDataSet1 do
    begin
      edit;
      fieldbyname('SKID').Value:=Trim(FBPIDSH);
    end;
  end;
  InitSHByOrdBP_SH();
end;

procedure TfrmBPZDY_LRSHK.InitSHByOrdBP_SH();
var
  i,j,z,x,q:Integer;
begin
  //OrdBP_SHWH.DisableControls;
  with ScrollBox2 do
  begin
    for x:=0 to ScrollBox2.ControlCount-1 do
    begin
      TPanel(Controls[x]).Visible:=false;
    end;
  end;
  with OrdBP_SHWH 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(OrdBP_SHWH.Fieldbyname('PTID').AsString);
          TPanel(Controls[i]).Color:=StrToInt('$'+Trim(OrdBP_SHWH.Fieldbyname('ColDaiMa').AsString));
          with TPanel(Controls[i]) do
          begin
            for j:=0 to ControlCount-1 do
            begin
              if Controls[j] is TPanel then
              begin
                with TPanel(Controls[j]) do
                begin
                  for z:=0 to ControlCount-1 do
                  begin
                    if Controls[z] is TEdit then
                    begin
                      if TEdit(Controls[z]).Tag=1 then
                      begin
                        TEdit(Controls[z]).Text:=Trim(OrdBP_SHWH.Fieldbyname('ColNo').AsString);
                        TEdit(Controls[z]).Hint:=Trim(OrdBP_SHWH.Fieldbyname('PTID').AsString);
                      end else
                      begin
                        TEdit(Controls[z]).Text:=Trim(OrdBP_SHWH.Fieldbyname('ColNameKH').AsString);
                        TEdit(Controls[z]).Hint:=Trim(OrdBP_SHWH.Fieldbyname('PTID').AsString);
                      end;
                    end;
                  end;
                end;
              end;
            end;
          end;
        end;
        i:=i+1;
      end;
      q:=q+1;
      Next;
    end;
  end;
  //OrdBP_SHWH.EnableControls;
end;

procedure TfrmBPZDY_LRSHK.SaveData();
var maxno:string;
begin
  if FGYName<>'' then exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    ClientDataSet1.DisableControls;
    with ClientDataSet1 do
    begin
      First;
      while not eof do
      begin
        if Trim(ClientDataSet1.FieldByName('BPID').AsString)='' then
        begin
          if GetLSNo(ADOQueryTemp,maxno,'BP','BP_ZDY',3,1)=False then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            ClientDataSet1.EnableControls;
            Application.MessageBox('取最大编号失败！','提示',0);
            Exit;
          end;
        end
        else
        begin
          maxno:=Trim(ClientDataSet1.fieldbyname('BPID').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from BP_ZDY where BPID='''+Trim(maxno)+'''');
          Open;
        end;
        if ADOQueryCmd.IsEmpty then
        begin
          ADOQueryCmd.Append;
        end
        else
        begin
          ADOQueryCmd.Edit;
        end;
        ADOQueryCmd.FieldByName('BPID').Value:=Trim(maxno);
        SSetSaveDataCDSNew(ADOQueryCmd,Tv1,ClientDataSet1,'BP_ZDY',3);
        ADOQueryCmd.FieldByName('BPType').Value:=flagName;
        ADOQueryCmd.FieldByName('BPFlag').Value:=flag;
        ADOQueryCmd.FieldByName('valid').Value:='Y';
        ADOQueryCmd.Post;
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.add('select * from BP_ZDY where BPCode='''+Trim(ClientDataSet1.fieldbyname('BPCode').AsString)+'''');
          sql.Add(' and BPFlag='''+trim(flag)+'''');
          Open;
        end;
        if ADOQueryTemp.IsEmpty=False then
        begin
          if ADOQueryTemp.RecordCount>1 then
          begin
            with ADOQueryCmd do
            begin
              Close;
              sql.Clear;
              SQL.Add('delete BP_ZDY where BPID='''+Trim(ClientDataSet1.fieldbyname('BPID').AsString)+'''');
              ExecSQL;
            end;
            ADOQueryCmd.Connection.RollbackTrans;
            ClientDataSet1.EnableControls;
            Application.MessageBox('编号重复！','提示',0);
            Exit;
          end;
        end;
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.add('select * from BP_ZDY where BPName='''+Trim(ClientDataSet1.fieldbyname('BPName').AsString)+'''');
          sql.add(' and isnull(BPMF,'''')='''+Trim(ClientDataSet1.fieldbyname('BPMF').AsString)+'''');
          sql.add(' and isnull(BPKZ,'''')='''+Trim(ClientDataSet1.fieldbyname('BPKZ').AsString)+'''');
          sql.add(' and isnull(BPJS,'''')='''+Trim(ClientDataSet1.fieldbyname('BPJS').AsString)+'''');
          sql.add(' and isnull(BPWS,'''')='''+Trim(ClientDataSet1.fieldbyname('BPWS').AsString)+'''');
          sql.add(' and isnull(BPMiDu,'''')='''+Trim(ClientDataSet1.fieldbyname('BPMiDu').AsString)+'''');
          sql.add(' and isnull(BPUnit,'''')='''+Trim(ClientDataSet1.fieldbyname('BPUnit').AsString)+'''');
          sql.Add(' and BPFlag='''+trim(flag)+'''');
          Open;
        end;
        if ADOQueryTemp.IsEmpty=False then
        begin
          if ADOQueryTemp.RecordCount>1 then
          begin
            with ADOQueryCmd do
            begin
              Close;
              sql.Clear;
              SQL.Add('delete BP_ZDY where BPID='''+Trim(ClientDataSet1.fieldbyname('BPID').AsString)+'''');
              ExecSQL;
            end;
            ADOQueryCmd.Connection.RollbackTrans;
            ClientDataSet1.EnableControls;
            Application.MessageBox('名称门幅克重经纱纬纱重复！','提示',0);
            Exit;
          end;
        end;
        ClientDataSet1.Edit;
        ClientDataSet1.FieldByName('BPID').Value:=Trim(maxno);
        //ClientDataSet1.Post;
        Next;
      end;
      ClientDataSet1.EnableControls;
    end;
    TV1.OptionsData.Editing:=false;
    TV1.OptionsSelection.CellSelect:=false;
    ADOQueryCmd.Connection.CommitTrans;
  except;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmBPZDY_LRSHK.FormCreate(Sender: TObject);
begin
  try
    //cxGrid1.Align:=alClient;
    with ADOConnection1 do
    begin
      Connected:=false;
      ConnectionString:=DConString;
      //ConnectionString:='';
      Connected:=true;
    end;
  except;
    frmBPZDY_LRSHK.Free;
  end;
  canshu1:=Trim(DParameters1);
end;

procedure TfrmBPZDY_LRSHK.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  ToolBar1.SetFocus;
  Finalize(Mach1);
  Finalize(Mach);
  Action:=caFree;
end;

procedure TfrmBPZDY_LRSHK.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Select_BP :Code,:PState,:CYType,:Stats ');
      if Formid='2' then
      begin
        Parameters.ParamByName('Code').Value:=FBPID;
        Parameters.ParamByName('PState').Value:=1;
      end
      else
      begin
        Parameters.ParamByName('Code').Value:='';
        Parameters.ParamByName('PState').Value:=0;
      end;
      Parameters.ParamByName('CYType').Value:=Trim(Order_Tree.fieldbyname('CPID').AsString);
      Parameters.ParamByName('Stats').Value:='';
      Open;
    end;
    SCreateCDS20(ADOQueryMain,ClientDataSet1);
    SInitCDSData20(ADOQueryMain,ClientDataSet1);
    SCreateCDS20(ADOQueryMain,Ord_Sel);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmBPZDY_LRSHK.TBSaveClick(Sender: TObject);
var
  maxno:string;
begin
  if ClientDataSet1.IsEmpty then Exit;
  Toolbar1.SetFocus;
  if ClientDataSet1.Locate('BPCode',null,[]) then
  begin
    Application.MessageBox('编号不能为空！','提示',0);
    Exit;
  end;
  if ClientDataSet1.Locate('BPCode','',[]) then
  begin
    Application.MessageBox('编号不能为空！','提示',0);
    Exit;
  end;
  if ClientDataSet1.Locate('BPName',null,[]) then
  begin
    Application.MessageBox('名称不能为空！','提示',0);
    Exit;
  end;
  if ClientDataSet1.Locate('BPName','',[]) then
  begin
    Application.MessageBox('名称不能为空！','提示',0);
    Exit;
  end;
  SaveData();
  Application.MessageBox('保存成功！','提示',0);
end;

procedure TfrmBPZDY_LRSHK.TBCloseClick(Sender: TObject);
begin
  panel1.SetFocus;
  WriteCxGrid('自定义'+Trim(flag)+'104',TV1,'自定义数据');
  Close;
end;

procedure TfrmBPZDY_LRSHK.FormShow(Sender: TObject);
begin
  initTree();
  InitGrid();
  if canshu1='查询' then
  begin
    THB.Visible:=false;
    TCF.Visible:=false;
    ToolButton1.Visible:=false;
    TXZCol.Visible:=false;
    Panel3.Visible:=false;
  end
  else
  begin
    THB.Visible:=true;
    TCF.Visible:=true;
    ToolButton1.Visible:=true;
    TXZCol.Visible:=true;
    Panel3.Visible:=true;
  end;
  ReadCxGrid('自定义'+Trim(flag)+'104',TV1,'自定义数据');
  frmBPZDY_LRSHK.Caption:=Trim(flagname);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.* from RT_PTColor A ');
    sql.Add('inner join BP_ColZDY B on B.PTID=A.PTID ');
    sql.Add('where 1=2 ');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,OrdBP_SHWH);
  SInitCDSData20(ADOQueryTemp,OrdBP_SHWH);
end;

procedure TfrmBPZDY_LRSHK.BPNamehange(Sender: TObject);
var
  fsj:String;
begin
  if Trim(BPNameM.Text)<>'' then
  begin
    fsj:=' BPName like '''+'%'+Trim(BPNameM.Text)+'%'+'''';
  end;
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,fsj);
    SCreateCDS20(ADOQueryMain,ClientDataSet1);
    SInitCDSData20(ADOQueryMain,ClientDataSet1);
  end;
end;

procedure TfrmBPZDY_LRSHK.V1NotePropertiesEditValueChanged(Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with ClientDataSet1 do
  begin
    Edit;
    FieldByName('BPKZ').Value:=mvalue;
    //Post;
  end;
end;

procedure TfrmBPZDY_LRSHK.V1HelpTypePropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with ClientDataSet1 do
  begin
    Edit;
    FieldByName('BPWS').Value:=mvalue;
    Post;
  end;
  {with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('Update KH_Zdy Set HelpType='''+Trim(mvalue)+'''');
    sql.Add(' where ZdyNo='''+Trim(ClientDataSet1.fieldbyname('ZdyNo').AsString)+'''');
    ExecSQL;
  end;}
end;

procedure TfrmBPZDY_LRSHK.v1note1PropertiesEditValueChanged(Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with ClientDataSet1 do
  begin
    Edit;
    FieldByName('BPMiDu').Value:=mvalue;
    Post;
  end;
end;

procedure TfrmBPZDY_LRSHK.V1BPCodePropertiesEditValueChanged(Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with ClientDataSet1 do
  begin
    Edit;
    FieldByName('BPCode').Value:=mvalue;
  end;
  {with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('Update BP_ZDY Set BPCode='''+Trim(mvalue)+'''');
    sql.Add(' where BPID='''+Trim(ClientDataSet1.fieldbyname('BPID').AsString)+'''');
    ExecSQL;
  end;}
end;

procedure TfrmBPZDY_LRSHK.V1BPNamePropertiesEditValueChanged(Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with ClientDataSet1 do
  begin
    Edit;
    FieldByName('BPName').Value:=mvalue;
  end;
end;

procedure TfrmBPZDY_LRSHK.ToolButton5Click(Sender: TObject);
begin
  ToolBar1.SetFocus;
  if ML_GYS.IsEmpty then Exit;
  if Trim(ML_GYS.FieldByName('BPSubID').AsString)<>'' then
  begin
    if application.MessageBox('确定要删除吗?','提示信息',1)=2 then exit;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete BP_ZDY_Sub where BPSubID='''+Trim(ML_GYS.fieldbyname('BPSubID').AsString)+'''');
      ExecSQL;
    end;
  end;
  ML_GYS.Delete;
end;

procedure TfrmBPZDY_LRSHK.BPCodeMChange(Sender: TObject);
var
  fsj:String;
begin
  if Trim(BPCodeM.Text)<>'' then
  begin
    fsj:=' BPCode like '''+'%'+Trim(BPCodeM.Text)+'%'+'''';
  end;
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,fsj);
    SCreateCDS20(ADOQueryMain,ClientDataSet1);
    SInitCDSData20(ADOQueryMain,ClientDataSet1);
  end;
end;

procedure TfrmBPZDY_LRSHK.Tv3CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var i:Integer;
begin
  if ML_GX.IsEmpty then exit;
  ML_GX.Delete;
  i:=1;
  ML_GX.DisableControls;
  with ML_GX do
  begin
    first;
    while not eof do
    begin
      Edit;
      FieldByName('BPMiDu').Value:=i;
      i:=i+1;
      next;
    end;
  end;
  ML_GX.EnableControls;
end;

procedure TfrmBPZDY_LRSHK.TPBLBClick(Sender: TObject);
begin
  frmCPTypePB:=TfrmCPTypePB.Create(self);
  with frmCPTypePB do
  begin
    if ShowModal=1 then
    begin

    end;
    free;
  end;
  initTree();
end;

procedure TfrmBPZDY_LRSHK.ToolButton1Click(Sender: TObject);
var
  maxno,FColID:string;
  j,i:Integer;
begin
  ToolBar1.SetFocus;
  BPCodeM.SetFocus;
  try
    ADOQueryCmd.Connection.BeginTrans;
    OrdBP_SHWH.DisableControls;
    with OrdBP_SHWH do
    begin
      First;
      while not Eof do
      begin
        FColID:=Trim(fieldbyname('ColID').AsString);
        if FieldByName('ColNo').AsString='' then
        begin
          ADOQueryCmd.Connection.RollbackTrans;
          application.MessageBox('色号不能为空','提示');
          exit;
        end;
        if FieldByName('ColNameKH').AsString='' then
        begin
          ADOQueryCmd.Connection.RollbackTrans;
          application.MessageBox('颜色不能为空','提示');
          exit;
        end;
        if Trim(FColID)='' then
        begin
          if GetLSNo(ADOQueryCmd,maxno,'CL','BP_ColZDY',3,1)=False then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取最大号失败!','提示',0);
            Exit;
          end;
        end else
        begin
          maxno:=Trim(FColID);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from BP_ColZDY where ColID='''+Trim(maxno)+'''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(FColID)='' then
          begin
            Append;
          end else
          begin
            Edit;
          end;
          FieldByName('ColID').Value:=Trim(maxno);
          FieldByName('PTID').Value:=Trim(OrdBP_SHWH.fieldbyname('PTID').AsString);
          FieldByName('ColNo').Value:=Trim(OrdBP_SHWH.fieldbyname('ColNo').AsString);
          FieldByName('ColNameKH').Value:=Trim(OrdBP_SHWH.fieldbyname('ColNameKH').AsString);
          FieldByName('SKID').Value:=Trim(FBPIDSH);
          Post;
        end;
        Edit;
        FieldByName('ColID').Value:=Trim(maxno);
        with ADOQueryCmd do
        begin
          close;
          sql.Clear;
          SQL.Add('update RT_PTColor set ColNameKH='''+trim(OrdBP_SHWH.fieldbyname('ColNameKH').AsString)+''' ');
          sql.Add(' where PTID='''+trim(OrdBP_SHWH.fieldbyname('PTID').AsString)+'''');
          ExecSQL;
        end;
        //Post;
        Next;
      end;
    end;
    OrdBP_SHWH.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    initimageSH();
    Application.MessageBox('保存成功。','提示');
  except
    OrdBP_SHWH.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存异常!','提示');
  end;
end;

procedure TfrmBPZDY_LRSHK.cxDBTreeList1Click(Sender: TObject);
begin
  InitGrid();
  if Order_Tree.FieldByName('CPLevel').AsInteger<3 then
  begin
  
  end else
  begin
    //Panel5.Visible:=True;
    //SClearData(Panel5,2);
   // BPMF.Text:='160';
    //BPCF.Text:='100%P';
   // Button1.Caption:='新增保存';
    FSKID:='';
    FCPID:=Trim(Order_Tree.fieldbyname('CPID').AsString);
    FCPNo:=Trim(Order_Tree.fieldbyname('CPNo').AsString);
    FCPName:=Trim(Order_Tree.fieldbyname('CPName').AsString);
   
  end;

end;

procedure TfrmBPZDY_LRSHK.TSHClick(Sender: TObject);
begin
  try
    frmFileUp_TPSH:=TfrmFileUp_TPSH.Create(Application);
    with frmFileUp_TPSH do
    begin
      if Self.ClientDataSet1.fieldbyname('SKID').AsString='' then
      begin
        Code.Text:=Trim(Self.ClientDataSet1.fieldbyname('BPCode').AsString);   //色卡的SKID
        CYID:=Trim(Self.ClientDataSet1.fieldbyname('BPCode').AsString);
        FSKID:=Trim(Self.ClientDataSet1.fieldbyname('BPCode').AsString);
      end
      else
      begin
        Code.Text:=Trim(Self.ClientDataSet1.fieldbyname('SKID').AsString);   //色卡的SKID
        CYID:=Trim(Self.ClientDataSet1.fieldbyname('SKID').AsString);
        FSKID:=Trim(Self.ClientDataSet1.fieldbyname('SKID').AsString);
      end;
      if ShowModal=1 then
      begin
        if Self.ClientDataSet1.fieldbyname('SKID').AsString='' then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('update BP_ZDY set SKID='''+Trim(Self.ClientDataSet1.fieldbyname('BPCode').AsString)+''' ');
            sql.Add('where BPID='''+Trim(ClientDataSet1.fieldbyname('BPID').AsString)+'''');
            execsql;
          end;
          with Self.ClientDataSet1 do
          begin
            edit;
            FieldByName('SKID').Value:=Trim(fieldbyname('BPCode').AsString);
          end;
        end
        else
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('update BP_ZDY set SKID='''+Trim(Self.ClientDataSet1.fieldbyname('SKID').AsString)+''' ');
            sql.Add('where BPID='''+Trim(ClientDataSet1.fieldbyname('BPID').AsString)+'''');
            execsql;
          end;
          with Self.ClientDataSet1 do
          begin
            edit;
            FieldByName('SKID').Value:=Trim(fieldbyname('SKID').AsString);
          end;
        end;
      end;
    end;
  finally
    frmFileUp_TPSH.Free;
  end;
  initimageSH();
end;

procedure TfrmBPZDY_LRSHK.TV1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Formid:='1';
  my:=1;
  if Trim(ClientDataSet1.fieldbyname('SKID').asstring)='' then
  FBPIDSH:=Trim(ClientDataSet1.fieldbyname('BPCode').asstring)
  else
  FBPIDSH:=Trim(ClientDataSet1.fieldbyname('SKID').asstring);
  FBPIDSel:=Trim(ClientDataSet1.fieldbyname('BPID').asstring);
  initimage();
  initimageSH();
end;

procedure TfrmBPZDY_LRSHK.Button1Click(Sender: TObject);
begin
  try
    frmFileUp_PB:=TfrmFileUp_PB.Create(Application);
    with frmFileUp_PB do
    begin
      if Self.ClientDataSet1.fieldbyname('SKID').AsString='' then
      begin
        Code.Text:=Trim(Self.ClientDataSet1.fieldbyname('BPCode').AsString);
        FSKID:=Trim(Self.ClientDataSet1.fieldbyname('BPCode').AsString);
      end
      else
      begin
        Code.Text:=Trim(Self.ClientDataSet1.fieldbyname('SKID').AsString);
        FSKID:=Trim(Self.ClientDataSet1.fieldbyname('SKID').AsString);
      end;
      if ShowModal=1 then
      begin
        if Self.ClientDataSet1.fieldbyname('SKID').AsString='' then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('update BP_ZDY set SKID='''+Trim(Self.ClientDataSet1.fieldbyname('BPCode').AsString)+''' ');
            sql.Add('where BPID='''+Trim(ClientDataSet1.fieldbyname('BPID').AsString)+'''');
            execsql;
          end;
          with Self.ClientDataSet1 do
          begin
            edit;
            FieldByName('SKID').Value:=Trim(fieldbyname('BPCode').AsString);
          end;
        end
        else
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('update BP_ZDY set SKID='''+Trim(Self.ClientDataSet1.fieldbyname('SKID').AsString)+''' ');
            sql.Add('where BPID='''+Trim(ClientDataSet1.fieldbyname('SKID').AsString)+'''');
            execsql;
          end;
          with Self.ClientDataSet1 do
          begin
            edit;
            FieldByName('SKID').Value:=Trim(fieldbyname('SKID').AsString);
          end;
        end;
      end;
    end;
  finally;
    frmFileUp_PB.Free;
  end;
  initimage();
end;

procedure TfrmBPZDY_LRSHK.THBClick(Sender: TObject);
var SSKID:string;
begin
  if ClientDataSet1.IsEmpty then Exit;
  if ClientDataSet1.Locate('Ssel',true,[])=false then
  begin
    application.MessageBox('没有选择数据','提示');
    exit;
  end;
  Panel107.Visible:=true;
  ClientDataSet1.DisableControls;
  with ClientDataSet1 do
  begin
    First;
    while not eof do
    begin
      if FieldByName('Ssel').AsBoolean=true then
      begin
        with Ord_Sel do
        begin
          Append;
          FieldByName('BPCode').Value:=Trim(ClientDataSet1.fieldbyname('BPCode').AsString);
          FieldByName('BPName').Value:=Trim(ClientDataSet1.fieldbyname('BPName').AsString);
          FieldByName('BPKZ').Value:=Trim(ClientDataSet1.fieldbyname('BPKZ').AsString);
          FieldByName('BPJS').Value:=Trim(ClientDataSet1.fieldbyname('BPJS').AsString);
          FieldByName('CPMiDu').Value:=Trim(ClientDataSet1.fieldbyname('CPMiDu').AsString);
          FieldByName('SKID').Value:=Trim(ClientDataSet1.fieldbyname('SKID').AsString);
          FieldByName('BPID').Value:=Trim(ClientDataSet1.fieldbyname('BPID').AsString);
          post;
        end;
      end;
      next;
    end;
  end;
  ClientDataSet1.EnableControls;
end;

procedure TfrmBPZDY_LRSHK.TCFClick(Sender: TObject);
begin
  if ClientDataSet1.IsEmpty then Exit;
  if ClientDataSet1.Locate('Ssel',true,[])=false then
  begin
    application.MessageBox('没有选择数据','提示');
    exit;
  end;
  if Application.MessageBox('确定要拆分吗','提示',1)=2 then exit;
  ClientDataSet1.DisableControls;
  with ClientDataSet1 do
  begin
    First;
    while not eof do
    begin
      if FieldByName('Ssel').AsBoolean=true then
      begin
        with ADOQueryCmd do
        begin
          close;
          sql.Clear;
          sql.Add('update BP_ZDY set SKID='''' ');
          sql.Add('where BPID='''+trim(ClientDataSet1.fieldbyname('BPID').AsString)+'''');
          ExecSQL;
        end;
        edit;
        FieldByName('SKID').Value:='';
      end;
      next;
    end;
  end;
  ClientDataSet1.EnableControls;
end;

procedure TfrmBPZDY_LRSHK.TXZColClick(Sender: TObject);
var i,j,x:Integer;
begin
  j:=0;
  if ClientDataSet1.IsEmpty then exit;
  if Trim(FBPIDSel)='' then
  begin
    Application.MessageBox('没有单击表格中的坯布数据!','提示',0);
    Exit;
  end;
  frmBPZDY_Panel:=TfrmBPZDY_Panel.create(self);
  with frmBPZDY_Panel do
  begin
    FColorFlag:=Trim(FBPIDSH);
    if ShowModal=1 then
    begin
      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=A.SKID and isnull(C.SKID,'''')<>'''') ');
        sql.Add(' from BP_ColZDY A');
        sql.Add(' inner join RT_PTColor B on A.PTID=B.PTID');
        sql.Add(' where A.SKID='''+Trim(FBPIDSH)+'''');
        sql.Add(' and isnull(A.SKID,'''')<>'''' ');
        sql.Add(' order by cast(A.ColNo as int)');
        Open;
      end;
      mz:=ceil(ADOQueryTemp.fieldbyname('MXGS').AsInteger/50);
      label554.Caption:=inttostr(my)+'/'+inttostr(mz);
      SCreateCDS20(ADOQueryTemp,OrdBP_SHWH);
      SInitCDSData20(ADOQueryTemp,OrdBP_SHWH);
      with Self.ScrollBox2 do
      begin
        for i:=0 to Self.ScrollBox2.ControlCount-1 do
        begin
          if Controls[i] is TPanel then
          begin
            if TPanel(Controls[i]).Ctl3D=False then
            begin
              TPanel(Controls[i]).Visible:=false;
              Self.ScrollBox2.Refresh;
            end;
          end;
        end;
      end;
      Self.ScrollBox2.Refresh;
      i:=OrdBP_SHWH.RecordCount+1;
      with frmBPZDY_Panel.Ord_SH do
      begin
        first;
        while not Eof do
        begin
          if Self.OrdBP_SHWH.Locate('PTID',Trim(frmBPZDY_Panel.Ord_SH.fieldbyname('PTID').AsString),[])=False then
          begin
            with Self.OrdBP_SHWH do
            begin
              Append;
              FieldByName('PTID').Value:=frmBPZDY_Panel.Ord_SH.fieldbyname('PTID').Value;
              FieldByName('ColNameEng').Value:=frmBPZDY_Panel.Ord_SH.fieldbyname('ColNameEng').Value;
              FieldByName('ColName').Value:=frmBPZDY_Panel.Ord_SH.fieldbyname('ColName').Value;
              FieldByName('ColNameKH').Value:=frmBPZDY_Panel.Ord_SH.fieldbyname('ColNameKH').Value;
              FieldByName('ColDaiMa').Value:=frmBPZDY_Panel.Ord_SH.fieldbyname('ColDaiMa').Value;
              FieldByName('ColNo').Value:=frmBPZDY_Panel.Ord_SH.fieldbyname('ColNo').Value;
              Post;
            end;
            i:=i+1;
          end;
          Next;
        end;
      end;
      Self.InitSHByOrdBP_SH();
      self.Formid:='0';
    end;
    free;
  end;
end;


procedure TfrmBPZDY_LRSHK.N1Click(Sender: TObject);
var
  i:Integer;
begin
  //ShowMessage(FPT);
  FrmBPZdy_YT:=TFrmBPZdy_YT.create(Self);
  with FrmBPZdy_YT do
  begin
    Panel1.Color:=StrToInt('$'+OrdBP_SHWH.fieldbyname('ColDaiMa').Value);
    Label1.Caption:=Trim(OrdBP_SHWH.fieldbyname('PTID').AsString);
    Label2.Caption:=Trim(OrdBP_SHWH.fieldbyname('ColNameEng').AsString);
    Label3.Caption:=Trim(OrdBP_SHWH.fieldbyname('ColName').AsString);
    Label4.Caption:=Trim(OrdBP_SHWH.fieldbyname('ColNameKH').AsString);
    Label5.Visible:=true;
    Label5.Caption:=Trim(OrdBP_SHWH.fieldbyname('ColNo').AsString);
    if showmodal=1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmBPZDY_LRSHK.Panel101MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  i:Integer;
begin
  OrdBP_SHWH.Locate('PTID',TPanel(Sender).Hint,[]);
end;

procedure TfrmBPZDY_LRSHK.TDYClick(Sender: TObject);
var i,j,x:Integer;
begin
  i:=0;
  j:=0;
  frmBPZDY_PanelCX:=TfrmBPZDY_PanelCX.create(self);
  with frmBPZDY_PanelCX do
  begin
    FColorFlag:=Trim(FBPIDSH);
    FBPID:=Trim(ClientDataSet1.fieldbyname('BPID').AsString);
    if ShowModal=1 then
    begin
      
    end;
    free;
  end;
end;

procedure TfrmBPZDY_LRSHK.N2Click(Sender: TObject);
begin
  if Application.MessageBox('确定要删除色号吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('delete BP_ColZDY where PTID='''+Trim(OrdBP_SHWH.fieldbyname('PTID').AsString)+'''');
    sql.Add(' and isnull(SKID,'''')='''+Trim(FBPIDSH)+'''');
    ExecSQL;
  end;
  initimageSH();
end;

procedure TfrmBPZDY_LRSHK.Edit1Exit(Sender: TObject);
var
  FPT,FTEX:string;
begin
  FPT:=Trim(TEdit(Sender).Hint);
  FTEX:=Trim(TEdit(Sender).Text);
  if FTEX<>'0' then
  begin
    if StrToIntDef(FTEX,0)=0 then
    begin
      application.MessageBox('色号必须是数字','提示');
      FTEX:='';
      TEdit(Sender).Text:='';
      exit;
    end;
  end;
  //ShowMessage(FPT);
  with OrdBP_SHWH do
  begin
    if Locate('PTID',FPT,[]) then
    begin
      Edit;
      FieldByName('ColNo').value:=Trim(FTEX);
      Post;
    end;
  end;
end;

procedure TfrmBPZDY_LRSHK.Edit2Exit(Sender: TObject);
var FPT,FTEX:string;
begin
  FPT:=Trim(TEdit(Sender).Hint);
  FTEX:=Trim(TEdit(Sender).Text);
  with OrdBP_SHWH do
  begin
    if Locate('PTID',FPT,[]) then
    begin
      Edit;
      FieldByName('ColNameKH').value:=Trim(FTEX);
      Post;
    end;
  end;
end;

procedure TfrmBPZDY_LRSHK.FormDestroy(Sender: TObject);
begin
  frmBPZDY_LRSHK:=nil;
end;

procedure TfrmBPZDY_LRSHK.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_SH();
  XY.Enabled:=true;
end;

procedure TfrmBPZDY_LRSHK.SYClick(Sender: TObject);
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_SH();
  SY.Enabled:=true;
end;

procedure TfrmBPZDY_LRSHK.Button2Click(Sender: TObject);
begin
  if SKID.Text='' then
  begin
    Application.MessageBox('合并后色卡编号不能为空','提示');
    exit;
  end;
  if Application.MessageBox('确定要合并吗','提示',1)=2 then exit;
  Ord_Sel.DisableControls;
  with Ord_Sel do
  begin
    First;
    while not eof do
    begin
      with ADOQueryCmd do
      begin
        close;
        sql.Clear;
        sql.Add('update BP_ZDY set SKID='''+trim(SKID.Text)+''' ');
        sql.Add('where BPID='''+trim(Ord_Sel.fieldbyname('BPID').AsString)+'''');
        ExecSQL;
      end;
      Delete;
    end;
  end;
  Ord_Sel.EnableControls;
  Panel107.Visible:=false;
end;

procedure TfrmBPZDY_LRSHK.BCloseClick(Sender: TObject);
begin
  Panel107.Visible:=false;
  with Ord_Sel do
  begin
    while not eof do
    begin
      Delete;
    end;
  end;
end;

procedure TfrmBPZDY_LRSHK.TV2MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Formid:='1';
  my:=1;
  if Trim(Ord_Sel.fieldbyname('SKID').asstring)='' then
  FBPIDSH:=Trim(Ord_Sel.fieldbyname('BPCode').asstring)
  else
  FBPIDSH:=Trim(Ord_Sel.fieldbyname('SKID').asstring);
  FBPIDSel:=Trim(Ord_Sel.fieldbyname('BPID').asstring);
  initimageSH();
  SKID.Text:=Trim(Ord_Sel.fieldbyname('SKID').AsString);
end;

end.
