⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 selectgoods.pas

📁 飞恒进销存(超市批发)管理系统V5.1(含源程序) 语言:Delphi 6/7 相关控件:FastReport 2.4以上, Ehlib 3.4以上 1.数据库为fhe2db_V51.da
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit SelectGoods;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons,db, ExtCtrls, Grids, DBGridEh, ComCtrls, ADODB, Variants,
  ImgList;

type
  TSelectGoodsForm = class(TForm)
    Panel2: TPanel;
    Label3: TLabel;
    edtcode: TEdit;
    Panel1: TPanel;
    Panel3: TPanel;
    Panel4: TPanel;
    btnAdd: TBitBtn;
    btnDel: TBitBtn;
    btnOk: TBitBtn;
    Label1: TLabel;
    DBGridEh1: TDBGridEh;
    cboStore: TComboBox;
    TreeView1: TTreeView;
    dbgGoods: TDBGridEh;
    qrySelGoods: TADOQuery;
    connectTmp: TADOConnection;
    dsSelGoods: TDataSource;
    qryTmp: TADOQuery;
    lblPrice: TLabel;
    cboPrice: TComboBox;
    ILinfo: TImageList;
    procedure FormShow(Sender: TObject);
    procedure edtcodeKeyPress(Sender: TObject; var Key: Char);
    procedure TreeView1Click(Sender: TObject);
    procedure btnAddClick(Sender: TObject);
    procedure btnDelClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnOkClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure cboStoreSelect(Sender: TObject);
    procedure cboPriceSelect(Sender: TObject);
    procedure dbgGoodsKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DBGridEh1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure qrySelGoodsNewRecord(DataSet: TDataSet);
    procedure dbgGoodsDblClick(Sender: TObject);
    procedure edtcodeChange(Sender: TObject);
  private
    { Private declarations }
    FStatus:string;
    FCusId:integer;
    node1,node2,node3,node4:TTreeNode;
    function GetID(Fieldname,TableName:string):integer;
    function GetStoreId:integer;
  public
    { Public declarations }
    property NewStatus:string read FStatus write FStatus;
    property NewCusId:integer read FCusId write FCusId;
  end;

var
  SelectGoodsForm: TSelectGoodsForm;

implementation

uses datamodule1, Unitmb;

{$R *.DFM}

procedure TSelectGoodsForm.FormShow(Sender: TObject);
var
  nStoreid:integer;
  strsql:string;
begin
  datae2.QueryTmp.Close;
  btnDel.Enabled:=False;
  lblPrice.Visible:=(FStatus='O');
  cboPrice.Visible:=(FStatus='O');
  edtcode.Text:='';
  edtcode.SetFocus;
  if FStatus='I' then
  begin
    dbgGoods.Columns[7].Title.caption:='进价';
    dbgGoods.Columns[7].FieldName:='inPrice';
    DBGridEh1.Columns[4].Title.caption:='进价';
  end
  else if FStatus='O' then
  begin
    cboPrice.ItemIndex:=0;
    dbgGoods.Columns[7].Title.caption:='销售价1';
    dbgGoods.Columns[7].FieldName:='SpePrice';
    DBGridEh1.Columns[4].Title.caption:='销售价1';
  end;

  with DataE2.qryType1 do
  begin
    close;
    SQL.Clear;
    SQL.Add('select * from goodsType');
    open;
    first;
  end;
  TreeView1.Items.Clear;
  while not DataE2.qryType1.eof do
  begin
    node2:=TreeView1.Items.Add(node1,DataE2.qryType1.FieldValues['type']+' '+DataE2.qryType1.FieldValues['name']);
    node2.ImageIndex:=0;
    with DataE2.qryType2 do
    begin
      close;
      SQL.Clear;
      SQL.Add('select * from goodsType1');
      SQL.ADD('where type =:type');
      Parameters[0].Value:=DataE2.qryType1.FieldValues['type'];
      open;
      first;
      while not eof do
      begin
        node3:=TreeView1.Items.AddChild(node2,DataE2.qryType1.FieldValues['type']+FieldValues['code1']+' '+FieldValues['name']);
        with dataE2.qryType3 do
        begin
          close;
          SQL.Clear;
          SQL.Add('select * from goodsType2');
          SQL.ADD('where type =:type and code1 =:code1');
          Parameters[0].value:=dataE2.qryType2.FieldValues['type'];
          Parameters[1].value:=dataE2.qryType2.FieldValues['code1'];
          open;
          first;
          while not eof do
          begin
            node4:=TreeView1.Items.AddChild(node3,dataE2.qryType1.FieldValues['type']+
            dataE2.qryType2.FieldValues['code1']+FieldValues['code2']+' '+FieldValues['name']);
            next;
          end;
        end;
        next;
      end;
    end;
    DataE2.qryType1.next;
  end;

  with DataE2.queryDlg do
  begin
    close;
    SQL.Clear;
    SQL.Add('select storeid,name from store order by storeid');
    open;
    first;
    nStoreid:=FieldValues['Storeid'];
    cboStore.Items.Clear;
    while not eof do
    begin
      cboStore.Items.Add(FieldValues['name']);
      next;
    end;
    cboStore.ItemIndex:=0;
  end;
end;

procedure TSelectGoodsForm.edtcodeKeyPress(Sender: TObject; var Key: Char);
var
  strsql:string;
begin
  if key = #13 then
  begin
//    if FStatus='I' then
    strsql:='select * from vInGoods ';
    strsql:=strsql + ' where (code like :code';
    strsql:=strsql + ' or name like :name or barcode like :barcode)';
    strsql:=strsql + ' and (storeid = :storeid or storeid=0)';
    strsql:=strsql + ' order by code';
    with DataE2.QueryTmp do
    begin
      if Active then Close;
      SQL.Text:=strsql;
      Prepared:=true;
      Parameters[0].Value:=edtcode.Text+'%';
      Parameters[1].Value:='%'+edtcode.Text+'%';
      Parameters[2].Value:=edtcode.Text+'%';
      Parameters[3].Value:=GetStoreId;
      Open;
      if not Eof then
        dbgGoods.SetFocus;
    end;
  cboPrice.ItemIndex:=0;
  dbgGoods.Columns[7].FieldName:='SpePrice';
{    else if FStatus='O' then
    begin
      strsql:='select * from vOutGoods ';
      strsql:=strsql + ' where (code like :code';
      strsql:=strsql + ' or name like :name)';
      strsql:=strsql + ' and (storeid = :storeid or storeid=0)';
      strsql:=strsql + ' and (clientid = :clientid or clientid=-1)';
      strsql:=strsql + ' order by code';
      with DataE2.QueryTmp do
      begin
        if Active then Close;
        SQL.Text:=strsql;
        Prepared:=true;
        Parameters[0].Value:=edtcode.Text+'%';
        Parameters[1].Value:=edtcode.Text+'%';
        Parameters[2].Value:=GetStoreId;
        Parameters[3].Value:=FCusId;
        Open;
        if not Eof then
          dbgGoods.SetFocus;
      end;
    end;}
  end;
end;

procedure TSelectGoodsForm.TreeView1Click(Sender: TObject);
var
  strsql:string;
begin
//  if FStatus='I' then
  strsql:='select * from vInGoods ';
  strsql:=strsql + ' where (storeid = :storeid or storeid=0)';
  strsql:=strsql + ' and typeCode like :typeCode';
  strsql:=strsql + ' order by code';
  with DataE2.QueryTmp do
  begin
    if Active then Close;
    SQL.Text:=strsql;
    Prepared:=true;
    Parameters[0].Value:=GetStoreId;
    Parameters[1].Value:=copy(TreeView1.Selected.Text,1,pos(' ',TreeView1.Selected.Text)-1)+'%';
    Open;
  end;
  cboPrice.ItemIndex:=0;
  dbgGoods.Columns[7].FieldName:='SpePrice';
{  else if FStatus='O' then
  begin
    strsql:='select * from vOutGoods ';
    strsql:=strsql + ' where (storeid = :storeid or storeid=0)';
    strsql:=strsql + ' and (clientid = :clientid or clientid=-1)';
    strsql:=strsql + ' and typeCode like :typeCode';
    strsql:=strsql + ' order by code';
    with DataE2.QueryTmp do
    begin
      if Active then Close;
      SQL.Text:=strsql;
      Prepared:=true;
      Parameters[0].Value:=GetStoreId;
      Parameters[1].Value:=FCusId;
      Parameters[2].Value:=copy(TreeView1.Selected.Text,1,pos(' ',TreeView1.Selected.Text)-1)+'%';
      Open;
    end;
  end; }
end;

function TSelectGoodsForm.GetStoreId: integer;
begin
  with DataE2.queryDlg do
  begin
    close;
    SQL.Clear;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -