// =====================================================================================
// Copyright © 2005 by . All rights are reserved.
//
// If you like this code then feel free to go ahead and use it.
// The only thing I ask is that you don't remove or alter my copyright notice.
//
// Your use of this software is entirely at your own risk. I make no claims or
// warrantees about the reliability or fitness of this code for any particular purpose.
// If you make changes or additions to this code please mark your code as being yours.
//
// website , email OmarALZabir@gmail.com, msn oazabir@hotmail.com
// =====================================================================================
#region Using directives
using System;
using System.ComponentModel;
using System.Collections;
using System.Xml.Serialization;
#endregion
namespace SmartInstitute
{
///<summary>
/// An object representation of the 'SectionRoutine' table. [No description for this table in the database]
///</summary>
/// <remarks>
/// Inherits from the <see cref="SectionRoutineBase"/> class.
/// Sorting and interfaces implementations are part of the <see cref="SectionRoutineBase"/> class.
/// Only custom implementations are done in this class.
/// </remarks>
[Serializable]
public class SectionRoutine : SectionRoutineBase
{
///<summary>
/// Creates a new <see cref="SectionRoutine"/> instance.
///</summary>
public SectionRoutine() : base()
{
}
///<summary>
/// Creates a new <see cref="SectionRoutine"/> instance.
///</summary>
///<param name="ID"></param>
///<param name="SectionID"></param>
///<param name="StartTime"></param>
///<param name="EndTime"></param>
///<param name="ClassType"></param>
///<param name="ChangeStamp"></param>
public SectionRoutine(System.Int32 ID, System.Int32 SectionID, System.Int32 StartTime, System.Int32 EndTime, System.Int32 ClassType, System.DateTime ChangeStamp) : base( ID, SectionID, StartTime, EndTime, ClassType, ChangeStamp)
{
}
[Flags]
public enum TypeEnum
{
Theory = 1,
Lab = 2
}
[XmlAttribute("ctE")]
public TypeEnum Type
{
get
{
return (TypeEnum)base.ClassType;
}
set
{
base.ClassType = (int)value;
}
}
public override string ToString()
{
return ToDateTime( this.StartTime ) + "-" + ToDateTime( this.EndTime );
}
private static readonly string [] _Days = { "Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri" };
private static readonly DayOfWeek [] _DayOfWeek = {
DayOfWeek.Saturday,
DayOfWeek.Sunday,
DayOfWeek.Monday,
DayOfWeek.Tuesday,
DayOfWeek.Wednesday,
DayOfWeek.Thursday,
DayOfWeek.Friday };
public System.DayOfWeek GetDay()
{
return _DayOfWeek[ this.StartDay ];
}
public bool Overlap( SectionRoutine routine )
{
if( routine.StartTime >= this.StartTime && routine.StartTime < this.EndTime )
return true;
if( routine.EndTime > this.StartTime && routine.EndTime <= this.EndTime )
return true;
return false;
}
public int DayFromDayOfWeek( DayOfWeek day )
{
return ((int)day+1)%7;
}
public void SetStartTime( DayOfWeek day, int hour, int min )
{
SetStartTime( DayFromDayOfWeek( day ), hour, min );
}
public void SetEndTime( DayOfWeek day, int hour, int min )
{
SetEndTime( DayFromDayOfWeek( day ), hour, min );
}
public void SetStartTime( int day, int hour, int min )
{
this.StartTime = (day * 24 * 60) + (hour * 60) + min;
}
public void SetEndTime( int day, int hour, int min )
{
this.EndTime = (day * 24 * 60) + (hour * 60) + min;
}
public string ToStringStartTime()
{
return this.ToDateTime( this.StartTime ); //(StartHour % 12).ToString() + ":" + StartMinute.ToString() + ":00 " + (StartHour < 12 ? "AM" : "PM");
}
public string ToStringEndTime()
{
return this.ToDateTime( this.EndTime ); //(EndHour % 12).ToString() + ":" + EndMinute.ToString() + ":00 " + (EndHour < 12 ? "AM" : "PM");
}
public int StartDay
{
get
{
return StartTime / (60 * 24);
}
}
public int StartHour
{
get
{
return (StartTime / 60) % 24;
}
}
public int StartMinute
{
get
{
return (StartTime % 60);
}
}
public int EndDay
{
get
{
return EndTime / (60 * 24);
}
}
public int EndHour
{
get
{
return (EndTime / 60) % 24;
}
}
public int EndMinute
{
get
{
return (EndTime % 60);
}
}
private string ToDateTime( int time )
{
int day = time / (60 * 24);
int hour = (time / 60) % 24;
int min = (time % 60);
return _Days[ StartDay ] + " " + (hour > 12 ?
(hour-12).ToString() + ":" + min.ToString() + " PM" :
hour.ToString() + ":" + min.ToString() );
}
}
}