Προς το περιεχόμενο

Save Data


ntaryl

Προτεινόμενες αναρτήσεις

Δημοσ.

καλησπερα

Παιδια θελω βοηθεια (visual basic)

Επισυναπτω ενα μικρο παραδειγμα στο οποιο οταν ο χρηστης το ανοιγει να μπορει να εισαγει δεδομενα μεσα στο text,checkbox,option box .

οταν ομως η φορμα κλρινρι να κραταει τα δεομενα ετσι ωστε την επομενη φορα που θα την ξανα ανοιξει να εχει κρατησει τα δεομενα απο την τελευταια φορα

ευχαριστω πολυ

save_data.zip

Δημοσ.

Θα πρέπει πριν κλείσεις τη φόρμα να τα κρατάς σε ένα αρχείο, το οποίο και θα διαβάζεις κάθε φορά που ανοίγει η φόρμα.

Επί τη ευκαιρία, γιατί ασχολείσαι με VB6;

Η VB 2008 είναι πολύ ανώτερη, και είναι δωρεάν. Δες εδώ

http://www.microsoft.com/express/vb/default.aspx

  • 3 εβδομάδες αργότερα...
Δημοσ.

Αν μπορείτε γράψτε και ένα παράδειγμα κώδικα πως θα μπορούσε να γίνει αυτό. Με ενδιαφέρει αρκετά και θα ήταν και πιο ολοκληρωμένο το θέμα έτσι για τους επόμενους ενδιαφέροντες. Ευχαριστώ

Δημοσ.

Download

 

εχω ενα dll το οποιο γραφει/διαβαζει διαφορα property σε ενα ini file

Εχει μια κλαση η οποια εχει 3 μεθοδους

1)AddNewProperty(string PropNAme,string PropValue,string FileName)

2)ReadProperty(string PropName,PropFile) return value

3)UpdateProperty(string OldProp,string NewProp,string FileName)

 

η κλαση δεν ειναι static

Δημοσ.

Ευχαριστω πολυ

Καλο απογευμα

 

 

-----Προστέθηκε 27/9/2008 στις 07 : 55 : 24-----

 

 

Θα προτιμουσα να ποσταριζες και τον πηγαιο κωδικα

Το εκτελεσιμο δεν χρησιμευει σε κατι ?

ευχαριστω παντως

Δημοσ.
Ευχαριστω πολυ

Καλο απογευμα

 

 

-----Προστέθηκε 27/9/2008 στις 07 : 55 : 24-----

 

 

Θα προτιμουσα να ποσταριζες και τον πηγαιο κωδικα

Το εκτελεσιμο δεν χρησιμευει σε κατι ?

ευχαριστω παντως

Οταν βαλω νετ

αυτο το ειχα πρωχειρα (ποσταρω απο την ταξη του ECDL που εκανα και τελιοσα σημερα με επιτυχια :) )

Δημοσ.
Οκ

περιμενω τον πηγαιο

καλο σαβατοκυριακο

 

>using System;
using System.IO;
namespace IniWriterReader
{
   public class SaveAndLoadDataD:ReadWriteProp
   {
       private string[] strBuffer;
       private string PathFile;
       private string FileName;
       private string ExtesionFile;
       /// <summary>
       /// 
       /// </summary>
       /// <param name="pathFile">path of the file</param>
       /// <param name="extesionFile">extesion of the file</param>
       public SaveAndLoadDataD(string pathFile,string FileName,string extesionFile)
       {
           this.FileName = FileName;
           PathFile = pathFile;
           ExtesionFile = extesionFile;
       }
       /// <summary>
       /// Default settings, the extesion is *.ini and the path is the current directory
       /// </summary>
       public SaveAndLoadDataD()
       {
           PathFile = Environment.CurrentDirectory;
           ExtesionFile = ".ini";
       }
       private void WriteBufferedStreamInIniFile(string fileName, string[] buffer)
       {
           Stream s = File.Open(PathFile + @"\" + fileName + ExtesionFile, FileMode.Create);
           using (StreamWriter sr = new StreamWriter(s))
           {
               for (int i = 0; i < buffer.Length; i++)
               {
                   sr.WriteLine(buffer[i]);

               }
               sr.Close();
           }
           ClearBuffer();


       }
       public void AddNewProperty(string proName, string proValue, string fileName)
       {
           Stream s = File.Open(PathFile + "\\" + fileName + ExtesionFile, FileMode.Append);
           using (StreamWriter sw = new StreamWriter(s))
           {
               sw.WriteLine("\n" + proName + "=" + proValue);
               sw.Close();
           }
       }
       public void AddNewProperty(string proName, string proValue)
       {
           Stream s = File.Open(PathFile + "\\" + FileName + ExtesionFile, FileMode.Append);
           using (StreamWriter sw = new StreamWriter(s))
           {
               sw.WriteLine("\n" + proName + "=" + proValue);
               sw.Close();
           }
       }
       private string Replace(string proName, string proValue)
       {
           return proName + "=" + proValue;
       }
       public void UpdateIni(string propertyName, string propertyValueReplace)
       {
           //Load all file in buffer
           GetIniFileInBuffer(FileName);
           string oldProperty = "";
           for (int i = 0; i < strBuffer.Length; i++)
           {
               if (strBuffer[i].StartsWith(propertyName))
               {
                   oldProperty = strBuffer[i].Substring(propertyName.Length + 1);
                   strBuffer[i] = Replace(propertyName, propertyValueReplace);

               }
           }
           //Write updated buffer
           WriteBufferedStreamInIniFile(FileName, strBuffer);
       }
       private void CreateBuffer(int Lines)
       {
           strBuffer = new string[Lines];
       }
       private void ClearBuffer()
       {
           strBuffer = null;
           
       }
       private int CountStringLines(string FileName)
       {
           int counter = 0;
           using (StreamReader sr = File.OpenText(PathFile + "\\" + FileName + ExtesionFile))
           {
               while (sr.ReadLine() != null)
               {
                   counter++;
               }
               sr.Close();
           }
           return counter;
       }
       private void GetIniFileInBuffer(string FileName)
       {
           string str;
           int i = 0;
           CreateBuffer(CountStringLines(FileName));
           using (StreamReader sr = File.OpenText(PathFile + "\\" + FileName + ExtesionFile))
           {
               while ((str = sr.ReadLine()) != null)
               {
                   strBuffer[i] = str;
                   i++;

               }
               sr.Close();
           }
       }
       
       
       /// <summary>
       /// Get propery value from an exist ini file
       /// </summary>
       /// <param name="propertyName">Property name</param>
       /// <param name="FileName">Ini file name only "No extesion"</param>
       /// <returns>Property Value</returns>
       public string PropertyReader(string propertyName, string FileName)
       {
           using (StreamReader sr = File.OpenText(PathFile + @"\" + FileName + ExtesionFile))
           {
               string str;
               while ((str = sr.ReadLine()) != null)
               {
                   if (str.StartsWith(propertyName))
                   {
                       return str.Substring(propertyName.Length + 1);
                   }
               }
               sr.Close();
               return "NotExist";
           }
       }
       public string PropertyReader(string propertyName)
       {
           using (StreamReader sr = File.OpenText(PathFile + @"\" + FileName + ExtesionFile))
           {
               string str;
               while ((str = sr.ReadLine()) != null)
               {
                   if (str.StartsWith(propertyName))
                   {
                       return str.Substring(propertyName.Length + 1);
                   }
               }
               sr.Close();
               return "NotExist";
           }
       }
       public object PropertyReader(string propertyName, Types T)
       {
           using (StreamReader sr = File.OpenText(PathFile + @"\" + FileName + ExtesionFile))
           {
               string str;
               switch (T)
               {
                   case Types.BOOL:
                       {

                           while ((str = sr.ReadLine()) != null)
                           {
                               if (str.StartsWith(propertyName))
                               {
                                   if (str.Substring(propertyName.Length + 1) == "True" || str.Substring(propertyName.Length + 1) == "true"
                                       || str.Substring(propertyName.Length + 1) == "TRUE") { return true; }
                                   else { return false; }
                               }
                           }
                           sr.Close();
                           return "NotExist";

                       }

                   case Types.INT:
                       {
                           while ((str = sr.ReadLine()) != null)
                           {
                               if (str.StartsWith(propertyName))
                               {
                                   return Convert.ToInt32(str.Substring(propertyName.Length + 1));
                               }
                           }
                           sr.Close();
                           return "NotExist";
                       }

                   case Types.STRING:
                       {
                           while ((str = sr.ReadLine()) != null)
                           {
                               if (str.StartsWith(propertyName))
                               {
                                   return str.Substring(propertyName.Length + 1);
                               }
                           }
                           sr.Close();
                           return "NotExist";
                       }
                   case Types.DOUBLE:
                       while ((str = sr.ReadLine()) != null)
                       {
                           if (str.StartsWith(propertyName))
                           {
                               return Convert.ToDouble(str.Substring(propertyName.Length + 1));
                           }
                       }
                       sr.Close();
                       return "NotExist";
                   default:
                       {
                           return null;
                       }
               }
           }
       }


       #region ReadWriteProp Members

       public string ReadProp(string PropName)
       {
         return  PropertyReader(PropName);
       }

       public object ReadProp(string PropName, Types toReturn)
       {
           return PropertyReader(PropName, toReturn);
       }

       public void AddNewProp(string PropName, string PropValue)
       {
           AddNewProperty(PropName, PropValue);
       }

       #endregion
   }
   public interface ReadWriteProp{
       string ReadProp(string PropName);
       object ReadProp(string PropName, Types toReturn);
       void AddNewProp(string PropName, string PropValue);

   }
   public class SaveInXmlFile:ReadWriteProp
   {
       private System.Xml.XmlDocument xDoc;
       public SaveInXmlFile()
       {
           xDoc = new System.Xml.XmlDocument();
       }
       public void SaveDoc(System.Xml.XmlDocument xdoc)
       {
          
       }

       #region ReadWriteProp Members

       public string ReadProp(string PropName)
       {
           throw new NotImplementedException();
       }

       public object ReadProp(string PropName, Types toReturn)
       {
           throw new NotImplementedException();
       }

       public void AddNewProp(string PropName, string PropValue)
       {
           throw new NotImplementedException();
       }

       #endregion
   }
   public class SaveInBinFile : ReadWriteProp
   {
       #region ReadWriteProp Members

       public string ReadProp(string PropName)
       {
           throw new NotImplementedException();
       }

       public object ReadProp(string PropName, Types toReturn)
       {
           throw new NotImplementedException();
       }

       public void AddNewProp(string PropName, string PropValue)
       {
           throw new NotImplementedException();
       }

       #endregion
   }
   public enum Types {
       BOOL,
       INT,
       STRING,
       DOUBLE
   }

}

Δεν το εχω ολοκλιροσει. Το ini δουλεβει μια χαρα.

Αρχειοθετημένο

Αυτό το θέμα έχει αρχειοθετηθεί και είναι κλειστό για περαιτέρω απαντήσεις.

  • Δημιουργία νέου...