Esempio n. 1
0
        public void DeleteLastExtensionHistory(int nPackageID, int last_nExtensionID)
        {
            myMemberPackage.NPackageID = nPackageID;
            myMemberPackage.SelectOne();

            TblPackageExtension packageExt = new TblPackageExtension();
            packageExt.NPackageID = nPackageID;
            DataTable packageExtTable = packageExt.SelectAllWnPackageIDLogic();

            if (packageExtTable == null)
                throw new Exception("This extension row has been deleted by others");
            if (packageExtTable.Rows.Count == 0)
                throw new Exception("This extension row has been deleted by others");

            if (packageExtTable.Rows.Count > 0)
            {
                DataRow [] rowList = packageExtTable.Select(" nStatusID = 0 AND nExtensionID > " + last_nExtensionID.ToString());
                if (rowList.Length > 0) // mean is not last package extension
                {
                    throw new Exception("Only the most recent package extension can be deleted.");
                }
            }

            DataRow[] deletedDataRowList = packageExtTable.Select("nStatusID = 0 and nExtensionID = " + last_nExtensionID, "nExtensionID", DataViewRowState.CurrentRows);
            if (deletedDataRowList.Length == 0)
                throw new Exception("This extension row has been deleted by others");
            //deletedDataRowList should be one row
            deletedDataRowList[0]["nStatusID"] = 1;
            TimeSpan durationToReverse = TimeSpan.FromDays((double) ACMS.Convert.ToInt32(deletedDataRowList[0]["nDaysExtended"]));

            DataRow[] tempDataRowList = packageExtTable.Select("nStatusID = 0", "nExtensionID", DataViewRowState.CurrentRows);
            // now need to use the last row's info to calculate the expriry date.
            // but if there is the only row in extension package for this member package, i have to use other info to calculate the expiry date for this memberpackage

            myMemberPackage.DtExpiryDate = myMemberPackage.DtExpiryDate.Value.Subtract(durationToReverse);

            ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider();

            try
            {
                myMemberPackage.MainConnectionProvider = connProvider;
                packageExt.MainConnectionProvider = connProvider;
                connProvider.OpenConnection();
                connProvider.BeginTransaction("SaveExtension");
                myMemberPackage.Update();
                packageExt.SaveData(packageExtTable);
                connProvider.CommitTransaction();
            }
            catch (Exception)
            {
                connProvider.RollbackTransaction("SaveExtension");
                throw new Exception("Failed to Create New Extension");
            }
            finally
            {
                if (connProvider.CurrentTransaction != null)
                    connProvider.CurrentTransaction.Dispose();
                if (connProvider.DBConnection != null)
             		{
                    if (connProvider.DBConnection.State == ConnectionState.Open)
                        connProvider.DBConnection.Close();
                }
                myMemberPackage.MainConnactionIsCreatedLocal = true;
                packageExt.MainConnactionIsCreatedLocal = true;
            }
        }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
        public void UpdateExtensionHistory(int last_nExtensionID, DateTime startDate, 
			DateTime endDate, int nReasonID, DateTime newExpiryDate)
        {
            int iReasonID = 0;
            TblPackageExtension packageExt = new TblPackageExtension();

            packageExt.NExtensionID = last_nExtensionID;
            DataTable packageExtensionTable = packageExt.SelectOne();
            if (packageExtensionTable.Rows.Count == 0)
                throw new Exception("This extension row has been deleted by others");
            if (packageExt.NStatusID.Value == 1)
                throw new Exception("This extension row has been deleted by others");

            packageExt.DtStartDate = startDate;
            packageExt.DtEndDate = endDate;
            packageExt.NReasonID = nReasonID;

            SaveExtensionHistory(packageExt.NPackageID.Value, packageExtensionTable, newExpiryDate,false, startDate, endDate, iReasonID);
        }
Esempio n. 4
0
        //public void SaveExtensionHistory(int nPackageID, DataTable packageExtensionTable, DateTime oldExpiryDate)
        public void SaveExtensionHistory(int nPackageID, DataTable packageExtensionTable, DateTime oldExpiryDate, bool isGiro, DateTime StartDate, DateTime EndDate, int iReasonID)
        {
            // *TO Do -- if dtStartDate is null, no allow extend
            DataRow packExtRow = packageExtensionTable.Rows[0];
            int nReasonID=0;
            if (iReasonID != 0)
                nReasonID = iReasonID;
            else
                nReasonID = ACMS.Convert.ToInt32(packExtRow["nReasonID"]);

            if (nReasonID < 0)
                return;
            // Assume that nReasonID = 0 is Others

            TblPackageExtension packageExt = new TblPackageExtension();
            ACMSDAL.ConnectionProvider connProvider = new ConnectionProvider();

            if (nReasonID > 0)
            {
                try
                {
                    myMemberPackage.MainConnectionProvider = connProvider;
                    packageExt.MainConnectionProvider = connProvider;

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

                        DateTime packageExtensionStartDate;
                        DateTime packageExtensionEndDate;

                        if (isGiro == true)
                    {
                        packExtRow["dtStartDate"] = StartDate;
                        packExtRow["dtEndDate"] = EndDate;
                        packageExtensionStartDate = StartDate;
                        packageExtensionEndDate = EndDate;
                    }
                    else
                    {
                            //to support extension for multiple package at once
                        if (StartDate.ToString() != "" && EndDate.ToString() != "")
                        {
                            // C=Leave Start Date
                            packageExtensionStartDate = Convert.ToDateTime(StartDate);
                            // D=Leave End Date
                            packageExtensionEndDate = Convert.ToDateTime(EndDate);
                        }
                        else
                        {
                            // C=Leave Start Date
                            packageExtensionStartDate = ACMS.Convert.ToDateTime(packExtRow["dtStartDate"]);
                            // D=Leave End Date
                            packageExtensionEndDate = ACMS.Convert.ToDateTime(packExtRow["dtEndDate"]);
                        }
                    }

                    //B4 Save, must Check whether the startdate have overlap with previous one or not
                    packageExt.NPackageID = nPackageID;
                    DataTable table = packageExt.SelectAllWnPackageIDLogic();
                    if (table != null && table.Rows.Count > 0)
                    {
            //						DataRow[] tempRow = table.Select("nStatusID = 0 and dtEndDate > '" + packageExtensionStartDate + "'", "nExtensionID");
            //						if (tempRow.Length > 0)
            //							throw new Exception("Overlapped date in extension package.");
                        int RowExtention;
                        DateTime e = packageExtensionStartDate;
                        DateTime f = packageExtensionEndDate;
                        for (RowExtention = 0; RowExtention <= table.Rows.Count-1; RowExtention++)
                        {
                            if (e < ACMS.Convert.ToDateTime(table.Rows[RowExtention]["dtEndDate"]) && f >= ACMS.Convert.ToDateTime(table.Rows[RowExtention]["dtStartDate"])
                                || (f < e))
                            {
                            throw new Exception("Overlapped date in extension package.");
                            }
                        }

                    }
                    //end checking

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

                    if  (myMemberPackage.DtStartDate.IsNull)
                        throw new Exception("Member Package not been used yet.");

                    if  (memberPackageTable.Rows[0]["DtStartDate"] == DBNull.Value)
                        return;

                    //bool isGiro = !myMemberPackage.NGIRORefID.IsNull;

                    // A=Member Package Start Date
                    DateTime memberPackageStartDate = myMemberPackage.DtStartDate.Value;
                    // B=Member Package End Date
                    DateTime memberPackageExpiryDate = myMemberPackage.DtExpiryDate.Value;
                    DateTime memberPackagePurchaseDate = myMemberPackage.DtPurchaseDate.Value;

                    //if (packageExtensionStartDate > memberPackageExpiryDate)
                    //	throw new Exception("Extension Start Date is not allow to later than Member Package's Expiry Date.");

                    if (isGiro == false)
                    {
                        if (packageExtensionStartDate > memberPackageExpiryDate)
                            throw new Exception("Extension Start Date is not allow to later than Member Package's Expiry Date.");

                        DateTime latestNewExpiryDate = DateTime.MinValue;

                        if ( packageExtensionStartDate > memberPackageStartDate)
                        {

                              DateTime latestExpiryDate = DateTime.ParseExact("2012-04-01", "yyyy'-'MM'-'dd", null);
                              if (memberPackagePurchaseDate > latestExpiryDate && nReasonID != 6)
                            {
                                TimeSpan duration = packageExtensionEndDate.Subtract(packageExtensionStartDate);

                                    if (2 > duration.Days )//01042012 Member only can apply extension with a minimun of 3 days
                                    {
                                        throw new Exception("Extension only can apply for minimun of 3 days.");
                                    }
                                    else
                                    {
                                        TimeSpan duration1 = packageExtensionEndDate.Subtract(packageExtensionStartDate);
                                        myMemberPackage.DtExpiryDate = myMemberPackage.DtExpiryDate.Value.Add(duration1).AddDays(1);
                                    }

                            }
                            else
                            {
                                           TimeSpan duration = packageExtensionEndDate.Subtract(packageExtensionStartDate);
                                            myMemberPackage.DtExpiryDate = myMemberPackage.DtExpiryDate.Value.Add(duration).AddDays(1);
                            }
                        }
                        else if (packageExtensionStartDate < memberPackageStartDate)
                        {
                            TimeSpan duration = packageExtensionEndDate.Subtract(memberPackageStartDate);
                            myMemberPackage.DtExpiryDate = myMemberPackage.DtExpiryDate.Value.Add(duration).AddDays(1);
                        }

                        myMemberPackage.DtLastEdit = System.DateTime.Now;
                        myMemberPackage.NEmployeeID = User.EmployeeID;
                    }
                    else
                    {
                        //int nGiroRefID = (int)myMemberPackage.NGIRORefID;
                        // if the member package is Giro
                        // then need to make sure all the extension is follow the base one

                        myMemberPackage.NPackageID = nPackageID;
                        DataTable tempTable = myMemberPackage.SelectAllWnGIROPackageIDLogic();

                        if (tempTable == null)
                            return;
                        if (tempTable.Rows.Count == 0)
                            return;

                        if (tempTable.Rows.Count > 1)
                        {
                            DataRow[] rowList = tempTable.Select("dtStartDate is not null", "nGiroRefID", DataViewRowState.CurrentRows);

                            if (rowList.Length > 0)
                            {
                                DateTime latestNewExpiryDate = DateTime.MinValue;
                                DateTime tempnewExpiryDate = DateTime.MinValue;

                                memberPackageStartDate = ACMS.Convert.ToDateTime(rowList[0]["dtStartDate"]);
                                memberPackageExpiryDate = ACMS.Convert.ToDateTime(rowList[0]["dtExpiryDate"]);

                                if (packageExtensionStartDate > memberPackageStartDate)
                                {
                                    TimeSpan duration = packageExtensionEndDate.Subtract(packageExtensionStartDate);
                                    tempnewExpiryDate = memberPackageExpiryDate.Add(duration).AddDays(1);
                                }
                                else if (packageExtensionStartDate < memberPackageStartDate)
                                {
                                    TimeSpan duration = packageExtensionEndDate.Subtract(memberPackageStartDate);
                                    tempnewExpiryDate = memberPackageExpiryDate.Add(duration).AddDays(1);
                                }

                                tempTable.BeginInit();
                                foreach (DataRow r in rowList)
                                {
                                    r["dtExpiryDate"] = tempnewExpiryDate;
                                    r["dtLastEdit"] = DateTime.Now;
                                    r["nEmployeeID"] = User.EmployeeID;
                                }
                                tempTable.EndInit();
                            }
                            else
                                return;
                        }
                        else
                        {
                            isGiro = false;
                            myMemberPackage.NPackageID = nPackageID;
                            myMemberPackage.SelectOne();
                            myMemberPackage.DtLastEdit = System.DateTime.Now;
                            myMemberPackage.NEmployeeID = User.EmployeeID;
                            DateTime latestNewExpiryDate = DateTime.MinValue;

                            if (packageExtensionStartDate > memberPackageStartDate)
                            {
                                TimeSpan duration = packageExtensionEndDate.Subtract(packageExtensionStartDate);
                                myMemberPackage.DtExpiryDate = myMemberPackage.DtExpiryDate.Value.Add(duration).AddDays(1);
                            }
                            else if (packageExtensionStartDate < memberPackageStartDate)
                            {
                                TimeSpan duration = packageExtensionEndDate.Subtract(memberPackageStartDate);
                                myMemberPackage.DtExpiryDate = myMemberPackage.DtExpiryDate.Value.Add(duration).AddDays(1);
                            }
                        }
                    }

                    //To support extension for multiple package at once
                    object dtEndValue = packExtRow["dtEndDate"];
                    object dtStartDate = packExtRow["dtEndDate"];
                    if (dtEndValue == DBNull.Value && dtStartDate == DBNull.Value)
                    {
                        packExtRow["dtEndDate"] = EndDate;
                        packExtRow["dtStartDate"] = StartDate;
                    }
                    TimeSpan nDaysExtend = ACMS.Convert.ToDateTime(packExtRow["dtEndDate"]).Subtract(ACMS.Convert.ToDateTime(packExtRow["dtStartDate"]));

                    packExtRow["nDaysExtended"] = nDaysExtend.TotalDays+1;
                    packExtRow["dtOldExpiry"]=oldExpiryDate;
                    packExtRow["dtNewExpiry"]=	oldExpiryDate.AddDays(nDaysExtend.TotalDays+1);
                    packExtRow["dtCreateDate"] = System.DateTime.Now; //jackie 14032012
                    if (nReasonID != 0)
                        packExtRow["nReasonID"] = nReasonID;

                    packExtRow["nDaysExtended"]=(nDaysExtend.TotalDays)+1;
                    #region ====== Added By Albert ======
                    //To update member package status. If expiry date is greater than today date, change the status to active.
                    DateTime dtExpireDate = Convert.ToDateTime(myMemberPackage.DtExpiryDate.ToString());
                    if(DateTime.Compare(dtExpireDate,DateTime.Now)>0)
                        myMemberPackage.NStatusID = 0;
                    #endregion
                    myMemberPackage.Update();

                    packageExt.SaveData(packageExtensionTable);

                    connProvider.CommitTransaction();
                }
                catch (Exception ex)
                {
                    connProvider.RollbackTransaction("SaveExtension");
                    throw ex;
                }
                finally
                {
                    if (connProvider.CurrentTransaction != null)
                        connProvider.CurrentTransaction.Dispose();
                    if (connProvider.DBConnection != null)
                    {
                        if (connProvider.DBConnection.State == ConnectionState.Open)
                            connProvider.DBConnection.Close();
                    }
                    myMemberPackage.MainConnactionIsCreatedLocal = true;
                    packageExt.MainConnactionIsCreatedLocal = true;
                }
            }
            else
            {
                try
                {
                    myMemberPackage.MainConnectionProvider = connProvider;
                    packageExt.MainConnectionProvider = connProvider;

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

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

                    if (myMemberPackage.DtStartDate.IsNull)
                        throw new Exception("Member Package is yet been used. No need to extend");

                    myMemberPackage.DtExpiryDate = oldExpiryDate;
                    myMemberPackage.DtLastEdit = System.DateTime.Today;
                    myMemberPackage.NEmployeeID = User.EmployeeID;
                    //packageExt
                    packExtRow["dtStartDate"] = myMemberPackage.DtStartDate.Value;
                    packExtRow["dtEndDate"] =  myMemberPackage.DtExpiryDate.Value;
                    packExtRow["nDaysExtended"] = myMemberPackage.DtExpiryDate.Value.CompareTo(myMemberPackage.DtStartDate.Value);

                    packageExt.SaveData(packageExtensionTable);
                    myMemberPackage.Update();

                    connProvider.CommitTransaction();
                }
                catch (Exception ex)
                {
                    connProvider.RollbackTransaction("SaveExtension");
                    throw ex;
                }
                finally
                {
                    if (connProvider.CurrentTransaction != null)
                        connProvider.CurrentTransaction.Dispose();
                    if (connProvider.DBConnection != null)
                    {
                        if (connProvider.DBConnection.State == ConnectionState.Open)
                            connProvider.DBConnection.Close();
                    }
                    myMemberPackage.MainConnactionIsCreatedLocal = true;
                    packageExt.MainConnactionIsCreatedLocal = true;
                }
            }
        }
Esempio n. 5
0
        public DataTable NewExtensionHistory(int nPackageID)
        {
            TblPackageExtension packageExt = new TblPackageExtension();
            packageExt.NExtensionID = -1;
            DataTable table = packageExt.SelectOne();

            DataRow row = table.NewRow();
            row["nPackageID"] = nPackageID;
            row["nEmployeeID"] = ACMSLogic.User.EmployeeID;
            row["nStatusID"] = 0;
            row["strRemarks"]="";
            table.Rows.Add(row);
            return table;
        }
Esempio n. 6
0
 public DataTable GetExtensionHistoryBasePackageID(int nPackageID)
 {
     TblPackageExtension packageExt = new TblPackageExtension();
     return packageExt.GetActivePackageExtension(nPackageID);
 }
Esempio n. 7
0
 public DataTable GetExtensionHistoryBaseExtensionID(int nExtensionID)
 {
     TblPackageExtension packageExt = new TblPackageExtension();
     packageExt.NExtensionID = nExtensionID;
     return packageExt.SelectOne();
 }