A Meal Reminder In C#

Download all components of this program here – mealreminder.zip (106k)

What does the code do?
If you're a hardcore coder, you'll agree that it's easy to skip meals.
This program will remind you to eat meals. Of course, the point of this
program is to see how the code works, but hey, if it helps you to stay a
little healthier, then great!

How to install?
The application has 2 files maa.exe and settime.exe. Copy maa.exe to startup
folder and execute settime.exe.
set time box will appear..

In the name box enter your name. In breakfast, lunch and dinner boxes
enter your meal timings. (Your meal timings after 1pm add 12hr. For a lunch
time of 1:30pm, you should enter 13:30(12:00+1:30)). After entering your timings
click ok. This settime.exe will create one file that is storetime.txt for
storing you data. That's all……


//filename settime.cs
using System;
using System.WinForms;
using System.Drawing;
using System.IO;
using System.Data;

//inheriting Form class
public class settime:Form

//Initialize components
private Label Name=null;
private TextBox Name1=null;

public settime(){
Name=new Label();
Name.Size=new Size(50,20);
Name.Location=new Point(20,50);
Name1=new TextBox();
Name1.Location=new Point(100,50);
Name1.Size=new Size(100,1);
Name1.Text=" ";

ok.Click+=new System.EventHandler(ok_click);
Cancel.Click+=new System.EventHandler(ok_click);
Clear.Click+=new System.EventHandler(ok_click);

//buttons on_click method
public void ok_click(object sender,EventArgs arg){
if(sender.Equals(ok)) {
string s=null;
StreamWriter sw=null;
try {
//creating storetime.txt and storing data
sw=new StreamWriter("storetime.txt",false);
s=Name1.Text+"\n"+Breakfast1.Text+"\n"+Lunch1.Text+"\n"+Dinner1.Text; sw.WriteLine(s);
//closing the form
if(sender.Equals(Cancel)) { base.Dispose(); Application.Exit(); }
//End settime.cs

//Filename Maa.cs
using System;
using System.IO;
using System.Threading;
using System.WinForms;
using System.Data;

//create thread
private static Thread secThread=new Thread(new ThreadStart(checkTime));

//importing windows multimedia dll
public static extern long PlaySound(String lpszName, long hModule, long dwFlags);

//getting the data from storetime.txt
public static void checkTime() {
string [,]ss=new string[4,20];
try {
StreamReader sr=new StreamReader(new FileStream("storetime.txt",FileMode.Open,FileAccess.Read));
int c=0;
while(c<4) {
ss[c,c]=sr.ReadLine(); c++; }

//checking every minute
for(;;) {
if(formatDate().Equals((ss[1,1]+":00"))||formatDate().Equals((ss[1,1]+":05"))||formatDate().Equals((ss[1,1]+":10"))) {

//playing sound
PlaySound("notify.wav" ,0 ,0);
MessageBox.Show(ss[0,0]+"\n"+DateTime.Now.ToLongTimeString()+"\n"+"this is the time to your Breakfast","Dear..",MessageBox.OK|MessageBox.IconQuestion); }

//formatdate method
public static String formatDate() {
int m=DateTime.Now.Minute;
int ss=DateTime.Now.Second;
String s=DateTime.Now.Hour.ToString();Br> if(m<10)
s+=":0"+m+":"+ (ss<10 ? "0"+ss.ToString() : ss.ToString());
s+=":"+m+":"+ (ss<10 ? "0"+ss.ToString() : ss.ToString());
return s; }

//starting thread
public static void Main(String[] a) {
try {
}catch (Exception e)
{Console.WriteLine( e.ToString());} }
//End Maa.cs

It doesn't check milliseconds and system should have .net framework for this application.
I would like to hear from you…

Twitter Digg Delicious Stumbleupon Technorati Facebook Email

No comments yet... Be the first to leave a reply!