📄 unitorderbill_edit.pas
字号:
{ DM.ADOQueryOrderBill.Edit;
DM.ADOQueryOrderBill.FieldByName('TotalPrice1').AsCurrency:=DM.ADOQueryOrderBill.FieldByName('TotalPrice1').AsCurrency-DM.ADOTableBillDetail.FieldByName('TotalPrice').AsCurrency;
DM.ADOQueryOrderBill.FieldByName('TotalWeight').AsFloat:=DM.ADOQueryOrderBill.FieldByName('TotalWeight').AsFloat-DM.ADOTableBillDetail.FieldByName('TotalWeight').AsFloat;
DM.ADOQueryOrderBill.Post;}
//===============更新总重量===========================
TotalPrice:=0;
TotalWeight:=0;
DM.ADOTableBillDetail.First;
For i:=1 to DM.ADOTableBillDetail.RecordCount do
Begin
TotalPrice:=TotalPrice+DM.ADOTableBillDetail.FieldByName('TotalPrice').AsCurrency;
TotalWeight:=TotalWeight+DM.ADOTableBillDetail.FieldByName('TotalWeight').AsFloat;
DM.ADOTableBillDetail.Next;
Next;
End;
DM.ADOQueryOrderBill.Edit;
DM.ADOQueryOrderBill.FieldByName('TotalPrice1').AsCurrency:=TotalPrice;
DM.ADOQueryOrderBill.FieldByName('TotalWeight').AsFloat:=TotalWeight;
DM.ADOQueryOrderBill.Post;
end;
end;
procedure TFrmOrderBill_Edit.FormShow(Sender: TObject);
begin
//cxGridDBTableView1.Columns[4].Visible:=DM.ADOQueryUserName.FieldByName('D23').AsBoolean;
//cxGridDBTableView1.Columns[5].Visible:=DM.ADOQueryUserName.FieldByName('D23').AsBoolean;
RzDBGrid1.Columns[4].Visible:=DM.ADOQueryUserName.FieldByName('D23').AsBoolean;
RzDBGrid1.Columns[5].Visible:=DM.ADOQueryUserName.FieldByName('D23').AsBoolean;
end;
procedure TFrmOrderBill_Edit.wwDBLookupCombo2Change(Sender: TObject);
var
s,OrderStr,Sqlstr: String;
ws: WideString;
begin
s := wwDBLookupCombo2.Text;
ws := s;
if (Length(s)=Length(ws)) THen //判断是否有汉字
Begin
if wwDBLookupCombo2.Text<>'' then
Begin
DM.ADOTableClientName.Filter:=' clientCode like '''+wwDBLookupCombo2.Text+'%''' ;
DM.ADOTableClientName.Filtered:=True;
End
Else
Begin
DM.ADOTableClientName.Filtered:=False;
End;
End;
end;
procedure TFrmOrderBill_Edit.wwDBLookupCombo2KeyPress(Sender: TObject;
var Key: Char);
begin
if Key=#13 then
begin
Key:=#0;
Perform(WM_NEXTDLGCTL,0,0);
end;
end;
procedure TFrmOrderBill_Edit.wwDBDateTimePicker1KeyPress(Sender: TObject;
var Key: Char);
begin
if Key=#13 then
begin
Key:=#0;
Perform(WM_NEXTDLGCTL,0,0);
end;
end;
procedure TFrmOrderBill_Edit.wwDBLookupCombo1KeyPress(Sender: TObject;
var Key: Char);
begin
if Key=#13 then
begin
Key:=#0;
Perform(WM_NEXTDLGCTL,0,0);
end;
end;
procedure TFrmOrderBill_Edit.DBGrid1KeyPress(Sender: TObject;
var Key: Char);
Var ColNum:Integer;
begin
{if Key=#13 then
if not(ActiveControl is TDBGrid) then
begin
Key:=#0;
Perform(WM_NEXTDLGCTL,0,0);
end else
if (ActiveControl is TDBGrid) then
with TDBGrid(ActiveControl) do
Begin
if wwDBLookupCombo2.Text='' then
Begin
Application.MessageBox('客户名称不能为空,请选择后进行录入!','提醒',MB_IconInformation);
wwDBLookupCombo2.SetFocus;
Exit;
End;
IF DM.ADOQueryOrderBill.State in [dsInsert,dsEdit] then DM.ADOQueryOrderBill.Post;
DM.ADOTableBillDetail.Edit;
DM.ADOTableBillDetail.FieldByName('OrderBill_ID').AsString:=DM.ADOQueryOrderBill.FieldValues['id']; //与订单关联
if SelectedIndex =0 then
Begin
ShowMessage(DBGrid1.Columns[0].Field.asstring);
DM.ADOQueryClientPrice.Filter:=' ClientName='''+wwDBLookupCombo2.Text+''' and ProductId='''+DBGrid1.Columns[0].Field.asstring+'''';
DM.ADOQueryClientPrice.Filtered:=True;
// if DM.ADOQueryClientPrice.RecordCount<1 then exit;
DM.ADOTableBillDetail.FieldByName('ProductName').asstring:=DM.ADOQueryClientPrice.FieldValues['ProductName'];
DM.ADOTableBillDetail.FieldByName('Price').AsCurrency:=DM.ADOQueryClientPrice.FieldValues['ClientPrice'];
End;
if DM.ADOQueryUserName.FieldByName('D23').AsBoolean then ColNum:=5 else ColNum:=3;
if SelectedIndex < ColNum then
selectedindex:=selectedindex+1
else
begin
(Sender as TDBGrid).DataSource.DataSet.Next;
selectedindex:=0; //应增加此句,否则焦点无法到第一个字段
if (Sender as TDBGrid).DataSource.DataSet.Eof then
Begin
//(Sender as TDBGrid).DataSource.DataSet.Post;
(Sender as TDBGrid).DataSource.DataSet.Append;
End;
selectedindex:=0;
end;
End; }
end;
procedure TFrmOrderBill_Edit.RzDBGrid1KeyPress(Sender: TObject;
var Key: Char);
Var ColNum:Integer;
i:Integer;
TotalPrice:Currency;
TotalWeight:double;
begin
if Key=#13 then
if not(ActiveControl is TRzDBGrid) then
begin
Key:=#0;
Perform(WM_NEXTDLGCTL,0,0);
end else
if (ActiveControl is TRzDBGrid) then
with TRzDBGrid(ActiveControl) do
Begin
if wwDBLookupCombo2.Text='' then
Begin
Application.MessageBox('客户名称不能为空,请选择后进行录入!','提醒',MB_IconInformation);
wwDBLookupCombo2.SetFocus;
Exit;
End;
IF DM.ADOQueryOrderBill.State in [dsInsert,dsEdit] then DM.ADOQueryOrderBill.Post;
DM.ADOTableBillDetail.Edit;
DM.ADOTableBillDetail.FieldByName('OrderBill_ID').AsString:=DM.ADOQueryOrderBill.FieldValues['id']; //与订单关联
if SelectedIndex =0 then
Begin
// ShowMessage(RzDBGrid1.Columns[0].Field.asstring);
DM.ADOQueryClientPrice.Filter:=' ClientName='''+wwDBLookupCombo2.Text+''' and ProductId='''+RzDBGrid1.Columns[0].Field.asstring+'''';
DM.ADOQueryClientPrice.Filtered:=True;
if DM.ADOQueryClientPrice.RecordCount<1 then
Begin
Application.MessageBox('该客户找不到此产品编号,请查正或在客户价格管理中设置!','提醒',MB_IconInformation);
exit;
End;
// ShowMessage('111');
DM.ADOTableBillDetail.FieldByName('ProductName').asstring:=DM.ADOQueryClientPrice.FieldValues['ProductName'];
DM.ADOTableBillDetail.FieldByName('Price').AsCurrency:=DM.ADOQueryClientPrice.FieldByName('ClientPrice').AsCurrency;
End;
if DM.ADOQueryUserName.FieldByName('D23').AsBoolean then ColNum:=5 else ColNum:=3;
if SelectedIndex < ColNum then
selectedindex:=selectedindex+1
else
begin
(Sender as TRzDBGrid).DataSource.DataSet.Next;
selectedindex:=0; //应增加此句,否则焦点无法到第一个字段
if (Sender as TRzDBGrid).DataSource.DataSet.Eof then
Begin
//(Sender as TRzDBGrid).DataSource.DataSet.Post;
//===============更新总重量===========================
TotalPrice:=0;
TotalWeight:=0;
DM.ADOTableBillDetail.First;
For i:=1 to DM.ADOTableBillDetail.RecordCount do
Begin
TotalPrice:=TotalPrice+DM.ADOTableBillDetail.FieldByName('TotalPrice').AsCurrency;
TotalWeight:=TotalWeight+DM.ADOTableBillDetail.FieldByName('TotalWeight').AsFloat;
DM.ADOTableBillDetail.Next;
End;
DM.ADOQueryOrderBill.Edit;
DM.ADOQueryOrderBill.FieldByName('TotalPrice1').AsCurrency:=TotalPrice;
DM.ADOQueryOrderBill.FieldByName('TotalWeight').AsFloat:=TotalWeight;
DM.ADOQueryOrderBill.Post;
//===============更新完=========================
(Sender as TRzDBGrid).DataSource.DataSet.Append;
End;
selectedindex:=0;
end;
End;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -