Ejemplo n.º 1
0
        /// <summary>
        /// Use to Transfer Service Session or Update the service Session
        /// </summary>
        /// <param name="nSessionID"></param>
        /// <param name="dtDate"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="strBranchCode"></param>
        /// <param name="nPackageID"></param>
        /// <param name="strServiceCode"></param>
        /// <param name="nEmployeeInChargeID"></param>
        /// <param name="remark"></param>
        /// <param name="isTransfer"></param>
        public void UpdateServiceSession(int nSessionID, DateTime dtDate, DateTime startTime,  DateTime endTime,
			string strBranchCode, int nPackageID, string strServiceCode, 
			int nEmployeeInChargeID, string remark, int status, bool isTransfer)
        {
            TblServiceSession serviceSession = new TblServiceSession();
            serviceSession.NSessionID = nSessionID;
            DataTable table = serviceSession.SelectOne();
            if (table == null || table.Rows.Count == 0)
                throw new Exception("failed to update this package. Record not found");

            TblService service = new TblService();
            service.StrServiceCode = strServiceCode;
            DataTable serviceTable = service.SelectOne();
            if (serviceTable == null || serviceTable.Rows.Count == 0)
                throw new Exception("The service is not available.");

            int duration = ACMS.Convert.ToInt32(service.NDuration);

            bool isPT = ACMS.Convert.ToInt32(service.NServiceTypeID) == 0;

            if (!isTransfer)
            {
                if (!isPT && !ACMSLogic.SpaBooking.VerifyMemberPackageAllowCertainService(nPackageID, strServiceCode))
                    throw new Exception("this member package is not allow to use the service");

                if (endTime == DateTime.MinValue)
                    endTime = startTime.AddMinutes((Double)duration);

                if (dtDate != DateTime.MinValue)
                    serviceSession.DtDate = dtDate;
                if (startTime != DateTime.MinValue)
                    serviceSession.DtStartTime = startTime;
                if (endTime != DateTime.MinValue)
                    serviceSession.DtEndTime= endTime;
                if (strBranchCode != "")
                    serviceSession.StrBranchCode = strBranchCode;
                if (strServiceCode != "")
                    serviceSession.StrServiceCode = strServiceCode;
                if (nEmployeeInChargeID != -1)
                    serviceSession.NServiceEmployeeID = nEmployeeInChargeID;
                if (nPackageID != -1)
                    serviceSession.NPackageID = nPackageID;
                if (remark != "")
                    serviceSession.StrRemarks = remark;
                if (status != -1)
                    serviceSession.NStatusID  = status;

                if (status == 5)
                    serviceSession.NMarkedByID = User.EmployeeID;
            }
            else
            {
                serviceSession.NPackageID = nPackageID;
            }

            myMemberPackage.NPackageID = nPackageID;
            DataTable memberPackageTable = myMemberPackage.SelectOne();

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

            DataRow masterRow = memberPackageTable.Rows[0];

            if (masterRow["dtStartDate"] == DBNull.Value)
            {
                // Means new class Attendance gonna insert
                TblPackage package = new TblPackage();
                package.StrPackageCode = masterRow["strPackageCode"].ToString();
                DataTable tablePackage = package.SelectOne();

                if (tablePackage == null && tablePackage.Rows.Count == 0)
                    throw new Exception("Failed to update service session. Package no found.");

                myMemberPackage.DtStartDate = serviceSession.DtDate.Value;
                myMemberPackage.DtExpiryDate = serviceSession.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 > serviceSession.DtDate.Value)
                {
                    myMemberPackage.DtExpiryDate = memberPackageExpiryDate.Subtract(memberPackageStartDate.Subtract(serviceSession.DtDate.Value));
                }
            }

            serviceSession.NEmployeeID = User.EmployeeID;
            serviceSession.DtLastEditDate = DateTime.Now;

            ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider();

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

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

                myMemberPackage.Update();
                serviceSession.Update();

                connProvider.CommitTransaction();
            }
            catch (Exception)
            {
                connProvider.RollbackTransaction("SaveServiceSession");
                throw new Exception("Failed to save Service Session");
            }
            finally
            {
                if (connProvider.CurrentTransaction != null)
                    connProvider.CurrentTransaction.Dispose();
                if (connProvider.DBConnection != null)
                {
                    if (connProvider.DBConnection.State == ConnectionState.Open)
                        connProvider.DBConnection.Close();
                }
                myMemberPackage.MainConnactionIsCreatedLocal = true;
                serviceSession.MainConnactionIsCreatedLocal = true;
            }
        }
Ejemplo n.º 2
0
        public bool NewServiceSession(int nPackageID, string strServiceCode, string strMemberShipID, int nEmployeeID,
            string strBranchCode, DateTime dtDate, DateTime startTime, DateTime dtTreatment, string strSignID, int nQuatity, Boolean forfeited,
            int MemberPackageCategoryID, string strSigKey, string strPdfExportPath, ref DataTable dtSessionID, string SsRemark)
        {
            // i will know whether the service session is for PT or not by using strServiceCode and query out the record from tblService.
            // i also can calculate the endTime using the data(nduration) from tblService

            TblService service = new TblService();
            service.StrServiceCode = strServiceCode;
            DataTable table = service.SelectOne();
            if (table == null || table.Rows.Count == 0)
                throw new Exception("The service is not available.");

            int duration = ACMS.Convert.ToInt32(service.NDuration);

            bool isPT = ACMS.Convert.ToInt32(service.NServiceTypeID) == 0;

            DateTime endTime = startTime.AddMinutes((Double)duration);

            TblEmployee Employee = new TblEmployee();
            Employee.NEmployeeID = nEmployeeID;
            DataTable Emptable = Employee.SelectOne();

            if (Emptable.Rows[0]["fPartTime"].ToString() == "True" || ACMSLogic.SpaBooking.TherapistIsAvailableToBook(nEmployeeID, dtDate, startTime, endTime, strBranchCode))
            {

                TblServiceSession serviceSession = new TblServiceSession();
                serviceSession.NPackageID = nPackageID;
                serviceSession.StrMembershipID = strMemberShipID;
                serviceSession.StrServiceCode = strServiceCode;
                serviceSession.NStatusID = 5;
                serviceSession.DtDate = dtDate;
                serviceSession.DtStartTime = startTime;
                serviceSession.DtEndTime = endTime;
                serviceSession.DtLastEditDate = DateTime.Now;
                serviceSession.NEmployeeID = User.EmployeeID;
                serviceSession.NMarkedByID = User.EmployeeID;
                serviceSession.NServiceEmployeeID = nEmployeeID;
                serviceSession.DtTreatment = dtTreatment;
                serviceSession.StrSignID = strSignID;
                serviceSession.StrSigKey = strSigKey;
                serviceSession.StrSigPdfPath = strPdfExportPath;
                serviceSession.StrUtilData = strSigKey;
                serviceSession.StrRemarks = SsRemark;

                if (forfeited == true)
                {
                    serviceSession.StrRemarks = "FORFEITED";
                }

                if (isPT)
                {
                    serviceSession.StrBranchCode = strBranchCode;
                }
                else
                    serviceSession.StrBranchCode = User.BranchCode;

                TblMemberPackage memberPackage = new TblMemberPackage();
                //1309
                memberPackage.NPackageID = nPackageID;
                DataTable memberPackageTable = memberPackage.GetMemberPackage(nPackageID);
                if (memberPackageTable == null || memberPackageTable.Rows.Count == 0)
                    throw new Exception("Failed to create new service session. Member Package with npackageID = " + nPackageID.ToString() + "has been deleted");

                CalculateMemberPackageBalance(strServiceCode, strMemberShipID, memberPackageTable);
                if (ACMS.Convert.ToInt32(memberPackageTable.Rows[0]["Balance"]) == 0 || ACMS.Convert.ToInt32(memberPackageTable.Rows[0]["Balance"]) - nQuatity < 0)
                    throw new Exception("The balance of this member's package is zero.");

                // Kean Yiap
                DataRow masterRow = memberPackageTable.Rows[0];
                if (masterRow["dtStartDate"] == DBNull.Value &&
                    masterRow["dtExpiryDate"] == DBNull.Value)
                {
                    // Means new service session gonna insert
                    TblPackage package = new TblPackage();
                    package.StrPackageCode = masterRow["strPackageCode"].ToString();
                    package.SelectOne();
                    masterRow["dtStartDate"] = dtDate;
                    masterRow["dtExpiryDate"] = dtDate.AddMonths(package.NPackageDuration.Value).AddDays(-1);
                }
                else
                {
                    DateTime memberPackageStartDate = ACMS.Convert.ToDateTime(masterRow["DtStartDate"]);
                    DateTime memberPackageExpiryDate = ACMS.Convert.ToDateTime(masterRow["dtExpiryDate"]);

                    if (memberPackageStartDate > dtDate)
                    {
                        masterRow["dtExpiryDate"] = memberPackageExpiryDate.Subtract(memberPackageStartDate.Subtract(dtDate));
                    }
                }

                ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider();

                try
                {
                    memberPackage.MainConnectionProvider = connProvider;
                    serviceSession.MainConnectionProvider = connProvider;

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

                    memberPackage.SaveData(memberPackageTable);

                    for (int i = 0; i < nQuatity; i++)
                    {
                        serviceSession.Insert();  //Capture Session ID Here

                        DataRow ssRow;
                        ssRow = dtSessionID.NewRow();
                        ssRow["nSessionID"] = Convert.ToInt32(serviceSession.NSessionID.Value);
                        ssRow["strMembershipID"] = strMemberShipID;
                        dtSessionID.Rows.Add(ssRow);
                    }

                    connProvider.CommitTransaction();
                    //DEREK Wrong Here Need to Fix //Use DataTable //Same goes with Live Version
                    //mySessionID = Convert.ToInt32(serviceSession.NSessionID.Value);

                    return true;
                }
                catch (Exception ex)
                {
                    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();
                    }
                    memberPackage.MainConnactionIsCreatedLocal = true;
                    serviceSession.MainConnactionIsCreatedLocal = true;

                }

            }
            else
            {
                return false;
            }
        }