uwhref.~pas
来自「DELPHI编程入门篇.从基础入手,浅显易懂,一定物有所值.」· ~PAS 代码 · 共 679 行 · 第 1/2 页
~PAS
679 行
end;
if stringgrid2.Cells[5,i] <> '' then
totalacc:=totalacc+strtofloat(stringgrid2.Cells[5,i]);
end;
if totalacc <> 0 then
edit4.Text:=floattostr(totalacc);
if edit4.Text = '' then
begin
showmessage('商品总价不能为空');
exit;
end;
adoquery1.SQL.Text:='select stockid from stockin where stockid = '''+edit2.Text+'''';
adoquery1.Open;
if adoquery1.RecordCount > 0 then
begin
showmessage('单据编号重复');
exit;
end;
adoquery1.Close;
sclient:=copy(combobox2.Text,1,5);
adoquery2.SQL.Text:='select filid from filiale where filname = '''+combobox3.Text+'''';
adoquery2.Open;
sfiliale:=adoquery2.Fields[0].AsString;
adoquery2.Close;
try
adoquery1.Connection.BeginTrans;
adoquery1.SQL.Text:='insert into whrefund values("'+edit2.Text+'","'+sclient+'",'
+'"'+sfiliale+'","'+datetostr(dtpicker3.Date)+'","'+edit3.Text+'","'+edit4.Text+'")';
adoquery2.Connection.BeginTrans;
for i:=1 to stringgrid2.RowCount-1 do
begin
adoquery2.SQL.Text:='insert into whrefund1 values("'+edit2.Text+'","'+stringgrid2.Cells[1,i]+'",'
+'"'+stringgrid2.Cells[3,i]+'","'+stringgrid2.Cells[4,i]+'")';
adoquery2.ExecSQL;
adoquery3.SQL.Text:='select prid,busanum from busary where filid = '''
+sfiliale+''' and prid = '''+stringgrid2.Cells[1,i]+'''';
adoquery3.Open;
if adoquery3.RecordCount > 0 then
begin
adoquery3.Edit;
adoquery3.FieldByName('busanum').AsFloat:=adoquery3.FieldByName('busanum').AsFloat+strtofloat(stringgrid2.Cells[3,i]);
adoquery3.Post;
adoquery3.Close;
end
else begin
adoquery3.Close;
adoquery3.SQL.Text:='insert into busary (filid,prid,busanum) values'+
'("'+sfiliale+'","'+stringgrid2.Cells[1,i]+'",'+stringgrid2.Cells[3,i]+')';
adoquery3.ExecSQL;
adoquery3.Close;
end;
end;
adoquery1.ExecSQL;
adoquery2.Connection.CommitTrans;
adoquery1.Connection.CommitTrans;
adoquery2.Close;
adoquery1.Close;
showmessage('保存成功!');
edit1.Enabled:=true;combobox1.Enabled:=true;
dtpicker1.Enabled:=true;dtpicker2.Enabled:=true;
edit2.Enabled:=false;
edit3.Enabled:=false;
combobox2.Enabled:=false;
combobox3.Enabled:=false;
dtpicker3.Enabled:=false;
speedbutton1.Enabled:=true;
speedbutton2.Enabled:=true;
speedbutton5.Enabled:=false;
speedbutton6.Enabled:=false;
speedbutton7.Enabled:=true;
speedbutton9.Enabled:=true;
except
adoquery2.Connection.RollbackTrans;
adoquery1.Connection.RollbackTrans;
adoquery2.Close;
adoquery1.Close;
end;
stringgrid2.Options:=stringgrid2.Options-[goediting];
end;
procedure Tfrmwhref.SpeedButton6Click(Sender: TObject);
var
i:integer;
begin
edit1.Enabled:=true;
combobox1.Enabled:=true;
dtpicker1.Enabled:=true;
dtpicker2.Enabled:=true;
edit2.Enabled:=false; edit2.Text:='';
edit3.Enabled:=false; edit3.Text:='';
edit4.Text:='';
combobox2.Enabled:=false; combobox2.ItemIndex:=-1;
combobox3.Enabled:=false; combobox3.ItemIndex:=-1;
dtpicker3.Enabled:=false;
speedbutton1.Enabled:=true;
speedbutton2.Enabled:=true;
speedbutton5.Enabled:=false;
speedbutton6.Enabled:=false;
speedbutton7.Enabled:=true;
speedbutton9.Enabled:=true;
for i:=1 to stringgrid2.RowCount-1 do
stringgrid2.Rows[i].Clear;
stringgrid2.RowCount:=2;
stringgrid2.Options:=stringgrid2.Options-[goediting];
end;
procedure Tfrmwhref.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 whrefund where wrefid = '''+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 whrefund1.wrefid,pluinfo.prname,whrefund1.refnum,'+
' whrefund1.price from whrefund1 inner join pluinfo on whrefund1.prid = pluinfo.prid'+
' where wrefid = '''+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['wrefid'];
stringgrid2.Cells[2,i]:=adoquery1.FieldValues['prname'];
stringgrid2.Cells[3,i]:=adoquery1.FieldValues['refnum'];
stringgrid2.Cells[4,i]:=adoquery1.FieldValues['price'];
stringgrid2.Cells[5,i]:=floattostr(strtofloat(stringgrid2.Cells[3,i])*strtofloat(stringgrid2.Cells[4,i]));
adoquery1.Next;
end;
end;
adoquery1.Close;
end;
end;
procedure Tfrmwhref.StringGrid2KeyPress(Sender: TObject; var Key: Char);
var
i,pnum,acol:integer;
str:string;
begin
acol:=stringgrid2.Col;
if ((not (key in ['0'..'9'])) and (key <> '.') and (key <>#8 ) and (key <>#3)) then
begin
showmessage('请输入数字或小数点');
key:=chr(0);
end
else begin
str:=stringgrid2.Cells[acol,stringgrid2.Row];
pnum:=0;
for i:=1 to length(str) do
if str[i] = '.' then inc(pnum);
if ((pnum >0) and (key = '.')) then
key:=chr(0);
end;
end;
procedure Tfrmwhref.StringGrid2KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
acol,arow:integer;
begin
acol:=stringgrid2.Col; arow:=stringgrid2.row;
if (acol = 4) then
begin
if (stringgrid2.Cells[4,arow] <> '') then
begin
if stringgrid2.Cells[3,arow] = '' then
begin
showmessage('请输入商品数量');
stringgrid2.Cells[4,arow]:= '';
stringgrid2.col:=3;
exit;
end
else
stringgrid2.Cells[5,arow]:=floattostr(strtofloat(stringgrid2.Cells[3,arow]) * strtofloat(stringgrid2.Cells[4,arow]));
end
else
stringgrid2.Cells[5,arow]:='';
end;
if ((acol = 3) and (stringgrid2.Cells[4,arow] <> '')) then
begin
stringgrid2.Cells[5,arow]:=floattostr(strtofloat(stringgrid2.Cells[3,arow]) * strtofloat(stringgrid2.Cells[4,arow]));
end;
end;
procedure Tfrmwhref.StringGrid2Exit(Sender: TObject);
var
totalacc:real;
i:integer;
begin
totalacc:=0;
for i:=1 to stringgrid2.RowCount-1 do
if stringgrid2.Cells[5,i] <> '' then
totalacc:=totalacc+strtofloat(stringgrid2.Cells[5,i]);
if totalacc <> 0 then
edit4.Text:=floattostr(totalacc);
end;
procedure Tfrmwhref.StringGrid2SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
var
arect:trect;
begin
stringgrid2.Options:=stringgrid2.Options-[goediting];
if speedbutton5.Enabled then
begin
if ((acol = 1) or (acol = 2)) then
begin
arect:=stringgrid2.CellRect(acol,arow);
arect.Left:=arect.Left+stringgrid2.Left;
arect.Top:=arect.Top+stringgrid2.Top;
dxbuttonedit1.Left:=arect.Left+1;
dxbuttonedit1.Top:=arect.Top+1;
dxbuttonedit1.Height:=stringgrid2.RowHeights[arow];
dxbuttonedit1.Width:=stringgrid2.ColWidths[acol]+1;
dxbuttonedit1.Visible:=true;
dxbuttonedit1.Text:=stringgrid2.Cells[acol,arow];
dxbuttonedit1.SetFocus;
end;
if ((acol = 3) or (acol = 4)) then
stringgrid2.Options:=stringgrid2.Options+[goediting];
if arow <> stringgrid2.RowCount-1 then
if stringgrid2.Cells[1,stringgrid2.RowCount-1] = '' then
begin
stringgrid2.Rows[stringgrid2.RowCount-1].Clear;
if stringgrid2.RowCount > 2 then
stringgrid2.RowCount:=stringgrid2.RowCount-1;
end;
end;
end;
procedure Tfrmwhref.N1Click(Sender: TObject);
var
arow:integer;
begin
if speedbutton5.Enabled then
begin
arow:=stringgrid2.RowCount-1;
if stringgrid2.Cells[1,arow] <> '' then
stringgrid2.RowCount:=stringgrid2.RowCount+1;
end
else
showmessage('请先点击添加按钮');
end;
procedure Tfrmwhref.N2Click(Sender: TObject);
var
i:integer;
begin
if speedbutton5.Enabled then
begin
if stringgrid2.RowCount > 2 then
begin
for i:=stringgrid2.Row to stringgrid2.RowCount-2 do
stringgrid2.Rows[i]:=stringgrid2.Rows[i+1];
stringgrid2.rows[stringgrid2.RowCount-1].Clear;
stringgrid2.RowCount:=stringgrid2.RowCount-1;
end
else
stringgrid2.Rows[1].Clear;
end
else
showmessage('请先点击添加按钮');
end;
procedure Tfrmwhref.dxButtonEdit1ButtonClick(Sender: TObject;
AbsoluteIndex: Integer);
begin
application.CreateForm(tfrmfilprod,frmfilprod);
frmfilprod.whosel:='whrefund';
frmfilprod.ShowModal;
frmfilprod.Release;
end;
procedure Tfrmwhref.dxButtonEdit1Exit(Sender: TObject);
begin
dxbuttonedit1.Text:='';
dxbuttonedit1.Visible:=false;
end;
procedure Tfrmwhref.SpeedButton9Click(Sender: TObject);
begin
modalresult:=mrcancel;
end;
procedure Tfrmwhref.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if not speedbutton9.Enabled then
begin
canclose:=false;
Application.MessageBox('请保存数据以后再退出','操作提示',MB_ICONWARNING+MB_OK);
end;
end;
procedure Tfrmwhref.SpeedButton7Click(Sender: TObject);
begin
if stringgrid2.Cells[1,1] <> '' then
begin
adoquery1.SQL.Text:='select whrefund1.prid,pluinfo.prname,whrefund1.refnum,'
+'whrefund1.price from whrefund1 inner join pluinfo on whrefund1.prid = '
+'pluinfo.prid where whrefund1.wrefid = '''+edit2.Text+'''';
adoquery2.SQL.Text:='select whrefund.wrefid,whrefund.refdate,whrefund.handleman,'
+'filiale.filname,clients.clientname from (whrefund inner join filiale on '
+'whrefund.filid = filiale.filid ) inner join clients on whrefund.clientid '
+'= clients.clientid where whrefund.wrefid = '''+edit2.Text+'''';
rvproject1.Execute;
rvproject1.Close;
end
else
showmessage('请先查询要打印的数据!');
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?