SIGN UP MEMBER LOGIN:    
ARTICLE

Meal Scheduler in C#

Posted by Maheswara Rao Articles | Windows Services in C# May 04, 2000
In this application once you enter your meal timings. A message box will appear on the screen while you are working and remember you about your meal with light sound.
Reader Level:

Hi.....

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 name 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 remember you about your meal with light sound.

How to install?

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 name box enter your name (pet name). In breakfast, lunch and dinner boxes enter your meal timings. (Your meal timings after 1pm add 12hr. your lunch time 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
 you data. That's all......

open source
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; .....
//constructor
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=" ";
//events
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(); }

File: 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
[sysimport(dll="winmm.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(;;)
{
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
reakfast","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());
else
s+=":"+m+":"+ (ss<10 ? "0"+ss.ToString() : ss.ToString());
return s; }
//starting thread
public static void Main(String[] a)
{
try
{
secThread.Start();
}
catch (Exception e)
{Console.WriteLine( e.ToString());}
}

Remarks

It doesn't check milliseconds and system should have .net framework for this application.

Login to add your contents and source code to this article
share this article :
post comment
 

I would like know the coding required for writing a windows service in C#.net 2005 for transferring data from Informix database to oracle database for every 1 hour. I also want to maintain a seperate event log for this service.

Posted by James Kennedy Feb 20, 2008
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Gauge for SharePoint
Become a Sponsor