SIMS 7 - Attendance Change Tracking Simplified Example
Switching to session attendance change tracking is important because it drastically reduces call volumes for TIs and makes it viable to get more frequent refreshes than might be reasonable via other methods.
Session Attendance Change Tracking does not need Data Change Tracking turned on in SIMS to work.
Starting point for the example is a c# console application on Framework 4.7.2.
For huge schools, an alternative version by registration group is described here.
Sample code, click here.
The main application is
using System;
using System.IO;
using System.Xml;
namespace Change_Tracked_Attendance
{
internal class Program
{
// Based on standard training data
public static string Database = "WelshGA";
public static string Server = ".";
public static string User = "Blacka";
public static string Password = "Pa$$w0rd";
public static DateTime Start = DateTime.Now.AddYears(-1);
public static DateTime End = DateTime.Now;
public static string OutputPath = @"c:\temp";
static void Main(string[] args)
{
SIMSInterface.SIMSDllResolution.AddSIMSDllResolution();
Remainder();
}
public static void Remainder()
{
if (SIMSInterface.LoginHelper.SIMSlogin(Server,Database,User,Password))
{
foreach (string y in SIMSInterface.Attendance.AttendanceYearGroups.Keys)
{
string fileName = Path.Combine(OutputPath, y + ".xml");
XmlDocument YearlyAttendance = SIMSInterface.Attendance.GetAttendanceForYearGroup(y, Start, End);
YearlyAttendance.Save(fileName);
}
XmlDocument Changes = SIMSInterface.Attendance.GetChangeAttendance(End.AddDays(-1));
Changes.Save(Path.Combine(OutputPath, "changes.xml"));
}
}
}
}
The use of SIMS Dll resolution as shown is always recommended.
It requires a SIMS Login.
The application then gets the set of year groups as follows:
private static Dictionary<string, int> _AttendanceYearGroups = new Dictionary<string, int>();
public static Dictionary<string,int> AttendanceYearGroups
{
get
{
if (_AttendanceYearGroups.Count == 0)
{
SIMS.Processes.GroupCache.Populate();
foreach (YearGroup y in SIMS.Entities.GroupCache.YearGroups)
{
_AttendanceYearGroups.Add(y.Code, y.ID);
}
}
return _AttendanceYearGroups;
}
}
using the group cache.
It keeps the volume of initial marks down by getting the year of marks per year group.
private static Dictionary<string, int> _AttendanceRegGroups = new Dictionary<string, int>();
public static Dictionary<string, int> AttendanceRegGroups
{
get
{
if (_AttendanceRegGroups.Count == 0)
{
SIMS.Processes.GroupCache.Populate();
foreach (RegistrationGroup r in SIMS.Entities.GroupCache.RegistrationGroups)
{
_AttendanceRegGroups.Add(r.Code, r.ID);
}
}
return _AttendanceRegGroups;
}
}
We can then simply iterate through the groups and get the base line attendance marks making the call below, both Year and Reg group coding is shown.
public static XmlDocument GetAttendanceForYearGroup(string YearGroup, DateTime Start, DateTime End)
{
XmlDocument doc = null;
int SampleGroup = -1;
if (AttendanceYearGroups.TryGetValue(YearGroup, out SampleGroup))
{
doc = GetAttendanceForGroup(SampleGroup, Start, End);
}
return doc;
}
public static XmlDocument GetAttendanceForGroup(int GroupId, DateTime Start, DateTime End)
{
SIMS.Processes.TPAttendanceRead ATR = new SIMS.Processes.TPAttendanceRead();
// XML Document needed to get the codes
XmlDocument doc = new System.Xml.XmlDocument();
// This is the actual call to get the codes
doc.InnerXml = ATR.GetXmlSessionAttendancesExtended(0, GroupId, Start.Date, End);
return doc;
}
Finally, it is very simple to get what's changed from a given point in time
public static XmlDocument GetChangeAttendance(DateTime Start)
{
DateTime End = DateTime.Now;
XmlDocument d = new XmlDocument();
TPAttendanceRead tpar = new TPAttendanceRead();
d.InnerXml = tpar.GetXmlChangedSessionAttendancesInRange(Start, End);
return d;
}