private void saveAttendance() { DojoMember member; string whereQuery; DojoAttendanceEntryManager aManager; DojoAttendanceEntryCollection attendance; int[] selectedClasses; string[] ids; bool removeEntry; bool formChanged; AttendanceScanner aScanner; // Load Member and set LastSignIn to present time member = new DojoMember(memberID); member.LastSignin = DateTime.Now; // Get classes on the attendance form. classIdArray = Context.Request.Form["___" + ClientID + "Classes"].Split(','); // Build query to get member's attendance for the classes on // the attendance form and get the memberTypeTemplates. whereQuery = "MemberID=" + member.iD; if (classIdArray.Length > 0) { whereQuery += " AND ("; for (int x = 0; x < classIdArray.Length; x++) { if (x == 0) { whereQuery += "ClassID=" + classIdArray[x] + " "; } else { whereQuery += "OR ClassID=" + classIdArray[x] + " "; } } whereQuery += ") "; } aManager = new DojoAttendanceEntryManager(); attendance = aManager.GetCollection(whereQuery, string.Empty, null); // Load selected classes from form. if (Page.Request.Form[this.ClientID + "classoptions"] != null) { ids = Page.Request.Form[this.ClientID + "classoptions"].Split(','); selectedClasses = new int[ids.Length]; for (int x = 0; x < ids.Length; x++) { selectedClasses[x] = int.Parse(ids[x]); } } else { // What the hell is this? selectedClasses = new int[0]; } // Assume that the form has not been changed. formChanged = false; // Save newly checked classes. for (int x = 0; x < selectedClasses.Length; x++) { // Ignore classes already checked! foreach (DojoAttendanceEntry aEntry in attendance) { if (selectedClasses[x] == aEntry.Class.iD) { goto NEXT_ENTRY; } } DojoAttendanceEntry entry = new DojoAttendanceEntry(); entry.Class = DojoClass.NewPlaceHolder(selectedClasses[x]); entry.Member = member; entry.Rank = member.rank; entry.SigninTime = localTime; attendance.Add(entry); entry.Save(); formChanged = true; NEXT_ENTRY: continue; } // Delete unchecked classes. foreach (DojoAttendanceEntry aEntry in attendance) { removeEntry = true; for (int x = 0; x < selectedClasses.Length; x++) { if (aEntry.Class.iD == selectedClasses[x]) { removeEntry = false; } } if (removeEntry) { aEntry.Delete(); formChanged = true; } } // Run attendance scan if form has changed if (formChanged) { aScanner = new AttendanceScanner(); aScanner.RunMemberAttendanceScan(member, TimeSpan.FromHours(1)); member.Save(); } }
protected void ok_Click(object sender, EventArgs e) { if (dojoAttendanceEntryID == 0) { obj = new DojoAttendanceEntry(); } else { obj = new DojoAttendanceEntry(dojoAttendanceEntryID); } obj.SigninTime = DateTime.Parse(tbSigninTime.Text); obj.SignoutTime = DateTime.Parse(tbSignoutTime.Text); if (msClass.SelectedItem != null && msClass.SelectedItem.Value != "Null") { obj.Class = DojoClass.NewPlaceHolder( int.Parse(msClass.SelectedItem.Value)); } else { obj.Class = null; } if (msMember.SelectedItem != null && msMember.SelectedItem.Value != "Null") { obj.Member = DojoMember.NewPlaceHolder( int.Parse(msMember.SelectedItem.Value)); } else { obj.Member = null; } if (msRank.SelectedItem != null && msRank.SelectedItem.Value != "Null") { obj.Rank = DojoRank.NewPlaceHolder( int.Parse(msRank.SelectedItem.Value)); } else { obj.Rank = null; } if (editOnAdd) { dojoAttendanceEntryID = obj.Save(); } else { obj.Save(); } if (resetOnAdd) { tbSigninTime.Text = DateTime.Now.ToString(); tbSignoutTime.Text = DateTime.Now.ToString(); msClass.SelectedIndex = 0; msMember.SelectedIndex = 0; msRank.SelectedIndex = 0; } OnUpdated(EventArgs.Empty); }