//**************************************************************
// anketa.pas
// ðåãèñòðàöèÿ àíêåòíûõ äàííûõ êîíòðàãåíòîâ. Âûçûâàåòñÿ â ñïðàâî÷íèêå êîíòðàãåíòîâ,
// èñïîëüçóåò òàáëèöó org_adv
//**************************************************************

var ID :integer; // êîä êîíòðàãåíòà, ïåðåäàåòñÿ â ñêðèïò ïðèëîæåíèåì


var TaOrg,taOrgAdv :TTable;

    Form :TForm;
    EditFIO1,EditFIO2,EditFIO3 :tedit; // ÔÈÎ
    EditBD_D,EditBD_M,EditBD_Y :tJVValidateEdit; // äàòà ðîæäåíèÿ
    //EditBD :TDateTimePicker;
    EditAdres_O,EditAdres_R,EditAdres_G,EditAdres_U,EditAdres_EM,EditAdres_Ind,EditAdres_ND,EditAdres_KV,EditAdres_TEL :TEdit;

    EditChild1,EditChild3,EditChild7,EditChild10 :tjvValidateEdit;

    EditSot :TListBox;
    EditFreq :TListBox;
    EditCause :Tlistbox;
    EditWay :TListBox;

    EditPoints :tjvValidateEdit;
    EditGEtInfo :TListBox;

    EditNumberApt :TEdit;
    EditNumberCard :TEdit;
    EditNumberCash :TEdit;
    EditNumberBirthCertif :TEdit;

    Lab,Lab1,Lab2 :TLabel;

    bevel1 :TBevel;
    Button1,Button2 :TButton;

    DT :Tdatetime;

    strvAlue :string;

const
    HDelim = 5;
    VDelim = 5;
    VLDelim = 2;
    FLeft = 10;


function GetAdvValue(ID :integer; const FieldName :string) :string;
begin
  result := '';
  bderefresh;
  taorgadv.open;
  if taorgadv.findkey([id,fieldname])
  then begin
    Result := Taorgadv.fieldbyname('fieldvalue').asstring;
  end;
end;

procedure SetAdvValue(ID :integer; const FieldName :string; const Value :string);
begin
  bderefresh;
  taorgadv.open;
  if taorgadv.findkey([ID,FieldName]) then
  begin
     if Value = '' then
     begin
        taOrgAdv.Delete;
        bdeflush;
     end
     else begin
        if taorgadv.fieldbyname('fieldvalue').asstring <> Value
        then begin
          taorgadv.edit;
          taorgadv.fieldbyname('fieldvalue').asstring := Value;
          taorgadv.post;
          bdeflush;
        end;
     end;
  end
  else if Value <> '' then
  begin
     taorgadv.append;
     taorgadv.fieldbyname('id_org').asinteger := ID;
     taorgadv.fieldbyname('fieldname').asstring := Fieldname;
     taorgadv.fieldbyname('fieldvalue').asstring := Value;
     taorgadv.post;
     bdeflush;
  end;
end;

begin

   taOrg := ttable.create(nil);
   taOrgAdv := TTable.create(nil);
   try
     taOrg.databasename := 'dbkassa';
     taOrgAdv.databasename := 'dbkassa';
     taOrg.tablename := 'agents.db';
     taorgadv.tablename := 'org_adv.db';

     Form := TForm.create(nil);
     try
       Form.caption := 'Àíêåòà ïîñòîÿííîãî ïîêóïàòåëÿ';
       Form.Position := poScreenCenter;
       Form.BorderStyle := bsDialog;
       Form.Width := 500;
       //Form.Height := 400;
       Form.Font.Name := 'Tahoma';

       Lab :=  TLabel.create(Form);
       Lab.Caption := 'Ôàìèëèÿ Èìÿ Îò÷åñòâî';
       Lab.Top := 5;
       Lab.Left := FLeft;
       Lab.parent := Form;

       EditFIO1 := TEdit.create(Form);
       EditFIO1.Top := Lab.Top + Lab.Height + VLDelim;
       EditFIO1.Left := FLeft;
       EditFIO1.width := 150;
       EditFIO1.Parent := Form;

       EditFIO2 := TEdit.create(Form);
       EditFIO2.Top := EditFIO1.top;
       EditFIO2.Left := EditFIO1.left + EditFIO1.Width + HDelim ;
       EditFIO2.width := 150;
       EditFIO2.Parent := Form;

       EditFIO3 := TEdit.create(Form);
       EditFIO3 := TEdit.create(Form);
       EditFIO3.Top := EditFIO1.top;
       EditFIO3.Left := EditFIO2.left + EditFIO2.Width + HDelim ;
       EditFIO3.width := 150;
       EditFIO3.Parent := Form;

       Lab2 :=  TLabel.create(Form);
       Lab2.Caption := 'Äàòà ðîæäåíèÿ:';
       Lab2.Top := EditFIO1.Top + EditFIO1.Height + VDelim;
       Lab2.Left := FLeft;
       //Lab2.Font.style := Lab2.Font.Style + fsUnderline;
       Lab2.parent := Form;
       Lab2.Font.Color := clNavy;

      {
       EditBD := TDateTimePicker.create(Form);
       EditBD.Top := Lab.Top + Lab.Height + VDelim;
       EditBD.Left := Lab.Left;
       EditBD.Width := EditFIO1.Width;
       EditBd.parent := Form;}

       Lab1 := TLabel.create(Form);
       Lab1.Caption := 'Äåíü';
       Lab1.Top := Lab2.Top;
       Lab1.Left := Lab2.Left + Lab2.width + HDelim;
       Lab1.Parent := Form;


       EditBD_D := TjvValidateEdit.create(Form);
       EditBD_D.AllowEmpty := true;
       EditBD_D.ZeroEmpty := true;
       EditBD_D.MinValue := 0;
       EditBD_D.MaxValue := 31;
       EditBD_D.HasMinVAlue := true;
       EditBD_D.HasMaxVAlue := true;
       EditBD_D.Left := lab1.Left + Lab1.Width + HDelim;
       EditBD_D.Top := Lab1.Top;
       EditBD_D.Width := 50;
       EditBD_D.Alignment := taCenter;
       EditBD_D.Parent := Form;

       Lab1 := TLabel.create(Form);
       Lab1.Caption := 'Ìåñÿö';
       Lab1.Top := Lab2.Top ;
       Lab1.Left := EditBD_D.Left + EditBD_D.width + HDelim;
       Lab1.Parent := Form;

       EditBD_M := TjvValidateEdit.create(Form);
       EditBD_M.AllowEmpty := true;
       EditBD_M.ZeroEmpty := true;
       EditBD_M.MinValue := 0;
       EditBD_M.MaxValue := 12;
       EditBD_M.HasMinVAlue := true;
       EditBD_M.HasMaxVAlue := true;
       EditBD_M.Left := lab1.Left + Lab1.Width + HDelim;
       EditBD_M.Top := Lab1.Top;
       EditBD_M.Width := 50;
       EditBD_M.Alignment := taCenter;
       EditBD_M.Parent := Form;

       Lab1 := TLabel.create(Form);
       Lab1.Caption := 'Ãîä';
       Lab1.Top := Lab2.Top;
       Lab1.Left := EditBD_M.Left + EditBD_M.width + HDelim;
       Lab1.Parent := Form;

       EditBD_Y := TjvValidateEdit.create(Form);
       EditBD_Y.AllowEmpty := true;
       EditBD_Y.ZeroEmpty := true;
       EditBD_Y.MinValue := 0;
       EditBD_Y.HasMinVAlue := true;
       EditBD_Y.Left := lab1.Left + Lab1.Width + HDelim;
       EditBD_Y.Top := Lab1.Top;
       EditBD_Y.Width := 50;
       EditBD_Y.Alignment := taCenter;
       EditBD_Y.Parent := Form;


       Lab1 := TLabel.create(Form);
       Lab1.Caption := 'Ïî÷òîâûé àäðåñ:';
       Lab1.Top := EditBD_D.Top+ EditBD_D.Height + VDelim;
       Lab1.Left := FLeft;
       Lab1.Parent := Form;
       Lab1.Font.Color := clNavy;

       Lab2 := TLabel.create(Form);
       Lab2.Caption := 'Îáëàñòü:';
       Lab2.Top := lab1.Top + Lab1.Height + VDelim;
       Lab2.Left := FLeft;
       Lab2.Parent := Form;

       EditAdres_O := TEdit.create(Form);
       EditAdres_o.Top := Lab2.Top;
       EditAdres_O.Left := Lab2.Left + Lab2.Width + HDelim;
       EditAdres_o.Width := EditFio2.left + EditFio2.Width - EditAdres_O.left;
       EditAdres_o.Parent := Form;

       Lab2 := TLabel.create(Form);
       Lab2.Caption := 'Ðàéîí:';
       Lab2.Top := EditAdres_o.Top + EditAdres_o.Height + VDelim;
       Lab2.Left := FLeft;
       Lab2.Parent := Form;

       EditAdres_R := TEdit.create(Form);
       EditAdres_r.Top := Lab2.Top;
       EditAdres_r.Left := EditAdres_o.left;
       EditAdres_r.Width := EditAdres_o.width;
       EditAdres_r.Parent := Form;

       Lab2 := TLabel.create(Form);
       Lab2.Caption := 'Ãîðîä:';
       Lab2.Top := EditAdres_R.Top + EditAdres_R.Height + VDelim;
       Lab2.Left := FLeft;
       Lab2.Parent := Form;

       EditAdres_G := TEdit.create(Form);
       EditAdres_g.Top := Lab2.Top;
       EditAdres_g.Left := EditAdres_o.left;
       EditAdres_g.Width := EditAdres_o.width;
       EditAdres_g.Parent := Form;

       Lab2 := TLabel.create(Form);
       Lab2.Caption := 'Óëèöà:';
       Lab2.Top := EditAdres_g.Top + EditAdres_g.Height + VDelim;
       Lab2.Left := FLeft;
       Lab2.Parent := Form;

       EditAdres_U := TEdit.create(Form);
       EditAdres_u.Top := Lab2.Top;
       EditAdres_u.Left := EditAdres_o.left;
       EditAdres_u.Width := EditAdres_o.width;
       EditAdres_u.Parent := Form;

       Lab2 := TLabel.create(Form);
       Lab2.Caption := 'email:';
       Lab2.Top := EditAdres_U.Top + EditAdres_u.Height + VDelim;
       Lab2.Left := FLeft;
       Lab2.Parent := Form;

       EditAdres_em := TEdit.create(Form);
       EditAdres_em.Top := Lab2.Top;
       EditAdres_em.Left := EditAdres_o.left;
       EditAdres_em.Width := EditAdres_o.width;
       EditAdres_em.Parent := Form;


       Lab2 := TLabel.create(Form);
       Lab2.Caption := 'Èíäåêñ:  ';
       Lab2.Top := EditAdres_O.Top;
       Lab2.Left := EditAdres_o.Left + EditAdres_o.width + HDelim;
       Lab2.Parent := Form;

       EditAdres_IND := TEdit.create(Form);
       EditAdres_IND.Top := Lab2.Top;
       EditAdres_IND.Left := lab2.Left + Lab2.Width  + HDelim;
       EditAdres_IND.Width := EditFIO3.Left+ EditFIO3.Width - EditAdres_IND.left;
       EditAdres_IND.Parent := Form;

       Lab1 := Lab2;

       Lab2 := TLabel.create(Form);
       Lab2.Caption := '¹ äîìà:';
       Lab2.Top := EditAdres_R.Top;
       Lab2.Left := Lab1.Left;
       Lab2.Parent := Form;

       EditAdres_ND := TEdit.create(Form);
       EditAdres_ND.Top := Lab2.Top;
       EditAdres_ND.Left := EditADRES_IND.Left;
       EditAdres_ND.Width := EditAdres_IND.Width;
       EditAdres_ND.Parent := Form;


       Lab2 := TLabel.create(Form);
       Lab2.Caption := '¹ êâ:';
       Lab2.Top := EditAdres_G.Top;
       Lab2.Left := Lab1.Left;
       Lab2.Parent := Form;

       EditAdres_KV := TEdit.create(Form);
       EditAdres_KV.Top := Lab2.Top;
       EditAdres_KV.Left := EditADRES_IND.Left;
       EditAdres_KV.Width := EditAdres_IND.Width;
       EditAdres_KV.Parent := Form;


       Lab2 := TLabel.create(Form);
       Lab2.Caption := 'Òåëåôîí:';
       Lab2.Top := EditAdres_U.Top;
       Lab2.Left := Lab1.Left;
       Lab2.Parent := Form;

       EditAdres_TEL := TEdit.create(Form);
       EditAdres_TEL.Top := Lab2.Top;
       EditAdres_TEL.Left := EditADRES_IND.Left;
       EditAdres_TEL.Width := EditAdres_IND.Width;
       EditAdres_TEL.Parent := Form;


       Lab1 := TLabel.create(Form);
       Lab1.Caption := 'Êîëè÷åñòâî äåòåé:';
       Lab1.Top := EditAdres_EM.Top+ EditAdres_EM.Height + VDelim;
       Lab1.Left := FLeft;
       Lab1.Parent := Form;
       Lab1.Font.Color := clNavy;


       Lab2 := TLabel.create(Form);
       Lab2.Caption := '1-3 ãîäà:';
       Lab2.Top := Lab1.Top + Lab1.Height + VDelim;
       Lab2.Left := FLeft;
       Lab2.Parent := Form;

       EditChild1 := TjvValidateEdit.create(Form);

       EditChild1.MinValue := 0;
       EditChild1.HasMinVAlue := true;
       EditChild1.Left := lab2.Left + Lab2.Width + HDelim;
       EditChild1.Top := Lab2.Top;
       EditChild1.Width := 50;
       EditChild1.Alignment := taCenter;
       EditChild1.Parent := Form;

       Lab2 := TLabel.create(Form);
       Lab2.Caption := '3-7 ëåò:';
       Lab2.Top := Lab1.Top + Lab1.Height + VDelim;
       Lab2.Left := EditChild1.left + EditChild1.width + HDelim;
       Lab2.Parent := Form;

       EditChild3 := TjvValidateEdit.create(Form);

       EditChild3.MinValue := 0;
       EditChild3.HasMinVAlue := true;
       EditChild3.Left := lab2.Left + Lab2.Width + HDelim;
       EditChild3.Top := Lab2.Top;
       EditChild3.Width := 50;
       EditChild3.Alignment := taCenter;
       EditChild3.Parent := Form;

       Lab2 := TLabel.create(Form);
       Lab2.Caption := '7-10 ëåò:';
       Lab2.Top := Lab1.Top + Lab1.Height + VDelim;
       Lab2.Left := EditChild3.left + EditChild3.width + HDelim;
       Lab2.Parent := Form;

       EditChild7 := TjvValidateEdit.create(Form);

       EditChild7.MinValue := 0;
       EditChild7.HasMinVAlue := true;
       EditChild7.Left := lab2.Left + Lab2.Width + HDelim;
       EditChild7.Top := Lab2.Top;
       EditChild7.Width := 50;
       EditChild7.Alignment := taCenter;
       EditChild7.Parent := Form;

       Lab2 := TLabel.create(Form);
       Lab2.Caption := '10-16 ëåò:';
       Lab2.Top := Lab1.Top + Lab1.Height + VDelim;
       Lab2.Left := EditChild7.left + EditChild7.width + HDelim;
       Lab2.Parent := Form;

       EditChild10 := TjvValidateEdit.create(Form);

       EditChild10.MinValue := 0;
       EditChild10.HasMinVAlue := true;
       EditChild10.Left := lab2.Left + Lab2.Width + HDelim;
       EditChild10.Top := Lab2.Top;
       EditChild10.Width := 50;
       EditChild10.Alignment := taCenter;
       EditChild10.Parent := Form;




       Lab1 := TLabel.create(Form);
       Lab1.Caption := 'Âàø ñîòîâûé îïåðàòîð:';
       //Lab1.Font.Color := clNavy;
       Lab1.Top := EditChild1.Top+ EditChild1.Height + VDelim;
       Lab1.Left := FLeft;
       Lab1.Parent := Form;

       EditSot := tListbox.create(Form);
       EditSot.Left := FLeft; //Lab1.left + Lab1.width + HDelim;
       EditSot.top := Lab1.Top + Lab1.Height + VLDelim;
       EditSot.Width := EditFIO1.Width;
       EditSot.height := Lab1.height * 6;
       EditSot.parent := Form;

       EditSot.items.add('ÌÒÑ');
       EditSot.items.add('Ìåãàôîí');
       EditSot.items.add('Áèëàéí');
       EditSot.items.add('Äðóãîé');

       Lab2 := Lab1;


       Lab1 := TLabel.create(Form);
       Lab1.Caption := '×àñòîòà ïîêóïîê â ñåòè ÄÑ:';
       //Lab1.Font.Color := clNavy;
       Lab1.Top := Lab2.top;
       Lab1.Left := EditFIO2.Left;
       Lab1.Parent := Form;

       EditFreq := TListBox.create(Form);
       EditFreq.Top := EditSot.Top;
       EditFreq.Left := EditFio2.left;
       EditFreq.Width := EditFIO2.Width;
       EditFreq.height := EditSot.height;
       EditFreq.Parent := Form;

       EditFreq.items.add('Íåñêîëüêî ðàç â íåäåëþ');
       EditFreq.items.add('1 ðàç â íåäåëþ');
       EditFreq.items.add('1 ðàç â 2 íåäåëè');
       EditFreq.items.add('1 ðàç â ìåñÿö');
       EditFreq.items.add('Äðóãîé');

       Lab1 := TLabel.create(Form);
       Lab1.Caption := 'Ïðè÷èíà âûáîðà àïòåêè:';
       //Lab1.Font.Color := clNavy;
       Lab1.Top := Lab2.Top;
       Lab1.Left := EditFIO3.Left;
       Lab1.Parent := Form;


       EditCause := TListBox.create(Form);
       EditCause.Top := EditSot.Top;
       EditCause.Left := EditFio3.left;
       EditCAuse.Width := EDITFIO3.Width;
       EditCause.height:= EditFreq.height;
       EditCAuse.parent := Form;

       EditCause.Items.add('Ðàáîòà ðÿäîì');
       EditCause.Items.add('Äîì ðÿäîì');
       EditCause.Items.add('Ïî ïóòè');
       EditCause.Items.add('Äðóãèå');

       Lab1 := TLabel.create(Form);
       Lab1.Caption := 'Êàê Âû äîáèðàåòåñü äî àïòåêè:';
       //Lab1.Font.Color := clNavy;
       Lab1.Top := EditCause.Top + EditCAuse.height + vdelim;
       Lab1.Left := FLeft;
       Lab1.Parent := Form;


       EditWay := TListBox.create(Form);
       EditWay.Top := Lab1.Top + Lab1.Height + VLDelim;
       EditWay.Left := FLeft;
       EditWay.Width := EDITFIO1.Width;
       EditWay.height:= Lab1.Height * 6;
       EditWay.parent := Form;

       EditWay.Items.add('Ïåøêîì');
       EditWay.Items.add('Íà àâòîáóñå/òðîëë/òðàìâ');
       EditWay.Items.add('Íà ìàøèíå');
       EditWay.Items.add('Íà ìåòðî???');
       EditWay.Items.add('Äðóãèå');



       Lab2 := TLabel.create(Form);
       Lab2.Top := EditWay.Top;
       Lab2.Left := EditFio2.left;
       Lab2.Caption := 'Îöåíèòå êà÷åñòâî '+#13+'îáñëóæèâàíèÿ (1-5 áàëëîâ)';
       Lab2.Parent := Form;


       EditPoints := TjvValidateEdit.create(Form);
       EditPOints.MinValue := 1;
       EditPOints.MaxValue := 5;
       EditPOints.HasMinVAlue := true;
       EditPOints.HasMaxVAlue := true;
       EditPOints.Left := EditFIO2.Left;
       EditPOints.Top := Lab2.Top + Lab2.height  + VLDelim;
       EditPOints.Width := 50;
       EditPOints.Alignment := taCenter;
       EditPOints.Parent := Form;

       Lab2 := TLabel.create(Form);
       Lab2.Top := Lab1.Top;
       Lab2.Left := EditFio3.left;
       Lab2.Caption := 'Õîòèòå ëè Âû ïîëó÷àòü '+#13+'èíôîðìàöèþ îò ÄÑ';
       Lab2.Parent := Form;


       EditGetInfo := TListBox.create(Form);
       EditGetInfo.Top := Lab2.Top + Lab2.Height + VLDelim;
       EditGetInfo.Left := EditFio3.Left;
       EditGetInfo.Width := EDITFIO3.Width;
       EditGetInfo.height:= EditWay.Top + EditWay.height - EditGetInfo.Top ;
       EditGetInfo.parent := Form;
       EditGetInfo.Items.add('ïî e-mail');
       EditGetInfo.Items.add('ïî ïî÷òå');
       EditGetInfo.Items.add('íå õî÷ó');

       Lab1 := TLabel.create(Form);
       Lab1.Top := EditWay.Top + EditWay.Height + VDelim;
       Lab1.Left := FLeft;
       Lab1.Caption := 'Äîêóìåíò, ïîäòâåðæäàþùèé ïðàâî ïîëó÷åíèÿ äèñêîíòíîé êàðòû';
       Lab1.Parent := Form;
       Lab1.Color := clNavy;

       Lab2 := TLabel.create(Form);
       Lab2.Top := Lab1.Top + Lab1.Height + VDelim;
       Lab2.Left := FLeft;
       Lab2.Caption := 'N àïòåêè';
       Lab2.Parent := Form;

       Lab1 := Lab2;

       EditNumberApt := TEdit.create(Form);
       EditNumberApt.Top := Lab1.Top  ;
       EditNumberApt.Left := Lab1.Left + lab1.Width + Hdelim;
       EditNumberApt.Width := 50;
       EditNumberApt.parent := Form;

       Lab2 := TLabel.create(Form);
       Lab2.Top := Lab1.Top ;
       Lab2.Left := EditNumberApt.Left + EditNUmberapt.width + HDelim;
       Lab2.Caption := '¹ ñâ. î ðîæä.'+#13+'ðåáåíêà';
       Lab2.Parent := Form;

       EditNumberBirthCertif := TEdit.create(Form);
       EditNumberBirthCertif.Top := Lab1.Top;
       EditNumberBirthCertif.Left := Lab2.Left + Lab2.width + hdelim ;
       EditNumberBirthCertif.Width := 50;
       EditNumberBirthCertif.parent := Form;

       Lab2 := TLabel.create(Form);
       Lab2.Top := Lab1.Top ;
       Lab2.Left := Editnumberbirthcertif.Left + editnumberbirthcertif.Width + HDelim;
       Lab2.Caption := '¹ êàðòû';
       Lab2.Parent := Form;

       EditNumberCard := TEdit.create(Form);
       EditNumberCard.Top := Lab1.Top;
       EditNumberCard.Left := Lab2.Left + Lab2.width + hdelim ;;
       EditNumberCard.Width := 50;
       EditNumberCard.parent := Form;

       Lab2 := TLabel.create(Form);
       Lab2.Top := Lab1.Top ;
       Lab2.Left := EditnUmbercard.Left + editnumbercard.Width + HDelim;
       Lab2.Caption := '¹ ÷åêà';
       Lab2.Parent := Form;

       EditNumberCAsh := TEdit.create(Form);
       EditNumberCash.Top := Lab1.top;
       EditNumberCash.Left := Lab2.Left + Lab2.width + hdelim ;
       EditNumberCash.Width := 50;
       EditNumberCash.parent := Form;


      Bevel1 := TBevel.create(Form);
      Bevel1.shape := bsTopLine;
      Bevel1.Height := 4;
      Bevel1.Width := Form.clientWidth - 30;
      Bevel1.Left := (Form.ClientWidth - Bevel1.Width) div 2;
      Bevel1.Top := EditNumberCash.Top + EditNumberCash.Height + HDelim * 2;
      Bevel1.parent := Form;

      Button1 := Tbutton.create(Form);
      Button1.Caption := 'Ok';
      Button1.Width := 70;
      Button1.ModalResult := mrOk;
      Button1.Top := Bevel1.Top + 13;
      button1.Default := true;
      Button1.Parent := Form;


      Button2 := Tbutton.create(Form);
      Button2.Caption := 'Îòìåíà';
      Button2.Width := 70;
      Button2.ModalResult := mrCancel;
      Button2.Top := Button1.top;
      Button2.left := Form.ClientWidth - Button2.Width - 35;
      Button2.Cancel := true;
      Button2.Parent := Form;

      Button1.left := Button2.left - Button1.width - 5;


      Form.clientHeight := Button1.Top + Button1.height + 15;

      taOrg.open;
      taOrgadv.open;

      if not taorg.findkey([ID])
      then
          CreateHint('Êîä '+inttostr(ID)+ ' íå íàéäåí â ñïðàâî÷íèêå êîíòðàãåíòîâ')
      else
      begin
        EditFIO1.text := getadvValue(ID,'FIO1');
        EditFIO2.text := getadvValue(ID,'FIO2');
        EditFIO3.text := getadvValue(ID,'FIO3');

        EditAdres_o.Text := GetAdvValue(ID,'ADDRESS_O');
        EditAdres_r.Text := GetAdvValue(ID,'ADDRESS_R');
        EditAdres_g.Text := GetAdvValue(ID,'ADDRESS_G');
        EditAdres_u.Text := GetAdvValue(ID,'ADDRESS_U');
        EditAdres_em.Text := GetAdvValue(ID,'ADDRESS_EM');
        EditAdres_ind.Text := GetAdvValue(ID,'ADDRESS_IND');
        EditAdres_ND.Text := GetAdvValue(ID,'ADDRESS_ND');
        EditAdres_KV.Text := GetAdvValue(ID,'ADDRESS_KV');
        EditAdres_TEL.Text := GetAdvValue(ID,'ADDRESS_TEL');

        EditSot.ItemIndex := EditSot.items.indexof(GetAdvValue(ID,'OPERATOR_SOT'));
        EditFreq.Itemindex := EditFreq.items.indexof(GetAdvValue(ID,'FREQ'));
        EditCAUSE.Itemindex := EditCause.items.indexof( GetAdvValue(ID,'CAUSE'));
        EditWAY.ItemIndex := EditWay.items.indexof(GetAdvValue(ID,'WAY'));
        EditPOINTS.VAlue := strtointprotected( GetAdvValue(ID,'POINTS'));
        EditGetInfo.ItemIndex := EditGetInfo.items.IndexOf(GetAdvValue(ID,'GETINFO'));

        EditNumberApt.Text := getadvValue(ID,'NUMBERAPT');
        EditNumberCard.Text := getadvValue(ID,'NUMBERCARD');
        EditNumberCASH.Text := getadvValue(ID,'NUMBERCASH');
        EditNumberBirthCertif.Text := getadvValue(ID,'NUMBERBIRTHCERTIF');



        DT := StrToDateProtected(getadvvalue(id,'BIRTHDAY'));
        if DT <>0
        then begin
          EditBD_D.Value := dayof(dt);
          EditBD_M.VAlue := monthof(dt);
          Editbd_y.value := yearof(dt);
        end;

        while Form.Showmodal = mrOk do
        begin

          if not taorg.findkey([ID])
          then
              CreateHint('Êîä '+inttostr(ID)+ ' íå íàéäåí â ñïðàâî÷íèêå êîíòðàãåíòîâ')
          else
          begin
            SetAdvValue(ID,'FIO1',EditFio1.text);
            SetAdvValue(ID,'FIO2',EditFio2.text);
            SetAdvValue(ID,'FIO3',EditFio3.text);


            taOrg.Edit;
            taorg.fieldbyname('name').asstring := trim(trim(EditFio1.text + ' '+ EditFio2.text) + ' '+ EditFio3.TExt);
            taorg.post;

            if (EditBD_D.VAlue<>0) and (EditBD_M.VAlue <> 0)  and (EditBD_Y.VAlue <> 0)
            then    SetAdvValue(ID,'BIRTHDAY',formatdatetime('dd.mm.yyyy',encodedate(editbd_y.value,editbd_m.value,editbd_d.value)))
            else    SetAdvValue(ID,'BIRTHDAY','');


            SetAdvValue(ID,'ADDRESS_O',EditAdres_o.text);
            SetAdvValue(ID,'ADDRESS_R',EditAdres_r.text);
            SetAdvValue(ID,'ADDRESS_G',EditAdres_g.text);
            SetAdvValue(ID,'ADDRESS_U',EditAdres_u.text);
            SetAdvValue(ID,'ADDRESS_EM',EditAdres_em.text);
            SetAdvValue(ID,'ADDRESS_IND',EditAdres_ind.text);
            SetAdvValue(ID,'ADDRESS_ND',EditAdres_ND.text);
            SetAdvValue(ID,'ADDRESS_KV',EditAdres_kv.text);
            SetAdvValue(ID,'ADDRESS_TEL',EditAdres_TEL.text);




            StrValue := '';
            if editsot.itemindex>=0
            then StrValue := EditSot.items[Editsot.itemindex];

            SetAdvValue(ID,'OPERATOR_SOT',StrValue);

            strVAlue := '';
            if editfreq.itemindex>=0
            then  StrVAlue := editFreq.items[Editfreq.itemindex];

            SetAdvValue(ID,'FREQ',StrValue);

            StrValue := '';
            if editCAuse.itemindex>=0
            then  StrVAlue := editCAuse.items[EditCause.itemindex];

            SetAdvValue(ID,'CAUSE',StrValue);

            StrValue := '';
            if editWay.itemindex>=0
            then  StrVAlue := editWay.items[EditWay.itemindex];
            SetAdvValue(ID,'WAY',StrValue);


            SetAdvValue(ID,'POINTS',inttostr(EditPoints.value));

            StrValue := '';
            if editGetINFO.itemindex>=0
            then  StrVAlue := editGetINFO.items[EditGETINFO.itemindex];

            SetAdvValue(ID,'GETINFO',StrValue);

            SetAdvValue(ID,'NUMBERAPT',EditNUmberApt.text);
            SetAdvValue(ID,'NUMBERCARD',EditNUmberCard.text);
            SetAdvValue(ID,'NUMBERCASH',EditNUmberCash.text);
            SetAdvValue(ID,'NUMBERBIRTHCERTIF',EditNUmberBIRTHCERTIF.text);


            bdeflush;
            break
          end;
        end;
      end;

     finally
       Form.free
     end;




   finally
     taOrg.free;
     taOrgadv.free
   end

end.
