📄 ustockin.pas
字号:
unit Ustockin;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls, ComCtrls, ExtCtrls, Buttons, DB, ADODB,
dxCntner, dxEditor, dxExEdtr, dxEdLib, Menus, RpRave, RpDefine, RpCon,
RpConDS;
type
Tfrmstockin = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
DTPicker1: TDateTimePicker;
DTPicker2: TDateTimePicker;
Label4: TLabel;
ComboBox1: TComboBox;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
Panel2: TPanel;
Label3: TLabel;
Edit2: TEdit;
Label5: TLabel;
ComboBox2: TComboBox;
Label6: TLabel;
DTPicker3: TDateTimePicker;
Label7: TLabel;
ComboBox3: TComboBox;
Label8: TLabel;
Edit3: TEdit;
Label9: TLabel;
Edit4: TEdit;
SpeedButton1: TSpeedButton;
Label10: TLabel;
Panel3: TPanel;
SpeedButton2: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
SpeedButton8: TSpeedButton;
SpeedButton9: TSpeedButton;
ADOQuery1: TADOQuery;
ADOQuery2: TADOQuery;
dxButtonEdit1: TdxButtonEdit;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
ADOQuery3: TADOQuery;
stockintConnection1: TRvDataSetConnection;
RvProject1: TRvProject;
stockinConnection2: TRvDataSetConnection;
procedure FormCreate(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure StringGrid1Click(Sender: TObject);
procedure SpeedButton5Click(Sender: TObject);
procedure SpeedButton6Click(Sender: TObject);
procedure StringGrid2SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure dxButtonEdit1Exit(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure dxButtonEdit1ButtonClick(Sender: TObject;
AbsoluteIndex: Integer);
procedure SpeedButton9Click(Sender: TObject);
procedure SpeedButton8Click(Sender: TObject);
procedure StringGrid2KeyPress(Sender: TObject; var Key: Char);
procedure StringGrid2KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure StringGrid2Exit(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure SpeedButton7Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmstockin: Tfrmstockin;
implementation
uses Udatamodule, Ufilprod, Uchobook;
{$R *.dfm}
procedure Tfrmstockin.FormCreate(Sender: TObject);
var
i,arow:integer;
begin
stringgrid1.Cells[1,0]:='单据编号';
stringgrid1.Cells[2,0]:='供应商';
stringgrid1.Cells[3,0]:='到货日期';
stringgrid2.Cells[1,0]:='商品编号';
stringgrid2.Cells[2,0]:='商品名称';
stringgrid2.Cells[3,0]:='商品数量';
stringgrid2.Cells[4,0]:='商品进价';
stringgrid2.Cells[5,0]:='商品总价';
dtpicker1.Date:=date-7;
dtpicker2.Date:=date;
dtpicker3.Date:=date;
adoquery1.SQL.Text:='select provid,provname from provinfo';
adoquery1.Open;
while not adoquery1.Eof do
begin
combobox1.Items.Add(adoquery1.FieldValues['provid']+' '+adoquery1.FieldValues['provname']);
combobox2.Items.Add(adoquery1.FieldValues['provid']+' '+adoquery1.FieldValues['provname']);
adoquery1.Next;
end;
adoquery1.Close;
adoquery1.SQL.Text:='select filname from filiale';
adoquery1.Open;
while not adoquery1.Eof do
begin
combobox3.Items.Add(adoquery1.FieldValues['filname']);
adoquery1.Next;
end;
adoquery1.Close;
adoquery1.SQL.Text:='select * from stockin ';
adoquery1.Open;
if adoquery1.RecordCount > 0 then
begin
edit2.Text:=adoquery1.FieldValues['stockid'];
edit3.Text:=adoquery1.FieldValues['handleman'];
edit4.Text:=adoquery1.FieldValues['accounts'];
dtpicker3.Date:=adoquery1.FieldValues['stockdate'];
for i:=0 to combobox2.Items.Count-1 do
if copy(combobox2.Items.Strings[i],1,5) = adoquery1.FieldByName('provid').AsString then
begin
combobox2.ItemIndex:=i;
break;
end;
adoquery2.SQL.Text:='select filname from filiale where filid = '''+adoquery1.FieldValues['filid']+'''';
adoquery2.Open;
for i:=0 to combobox3.Items.Count-1 do
begin
if combobox3.Items.Strings[i] = adoquery2.FieldByName('filname').AsString then
begin
combobox3.ItemIndex:=i;
break;
end;
end;
stringgrid1.RowCount:=adoquery1.RecordCount+1;
arow:=1;
while not adoquery1.Eof do
begin
stringgrid1.Cells[1,arow]:=adoquery1.FieldValues['stockid'];
stringgrid1.Cells[2,arow]:=adoquery1.FieldValues['provid'];
stringgrid1.Cells[3,arow]:=adoquery1.FieldValues['stockdate'];
adoquery1.Next;
inc(arow);
end;
adoquery1.Close;
stringgrid1.Cols[0].Clear;
stringgrid1.Cells[0,1]:='*';
adoquery1.SQL.Text:='select stockin1.prid,pluinfo.prname,stockin1.stocknum,'+
' stockin1.stoprice from stockin1 inner join pluinfo on stockin1.prid = pluinfo.prid'+
' where stockid = '''+edit2.Text+'''';
adoquery1.Open;
if adoquery1.RecordCount > 0 then
begin
stringgrid2.RowCount:=adoquery1.RecordCount+1;
for i:=1 to stringgrid2.RowCount-1 do
begin
stringgrid2.Cells[1,i]:=adoquery1.FieldValues['prid'];
stringgrid2.Cells[2,i]:=adoquery1.FieldValues['prname'];
stringgrid2.Cells[3,i]:=adoquery1.FieldValues['stocknum'];
stringgrid2.Cells[4,i]:=adoquery1.FieldValues['stoprice'];
stringgrid2.Cells[5,i]:=floattostr(strtofloat(stringgrid2.Cells[3,i])*strtofloat(stringgrid2.Cells[4,i]));
adoquery1.Next;
end;
end;
adoquery1.Close;
end;
end;
procedure Tfrmstockin.SpeedButton2Click(Sender: TObject);
var
ayear,amonth,adate:word;
smonth,sdate,maxid:string;
i:integer;
begin
dtpicker3.Date:=date;
combobox2.Enabled:=true;combobox2.ItemIndex:=-1;
combobox3.Enabled:=true;combobox3.ItemIndex:=-1;
edit3.Enabled:=true;edit3.Text:='';
edit4.Text:='';
dtpicker3.Enabled:=true;
edit1.Enabled:=false;
dtpicker1.Enabled:=false;
dtpicker2.Enabled:=false;
combobox1.Enabled:=false;
speedbutton1.Enabled:=false;
speedbutton2.Enabled:=false;
speedbutton5.Enabled:=true;
speedbutton6.Enabled:=true;
speedbutton7.Enabled:=false;
speedbutton8.Enabled:=true;
speedbutton9.Enabled:=false;
decodedate(date,ayear,amonth,adate);
smonth:=inttostr(amonth);sdate:=inttostr(adate);
if length(smonth) < 2 then smonth:= '0'+smonth;
if length(sdate) < 2 then sdate:='0'+sdate;
maxid:=inttostr(ayear)+smonth+sdate;
adoquery1.SQL.Text:='select max(stockid) as maxid from stockin where stockid like '''+maxid+'%''';
adoquery1.Open;
if adoquery1.FieldValues['maxid'] = null then
edit2.Text:=maxid+'0001'
else
edit2.Text:=inttostr(strtoint64(adoquery1.FieldValues['maxid'])+1);
adoquery1.Close;
for i:=1 to stringgrid2.RowCount-1 do
stringgrid2.Rows[i].Clear;
stringgrid2.RowCount:=2;
stringgrid1.Cols[0].Clear;
end;
procedure Tfrmstockin.SpeedButton1Click(Sender: TObject);
var
i,arow:integer;
begin
for i:=1 to stringgrid1.RowCount-1 do
stringgrid1.Rows[i].Clear;
stringgrid1.RowCount:=2;
for i:=1 to stringgrid2.RowCount-1 do
stringgrid2.Rows[i].Clear;
stringgrid1.RowCount:=2;
adoquery1.SQL.Text:='select stockid,provid,stockdate,handleman,filid,accounts from stockin where stockdate between #'+datetostr(dtpicker1.date)+'# and #'+datetostr(dtpicker2.date)+'#';
if edit1.Text <> '' then
adoquery1.SQL.Add('and stockid = '''+edit1.Text+'''');
if combobox1.Text <> '' then
adoquery1.SQL.add('and provid = '''+copy(combobox1.Text,1,5)+'''');
adoquery1.Open;
if adoquery1.RecordCount > 0 then
begin
edit2.Text:=adoquery1.FieldValues['stockid'];
edit3.Text:=adoquery1.FieldValues['handleman'];
edit4.Text:=adoquery1.FieldValues['accounts'];
dtpicker3.Date:=adoquery1.FieldValues['stockdate'];
for i:=0 to combobox2.Items.Count-1 do
if copy(combobox2.Items.Strings[i],1,5) = adoquery1.FieldByName('provid').AsString then
begin
combobox2.ItemIndex:=i;
break;
end;
adoquery2.SQL.Text:='select filname from filiale where filid = '''+adoquery1.FieldValues['filid']+'''';
adoquery2.Open;
for i:=0 to combobox3.Items.Count-1 do
begin
if combobox3.Items.Strings[i] = adoquery2.FieldByName('filname').AsString then
begin
combobox3.ItemIndex:=i;
break;
end;
end;
stringgrid1.RowCount:=adoquery1.RecordCount+1;
arow:=1;
while not adoquery1.Eof do
begin
stringgrid1.Cells[1,arow]:=adoquery1.FieldValues['stockid'];
stringgrid1.Cells[2,arow]:=adoquery1.FieldValues['provid'];
stringgrid1.Cells[3,arow]:=adoquery1.FieldValues['stockdate'];
adoquery1.Next;
inc(arow);
end;
adoquery1.Close;
stringgrid1.Cols[0].Clear;
stringgrid1.Cells[0,1]:='*';
adoquery1.SQL.Text:='select stockin1.prid,pluinfo.prname,stockin1.stocknum,'+
' stockin1.stoprice from stockin1 inner join pluinfo on stockin1.prid = pluinfo.prid'+
' where stockid = '''+edit2.Text+'''';
adoquery1.Open;
if adoquery1.RecordCount > 0 then
begin
stringgrid2.RowCount:=adoquery1.RecordCount+1;
for i:=1 to stringgrid2.RowCount-1 do
begin
stringgrid2.Cells[1,i]:=adoquery1.FieldValues['prid'];
stringgrid2.Cells[2,i]:=adoquery1.FieldValues['prname'];
stringgrid2.Cells[3,i]:=adoquery1.FieldValues['stocknum'];
stringgrid2.Cells[4,i]:=adoquery1.FieldValues['stoprice'];
stringgrid2.Cells[5,i]:=floattostr(strtofloat(stringgrid2.Cells[3,i])*strtofloat(stringgrid2.Cells[4,i]));
adoquery1.Next;
end;
end;
adoquery1.Close;
end
else begin
edit2.Text:='';
edit3.Text:='';
edit4.Text:='';
combobox2.ItemIndex:=-1;
combobox3.ItemIndex:=-1;
end;
end;
procedure Tfrmstockin.StringGrid1Click(Sender: TObject);
var
i:integer;
begin
if ((stringgrid1.Row > 0) and (stringgrid1.Cells[1,1] <> '')) then
begin
for i:=1 to stringgrid2.RowCount-1 do
stringgrid2.Rows[i].Clear;
stringgrid2.RowCount:=2;
stringgrid1.Cols[0].Clear;
stringgrid1.Cells[0,stringgrid1.Row]:='*';
edit2.Text:=stringgrid1.Cells[1,stringgrid1.Row];
for i:=0 to combobox2.Items.Count-1 do
if copy(combobox2.Items.Strings[i],1,5) = stringgrid1.Cells[2,stringgrid1.Row] then
begin
combobox2.ItemIndex:=i;
break;
end;
dtpicker3.Date:=strtodatetime(stringgrid1.Cells[3,stringgrid1.row]);
adoquery1.SQL.Text:='select handleman,filid,accounts from stockin where stockid = '''+edit2.Text+'''';
adoquery1.Open;
adoquery2.SQL.Text:='select filname from filiale where filid = '''+adoquery1.FieldValues['filid']+'''';
adoquery2.Open;
for i:=0 to combobox3.Items.Count-1 do
if combobox3.Items.Strings[i] = adoquery2.Fields[0].AsString then
begin
combobox3.ItemIndex:=i;
break;
end;
adoquery2.Close;
edit3.Text:=adoquery1.FieldValues['handleman'];
edit4.Text:=adoquery1.FieldValues['accounts'];
adoquery1.Close;
adoquery1.SQL.Text:='select stockin1.prid,pluinfo.prname,stockin1.stocknum,'+
' stockin1.stoprice from stockin1 inner join pluinfo on stockin1.prid = pluinfo.prid'+
' where stockid = '''+edit2.Text+'''';
adoquery1.Open;
if adoquery1.RecordCount > 0 then
begin
stringgrid2.RowCount:=adoquery1.RecordCount+1;
for i:=1 to stringgrid2.RowCount-1 do
begin
stringgrid2.Cells[1,i]:=adoquery1.FieldValues['prid'];
stringgrid2.Cells[2,i]:=adoquery1.FieldValues['prname'];
stringgrid2.Cells[3,i]:=adoquery1.FieldValues['stocknum'];
stringgrid2.Cells[4,i]:=adoquery1.FieldValues['stoprice'];
stringgrid2.Cells[5,i]:=floattostr(strtofloat(stringgrid2.Cells[3,i])*strtofloat(stringgrid2.Cells[4,i]));
adoquery1.Next;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -