Beispiel #1
0
        public void CancelClassInstance(int nClassInstanceID, string remark)
        {
            myClassInstance.NClassInstanceID = nClassInstanceID;
            myClassInstance.SelectOne();
            myClassInstance.FCancelled = System.Data.SqlTypes.SqlBoolean.True;
            myClassInstance.StrRemarks = remark;
            TblAudit audit = new TblAudit();

            audit.DtDate = DateTime.Today;
            audit.NAuditTypeID = AuditTypeID.ClassAuditTypeID;
            audit.NEmployeeID = ACMSLogic.User.EmployeeID;
            audit.StrAuditEntry = "Cancel class instance " + nClassInstanceID.ToString();
            audit.StrReference = nClassInstanceID.ToString();

            TblClassAttendance classAttendance = new TblClassAttendance();
            classAttendance.NClassInstanceID = nClassInstanceID;
            DataTable classAttendanceTable = classAttendance.SelectAllWnClassInstanceIDLogic();

            if (classAttendanceTable != null && classAttendanceTable.Rows.Count > 0)
            {
                foreach (DataRow r in classAttendanceTable.Rows)
                {
                    r["nStatusID"] = 3;
                }
            }

            ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider();

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

                connProvider.OpenConnection();
                connProvider.BeginTransaction("CancelClassInstance");
                myClassInstance.Update();
                audit.Insert();
                classAttendance.SaveData(classAttendanceTable);
                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 = row["strDescription"].ToString() + " at " + row["strBranchName"] + " at " + Convert.ToDateTime(myClassInstance.DtStartTime).ToString("h.mmtt") + " on " + Convert.ToDateTime(myClassInstance.DtStartTime).ToString("dd MMM") + " has been cancelled. Sorry for any inconvenience caused.";
                        PushNotification(row["strMembershipID"].ToString(), strMsgContent);
                    }
                }
            }
            catch (Exception)
            {
                connProvider.RollbackTransaction("CancelClassInstance");
                throw;
            }
            finally
            {
                if (connProvider.CurrentTransaction != null)
                    connProvider.CurrentTransaction.Dispose();
                if (connProvider.DBConnection != null)
                {
                    if (connProvider.DBConnection.State == ConnectionState.Open)
                        connProvider.DBConnection.Close();
                }
                myClassInstance.MainConnactionIsCreatedLocal = true;
            }
        }
Beispiel #2
0
        public bool VerifyIntructor(int nClassInstanceIDToBeVerified, int verifyUserID,string verifyUserPassword,
			int nStandingIntructorID, string remark)
        {
            TblEmployee verifyUser = new TblEmployee();

            verifyUser.NEmployeeID = verifyUserID;

            verifyUser.SelectOne();

            int [,] intArray = new int[50,2];

            int ArrayNo=1;

            if (verifyUser.StrPassword.Value != verifyUserPassword)

                return false;

            myClassInstance.NClassInstanceID = nClassInstanceIDToBeVerified;

            myClassInstance.SelectOne();

            if (myClassInstance.NActualInstructorID.IsNull)

                throw new Exception("Missing Intructor login info");

            if (myClassInstance.NActualInstructorID.Value == verifyUserID)

                throw new Exception("Instructor are not allowed to verfiy for the same class.");

            if (!myClassInstance.NVerifyID.IsNull)

                throw new Exception("This class have been verify by other staff with the employee ID : "+  myClassInstance.NVerifyID.Value.ToString());

            bool isLate =false;

            DateTime StartTime;

            DateTime LoginTime;

            myClassInstance.MInstructorDeduction=0;

            StartTime=ACMS.Convert.ToDBDateTime(myClassInstance.DtStartTime.Value.ToLongTimeString());

            LoginTime=ACMS.Convert.ToDBDateTime(myClassInstance.DtInstructorLogin.Value.ToLongTimeString());

            if (DateTime.Compare(LoginTime,StartTime)>0)

            {

                isLate=true;

            }

            bool haveStandingIntructor = nStandingIntructorID > 0;

            if (haveStandingIntructor)

                myClassInstance.NStandinInstructorID = nStandingIntructorID;

            if (isLate)

            {

                TblCompany company = new TblCompany();

                DataTable companyTable = company.SelectAll();

                decimal instructorLateDeductionFee = 0;

                if (companyTable.Rows.Count > 0)

                {

                    instructorLateDeductionFee =  ACMS.Convert.ToDecimal(companyTable.Rows[0]["mInstructorLateDeductionFee"]);

                }

                myClassInstance.MInstructorDeduction=instructorLateDeductionFee;

                if (nStandingIntructorID != 0)

                    myClassInstance.MStandinInstructorFees = instructorLateDeductionFee;

            }

            int nCommissionTypeID = myClassInstance.NCommissionTypeID.Value;

            TblEmployee actualInstructor = new TblEmployee();

            actualInstructor.NEmployeeID = myClassInstance.NActualInstructorID;

            actualInstructor.SelectOne();

            int nInstructorTypeID = ACMS.Convert.ToInt32(actualInstructor.NInstructorTypeID);

            myClassInstance.MInstructorFees = (GetCommission(nCommissionTypeID, nInstructorTypeID) - myClassInstance.MInstructorDeduction);

            TblClassAttendance classAttendance = new TblClassAttendance();

            classAttendance.NClassInstanceID = nClassInstanceIDToBeVerified;

            DataTable classAttendanceTable = classAttendance.SelectAllWnClassInstanceIDLogic();

            DataRow[] classAttendanceRowList = null;

            if (classAttendanceTable != null && classAttendanceTable.Rows.Count > 0)

            {

                classAttendanceRowList = classAttendanceTable.Select("nStatusID = 0", "nAttendanceID", DataViewRowState.CurrentRows);

                foreach (DataRow r in classAttendanceRowList)

                {

                    r["nStatusID"] = 2;
                    r["nTypeID"]=0;

                }

            }

            ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider();

            try

            {

                myClassInstance.MainConnectionProvider = connProvider;

                classAttendance.MainConnectionProvider = connProvider;

                connProvider.OpenConnection();

                connProvider.BeginTransaction("VerifyClassInstance");

                myClassInstance.NVerifyID = verifyUserID;

                myClassInstance.StrRemarks = remark;

                myClassInstance.Update();

                classAttendance.SaveData(classAttendanceTable);

                TblMemberPackage sqlMemberPackage = new TblMemberPackage();

                sqlMemberPackage.MainConnectionProvider = connProvider;

                if (classAttendanceRowList != null)

                {

                    int nPackageID = -1;

                    foreach (DataRow r in classAttendanceRowList)

                    {

                        nPackageID = ACMS.Convert.ToInt32(r["nPackageID"]);

                        int nAttendanceID=ACMS.Convert.ToInt32(r["nAttendanceID"]);

                        DataTable memberPackageTable = sqlMemberPackage.GetMemberPackage(nPackageID);

                        if (memberPackageTable.Rows[0]["strPackageCode"].ToString() != "Unlinked")

                        {

                            #region test

                            //MemberPackage.CalculateMemberPackageBalance(memberPackageTable, connProvider);

                            if (ACMS.Convert.ToInt32(memberPackageTable.Rows[0]["Balance"]) > 0)

                            {

                                DateTime classDate = myClassInstance.DtDate.IsNull ? DateTime.Today.Date : myClassInstance.DtDate.Value;

                                DataRow masterRow = memberPackageTable.Rows[0];// Means new class Attendance gonna insert

                                if (masterRow["dtStartDate"] == DBNull.Value &&

                                    masterRow["dtExpiryDate"] == DBNull.Value)

                                {

                                    TblPackage package = new TblPackage();

                                    package.StrPackageCode = masterRow["strPackageCode"].ToString();

                                    package.SelectOne();

                                    if (package.NPackageDuration == 0 && package.NPackageDay > 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);
                                    }

                                }

                                else

                                {

                                    DateTime memberPackageStartDate =  ACMS.Convert.ToDateTime(masterRow["DtStartDate"]);

                                    DateTime memberPackageExpiryDate = ACMS.Convert.ToDateTime(masterRow["dtExpiryDate"]);

                                    if (memberPackageStartDate > classDate)

                                    {

                                        masterRow["dtExpiryDate"] = memberPackageExpiryDate.Subtract(memberPackageStartDate.Subtract(classDate));

                                    }

                                }

                            }

                            else if (ACMS.Convert.ToInt32(memberPackageTable.Rows[0]["Balance"]) <=0)

                            {

                                intArray[ArrayNo,0]=nPackageID;

                                intArray[ArrayNo,1]=nAttendanceID;

                                ArrayNo=ArrayNo+1;

                                MessageBox.Show("Package Balance of " + memberPackageTable.Rows[0]["strMembershipID"].ToString().TrimEnd() + " is Zero. Attendance will be cancel");

                            }

                            #endregion

                        }

                        if (ACMS.Convert.ToInt32(memberPackageTable.Rows[0]["nMaxSession"]) == 9999 && memberPackageTable.Rows[0]["fGIRO"].ToString() != "1")
                        {

                            DateTime dtExpiryDate = ACMS.Convert.ToDateTime(memberPackageTable.Rows[0]["dtExpiryDate"]);

                            DateTime dtStartDate = ACMS.Convert.ToDateTime(memberPackageTable.Rows[0]["dtStartDate"]);

                            if (dtExpiryDate != DateTime.MinValue)

                            {

                                memberPackageTable.Rows[0]["dtExpiryDate"] = dtExpiryDate.AddDays(-1);

                            }

                        }

                        sqlMemberPackage.SaveData(memberPackageTable);

                    }

                }

                connProvider.CommitTransaction();

            }

            catch (Exception)

            {

                connProvider.RollbackTransaction("VerifyClassInstance");

                throw;

            }

            finally

            {

                if (connProvider.CurrentTransaction != null)

                    connProvider.CurrentTransaction.Dispose();

                if (connProvider.DBConnection != null)

                {

                    if (connProvider.DBConnection.State == ConnectionState.Open)

                        connProvider.DBConnection.Close();

                }

                myClassInstance.MainConnactionIsCreatedLocal = true;

                classAttendance.MainConnactionIsCreatedLocal = true;

            }

            for (int j=1;j<=50;j++)

            {

                if (intArray[j,0]>0) DeleteClassAttendance(intArray[j,0],intArray[j,1],"");

                else if (intArray[j,0]<=0)

                {return true;}

            }

            return true;
        }