/// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static Business.Investor sFacadeAddNewInvestor(int InvestorStatusID, int InvestorGroupID, string AgentID, double Balance, double Credit, string Code, string Pwd,
                                                double TaxRate, double Leverage, string Address, string Phone,
                                                string City, string Country, string Email, string ZipCode,string State,
                                                string NickName)
        {
            if (Business.Market.IsRealSearver)
                return null;

            Business.Investor objInvestor = new Business.Investor();
            objInvestor.InvestorStatusID = InvestorStatusID;
            //objInvestor.InvestorGroupInstance = TradingServer.Facade.FacadeGetInvestorGroupByInvestorGroupID(InvestorGroupID);

            string tempDefaultGroupName = string.Empty;
            if (Business.Market.MarketConfig != null)
            {
                int countMarketConfig = Business.Market.MarketConfig.Count;
                for (int i = 0; i < countMarketConfig; i++)
                {
                    if (Business.Market.MarketConfig[i].Code == "C33")
                    {
                        tempDefaultGroupName = Business.Market.MarketConfig[i].StringValue;
                    }
                }
            }

            double tempDefaultDeposit = 0;

            bool isExists = false;
            if (Business.Market.InvestorGroupList != null)
            {
                int count = Business.Market.InvestorGroupList.Count;
                for (int i = 0; i < count; i++)
                {
                    if (Business.Market.InvestorGroupList[i].Name.Trim().ToUpper() == tempDefaultGroupName.Trim().ToUpper())
                    {
                        if (Business.Market.InvestorGroupList[i].ParameterItems != null)
                        {
                            int countConfig = Business.Market.InvestorGroupList[i].ParameterItems.Count;
                            for (int j = 0; j < countConfig; j++)
                            {
                                if (Business.Market.InvestorGroupList[i].ParameterItems[j].Code == "G24")
                                    double.TryParse(Business.Market.InvestorGroupList[i].ParameterItems[j].StringValue, out tempDefaultDeposit);
                            }
                        }

                        objInvestor.InvestorGroupInstance = Business.Market.InvestorGroupList[i];
                        break;
                    }
                }
            }

            objInvestor.AgentID = AgentID;

            if (tempDefaultDeposit > 0)
                objInvestor.Balance = tempDefaultDeposit;
            else
                objInvestor.Balance = Balance;

            objInvestor.Credit = Credit;

            int ranCode = -1;

            //bool CheckCode = false;
            //while (!CheckCode)
            //{
            //    Random ran = new Random();
            //    ranCode = ran.Next(0000000, 9999999);

            //    CheckCode = TradingServer.Facade.FacadeGetInvestorByCode(ranCode.ToString());
            //}

            string rendCode = TradingServer.Model.TradingCalculate.Instance.GetNextRandomCode();

            bool CheckCode = false;
            CheckCode = TradingServer.Facade.FacadeGetInvestorByCode(rendCode);

            //objInvestor.Code = ranCode.ToString();
            objInvestor.Code = rendCode;
            objInvestor.PrimaryPwd = Pwd;
            objInvestor.ReadOnlyPwd = Pwd;
            objInvestor.PhonePwd = Pwd;
            objInvestor.IsDisable = false;
            objInvestor.TaxRate = TaxRate;

            objInvestor.Leverage = Leverage;
            objInvestor.Address = Address;
            objInvestor.Phone = Phone;
            objInvestor.City = City;
            objInvestor.Country = Country;
            objInvestor.Email = Email;
            objInvestor.ZipCode = "NaN";
            objInvestor.RegisterDay = DateTime.Now;
            objInvestor.InvestorComment = "Demo Account";
            objInvestor.State = "NaN";
            objInvestor.NickName = NickName;
            objInvestor.SendReport = true;
            objInvestor.AllowChangePwd = true;
            objInvestor.UserConfig = "";

            string primaryPwd = objInvestor.PrimaryPwd;

            string temp = TradingServer.Model.ValidateCheck.Encrypt(objInvestor.PrimaryPwd);
            objInvestor.PrimaryPwd = temp;
            objInvestor.ReadOnlyPwd = temp;
            objInvestor.PhonePwd = temp;

            double tempBalance = objInvestor.Balance;
            objInvestor.Balance = 0;

            objInvestor.InvestorID = TradingServer.Facade.FacadeAddNewInvestor(objInvestor);

            if (objInvestor.InvestorID > 0)
            {
                int resultProfileID = TradingServer.Facade.FacadeAddInvestorProfile(objInvestor);

                objInvestor.InvestorProfileID = resultProfileID;

                Business.Market.InvestorList.Add(objInvestor);

                TradingServer.Facade.FacadeAddDeposit(objInvestor.InvestorID, tempBalance, "[add deposit create account]");
            }

            //SEND MAIL IF CREATE NEW INVESTOR COMPLETE
            if (objInvestor.InvestorID > 0)
            {
                #region SEND MAIL CREATE ACCOUNT
                Model.MailConfig newMailConfig = new Model.MailConfig();
                newMailConfig = TradingServer.Facade.FacadeGetMailConfig(objInvestor);

                //string header = "<!DOCTYPE html PUBLIC" + '"' + "-//W3C//DTD XHTML 1.0 Transitional//EN" + '"' + '"' + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd +" + '"' + ">" +
                //        "<html xmlns=" + '"' + "http://www.w3.org/1999/xhtml" + '"' + "><head><meta content=" + '"' + "text/html; charset=utf-8" + '"' + "http-equiv=" + '"' + "Content-Type" + '"' + "/>" +
                //        "<title>Confirmation Mail</title><style type=" + '"' + "text/css" + '"' + ">a{	text-decoration:none;color:#333333;	} a:hover{	color:#156a9d;text-decoration:underline;}</style> " +
                //        "<script type=" + '"' + "text/javascript" + '"' + "></script></head><body style=" + '"' + "font-family:Arial;font-size:12px;color:#333333;width:500px;margin-left:auto;margin-right:auto;" + '"' + ">" +
                //        "<div id=" + '"' + "header" + '"' + "style=" + '"' + "width:500px;height:70px;border-bottom:2px #dddddd solid;border-top:2px #dddddd solid;background-color:#f9f9f9;background-image:url('http://et5.mpf.co.id/img/mpflogo.png');background-repeat:no-repeat" + '"' + ">" +
                //        "</div><div style=" + '"' + "background-color:white;width:90%;color:#333333;margin:15px;" + '"' + "><b>Dear " +
                //        objInvestor.NickName + "</b>,<br/><br/>" +
                //        "<span style='color:#156a9d;font-weight:bold'>Your demo account has been activated !</span><br/><br/>" +
                //        "Please, keep your login credentials for future access :<br/><br/><table>";

                //string userandpass = "******" + objInvestor.Code + "</td></tr>" +
                //    "<tr><td style='width:100px'>Password :</td><td>" + primaryPwd + "</td></tr>";

                //string bottom = "<tr><td style='width:100px'>Access :</td><td><a href='http://et5.mpf.co.id'>http://et5.mpf.co.id</a></td></tr> " +
                //    "</table><br/><span style='color:#156a9d;font-weight:bold'>Best Regards,</span><br/>Millennium Penata Futures Customer Service<br/>" +
                //    "Contact us anytime: <a href='mailto:[email protected]'>[email protected]</a><br/><br/></div>" +
                //    "<div style='background-color:#f7f7f7;width:480px;border-top:2px #dddddd solid;border-bottom:2px #dddddd solid;padding:10px;'>" +
                //    "<span style='color:#156a9d;font-weight:bold'>PT. Millennium Penata Futures </span>is the first financial institution offering online-based  investment business in Indonesia. Through years of trial, we succeeded in finding an online system that provides data and news in realtime mode." +
                //    "</div><div style='width:490px;padding:5px;font-size:10px;text-align:right'>© Copyright 2011. PT. Millennium Penata Futures</div></body></html>";

                //string content = header + userandpass + bottom;

                StringBuilder content = new StringBuilder();
                Business.ConfirmationTemplate newTemplate = new Business.ConfirmationTemplate();
                content = newTemplate.GetConfirmation();
                content.Replace("[#LinkLogo]", "http://et5.mpf.co.id/img/mpflogo.png");
                content.Replace("[#FullName]", objInvestor.NickName);
                content.Replace("[#AccountType]", "demo account");
                content.Replace("[#UserName]", objInvestor.Code);
                content.Replace("[#Password]", primaryPwd);
                content.Replace("[#Website]", "http://et5.mpf.co.id");
                content.Replace("[#AccessLink]","http://et5.mpf.co.id");
                content.Replace("[#ServiceName]","Millennium Penata Futures Customer Service");
                content.Replace("[#MailSupport]","mailto:[email protected]");
                content.Replace("[#EmailContact]","*****@*****.**");
                content.Replace("[#CompanyName]","PT. Millennium Penata Futures ");
                content.Replace("[#CompanyIntroduct]","is the first financial institution offering online-based  investment business in Indonesia. Through years of trial, we succeeded in finding an online system that provides data and news in realtime mode.");
                content.Replace("[#CompanyCopyright]","PT. Millennium Penata Futures");

                TradingServer.Model.TradingCalculate.Instance.SendMail(objInvestor.Email, "CONFIRMATION EMAIL", content.ToString(), newMailConfig);
                #endregion
            }

            Business.Investor newInvestor = new Business.Investor();
            if (objInvestor.InvestorID > 0)
            {
                //newInvestor.Code = ranCode.ToString();
                newInvestor.Code = rendCode;
                newInvestor.PrimaryPwd = primaryPwd;
                newInvestor.ReadOnlyPwd = primaryPwd;
                newInvestor.PhonePwd = primaryPwd;
                newInvestor.IsDisable = false;
                newInvestor.TaxRate = TaxRate;
                newInvestor.Leverage = Leverage;
                newInvestor.Address = Address;
                newInvestor.Phone = Phone;
                newInvestor.City = City;
                newInvestor.Country = Country;
                newInvestor.Email = Email;
                newInvestor.ZipCode = "NaN";
                newInvestor.RegisterDay = DateTime.Now;
                newInvestor.InvestorComment = "Demo Account";
                newInvestor.State = "NaN";
                newInvestor.NickName = NickName;
                newInvestor.SendReport = true;
                newInvestor.InvestorID = objInvestor.InvestorID;
            }

            //SEND NOTIFY TO MANAGER
            //TradingServer.Facade.FacadeSendNotifyManagerRequest(3, newInvestor);
            //TradingServer.Facade.FacadeAutoSendMailRegistration(newInvestor);
            return newInvestor;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static Business.Investor FacadeAddNewInvestor(int InvestorStatusID, int InvestorGroupID, string AgentID, double Balance, double Credit, string Code, string Pwd,
                                                double TaxRate, double Leverage, string Address, string Phone,
                                                string City, string Country, string Email, string ZipCode, string State,
                                                string NickName,string key)
        {
            Business.Investor objInvestor = new Business.Investor();
            objInvestor.InvestorStatusID = InvestorStatusID;
            //objInvestor.InvestorGroupInstance = TradingServer.Facade.FacadeGetInvestorGroupByInvestorGroupID(InvestorGroupID);

            string tempDefaultGroupName = string.Empty;

            if (Business.Market.MarketConfig != null)
            {
                int countMarketConfig = Business.Market.MarketConfig.Count;
                for (int i = 0; i < countMarketConfig; i++)
                {
                    if (Business.Market.MarketConfig[i].Code == "C34")
                    {
                        string[] subValue = Business.Market.MarketConfig[i].StringValue.Split('`');

                        #region PROCESS DOMAIN CLIENT
                        string[] subKey = key.Split('/');

                        string tempKey = string.Empty;

                        if (subKey.Length > 2)
                        {
                            tempKey = subKey[2];
                        }
                        else
                        {
                            tempKey = subKey[0];
                        }

                        tempKey = tempKey.Replace("http://", string.Empty);
                        tempKey = tempKey.Replace("www.", string.Empty);
                        tempKey = tempKey.Replace("/", string.Empty);
                        tempKey = tempKey.Replace("?", string.Empty);
                        #endregion

                        #region PROCESS DOMAIN SERVER
                        string[] subDomain = subValue[0].Split('/');
                        string tempDomainServer = string.Empty;
                        if (subDomain.Length == 4)
                        {
                            tempDomainServer = subDomain[2];
                        }
                        else
                        {
                            tempDomainServer = subDomain[0];
                        }

                        tempDomainServer = tempDomainServer.Replace("http://", string.Empty);
                        tempDomainServer = tempDomainServer.Replace("www.", string.Empty);
                        tempDomainServer = tempDomainServer.Replace("/", string.Empty);
                        tempDomainServer = tempDomainServer.Replace("?", string.Empty);
                        #endregion

                        if (key.ToUpper().Trim() == tempDomainServer.ToUpper().Trim())
                        {
                            tempDefaultGroupName = subValue[1];

                            break;
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(tempDefaultGroupName))
            {
                int countMarketConfig = Business.Market.MarketConfig.Count;
                for (int i = 0; i < countMarketConfig; i++)
                {
                    if (Business.Market.MarketConfig[i].Code == "C33")
                    {
                        tempDefaultGroupName = Business.Market.MarketConfig[i].StringValue;
                        break;
                    }
                }
            }

            bool isExists = false;
            double tempDepositDefault = 0;

            if (Business.Market.InvestorGroupList != null)
            {
                int count = Business.Market.InvestorGroupList.Count;
                for (int i = 0; i < count; i++)
                {
                    if (Business.Market.InvestorGroupList[i].Name.Trim().ToUpper() == tempDefaultGroupName.Trim().ToUpper())
                    {
                        if (Business.Market.InvestorGroupList[i].ParameterItems != null)
                        {
                            int countConfig = Business.Market.InvestorGroupList[i].ParameterItems.Count;
                            for (int j = 0; j < countConfig; j++)
                            {
                                if (Business.Market.InvestorGroupList[i].ParameterItems[j].Code == "G24")
                                {
                                    double.TryParse(Business.Market.InvestorGroupList[i].ParameterItems[j].StringValue, out tempDepositDefault);

                                    break;
                                }
                            }
                        }
                        objInvestor.InvestorGroupInstance = Business.Market.InvestorGroupList[i];
                        break;
                    }
                }
            }

            objInvestor.AgentID = AgentID;

            if (tempDepositDefault > 0)
                objInvestor.Balance = tempDepositDefault;
            else
                objInvestor.Balance = Balance;

            objInvestor.Credit = Credit;

            int ranCode = -1;

            //bool CheckCode = false;
            //while (!CheckCode)
            //{
            //    Random ran = new Random();
            //    ranCode = ran.Next(0000000, 9999999);

            //    CheckCode = TradingServer.Facade.FacadeGetInvestorByCode(ranCode.ToString());
            //}

            string rendCode = TradingServer.Model.TradingCalculate.Instance.GetNextRandomCode();

            bool CheckCode = false;
            CheckCode = TradingServer.Facade.FacadeGetInvestorByCode(rendCode);

            //objInvestor.Code = ranCode.ToString();
            objInvestor.Code = rendCode;
            objInvestor.PrimaryPwd = Pwd;
            objInvestor.ReadOnlyPwd = Pwd;
            objInvestor.PhonePwd = Pwd;
            objInvestor.IsDisable = false;
            objInvestor.TaxRate = TaxRate;
            objInvestor.Leverage = Leverage;
            objInvestor.Address = Address;
            objInvestor.Phone = Phone;
            objInvestor.City = City;
            objInvestor.Country = Country;
            objInvestor.Email = Email;
            objInvestor.ZipCode = "NaN";
            objInvestor.RegisterDay = DateTime.Now;
            objInvestor.InvestorComment = "Demo Account";
            objInvestor.State = "NaN";
            objInvestor.NickName = NickName;
            objInvestor.SendReport = true;
            objInvestor.AllowChangePwd = true;
            objInvestor.UserConfig = "";

            string primaryPwd = objInvestor.PrimaryPwd;

            string temp = TradingServer.Model.ValidateCheck.Encrypt(objInvestor.PrimaryPwd);
            objInvestor.PrimaryPwd = temp;
            objInvestor.ReadOnlyPwd = temp;
            objInvestor.PhonePwd = temp;

            double tempBalance = objInvestor.Balance;
            objInvestor.Balance = 0;

            objInvestor.InvestorID = TradingServer.Facade.FacadeAddNewInvestor(objInvestor);

            if (objInvestor.InvestorID > 0)
            {
                int resultProfileID = TradingServer.Facade.FacadeAddInvestorProfile(objInvestor);

                objInvestor.InvestorProfileID = resultProfileID;

                Business.Market.InvestorList.Add(objInvestor);

                TradingServer.Facade.FacadeAddDeposit(objInvestor.InvestorID, tempBalance, "[add deposit create account]");
            }

            //SEND MAIL IF CREATE NEW INVESTOR COMPLETE
            if (objInvestor.InvestorID > 0)
            {
                #region SEND MAIL CREATE ACCOUNT
                Model.MailConfig newMailConfig = new Model.MailConfig();
                newMailConfig = TradingServer.Facade.FacadeGetMailConfig(objInvestor);

                StringBuilder content = new StringBuilder();
                Business.ConfirmationTemplate newTemplate = new Business.ConfirmationTemplate();
                content = newTemplate.GetConfirmation();
                content.Replace("[#LinkLogo]", "http://et5.mpf.co.id/img/mpflogo.png");
                content.Replace("[#FullName]", objInvestor.NickName);
                content.Replace("[#AccountType]", "demo account");
                content.Replace("[#UserName]", objInvestor.Code);
                content.Replace("[#Password]", primaryPwd);
                content.Replace("[#Website]", "http://demo.efxgm.com");
                //content.Replace("[#Website]", Business.Market.CompanyWebsite);
                content.Replace("[#AccessLink]", "http://demo.efxgm.com");
                //content.Replace("[#AccessLink]", Business.Market.AccessLink);
                content.Replace("[#ServiceName]", "EFXGM Customer Service");
                //content.Replace("[#ServiceName]", Business.Market.ServiceName);
                content.Replace("[#MailSupport]", "mailto:[email protected]");
                //content.Replace("[#MailSupport]", Business.Market.MailSupport);
                content.Replace("[#EmailContact]", "*****@*****.**");
                //content.Replace("[#EmailContact]", Business.Market.MailContact);
                //content.Replace("[#CompanyName]", "PT. Millennium Penata Futures ");
                //content.Replace("[#CompanyIntroduct]", "is the first financial institution offering online-based  investment business in Indonesia. Through years of trial, we succeeded in finding an online system that provides data and news in realtime mode.");
                content.Replace("[#CompanyCopyright]", "EFXGM");
                //content.Replace("[#CompanyCopyright]", Business.Market.CompanyCopyright);

                TradingServer.Model.TradingCalculate.Instance.SendMail(objInvestor.Email, "CONFIRMATION EMAIL", content.ToString(), newMailConfig);
                #endregion
            }

            Business.Investor newInvestor = new Business.Investor();
            if (objInvestor.InvestorID > 0)
            {
                //newInvestor.Code = ranCode.ToString();
                newInvestor.Code = rendCode;
                newInvestor.PrimaryPwd = primaryPwd;
                newInvestor.ReadOnlyPwd = primaryPwd;
                newInvestor.PhonePwd = primaryPwd;
                newInvestor.IsDisable = false;
                newInvestor.TaxRate = TaxRate;
                newInvestor.Leverage = Leverage;
                newInvestor.Address = Address;
                newInvestor.Phone = Phone;
                newInvestor.City = City;
                newInvestor.Country = Country;
                newInvestor.Email = Email;
                newInvestor.ZipCode = "NaN";
                newInvestor.RegisterDay = DateTime.Now;
                newInvestor.InvestorComment = "Demo Account";
                newInvestor.State = "NaN";
                newInvestor.NickName = NickName;
                newInvestor.SendReport = true;
                newInvestor.InvestorID = objInvestor.InvestorID;
            }

            //SEND NOTIFY TO MANAGER
            //TradingServer.Facade.FacadeSendNotifyManagerRequest(3, newInvestor);
            //TradingServer.Facade.FacadeAutoSendMailRegistration(newInvestor);
            return newInvestor;
        }