Hi.....
My name is Mahesh I am working as a developer in CMS Jamshedpur (India). While I sit in front of my system I tend to forget my meals and I guess there must be many of them like me. For the benefit of such people, I developed an application named MAA...(Who takes care of your health) this is my first application using C#.
What does the code do?
In this application once you enter your meal timings. A message box will appear on the screen while you are working and remind you about your meal with a light sound.
How to install it?
Application has 2 files maa.exe and settime.exe. Copy maa.exe to the startup folder and execute settime.exe. set time box will appear.
![maa.exe]()
In the name box enter your name (pet name). In breakfast, lunch and dinner boxes enter your meal timings.
(Your meal timings after 1 pm add 12. your lunchtime 1:30 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; your data. That's all......
Open source: set time.cs
using System;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using System.Data;
using System.Threading;
public class SetTime : Form
{
private Label Name = null;
private TextBox Name1 = null;
public SetTime()
{
Name = new Label();
Name.Text = "Name:";
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 = " ";
// Other components initialization...
// Events
ok.Click += new System.EventHandler(Ok_Click);
Cancel.Click += new System.EventHandler(Ok_Click);
Clear.Click += new System.EventHandler(Ok_Click);
}
public void Ok_Click(object sender, EventArgs arg)
{
if (sender.Equals(ok))
{
string s = null;
StreamWriter sw = null;
try
{
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();
}
}
}
}
public class TimeChecker
{
private static Thread secThread = new Thread(new ThreadStart(CheckTime));
[System.Runtime.InteropServices.DllImport("winmm.dll")]
public static extern long PlaySound(string lpszName, long hModule, long dwFlags);
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++;
}
// Other code...
// Checking every minute
for (;;)
{
Thread.Sleep(1000);
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..", MessageBoxButtons.OK | MessageBoxIcon.Question);
}
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
public static string FormatDate()
{
int m = DateTime.Now.Minute;
int ss = DateTime.Now.Second;
string s = DateTime.Now.Hour.ToString();
if (m < 10)
s += ":0" + m + ":" + (ss < 10 ? "0" + ss.ToString() : ss.ToString());
else
s += ":" + m + ":" + (ss < 10 ? "0" + ss.ToString() : ss.ToString());
return s;
}
public static void Main(string[] a)
{
try
{
secThread.Start();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
Remarks
It doesn't check milliseconds and the system should have a .net framework for this application.
This application is dedicated to my parents.