SIMS 7 - Cover Diary Sample Project
Introduction
This application is designed to show how the SIMS 7 cover diary can be accessed and modified. The UI is designed to facilitate the demo rather than to suggest good UI practice. The interfaces are simply sufficient to show principle and necessary information rather than elegance.
The code project will populate a given day's cover diary, allow for the creation of new cover activities, editing previous cover activities and closing of classrooms.
Click here to download.
Legal Bit
The download and use of the sample code is subject to terms and conditions of use and would require the distributor to register as a SIMS Partner and be subject to any charges which result from that partnership. Sample code may not be redistributed as code; however, permission is given to share the URL of this document and for the subsequent reader to download the code themselves subject to the same terms and conditions. This enables ESS to update the code samples and reduces the likelihood of bug propagation.
Loading the Cover Diary
The Cover diary is made of several parts, a Cover Day made from Activities, which hold assignments, in order to obtain the whole of a given days cover diary the sample code loops through each of these building a list of the periods both lessons and class closures that need covering.
foreach (SIMS.Entities.CovDiaryDayActivity dayActivity in covDiary.DayDiary.DayActivities)//This is the Covers on a given day
{
CoverItem cover = new CoverItem();
cover.StaffName = dayActivity.Resource.Description;
if (dayActivity.UnavailabilityAttribute.Count > 0)
{
cover.Reason = dayActivity.UnavailabilityAttribute[0].ReasonDescription;
Console.WriteLine(dayActivity.UnavailabilityAttribute[0].StartDate + " / " + dayActivity.UnavailabilityAttribute[0].EndDate);
}
else
{
}
cover.StaffCode = dayActivity.Resource.Code;
foreach (SIMS.Entities.CovDiaryActivity cov in dayActivity.Activities)// This is a Cover Period
{
cover.CoverItemID = cov.ID;
foreach (SIMS.Entities.CovDiaryAssignment diaryAssignment in cov.Assignments)// This is the details of a Cover Period
{
CoverActivity ca = new CoverActivity();
ca.PeriodID = diaryAssignment.ClassPeriodID;
ca.Period = Convert.ToString(diaryAssignment.StartTime.TimeOfDay);
ca.CoverActivityID = diaryAssignment.ID;
ca.FromStaffID = diaryAssignment.PersonId;
ca.FromStaffCode = dayActivity.Resource.Code;
ca.RoomID = diaryAssignment.RoomId;
if (diaryAssignment.CoverResource != null)
{
ca.ToStaffCode = diaryAssignment.CoverResource.Code;
}
else
{
ca.ToStaffCode = "Required";
}
cover.activities.Add(ca.CoverActivityID,ca);
if(tempConflict == true && iteration == 0)
{
ca.conflickExisted = true;
}
activities.Add(ca);
iteration++;
}
}
}
Creating a Cover Assignment
A Cover Assignment requires, a staff member, an absence reason, start and end date, it does not require an immediate resource be assigned to cover this session, as such the sample code brakes this process into two, on for creating the assignment and on for assigning a covering resource.
public static void createCover(Staff selectedStaff, Reason selectedReason,DateTime date)
{
// DateTime sould have correct time for Class Periods or else the Cover will display incorrectly
date = date.Date;//Zeros the time for use
DateTime end = date.AddHours(16.0);
DateTime start = date.AddHours(8.75);
SIMS.Entities.InformationDomainEnum infodomain = SIMS.Entities.InformationDomainEnum.CoverCommon;
SIMS.Entities.CovDiaryAbsenceClosure absenceClosure = new SIMS.Entities.CovDiaryAbsenceClosure(infodomain);
absenceClosure.Resource.ID = selectedStaff.StaffId;// staff id, drawn from combobox
absenceClosure.ReasonId = selectedReason.ReasonId; // reason for cover, drawn from combobox
absenceClosure.StartDate = start;
absenceClosure.EndDate = end;
absenceClosure.ExtendAbsence = false; // is extended absence
absenceClosure.ExternalID = ""; //autofilled
covRegister.CovDiaryAbsenceClosures.Add(absenceClosure);
covDiary.absenceXML = covRegister.GetSaveXML();
covDiary.Save();
}
public static void assignStaff(CoverActivity coverActivity, Staff selectedStaff)
{
SIMS.Entities.CovDiaryAssignments diaryAssignments = null;
SIMS.Entities.CovDiaryActivitys diaryActivitys = null;
SIMS.Entities.CovDiaryBaseResource covDiaryBase = null;
foreach(SIMS.Entities.CovDiaryStaff covStaff in covDiary.Staffs)
{
if(covStaff.ID == selectedStaff.StaffId)
{
covDiaryBase = covStaff;
}
}
foreach (SIMS.Entities.CovDiaryDayActivity dayActivity in covDiary.DayDiary.DayActivities)//This is the Covers on a given day
{
if (coverActivity.FromStaffCode == dayActivity.Resource.Code)
{
foreach (SIMS.Entities.CovDiaryActivity cov in dayActivity.Activities)// This is a Cover Period
{
if (coverActivity.PeriodID == cov.ClassPeriodId)
{
foreach (SIMS.Entities.CovDiaryAssignment diaryAssignment in cov.Assignments)// This is the details of a Cover Period
{
covDiary.AssignResource(diaryAssignment, cov, covDiaryBase, out diaryActivitys, out diaryAssignments);
covDiary.Save();
break;
}
break;
}
}
break;
}
}
}