private int UpgradePackage(ACMSDAL.ConnectionProvider connProvider, ACMSLogic.POS pos) { int OriginalCategoryID = 10 ; if (pos.NCategoryID == 10 && pos.WantToUpgradeMemberPackageTable.Rows.Count == 1) { int wantToUpgrade_nPackageID = ACMS.Convert.ToInt32(pos.WantToUpgradeMemberPackageRow["nPackageID"]); string oldStrPackageCode = pos.WantToUpgradeMemberPackageRow["strPackageCode"].ToString(); foreach (DataRow r in pos.ReceiptItemsTable.Rows) { pos.CheckPackageWhenSave(r["strCode"].ToString(), wantToUpgrade_nPackageID); } // from here, we can get a list of strClassCode that already been used by member //DataTable attendedClassCodetable = GetAttendedClassCode(ACMS.Convert.ToInt32(myWantToUpgradeMemberPackageTable.Rows[0]["nPackageID"])); // from here, we can get a list of strClassCode that already been used by member //DataTable attendedServiceCodetable = GetAttendedServiceCode(ACMS.Convert.ToInt32(myWantToUpgradeMemberPackageTable.Rows[0]["nPackageID"])); TblMemberPackage memberPackage = new TblMemberPackage(); TblClassAttendance classAttendance = new TblClassAttendance(); TblServiceSession serviceSession = new TblServiceSession(); TblPackage freeSpaPackage = new TblPackage(); memberPackage.MainConnectionProvider = connProvider; classAttendance.MainConnectionProvider = connProvider; serviceSession.MainConnectionProvider = connProvider; freeSpaPackage.MainConnectionProvider = connProvider; DataTable memberPackagetable = memberPackage.FillSchema("Select * from tblMemberPackage"); //get old free spa package Code freeSpaPackage.StrPackageCode = oldStrPackageCode; DataTable OldFreePackageCode = freeSpaPackage.SelectSpaPackageFreebie(); string strOldFreePackage = OldFreePackageCode.Rows[0]["strFreePkgCode"].ToString(); foreach (DataRow r in pos.ReceiptItemsTable.Rows) { int nQuantity = ACMS.Convert.ToInt32(r["nQuantity"]); for (int i = 0; i < nQuantity; i++) { DataRow rowToAdd = memberPackagetable.NewRow(); MemberPackage.InitMemberPackageRowInPOS(rowToAdd, pos.StrReceiptNo, pos.StrMembershipID, r["strCode"].ToString(), "", false); memberPackagetable.Rows.Add(rowToAdd); } } //insert a new upgrade package to member package if (memberPackagetable.Rows.Count > 0) memberPackage.SaveData(memberPackagetable); DataTable newAddMemberPackageTable = memberPackage.SelectAllWstrReceiptNo(pos.StrReceiptNo); DataRow[] rowNewAddMemberPackage = newAddMemberPackageTable.Select("fFree = 0"); DataTable attendedClassTable = classAttendance.GetAllClassAttendancesBasePackageID(wantToUpgrade_nPackageID, pos.StrMembershipID, pos.StrBranchCode); DataTable serviceUsedTable = serviceSession.GetMemberServiceSessionBasePackageID(wantToUpgrade_nPackageID, pos.StrMembershipID, pos.StrBranchCode); //insert a new freebie package based on new added upgrade pacakge string newStrPackageCode = ""; for( int i = 0; i<newAddMemberPackageTable.Rows.Count; i++) { if (newAddMemberPackageTable.Rows[i]["fFree"].ToString() == "False") { if (newAddMemberPackageTable.Rows.Count > 1) newStrPackageCode = newAddMemberPackageTable.Rows[newAddMemberPackageTable.Rows.Count - 1]["strPackageCode"].ToString(); else newStrPackageCode = newAddMemberPackageTable.Rows[0]["strPackageCode"].ToString(); } } //get new free spa package Code freeSpaPackage.StrPackageCode = newStrPackageCode; DataTable NewFreePackageCode = freeSpaPackage.SelectSpaPackageFreebie(); string strNewFreePackage = NewFreePackageCode.Rows[0]["strFreePkgCode"].ToString(); if (strNewFreePackage != "") { DataTable FreememberPackagetable = memberPackage.FillSchema("Select * from tblMemberPackage"); DataRow rowToAdd2 = FreememberPackagetable.NewRow(); MemberPackage.InitMemberPackageRowInPOS(rowToAdd2, pos.StrReceiptNo, pos.StrMembershipID, strNewFreePackage, "", true); FreememberPackagetable.Rows.Add(rowToAdd2); if (FreememberPackagetable.Rows.Count > 0) memberPackage.SaveData(FreememberPackagetable); //move session from old freebie to new freebie //find old free package ID,via wantToUpgrade_nPackageID freeSpaPackage.NPackageID = wantToUpgrade_nPackageID; freeSpaPackage.StrPackageCode = oldStrPackageCode; DataTable OldFreePackageID = freeSpaPackage.SelectSpaPackageFreebieID(); int nOldFreePackageID; if (OldFreePackageID.Rows.Count > 0) nOldFreePackageID = ACMS.Convert.ToInt32(OldFreePackageID.Rows[OldFreePackageID.Rows.Count - 1]["nPackageID"]); else nOldFreePackageID = 0; DataTable newFreeMemberPackageTable = memberPackage.SelectAllWstrReceiptNo(pos.StrReceiptNo); DataRow[] rowNewFreeMemberPackage = newFreeMemberPackageTable.Select("fFree = 1"); DataTable freeserviceUsedTable = serviceSession.GetMemberServiceSessionBasePackageID(nOldFreePackageID, pos.StrMembershipID, pos.StrBranchCode); //foreach (DataRow FmemberPackageRow in rowNewFreeMemberPackage) //{ string strFreePackageCode =""; if (rowNewFreeMemberPackage.Length > 0) strFreePackageCode = rowNewFreeMemberPackage[rowNewFreeMemberPackage.Length - 1]["strPackageCode"].ToString(); DataRow[] tempRowList3 = freeserviceUsedTable.Select("nPackageID = '"+nOldFreePackageID+"'", "dtDate"); if (tempRowList3.Length > 0) { foreach (DataRow freeserviceUsedRow in tempRowList3) { freeserviceUsedRow["nPackageID"] = rowNewFreeMemberPackage[rowNewFreeMemberPackage.Length - 1]["nPackageID"]; } } if (tempRowList3.Length > 0) { //update the expiryDate TblPackage package = new TblPackage(); package.MainConnectionProvider = connProvider; package.StrPackageCode = strFreePackageCode; DataTable tablePackage = package.SelectOne(); if (tablePackage == null && tablePackage.Rows.Count == 0) throw new Exception("Package no found."); if (tempRowList3.Length > 0) { rowNewFreeMemberPackage[rowNewFreeMemberPackage.Length - 1]["DtStartDate"] = ACMS.Convert.ToDateTime(tempRowList3[0]["dtDate"]); rowNewFreeMemberPackage[rowNewFreeMemberPackage.Length - 1]["DtExpiryDate"] = ACMS.Convert.ToDateTime( rowNewFreeMemberPackage[rowNewFreeMemberPackage.Length - 1]["DtStartDate"]).AddMonths(ACMS.Convert.ToInt32(package.NPackageDuration.Value)).AddDays(-1); } } //} DataTable oldFreeMemberPackageTable = memberPackage.SelectPackageID(nOldFreePackageID); oldFreeMemberPackageTable.Rows[0]["nStatusID"] = 2; serviceSession.UpgradePackage(ACMS.Convert.ToInt32(rowNewFreeMemberPackage[rowNewFreeMemberPackage.Length - 1]["nPackageID"]), nOldFreePackageID, pos.StrMembershipID); memberPackage.SaveData(oldFreeMemberPackageTable); memberPackage.SaveData(newFreeMemberPackageTable); } //move session from old package to new package foreach (DataRow memberPackageRow in rowNewAddMemberPackage) { string strPackageCode = memberPackageRow["strPackageCode"].ToString(); DataRow[] tempRowList = attendedClassTable.Select("nPackageID = '" + wantToUpgrade_nPackageID + "'", "dtDate"); if (tempRowList.Length > 0) { foreach (DataRow attendedClassRow in tempRowList) { // new packageID attendedClassRow["nPackageID"] = memberPackageRow["nPackageID"]; } } DataRow[] tempRowList2 = serviceUsedTable.Select("nPackageID = '" + wantToUpgrade_nPackageID + "'", "dtDate"); if (tempRowList2.Length > 0) { foreach (DataRow serviceUsedRow in tempRowList2) { serviceUsedRow["nPackageID"] = memberPackageRow["nPackageID"]; } } if (tempRowList.Length > 0 || tempRowList2.Length > 0) { //update the expiryDate TblPackage package = new TblPackage(); package.MainConnectionProvider = connProvider; package.StrPackageCode = strPackageCode; DataTable tablePackage = package.SelectOne(); TblPackageExtension PackExtension = new TblPackageExtension(); PackExtension.MainConnectionProvider = connProvider; PackExtension.NPackageID = ACMS.Convert.ToInt32(rowNewAddMemberPackage[0]["nPackageID"]); PackExtension.NPackageIDOld = wantToUpgrade_nPackageID; int days = 0; DataTable tblPkgExt = PackExtension.SelectExtensionDays(); if (PackExtension.NDaysExtended.IsNull == false) days = System.Convert.ToInt32(PackExtension.NDaysExtended.Value); if (tablePackage == null && tablePackage.Rows.Count == 0) throw new Exception("Package no found."); if (tempRowList.Length > 0 && tempRowList2.Length == 0) { ///07/11/2012 Jackie DataTable myDataTable1; DateTime dtDate; ACMSDAL.TblClassAttendance ClassAttendance = new ACMSDAL.TblClassAttendance(); myDataTable1 = ClassAttendance.LoadData("Select top 1 dtDate From tblClassAttendance where nstatusid=1 and nPackageID= " + wantToUpgrade_nPackageID + " and " + " strMemberShipID = @strMembershipID order by dtDate", new string[] { "@strMembershipID" }, new object[] { pos.StrMembershipID }); dtDate = DateTime.Now; if (myDataTable1.Rows.Count > 0) dtDate = System.Convert.ToDateTime(myDataTable1.Rows[0][0]); memberPackageRow["DtStartDate"] = dtDate; // Stop memberPackageRow["DtExpiryDate"] = ACMS.Convert.ToDateTime( memberPackageRow["DtStartDate"]).AddMonths(ACMS.Convert.ToInt32(package.NPackageDuration.Value)).AddDays(days - 1); } else if (tempRowList2.Length > 0 && tempRowList.Length == 0) { memberPackageRow["DtStartDate"] = ACMS.Convert.ToDateTime(tempRowList2[0]["dtDate"]); memberPackageRow["DtExpiryDate"] = ACMS.Convert.ToDateTime( memberPackageRow["DtStartDate"]).AddMonths(ACMS.Convert.ToInt32(package.NValidMonths.Value)).AddDays(days - 1); } } } OriginalCategoryID= ACMS.Convert.ToDBInt32(pos.WantToUpgradeMemberPackageRow["nCategoryID"]) ; pos.WantToUpgradeMemberPackageRow["nStatusID"] = 2; serviceSession.UpgradePackage(ACMS.Convert.ToInt32(rowNewAddMemberPackage[0]["nPackageID"]), wantToUpgrade_nPackageID, pos.StrMembershipID); memberPackage.SaveData(pos.WantToUpgradeMemberPackageTable); memberPackage.SaveData(newAddMemberPackageTable); classAttendance.SaveData(wantToUpgrade_nPackageID,pos.StrMembershipID); } return OriginalCategoryID; }
public DataTable GetMemberServiceSessionBasePackageID(int nPackageID, string strMemberShipID, string strBranchCode) { TblServiceSession serviceSession = new TblServiceSession(); return serviceSession.GetMemberServiceSessionBasePackageID(nPackageID, strMemberShipID, strBranchCode); }