unit uFilter;

interface

uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls, 
  Buttons, ExtCtrls,defs,MservClients;

type
  TFilterSetttingDlg = class(TForm)
    OKBtn: TButton;
    CancelBtn: TButton;
    Label1: TLabel;
    listboxGenresInclude: TListBox;
    Label2: TLabel;
    listboxGenresExclude: TListBox;
    btnFilterOff: TButton;
    ComboBox1: TComboBox;
    Label3: TLabel;
    Label4: TLabel;
    ComboBox2: TComboBox;
	 ComboBox3: TComboBox;
    procedure btnFilterOffClick(Sender: TObject);
  private
    { Private declarations }
  public
	 { Public declarations }
	 procedure Execute;
  end;

var
  FilterSetttingDlg: TFilterSetttingDlg;

implementation

{$R *.dfm}


procedure TFilterSetttingDlg.Execute;
var
	Genres: TStringArray;
	i:Integer;
	mr:Integer;
	sIncludeGenre:String;
	sExcludeGenre:String;
	sNewGenre:string;

begin
	MServClient.GetGenres(Genres);
	listboxGenresInclude.Items.Clear;
	listboxGenresExclude.Items.Clear;
	for i:=0 to High(Genres) do begin
		listboxGenresInclude.Items.Add(Genres[i]);
		listboxGenresExclude.Items.Add(Genres[i]);
	end;
	mr:=ShowModal;
	if mr=mrOk then begin
		sIncludeGenre:='';
		for i:=0 to listboxGenresInclude.Items.Count-1  do begin
			if listboxGenresInclude.Selected[i] then begin
				if length(sIncludeGenre)>0 then
					sIncludeGenre:=sIncludeGenre+'|';
				sIncludeGenre:=sIncludeGenre+'genre='+listboxGenresInclude.Items[i];
			end;
		end;
		sExcludeGenre:='';
		for i:=0 to listboxGenresExclude.Items.Count-1  do begin
			if listboxGenresExclude.Selected[i] then begin
				if length(sExcludeGenre)>0 then
					sExcludeGenre:=sExcludeGenre+'|';
				sExcludeGenre:=sExcludeGenre+'genre='+listboxGenresExclude.Items[i];
			end;
		end;
		sNewGenre:='';
		if length(sIncludeGenre)>0 then
			sNewGenre:='('+sIncludeGenre+')';
		if length(sExcludeGenre)>0 then begin
			if length(sNewGenre)>0 then
				sNewGenre:=sNewGenre+' & ';
			sNewGenre:=sNewGenre+'!('+sExcludeGenre+')';
		end;
		MServClient.SetFilter(true,sNewGenre);
	end;
	if mr=44 then
		MServClient.SetFilter(false,'');
end;


procedure TFilterSetttingDlg.btnFilterOffClick(Sender: TObject);
begin
	modalResult:=44;
end;

end.
