Esempio n. 1
0
        public bool NewClassAttendance(int nPackageID, string strMemberShipID, int nClassInstance,
            int nType, string strBranchCode, DateTime classDate,
            DateTime startTime, DateTime endTime, bool isRefunded)
        {
            if (!isRefunded)
            {
                ACMSDAL.TblReceipt sqlReceipt = new ACMSDAL.TblReceipt();
                DataTable receipttable = sqlReceipt.GetToDayForgetCardReceipt(strMemberShipID, 17);

                if (receipttable == null || receipttable.Rows.Count == 0)
                {
                    throw new Exception("You have yet to pay the forget card deposit today.");
                }
            }

            TblClassAttendance classAttendance = new TblClassAttendance();
            bool isPostFromOtherRecord = false;
            bool needtoAddBackOneDayExpiryDate = false;
            bool BalanceStatus = true;
            DataTable memberPackageTable = null;

            if (nType != 1)
            {

                DataRow classAttendanceRow = null;

                bool isAttendedNow = classAttendance.IsAttendedThisClass(nClassInstance, strMemberShipID, ref classAttendanceRow);

                if (isAttendedNow)
                {
                    int nStatusID = ACMS.Convert.ToInt32(classAttendanceRow["nStatusID"]);

                    if (nStatusID == 1)
                    {
                        // Process
                        throw new Exception("Member already been marked in this class.");
                    }
                    else
                    {
                        //Forfeit and need to change to process
                        if (classAttendanceRow != null)
                        {
                            int nClassAttendanceID = ACMS.Convert.ToInt32(classAttendanceRow["nAttendanceID"]);
                            classAttendance.NAttendanceID = nClassAttendanceID;
                            classAttendance.SelectOne();
                            isPostFromOtherRecord = true;
                            nPackageID = classAttendance.NPackageID.Value;
                            isRefunded = classAttendance.FRefunded.IsNull ? true : classAttendance.FRefunded.Value;

                            // this only true if the package is unlimited one
                            memberPackageTable = myMemberPackage.GetMemberPackage(nPackageID);

                            if (ACMS.Convert.ToInt32(memberPackageTable.Rows[0]["nMaxSession"]) == 9999)
                                needtoAddBackOneDayExpiryDate = true;
                        }
                    }
                }
                else if (classAttendanceRow != null && nType == 0)
                {
                    int nClassAttendanceID = ACMS.Convert.ToInt32(classAttendanceRow["nAttendanceID"]);

                    classAttendance.NAttendanceID = nClassAttendanceID;
                    classAttendance.SelectOne();
                    isPostFromOtherRecord = true;
                    nPackageID = classAttendance.NPackageID.Value;
                    isRefunded = classAttendance.FRefunded.IsNull ? true : classAttendance.FRefunded.Value;
                }
            }

            if (memberPackageTable == null)
            {
                myMemberPackage.NPackageID = nPackageID;
                memberPackageTable = myMemberPackage.GetMemberPackage(nPackageID);
            }

            if (memberPackageTable == null || memberPackageTable.Rows.Count == 0)
                throw new Exception("Failed to create new class attendance. Member Package with npackageID = " + nPackageID.ToString() + "has been deleted");

            classAttendance.NPackageID = nPackageID;
            classAttendance.StrMembershipID = strMemberShipID;
            classAttendance.NClassInstanceID = nClassInstance;
            classAttendance.NTypeID = nType;
            classAttendance.StrBranchCode = strBranchCode;
            classAttendance.DtDate = classDate;
            classAttendance.DtStartTime = startTime;
            classAttendance.DtEndTime = endTime;
            classAttendance.DtLastEditDate = DateTime.Now;
            classAttendance.NEmployeeID = ACMSLogic.User.EmployeeID;

            //indicated free class or not
            TblClassInstance classInstance = new TblClassInstance();
            DataTable Instance = classInstance.LoadData("Select fFree from tblClassInstance Where nClassInstanceID = @nClassInstanceID",
                new string[] { "@nClassInstanceID" }, new object[] { nClassInstance });

            if (Instance.Rows[0][0].ToString() == "True")
                classAttendance.NStatusID = 4;
            else
                classAttendance.NStatusID = 1;

            classAttendance.FRefunded = isRefunded;// System.Data.SqlTypes.SqlBoolean.

            //UnLinked is for temporary only
            if (memberPackageTable.Rows[0]["strPackageCode"].ToString() != "Unlinked")
            {
                CalculateMemberPackageBalance(memberPackageTable.Rows[0]["strPackageCode"].ToString(), strMemberShipID, memberPackageTable);

                DataRow masterRow = memberPackageTable.Rows[0];

                //				if (ACMS.Convert.ToDBInt32(memberPackageTable.Rows[0]["Balance"])<999 &&  ACMS.Convert.ToDBInt32(memberPackageTable.Rows[0]["nAdjust"])>=1)
                //				{
                //					memberPackageTable.Rows[0]["Balance"]=ACMS.Convert.ToDBInt32(memberPackageTable.Rows[0]["Balance"])- ACMS.Convert.ToDBInt32(memberPackageTable.Rows[0]["nAdjust"]);
                //				}

                if (ACMS.Convert.ToInt32(memberPackageTable.Rows[0]["Balance"]) <= 0)
                {
                    throw new Exception("Balance is zero");
                    masterRow["nBalance"] = false;
                    BalanceStatus = false;
                }

                if (masterRow["fGiro"].ToString() != "1")
                {
                    if ((masterRow["dtStartDate"] == DBNull.Value &&
                    masterRow["dtExpiryDate"] == DBNull.Value) || (masterRow["dtStartDate"] != DBNull.Value && Convert.ToDateTime(masterRow["dtStartDate"]) > classDate))
                    {
                        // Means new class Attendance gonna insert
                        TblPackage package = new TblPackage();
                        package.StrPackageCode = masterRow["strPackageCode"].ToString();
                        package.SelectOne();

                        //if (package.NPackageDuration.Value == 0 && package.NPackageDay.Value > 0)
                        //{
                        //    masterRow["dtStartDate"] = classDate;
                        //    masterRow["dtExpiryDate"] = classDate.AddDays(package.NPackageDay.Value - 1);
                        //}
                        //else
                        //{
                        //    masterRow["dtStartDate"] = classDate;
                        //    masterRow["dtExpiryDate"] = classDate.AddMonths(package.NPackageDuration.Value).AddDays(-1);
                        //}

                        //jackie Start 05042012
                        masterRow["dtStartDate"] = classDate;
                        if (package.NPackageDuration.Value == 0)
                        {

                            string txt = package.StrPackageCode.ToString();

                            if (txt == "FTRIAL")
                            {
                                masterRow["dtExpiryDate"] = classDate.AddDays(1).AddDays(0);
                            }
                            else
                            {
                                string strduration;

                                int cstarts = txt.IndexOf("(") + 1;
                                int len = txt.IndexOf(")") - cstarts;
                                txt = txt.Substring(cstarts, len);

                                if (string.IsNullOrEmpty(txt))
                                {
                                    strduration = string.Empty;
                                }
                                else
                                {
                                    int lens = txt.Length;
                                    strduration = txt.Substring(txt.Length - 1, 1);
                                }

                                if (strduration == "D")
                                {

                                    strduration = txt.Replace("D", "");
                                    int iduration = Int32.Parse(strduration);
                                    masterRow["dtExpiryDate"] = classDate.AddDays(iduration - 1).AddDays(0);

                                }
                                if (strduration == "W")
                                {
                                    strduration = txt.Replace("W", "");
                                    int iduration = Int32.Parse(strduration);
                                    iduration = iduration * 7;
                                    masterRow["dtExpiryDate"] = classDate.AddDays(iduration - 1).AddDays(0);

                                }
                            }

                        }
                        else
                        {
                            int iduration = package.NPackageDuration.Value;
                            if (package.StrDurationUnit.ToString().Trim() == "DAY")
                                masterRow["dtExpiryDate"] = classDate.AddDays(iduration - 1).AddDays(0);
                            else if (package.StrDurationUnit.ToString().Trim() == "WEEK")
                            {
                                iduration = iduration * 7;
                                masterRow["dtExpiryDate"] = classDate.AddDays(iduration - 1).AddDays(0);
                            }
                            else if (package.StrDurationUnit.ToString().Trim() == "MONTH")
                                masterRow["dtExpiryDate"] = classDate.AddMonths(package.NPackageDuration.Value).AddDays(-1);
                        }
                        //jackie END 2/02/2012

                    }
                    else
                    {
                        // Kean Yiap
                        string strPackageCode = masterRow["strPackageCode"].ToString();
                        CalculateMemberPackageBalance(strPackageCode, strMemberShipID, memberPackageTable);
                        DateTime memberPackageStartDate = ACMS.Convert.ToDateTime(masterRow["DtStartDate"]);
                        DateTime memberPackageExpiryDate = ACMS.Convert.ToDateTime(masterRow["dtExpiryDate"]);

                        //if (memberPackageStartDate > classDate)
                        //{
                        //jackie why must change ExpiryDate 26042012
                        //	masterRow["dtExpiryDate"] = memberPackageExpiryDate.Subtract(memberPackageStartDate.Subtract(classDate));
                        //}
                    }
                }

                if (ACMS.Convert.ToInt32(memberPackageTable.Rows[0]["Balance"]) <= 1)
                {
                    if (masterRow["strPackageCode"].ToString() == "FTRIAL")
                    {
                        memberPackageTable.Rows[0]["nBalance"] = 1;
                    }
                    else
                    {
                        memberPackageTable.Rows[0]["nBalance"] = 0;
                    }
                }

            }

            ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider();

            try
            {
                myMemberPackage.MainConnectionProvider = connProvider;
                classAttendance.MainConnectionProvider = connProvider;

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

                if (needtoAddBackOneDayExpiryDate && memberPackageTable.Rows[0]["fGIRO"].ToString() != "1")
                {
                    memberPackageTable.Rows[0]["dtExpiryDate"] = ACMS.Convert.ToDateTime(memberPackageTable.Rows[0]["dtExpiryDate"]).AddDays(1);
                }

                myMemberPackage.SaveData(memberPackageTable);

                if (BalanceStatus)
                {
                    if (!isPostFromOtherRecord)
                        classAttendance.Insert();
                    else
                        classAttendance.Update();

                    connProvider.CommitTransaction();
                }

                return true;
            }
            catch (Exception)
            {
                connProvider.RollbackTransaction("SaveClassAttendance");
                throw new Exception("Failed to save Class Attendance");
            }
            finally
            {
                if (connProvider.CurrentTransaction != null)
                    connProvider.CurrentTransaction.Dispose();
                if (connProvider.DBConnection != null)
                {
                    if (connProvider.DBConnection.State == ConnectionState.Open)
                        connProvider.DBConnection.Close();
                }
                myMemberPackage.MainConnactionIsCreatedLocal = true;
                classAttendance.MainConnactionIsCreatedLocal = true;
            }
        }
Esempio n. 2
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.");
        }