为什么我在删除数据时只能删除一条记录,啊??? ( 积分: 50 )

  • 主题发起人 主题发起人 han--bing
  • 开始时间 开始时间
H

han--bing

Unregistered / Unconfirmed
GUEST, unregistred user!
(销售明细表)有时侯能全部删除,有时候只能删除一条记录!有是添加数据时会自动跑出来上次删除的数据,或者有时添加一条数据时,会自动添加一条同样的数据!!好奇怪???

有两个表:Productsell (DM1.ADODataSet6) 产品销售主表
SellDetail (DM1.ADODataSet7) 销售明细表

procedure TEditSellForm.RzBitBtn2Click(Sender: TObject); //退出
begin
if Messagebox(handle,'您确定要放弃对销售出库资料的修改吗?','询问',MB_YESNO+MB_ICONQUESTION)=IDYES then
with ADOQuery1 do try
Close;
SQL.Clear;
SQL.Add('delete from SellDetail where OrderFormID=:AM and ProductName=:PM');
Parameters.ParamByName('AM').Value:=EditSellForm.RzDBLabel1.Caption;
Parameters.ParamByName('PM').Value:=DM1.ADODataSet5.FieldByname('ProductName').AsString;
ExecSQL;
except
end;
close;
end;

procedure TEditSellForm.FormClose(Sender: TObject;
var Action: TCloseAction); //关闭
begin
if IsInsert and(DM1.ADODataSet6.State in[dsEdit]) then DM1.ADODataSet6.Delete;
DM1.ADODataSet7.Cancel;
DM1.ADODataSet6.Cancel;
end;

procedure TEditSellForm.RzDBGrid1CellClick(Column: TColumn); //修改数量计算金额
begin
DM1.ADODataSet7.Edit;
DM1.ADODataSet7.FieldByName('Money').AsFloat:=DM1.ADODataSet7.FieldByName('Number').AsFloat*DM1.ADODataSet7.FieldByName('UnitPrice').AsFloat;
DM1.ADODataSet7.Post;
end;

procedure TProductListForm.RzBitBtn1Click(Sender: TObject); //选择产品后返回
var y: String;
begin
DM1.ADOTable2.Close;
DM1.ADOTable2.Open;
DM1.ADOTable2.First;
DM1.ADOTable2.Last;
if DM1.ADOTable2.RecordCount>0
then
y:=formatfloat('0000',DM1.ADOTable2.FieldByName('NUM').AsInteger+1)
else y:=formatfloat('0000',1);
//检查本次订单中是否已经包含这一产品
With DM1 do try
ADODataSet7.Append;
if TestSellList then begin
Messagebox(handle,'本次订单中已经包含这一产品,请选择其他产品!','提示',MB_OK+MB_ICONWARNING);
ADODataSet7.Cancel;
Exit;
end ELSE begin
DM1.ADODataSet7.FieldByName('NUM').AsString:=y;
DM1.ADODataSet7.FieldByName('ID').AsString:=DM1.ADODataSet5.FieldByName('ID').AsString;
DM1.ADODataSet7.FieldByName('ProductName').AsString:=DM1.ADODataSet5.FieldByName('ProductName').AsString;
DM1.ADODataSet7.FieldByName('Spec').AsString:=DM1.ADODataSet5.FieldByName('Spec').AsString;
DM1.ADODataSet7.FieldByName('Unit').AsString:=DM1.ADODataSet5.FieldByName('Unit').AsString;
DM1.ADODataSet7.FieldByName('UnitPrice').AsFloat:=DM1.ADODataSet5.FieldByName('Price').AsFloat;
DM1.ADODataSet7.FieldByName('Number').AsInteger:=0;
DM1.ADODataSet7.FieldByName('money').AsFloat:=0;
DM1.ADODataSet7.FieldByName('shuie').AsFloat:=0;
DM1.ADODataSet7.FieldByName('Agio').AsFloat:=0.17;
DM1.ADODataSet7.FieldByName('ClientID').AsString:=editsellform.Rzdbedit2.Text;
DM1.ADODataSet7.FieldByName('Selldate').AsDateTime:=editsellform.cxDBDateEdit1.Date;
ProductListForm.Close;
DM1.ADODataSet7.Refresh;
end;
except;
end;
end;
 
(销售明细表)有时侯能全部删除,有时候只能删除一条记录!有是添加数据时会自动跑出来上次删除的数据,或者有时添加一条数据时,会自动添加一条同样的数据!!好奇怪???

有两个表:Productsell (DM1.ADODataSet6) 产品销售主表
SellDetail (DM1.ADODataSet7) 销售明细表

procedure TEditSellForm.RzBitBtn2Click(Sender: TObject); //退出
begin
if Messagebox(handle,'您确定要放弃对销售出库资料的修改吗?','询问',MB_YESNO+MB_ICONQUESTION)=IDYES then
with ADOQuery1 do try
Close;
SQL.Clear;
SQL.Add('delete from SellDetail where OrderFormID=:AM and ProductName=:PM');
Parameters.ParamByName('AM').Value:=EditSellForm.RzDBLabel1.Caption;
Parameters.ParamByName('PM').Value:=DM1.ADODataSet5.FieldByname('ProductName').AsString;
ExecSQL;
except
end;
close;
end;

procedure TEditSellForm.FormClose(Sender: TObject;
var Action: TCloseAction); //关闭
begin
if IsInsert and(DM1.ADODataSet6.State in[dsEdit]) then DM1.ADODataSet6.Delete;
DM1.ADODataSet7.Cancel;
DM1.ADODataSet6.Cancel;
end;

procedure TEditSellForm.RzDBGrid1CellClick(Column: TColumn); //修改数量计算金额
begin
DM1.ADODataSet7.Edit;
DM1.ADODataSet7.FieldByName('Money').AsFloat:=DM1.ADODataSet7.FieldByName('Number').AsFloat*DM1.ADODataSet7.FieldByName('UnitPrice').AsFloat;
DM1.ADODataSet7.Post;
end;

procedure TProductListForm.RzBitBtn1Click(Sender: TObject); //选择产品后返回
var y: String;
begin
DM1.ADOTable2.Close;
DM1.ADOTable2.Open;
DM1.ADOTable2.First;
DM1.ADOTable2.Last;
if DM1.ADOTable2.RecordCount>0
then
y:=formatfloat('0000',DM1.ADOTable2.FieldByName('NUM').AsInteger+1)
else y:=formatfloat('0000',1);
//检查本次订单中是否已经包含这一产品
With DM1 do try
ADODataSet7.Append;
if TestSellList then begin
Messagebox(handle,'本次订单中已经包含这一产品,请选择其他产品!','提示',MB_OK+MB_ICONWARNING);
ADODataSet7.Cancel;
Exit;
end ELSE begin
DM1.ADODataSet7.FieldByName('NUM').AsString:=y;
DM1.ADODataSet7.FieldByName('ID').AsString:=DM1.ADODataSet5.FieldByName('ID').AsString;
DM1.ADODataSet7.FieldByName('ProductName').AsString:=DM1.ADODataSet5.FieldByName('ProductName').AsString;
DM1.ADODataSet7.FieldByName('Spec').AsString:=DM1.ADODataSet5.FieldByName('Spec').AsString;
DM1.ADODataSet7.FieldByName('Unit').AsString:=DM1.ADODataSet5.FieldByName('Unit').AsString;
DM1.ADODataSet7.FieldByName('UnitPrice').AsFloat:=DM1.ADODataSet5.FieldByName('Price').AsFloat;
DM1.ADODataSet7.FieldByName('Number').AsInteger:=0;
DM1.ADODataSet7.FieldByName('money').AsFloat:=0;
DM1.ADODataSet7.FieldByName('shuie').AsFloat:=0;
DM1.ADODataSet7.FieldByName('Agio').AsFloat:=0.17;
DM1.ADODataSet7.FieldByName('ClientID').AsString:=editsellform.Rzdbedit2.Text;
DM1.ADODataSet7.FieldByName('Selldate').AsDateTime:=editsellform.cxDBDateEdit1.Date;
ProductListForm.Close;
DM1.ADODataSet7.Refresh;
end;
except;
end;
end;
 
后退
顶部