Volvi a el codigo que mas se acerco a la solucion
DOBLE CLICK EN EL DBGRID
Código Delphi
[-]procedure TForm14.DBGrid2DblClick(Sender: TObject);
Begin
if (Edit6.Text) = ''then
begin
Application.MessageBox('Ingrese el Numero de Factura'+ #13 +'Luego cargue los Items'+ #13 +'Finalmente pulse Nueva Factura','¡ATENCION!',Mb_OK + Mb_IconWarning);
end
else
begin
Table2.Filtered := False;
Table2.Close;
Table2.Open;
Table7.Open; Table7.Last; Table7.Insert; Table7.Edit;
if combobox1.Text = 'Productos' then
begin
datasource5.DataSet:= Table4; Table2.Insert; Table2Cod_prodser.Value:= Table4Cod_prod.Value; Table2Codigo.Value:= Table4Codigo.Value;
Table2Descripcion.Value:= Table4Descripcion.Value;
Table2Importunidad.Value:= Table4ImpVent.Value;
Table2Cantidad.Value:= StrToFloat(Edit1.Text); Table2TotalImp.Value:=Table2Cantidad.Value * Table2Importunidad.Value; Table2ID_Factura.Value:= StrToInt(Edit6.Text); Table2.Post; end;
if combobox1.Text = 'Servicios' then
begin
datasource3.DataSet:= Table3; Table2.Insert; Table2Cod_prodser.Value:= Table5Cod_servcio.Value; Table2Codigo.Value:= Table5Codigo.Value;
Table2Descripcion.Value:= Table5Servicio.Value;
Table2Cantidad.Value:= StrToFloat(Edit1.Text); Table2Importunidad.Value:= Table5ImpServ.Value;
Table2TotalImp.Value:=Table2Cantidad.Value * Table2Importunidad.Value;
Table2ID_Factura.Value:= StrToInt(Edit6.Text); Table2.Post; end;
calcula;
end;
end;
BOTON NUEVA FACTURA
Código Delphi
[-]procedure TForm14.BitBtn1Click(Sender: TObject); begin
if Table2.IsEmpty then
Application.MessageBox('Ingrese Nº de Factura'+ #13 +'Cargue los Items a Facturar'+ #13 +'Finalmente pulse Nueva Factura','¡ATENCION!',Mb_OK + Mb_IconWarning);
with Query1 do
begin
Close;
SQL.Clear;
SQL.Add('INSERT INTO detfacturafinal');
SQL.Add('SELECT * FROM detfactura');
ExecSQL;
end;
end;
BOTON GUARDAR
Código Delphi
[-]procedure TForm14.SpeedButton4Click(Sender: TObject);
begin
Table7.Edit;
Table7.Post;
Table7.Refresh;
end;
BOTON LIMPIAR LA TABLA TEMPORAL
Código Delphi
[-]procedure TForm14.SpeedButton3Click(Sender: TObject);
begin
with Query1 do
begin
Close;
SQL.Clear;
SQL.Add('DELETE FROM detfactura');
ExecSQL;
end;
Edit6.Text:='';
Table2.Refresh;
Table7.Refresh;
end;
Esta casi funcionando, puedo cargar la factura, guardarla, limpiar el DBGrid Y si intento cargar una nueva factura ahi salta el error EDBEngineError with message 'key violation'. ...
a mi me parece como que ademas de guardar inserta una linea nueva en blanco, asi que cuando pongo nuevamente, nueva factura salta el error.
Creo que me estoy equivocando con los edit, insert, post, close, etc en las distintas parte del codigo, alguno no esta bien ubicado, a ver si ustedes logran darse cuenta.