how to load/save this?

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2008
Posts: 47
Reputation: ctrl-alt-del is an unknown quantity at this point 
Solved Threads: 0
ctrl-alt-del ctrl-alt-del is offline Offline
Light Poster

how to load/save this?

 
0
  #1
Sep 21st, 2009
Hi all!

Well, the name isn't entirely accurate but since I have found it very hard to find some actual useful information on the topic I decided to name it as such.

Purely as a programming practice I would like to make a calendar application. Something along the lines of Rainlendar (brilliant piece of software).

It should save all my appointments and notes and ToDo things and what not.
But for that to work...

I need to be able to write all the information to my harddrive and load it again when the program is loaded again. Now I know the basics of FileStream, StreamWrite and StreamRead but I don't know how to use that with this kind of information.

I'm thinking of something along the lines of this for the lines in a simple .txt file (every type of file is fine by me by the way):
22-09-09, 12.30-14.00, Driving lessons, yes, 22-09-09, 11.00
The date of the appointment, the time, the text to display, whether and alarm should be activated, and then the date and time of that alarm.

But I don't have a clue how to implement something like this.

Is there anybody willing to hand me some pointers on this? It would really be greatly appreciated!
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 956
Reputation: DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough 
Solved Threads: 198
DdoubleD DdoubleD is offline Offline
Posting Shark

Re: how to load/save this?

 
0
  #2
Sep 21st, 2009
If the storage file does not need to be text, check out this IO Class: BinaryReader & BinaryWriter , which will simplify much of the data typing IO of your fields.

In addition, consider using the BinaryFormatter class:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Collections;
  6. using System.Runtime.Serialization.Formatters.Binary;
  7. using System.IO;
  8.  
  9. namespace TestSerializer
  10. {
  11. public class DataSerializer
  12. {
  13. [Serializable]
  14. public class Data : ArrayList
  15. {
  16. [Serializable]
  17. public struct Field
  18. {
  19. string s1;
  20. string s2;
  21. string s3;
  22. int i1;
  23. int i2;
  24. int i3;
  25.  
  26. public Field(string s1, string s2, string s3, int i1, int i2, int i3)
  27. {
  28. this.s1 = s1;
  29. this.s2 = s2;
  30. this.s3 = s3;
  31. this.i1 = i1;
  32. this.i2 = i2;
  33. this.i3 = i3;
  34. }
  35. }
  36.  
  37. public Data()
  38. {
  39. for (int i = 0; i < 100000; i++)
  40. {
  41. Field fld = new Field(
  42. "1 - Some Text " + i,
  43. "2 - Some Text " + i,
  44. "3 - Some Text " + i,
  45. i * 1,
  46. i * 2,
  47. i * 3
  48. );
  49.  
  50. Add(fld);
  51. }
  52. }
  53. }
  54.  
  55. public DataSerializer()
  56. {
  57. Data data = new Data();
  58.  
  59. BinaryFormatter bf = new BinaryFormatter();
  60. using (Stream stream = new FileStream("data.dat", FileMode.Create, FileAccess.Write))
  61. {
  62. bf.Serialize(stream, data);
  63. stream.Flush();
  64. stream.Close();
  65. }
  66.  
  67. Data dataRead;
  68. using (Stream stream = new FileStream("data.dat", FileMode.Open, FileAccess.Read))
  69. {
  70. dataRead = (Data)bf.Deserialize(stream);
  71. stream.Flush();
  72. stream.Close();
  73. }
  74. }
  75.  
  76. public static void Test()
  77. {
  78. DateTime dt = DateTime.Now;
  79. TimeSpan dtStart = dt.TimeOfDay;
  80.  
  81. DataSerializer ds = new DataSerializer();
  82.  
  83. dt = DateTime.Now;
  84. TimeSpan dtEnd = dt.TimeOfDay;
  85.  
  86. TimeSpan dtTotal = dtEnd - dtStart;
  87.  
  88. Console.WriteLine("DataSerializer Total Time: " + dtTotal);
  89. }
  90.  
  91. }
  92. }

Also, check out this thread using a DataSet with xml read/write: http://www.daniweb.com/forums/thread224213.html

There are so many ways you can do this--these are but a few...
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,995
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 294
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: how to load/save this?

 
0
  #3
Sep 21st, 2009
The date of the appointment, the time, the text to display, whether and alarm should be activated, and then the date and time of that alarm.
First, you should try to organize your info into a class or struct.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,328
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 600
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: how to load/save this?

 
0
  #4
Sep 21st, 2009
Once you have followed danny's recommendation and organized your members in to a class/struct you can use the XmlSerializer also to persist your class to disk.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,719
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 493
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: how to load/save this?

 
0
  #5
Sep 22nd, 2009
Reply With Quote Quick reply to this message  
Reply

Tags
load, save, stream

Message:


Thread Tools Search this Thread



Tag cloud for load, save, stream
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC