static void DoOldFileGenProcess(string daAcademicYear, string smsBaseQuarter, string outputFilePath) { int recordCharLength = 41; char[] buf = new char[recordCharLength]; InitBuffer(buf); using (var ctx = new SMSData.T200EXTRACTSDataContext()) { var q_enr = from sym in ctx.STU_YRQ_Ms join sd in ctx.STU_Ds on sym.SQ_SID equals sd.SID where sym.SQ_YRQ.CompareTo(smsBaseQuarter) >= 0 && sym.STU_QTR_STAT.Equals('A') && !sd.STU_PRG_ENR.Equals("") //do not include undeclared students. group sym by sym.SQ_SID into g_sid join sd2 in ctx.STU_Ds on g_sid.Key equals sd2.SID select new { sd2.SID, sd2.STU_NAME, STU_PRG_ENR = sd2.STU_PRG_ENR, }; using (var sw = new System.IO.StreamWriter(outputFilePath, false, Encoding.ASCII)) { foreach (var item in q_enr) { InitBuffer(buf); AddSid(item.SID, buf); AddName(item.STU_NAME, buf); AddEPC(item.STU_PRG_ENR, buf); AddAYR(daAcademicYear, buf); sw.Write(buf); } sw.Close(); } } }
/// <summary> /// /// </summary> /// <param name="baseYrq">The cohort of students will include any enrolled in the given </param> /// <param name="outputFilePath"></param> public void GenerateSD4006SFile(string baseYrq, string outputFilePath) { DateTime today = DateTime.Now; //first quarter that is not summer. var ctx = new SMSData.T200EXTRACTSDataContext(); var q_current_yrq_not_summer = (from y in ctx.YRQ_Ms where y.FIRST_DAY_YRQ.Value.CompareTo(today) <= 0 && !y.YRQ.Substring(3, 1).Equals("1") /* exclude summer */ orderby y.FIRST_DAY_YRQ descending select y.YRQ).First(); var q_cohort = from x in ctx.STU_YRQ_Ms where x.STU_QTR_STAT.Equals('A') && x.SQ_YRQ.CompareTo(baseYrq) >= 0 && !x.SQ_YRQ.Substring(3, 1).Equals("1") /* exclude summer */ group x by x.SQ_SID into g_x let maxYrq = g_x.Max(z => z.SQ_YRQ) join sym in ctx.STU_YRQ_Ms on new { A = g_x.Key, B = maxYrq } equals new { A = sym.SQ_SID, B = sym.SQ_YRQ } where !sym.STU_PRG_ENR.Equals("") join sd in ctx.STU_Ds on g_x.Key equals sd.SID into j_sd from sd in j_sd.DefaultIfEmpty() select new { SID = g_x.Key, MaxYRQ = maxYrq, EPC = sym.STU_PRG_ENR, StudentName = sd.STU_NAME, }; var q_quarter_list = from y in ctx.YRQ_Ms where !y.YRQ.Substring(3, 1).Equals("1") && !y.YRQ.Equals("Z999") && (y.YRQ.CompareTo(q_current_yrq_not_summer) <= 0) orderby y.YRQ descending select y.YRQ; var q_epc_history = (from x in q_cohort join sym in ctx.STU_YRQ_Ms on new { A = x.SID, B = x.EPC } equals new { A = sym.SQ_SID, B = sym.STU_PRG_ENR } where sym.STU_QTR_STAT.Equals("A") select new { sym.SQ_SID, sym.SQ_YRQ }).ToList(); var q_epc_stu_group = (from x in q_epc_history group x.SQ_YRQ by x.SQ_SID into g_x select new { SID = g_x.Key, Quarters = g_x.OrderByDescending(z => z).ToList() }).ToDictionary(z => z.SID, z => z.Quarters); //q_epc_stu_group.Dump(); string earliestYrq = null; List <AuditConfigRecord> acrList = new List <AuditConfigRecord>(); AuditConfigRecord acrTemp = null; foreach (var c in q_cohort) { //if the latest enrollment is not the current quarter then use the current quarter. if (!c.MaxYRQ.Equals(q_current_yrq_not_summer)) { earliestYrq = q_current_yrq_not_summer; } else { //check the yrq timeline until there is no match in the student data. return earliest YRQ found. earliestYrq = null; foreach (var yrq in q_quarter_list) { if (q_epc_stu_group[c.SID].Contains(yrq)) { earliestYrq = yrq; } else { //found the first non-match stop processing this student. //(earliestYrq + ":" + c.SID).Dump(); break; } } } acrTemp = new AuditConfigRecord() { AuditAYR = MapToAuditAYR(earliestYrq), AuditEPC = c.EPC, FullName = c.StudentName, MostRecentYRQEnrolledInEPC = c.MaxYRQ, SID = c.SID }; acrList.Add(acrTemp); } int recordCharLength = 41; char[] buf = new char[recordCharLength]; InitBuffer(buf); var sw = new System.IO.StreamWriter(outputFilePath, false, Encoding.ASCII); foreach (var acr in acrList) { InitBuffer(buf); AddSid(acr.SID, buf); AddName(acr.FullName, buf); AddEPC(acr.AuditEPC, buf); AddAYR(acr.AuditAYR, buf); sw.Write(buf); } sw.Close(); }