Example #1
0
        public static void CreateClassInstance(System.DayOfWeek dayOfWeek)
        {
            TblClassInstance classInstance = new TblClassInstance();
            TblClassSchedule classSchedule = new TblClassSchedule();

            DateTime dateNow = System.DateTime.Today.Date;

            if (dateNow.DayOfWeek != dayOfWeek)
            {
                for (double i = 1; i < 8; i++)
                {
                    dateNow = dateNow.AddDays(1).Date;
                    if (dateNow.DayOfWeek == dayOfWeek)
                        break;
                }
            }

            for (double i = 0; i < 2; i++)
            {
                DateTime date;
                if (i == 0)
                    date = dateNow;
                else
                {
                    double dayToAdd = i * 7;
                    date = dateNow.AddDays(dayToAdd).Date;
                }
                int nDay = ConvertDateToNDay(date);

                DataTable table = classSchedule.SelectAllWnDay(nDay, User.BranchCode);

                if (table == null || table.Rows.Count == 0)
                    continue;
                else
                {
                    foreach (DataRow r in table.Rows)
                    {
                        //DateTime newdate = System.DateTime.(date.Year, date.Month, date.Year);
                        //DateTime dt= System.Convert.ToDateTime(date.ToString("dd/MM/yyyy"));

                        DateTime dtEndTime = ACMS.Convert.ToDateTime(r["dtEndTime"]);
                        DateTime dtStartTime = ACMS.Convert.ToDateTime(r["dtStartTime"]);
                        string strClassCode = r["strClassCode"].ToString();
                        int nHallNo = ACMS.Convert.ToInt32(r["nHallNo"]);

                        bool createdInstance = classInstance.HaveClassInstance(date,
                            dtEndTime, dtStartTime, strClassCode, nHallNo, User.BranchCode);

                        if (!createdInstance)
                        {
                            classInstance.DtDate = date;
                            classInstance.DtEndTime = ACMS.Convert.ToDateTime(r["dtEndTime"]);
                            classInstance.DtStartTime = ACMS.Convert.ToDateTime(r["dtStartTime"]);
                            classInstance.StrClassCode = ACMS.Convert.ToSqlString(r["strClassCode"]);
                            classInstance.NHallNo = ACMS.Convert.ToSqlInt32(r["nHallNo"]);
                            classInstance.NPermanentInstructorID = ACMS.Convert.ToSqlInt32(r["nInstructorID"]);
                            classInstance.FFree = ACMS.Convert.ToBoolean(r["fFree"]);
                            classInstance.FPeak = ACMS.Convert.ToBoolean(r["fPeak"]);
                            classInstance.FAllowStudentOnPeak = ACMS.Convert.ToBoolean(r["fAllowStudentOnPeak"]);
                            classInstance.FReservation = ACMS.Convert.ToBoolean(r["fReservation"]);
                                    classInstance.FPeak = ACMS.Convert.ToBoolean(r["fPeak"]);
                            classInstance.FAllowStudentOnPeak = ACMS.Convert.ToBoolean(r["fAllowStudentOnPeak"]);
                            classInstance.FReservation = ACMS.Convert.ToBoolean(r["fReservation"]);
                            classInstance.NMaxNo = ACMS.Convert.ToSqlInt32(r["nMaxNo"]);
                            classInstance.FAllowUOBBooking = ACMS.Convert.ToBoolean(r["fAllowUOBBooking"]);
                            classInstance.NCommissionTypeID = ACMS.Convert.ToSqlInt32(r["nCommissionTypeID"]);
                            classInstance.StrBranchCode = User.BranchCode;
                            classInstance.FCancelled = System.Data.SqlTypes.SqlBoolean.False;
                            classInstance.Insert();
                        }
                    }
                }
            }
        }
Example #2
0
        public static void CreateClassInstance()
        {
            TblClassInstance classInstance = new TblClassInstance();
                TblClassSchedule classSchedule = new TblClassSchedule();

                classInstance.StrClassCode = "GYM";
                DataTable temptable = classInstance.SelectAllWstrClassCodeLogic();
                if (temptable == null || temptable.Rows.Count == 0)
                {
                    TblInstructorTypeCommission dummyInstructorTypeCommission = new TblInstructorTypeCommission();
                    DataTable dummyTable = dummyInstructorTypeCommission.SelectAll();

                    if (dummyTable.Rows.Count == 0)
                        throw new Exception("Please insert a record in InstructorTypeCommission table.");

                    classInstance.StrClassCode = "GYM";
                    classInstance.NPermanentInstructorID = User.EmployeeID;
                    classInstance.NCommissionTypeID = ACMS.Convert.ToInt32(dummyTable.Rows[0]["nCommissionTypeID"]);
                    classInstance.StrBranchCode = User.BranchCode;
                    classInstance.DtDate = DateTime.Today.Date;
                    classInstance.DtEndTime = DateTime.Now;
                    classInstance.DtStartTime = DateTime.Now;
                    //classInstance.nClassScheduleID = 0;
                    classInstance.Insert();
                }

                DateTime dateNow = System.DateTime.Now;

                for (double i = 0; i < 2; i++)
                {
                    DateTime date;
                    if (i == 0)
                        date = DateTime.Today.Date;
                    else
                    {
                        double dayToAdd = i * 7;
                        date = dateNow.AddDays(dayToAdd).Date;
                    }
                    int nDay = ConvertDateToNDay(date);

                    DataTable table = classSchedule.SelectAllWnDay(nDay, User.BranchCode);

                    if (table == null || table.Rows.Count == 0)
                        continue;
                    else
                    {
                        foreach (DataRow r in table.Rows)
                        {
                            //DateTime newdate = System.DateTime.(date.Year, date.Month, date.Year);
                            //DateTime dt= System.Convert.ToDateTime(date.ToString("dd/MM/yyyy"));

                            DateTime dtEndTime = ACMS.Convert.ToDateTime(r["dtEndTime"]);
                            DateTime dtStartTime = ACMS.Convert.ToDateTime(r["dtStartTime"]);
                            string strClassCode = r["strClassCode"].ToString();
                            int nHallNo = ACMS.Convert.ToInt32(r["nHallNo"]);

                            bool createdInstance = classInstance.HaveClassInstance(date,
                                dtEndTime, dtStartTime, strClassCode, nHallNo, User.BranchCode);

                            if (!createdInstance)
                            {
                                classInstance.DtDate = date;
                                classInstance.DtEndTime = ACMS.Convert.ToDateTime(r["dtEndTime"]);
                                classInstance.DtStartTime = ACMS.Convert.ToDateTime(r["dtStartTime"]);
                                classInstance.StrClassCode = ACMS.Convert.ToSqlString(r["strClassCode"]);
                                classInstance.NHallNo = ACMS.Convert.ToSqlInt32(r["nHallNo"]);
                                classInstance.NPermanentInstructorID = ACMS.Convert.ToSqlInt32(r["nInstructorID"]);
                                classInstance.FFree = ACMS.Convert.ToBoolean(r["fFree"]);
                                classInstance.FPeak = ACMS.Convert.ToBoolean(r["fPeak"]);
                                classInstance.FAllowStudentOnPeak = ACMS.Convert.ToBoolean(r["fAllowStudentOnPeak"]);
                                classInstance.FReservation = ACMS.Convert.ToBoolean(r["fReservation"]);
                                classInstance.NMaxNo = ACMS.Convert.ToSqlInt32(r["nMaxNo"]);
                                classInstance.FAllowUOBBooking = ACMS.Convert.ToBoolean(r["fAllowUOBBooking"]);
                                classInstance.NCommissionTypeID = ACMS.Convert.ToSqlInt32(r["nCommissionTypeID"]);
                                classInstance.StrBranchCode = User.BranchCode;
                                classInstance.FCancelled = System.Data.SqlTypes.SqlBoolean.False;
                                #region ====== Added by Albert ======
                                /*To insert class schedule id while creating class instance.*/
                                classInstance.nClassScheduleID = ACMS.Convert.ToSqlInt32(r["nClassScheduleID"]);
                                #endregion
                                classInstance.Insert();

                                }
                        }
                    }
                }
        }