Click here to Skip to main content
15,894,405 members
Articles / Programming Languages / C#

CooksMate

Rate me:
Please Sign up or sign in to vote.
3.32/5 (8 votes)
21 Jan 2008GPL32 min read 56.8K   1K   23  
A simple program to help get the timing of a roast dinner
/*
 * Created by SharpDevelop.
 * User: andy
 * Date: 26/12/2007
 * Time: 09:04
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Xml;

namespace uk.org.aspellclark.cooksmate.engine
{
	/// <summary>
	/// This enumeration contains the methods of cooking.
	/// this is used to display a picture depicting 
	/// how to do the next action
	/// </summary>
	public enum ActionStepType
	{
		Oven,
		Hob,
		Steamer
	};
	
	/// <summary>
	/// Description of ActionStep.
	/// </summary>
	public class ActionStep
	{		
		private int seqNbr;
		private string name;
		private int minsDuration;
		private int weightGrams;
		private int minsPerKilo;
		private int minsStanding;
		private bool done = false;
		private ActionStepType type;
		

		public bool Done
		{
			get { return done; }
			set { done = value;}
		}
		public ActionStepType Type
		{
			get {return type;}
			set {type=value;}
		}
		public string TypeString
		{
			set {
				switch (value.ToLower())
				{
					case "hob":
					{
						type=ActionStepType.Hob;
						break;
					}
					case "steamer":
					{
						type=ActionStepType.Steamer;
						break;
					}
					case "oven":
					{
						type=ActionStepType.Oven;
						break;
					}
				}
			}
		}
		public int SequenceNbr
		{
			get {return seqNbr;}
			set {seqNbr=value;}
		}
		public string Name
		{
			get {return name;}
			set {name=value;}
		}
		public int MinsDuration
		{
			get {
					if ( minsDuration > 0)
					{
						return minsDuration;
					}
					else
					{
						int mins  = (int)(MinsPerKilo * WeightKg);
						mins += MinsStanding;
						return mins;
					}
				}
			set {minsDuration=value;}
		}
		public double WeightKg
		{
			get {return (double)weightGrams/1000;}
		}
		public int WeightGrams
		{
			get {return weightGrams;}
			set {weightGrams=value;}
		}
		public int MinsPerKilo
		{
			get {return minsPerKilo;}
			set {minsPerKilo=value;}
		}
		public int MinsStanding
		{
			get {return minsStanding;}
			set {minsStanding=value;}
		}
		
		public DateTime StartTime(DateTime serveTime)
		{
			DateTime start = serveTime;
			int days=0;
			int hrs=0;
			int mins=this.MinsDuration;
			int secs=0;
			if (mins==0)
			{
				mins  = (int)(MinsPerKilo * WeightKg);
				mins += MinsStanding;
			}
			start = start - new TimeSpan(days, hrs, mins, secs);
			return start;
		}

		
		public ActionStep()
		{}

		#region XMLCode

		/// <summary>
		/// This constructor reads in it's contained
		/// information from an xml file
		/// </summary>
		/// <param name="reader"></param>
		public ActionStep(XmlReader reader)
		{
			while (reader.Read())
			{
				switch (reader.NodeType)
				{
					case XmlNodeType.EndElement:
						if (reader.Name.Equals(Constants.XML_TAG_ACTION))
						{
							return;
						}
						break;
					case XmlNodeType.Element:
						if (reader.Name.Equals(Constants.XML_TAG_NAME))
						{
							reader.Read();
							this.Name = reader.Value;
						}
						else if (reader.Name.Equals(Constants.XML_TAG_MINSDURATION))
						{
							reader.Read();
							this.MinsDuration = Convert.ToInt16(reader.Value);
						}
						else if (reader.Name.Equals(Constants.XML_TAG_TYPE))
						{
							reader.Read();
							this.TypeString = reader.Value;
						}
						else if (reader.Name.Equals(Constants.XML_TAG_MINSPERKILO))
						{
							reader.Read();
							this.MinsPerKilo = Convert.ToInt16(reader.Value);
						}
						else if (reader.Name.Equals(Constants.XML_TAG_MINSSTANDING))
						{
							reader.Read();
							this.MinsStanding = Convert.ToInt16(reader.Value);
						}
						else if (reader.Name.Equals(Constants.XML_TAG_WEIGHTGRAMS))
						{
							reader.Read();
							this.WeightGrams = Convert.ToInt16(reader.Value);
						}
						break;
				}//switch
			}//while
		}
		

		/// <summary>
		/// this method write the current step out to an xml file
		/// </summary>
		/// <param name="xmlWriter"></param>
		public void WriteToXml(XmlWriter xmlWriter)
		{
            xmlWriter.WriteStartElement(Constants.XML_TAG_ACTION);

            xmlWriter.WriteElementString(Constants.XML_TAG_NAME, this.Name);
            xmlWriter.WriteElementString(Constants.XML_TAG_SEQ_NBR, this.SequenceNbr.ToString());
            xmlWriter.WriteElementString(Constants.XML_TAG_TYPE, this.Type.ToString());
            xmlWriter.WriteElementString(Constants.XML_TAG_MINSDURATION, this.MinsDuration.ToString());
            xmlWriter.WriteElementString(Constants.XML_TAG_MINSPERKILO, this.MinsPerKilo.ToString());
            xmlWriter.WriteElementString(Constants.XML_TAG_MINSSTANDING, this.MinsStanding.ToString());
            xmlWriter.WriteElementString(Constants.XML_TAG_WEIGHTGRAMS, this.WeightGrams.ToString());

            xmlWriter.WriteEndElement();
		}		
		
		#endregion
		
		public string ToString()
		{
            return String.Format("{0}, ({1:d})", 
        	                     this.name,
        	                     this.MinsDuration);
        }
		public string ToString(DateTime srveTime)
		{
            return String.Format("{0}, {1:d}", 
        	                     this.name,
        	                     this.StartTime(srveTime));
        }

	}//class
}//namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior) Airbus Defense and Space
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions