📄 cancelbook.pas
字号:
else if (TEdit(Sender).Name = 'Bookname')and(Trim(Bookname.Text)<>'')and(Trim(Barcode.Text)='') then
begin
With t_data.Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select a.bookname,a.barcode,a.bookconcern,a.author,b.sellprice from tb_bookinfo a inner join tb_fixprice b on a.barcode = b.barcode and a.bookname = :name');
Parameters.ParamByName('name').Value := Trim(Bookname.Text);
Open;
end;
if t_data.Query1.RecordCount>0 then
begin
Barcode.Text := Trim(t_data.Query1.FieldByName('barcode').AsString);
Bookname.Text := Trim(t_data.Query1.FieldByName('bookname').AsString);
Price.Text :=Trim(t_data.Query1.FieldByName('sellprice').AsString);
Author.Text := Trim(t_data.Query1.FieldByName('Author').AsString);
end
else
Application.MessageBox('该书籍不存在或没有定价.','提示',64);
end;
FindNext(True);
end
else if (Key = vk_control)and(Grid1.Visible = True) then
Grid1.SetFocus
else if (Key = vk_insert)and(DetailIsNull = False) then
begin
Grid.Cells[c_barcode,Grid.RowCount-1]:= Trim(Barcode.Text);
Grid.Cells[c_bookname,Grid.RowCount-1]:= Trim(Bookname.Text);
Grid.Cells[c_price,Grid.RowCount-1]:= Trim(Price.Text);
Grid.Cells[c_author,Grid.RowCount-1]:= Trim(Author.Text);
Grid.Cells[c_sum,Grid.RowCount-1] := Trim(Sum.Text);
Grid.Cells[c_money,Grid.RowCount-1]:= Trim(Money.Text);
Grid.RowCount := Grid.RowCount+1;
if Trim(Sumprice.Text)= '' then
Sumprice.Text := Money.Text
else
Sumprice.Text := FloatToStr(StrToFloat(Sumprice.Text)+ StrToFloat(Money.Text));
ClearDetail;
Barcode.SetFocus;
end
else if Key =vk_escape then
begin
ClearDetail;
end;
end;
procedure Tf_cancelbook.Grid1DblClick(Sender: TObject);
begin
inherited;
Price.Text :=Trim(Source1.DataSet.FieldByName('sellprice').AsString);
Barcode.Text := Trim(Source1.DataSet.FieldByName('barcode').AsString);
Bookname.Text := Trim(Source1.DataSet.FieldByName('bookname').AsString);
Author.Text := Trim(Source1.DataSet.FieldByName('author').AsString);
Grid1.Visible := False;
Sum.SetFocus;
end;
procedure Tf_cancelbook.Grid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
inherited;
if Key = vk_Return then
Grid1.OnDblClick(Sender);
end;
procedure Tf_cancelbook.priceChange(Sender: TObject);
begin
inherited;
if (Trim(Price.Text)<>'')and(Trim(sum.Text)<>'') then
Money.Text := FloatToStr(StrToFloat(Price.Text)*StrToFloat(sum.Text))
else
Money.Clear;
end;
procedure Tf_cancelbook.RebateChange(Sender: TObject);
begin
inherited;
if (Trim(Rebate.Text)<>'')and(Trim(sumprice.Text)<>'')and(StrToFloat(Rebate.Text)<=1) then
begin
Paymoney.Text := FloatToStr(StrToFloat(Sumprice.Text)* StrToFloat(Rebate.Text));
end
else
Paymoney.Clear;
end;
procedure Tf_cancelbook.RebateExit(Sender: TObject);
begin
inherited;
if StrToFloat(Rebate.Text)>1 then
begin
Application.MessageBox('折扣不能大于1.','提示',64);
Rebate.Text := '1.0';
end;
end;
procedure Tf_cancelbook.CancelClick(Sender: TObject);
var
i: Integer;
begin
inherited;
For i := 0 to ComponentCount-1 do
if Components[i]is TEdit then
TEdit(Components[i]).Clear
else if (Components[i]is TComboBox) then
TComboBox(Components[i]).ItemIndex := -1
else if (Components[i]is TDateTimePicker) then
TDateTimePicker(Components[i]).DateTime := Now
else if (Components[i]is TStringGrid) then
ClearGrid;
Operator.Text := Username;
Rebate.Text := '1.0';
end;
procedure Tf_cancelbook.PickerKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
inherited;
if Key = vk_Return then
Barcode.SetFocus;
end;
procedure Tf_cancelbook.BooknameChange(Sender: TObject);
begin
inherited;
if (Trim(Bookname.Text)<>'')and(Bookname.Focused) then
begin
With t_data.Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select a.bookname,a.barcode,a.bookconcern,author,b.sellprice from tb_bookinfo a inner join tb_fixprice b on a.barcode = b.barcode and a.bookname like :name');
Parameters.ParamByName('name').Size := 100;
Parameters.ParamByName('name').Value := Trim(Bookname.Text)+'%';
Open;
end;
if t_data.Query1.RecordCount>0 then
begin
Source1.DataSet := t_data.Query1;
Grid1.Visible := True;
end
else
begin
t_data.Query1.Close;
Grid1.Visible := False;
end;
end;
end;
procedure Tf_cancelbook.GridKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
i,j: Integer;
begin
inherited;
if Key = vk_delete then
begin
if x <> Grid.RowCount-1 then //因为最后一行始终为空,不能够删除
begin
if Application.MessageBox('确实要删除当前行数据吗?','提示',mb_yesno)= ID_Yes then
begin
Sumprice.Text := FloatToStr(StrToFloat(Sumprice.Text)-StrToFloat(Grid.Cells[c_money,x]));
begin
For i := x to Grid.RowCount-2 do
begin
For j := 0 to Grid.ColCount-1 do
Grid.Cells[j,i]:= Grid.Cells[j,i+1];
end;
Grid.RowCount := Grid.RowCount-1;
end;
end;
end;
end
end;
procedure Tf_cancelbook.SaveClick(Sender: TObject);
var
Connect: TADOConnection;
Query1: TADOQuery;
row: Integer;
inid: String;
begin
inherited;
Connect:= Nil;
Query1 := Nil;
if MasterIsValid then
begin
if AccountIsNull = False then
begin
Try
Connect := TADOConnection.Create(nil);
Connect.LoginPrompt := False;
Connect.ConnectionString := t_data.Connection1.ConnectionString;
Connect.Open;
Query1 := TADOQuery.Create(nil);
Query1.Connection := Connect;
Try
Connect.BeginTrans;
With Query1 do
begin
Close;
SQL.Clear;
SQL.Add('Exec Add_CancelID :counter,:operator,:rebate,:cancelmoney,:date,:cancelid output');
Parameters.ParamByName('counter').Value := Trim(Counter.Text);
Parameters.ParamByName('operator').Value := Trim(Operator.Text);
Parameters.ParamByName('rebate').Value := StrToFloat(Rebate.Text);
Parameters.ParamByName('cancelmoney').Value := StrToFloat(Paymoney.Text);
Parameters.ParamByName('date').Value := Picker.DateTime;
Parameters.ParamByName('cancelid').Value := 'temp';
ExecSQL;
end;
inid := Trim(Query1.Parameters.ParamByName('cancelid').Value);
For Row := 1 to Grid.RowCount-2 do
begin
With Query1 do
begin
Close;
SQL.Clear;
SQL.Add('insert into tb_canceldetail values (:cancelid,:barcode,:unitprice,:num,:money)');
Parameters.ParamByName('cancelid').Value := Trim(inid);
Parameters.ParamByName('barcode').Value := Trim(Grid.Cells[c_barcode,Row]);
Parameters.ParamByName('unitprice').Value := StrToFloat(Grid.Cells[c_price,Row]);
Parameters.ParamByName('num').Value := StrToFloat(Grid.Cells[c_sum,Row]);
Parameters.ParamByName('money').Value := StrToFloat(Grid.Cells[c_money,Row]);
ExecSQL;
end;
With Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from tb_bookcounter where barcode = :barcode and counter = :counter');
Parameters.ParamByName('barcode').Value := Trim(Grid.Cells[c_barcode,Row]);
Parameters.ParamByName('counter').Value := Trim(Counter.Text);
Open;
end;
if Query1.RecordCount>0 then
begin
With Query1 do
begin
Close;
SQL.Clear;
SQL.Add('update tb_bookcounter set num = num+:sum where barcode = :barcode and counter = :counter');
Parameters.ParamByName('sum').Value := StrToFloat(Grid.Cells[c_sum,Row]);
Parameters.ParamByName('barcode').Value := Trim(Grid.Cells[c_barcode,Row]);
Parameters.ParamByName('counter').Value := Trim(Counter.Text);
ExecSQL;
end;
end
else
begin
With Query1 do
begin
Close;
SQL.Clear;
SQL.Add('Insert into tb_bookcounter Values(:counter,:barcode,:sum)');
Parameters.ParamByName('counter').Value := Trim(Counter.Text);
Parameters.ParamByName('barcode').Value := Trim(Grid.Cells[c_barcode,Row]);
Parameters.ParamByName('sum').Value := StrToFloat(Grid.Cells[c_sum,Row]);
ExecSQL;
end;
end;
end;
Connect.CommitTrans;
Application.MessageBox(Pchar('操作成功,票号为: '+ inid),'提示',64);
Cancel.Click;
Except
Connect.RollbackTrans;
Application.MessageBox('操作失败.','');
End;
Finally
Query1.Free;
Connect.Free;
End;
end
else
Application.MessageBox('账目信息不能为空.','提示',64);
end
else
Application.MessageBox('标题信息有误,请检查标题信息是否为空或柜台名称是否正确.','提示',64);
end;
procedure Tf_cancelbook.GridSelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
inherited;
x := ARow;
y := ACol;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -