示例#1
0
        public void DeleteClassAttendance(int nPackageID, int nAttendanceID, string remark)
        {
            // i need to know it is only one record, and it is 1st record also
            TblClassAttendance classAttendance = new TblClassAttendance();
            classAttendance.NPackageID = nPackageID;
            DataTable table = classAttendance.SelectAllWnPackageIDLogic();

            bool setNullInMemberPackage = false;
            bool isDelete1stRecord = false;
            bool isGIRO = false;
            bool isGiveBackOneDay = false;

            DateTime newfirstRecordClassAttendanceDate = DateTime.MinValue;

            if (table != null && table.Rows.Count > 0)
            {
                table.DefaultView.RowFilter = "nStatusID = 1 or nStatusID = 2 or nStatusID = 4";

                if (table.DefaultView.Count == 1)
                {
                    DataSet ds = new DataSet();

                    string strSQL = "select nCategoryID from tblMemberPackage mp join tblPackage p on mp.strPackageCode=p.strPackageCode where nPackageID=" + nPackageID.ToString();
                    SqlHelper.FillDataset(connection, CommandType.StoredProcedure, "UP_GETDATA", ds, new string[] { "Table" }, new SqlParameter("@strSQL", strSQL));

                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        if (ds.Tables[0].Rows[0]["nCategoryID"].ToString() == "2")
                        {
                            isGIRO = true;
                            setNullInMemberPackage = false;
                        }
                        else
                            setNullInMemberPackage = true;
                    }
                    else
                        setNullInMemberPackage = true;
                }
                else
                {
                    DataRow [] rowList = table.Select("nStatusID = 1 or nStatusID = 2 or nStatusID = 4",
                        "nAttendanceID", DataViewRowState.CurrentRows);

                    int firstRecord_nAttendanceID = ACMS.Convert.ToInt32(rowList[0]["nAttendanceID"]);
                    if (firstRecord_nAttendanceID == nAttendanceID)
                    {
                        isDelete1stRecord = true;
                        newfirstRecordClassAttendanceDate = ACMS.Convert.ToDateTime(rowList[1]["dtDate"]);
                    }
                }
            }

            classAttendance.NAttendanceID = nAttendanceID;
            classAttendance.SelectOne();
            classAttendance.DtLastEditDate = DateTime.Now;
            classAttendance.NEmployeeID = ACMSLogic.User.EmployeeID;
            if (classAttendance.NStatusID == 2)
                isGiveBackOneDay = true;
            classAttendance.NStatusID = 5;
            classAttendance.StrRemarks = remark;

            TblAudit audit = new TblAudit();
            audit.DtDate = DateTime.Now;
            audit.NAuditTypeID = 3;
            audit.NEmployeeID = User.EmployeeID;
            audit.StrAuditEntry = "Delete class attendance with nAttendanceID = " + nAttendanceID +
                " and nPackageID = " + nPackageID;
            audit.StrReference = nAttendanceID.ToString();

            TblMemberPackage memberPackage = new TblMemberPackage();
            memberPackage.NPackageID = nPackageID;
            memberPackage.SelectOne();

            if (setNullInMemberPackage)
            {
                //				bool isUnlimited = memberPackage.IsUnlimitedPackage(nPackageID);
                //
                //				if (!isUnlimited)
                //				{
                memberPackage.DtExpiryDate = System.Data.SqlTypes.SqlDateTime.Null;
                memberPackage.DtStartDate = System.Data.SqlTypes.SqlDateTime.Null;
                memberPackage.DtLastEdit = DateTime.Now;
                memberPackage.NEmployeeID = User.EmployeeID;
                //				}
            }
            else if (isDelete1stRecord)
            {
                if (!isGIRO)
                {
                    TimeSpan duration = memberPackage.DtExpiryDate.Value.Subtract(memberPackage.DtStartDate.Value);
                    DateTime newExpriry = newfirstRecordClassAttendanceDate.Add(duration);
                    memberPackage.DtExpiryDate = newExpriry;
                    memberPackage.DtStartDate = newfirstRecordClassAttendanceDate;
                    memberPackage.DtLastEdit = DateTime.Now;
                    memberPackage.NEmployeeID = User.EmployeeID;
                }
            }
            else if (isGiveBackOneDay)
            {
                if (!isGIRO)
                {
                    // Check if status = forfeited, give back 1 day to duration pkg
                    DateTime newExpriry = memberPackage.DtExpiryDate.Value.AddDays(1);
                    memberPackage.DtExpiryDate = newExpriry;
                    memberPackage.DtLastEdit = DateTime.Now;
                    memberPackage.NEmployeeID = User.EmployeeID;
                }
            }

            ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider();

            try
            {
                memberPackage.MainConnectionProvider = connProvider;
                classAttendance.MainConnectionProvider = connProvider;
                audit.MainConnectionProvider = connProvider;

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

                memberPackage.Update();
                audit.Insert();
                classAttendance.Update();

                connProvider.CommitTransaction();
                //return true;
            }
            catch (Exception ex)
            {
                connProvider.RollbackTransaction("DeleteClassAttendance");
                throw new Exception("Failed to delete Class Attendance :: " + ex.Message);
            }
            finally
            {
                if (connProvider.CurrentTransaction != null)
                    connProvider.CurrentTransaction.Dispose();
                if (connProvider.DBConnection != null)
                {
                    if (connProvider.DBConnection.State == ConnectionState.Open)
                        connProvider.DBConnection.Close();
                }
                memberPackage.MainConnactionIsCreatedLocal = true;
                classAttendance.MainConnactionIsCreatedLocal = true;
                audit.MainConnactionIsCreatedLocal = true;
            }
        }
示例#2
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;
            }
        }
示例#3
0
        public void UpdateClassAttendance(int nAttendanceID, int nNewPackageID)
        {
            TblClassAttendance classAttendance = new TblClassAttendance();
            System.Data.SqlTypes.SqlInt32 nOldPackageID;

            classAttendance.NAttendanceID = nAttendanceID;
            DataTable table = classAttendance.SelectOne();
            if (table != null && table.Rows.Count > 0)
            {
                nOldPackageID = classAttendance.NPackageID;
                classAttendance.NEmployeeID = User.EmployeeID;
                classAttendance.NPackageID = nNewPackageID;

                myMemberPackage.NPackageID = nNewPackageID;
                DataTable memberPackageTable = myMemberPackage.SelectOne();
                if (memberPackageTable == null || memberPackageTable.Rows.Count == 0)
                    throw new Exception("Failed to update/transfer class attendance. Member Package with Package ID = "+ nNewPackageID.ToString() + "has been deleted");

                DataRow masterRow = memberPackageTable.Rows[0];
                TblPackage package = new TblPackage();
                package.StrPackageCode = masterRow["strPackageCode"].ToString();
                package.SelectOne();

                if (masterRow["dtStartDate"] == DBNull.Value)
                {
                    if (!package.FGIRO || package.FGIRO.IsNull)
                    {
                        myMemberPackage.DtStartDate = classAttendance.DtDate;
                        int iduration = package.NPackageDuration.Value;
                        if (package.StrDurationUnit.ToString().Trim() == "DAY")
                            myMemberPackage.DtExpiryDate = classAttendance.DtDate.Value.AddDays(iduration - 1).AddDays(0);
                        else if (package.StrDurationUnit.ToString().Trim() == "WEEK")
                        {
                            iduration = iduration * 7;
                            myMemberPackage.DtExpiryDate = classAttendance.DtDate.Value.AddDays(iduration - 1).AddDays(0);
                        }
                        else
                            myMemberPackage.DtExpiryDate = classAttendance.DtDate.Value.AddMonths(package.NPackageDuration.Value).AddDays(-1);
                    }
                }
                else
                {
                    if (!package.FGIRO || package.FGIRO.IsNull)
                    {
                        if (classAttendance.DtDate < ACMS.Convert.ToDateTime(masterRow["DtStartDate"]))
                        {
                            myMemberPackage.DtStartDate = classAttendance.DtDate;
                            int iduration = package.NPackageDuration.Value;
                            if (package.StrDurationUnit.ToString().Trim() == "DAY")
                                myMemberPackage.DtExpiryDate = classAttendance.DtDate.Value.AddDays(iduration - 1).AddDays(0);
                            else if (package.StrDurationUnit.ToString().Trim() == "WEEK")
                            {
                                iduration = iduration * 7;
                                myMemberPackage.DtExpiryDate = classAttendance.DtDate.Value.AddDays(iduration - 1).AddDays(0);
                            }
                            else
                                myMemberPackage.DtExpiryDate = classAttendance.DtDate.Value.AddMonths(package.NPackageDuration.Value).AddDays(-1);
                        }
                        else
                        {
                            DateTime memberPackageStartDate = ACMS.Convert.ToDateTime(masterRow["DtStartDate"]);
                            DateTime memberPackageExpiryDate = ACMS.Convert.ToDateTime(masterRow["dtExpiryDate"]);

                            if (memberPackageStartDate > classAttendance.DtDate)
                            {
                                myMemberPackage.DtExpiryDate = memberPackageExpiryDate.Subtract(memberPackageStartDate.Subtract(classAttendance.DtDate.Value));
                                myMemberPackage.DtStartDate = classAttendance.DtDate;
                            }
                        }
                    }
                }

                ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider();

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

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

                    myMemberPackage.Update();
                    classAttendance.Update();
                    //UpdateStartExpiryDate(nOldPackageID);

                    connProvider.CommitTransaction();
                    connProvider.BeginTransaction("SaveClassAttendance");
                    UpdateStartExpiryDate(nOldPackageID);
                    connProvider.CommitTransaction();
                }
                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;
                }
            }
        }
示例#4
0
        public void CancelReservation(int nAttendanceID)
        {
            TblCompany comp = new TblCompany();
            DataTable table = comp.SelectAll();
            int nhourBeforeToDelete = 0;

            if (table != null && table.Rows.Count>0)
            {
                nhourBeforeToDelete = ACMS.Convert.ToInt32(table.Rows[0]["nCancelBookingLimit"]);
            }

            TblClassAttendance classAttendance = new TblClassAttendance();
            classAttendance.NAttendanceID = nAttendanceID;
            classAttendance.SelectOne();

            TblClassInstance classInstance = new TblClassInstance();
            classInstance.NClassInstanceID = classAttendance.NClassInstanceID.Value;
            classInstance.SelectOne();

            if (DateTime.Today.Date > classInstance.DtDate.Value.Date)
                return;
            else if (DateTime.Today.Date == classInstance.DtDate.Value.Date)
            {
            //				if (oUser.DateTime.Now.Hour + nhourBeforeToDelete > classAttendance.DtStartTime.Value.Hour)
            //					throw new Exception("You are not allow to cancel this reservation because you have passed the time period that allow you to cancel the reservation.");
            //				else
            //				{
                    classAttendance.NStatusID = 3;
                    classAttendance.Update();

                //}
            }
            else
            {
                try
                {
                    classAttendance.NStatusID = 3;
                    classAttendance.Update();
                }
                catch(Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }