private void TopUpSingleTreatmentTransaction(ACMSDAL.ConnectionProvider connProvider, ACMSLogic.POS pos) { if (pos.NCategoryID == 19) { TblServiceSession sqlserviceSession = new TblServiceSession(); sqlserviceSession.MainConnectionProvider = connProvider; string strServiceCode = ""; int nPackageID = -1; foreach (DataRow r in pos.ReceiptItemsTable.Rows) { strServiceCode = r["strCode"].ToString(); nPackageID = ACMS.Convert.ToInt32(r["strReferenceNo"]); sqlserviceSession.DtDate = DateTime.Today.Date; sqlserviceSession.DtStartTime = DateTime.Now; sqlserviceSession.DtEndTime = DateTime.Now.AddMinutes(15); sqlserviceSession.DtLastEditDate = DateTime.Now; sqlserviceSession.NEmployeeID = User.EmployeeID; sqlserviceSession.NPackageID = nPackageID; sqlserviceSession.NStatusID = 5; sqlserviceSession.StrBranchCode = User.BranchCode; sqlserviceSession.StrMembershipID = pos.StrMembershipID; sqlserviceSession.StrServiceCode = strServiceCode; sqlserviceSession.Insert(); r["strReferenceNo"] = sqlserviceSession.NSessionID; } } }
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; } }