{Copyright or © or Copr. :

CNRS - Laboratoire Mouvement & Perception
franck.buloup@univmed.fr

This software is a computer program whose purpose is to highly simplify  
the use of ADwinPro realtime systems when you develop experimental
protocols  on life's sciences area.

This software is governed by the CeCILL  license under French law and
abiding by the rules of distribution of free software.  You can  use, 
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info". 

As a counterpart to the access to the source code and  rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty  and the software's author,  the holder of the
economic rights,  and the successive licensors  have only  limited
liability. 

In this respect, the user's attention is drawn to the risks associated
with loading,  using,  modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean  that it is complicated to manipulate,  and  that  also
therefore means  that it is reserved for developers  and  experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or 
data to be ensured and,  more generally, to use and operate it in the 
same conditions as regards security. 

The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.}
unit UTransfert_Ice;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, xmldom, XMLIntf, msxmldom, XMLDoc, StdCtrls, Buttons, ExtCtrls,
  CheckLst,Registry, UGlobal;

type
  TTransfertIceForm = class(TForm)
    Memo1: TMemo;
    ListCanauxCheckListBox: TCheckListBox;
    Panel1: TPanel;
    BitBtn1: TBitBtn;
    Button1: TButton;
		XMLDocEchange: TXMLDocument;
    Label3: TLabel;
    numPSCB: TComboBox;
		procedure FormShow(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure numPSCBChange(Sender: TObject);
  private
		{ Déclarations privées }
		procedure MAJIHM;
  public
    { Déclarations publiques }
  end;

var
	TransfertIceForm: TTransfertIceForm;

implementation

uses XMLClassesEchanges;

const Mess = 'Cette action n''est pas totalement configurée.'+
          #13'Quitter tout de même ?';

var DocEchange : IXMLEchangeROOTType;
    //Rep_Racine,Rep_Traitements,Rep_Actions,Rep_Fonctions,SystemType : string;

{$R *.dfm}

procedure TTransfertIceForm.MAJIHM;
var i,index : integer;
begin
  for i := 0 to DocEchange.FONCTION.SORTIE.Count - 1 do
  begin
    index := ListCanauxCheckListBox.Items.IndexOf(DocEchange.FONCTION.SORTIE[i].NOM);
    if index > -1
    then ListCanauxCheckListBox.Checked[index] := true;
	end;

	numPSCB.ItemIndex := numPSCB.items.indexOF(DocEchange.FONCTION.PARAM[0].NOM);

end;

procedure TTransfertIceForm.FormShow(Sender: TObject);
var i : integer;
    Param  : IXMLEchangeParamType;
begin
  Readconfig;
  XMLDocEchange.LoadFromFile(Rep_Fonctions+'Echange.xml');
  DocEchange := GetRootEchange(XMLDocEchange);

  ListCanauxCheckListBox.Clear;
  for i := 0 to DocEchange.CANAL.Count - 1
	do ListCanauxCheckListBox.Items.Add(DocEchange.CANAL.Items[i].NOM);

  if DocEchange.FONCTION.PARAM.Count = 0 then
	begin
		DocEchange.FONCTION.PARAM.Add;
	end;
  MAJIHM;
end;

procedure TTransfertIceForm.numPSCBChange(Sender: TObject);
var Param  : IXMLEchangeParamType;
begin
	Param := DocEchange.FONCTION.PARAM[0];
	Param.NOM := numPSCB.Text;
end;

procedure TTransfertIceForm.BitBtn1Click(Sender: TObject);
var i : integer;
		ASortie : IXMLEchangeSortieType;
		reponse : integer;
		InfoNotOK : boolean;
begin
  DocEchange.FONCTION.SORTIE.Clear;
  for i := 0 to ListCanauxCheckListBox.Count - 1 do
  begin
    if ListCanauxCheckListBox.Checked[i] then
    begin
      ASortie := DocEchange.FONCTION.SORTIE.Add;
      ASortie.NOM := ListCanauxCheckListBox.Items[i];
    end;
	end;

  reponse := mrYes;
  InfoNotOK := (DocEchange.FONCTION.SORTIE.count = 0) or
						   (DocEchange.FONCTION.PARAM[0].NOM = '');
  if InfoNotOK
  then reponse :=  messagedlg(Mess,mtInformation,[mbYes,mbNo],0);
  if reponse = mrYes then
  begin
    XMLDocEchange.SaveToFile(Rep_Fonctions+'Echange.xml');
		TransfertIceForm.close;
  end;
end;

procedure TTransfertIceForm.Button1Click(Sender: TObject);
var i : integer;
begin
  for i := 0 to ListCanauxCheckListBox.Items.Count - 1
  do ListCanauxCheckListBox.Checked[i] := not ListCanauxCheckListBox.Checked[i];
end;

end.
