unit uViewArticulo; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, uViewBase, ExtCtrls, StdCtrls, Buttons, DB, uDADataTable, DBCtrls, Grids, DBGrids, uBizArticulos, Mask, ComCtrls, uCustomView, JvComponent, JvFormAutoSize, cxControls, cxContainer, cxEdit, cxTextEdit, cxDBEdit, dxLayoutControl, cxCheckBox, PngSpeedButton, cxImage, ActnList, ImgList, PngImageList, cxGraphics, cxMaskEdit, cxDropDownEdit, uFamiliasController, uViewDatosYSeleccionProveedor, cxSpinEdit, cxCurrencyEdit, uArticulosController, uDAInterfaces; type IViewArticulo = interface(IViewBase) ['{65206152-786D-47AE-A037-5EF480BC056C}'] function GetArticulo: IBizArticulo; procedure SetArticulo(const Value: IBizArticulo); property Articulo: IBizArticulo read GetArticulo write SetArticulo; function GetController : IArticulosController; procedure SetController (const Value : IArticulosController); property Controller : IArticulosController read GetController write SetController; end; TfrViewArticulo = class(TfrViewBase, IViewArticulo) dsViewArticulo: TDADataSource; dxLayoutControlArticuloGroup_Root: TdxLayoutGroup; dxLayoutControlArticulo: TdxLayoutControl; dxLayoutControlArticuloGroup1: TdxLayoutGroup; dxLayoutControlArticuloItem3: TdxLayoutItem; eReferencia: TcxDBTextEdit; dxLayoutControlArticuloItem8: TdxLayoutItem; eDescripcion: TcxDBTextEdit; dxLayoutControlArticuloGroup2: TdxLayoutGroup; dxLayoutControlArticuloItem1: TdxLayoutItem; eNoComisionable: TcxDBCheckBox; dxLayoutControlArticuloGroup4: TdxLayoutGroup; OpenDialog1: TOpenDialog; SmallImages: TPngImageList; ActionList1: TActionList; actAnadir: TAction; actEliminar: TAction; dxLayoutControlArticuloItem2: TdxLayoutItem; PngSpeedButton2: TPngSpeedButton; dxLayoutControlArticuloItem5: TdxLayoutItem; PngSpeedButton1: TPngSpeedButton; dxLayoutControlArticuloGroup3: TdxLayoutGroup; dxLayoutControlArticuloGroup7: TdxLayoutGroup; eImagen: TcxImage; dxLayoutControlArticuloItem6: TdxLayoutItem; dxLayoutControlArticuloGroup5: TdxLayoutGroup; dxLayoutControlArticuloItem4: TdxLayoutItem; cbFamilia: TcxDBComboBox; dxLayoutControlArticuloGroup6: TdxLayoutGroup; dxLayoutControlArticuloItem14: TdxLayoutItem; frViewDatosYSeleccionProveedor1: TfrViewDatosYSeleccionProveedor; dxLayoutControlArticuloItem15: TdxLayoutItem; eReferenciaProv: TcxDBTextEdit; dxLayoutControlArticuloItem16: TdxLayoutItem; ePrecioCoste: TcxDBCurrencyEdit; dxLayoutControlArticuloItem17: TdxLayoutItem; eDescuento: TcxDBSpinEdit; dxLayoutControlArticuloItem18: TdxLayoutItem; ePrecioNeto: TcxDBCurrencyEdit; dxLayoutControlArticuloItem19: TdxLayoutItem; ePrecioPorte: TcxDBCurrencyEdit; dxLayoutControlArticuloGroup11: TdxLayoutGroup; dxLayoutControlArticuloGroup12: TdxLayoutGroup; dxLayoutControlArticuloItem7: TdxLayoutItem; cbNoInventariable: TcxDBCheckBox; dxLayoutControlArticuloGroup8: TdxLayoutGroup; dxLayoutControlArticuloItem9: TdxLayoutItem; ePrecioPVP: TcxDBCurrencyEdit; procedure actEliminarExecute(Sender: TObject); procedure actAnadirExecute(Sender: TObject); procedure cbFamiliaPropertiesInitPopup(Sender: TObject); procedure CustomViewCreate(Sender: TObject); procedure CustomViewDestroy(Sender: TObject); procedure cbFamiliaPropertiesValidate(Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean); procedure CustomViewShow(Sender: TObject); procedure PrecioNetoChanged(Sender: TObject); private procedure CargarImagen; protected FFamiliasController: IFamiliasController; FController: IArticulosController; FArticulo: IBizArticulo; FImagenModificada: Boolean; function GetArticulo: IBizArticulo; procedure SetArticulo(const Value: IBizArticulo); virtual; function GetController : IArticulosController; procedure SetController (const Value : IArticulosController); procedure OnProveedorChanged(Sender: TObject); public function GetModified: Boolean; override; procedure SetModified(const Value: Boolean); override; property Articulo: IBizArticulo read GetArticulo write SetArticulo; property Controller : IArticulosController read GetController write SetController; end; implementation uses uDataModuleArticulos, uSistemaFunc, schArticulosClient_Intf, uBizFamilias, uBizContactos; {$R *.dfm} { TfrViewArticulos } { ******************************* TfrViewArticulos ******************************** } procedure TfrViewArticulo.actAnadirExecute(Sender: TObject); var aAux : String; begin eImagen.LoadFromFile; if Assigned(eImagen.Picture) then begin ShowHourglassCursor; try aAux := DarFicheroJPGTemporal; eImagen.Picture.SaveToFile(aAux); FController.PonerImagen(Articulo, aAux); FImagenModificada := True; finally DeleteFile(aAux); HideHourglassCursor; end; end; end; procedure TfrViewArticulo.actEliminarExecute(Sender: TObject); begin inherited; eImagen.Clear; FController.QuitarImagen(Articulo); FImagenModificada := True; end; procedure TfrViewArticulo.CargarImagen; var aAux : String; begin if FArticulo.HayImagen then begin ShowHourglassCursor; try aAux := DarFicheroJPGTemporal; Articulo.DataTable.FieldByName(fld_ArticulosIMAGEN).SaveToFile(aAux); try eImagen.Picture.LoadFromFile(aAux); except on EInvalidGraphic do ShowMessage('error de imagen en el articulo'); end; finally DeleteFile(aAux); HideHourglassCursor; end; end; end; procedure TfrViewArticulo.cbFamiliaPropertiesInitPopup(Sender: TObject); begin inherited; with cbFamilia.Properties.Items do begin BeginUpdate; try Clear; AddStrings(FFamiliasController.DarListaFamilias); finally EndUpdate; end; end; end; procedure TfrViewArticulo.cbFamiliaPropertiesValidate(Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean); var AFamilias : IBizFamilia; begin inherited; with (Sender as TcxDBComboBox) do begin if (Length(DisplayValue) > 0) and (DisplayValue <> FArticulo.FAMILIA) then if Properties.LookupItems.IndexOf(DisplayValue) < 0 then begin Properties.LookupItems.BeginUpdate; AFamilias := FFamiliasController.BuscarTodos; AFamilias.DataTable.Active := True; try FFamiliasController.Anadir(AFamilias); AFamilias.DESCRIPCION := DisplayValue; FFamiliasController.Guardar(AFamilias); Properties.LookupItems.Add(DisplayValue); finally Properties.LookupItems.EndUpdate; AFamilias := NIL; end; end; end; end; procedure TfrViewArticulo.CustomViewCreate(Sender: TObject); begin inherited; FImagenModificada := False; FFamiliasController := TFamiliasController.Create; end; procedure TfrViewArticulo.CustomViewDestroy(Sender: TObject); begin FFamiliasController := Nil; ePrecioCoste.Properties.OnEditValueChanged := Nil; eDescuento.Properties.OnEditValueChanged := Nil; inherited; end; procedure TfrViewArticulo.CustomViewShow(Sender: TObject); begin inherited; ePrecioCoste.Properties.OnEditValueChanged := PrecioNetoChanged; eDescuento.Properties.OnEditValueChanged := PrecioNetoChanged; end; function TfrViewArticulo.GetArticulo: IBizArticulo; begin Result := FArticulo; end; function TfrViewArticulo.GetController: IArticulosController; begin Result := FController; end; function TfrViewArticulo.GetModified: Boolean; begin Result := inherited GetModified; //COMPROBAMOS SI EN LA VISTA HA HABIDO CAMBIOS EN LA IMAGEN if not Result then Result := Result or FImagenModificada; end; procedure TfrViewArticulo.OnProveedorChanged(Sender: TObject); begin if Assigned(FArticulo) then begin FArticulo.Edit; FArticulo.ID_PROVEEDOR := frViewDatosYSeleccionProveedor1.Proveedor.ID; FArticulo.DESCUENTO := frViewDatosYSeleccionProveedor1.Proveedor.DESCUENTO; end; end; procedure TfrViewArticulo.PrecioNetoChanged(Sender: TObject); begin if Assigned(FController) then FController.CalcularPrecioNeto(FArticulo); end; procedure TfrViewArticulo.SetArticulo(const Value: IBizArticulo); begin FArticulo := Value; frViewDatosYSeleccionProveedor1.OnProveedorChanged := NIL; if Assigned(FArticulo) then begin dsViewArticulo.DataTable := FArticulo.DataTable; frViewDatosYSeleccionProveedor1.Controller := FController.ProveedoresController; frViewDatosYSeleccionProveedor1.Proveedor := (FController.ProveedoresController.Buscar(FArticulo.ID_PROVEEDOR) as IBizProveedor); frViewDatosYSeleccionProveedor1.OnProveedorChanged := OnProveedorChanged; CargarImagen; end else begin dsViewArticulo.DataTable := NIL; FArticulo := NIL; eImagen.Clear; end; end; procedure TfrViewArticulo.SetController(const Value: IArticulosController); begin FController := Value; end; procedure TfrViewArticulo.SetModified(const Value: Boolean); begin inherited; if not Value then FImagenModificada := False; end; end.