{ =============================================================================== Copyright (©) 2006. Rodax Software. =============================================================================== Los contenidos de este fichero son propiedad de Rodax Software titular del copyright. Este fichero sólo podrá ser copiado, distribuido y utilizado, en su totalidad o en parte, con el permiso escrito de Rodax Software, o de acuerdo con los términos y condiciones establecidas en el acuerdo/contrato bajo el que se suministra. ----------------------------------------------------------------------------- Web: www.rodax-software.com =============================================================================== Fecha primera versión: 22-05-2006 Versión actual: 1.0.0 Fecha versión actual: 22-05-2006 =============================================================================== Modificaciones: Fecha Comentarios --------------------------------------------------------------------------- =============================================================================== } unit uBizContacto; interface uses uDAInterfaces, uDADataTable, Classes, uDBSelectionList, schContactosClient_Intf, uExceptions, Controls; const BIZ_CATEGORIA = 'Client.Categoria'; BIZ_CONTACTO = 'Client.Contacto'; BIZ_CATEGORIACONTACTO = 'Client.CategoriaContacto'; BIZ_CONTACTOASOCIADO = 'Client.ContactoAsociado'; BIZ_NOMBRECONTACTO = 'Client.Field.NombreContacto'; type IBizContacto = Interface; //Se declara después IBizNombre = interface(IDAStronglyTypedDataTable) ['{6A9117D2-5C90-4AAA-ADA3-022519BCAB4D}'] end; IBizCategoria = interface(ICATEGORIAS) ['{8713CDAC-1CDD-479E-82F6-ACA58232C19E}'] procedure Show; end; IBizCategoriaContacto = interface(ICONTACTOSCATEGORIAS) ['{1EF7B91A-4513-4057-BD6A-613CB1A4CBB8}'] function GetListaCategorias: String; property ListaCategorias: String read GetListaCategorias; procedure Show; end; IBizContactoAsociado = interface(ICONTACTOSASOCIADOS) ['{7424E52D-C4C6-407B-92E9-C2AE53842D9F}'] procedure AppendContactos(CodigoContacto: Variant; AContactos: IBizContacto); procedure UpdateContactoAsociado(AContacto: IBizContacto); end; IBizContacto = interface(ICONTACTOS) ['{800A68B8-8C95-4CEB-B12A-C3D039ACDC14}'] function GetCategorias: IBizCategoriaContacto; procedure SetCategorias(const Value: IBizCategoriaContacto); property Categorias: IBizCategoriaContacto read GetCategorias write SetCategorias; function GetAsociados: IBizContactoAsociado; procedure SetAsociados(const Value: IBizContactoAsociado); property Asociados : IBizContactoAsociado read GetAsociados write SetAsociados; procedure Show; procedure ShowAll; procedure Preview; function ShowForSelect : TModalResult; function ShowForMultiSelect: TModalResult; end; TBizNombreFieldRules = class(TDAFieldRules) protected procedure OnChange(Sender: TDACustomField); override; end; TBizContactoAsociadoDataTableRules = class(TCONTACTOSASOCIADOSDataTableRules, IBizContactoAsociado) protected procedure BeforeInsert(Sender: TDADataTable); override; public procedure AppendContactos(CodigoContacto: Variant; AContactos: IBizContacto); procedure UpdateContactoAsociado(AContacto: IBizContacto); end; TBizCategoriaDataTableRules = class(TCATEGORIASDataTableRules, IBizCategoria) public procedure Show; end; TBizContactoDataTableRules = class(TCONTACTOSDataTableRules, IBizContacto, IApplyUpdateFailedException, ISelectedRowList) private FCategorias: IBizCategoriaContacto; FCategoriasLink: TDADataSource; FAsociados: IBizContactoAsociado; FAsociadosLink: TDADataSource; FSelectedRows : TSelectedRowList; protected procedure OnNewRecord(Sender: TDADataTable); override; procedure BeforeApplyUpdates(DataTable: TDADataTable; const Delta: IDADelta); function GetSelectedRows : TSelectedRowList; virtual; procedure ShowApplyUpdateFailed (const Error: EDAApplyUpdateFailed); virtual; function GetCategorias: IBizCategoriaContacto; procedure SetCategorias(const Value: IBizCategoriaContacto); function GetAsociados: IBizContactoAsociado; procedure SetAsociados(const Value: IBizContactoAsociado); public property Asociados : IBizContactoAsociado read GetAsociados write SetAsociados; property Categorias: IBizCategoriaContacto read GetCategorias write SetCategorias; property SelectedRows : TSelectedRowList read GetSelectedRows; function ShowForMultiSelect: TModalResult; virtual; function ShowForSelect: TModalResult; procedure Show; virtual; procedure ShowAll; virtual; procedure Preview; virtual; constructor Create(aDataTable: TDADataTable); override; destructor Destroy; override; end; TBizCategoriaContacto = class(TCONTACTOSCATEGORIASDataTableRules, IBizCategoriaContacto) private FListaCategorias: String; function GetListaCategorias: String; protected procedure BeforeInsert(Sender: TDADataTable); override; public property ListaCategorias: String read GetListaCategorias; procedure Show; end; procedure ValidarContacto (const AObj : IBizContacto); implementation uses DB, Variants, uDACDSDataTable, SysUtils, uEditorUtils, uDataModuleContactos, Dialogs, Windows, LiteralesContactos, uDataModuleBase, uUtils; procedure ValidarContacto (const AObj : IBizContacto); begin // end; { TBizContactoDataTableRules } { ************************** TBizContactoDataTableRules ************************** } constructor TBizContactoDataTableRules.Create(aDataTable: TDADataTable); begin inherited; FAsociadosLink := TDADataSource.Create(NIL); FCategoriasLink := TDADataSource.Create(NIL); FSelectedRows := TSelectedRowList.Create(aDataTable); aDataTable.OnBeforeApplyUpdates := BeforeApplyUpdates; end; destructor TBizContactoDataTableRules.Destroy; begin FCategorias := Nil; FCategoriasLink.Free; FAsociados := Nil; FAsociadosLink.Free; FSelectedRows.Free; FSelectedRows := Nil; inherited; end; function TBizContactoDataTableRules.GetCategorias: IBizCategoriaContacto; begin Result := FCategorias; end; procedure TBizContactoDataTableRules.OnNewRecord(Sender: TDADataTable); begin inherited; CODIGOEMPRESA := dmBase.CodigoEmpresa; CODIGO := dmContactos.getCodigo; USUARIO := dmBase.Usuario; FECHAALTA := dmBase.Fecha; NOMBRE := msgLitNombre; end; procedure TBizContactoDataTableRules.SetCategorias(const Value: IBizCategoriaContacto); begin FCategorias := Value; FCategoriasLink.DataTable := Self.DataTable; FCategorias.DataTable.MasterSource := FCategoriasLink; end; procedure TBizContactoDataTableRules.Show; begin ShowEditor(IBizContacto, Self, etItem); end; procedure TBizContactoDataTableRules.Preview; begin dmContactos.Preview; end; procedure TBizContactoDataTableRules.ShowAll; begin ShowEditor(IBizContacto, Self, etItems); end; { TBizCategoriaDataTableRules } { ************************** TBizCategoriaDataTableRules ************************ } procedure TBizCategoriaDataTableRules.Show; begin ShowEditor(IBizCategoria, Self, etItems); end; { TBizCategoriaContacto } { ************************** TBizCategoriaContacto ****************************** } procedure TBizCategoriaContacto.BeforeInsert(Sender: TDADataTable); begin inherited; if Assigned(DataTable.MasterSource) and (DataTable.MasterSource.DataTable.State in dsEditModes) then DataTable.MasterSource.DataTable.Post; end; function TBizCategoriaContacto.GetListaCategorias: String; begin FListaCategorias := ''; if not DataTable.Active then DataTable.Active := True; First; while not DataTable.EOF do begin if FListaCategorias <> '' then FListaCategorias := FListaCategorias + '; '; FListaCategorias := FListaCategorias + DESCRIPCION; Next; end; Result := FListaCategorias; end; procedure TBizCategoriaContacto.Show; begin ShowEditor(IBizCategoriaContacto, Self, etItems); end; function TBizContactoDataTableRules.GetSelectedRows: TSelectedRowList; begin Result := FSelectedRows; end; function TBizContactoDataTableRules.ShowForSelect : TModalResult; begin Result := ShowEditor(IBizContacto, Self, etSelectItem); end; function TBizContactoDataTableRules.ShowForMultiSelect: TModalResult; begin Result := ShowEditor(IBizContacto, Self, etSelectItems); end; procedure TBizContactoDataTableRules.ShowApplyUpdateFailed(const Error: EDAApplyUpdateFailed); begin if (Pos(AUF_FKVIOLATION, Error.Message) > 0) then MessageBox(0, PChar(msgErrorContactoAsociado), PChar(msgAtencion), MB_ICONWARNING or MB_OK); end; procedure TBizContactoDataTableRules.BeforeApplyUpdates(DataTable: TDADataTable; const Delta: IDADelta); begin ValidarContacto(Self); end; { TBizNombreFieldRules } procedure TBizNombreFieldRules.OnChange(Sender: TDACustomField); begin inherited; if Length(Sender.Value) = 0 then begin Showmessage(msgLitNombreObligatorio); Sender.Value := msgLitNombre; Sender.FocusControl; end; end; function TBizContactoDataTableRules.GetAsociados: IBizContactoAsociado; begin Result := FAsociados; end; procedure TBizContactoDataTableRules.SetAsociados( const Value: IBizContactoAsociado); begin FAsociados := Value; FAsociadosLink.DataTable := Self.DataTable; FAsociados.DataTable.MasterSource := FAsociadosLink; end; { TBizContactoAsociadoDataTableRules } procedure TBizContactoAsociadoDataTableRules.AppendContactos(CodigoContacto: Variant; AContactos: IBizContacto); var CadenaClaves: String; ListaValoresClave: TStringList; begin if not AContactos.DataTable.Active then AContactos.DataTable.Active := True; CadenaClaves := fld_ContactosAsociadosCODIGOCONTACTO; CadenaClaves := CadenaClaves + ';' + fld_ContactosAsociadosCODIGOASOCIADO; ListaValoresClave := TStringList.Create; Self.DataTable.DisableControls; with AContactos do begin DataTable.First; while not DataTable.EOF do begin //Por cada elemento a añadir lo buscamos por si ya estuviese añadido Self.DataTable.First; ListaValoresClave.Clear; ListaValoresClave.Add(VarToStr(CodigoContacto)); ListaValoresClave.Add(IntToStr(CODIGO)); if Self.DataTable.Locate(CadenaClaves, getArrList(ListaValoresClave), []) then // MessageBox(0, PChar(NOMBRE + msgLitContactoObraAnadido), 'Atención', MB_ICONWARNING or MB_OK) else begin Self.DataTable.Append; Self.CODIGOCONTACTO := CodigoContacto; Self.CODIGOASOCIADO := CODIGO; Self.NOMBRE := NOMBRE; Self.DataTable.Post; end; Next; end; end; FreeAndNil(ListaValoresClave); Self.DataTable.EnableControls; end; procedure TBizContactoAsociadoDataTableRules.BeforeInsert(Sender: TDADataTable); begin inherited; if Assigned(DataTable.MasterSource) and (DataTable.MasterSource.DataTable.State in dsEditModes) then DataTable.MasterSource.DataTable.Post; end; procedure TBizContactoAsociadoDataTableRules.UpdateContactoAsociado(AContacto: IBizContacto); begin if not (Self.DataTable.State in dsEditModes) then Self.DataTable.Edit; Self.NOMBRE := AContacto.NOMBRE; if (Self.DataTable.State in dsEditModes) then Self.DataTable.Post; end; initialization RegisterDataTableRules(BIZ_CATEGORIA, TBizCategoriaDataTableRules); RegisterDataTableRules(BIZ_CONTACTO, TBizContactoDataTableRules); RegisterDataTableRules(BIZ_CATEGORIACONTACTO, TBizCategoriaContacto); RegisterDataTableRules(BIZ_CONTACTOASOCIADO, TBizContactoAsociadoDataTableRules); RegisterFieldRules(BIZ_NOMBRECONTACTO, TBizNombreFieldRules); finalization end.