예제 #1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        AdoNetManager db=new AdoNetManager("DaysInMonth");
        int result;

        db.objCmd.Parameters.Add(
            "@dtmYearMonth",SqlDbType.DateTime).Value=parseDate(lblMonth.Text);

        result=Convert.ToInt32(db.executeScalar(
            " SELECT count(*) FROM DaysInMonth "+
            " WHERE DATEPART(MONTH, YearMonth) = DATEPART(MONTH, @dtmYearMonth) " +
            " AND DATEPART(YEAR, YearMonth)= DATEPART(YEAR, @dtmYearMonth) "
            ));

         db.objCmd.Parameters.Clear();
         db.objCmd.Parameters.Add(
            "@dtmYearMonth", SqlDbType.DateTime).Value = parseDate(lblMonth.Text);
         db.objCmd.Parameters.Add(
            "@mon", SqlDbType.Int).Value = Convert.ToInt32(txtMonday.Text);
         db.objCmd.Parameters.Add(
            "@tues",SqlDbType.Int).Value=Convert.ToInt32(txtTuesday.Text);
         db.objCmd.Parameters.Add(
            "@wed",SqlDbType.Int).Value=Convert.ToInt32(txtWednesday.Text);
         db.objCmd.Parameters.Add(
            "@thurs",SqlDbType.Int).Value=Convert.ToInt32(txtThursday.Text);
         db.objCmd.Parameters.Add(
            "@fri",SqlDbType.Int).Value=Convert.ToInt32(txtFriday.Text);
         db.objCmd.Parameters.Add(
            "@sat",SqlDbType.Int).Value=Convert.ToInt32(txtSaturday.Text);
         db.objCmd.Parameters.Add(
            "@sun",SqlDbType.Int).Value=Convert.ToInt32(txtSunday.Text);
        if(result==0)
        {
            db.executeCommand(
                " INSERT INTO DaysInMonth " +
                " (YearMonth, NumOfMonday, NumOfTuesday, NumOfWednesday, "+
                " NumOfThursday, NumOfFriday, NumOfSaturday, NumOfSunday) "+
                " VALUES (@dtmYearMonth,@mon,@tues,@wed, @thurs, @fri,@sat,@sun) ");

        }else
        {
            db.queryDataSet
               ("UPDATE DaysInMonth SET " +
               " NumOfMonday=@mon, " +
               " NumOfTuesday=@tues, " +
               " NumOfWednesday=@wed, " +
               " NumOfThursday=@thurs, " +
               " NumOfFriday=@fri, " +
               " NumOfSaturday=@sat, " +
               " NumOfSunday=@sun " +
               " WHERE DATEPART(MONTH, YearMonth) = DATEPART(MONTH, @dtmYearMonth) " +
               " AND DATEPART(YEAR, YearMonth)= DATEPART(YEAR, @dtmYearMonth) "
               );

        }

        Response.Redirect(
            "OpenPaymentAdvice.aspx?month=" + Server.UrlEncode(lblMonth.Text)
            );
    }
예제 #2
0
    public bool checkPreRequisites()
    {
        AdoNetManager db = new AdoNetManager("DaysInMonth");
        int result;

        db.objCmd.Parameters.Add(
            "@dtmYearMonth", SqlDbType.DateTime).Value = parseDate(lblMonth.Text);

        result = Convert.ToInt32(db.executeScalar(
            " SELECT count(*) FROM DaysInMonth " +
            " WHERE DATEPART(MONTH, YearMonth) = DATEPART(MONTH, @dtmYearMonth) " +
            " AND DATEPART(YEAR, YearMonth)= DATEPART(YEAR, @dtmYearMonth) "
            ));

        if (result == 0)
        {
            Response.Write("<script language='javascript' type='text/javascript'>" +
             "window.location.href='EnterNumberOfLessons.aspx?month='+escape('" + lblMonth.Text + "');" +
             "</script>");

            return false;
        }
        else
        {
            return true;
        }
    }
예제 #3
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.");

            }
        }
예제 #4
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;
        }