一个十万火急的难题请教高手!(200分)

  • 主题发起人 主题发起人 周明
  • 开始时间 开始时间

周明

Unregistered / Unconfirmed
GUEST, unregistred user!
我用DELPHI设计一款进销存的软件,但是在仓库数量明细查询这一块出现了一个问题.按客户的要求需要达到按每个产品的名称在其结算日期查询其库存数量和按时间查询仓库里所有产品的库存量(库存量=进仓库的货-销售的货+退到仓库的货).前一个达到了要求,我想请教各位高手的是如何通过DELPHI语言实现既能按单个产品名称在其结算日期查询到该产品的库存量又能按一段时期或也其一定的结算日期查询到所有产品的库存量。

unit kcmxunit;

interface

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

type
Tkcmxfrm = class(TForm)
Panel1: TPanel;
Label2: TLabel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
DBGrid1: TDBGrid;
BitBtn3: TBitBtn;
GroupBox1: TGroupBox;
DateTimePicker1: TDateTimePicker;
Label3: TLabel;
ComboBox1: TComboBox;
GroupBox2: TGroupBox;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label5: TLabel;
Label6: TLabel;
BitBtn4: TBitBtn;
ComboBox2: TComboBox;
Label7: TLabel;
Label8: TLabel;
DateTimePicker3: TDateTimePicker;
Edit4: TEdit;
Label9: TLabel;
BitBtn5: TBitBtn;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
Edit5: TEdit;
Label4: TLabel;
CheckBox3: TCheckBox;
ComboBox3: TComboBox;
Label10: TLabel;
ComboBox4: TComboBox;
Label11: TLabel;
procedure kcmxfrmshow(Sender: TObject);

procedure BitBtn2Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure combobox1dp(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
procedure combobox2dp(Sender: TObject);
procedure BitBtn5Click(Sender: TObject);
procedure combobox3dp(Sender: TObject);
procedure combobox4dp(Sender: TObject);



private
{ Private declarations }
public
{ Public declarations }
end;

var
kcmxfrm: Tkcmxfrm;

implementation
uses dmunit,repkcmxunit;
{$R *.dfm}

procedure Tkcmxfrm.kcmxfrmshow(Sender: TObject);
begin
self.Caption:='库存明细表窗口';
combobox1.clear;
combobox2.Clear;
Left:=screen.Width div 2-width div 2;
Top:=screen.Height div 2-height div 2;

end;

procedure Tkcmxfrm.BitBtn2Click(Sender: TObject);
begin
self.Close;
end;

procedure Tkcmxfrm.BitBtn3Click(Sender: TObject);
var
i:integer;
shul,shu2,shu3,dj:variant;

begin
with dm.queryjk do
begin
sql.Clear;
sql.Add('select 产品单价,产品数量 from ingoods where 产品名称=:cpmc1');
parameters.Items[0].value:=trim(combobox1.Text);
execsql;
active:=true;
if dm.queryjk.RecordCount>0 then
dm.queryjk.First;
dj:=dm.queryjk.fieldbyname('产品单价').AsFloat;
for i:=0 to RecordCount-1 do
begin
shul:=dm.queryjk.fieldbyname('产品数量').AsInteger+shul;
dm.queryjk.next;
end;
edit1.Text:=floattostr(shul);
edit5.Text:=floattostr(dj);
end;
with dm.queryck do
begin
sql.Clear;
sql.Add('select 出库数量 from outgoods where 产品名称=:cpmc2');
parameters.Items[0].value:=trim(combobox1.Text);
execsql;
active:=true;
if dm.queryck.RecordCount>0 then
dm.queryck.First;

for i:=0 to RecordCount-1 do
begin
shu2:=dm.queryck.fieldbyname('出库数量').AsInteger+shu2;
dm.queryck.next;
end;
edit2.Text:=floattostr(shu2);
end;
with dm.querytk do
begin
sql.Clear;
sql.Add('select 退库数量 from thdata where 产品名称=:cpmc3');
parameters.Items[0].value:=trim(combobox1.Text);
execsql;
active:=true;
if dm.querytk.RecordCount>0 then
dm.querytk.First;

for i:=0 to RecordCount-1 do
begin
shu3:=dm.querytk.fieldbyname('退库数量').AsInteger+shu3;
dm.querytk.next;
end;
edit3.Text:=floattostr(shu3);
end;
edit4.Text:=floattostr(shul-shu2+shu3);
end;



procedure Tkcmxfrm.BitBtn1Click(Sender: TObject);
begin
Application.CreateForm(Trepkcmxfrm, repkcmxfrm);
repkcmxfrm.Preview;
repkcmxfrm.Free;
end;

procedure Tkcmxfrm.combobox1dp(Sender: TObject);
var
i:integer;
begin
combobox1.Clear;
if (dm.tchpdata.RecordCount>0) then
dm.tchpdata.First;
for i:=0 to dm.tchpdata.RecordCount-1 do
begin
combobox1.Items.Add(dm.tchpdata.fieldbyname('产品名称').AsString);
dm.tchpdata.Next;
end;
end;

procedure Tkcmxfrm.BitBtn4Click(Sender: TObject);
begin
dm.tthtkdata.Open;
dm.tthtkdata.Append;
dm.tthtkdata.FieldByName('产品名称').AsString:=trim(combobox1.Text);
dm.tthtkdata.FieldByName('单位').AsString:=trim(combobox2.Text);
dm.tthtkdata.FieldByName('产品数量').AsFloat:=strtofloat(edit1.Text);
dm.tthtkdata.FieldByName('出库数量').AsFloat:=strtofloat(edit2.Text);
dm.tthtkdata.FieldByName('退库数量').AsFloat:=strtofloat(edit3.Text);
dm.tthtkdata.FieldByName('结算日期').AsVariant:=datetimepicker3.Date;
dm.tthtkdata.FieldByName('库存数量').AsFloat:=strtofloat(edit4.Text);
dm.tthtkdata.FieldByName('单价').AsFloat:=strtofloat(edit5.Text);
dm.tthtkdata.FieldByName('经手人').AsString:=trim(combobox3.Text);
dm.tthtkdata.Post;
dbgrid1.DataSource:=dm.dsthtkdata;
end;

procedure Tkcmxfrm.combobox2dp(Sender: TObject);
var
i:integer;
begin
combobox2.Clear;
if (dm.tshpdwdata.RecordCount>0) then
dm.tshpdwdata.First;
for i:=0 to dm.tshpdwdata.RecordCount-1 do
begin
combobox2.Items.Add(dm.tshpdwdata.fieldbyname('商品单位').AsString);
dm.tshpdwdata.Next;
end;
end;

procedure Tkcmxfrm.BitBtn5Click(Sender: TObject);
begin
with dm.querykcmx do
begin
if checkbox1.Checked then
begin
sql.Clear;
sql.Add('select * from thtkdata where 结算日期=:jsrq');
parameters.Items[0].value:=datetostr(datetimepicker1.Date);
execsql;
active:=true;
end;
if checkbox2.Checked then
begin
sql.Clear;
sql.Add('select * from thtkdata where 产品名称=:jsrq1');
parameters.Items[0].value:=trim(combobox1.Text);
execsql;
active:=true;
end;
if checkbox3.Checked then
begin
sql.Clear;
sql.Add('select * from thtkdata where 经手人=:jsr');
parameters.Items[0].value:=trim(combobox4.Text);
execsql;
active:=true;
end;
if checkbox1.Checked and checkbox2.Checked then
begin
sql.Clear;
sql.Add('select * from thtkdata where 结算日期=:jsrq and 产品名称=:jsrq1');
parameters.Items[0].value:=datetostr(datetimepicker1.Date);
parameters.Items[1].value:=trim(combobox1.Text);
execsql;
active:=true;
end;
if checkbox1.Checked and checkbox3.Checked then
begin
sql.Clear;
sql.Add('select * from thtkdata where 结算日期=:jsrq and 经手人=:jsr');
parameters.Items[0].value:=datetostr(datetimepicker1.Date);
parameters.Items[1].value:=trim(combobox4.Text);
execsql;
active:=true;
end;

end;
dbgrid1.DataSource:=dm.dsquerykcmx;
end;

procedure Tkcmxfrm.combobox3dp(Sender: TObject);
var
i:integer;
begin
combobox3.Clear;
if (dm.tjshrdata.RecordCount>0) then
dm.tjshrdata.First;
for i:=0 to dm.tjshrdata.RecordCount-1 do
begin
combobox3.Items.Add(dm.tjshrdata.fieldbyname('经手人名称').AsString);
dm.tjshrdata.Next;
end;
end;

procedure Tkcmxfrm.combobox4dp(Sender: TObject);
var
i:integer;
begin
combobox4.Clear;
if (dm.tjshrdata.RecordCount>0) then
dm.tjshrdata.First;
for i:=0 to dm.tjshrdata.RecordCount-1 do
begin
combobox4.Items.Add(dm.tjshrdata.fieldbyname('经手人名称').AsString);
dm.tjshrdata.Next;
end;
end;

end.



这是源程序.如何实现按日期查询到仓库里所有产品的总库存量(进货量-出货量-退货)
 
后退
顶部