ypkc.pas
来自「完整的delphi书籍源代码,大家有空的时候自己慢慢看看」· PAS 代码 · 共 189 行
PAS
189 行
unit YPKC;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, Grids;
type
TYPKCFrm = class(TForm)
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
RadioButton1: TRadioButton;
ComboBox1: TComboBox;
Button1: TButton;
Button2: TButton;
ADOQuery1: TADOQuery;
ADOTable1: TADOTable;
ADOQuery2: TADOQuery;
StringGrid1: TStringGrid;
ADOQuery3: TADOQuery;
RadioButton2: TRadioButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
YPKCFrm: TYPKCFrm;
count:integer;
implementation
{$R *.dfm}
procedure TYPKCFrm.Button1Click(Sender: TObject);
var RKSL,CKSL,KCSL,YPMC:string;
i:integer;
begin
for i:=1 to count do
begin
with stringgrid1 do
begin
cells[0,i]:='';
cells[1,i]:='';
cells[2,i]:='';
cells[3,i]:='';
cells[4,i]:='';
cells[5,i]:='';
cells[6,i]:='';
end;
next;
end;
if Radiobutton1.checked=true then
if combobox1.text='' then
showmessage('请输入相应查询条件')
else
begin
with adoquery1 do
begin
close;
sql.clear;
sql.add('select sum(GRSL) RKSL from YPRK where YPMC='+''''+combobox1.text+'''');
open;
first;
if fieldbyname('RKSL').asstring='' then
RKSL:='0'
else
RKSL:=fieldbyname('RKSL').asstring;
end;
with adoquery1 do
begin
close;
sql.clear;
sql.add('select sum(XSSL) CKSL from YPXS where YPMC='+''''+combobox1.text+'''' );
open;
first;
if fieldbyname('CKSL').AsString='' then
CKSL:='0'
else
CKSL:=fieldbyname('CKSL').AsString;
end;
KCSL:=floattostr(strtofloat(RKSL)-strtofloat(CKSL));
with adoquery1 do
begin
close;
sql.clear;
sql.add('select * from YPXX where YPMC='+''''+combobox1.text+'''');
open;
first;
with stringgrid1 do
begin
cells[0,1]:=fieldbyname('YPBH').asstring;
cells[1,1]:=fieldbyname('YPMC').asstring;
cells[2,1]:=fieldbyname('JLDW').asstring;
cells[3,1]:=fieldbyname('YPLB').asstring;
cells[4,1]:=RKSL;
cells[5,1]:=CKSL;
cells[6,1]:=KCSL;
end;
end;
end;
if Radiobutton2.checked=true then
begin
with adoquery1 do
begin
close;
sql.clear;
sql.add('select sum(GRSL) RKSL,YPMC from YPRK group by YPMC');
open;
first;
count:=recordcount;
for i:=1 to recordcount do
begin
YPMC:=fieldbyname('YPMC').asstring;
RKSL:=fieldbyname('RKSL').asstring;
with adoquery2 do
begin
close;
sql.clear;
sql.add('select sum(XSSL) CKSL from YPXS where YPMC='+''''+YPMC+'''');
open;
first;
if fieldbyname('CKSL').AsString='' then
CKSL:='0'
else
CKSL:=fieldbyname('CKSL').AsString;
end;
KCSL:=floattostr(strtofloat(RKSL)-strtofloat(CKSL));
with adoquery3 do
begin
close;
sql.clear;
sql.add('select * from YPXX where YPMC='+''''+YPMC+'''');
open;
first;
with stringgrid1 do
begin
cells[0,i]:=fieldbyname('YPBH').asstring;
cells[1,i]:=fieldbyname('YPMC').asstring;
cells[2,i]:=fieldbyname('JLDW').asstring;
cells[3,i]:=fieldbyname('YPLB').asstring;
cells[4,i]:=RKSL;
cells[5,i]:=CKSL;
cells[6,i]:=KCSL;
end;
end;
next;
end;
end;
end;
end;
procedure TYPKCFrm.Button2Click(Sender: TObject);
begin
YPKCFrm.hide;
end;
procedure TYPKCFrm.FormCreate(Sender: TObject);
begin
while not ADOtable1.eof do
begin
combobox1.items.insert(-1,ADOtable1.fieldbyname('YPMC').asstring);
ADOtable1.Next;
end;
with stringgrid1 do
begin
cells[0,0]:='药品编号';
cells[1,0]:='药品名称';
cells[2,0]:='计量单位';
cells[3,0]:='药品类别';
cells[4,0]:='入库数量';
cells[5,0]:='出库数量';
cells[6,0]:='库存数量';
end;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?