Ver Mensaje Individual
  #66  
Antiguo 18-08-2013
DOS DOS is offline
Miembro
NULL
 
Registrado: jul 2011
Posts: 173
Reputación: 13
DOS Va por buen camino
Volvi a el codigo que mas se acerco a la solucion
DOBLE CLICK EN EL DBGRID
Código Delphi [-]
// Doble click para la carga de productos y servicios
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;  // nuevo
Table7.Last;    // nuevo
Table7.Insert;  // nuevo
Table7.Edit;
if combobox1.Text = 'Productos' then
  begin
   datasource5.DataSet:= Table4;  // tabla de productos
   Table2.Insert; // inserta un campo
   Table2Cod_prodser.Value:= Table4Cod_prod.Value; // el campo cod_prod de la tabla nueva es igual al de la tabla5
   Table2Codigo.Value:= Table4Codigo.Value;
   Table2Descripcion.Value:= Table4Descripcion.Value;
   Table2Importunidad.Value:= Table4ImpVent.Value;
   Table2Cantidad.Value:= StrToFloat(Edit1.Text);  //cantidad cargada por el usuario
   Table2TotalImp.Value:=Table2Cantidad.Value * Table2Importunidad.Value;   // multiplica la cantidad por el valor unitario
   Table2ID_Factura.Value:= StrToInt(Edit6.Text); // Nº de facturar del usuario
   Table2.Post; // guarda el dato en la tabla nueva.
   end;
  if combobox1.Text = 'Servicios' then
  begin
  datasource3.DataSet:= Table3;  // tabla servicios
   Table2.Insert; // inserta un campo
   Table2Cod_prodser.Value:= Table5Cod_servcio.Value; // el campo cod_servicio de la tabla nueva es igual al de la tabla3
   Table2Codigo.Value:= Table5Codigo.Value;
   Table2Descripcion.Value:= Table5Servicio.Value;
   Table2Cantidad.Value:= StrToFloat(Edit1.Text);  // cantidad cargada por el usuario
   Table2Importunidad.Value:= Table5ImpServ.Value;
   Table2TotalImp.Value:=Table2Cantidad.Value * Table2Importunidad.Value;
   Table2ID_Factura.Value:= StrToInt(Edit6.Text); // Nº de facturar del usuario
   Table2.Post; // guarda el dato en la tabla nueva.
   end;
  calcula;
end;
end;

BOTON NUEVA FACTURA
Código Delphi [-]
procedure TForm14.BitBtn1Click(Sender: TObject);  // nueva factura,
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.
Responder Con Cita