3

I am a student and working on winform c#. I have a small app and I want to add a new feature of memo reminder. For example, when I type something in a text box, the app saves it and set a timer of 8 hours. If the app is running, then a message should popup with the message I have saved.

It's not clear to me if I should use a database for reminding the entries or something else provided by c#. As far as I know all thing are automated. Is there anything which will help me to build this functionality, like a timer??

Fls'Zen
  • 4,594
  • 1
  • 29
  • 37
aquib Rocks
  • 113
  • 1
  • 11
  • 1
    How are you storing your reminders - in a database table? – mbeckish Mar 20 '13 at 16:23
  • 1
    Have you tried looking for `timer` on MSDN? – O. R. Mapper Mar 20 '13 at 16:24
  • You could start a background thread and tell it to run that thread for a provided time and int the `runworkercompleated` you could show a message box. Kinda brute force but it might work. – DROP TABLE users Mar 20 '13 at 16:25
  • 2
    What happens if you close the app now, and open it again. Shall it honor previous reminder? – Yahya Mar 20 '13 at 16:26
  • Seeing as you are just learning, you need to consider which data source you find easier to use. XML? SQL? – LukeHennerley Mar 20 '13 at 16:28
  • @LukeHennerley i know sql server and i am going to use that. can you help me? – aquib Rocks Mar 20 '13 at 16:39
  • @Yahya i when restart the app it just gives the expiration message that the notification is expired if the time is gone and if the time is remaining then it will be same as the previous reminders – aquib Rocks Mar 20 '13 at 16:42
  • @aquibRocks I have posted a simple flow, if that helps. See the answers below. – Yahya Mar 20 '13 at 16:53
  • Database vs Local File Pro/Con: Database gives you strongly-typed data (pro) and memos can follow around the user, not the machine (pro), but to use the app requires a network connection (possible con) and increases complexity of the solution (i.e., maintaining a DB; con). Local file is a standalone, no network, solution (possible pro), but requires parsing the data yourself (con, but can be made easier by many pre-existing parsers, like for XML). – Mike Guthrie Mar 20 '13 at 16:59

2 Answers2

4

Store somewhere in the txt file if using database is not possible. Like this:

3.20.2013 11:20:00 | Remind me something.

Then your timer checks every minute or so.

UPDATE:

Example:

DateTime savedTime = Convert.ToDateTime("date from the text file");
if(DateTime.Now >= savedTime)
{
     MessageBox.Show("reminder from the text file");
}

UPDATE2:

string pathToStoreTXT = Application.UserAppDataPath;

pathToStoreTXT has the path something like: "C:\Users\UserName\AppData". Your timer need's to check for that folder all the time. Name your txt file like "MyReminders.txt".

Mike Guthrie
  • 4,029
  • 2
  • 25
  • 48
Dilshod
  • 3,189
  • 3
  • 36
  • 67
  • 1
    +1 low tech solution. – DROP TABLE users Mar 20 '13 at 16:31
  • sir but how that can be possible that timer will check only the date and time part???? – aquib Rocks Mar 20 '13 at 16:41
  • @aquibRocks `DateTime.Parse(string.Split('|')[0])`. Obviously there's more to it than that, but if you are not yet skilled at file parsing, then do a web search first, then ask any specifics you don't understand. – Mike Guthrie Mar 20 '13 at 16:47
  • sir sir. one more question. i have to save the text file in the hard drive? the how can i locate the location in the timer to find the file in that specific folder? – aquib Rocks Mar 20 '13 at 16:52
  • @aquibRocks If you want to go with local file, I'd recommend either `Application.ExecutablePath` or `Application.UserAppDataPath` then just append your static filename, like `Application.UserAppDataPath + "\\WhateverNameIGiveMyFile.txt"` – Mike Guthrie Mar 20 '13 at 16:55
  • sir what is this?? what is this known as? first can you tell me i am not a prefessional programmer which knows every thing. i have just started c# sorry but i cant understand what you are telling can you please elaborate – aquib Rocks Mar 20 '13 at 16:59
0

Simple flow would be:

  1. When app is run, check if file is created or not. This file will store your data!
  2. Check if there is any record in the file or not. 2a. Show expired messages and clear them too.
  3. Add timer like Dilshod has suggested. 3a. Convert reminder datetime as timestamp and concatenate it with message to store in text file
  4. Create at a timer object with tick event every 1 minute, something like this. (Obviously you will need to set frequency which is passed as parameter)
Yahya
  • 3,386
  • 3
  • 22
  • 40
  • sir this is the suggestion that, the fucntion should be like this or like that. but how can i achive this?? how can i check that file?? you are telling to create a text file for all the reminders and updating the text file??? means that no one textfile or each reminder?? – aquib Rocks Mar 20 '13 at 16:56
  • One text file to store all reminders. Simple thing is to breakdown your problem first. Try learning how timer works in C# first. And then take it to next step. – Yahya Mar 20 '13 at 16:58
  • Stackoverflow is to solve your problems, not to teach you coding unfortunately! – Yahya Mar 20 '13 at 16:59
  • sir i know how timer works. it have a tick event but how can i save the file?? and update the file if the file is created?? can you help me in that? – aquib Rocks Mar 20 '13 at 17:03
  • @aquibRocks http://www.csharp-station.com/howto/readwritetextfile.aspx – Yahya Mar 21 '13 at 09:25