protected void btnCheckSecurityCode_Click(object sender, EventArgs e)
        {
            strUserID = Session[clsSystem_Session.strSession.User.ToString()].ToString();

            //try 
            //{
                if (!txtSecurityCode.Text.Equals(string.Empty))
                {
                    strClientID = Session[clsSystem_Session.strSession.clientID.ToString()].ToString();
                    strPortfolioID = Session[clsSystem_Session.strSession.tempportfolioid.ToString()].ToString();
                    int intSwitchID = (int)ViewState["intSwitchID"];

                    clsSecurityCode oSecurityCode = new clsSecurityCode(this.txtSecurityCode.Text.Trim());
                    string strSecurityCodeMessage = oSecurityCode.ValidateSecurityCode(intSwitchID, strClientID, strPortfolioID);

                    if (strSecurityCodeMessage.Contains("Sorry, the security code you have entered is incorrect, please re-enter the security code."))
                    {
                        this.mpeSecurityCodePanel.Show();
                    }
                    else if (strSecurityCodeMessage.Contains("Thank you, the proposed changes will be made to your portfolio."))
                    {
                        clsSwitchDetails.transferClientSwitchToIFA((List<clsSwitchDetails_Client>)Session["SwitchDetails_Client"], strUserID);

                        int intHistoryID = clsHistory.insertHeader(strPortfolioID, intSwitchID, (Int16)clsSwitch.enumSwitchStatus.Approved);
                        clsHistory.insertDetailsClient(intHistoryID, (List<clsSwitchDetails_Client>)Session["SwitchDetails_Client"]);
                        clsHistory.insertMessage(intHistoryID, new clsSwitch_Client(intSwitchID).propDescription);

                        NotifyApprovedSwtich(new clsPortfolio(strClientID, strPortfolioID, strUserID));

                        ClientScript.RegisterStartupScript(this.GetType(), "showApproveSwitch", string.Format("showApproveSwitchPanel();"), true);

                        showhideAmendArea(false);
                        showhideButtons(enumPageState.view);

                    }
                    ClientScript.RegisterStartupScript(this.GetType(), "alertMessage", string.Format("alert('{0}');", strSecurityCodeMessage), true);
                }

                clsPortfolio oPortfolio = new clsPortfolio(strClientID, strPortfolioID, strUserID);
                populateHeader(oPortfolio);
                populateProposedSwitch(oPortfolio.propSwitch.propSwitchDetails);
            //}
            //catch (Exception ex)
            //{
            //    string backPageURL = "https://" + Request.ServerVariables["SERVER_NAME"] + ":" + Request.ServerVariables["SERVER_PORT"] + "/report/" + "portfoliodetails.asp";
            //    ClientScript.RegisterStartupScript(this.GetType(), "alertApproveError", "alert('Error! " + ex.ToString().Replace("'", "") + "'); window.location='" + backPageURL + "';", true);
            //}
        }
 private string GenerateSecurityCode(int intSwitchID, string strClientID, string strPortfolioID)
 {
     string strSecurityCode = string.Empty;
     int intSecurityCode = 0;
     while (intSecurityCode == 0)
     {
         clsSecurityCode oSecurityCode = new clsSecurityCode(4);
         intSecurityCode = oSecurityCode.insertEncryptedCode(intSwitchID, strClientID, strPortfolioID);
         strSecurityCode = oSecurityCode.propSecurityCode;
     }
     return strSecurityCode;
 }
        protected void btnCheckSecurityCode_Click(object sender, EventArgs e)
        {
            String strUserID = Session[clsSystem_Session.strSession.User.ToString()].ToString();
            String strSchemeID = Session[clsSystem_Session.strSession.tempschemeid.ToString()].ToString();
            String strClientID = Session[clsSystem_Session.strSession.clientID.ToString()].ToString();

            int intSwitchID = propSwitchID;

            List<clsSwitchScheme_Client.clsSwitchSchemeDetails_Client> listSwitchDetailsPortfolio = (List<clsSwitchScheme_Client.clsSwitchSchemeDetails_Client>)Session["SwitchSchemeDetailsPortfolio_Client"];
            List<clsSwitchScheme_Client.clsSwitchSchemeDetails_Client> listSwitchDetailsContribution = (List<clsSwitchScheme_Client.clsSwitchSchemeDetails_Client>)Session["SwitchSchemeDetailsContribution_Client"];

            if (!txtSecurityCode.Text.Equals(string.Empty))
            {                

                if (listSwitchDetailsPortfolio == null) 
                { 
                    clsSwitchScheme_Client SwitchScheme_Client = new clsSwitchScheme_Client(intSwitchID);

                    listSwitchDetailsPortfolio = SwitchScheme_Client.propSwitchDetailsPortfolio;
                    listSwitchDetailsContribution = SwitchScheme_Client.propSwitchDetailsContribution;
                }

                clsSecurityCode oSecurityCode = new clsSecurityCode(this.txtSecurityCode.Text.Trim());
                string strSecurityCodeMessage = oSecurityCode.ValidateSecurityCodeScheme(intSwitchID, strClientID, strSchemeID);

                if (strSecurityCodeMessage.Contains("Sorry, the security code you have entered is incorrect, please re-enter the security code."))
                {
                    this.mpeSecurityCodePanel.Show();
                }
                else if (strSecurityCodeMessage.Contains("Thank you, the proposed changes will be made to your portfolio."))
                {
                    if (listSwitchDetailsPortfolio != null)
                    {
                        clsSwitchScheme.clsSwitchSchemeDetails.transferClientSwitchToIFA(listSwitchDetailsPortfolio, strUserID, false, true);
                        clsSwitchScheme.clsSwitchSchemeDetails.transferClientSwitchToIFA(listSwitchDetailsContribution, strUserID, true, false);
                    }

                    NotifyApprovedSwtich();

                    int intHistoryID = clsHistory.clsHistoryScheme.insertHeader(strSchemeID, intSwitchID, (Int16)clsSwitch.enumSwitchStatus.Approved);
                    clsHistory.clsHistoryScheme.insertDetailsClient(intHistoryID, listSwitchDetailsPortfolio, false);
                    clsHistory.clsHistoryScheme.insertDetailsClient(intHistoryID, listSwitchDetailsContribution, true);
                    clsHistory.clsHistoryScheme.insertMessage(intHistoryID, new clsSwitch_Client(intSwitchID).propDescription);

                    Page.ClientScript.RegisterStartupScript(this.GetType(), "alertCancelledSwitch", "alert('This Switch has been approved!'); window.location='" + this.propBackPageURL + "';", true);

                }
                else if (strSecurityCodeMessage.Contains("Sorry, you have entered the security code incorrectly three times"))
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "alertMessage", string.Format("alert('{0}'); window.location='" + this.propBackPageURL + "'; ", strSecurityCodeMessage), true);
                }

                Page.ClientScript.RegisterStartupScript(this.GetType(), "alertMessage", string.Format("alert('{0}'); ", strSecurityCodeMessage), true);
            }            

            populate(listSwitchDetailsPortfolio, false);
            populate(listSwitchDetailsContribution, true);

        }