unit U_MaterialManySelHelp;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB, StdCtrls, Grids, DBGrids, ComCtrls, ToolWin, ImgList,
  DBClient, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, cxDBData, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxControls, cxGridCustomView, cxClasses, cxGridLevel,
  cxGrid, cxTextEdit;

type
  TfrmMaterialManySelHelp = class(TForm)
    DataSource1: TDataSource;
    ADOQuery1: TADOQuery;
    ImageList24: TImageList;
    ToolBar1: TToolBar;
    Tok: TToolButton;
    Tclose: TToolButton;
    GroupBox1: TGroupBox;
    edttj: TEdit;
    Label1: TLabel;
    CDS_sel: TClientDataSet;
    DataSourceSel: TDataSource;
    ADOQuery1MNumber: TStringField;
    ADOQuery1Mname: TWideStringField;
    ADOQuery1Model: TWideStringField;
    ADOQuery1CaiZhi: TWideStringField;
    ADOQuery1PurSortCode: TStringField;
    ADOQuery1InvSortcode: TStringField;
    ADOQuery1PrimaryUnit: TStringField;
    ADOQuery1PrimaryUnitName: TWideStringField;
    ADOQuery1PurUnit: TStringField;
    ADOQuery1PurUnitName: TWideStringField;
    ADOQuery1NowStorage: TBCDField;
    ADOQuery1HighStorage: TBCDField;
    ADOQuery1LowStorage: TBCDField;
    ADOQuery1SafeQuan: TBCDField;
    ADOQuery1Isbzqgl: TBooleanField;
    ADOQuery1Ispcgl: TBooleanField;
    CDS_selMNumber: TStringField;
    CDS_selMname: TWideStringField;
    CDS_selModel: TWideStringField;
    CDS_selCaiZhi: TWideStringField;
    CDS_selPurSortCode: TStringField;
    CDS_selInvSortcode: TStringField;
    CDS_selPrimaryUnit: TStringField;
    CDS_selPrimaryUnitName: TWideStringField;
    CDS_selPurUnit: TStringField;
    CDS_selPurUnitName: TWideStringField;
    CDS_selNowStorage: TBCDField;
    CDS_selHighStorage: TBCDField;
    CDS_selLowStorage: TBCDField;
    CDS_selSafeQuan: TBCDField;
    CDS_selIsbzqgl: TBooleanField;
    CDS_selIspcgl: TBooleanField;
    Label2: TLabel;
    Edit1: TEdit;
    ADOQuery1cess: TFloatField;
    CDS_selcess: TFloatField;
    GroupBox2: TGroupBox;
    dbGrid1: TcxGrid;
    dbGrid1Level1: TcxGridLevel;
    Tv1: TcxGridDBTableView;
    Tv1MNumber1: TcxGridDBColumn;
    Tv1Mname1: TcxGridDBColumn;
    Tv1Model1: TcxGridDBColumn;
    Tv1CaiZhi1: TcxGridDBColumn;
    Tv1PrimaryUnitName1: TcxGridDBColumn;
    DBGrid2: TcxGrid;
    DBGrid2Level1: TcxGridLevel;
    TV2: TcxGridDBTableView;
    TV2MNumber1: TcxGridDBColumn;
    TV2Mname1: TcxGridDBColumn;
    TV2Model1: TcxGridDBColumn;
    TV2CaiZhi1: TcxGridDBColumn;
    TV2PrimaryUnitName1: TcxGridDBColumn;
    TV2endquan1: TcxGridDBColumn;
    ADOConnection1: TADOConnection;
    procedure FormShow(Sender: TObject);
    procedure DBGrid1TitleClick(Column: TColumn);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure edttjChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TcloseClick(Sender: TObject);
    procedure TokClick(Sender: TObject);
    procedure edttjKeyPress(Sender: TObject; var Key: Char);
    procedure Edit1Change(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure TV2DblClick(Sender: TObject);
  private
    SortField,SortOrder,SortCaption:string;
    SortID:integer;
    procedure AddSelRow();
  public
    str_dylx:string;
    FStoreCode:string;
  end;

var
  frmMaterialManySelHelp: TfrmMaterialManySelHelp;

implementation
uses
  U_global;

{$R *.dfm}

procedure TfrmMaterialManySelHelp.FormShow(Sender: TObject);
begin
  with adoquery1 do
  begin
    close;
    sql.Clear;
    sql.Add('select * from Gy_material ');
    sql.Add('where StopFlag=''0''');
    if trim(FStoreCode)<>'' then
      sql.Add('and whcode='''+trim(FStoreCode)+'''');
    sql.Add('order by Mnumber');
    open;
  end;
  edttj.SetFocus ;
end;

procedure TfrmMaterialManySelHelp.DBGrid1TitleClick(Column: TColumn);
begin
  if  ADOQuery1.isEmpty then Exit;
end;

procedure TfrmMaterialManySelHelp.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action:=caFree;
end;
/////////////////////////////////////////////////
  //条件过滤
/////////////////////////////////////////////////
procedure TfrmMaterialManySelHelp.edttjChange(Sender: TObject);
begin
  try
      ADOQuery1.DisableControls;
      if trim(edttj.Text)<>'' then
      begin
        with ADOQuery1 do
        begin
          filtered:=false;
          filter:='mNumber like '+quotedStr('%'+trim(edttj.Text)+'%')+
                  ' or mName like '+quotedStr('%'+trim(edttj.Text)+'%');
          filtered:=true;
        end;
      end
      else
      begin
        with ADOQuery1 do
        begin
          filtered:=false;
        end;

      end;
  finally
      ADOQuery1.EnableControls;
  end;

end;

procedure TfrmMaterialManySelHelp.FormCreate(Sender: TObject);
begin
  with ADOConnection1 do
  begin
    Connected:=False;
    ConnectionString:=gConString;
    Connected:=True;
  end;
  //dbgrid1.Align :=alClient;
  groupBox2.Align :=alClient;
  CDS_Sel.Close;
  CDS_Sel.CreateDataSet;
end;
/////////////////////////////////////////////////////
  //函数功能：增加选择的记录
////////////////////////////////////////////////////
procedure TfrmMaterialManySelHelp.AddSelRow();
var
  i:integer;
begin
  with CDS_Sel do
  begin
    CDS_Sel.append;
    for i:=0 to ADOQuery1.FieldCount-1 do
    begin
      fields[i].Value:=ADOQuery1.Fields[i].Value;
    end;
    CDS_Sel.Post;
  end;

end;
procedure TfrmMaterialManySelHelp.TcloseClick(Sender: TObject);
begin
  close;
end;

procedure TfrmMaterialManySelHelp.TokClick(Sender: TObject);
begin
  if adoquery1.IsEmpty then
    ModalResult:=-1
  else
    modalResult:=1;
end;

procedure TfrmMaterialManySelHelp.edttjKeyPress(Sender: TObject;
  var Key: Char);
begin
  if key=#13 then
  begin
    with ADOQuery1 do
    begin
      ////////
      if RecordCount>=1 then
      begin
        AddSelRow();
      end;
      edttj.SelectAll ;
      EnableControls;
    end;
  end;
end;

procedure TfrmMaterialManySelHelp.Edit1Change(Sender: TObject);
begin
  try
      ADOQuery1.DisableControls;
      if trim(edit1.Text)<>'' then
      begin
        with ADOQuery1 do
        begin
          filtered:=false;
          filter:='model like '+quotedStr('%'+trim(edit1.Text)+'%');
          filtered:=true;
        end;
      end
      else
      begin
        with ADOQuery1 do
        begin
          filtered:=false;
        end;

      end;
  finally
      ADOQuery1.EnableControls;
  end;
end;

procedure TfrmMaterialManySelHelp.Tv1DblClick(Sender: TObject);
begin
   AddSelRow();
end;

procedure TfrmMaterialManySelHelp.TV2DblClick(Sender: TObject);
begin
  if CDS_sel.IsEmpty then exit;
  Cds_sel.Delete ;
end;

end.
