📄 indepot.~pas
字号:
begin
inherited;
if Trim(barcode.Text)<>'' then
Key := #0;
end;
procedure Tf_indepot.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]).Date := Now
else if Components[i]is TStringGrid then
begin
ClearGrid;
end;
Operator.Text := Username;
end;
procedure Tf_indepot.ClearGrid;
var
x,y: Integer;
begin
For x := 1 to Grid.RowCount-1 do
For y := 0 to Grid.ColCount-1 do
Grid.Cells[y,x]:='';
Grid.RowCount := 2;
end;
function Tf_indepot.DetailIsNull: Boolean;
var
i: Integer;
begin
Result := False;
For i := 0 to Panel2.ControlCount-1 do
begin
if Panel2.Controls[i]is TEdit then
begin
if Trim(TEdit(Panel2.Controls[i]).Text)='' then
begin
Result := True;
Break;
end;
end
else if Panel2.Controls[i]is TComboBox then
if Trim(TComboBox(Panel2.Controls[i]).Text) = '' then
begin
Result := True;
Break;
end;
end;
end;
procedure Tf_indepot.ClearDetail;
var
i: Integer;
begin
For i := 0 to Panel2.ControlCount-1 do
if Panel2.Controls[i]is TEdit then
TEdit(Panel2.Controls[i]).Clear
else if Panel2.Controls[i]is TComboBox then
TComboBox(Panel2.Controls[i]).ItemIndex := -1;
Barcode.SetFocus;
end;
procedure Tf_indepot.GridSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
begin
inherited;
x := ARow;
y := ACol;
end;
procedure Tf_indepot.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
Summoney.Text := FloatToStr(StrToFloat(Summoney.Text)-StrToFloat(Grid.Cells[sumprice,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_indepot.SaveClick(Sender: TObject);
var
Connect: TADOConnection;
Query1,Query2: TADOQuery;
row: Integer;
inid: String;
begin
inherited;
Connect := Nil;
Query1 := Nil;
Query2 := Nil;
Try
Connect := TADOConnection.Create(nil);
Connect.LoginPrompt := False;
Connect.ConnectionString := t_data.Connection1.ConnectionString;
Connect.Open;
Query1 := TADOQuery.Create(nil);
Query2 := TADOQuery.Create(nil);
Query1.Connection := Connect;
Query2.Connection := Connect;
if MasterIsNull = False then
begin
if GridIsNull = False then
begin
if ProviderIsValid = True then
begin
Try
Connect.BeginTrans;
With Query1 do
begin
Close;
SQL.Clear;
SQL.Add('Exec add_bookin :provider,:principal,:Operator,:data,:id output');
Parameters.ParamByName('provider').Value := Trim(Provider.Text);
Parameters.ParamByName('principal').Value := Trim(Principal.Text);
Parameters.ParamByName('operator').Value := Trim(Operator.Text);
Parameters.ParamByName('data').Value := Picker.Date;
Parameters.ParamByName('id').Value := 'temp';
ExecSQL;
end;
With Query2 do
begin
Close;
SQL.Clear;
SQL.Add('select * from tb_provideracount where provider = :provider');
Parameters.ParamByName('provider').Value := Trim(Provider.Text);
Open;
end;
if Query2.RecordCount>0 then
begin
With Query2 do
begin
Close;
SQL.Clear;
SQL.Add('update tb_provideracount set money = money + :money where provider = :provider');
Parameters.ParamByName('provider').Value := Trim(Provider.Text);
Parameters.ParamByName('money').Value := StrToFloat(Summoney.Text);
ExecSQL;
end;
end
else
begin
With Query2 do
begin
Close;
SQL.Clear;
SQL.Add('Insert into tb_provideracount values (:provider,:money)');
Parameters.ParamByName('provider').Value := Trim(Provider.Text);
Parameters.ParamByName('money').Value := StrToFloat(Summoney.Text);
ExecSQL;
end;
end;
inid := Trim(Query1.Parameters.ParamByName('id').Value);
For Row := 1 to Grid.RowCount-2 do
begin
With Query2 do
begin
Close;
SQL.Clear;
SQL.Add('insert into tb_bookindetail Values(:id,:barcode,:price,:num,:money,:depot)');
Parameters.ParamByName('id').Value := Trim(inid);
Parameters.ParamByName('barcode').Value := Trim(Grid.Cells[bar,row]);
Parameters.ParamByName('price').Value := StrToFloat(Grid.Cells[unitprice,row]);
Parameters.ParamByName('num').Value := StrToFloat(Grid.Cells[amount,row]);
Parameters.ParamByName('money').Value := StrToFloat(Grid.Cells[sumprice,Row]);
Parameters.ParamByName('depot').Value := Trim(Grid.Cells[depot,row]);
ExecSQL;
end;
With Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from tb_bookdepot where barcode = :bar and depot = :depot');
Parameters.ParamByName('bar').Value := Trim(Grid.Cells[bar,row]);
Parameters.ParamByName('depot').Value := Trim(Grid.Cells[depot,row]);
Open;
end;
if Query1.RecordCount>0 then
begin
With Query2 do
begin
Close;
SQL.Clear;
SQL.Add('update tb_bookdepot set num = num+:sum where barcode = :bar and depot = :depot');
Parameters.ParamByName('sum').Value := StrToFloat(Grid.Cells[amount,row]);
Parameters.ParamByName('bar').Value := Trim(Grid.Cells[bar,row]);
Parameters.ParamByName('depot').Value := Trim(Grid.Cells[depot,row]);
ExecSQL;
end;
end
else
begin
With Query2 do
begin
Close;
SQL.Clear;
SQL.Add('insert into tb_bookdepot Values(:depot,:barcode,:sum)');
Parameters.ParamByName('sum').Value := StrToFloat(Grid.Cells[amount,row]);
Parameters.ParamByName('barcode').Value := Trim(Grid.Cells[bar,row]);
Parameters.ParamByName('depot').Value := Trim(Grid.Cells[depot,row]);
ExecSQL;
end;
end;
end;
Connect.CommitTrans;
Application.MessageBox(Pchar('操作成功,票号为: '+ inid),'提示',64);
Cancel.Click;
Except
Connect.RollbackTrans;
Application.MessageBox('操作失败.','提示',64);
End;
end
else
Application.MessageBox('供应商不存在.','提示',64);
end
else
Application.MessageBox('表格信息不能为空.','提示',64);
end
else
Application.MessageBox('标题信息不能为空.','提示',64);
Finally
Query1.Free;
Query2.Free;
Connect.Free;
End;
end;
function Tf_indepot.MasterIsNull: Boolean;
var
i: Integer;
begin
Result := False;
For i := 0 to Panel1.ControlCount-1 do
if Panel1.Controls[i]is TEdit then
begin
if Trim(TEdit(Panel1.Controls[i]).Text)= '' then
begin
Result := True;
Exit;
end;
end
else if Panel1.Controls[i]is TComboBox then
if Trim(TComboBox(Panel1.Controls[i]).Text) = '' then
begin
Result := True;
Exit;
end;
end;
function Tf_indepot.GridIsNull: Boolean;
var
i,j: Integer;
begin
Result := False;
if Grid.RowCount =2 then
begin
Result := True;
Exit;
end;
For i := 1 to Grid.RowCount-2 do
begin
For j := 0 to Grid.ColCount-1 do
if Trim(Grid.Cells[j,i])= '' then
begin
Result := True;
Break;
end;
end;
end;
function Tf_indepot.ProviderIsValid: Boolean;
begin
Result := True;
With t_data.Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from tb_providerinfo where providername = :name');
Parameters.ParamByName('name').Value := Trim(provider.Text);
Open;
end;
if t_data.Query1.RecordCount<1 then
Result := False;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -