Beispiel #1
0
        protected void Validate()
        {
            if (StudentName.Length == 0)
            {
                throw new MyFlightbookException(Resources.SignOff.errNoStudent);
            }

            if (GetDigitizedSig() == null || GetDigitizedSig().Length == 0)
            {
                // Not an ad-hoc endorsement: requires a valid instructor name and a valid expiration date
                if (String.IsNullOrWhiteSpace(InstructorName))
                {
                    throw new MyFlightbookException(Resources.SignOff.errNoInstructor);
                }
                if (!CFIExpirationDate.HasValue() || CFIExpirationDate.CompareTo(Date) < 0)
                {
                    throw new MyFlightbookException(Resources.SignOff.errExpiredCertificate);
                }

                if (StudentType == StudentTypes.Member && !new CFIStudentMap(InstructorName).IsInstructorOf(StudentName))
                {
                    throw new MyFlightbookException(String.Format(CultureInfo.CurrentCulture, Resources.SignOff.errNoRelationship, InstructorName, StudentName));
                }
            }
            else
            {
                // Verify that we don't also have an instructor name
                if (!String.IsNullOrWhiteSpace(InstructorName))
                {
                    throw new MyFlightbookValidationException(Resources.SignOff.errBothScribbleAndCFI);
                }
                // And no expiration is OK (e.g., for ground instructors), but it needs to be after date of issuance of endorsement
                if (CFIExpirationDate.HasValue() && CFIExpirationDate.CompareTo(Date) < 0)
                {
                    throw new MyFlightbookException(Resources.SignOff.errExpiredCertificate);
                }
            }
            if (CFICertificate.Length == 0)
            {
                throw new MyFlightbookException(Resources.SignOff.errNoCertificate);
            }
            if (EndorsementText.Length == 0)
            {
                throw new MyFlightbookException(Resources.SignOff.errNoEndorsement);
            }
            if (Title.Length == 0)
            {
                throw new MyFlightbookException(Resources.SignOff.errNoTitle);
            }
        }
Beispiel #2
0
        public void FCommit()
        {
            string szQ = (this.ID < 0) ? "INSERT INTO endorsements SET CFI=?cfi, CFIFullName=?cfifullname, Student=?Student, StudentType=?studentType, Date=?dt, DateCreated=Now(), CFINum=?cfiNumber, CFIExpiration=?dtExp, Endorsement=?bodytext, Title=?title, FARRef=?farref" :
                         "UPDATE endorsements SET CFI=?cfi, Student=?Student, StudentType=?studentType, Date=?dt, CFINum=?cfiNumber, CFIExpiration=?dtExp, Endorsement=?bodytext, Title=?title, FARRef=?farref WHERE ID=?id";

            if (InstructorName.Length == 0)
            {
                throw new MyFlightbookException(Resources.SignOff.errNoInstructor);
            }
            if (StudentName.Length == 0)
            {
                throw new MyFlightbookException(Resources.SignOff.errNoStudent);
            }
            if (StudentType == StudentTypes.Member && !new CFIStudentMap(InstructorName).IsInstructorOf(StudentName))
            {
                throw new MyFlightbookException(String.Format(CultureInfo.CurrentCulture, Resources.SignOff.errNoRelationship, InstructorName, StudentName));
            }
            if (CFICertificate.Length == 0)
            {
                throw new MyFlightbookException(Resources.SignOff.errNoCertificate);
            }
            if (CFIExpirationDate.CompareTo(DateTime.Now) < 0)
            {
                throw new MyFlightbookException(Resources.SignOff.errExpiredCertificate);
            }
            if (EndorsementText.Length == 0)
            {
                throw new MyFlightbookException(Resources.SignOff.errNoEndorsement);
            }
            if (Title.Length == 0)
            {
                throw new MyFlightbookException(Resources.SignOff.errNoTitle);
            }

            DBHelper dbh = new DBHelper(szQ);

            dbh.DoNonQuery((cmd) =>
            {
                cmd.Parameters.AddWithValue("id", ID);
                cmd.Parameters.AddWithValue("cfi", InstructorName);
                cmd.Parameters.AddWithValue("Student", StudentName);
                cmd.Parameters.AddWithValue("studentType", (int)StudentType);
                cmd.Parameters.AddWithValue("dt", Date);
                cmd.Parameters.AddWithValue("cfiNumber", CFICertificate);
                cmd.Parameters.AddWithValue("dtExp", CFIExpirationDate);
                cmd.Parameters.AddWithValue("bodytext", EndorsementText);
                cmd.Parameters.AddWithValue("title", Title);
                cmd.Parameters.AddWithValue("farref", FARReference);
                cmd.Parameters.AddWithValue("cfifullname", Profile.GetUser(InstructorName).UserFullName);
            });

            if (dbh.LastError.Length > 0)
            {
                throw new MyFlightbookException(Resources.SignOff.errCommitFailed + dbh.LastError);
            }

            if (ID < 0)
            {
                ID = dbh.LastInsertedRowId;
            }
        }