cpxxcxsz.pas

来自「一个仓库管理中的子系统--采购子系统」· PAS 代码 · 共 294 行

PAS
294
字号
unit cpxxcxsz;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, StdCtrls, DBGrids, ExtCtrls, Buttons;

type
  TwzxxcxForm = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    DBGrid1: TDBGrid;
    cpbhEdit: TEdit;
    Label2: TLabel;
    StringGrid1: TStringGrid;
    Label3: TLabel;
    Label4: TLabel;
    cpmcEdit: TEdit;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    Label5: TLabel;
    xhggEdit: TEdit;
    procedure cpbhEditChange(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure cpmcEditExit(Sender: TObject);
    procedure cpmcEditKeyPress(Sender: TObject; var Key: Char);
    procedure BitBtn3Click(Sender: TObject);
    procedure cpbhEditKeyPress(Sender: TObject; var Key: Char);
    procedure cpmcEditChange(Sender: TObject);
    procedure xhggEditChange(Sender: TObject);
  private
    { Private declarations }
  public
  cpbhstr:string;
  cpmcstr:string;
  xhggstr:string;
  Function IntToStrPad0(N:LongInt;Len:Integer):string;
    { Public declarations }
  end;

var
  wzxxcxForm: TwzxxcxForm;

implementation

uses Datamodule, wzsz;

{$R *.DFM}

Function TwzxxcxForm.IntToStrPad0(N:LongInt;Len:Integer):string; //定制字符串的长度,不够的加零补齐
begin
   FmtStr(Result,'%d',[N]);
   while Length(Result)<len do
    Result:='0'+Result;
end;

procedure TwzxxcxForm.cpbhEditChange(Sender: TObject);
begin
    if cpmcedit.Text<>'' then
    cpmcedit.Text:='';
    with datamodule1.wzdmquery do
    begin
    sql.clear;
    sql.Add('select wzidh as 物资编号,wzmc as 物资名称,xhgg as 型号规格 From dbo.e_wzdmb');
    sql.Add('where wzidh like '+''''+cpbhedit.text+'%'+'''');
    prepare;
    open;
    with stringGrid1 do
    begin
    cells[0,0]:=FieldByName('物资编号').asstring;
    cells[1,0]:=FieldByName('物资名称').asstring;
    cells[2,0]:=FieldByName('型号规格').asstring;
    cpbhstr:=cells[0,0];
    cpmcstr:=cells[1,0];
    xhggstr:=cells[2,0];
    end;
    end;
    if length(cpbhedit.text)=11 then
    if datamodule1.wzdmquery.RecordCount=0 then
    showmessage('该物资编号不存在,请新增该物资!');
end;

procedure TwzxxcxForm.FormActivate(Sender: TObject);
begin
    cpbhstr:='';
    cpmcstr:='';
    xhggstr:='';
    with datamodule1.wzdmquery do
    begin
    sql.clear;
    sql.Add('select wzidh as 物资编号,wzmc as 物资名称,xhgg as 型号规格 From dbo.e_wzdmb');
    sql.Add('where wzidh like '+''''+cpbhedit.text+'%'+'''');
    prepare;
    open;
    with stringGrid1 do
    begin
    cells[0,0]:=FieldByName('物资编号').asstring;
    cells[1,0]:=FieldByName('物资名称').asstring;
    cells[2,0]:=FieldByName('型号规格').asstring;
    {cpbhstr:=cells[0,0];
    cpmcstr:=cells[1,0];
    xhggstr:=cells[2,0];}
    end;
    end;

end;

procedure TwzxxcxForm.cpmcEditExit(Sender: TObject);
begin
    {if (cpbhedit.Text<>'') and (xhggedit.Text<>'') then
     with datamodule1.wzdmquery do
    begin
    sql.clear;
    sql.Add('select wzidh as 物资编号,wzmc as 物资名称,xhgg as 型号规格 From dbo.e_wzdmb');
    sql.Add('where wzidh like '+''''+cpbhedit.text+'%'+''''+' and xhgg='+''''+xhggedit.Text+'''');
    prepare;
    open;
    with stringGrid1 do
    begin
    cells[0,0]:=FieldByName('物资编号').asstring;
    cells[1,0]:=FieldByName('物资名称').asstring;
    cells[2,0]:=FieldByName('型号规格').asstring;
    cpbhstr:=cells[0,0];
    cpmcstr:=cells[1,0];
    xhggstr:=cells[2,0];
    end;
    end;}
end;

procedure TwzxxcxForm.cpmcEditKeyPress(Sender: TObject; var Key: Char);
begin
    {if key=#13 then
    if (cpbhedit.Text<>'') and (xhggedit.Text<>'') then
    with datamodule1.wzdmquery do
    begin
    sql.clear;
    sql.Add('select wzidh as 物资编号,wzmc as 物资名称,xhgg as 型号规格 From dbo.e_wzdmb');
    sql.Add('where wzidh like '+''''+cpbhedit.text+'%'+''''+' and xhgg='+''''+xhggedit.Text+'''');
    prepare;
    open;
    with stringGrid1 do
    begin
    cells[0,0]:=FieldByName('物资编号').asstring;
    cells[1,0]:=FieldByName('物资名称').asstring;
    cells[2,0]:=FieldByName('型号规格').asstring;
    cpbhstr:=cells[0,0];
    cpmcstr:=cells[1,0];
    xhggstr:=cells[2,0];
    end;
    end;}
end;

procedure TwzxxcxForm.BitBtn3Click(Sender: TObject);
begin
    if length(cpbhedit.Text)<6 then
    begin
    showmessage('请您输入物资的六位类别号!');
    exit;
    end;
    with datamodule1.PublicQuery1 do
    begin
    sql.Clear;
    sql.Add('select * From dbo.e_wzdmb');
    sql.Add('where wzidh like '+''''+copy(cpbhedit.text,1,6)+'%'+'''');
    prepare;
    open;
    wzszForm:=TwzszForm.Create(application);
    wzszForm.wzidedit.text:=copy(cpbhedit.text,1,6)+IntToStrPad0(RecordCount+1,5);
    wzszForm.wzmcEdit.text:=FieldByname('wzmc').asstring;
    close;
    end;
    hide;
    if wzszForm.ShowModal=mrOK then
    cpbhedit.text:=wzszForm.wzidEdit.Text;
    wzszForm.free;
    show;
end;

procedure TwzxxcxForm.cpbhEditKeyPress(Sender: TObject; var Key: Char);
begin
    if length(cpbhedit.Text)=11 then
    if  not (key in [#8,#13]) then
    begin
    key:=#0;
    beep;
    end;
end;

procedure TwzxxcxForm.cpmcEditChange(Sender: TObject);
begin
    if xhggedit.Text='' then
    begin
    if cpbhedit.Text<>'' then
    cpbhedit.Text:='';
    with datamodule1.wzdmquery do
    begin
    sql.clear;
    sql.Add('select wzidh as 物资编号,wzmc as 物资名称,xhgg as 型号规格 From dbo.e_wzdmb');
    sql.Add('where wzmc like '+''''+'%'+cpmcedit.text+'%'+'''');
    prepare;
    open;
    with stringGrid1 do
    begin
    cells[0,0]:=FieldByName('物资编号').asstring;
    cells[1,0]:=FieldByName('物资名称').asstring;
    cells[2,0]:=FieldByName('型号规格').asstring;
    cpbhstr:=cells[0,0];
    cpmcstr:=cells[1,0];
    xhggstr:=cells[2,0];
    end;
    end;
    end
    else
    begin
    if cpbhedit.Text<>'' then
    cpbhedit.Text:='';
    with datamodule1.wzdmquery do
    begin
    sql.clear;
    sql.Add('select wzidh as 物资编号,wzmc as 物资名称,xhgg as 型号规格 From dbo.e_wzdmb');
    sql.Add('where wzmc like '+''''+'%'+cpmcedit.text+'%'+''''+' and '+'xhgg like '+''''+xhggedit.Text+'%'+'''');
    prepare;
    open;
    with stringGrid1 do
    begin
    cells[0,0]:=FieldByName('物资编号').asstring;
    cells[1,0]:=FieldByName('物资名称').asstring;
    cells[2,0]:=FieldByName('型号规格').asstring;
    cpbhstr:=cells[0,0];
    cpmcstr:=cells[1,0];
    xhggstr:=cells[2,0];
    end;
    end;
    end;
    {if length(cpbhedit.text)=11 then
    if datamodule1.wzdmquery.RecordCount=0 then
    showmessage('该物资编号不存在,请新增该物资!');}
end;

procedure TwzxxcxForm.xhggEditChange(Sender: TObject);
begin
   if cpmcedit.Text='' then
    begin
    if cpbhedit.Text<>'' then
    cpbhedit.Text:='';
    with datamodule1.wzdmquery do
    begin
    sql.clear;
    sql.Add('select wzidh as 物资编号,wzmc as 物资名称,xhgg as 型号规格 From dbo.e_wzdmb');
    sql.Add('where xhgg like '+''''+'%'+xhggedit.text+'%'+'''');
    prepare;
    open;
    with stringGrid1 do
    begin
    cells[0,0]:=FieldByName('物资编号').asstring;
    cells[1,0]:=FieldByName('物资名称').asstring;
    cells[2,0]:=FieldByName('型号规格').asstring;
    cpbhstr:=cells[0,0];
    cpmcstr:=cells[1,0];
    xhggstr:=cells[2,0];
    end;
    end;
    end
    else
    begin
    if cpbhedit.Text<>'' then
    cpbhedit.Text:='';
    with datamodule1.wzdmquery do
    begin
    sql.clear;
    sql.Add('select wzidh as 物资编号,wzmc as 物资名称,xhgg as 型号规格 From dbo.e_wzdmb');
    sql.Add('where wzmc like '+''''+'%'+cpmcedit.text+'%'+''''+' and '+'xhgg like '+''''+xhggedit.Text+'%'+'''');
    prepare;
    open;
    with stringGrid1 do
    begin
    cells[0,0]:=FieldByName('物资编号').asstring;
    cells[1,0]:=FieldByName('物资名称').asstring;
    cells[2,0]:=FieldByName('型号规格').asstring;
    cpbhstr:=cells[0,0];
    cpmcstr:=cells[1,0];
    xhggstr:=cells[2,0];
    end;
    end;
    end;
    {if length(cpbhedit.text)=11 then
    if datamodule1.wzdmquery.RecordCount=0 then
    showmessage('该物资编号不存在,请新增该物资!');}
end;

end.

⌨️ 快捷键说明

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