Bueno despues de tanto luchar con este tema.. lo he logrado de una manera que aún no me convence pero que da resultados buenos, pero tambien tiene muuuuuchas contras, sin mas aquí les dejo mi código por si alguien lo quisiera usar, aunque estoy seguro que solo serviría para confundir aún mas
Bueno comenzemos.. como ya tengo las 2 tablas PRODUCTOS y la tabla TARIFAS en los anteriores post puse la estructura, así que no la repetiré
Asi que este es el código con el cual AGREGO tooooodos los campos que tengo en diferentes edits y DataBaseComboBoxsLoock y un meno.
AGREGAR PRODUCTOS
Tengo estas variables definidas
Código Delphi
[-]
var
FrmAgregarProductos: TFrmAgregarProductos;
Editando : Boolean;
idTarifa, prec1Old, prec2Old, prec3Old, prec4Old, prec5Old, prec6Old : Integer;
codBarOld, codProOld : String;
Y el código del botón agregar
si, ya se que esta largo y feo
Código Delphi
[-]procedure TFrmAgregarProductos.SBAgregarClick(Sender: TObject);
var
idProducto : Integer;
begin
if (ECodProducto.Text <> '') then
begin
if (ECodigoBarra.Text <> '') then
begin
if (MDescripcion.Text <> '') then
begin
if (DBLCBCategoria.Text <> '') then
begin
if (DBLCBSubCategoria.Text <> '') then
begin
if (ECantidad.Text <> '') then
begin
if (DBLCBUnidadPrecio.Text <> '') AND (DBLCBUnidad.Text <> '') then
begin
with DM.ZQProductos do
begin
Close;
SQL.Clear;
SQL.Add('INSERT INTO productos (Descripcion, Categoria, SubCategoria, Unidad, Cantidad, Proveedor, ');
SQL.Add('UnidadPrecio, PrecioCompraBs, PrecioCompraSus, Costo, FechaActualizacion)');
SQL.Add('VALUES (es, :Cat, :SubCat, :Uni, :Cant, :Prov, :UniPre, :PCB, :PCS, :Cos, :FechAct)');
ParamByName('Des').AsString := MDescripcion.Text;
ParamByName('Cat').AsString := DBLCBCategoria.Text;
ParamByName('SubCat').AsString := DBLCBSubCategoria.Text;
ParamByName('Uni').AsString := DBLCBUnidad.Text;
ParamByName('Cant').AsString := ECantidad.Text;
ParamByName('Prov').AsString := DBLCBProveedor.Text;
ParamByName('UniPre').AsString := DBLCBUnidadPrecio.Text;
ParamByName('PCB').AsString := EPrecioCompraBs.Text;
ParamByName('PCS').AsString := EPrecioCompraSus.Text;
ParamByName('Cos').AsString := ECosto.Text;
ParamByName('FechAct').AsDateTime := DateTimePicker1.Date;
ExecSQL;
end;
with DM.ZQProductos do
begin
Close;
SQL.Clear;
SQL.Add('SELECT max(id_producto) as xxx FROM productos');
Open;
end;
idProducto := DM.ZQProductos.fieldByName('xxx').AsInteger;
with DM.ZQProductos do
begin
Close;
SQL.Clear;
SQL.Add('INSERT INTO tarifas (Id_producto, CodigoBarra , CodProducto , ListaPrecio , Precio)');
SQL.Add('VALUES (:IDP, :CB, :CP, :LP1, rec1), ');
SQL.Add('(:IDP, :CB, :CP, :LP2, rec2), ');
SQL.Add('(:IDP, :CB, :CP, :LP3, rec3), ');
SQL.Add('(:IDP, :CB, :CP, :LP4, rec4), ');
SQL.Add('(:IDP, :CB, :CP, :LP5, rec5), ');
SQL.Add('(:IDP, :CB, :CP, :LP6, rec6)');
ParamByName('IDP').AsInteger := idProducto;
ParamByName('CB').AsString := ECodigoBarra.Text;
ParamByName('CP').AsString := ECodProducto.Text;
ParamByName('LP1').AsString := 'precio1';
ParamByName('LP2').AsString := 'precio2';
ParamByName('LP3').AsString := 'precio3';
ParamByName('LP4').AsString := 'precio4';
ParamByName('LP5').AsString := 'precio5';
ParamByName('LP6').AsString := 'precio6';
ParamByName('prec1').AsInteger := StrToInt(EPrecio1.Text);
ParamByName('prec2').AsInteger := StrToInt(EPrecio2.Text);
ParamByName('prec3').AsInteger := StrToInt(EPrecio3.Text);
ParamByName('prec4').AsInteger := StrToInt(EPrecio4.Text);
ParamByName('prec5').AsInteger := StrToInt(EPrecio5.Text);
ParamByName('prec6').AsInteger := StrToInt(EPrecio6.Text);
ExecSQL;
end;
ModoEditar(False);
SBAgregar.Enabled := False;
SBCancelar.Enabled := False;
SBNuevo.Enabled := True;
SBEditar.Enabled := True;
SBEliminar.Enabled := True;
end
else
begin
ShowMessage('Los campos Unidad no pueden estar vacíos');
end;
end
else
begin
ShowMessage('El campo Cantidad no puede estar vacío');
end;
end
else
begin
ShowMessage('El campo proveedor no puede estar vacío');
end;
end
else
begin
ShowMessage('El campo Categoría no puede estar vacío');
end;
end
else
begin
ShowMessage('El campo Descripción no puede estar vacío');
end;
end
else
begin
ShowMessage('El campo Código Barra no puede estar vacío');
end;
end
else
begin
ShowMessage('El campo Código no puede estar vacío');
end;
end;
pfff Bueno ahora toca el código de edición, para lo cual realizo una búsqueda por CodigoBarra y llenos los edits, DataBaseComboBoxLook y el meno
BUSCAR Y LLENAR LOS COMPONTES
Todo esto en el evento OnClik del boton búsqueda
Código Delphi
[-]procedure TFrmAgregarProductos.SBBuscarClick(Sender: TObject);
begin
if (EPalabra.Text <> '') then
begin
with DM.ZQBusqProducto do
begin
Close;
SQL.Clear;
SQL.Add('SELECT * FROM tarifas WHERE CodigoBarra = :CB AND ListaPrecio = :LP1');
ParamByName('CB').AsString := EPalabra.Text;
ParamByName('LP1').AsString := 'Precio1';
Open;
end;
EPrecio1.Text := IntToStr(DM.ZQBusqProducto.FieldByName('precio').AsInteger);
idTarifa := DM.ZQBusqProducto.FieldByName('id_producto').AsInteger;
codBarOld := DM.ZQBusqProducto.FieldByName('CodigoBarra').AsString;
codProOld := DM.ZQBusqProducto.FieldByName('CodProducto').AsString;
prec1Old := DM.ZQBusqProducto.FieldByName('precio').AsInteger;
ECodProducto.Text := DM.ZQBusqProducto.FieldByName('CodProducto').AsString;
ECodigoBarra.Text := DM.ZQBusqProducto.FieldByName('CodigoBarra').AsString;
with DM.ZQBusqProducto do
begin
Close;
SQl.Clear;
SQL.Add('SELECT * FROM tarifas WHERE CodigoBarra = :CB AND ListaPrecio = :LP2');
ParambyName('CB').AsString := EPalabra.Text;
ParamByName('LP2').AsString := 'precio2';
Open;
end;
EPrecio2.Text := IntToStr(DM.ZQBusqProducto.FieldByName('precio').AsInteger);
prec2Old := DM.ZQBusqProducto.FieldByName('precio').AsInteger;
with DM.ZQBusqProducto do
begin
Close;
SQl.Clear;
SQL.Add('SELECT * FROM tarifas WHERE CodigoBarra = :CB AND ListaPrecio = :LP3');
ParambyName('CB').AsString := EPalabra.Text;
ParamByName('LP3').AsString := 'precio3';
Open;
end;
EPrecio3.Text := IntToStr(DM.ZQBusqProducto.FieldByName('precio').AsInteger);
prec3Old := DM.ZQBusqProducto.FieldByName('precio').AsInteger;
with DM.ZQBusqProducto do
begin
Close;
SQl.Clear;
SQL.Add('SELECT * FROM tarifas WHERE CodigoBarra = :CB AND ListaPrecio = :LP4');
ParambyName('CB').AsString := EPalabra.Text;
ParamByName('LP4').AsString := 'precio4';
Open;
end;
EPrecio4.Text := IntToStr(DM.ZQBusqProducto.FieldByName('precio').AsInteger);
prec4Old := DM.ZQBusqProducto.FieldByName('precio').AsInteger;
with DM.ZQBusqProducto do
begin
Close;
SQl.Clear;
SQL.Add('SELECT * FROM tarifas WHERE CodigoBarra = :CB AND ListaPrecio = :LP5');
ParambyName('CB').AsString := EPalabra.Text;
ParamByName('LP5').AsString := 'precio5';
Open;
end;
EPrecio5.Text := IntToStr(DM.ZQBusqProducto.FieldByName('precio').AsInteger);
prec5Old := DM.ZQBusqProducto.FieldByName('precio').AsInteger;
with DM.ZQBusqProducto do
begin
Close;
SQl.Clear;
SQL.Add('SELECT * FROM tarifas WHERE CodigoBarra = :CB AND ListaPrecio = :LP6');
ParambyName('CB').AsString := EPalabra.Text;
ParamByName('LP6').AsString := 'precio6';
Open;
end;
EPrecio6.Text := IntToStr(DM.ZQBusqProducto.FieldByName('precio').AsInteger);
prec6Old := DM.ZQBusqProducto.FieldByName('precio').AsInteger;
with DM.ZQBusqProducto do
begin
Close;
SQL.Clear;
SQL.Add('SELECT * FROM productos WHERE id_producto = :IDT');
ParamByName('IDT').AsInteger := idTarifa;
Open;
end;
MDescripcion.Text := DM.ZQBusqProducto.FieldByName('descripcion').AsString;
DBLCBCategoria.KeyValue := DM.ZQBusqProducto.FieldByName('Categoria').AsString;
DBLCBSubCategoria.KeyValue := DM.ZQBusqProducto.FieldByName('SubCategoria').AsString;
DBLCBProveedor.KeyValue := DM.ZQBusqProducto.FieldByName('Proveedor').AsString;
DBLCBUnidad.KeyValue := DM.ZQBusqProducto.FieldByName('Unidad').AsString;
DBLCBUnidadPrecio.KeyValue := DM.ZQBusqProducto.FieldByName('UnidadPrecio').AsString;
ECantidad.Text := DM.ZQBusqProducto.FieldByName('Cantidad').AsString;
ECosto.Text := DM.ZQBusqProducto.FieldByName('Costo').AsString;
EPrecioCompraBs.Text := DM.ZQBusqProducto.FieldByName('PrecioCompraBs').AsString;
EPrecioCompraSus.Text := DM.ZQBusqProducto.FieldByName('PrecioCompraSus').AsString;
DateTimePicker1.Date := DM.ZQBusqProducto.FieldByName('FechaActualizacion').AsDateTime;
modoEditar(True);
SBGuardar.Enabled := True;
SBCancelar.Enabled := True;
SBNuevo.Enabled := False;
SBAgregar.Enabled := False;
SBEditar.Enabled := False;
SBEliminar.Enabled := False;
SBDelete.Enabled := True;
end
else
begin
ShowMessage('Por Favor ingrese un código');
end;
end;
continuaaa...