Example #1
0
        public void NormalReserve(string strMembershipID, int nPackageID, int nClassInstanceID, bool needToVerifyMemberPackage)
        {
            TblClassInstance classInstance = new TblClassInstance();
            classInstance.NClassInstanceID = nClassInstanceID;
            classInstance.SelectOne();

            TblClassAttendance classAttendance = new TblClassAttendance();

            DateTime classDate = new DateTime(classInstance.DtDate.Value.Year, classInstance.DtDate.Value.Month, classInstance.DtDate.Value.Day,
                classInstance.DtStartTime.Value.Hour, classInstance.DtStartTime.Value.Minute, classInstance.DtStartTime.Value.Second);

            if (DateTime.Today > classDate)
                throw new Exception("You are not allow to reserve the previous day class.");

            if (classAttendance.IsReservedThisClass(nClassInstanceID, strMembershipID))
            {
                throw new Exception("You have reserved this class.");
            }

            if (classAttendance.GetReservation(nClassInstanceID).Rows.Count > ACMS.Convert.ToInt32(classInstance.NMaxNo))
            {
                throw new Exception("Class is fully reserved by members. Please try again later.");
            }

            if (needToVerifyMemberPackage)
            {
                if (!VerifyMemberPackageAllowCertainClass(nPackageID, classInstance.StrClassCode.Value))
                {
                    //throw new Exception("The package you wish to use is not allow to attend the class. Please use other package.");
                    DialogResult result = MessageBox.Show("The package you wish to use is not allow to attend the class. Do you still want to reserve it. \n " +
                        "(An unlinked record will be create if you click yes) ", "Warning",MessageBoxButtons.YesNo);

                    if (result == DialogResult.Yes)
                    {
                        MemberPackage.CreateUnlinkedMemberPackage(strMembershipID, ref nPackageID);
                    }
                    else
                    {
                        return;
                    }
                }
            }

            //			if (!VerifyMemberPackageAllowCertainClass(nPackageID, classInstance.StrClassCode.Value))
            //				throw new Exception("The package you wish to use is not allow to reserve the class. Please use other package.");

            //Prompt Package going to expiry
            //Prompt Remaining class

            classAttendance.NClassInstanceID = nClassInstanceID;
            classAttendance.StrMembershipID = strMembershipID;
            classAttendance.NEmployeeID = User.EmployeeID;
            classAttendance.NReservedByID = User.EmployeeID;
            classAttendance.FUOBBooking = System.Data.SqlTypes.SqlBoolean.False;
            classAttendance.DtDate = classInstance.DtDate.Value;
            classAttendance.DtReservationDate = DateTime.Today.Date;
            classAttendance.DtStartTime = Convert.ToDateTime(classInstance.DtDate.Value.ToString("yyyy-MM-dd")+" "+ classInstance.DtStartTime.Value.ToString("H:mm:ss"));
            classAttendance.DtEndTime = Convert.ToDateTime(classInstance.DtDate.Value.ToString("yyyy-MM-dd") + " " + classInstance.DtEndTime.Value.ToString("H:mm:ss"));
            classAttendance.StrBranchCode = User.BranchCode;
            classAttendance.DtLastEditDate = DateTime.Now;
            classAttendance.NStatusID = 0;
            classAttendance.NPackageID = nPackageID;
            classAttendance.Insert();

            TblBranch sqlBranch = new TblBranch();
            TblClass sqlClass = new TblClass();

            sqlBranch.StrBranchCode = classAttendance.StrBranchCode.ToString();
            sqlBranch.SelectOne();

            sqlClass.StrClassCode = classInstance.StrClassCode;
            sqlClass.SelectOne();

            if (isMobileAppUser(strMembershipID))
                PushNotification(strMembershipID, "Your class booking for " + sqlClass.StrDescription.ToString() + " at " + sqlBranch.StrBranchName.ToString() + " at " + classAttendance.DtStartTime.Value.ToString("h.mmtt") + " on " + classAttendance.DtStartTime.Value.ToString("dd MMM") + " has been confirmed.");
        }
Example #2
0
        public void ChangeClass(int nClassInstanceID, string strClassCode, string strRemark)
        {
            TblAudit audit = new TblAudit();
            TblClassInstance sqlClassIns = new TblClassInstance();
            TblClass sqlClass = new TblClass();
            TblBranch sqlBranch = new TblBranch();

            ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider();

            string oldClassCode = "";
            string oldClassName="";
            string newClassName = "";
            string strBranchName = "";

            try
            {
                sqlClassIns.MainConnectionProvider = connProvider;
                audit.MainConnectionProvider = connProvider;

                connProvider.OpenConnection();
                connProvider.BeginTransaction("ChangeClassInstance");

                sqlClassIns.NClassInstanceID = nClassInstanceID;
                sqlClassIns.SelectOne();
                oldClassCode = sqlClassIns.StrClassCode.Value;
                if (sqlClassIns.DtDate < DateTime.Now.Date)
                    throw new Exception("Only future class can assign new class code");

                sqlClassIns.StrClassCode = strClassCode;
                sqlClassIns.StrRemarks = strRemark;
                sqlClassIns.Update();

                sqlClass.StrClassCode = oldClassCode;
                sqlClass.SelectOne();
                oldClassName = sqlClass.StrDescription.ToString();

                sqlBranch.StrBranchCode = sqlClassIns.StrBranchCode.ToString();
                sqlBranch.SelectOne();
                strBranchName = sqlBranch.StrBranchName.ToString();

                sqlClass.StrClassCode = strClassCode;
                sqlClass.SelectOne();
                newClassName = sqlClass.StrDescription.ToString();

                audit.DtDate = DateTime.Now;
                audit.NAuditTypeID = AuditTypeID.ClassAuditTypeID;
                audit.NEmployeeID = ACMSLogic.User.EmployeeID;
                audit.StrAuditEntry = string.Format("Old Class Code = {0}, " +
                                                    "New Class Code = {1}",
                                                    oldClassCode, strClassCode); // "Change class instance : " + nClassInstanceID.ToString() + " to class code: " + strClassCode;
                audit.StrReference = "Class InstanceID :" + nClassInstanceID.ToString();
                audit.Insert();
                connProvider.CommitTransaction();

                DataTable dtAttendance = new DataTable();
                dtAttendance = GetClassAttendanceReservedAndAttended(nClassInstanceID);

                DialogResult result1 = MessageBox.Show("Push Notification to Mobile app users? ", "Confirm", MessageBoxButtons.YesNo);
                if (result1 == DialogResult.Yes)
                {
                    foreach (DataRow row in dtAttendance.Rows)
                    {
                        string strMsgContent = oldClassName + " at " + strBranchName + " at " + Convert.ToDateTime(row["dtStartTime"]).ToString("h.mmtt") + " on " + Convert.ToDateTime(row["dtStartTime"]).ToString("dd MMM") + " has been changed to " + newClassName + ". Sorry for any inconvenience caused.";
                        PushNotification(row["strMembershipID"].ToString(), strMsgContent);
                    }
                }
            }
            catch (Exception)
            {
                connProvider.RollbackTransaction("ChangeClassInstance");
                throw;
            }
            finally
            {
                if (connProvider.CurrentTransaction != null)
                    connProvider.CurrentTransaction.Dispose();
                if (connProvider.DBConnection != null)
                {
                    if (connProvider.DBConnection.State == ConnectionState.Open)
                        connProvider.DBConnection.Close();
                }
            }
        }