unit uViewComercial; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, uViewContacto, dxLayoutLookAndFeels, DB, uDADataTable, dxLayoutControl, cxMemo, cxDBEdit, cxContainer, cxEdit, cxTextEdit, cxControls, cxMaskEdit, cxSpinEdit, ImgList, PngImageList, ActnList, cxHyperLinkEdit, Buttons, PngSpeedButton, cxDropDownEdit, cxCalendar, cxGraphics, uDAInterfaces, uCustomView, uViewBase, uViewTienda, uBizContactos, uDelegacionesController, uViewObservaciones; type IViewComercial = interface(IViewContacto) ['{ABD730E4-9328-42C4-8567-F46CE93AE826}'] end; TfrViewComercial = class(TfrViewContacto, IViewComercial) dxLayoutControlContactoItem19: TdxLayoutItem; cbUsuario: TcxComboBox; dxLayoutControlContactoItem20: TdxLayoutItem; edtComision: TcxDBSpinEdit; dxLayoutControlContactoItem21: TdxLayoutItem; cbDelegacionCliente: TcxDBComboBox; procedure CustomViewCreate(Sender: TObject); procedure CustomViewDestroy(Sender: TObject); procedure cbUsuarioPropertiesValidate(Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean); procedure cbDelegacionClientePropertiesInitPopup(Sender: TObject); procedure cbDelegacionClientePropertiesValidate(Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean); private FDataItem : TDADataTable; // FListaUsuarios : TStringList; FDelegacionesController: IDelegacionesController; function GetDataItem: TDADataTable; procedure SetDataItem(const Value: TDADataTable); protected procedure SetContacto(const Value: IBizContacto); override; public property DataItem : TDADataTable read GetDataItem write SetDataItem; procedure ElegirUsuario(const AIDUsuario : Integer); end; implementation {$R *.dfm} uses uFactuGES_App, uBizDelegaciones; procedure TfrViewComercial.cbDelegacionClientePropertiesInitPopup(Sender: TObject); begin inherited; with cbDelegacionCliente.Properties.Items do begin BeginUpdate; try Clear; AddStrings(FDelegacionesController.DarListaDelegaciones); finally EndUpdate; end; end; end; procedure TfrViewComercial.cbDelegacionClientePropertiesValidate( Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean); var ADelegacion : IBizDelegacion; begin inherited; with (Sender as TcxDBComboBox) do begin if (Length(DisplayValue) > 0) and (DisplayValue <> (Contacto as IBizComercial).DELEGACION) then if Properties.LookupItems.IndexOf(DisplayValue) < 0 then begin Properties.LookupItems.BeginUpdate; ADelegacion := FDelegacionesController.BuscarTodos; ADelegacion.DataTable.Active := True; try FDelegacionesController.Anadir(ADelegacion); ADelegacion.DESCRIPCION := DisplayValue; FDelegacionesController.Guardar(ADelegacion); Properties.LookupItems.Add(DisplayValue); finally Properties.LookupItems.EndUpdate; ADelegacion := NIL; end; end; end; end; procedure TfrViewComercial.cbUsuarioPropertiesValidate(Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean); var AIndex : integer; begin inherited; { if Assigned(FDataItem) and FDataItem.Active then begin AIndex := StrToInt(FListaUsuarios.Values[DisplayValue]); FDataItem.Edit; if Assigned(FDataItem.FindField('ID_USUARIO')) then FDataItem.FieldByName('ID_USUARIO').AsInteger := AIndex; // if Assigned(FDataItem.FindField('USUARIO')) then // FDataItem.FieldByName('USUARIO').AsString := DisplayValue; FDataItem.post; end; } end; procedure TfrViewComercial.CustomViewCreate(Sender: TObject); //var // i : integer; begin inherited; FDelegacionesController := TDelegacionesController.Create; { FListaUsuarios := AppFactuGES.UsuariosController.DarListaUsuarios; with cbUsuario.Properties.Items do begin BeginUpdate; try Clear; for i := 0 to FListaUsuarios.Count - 1 do Add(FListaUsuarios.Names[i]); finally EndUpdate; end; end; } end; procedure TfrViewComercial.CustomViewDestroy(Sender: TObject); begin // FreeAndNIL(FListaUsuarios); FDelegacionesController := NIL; inherited; end; procedure TfrViewComercial.ElegirUsuario(const AIDUsuario: Integer); var i : integer; begin { for i := 0 to FListaUsuarios.Count-1 do begin if FListaUsuarios.ValueFromIndex[i] = IntToStr(AIDUsuario) then begin cbUsuario.Text := FListaUsuarios.Names[i]; Break; end; end; } end; function TfrViewComercial.GetDataItem: TDADataTable; begin Result := FDataItem; end; procedure TfrViewComercial.SetContacto(const Value: IBizContacto); begin inherited; DataItem := FContacto.DataTable; end; procedure TfrViewComercial.SetDataItem(const Value: TDADataTable); begin { FDataItem := Value; if Assigned(FDataItem.FindField('ID_USUARIO')) then ElegirUsuario(FDataItem.FieldByName('ID_USUARIO').AsInteger); } end; end.