unit U_BPZdy_LRM;

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,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, cxTLdxBarBuiltInMenu;

type
  TfrmBPZDY_LRM = class(TForm)
    ToolBar1: TToolBar;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DataSource1: TDataSource;
    ClientDataSet1: TClientDataSet;
    TBClose: TToolButton;
    ADOConnection1: TADOConnection;
    ThreeImgList: TImageList;
    DataSource2: TDataSource;
    ML_GYS: TClientDataSet;
    DataSource3: TDataSource;
    ML_GX: TClientDataSet;
    ADOQuery6: TADOQuery;
    ADOQuery2: TADOQuery;
    ADOQuery3: TADOQuery;
    Panel4: TPanel;
    Panel5: TPanel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    DataSource4: TDataSource;
    ADOQueryTree: TADOQuery;
    Order_Tree: TClientDataSet;
    Panel6: TPanel;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    V1BPCode: TcxGridDBColumn;
    V1BPName: TcxGridDBColumn;
    V1BPMF1: TcxGridDBColumn;
    V1BPKZ: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    Panel7: TPanel;
    cxDBTreeList1: TcxDBTreeList;
    cxDBTreeList1cxDBTreeListColumn2: TcxDBTreeListColumn;
    ToolBar3: TToolBar;
    cxGridPopupMenu1: TcxGridPopupMenu;
    cxGridPopupMenu2: TcxGridPopupMenu;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyleRepository2: TcxStyleRepository;
    cxStyle2: TcxStyle;
    BPMF: TEdit;
    BPKZ: TEdit;
    MXCode: TEdit;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    BPNameM: TEdit;
    BPCodeM: TEdit;
    Label16: TLabel;
    Label3: TLabel;
    MXName: TEdit;
    V1BPCF: TcxGridDBColumn;
    Label4: TLabel;
    BPCF: TEdit;
    TV1Column1: TcxGridDBColumn;
    TV1Column2: TcxGridDBColumn;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TV1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure BPNamehange(Sender: TObject);
    procedure v1note1PropertiesEditValueChanged(Sender: TObject);
    procedure V1BPCodePropertiesEditValueChanged(Sender: TObject);
    procedure V1BPNamePropertiesEditValueChanged(Sender: TObject);
    procedure BPCodeMChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Button1KeyPress(Sender: TObject; var Key: Char);
    procedure cxDBTreeList1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure TV1FocusedRecordChanged(Sender: TcxCustomGridTableView;
      APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord;
      ANewItemRecordFocusingChanged: Boolean);
  private
    FBPID,FCPID,FCPNo,FCPName:string;
    procedure InitGrid();
    procedure initTree();
    { Private declarations }
  public
    flag,flagname,snote,MainType,FGYName,Fint,canshu1:string;
    fnote,fnote1,forderno,fZdyFlag,ViewFlag,fHelpType:Boolean;
    PPSTE:integer;
    { Public declarations }
  end;
var
  frmBPZDY_LRM: TfrmBPZDY_LRM;

implementation
uses
  U_DataLink,U_Fun10;

{$R *.dfm}
procedure TfrmBPZDY_LRM.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_TypeM order by CPlevel,CPOrder,CPName');
    Open;
  end;
  SCreateCDS20(ADOQueryTree,Order_Tree);
  SInitCDSData20(ADOQueryTree,Order_Tree);
  cxDBTreeList1.Items[0].Expand(true);
end;



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

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

procedure TfrmBPZDY_LRM.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Select_M :Code,:PState,:CYType,:Stats ');
      Parameters.ParamByName('Code').Value:='';
      Parameters.ParamByName('PState').Value:=0;
      Parameters.ParamByName('CYType').Value:=Trim(Order_Tree.fieldbyname('CPID').AsString);
      Parameters.ParamByName('Stats').Value:='';
      Open;
    end;
    SCreateCDS20(ADOQueryMain,ClientDataSet1);
    SInitCDSData20(ADOQueryMain,ClientDataSet1);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

procedure TfrmBPZDY_LRM.FormShow(Sender: TObject);
begin
  initTree();
  InitGrid();
  ReadCxGrid('自定义'+Trim(flag)+'1YX1',TV1,'自定义数据');
  frmBPZDY_LRM.Caption:=Trim(flagname);
  
end;

procedure TfrmBPZDY_LRM.TV1CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var i:integer;
begin
  if ToolButton1.Visible=true then
  begin
    Fint:='1';
    ModalResult:=1;
  end else
  begin
    ToolBar1.SetFocus;
    if ClientDataSet1.IsEmpty then exit;
    BPMF.Text:=Trim(ClientDataSet1.fieldbyname('BPMF').AsString);
    BPKZ.Text:=Trim(ClientDataSet1.fieldbyname('BPKZ').AsString);
    BPCF.Text:=Trim(ClientDataSet1.fieldbyname('BPCF').AsString);
    MXCode.Text:=Trim(ClientDataSet1.FieldByName('MXCode').AsString);
    MXName.Text:=Trim(ClientDataSet1.FieldByName('MXName').AsString);
    FBPID:=Trim(ClientDataSet1.fieldbyname('BPID').AsString);
    FCPID:=Trim(ClientDataSet1.fieldbyname('CPID').AsString);
    FCPNo:=Trim(ClientDataSet1.fieldbyname('CPNo').AsString);
    FCPName:=Trim(ClientDataSet1.fieldbyname('CPName').AsString);
    Panel5.Visible:=True;
  end;
end;

procedure TfrmBPZDY_LRM.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_LRM.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_LRM.V1BPCodePropertiesEditValueChanged(Sender: TObject);
var
  mvalue:string;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  with ClientDataSet1 do
  begin
    Edit;
    FieldByName('BPCode').Value:=mvalue;
  end;
end;

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

procedure TfrmBPZDY_LRM.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_LRM.ToolButton1Click(Sender: TObject);
begin
  ToolBar1.SetFocus;
  Fint:='1';
  ModalResult:=1;
end;

procedure TfrmBPZDY_LRM.Button1KeyPress(Sender: TObject; var Key: Char);
var maxno:string;
begin

end;

procedure TfrmBPZDY_LRM.cxDBTreeList1Click(Sender: TObject);
begin
  InitGrid();
  Panel5.Visible:=False;
  if Order_Tree.FieldByName('CPLevel').AsInteger<3 then
  begin

  end else
  begin
    FBPID:='';
    FCPID:=Trim(Order_Tree.fieldbyname('CPID').AsString);
    FCPNo:=Trim(Order_Tree.fieldbyname('CPNo').AsString);
    FCPName:=Trim(Order_Tree.fieldbyname('CPName').AsString);
  end;
  Label16.Caption:=Trim(Order_Tree.fieldbyname('CPNo').AsString);
end;

procedure TfrmBPZDY_LRM.FormDestroy(Sender: TObject);
begin
  frmBPZDY_LRM:=nil;
end;

procedure TfrmBPZDY_LRM.TV1FocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord;
  ANewItemRecordFocusingChanged: Boolean);
begin
  Panel5.Visible:=False;
end;

end.
