From 68de7c2f96b252a21eb358259bd5acbc73c17965 Mon Sep 17 00:00:00 2001
From: angelo <angelo@c028cbd2-c16b-5b4b-a496-9718f37d4682>
Date: Sat, 23 Dec 1995 12:14:50 +0000
Subject: [PATCH] Aggiunto metodo TForm::reread() per rileggere una sezione.
 Aggiunto metodo TPrint_section::destroy_fields() per rimuovere tutti i campi.

git-svn-id: svn://10.65.10.50/trunk@2356 c028cbd2-c16b-5b4b-a496-9718f37d4682
---
 include/form.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/form.h   |  4 +++-
 2 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/include/form.cpp b/include/form.cpp
index e0a2d22b9..fd8266abc 100755
--- a/include/form.cpp
+++ b/include/form.cpp
@@ -2909,6 +2909,65 @@ TPrint_section& TForm::section(char s, word pagenum)
   return section(s, pt);
 }
 
+bool TForm::reread(char sec, pagetype p)
+{
+  TPrint_section* s = exist(sec,p);
+  bool ok = FALSE;
+  if (s != NULL)
+      for (word j = 0; j < s->fields(); j++)
+        ok |= s->field(j).dirty();
+  if (s != NULL && ok)
+  {
+    s->destroy_fields();  // Distrugge tutti gli items...
+    // ...si posiziona nel file sorgente alla sezione opportuna...
+    TFilename n(_name); n.ext("frm");
+    TScanner scanner(n);
+    bool ok = FALSE;
+    while (!ok)
+    {
+      while (TRUE)     // ...scans searching for a section...
+      {
+        const TString& key = scanner.popkey();
+        if (key == "SE" || key == "") // ..if section or end of file...
+          break;
+      }
+      const char   secr = scanner.popkey()[0];             // Section name (GRAPH, HEAD, BODY, FOOT)
+      if (secr=='\0') break;
+      const pagetype pr = char2page(scanner.popkey()[0]);  // Section type (odd, even, first, last)
+      if (secr==sec && pr==p) ok = TRUE;  // L'ha trovata...
+    }
+    // ...riesegue la parse della sezione leggendo dal file sorgente
+    if(ok && s->parse(scanner))
+    {                          
+     // Legge le modifiche su archivio e poi e' finita.
+      s->set_dirty(FALSE);
+      TLocalisamfile rprof(LF_RFORM); 
+      const char sez[3] = {sec,p+'0','\0'};
+      rprof.zero();
+      rprof.put("TIPOPROF", _name);
+      rprof.put("CODPROF", _code);
+      rprof.put("SEZ", sez);
+      const TRectype filter(rprof.curr());
+                    
+      for (int err = rprof.read(_isgteq); err == NOERR && rprof.curr() == filter; err = rprof.next())
+      {              
+        const short id = rprof.get_int("ID");
+                      
+        if (id == 0)
+        {
+          TPrint_section& se = section(sec, p);
+          se.read_from(rprof.curr());
+        }
+        else
+        {
+          TForm_item& item = find_field(sec, p, id);
+          item.read_from(rprof.curr());
+        }
+      }              
+    }
+  }             
+  return ok;
+}
                             
 // ===========================================                            
 // TForm                                      
diff --git a/include/form.h b/include/form.h
index 4ad67a4e2..e894d2e4b 100755
--- a/include/form.h
+++ b/include/form.h
@@ -171,7 +171,8 @@ public:
   void change_date_format(const char* f);                     
   // cambia il formato di tutti i numeri nel form                                          
   void change_number_format(int w, int dec, const char* p);                     
-                       
+  // Rilegge la sezione specificata
+  bool reread(char sec, pagetype p);
   // editor interface
   TForm_editor& editor() const;
   
@@ -253,6 +254,7 @@ public:
   TForm_item& field(int n) const { return (TForm_item&)_item[n]; }
   TForm_item& find_field(short id) const;
   void        destroy_field(int n) {  _item.destroy(n, TRUE);  }
+  void        destroy_fields() { _item.destroy(); }
   void        change_field(int n, TForm_item* f);
   void        insert_field(int n, TForm_item* f);                 
   void        add_field(TForm_item* f);