unit p_stocklist;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  RzButton, ExtCtrls, RzPanel, cxGridLevel, cxGridCustomTableView,
  cxGridCardView, cxGridDBCardView, cxClasses, cxControls,
  cxGridCustomView, cxGrid, StdCtrls, cxStyles, cxPropertiesStore,
  cxGridTableView, cxGridDBTableView;

type
  Tf_stocklist = class(TForm)
    RzPanel1: TRzPanel;
    RzPanel2: TRzPanel;
    RzBitBtn1: TRzBitBtn;
    RzBitBtn2: TRzBitBtn;
    cxGrid1: TcxGrid;
    cxGrid1Level1: TcxGridLevel;
    Edit1: TEdit;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxGrid1DBTableView1: TcxGridDBTableView;
    cxGrid1DBTableView1ITEM: TcxGridDBColumn;
    cxGrid1DBTableView1DESCR1: TcxGridDBColumn;
    cxGrid1DBTableView1POSPRICE1: TcxGridDBColumn;
    cxGrid1DBTableView1Column1: TcxGridDBColumn;
    cxStyle2: TcxStyle;
    cxGrid1DBTableView1Column2: TcxGridDBColumn;
    procedure Edit1Change(Sender: TObject);
    procedure cxGrid1DBCardView1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  f_stocklist: Tf_stocklist;myenter:integer;

implementation

uses p_posmodule;


{$R *.DFM}

procedure Tf_stocklist.Edit1Change(Sender: TObject);
begin
posmodule.stock.close;
posmodule.stock.sql.strings[1]:='where (descr1 like ''%'+trim(edit1.text)+'%'''+
' or (barcode1='''+edit1.text+''') or (barcode2='''+edit1.text+''') or (barcode3='''+
edit1.text+''') or (barcode4='''+edit1.text+''')  or (item like '''+edit1.text+'%''))' ;

posmodule.stock.open;
cxGrid1DBTableView1POSPRICE1.DataBinding.FieldName:='posprice1';
if trim(edit1.Text)<>'' then
begin

if (edit1.Text=posmodule.stockBARCODE1.AsString) then
cxGrid1DBTableView1POSPRICE1.DataBinding.FieldName:='price1'
else
if (edit1.Text=posmodule.stockBARCODE2.AsString) then
cxGrid1DBTableView1POSPRICE1.DataBinding.FieldName:='price2'

end
else
begin
cxGrid1DBTableView1POSPRICE1.DataBinding.FieldName:='posprice1'
end;

end;

procedure Tf_stocklist.cxGrid1DBCardView1CellClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
modalresult:=mrok;
end;

procedure Tf_stocklist.FormShow(Sender: TObject);
begin
if myenter=1 then
RzBitBtn2.Default:=true;
edit1.SetFocus;
 if posmodule.CONFIGSDISCOUNTTYPE.AsInteger=2 then
cxGrid1DBTableView1Column1.DataBinding.FieldName:='disc2';
end;

procedure Tf_stocklist.FormCreate(Sender: TObject);
begin
myenter:=0;
end;

procedure Tf_stocklist.Edit1KeyPress(Sender: TObject; var Key: Char);
var s:string;
begin
if key=#13 then
begin
try
s:=Edit1.text;
if (trim(s)='') then  exit;
posmodule.barcodes.close;
posmodule.barcodes.ParamByName('myitem').AsString:=s;
posmodule.barcodes.open;
if posmodule.barcodes.IsEmpty=false then
begin
posmodule.stock.close;
posmodule.stock.sql.strings[1]:= 'where item='''+posmodule.barcodes.fieldbyname('item').AsString+'''';
posmodule.stock.open;
end;
posmodule.barcodes.close;


except
end;

end;
end;

end.
