예제 #1
0
        public void LoadData()
        {
            base.LoadData();

            ApasConfigurationManager cfg=new ApasConfigurationManager();
            AdoNetManager db = new AdoNetManager("APAS_Regular");

            db.ClearParameters();
            db.objCmd.Parameters.Clear();

            db.objCmd.Parameters.Add(
                "@id", SqlDbType.Int).Value = Id;

            DataTable tbl = db.queryTable(
                " SELECT * FROM APAS_Regular " +
                " WHERE intIdRegular = @id ");

            if (tbl.Rows.Count > 0)
            {
                ColorCode = (string)tbl.Rows[0]["strColorCodeRegular"];
            }
            else
            {
                //if base regular exists and extended APAS_Regular does not
                //exist, assume null for ColorCode

                ColorCode = cfg.getConfigValue("DefaultClassColor");

                //throw new ApasDatabaseException
                //    ("Requested Regular record is not found.");
            }
        }
예제 #2
0
        /// <summary>
        /// Will only save the ApasRegular part
        /// </summary>
        public void Save()
        {
            //will use AdoNetManager to directly Access the Database
            AdoNetManager db = new AdoNetManager("APAS_Regular");

            //check if the extended ApasRegular record already exists
            db.ClearParameters();
            db.objCmd.Parameters.Clear();
            db.objCmd.Parameters.Add(
                "@id", SqlDbType.Int).Value = Id;

            int result = Convert.ToInt32(db.executeScalar(
                " SELECT COUNT(*) FROM APAS_Regular " +
                " WHERE intIdRegular = @id "));

            if (result > 0)
            {
                //exists
                db.objCmd.Parameters.Clear();
                db.objCmd.Parameters.Add(
                    "@id", SqlDbType.Int).Value = Id;
                db.objCmd.Parameters.Add(
                    "@cc", SqlDbType.VarChar, 50).Value = ColorCode;

                result = db.executeCommand(
                   " UPDATE APAS_Regular " +
                   " SET strColorCodeRegular= @cc " +
                   " WHERE intIdRegular = @id ");

                if (result == 0)
                    throw new ApasDatabaseException(
                        "A database update failed for unknown reason.");
            }
            else
            {
                //not exists
                db.objCmd.Parameters.Clear();
                db.objCmd.Parameters.Add(
                    "@id", SqlDbType.Int).Value = Id;
                db.objCmd.Parameters.Add(
                    "@cc", SqlDbType.VarChar, 50).Value = ColorCode;

                result = db.executeCommand(
                    " INSERT INTO APAS_Regular " +
                    " (intIdRegular, strColorCodeRegular) " +
                    " VALUES (@id, @cc) ");

                if (result == 0)
                    throw new ApasDatabaseException(
                        "A database update failed for unknown reason.");

            }
        }
예제 #3
0
        //This method tightly couples with CORE classes. maybe, reconsider later
        //Nhibernate does not suppport bidirectional association with
        //list collections. No choice but have to ask the parent for studId
        public virtual void SyncDerivedFields(PaymentAdvice parent)
        {
            wsvAttendanceLn.AttendanceLn DBAttln =
                new wsvAttendanceLn.AttendanceLn();

            wsvAttendanceLn.CAttendanceLn[] aryAttln =
                DBAttln.GetAttendanceByStudentClass(parent.IdStudent, IdRegular);

            Absence = 0;
            Prorate = 0;
            if (aryAttln != null)
            {
                foreach (wsvAttendanceLn.CAttendanceLn attln in aryAttln)
                {
                    if (attln.isPresent == 0)
                        Absence++;
                    else if (attln.isPresent == 2)
                        Prorate++;
                }
            }

            //check log for number of forfeits. Very unnatural....
            AdoNetManager db = new AdoNetManager("ForfeitLog");

            String strSQL =
            " SELECT ISNULL(SUM(intCreditForfeitLog),0) FROM ForfeitLog " +
            " WHERE intIdUserForfeitLog=@idStud " +
            " AND intIdClassScheduleForfeitLog=@idClass ";

            db.ClearParameters();
            db.Parameters.Add("@idClass", SqlDbType.Int).Value = IdRegular;
            db.Parameters.Add("@idStud", SqlDbType.Int).Value = parent.IdStudent;

            Forfeit =Convert.ToInt32(db.executeScalar(strSQL));

            wsvMakeupAttendance.MakeupAttendance dbMakeup
                = new wsvMakeupAttendance.MakeupAttendance();
            wsvMakeupAttendance.CMakeupAttendance[] aryMakeup
                = dbMakeup.getMakeupAttendanceByStudent(parent.IdStudent);

            if (aryMakeup == null)
                Makeup = 0;
            else
            {
                foreach (wsvMakeupAttendance.CMakeupAttendance objMakeup in aryMakeup)
                {
                    if (objMakeup.IdAttendanceRegular == IdRegular)
                        Makeup++;
                }
            }

            ApasRegular regClass = GetAssociatedClass();
            PerLessonFee = Convert.ToDecimal(regClass.Fee);

            //get credit from student classshedule
            wsvStudentClassSchedule.StudentClassSchedule dbSC =
                new wsvStudentClassSchedule.StudentClassSchedule();

            wsvStudentClassSchedule.CStudentClassSchedule objSC =
                dbSC.getStudentClassSchedule(parent.IdStudent, IdRegular);

            //offset credit with number of attendances unmarked in this month
            DateTime month = parent.GetParentPAList().Month.AddMonths(-1);

            wsvAttendance.Attendance dbAtt = new wsvAttendance.Attendance();
            wsvAttendance.CAttendance[] aryAtt =
                dbAtt.getAttendancesBetween(regClass.Id,
                new DateTime(month.Year, month.Month, 1),
                new DateTime(month.Year, month.Month, DateTime.DaysInMonth(month.Year, month.Month))
            );
            int dayCount = GetDayCountOf(regClass.Day, regClass.ClassStartDate, month);
            int attCount = (aryAtt == null) ? 0 : aryAtt.Length;
            int unmarkedCount = (dayCount-attCount) < 0 ? 0 : dayCount-attCount;

            Credit = objSC.Credit-unmarkedCount;
        }