} // Create ()
        //------------

        private static Account BuildFromSqlDataReader(SqlDataReader i_sqlDataReader)
        {
            Account l_result;

            l_result = new Account();
            l_result.AddressCity = (string)i_sqlDataReader["AddressCity"];
            if ( i_sqlDataReader["AddressNumber"] != DBNull.Value )
            {
                l_result.AddressNumber = (string)i_sqlDataReader["AddressNumber"];    
            }            
            l_result.AddressPostCode = (string)i_sqlDataReader["AddressPostCode"];
            l_result.AddressStreet = (string)i_sqlDataReader["AddressStreet"];
            l_result.CountryId = (int)i_sqlDataReader["CountryId"];
            l_result.DateOfBirth = (DateTime)i_sqlDataReader["DateOfBirth"];
            l_result.DateOfRegistration = (DateTime)i_sqlDataReader["DateOfRegistration"];
            l_result.Email = (string)i_sqlDataReader["Email"];
            l_result.Firstname = (string)i_sqlDataReader["Firstname"];
            l_result.Id = (int)i_sqlDataReader["Id"];
            if ( i_sqlDataReader["Mobile"] != DBNull.Value )
            {
                l_result.Mobile = (string)i_sqlDataReader["Mobile"];    
            }            
            l_result.Password = (string)i_sqlDataReader["Password"];
            l_result.Surname = (string)i_sqlDataReader["Surname"];
            if ( i_sqlDataReader["Telephone"] != DBNull.Value )
            {
                l_result.Telephone = (string)i_sqlDataReader["Telephone"];    
            }            
            l_result.TitleId = (int)i_sqlDataReader["TitleId"];
            l_result.Username = (string)i_sqlDataReader["Username"];
            if ( i_sqlDataReader["IpAddressOnRegistration"] != DBNull.Value )
            {
                l_result.IpAddressOnRegistration = (string)i_sqlDataReader["IpAddressOnRegistration"];    
            }            
            return l_result;
               
        }
        } // SaveToSession ()
        //--------------------

        private Event CreateAndSendCheckoutEvent(Account i_account)
        {
            Event l_eventToCreate = new Event(Event.CheckoutEvent);
            l_eventToCreate.AddData("MERCHANT_REFERENCE", lblOrderNumber.Text);   

            // PURCHASE_AMOUNT is a System Session Attribute
            l_eventToCreate.AddData("PURCHASE_AMOUNT", txtbxAmount.Text);

            // CC_HASH is a System Attribute. You should always use the CreditCardHash to hash your 
            // Credit Card Number and send it to Fraud Pointer Server.
            l_eventToCreate.AddData("CC_HASH", _client.CreditCardHash(txtbxCardNumber.Text));

            // CC_CARD_HOLDER_NAME is a System Attribute.
            l_eventToCreate.AddData("CC_CARD_HOLDER_NAME", txtbxNameOnCard.Text);

            // CC_BANK_NAME is a System Attribute
            l_eventToCreate.AddData("CC_BANK_NAME", txtbxBankNameOfCard.Text);

            // CREDIT_CARD_FIRST_6_DIGITS
            if ( txtbxCardNumber.Text.Length>=6 )
            {
                l_eventToCreate.AddData("CREDIT_CARD_FIRST_6_DIGITS", txtbxCardNumber.Text.Substring(0, 6));    
            }            
            else
            {
                l_eventToCreate.AddData("CREDIT_CARD_FIRST_6_DIGITS", txtbxCardNumber.Text.Substring(0, txtbxCardNumber.Text.Length));    
            }

            // LET US SEND THE USER_E_MAIL 
            l_eventToCreate.AddData("USER_E_MAIL", i_account.Email);

            // LET US SEND THE USERNAME
            l_eventToCreate.AddData("USERNAME", i_account.Username);


            // first name
            l_eventToCreate.AddData("USER_FIRSTNAME", i_account.Firstname);

            // last name
            l_eventToCreate.AddData("USER_LASTNAME", i_account.Surname);

            // country of customer
            Country l_billingCountry = Country.Find(i_account.CountryId);
            if ( l_billingCountry != null )
            {
                l_eventToCreate.AddData("BILLING_COUNTRY", Country.Find(i_account.CountryId).Iso2);    
            }
            
            // address street
            if ( String.IsNullOrEmpty(i_account.AddressStreet) == false )
            {
                l_eventToCreate.AddData("BILLING_ADDRESS_STREET_NAME", i_account.AddressStreet);    
            }

            //BILLING_ADDRESS_STREET_NUMBER
            if (String.IsNullOrEmpty(i_account.AddressNumber) == false)
            {
                l_eventToCreate.AddData("BILLING_ADDRESS_STREET_NUMBER", i_account.AddressNumber);
            }

            //BILLING_ADDRESS_CITY
            if (String.IsNullOrEmpty(i_account.AddressCity) == false)
            {
                l_eventToCreate.AddData("BILLING_ADDRESS_CITY", i_account.AddressCity);
            }

            // BILLING_ADDRESS_POST_CODE
            if (String.IsNullOrEmpty(i_account.AddressPostCode) == false)
            {
                l_eventToCreate.AddData("BILLING_ADDRESS_POST_CODE", i_account.AddressPostCode);
            }
            
            // BILLING_TELEPHONE_NUMBER
            if (String.IsNullOrEmpty(i_account.Telephone) == false)
            {
                l_eventToCreate.AddData("BILLING_TELEPHONE_NUMBER", i_account.Telephone);
            }                   

            int l_iNumberOfDeposits = 0;
            l_iNumberOfDeposits = Transaction.NumberOfDeposits(i_account.Id, DateTime.MinValue);
            l_eventToCreate.AddData("SUPER_SPORTING_BET_NUMBER_OF_USER_S_DEPOSITS_SINCE_INITIAL_REGISTRATION_DATE", l_iNumberOfDeposits);

            int l_iNumberOfDaysSinceInitialRegistrationDate = 0;
            l_iNumberOfDaysSinceInitialRegistrationDate = (DateTime.Now - i_account.DateOfRegistration).Days;
            l_eventToCreate.AddData("SUPER_SPORTING_BET_DAYS_SINCE_INITIAL_REGISTRATION_DATE", l_iNumberOfDaysSinceInitialRegistrationDate);

            // SUPER_SPORTING_BET_LAST_30_DAYS__ACCUMULATED_VALUE_OF_USER_S_DEPOSITS
            decimal l_iLast30DaysAccumulatedValueOfUsersDeposits = 0;
            l_iLast30DaysAccumulatedValueOfUsersDeposits = Transaction.SumDepositsLaterThan(i_account.Id, DateTime.Now.AddDays(-30));
            l_eventToCreate.AddData("SUPER_SPORTING_BET_LAST_30_DAYS__ACCUMULATED_VALUE_OF_USER_S_DEPOSITS", l_iLast30DaysAccumulatedValueOfUsersDeposits);

            // SUPER_SPORTING_BET_LAST_30_DAYS__NUMBER_OF_USER_S_DEPOSITS
            int l_iNumberOfDepositsDuringLast30Days = 0;
            l_iNumberOfDepositsDuringLast30Days = Transaction.NumberOfDeposits(i_account.Id, DateTime.Now.AddDays(-30));
            l_eventToCreate.AddData("SUPER_SPORTING_BET_LAST_30_DAYS__NUMBER_OF_USER_S_DEPOSITS", l_iNumberOfDepositsDuringLast30Days);
            
            // "SUPER_SPORTING_BET_USER_S_IP_ADDRESS_ON_REGISTRATION"
            if ( String.IsNullOrEmpty(i_account.IpAddressOnRegistration) == false )
            {
                l_eventToCreate.AddData("SUPER_SPORTING_BET_USER_S_IP_ADDRESS_ON_REGISTRATION", i_account.IpAddressOnRegistration);                
            }

            // SUPER_SPORTING_BET_USER_HAS_AT_LEAST_ONE_BANK_DEPOSIT
            int l_iNumberOfBankDeposits = Transaction.NumberOfBankDeposits(i_account.Id, DateTime.MinValue);
            l_eventToCreate.AddData("SUPER_SPORTING_BET_USER_HAS_AT_LEAST_ONE_BANK_DEPOSIT", l_iNumberOfBankDeposits >= 1);

            try
            {
                Event l_eventCreated = _client.AppendEventToAssessmentSession(GetOrCreateAssessmentSession(), l_eventToCreate);
                return l_eventCreated;
            }
            catch (ClientException ex)
            {
                return null;
            }

        } // CreateAndSendCheckoutEvent ()
        } // FindByUsername ()
        //---------------------------------

        public static Account Create (Account i_accountToCreate)
        {
            SqlConnection l_sqlConnection = null;
            SqlCommand l_sqlCommand = null;
            string l_strSqlForInsert = "insert into accounts (TitleId, Firstname, Surname, CountryId, AddressStreet, " +
                                       " AddressNumber, AddressCity, AddressPostCode, DateOfBirth, Email, Telephone, Mobile, Username, Password, DateOfRegistration, IpAddressOnRegistration ) " +
                                       " values ( @TitleId, @Firstname, @Surname, @CountryId, @AddressStreet, @AddressNumber, " +
                                       " @AddressCity, @AddressPostCode, @DateOfBirth, @Email, @Telephone, @Mobile, @Username, @Password, @DateOfRegistration, @IpAddressOnRegistration )";
            try
            {
                l_sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings[Common.DbName].ConnectionString);
                l_sqlConnection.Open();

                l_sqlCommand = new SqlCommand(l_strSqlForInsert, l_sqlConnection);

                SqlParameter l_paramTitleId = new SqlParameter("TitleId", SqlDbType.Int);
                l_paramTitleId.Value = i_accountToCreate.TitleId;
                l_sqlCommand.Parameters.Add(l_paramTitleId);

                SqlParameter l_paramFirstName = new SqlParameter("Firstname", SqlDbType.NVarChar);
                l_paramFirstName.Value = i_accountToCreate.Firstname;
                l_sqlCommand.Parameters.Add(l_paramFirstName);

                SqlParameter l_paramSurname = new SqlParameter("Surname", SqlDbType.NVarChar);
                l_paramSurname.Value = i_accountToCreate.Surname;
                l_sqlCommand.Parameters.Add(l_paramSurname);

                SqlParameter l_paramCountryId = new SqlParameter("CountryId", SqlDbType.Int);
                l_paramCountryId.Value = i_accountToCreate.CountryId;
                l_sqlCommand.Parameters.Add(l_paramCountryId);

                SqlParameter l_paramAddressStreet = new SqlParameter("AddressStreet", SqlDbType.NVarChar);
                l_paramAddressStreet.Value = i_accountToCreate.AddressStreet;
                l_sqlCommand.Parameters.Add(l_paramAddressStreet);

                SqlParameter l_paramAddressNumber = new SqlParameter("AddressNumber", SqlDbType.NVarChar);
                if ( String.IsNullOrEmpty(i_accountToCreate.AddressNumber))
                {
                    l_paramAddressNumber.Value = DBNull.Value;    
                }                
                else
                {
                    l_paramAddressNumber.Value = i_accountToCreate.AddressNumber;
                }
                l_sqlCommand.Parameters.Add(l_paramAddressNumber);

                SqlParameter l_paramAddressCity = new SqlParameter("AddressCity", SqlDbType.NVarChar);
                l_paramAddressCity.Value = i_accountToCreate.AddressCity;
                l_sqlCommand.Parameters.Add(l_paramAddressCity);

                SqlParameter l_paramAddressPostCode = new SqlParameter("AddressPostCode", SqlDbType.NVarChar);
                l_paramAddressPostCode.Value = i_accountToCreate.AddressPostCode;
                l_sqlCommand.Parameters.Add(l_paramAddressPostCode);

                SqlParameter l_paramDateOfBirth = new SqlParameter("DateOfBirth", SqlDbType.DateTime);
                l_paramDateOfBirth.Value = i_accountToCreate.DateOfBirth;
                l_sqlCommand.Parameters.Add(l_paramDateOfBirth);                               

                SqlParameter l_paramEmail = new SqlParameter("Email", SqlDbType.NVarChar);
                l_paramEmail.Value = i_accountToCreate.Email;
                l_sqlCommand.Parameters.Add(l_paramEmail);

                SqlParameter l_paramTelephone = new SqlParameter("Telephone", SqlDbType.NVarChar);
                if (String.IsNullOrEmpty(i_accountToCreate.Telephone))
                {
                    l_paramTelephone.Value = DBNull.Value;
                }
                else
                {
                    l_paramTelephone.Value = i_accountToCreate.Telephone;
                }
                l_sqlCommand.Parameters.Add(l_paramTelephone);

                SqlParameter l_paramMobile = new SqlParameter("Mobile", SqlDbType.NVarChar);
                if (String.IsNullOrEmpty(i_accountToCreate.Mobile))
                {
                    l_paramMobile.Value = DBNull.Value;
                }
                else
                {
                    l_paramMobile.Value = i_accountToCreate.Mobile;
                }
                l_sqlCommand.Parameters.Add(l_paramMobile);

                SqlParameter l_paramUsername = new SqlParameter("Username", SqlDbType.NVarChar);
                l_paramUsername.Value = i_accountToCreate.Username;
                l_sqlCommand.Parameters.Add(l_paramUsername);

                SqlParameter l_paramPassword = new SqlParameter("Password", SqlDbType.NVarChar);
                l_paramPassword.Value = i_accountToCreate.Password;
                l_sqlCommand.Parameters.Add(l_paramPassword);

                SqlParameter l_paramDateOfRegistration = new SqlParameter("DateOfRegistration", SqlDbType.DateTime);
                l_paramDateOfRegistration.Value = i_accountToCreate.DateOfRegistration;
                l_sqlCommand.Parameters.Add(l_paramDateOfRegistration);

                SqlParameter l_paramIpAddressOnRegistration = new SqlParameter("IpAddressOnRegistration", SqlDbType.NVarChar);
                if (String.IsNullOrEmpty(i_accountToCreate.Mobile))
                {
                    l_paramIpAddressOnRegistration.Value = DBNull.Value;
                }
                else
                {
                    l_paramIpAddressOnRegistration.Value = i_accountToCreate.IpAddressOnRegistration;
                }
                l_sqlCommand.Parameters.Add(l_paramIpAddressOnRegistration);                

                l_sqlCommand.ExecuteNonQuery();
                             
                // check that the account has been created
                Account l_accountFound = FindByEmail(i_accountToCreate.Email);
                return l_accountFound;

            }
            catch (Exception ex)
            {
                throw new Exception("Cannot create account, ex: " + ex);
            }
            finally
            {
                if (l_sqlCommand != null)
                {
                    l_sqlCommand.Dispose();
                }
                if (l_sqlConnection != null)
                {
                    if (l_sqlConnection.State == ConnectionState.Open)
                    {
                        l_sqlConnection.Close();
                    }
                    l_sqlConnection.Dispose();
                }   
            }
       
        } // Create ()
        protected void Submit_Click (Object o, EventArgs e)
        {
            // collect data
            int l_iTitleId = int.Parse(lstbxTitle.SelectedValue);
            
            string l_strFirstname = txtbxFirstname.Text;
            if (l_strFirstname == "")
            {
                lblMessageToUser.Text = "You have to give Firstname";
                return;
            }

            string l_strSurname = txtbxSurname.Text;
            if (l_strSurname == "")
            {
                lblMessageToUser.Text = "You have to give Surname";
                return;
            }

            int l_iCountryId = int.Parse(lstbxCountry.SelectedValue);

            string l_strAddressStreet = txtbxAddressStreet.Text;
            if (l_strAddressStreet == "")
            {
                lblMessageToUser.Text = "You have to give Address Street";
                return;
            }

            string l_strAddressNumber = txtbxAddressNumber.Text;

            string l_strAddressCity = txtbxAddressCity.Text;
            if ( l_strAddressCity == "" )
            {
                lblMessageToUser.Text = "You have to give Address City";
                return;
            }

            string l_strAddressPostCode = txtbxAddressPostCode.Text;
            if ( l_strAddressPostCode == "" )
            {
                lblMessageToUser.Text = "You have to give Address Post Code";
                return;
            }

            DateTime l_dtDateOfBirth;
            try
            {
                l_dtDateOfBirth = new DateTime(int.Parse(lstbxDateOfBirthYear.SelectedValue),
                                                     int.Parse(lstbxDateOfBirthMonth.SelectedValue),
                                                     int.Parse(lstbxDateOfBirthDayOfMonth.SelectedValue));

            }
            catch (Exception ex)
            {
                lblMessageToUser.Text = "Invalid Date of Birth";
                return;
            }

            string l_strEmail = txtbxEmail.Text;
            if ( l_strEmail == "" )
            {
                lblMessageToUser.Text = "You have to give Email";
                return;
            }

            string l_strTelephone = txtbxTelephone.Text;

            string l_strMobile = txtbxMobile.Text;

            string l_strUsername = txtbxUsername.Text;
            if ( l_strUsername == "" )
            {
                lblMessageToUser.Text = "You have to give Username";
                return;
            }

            string l_strPassword = txtbxPassword.Text;
            if ( l_strPassword == "" )
            {
                lblMessageToUser.Text = "You have to give password";
                return;
            }

            string l_strConfirmPassword = txtbxConfirmPassword.Text;
            if ( l_strConfirmPassword != l_strPassword )
            {
                lblMessageToUser.Text = "Password and Confirmation do not match";
                return;
            }

            DateTime l_dtDateOfRegistration;
            try
            {
                l_dtDateOfRegistration = new DateTime(int.Parse(lstbxDateOfRegistrationYear.SelectedValue),
                                                      int.Parse(lstbxDateOfRegistrationMonth.SelectedValue),
                                                      int.Parse(lstbxDateOfRegistrationDayOfMonth.SelectedValue));

            }
            catch (Exception ex)
            {
                lblMessageToUser.Text = "Invalid Date of Registration";
                return;
            }                     

            // data are valid

            // let us check for already taken data
            Account l_accountFound = Account.FindByFirstnameAndSurname(l_strFirstname, l_strSurname);
            if ( l_accountFound != null )
            {
                lblMessageToUser.Text = "Firstname/Surname already taken";
                return;
            }

            l_accountFound = Account.FindByEmail(l_strEmail);
            if ( l_accountFound != null )
            {
                lblMessageToUser.Text = "Email already taken";
                return;                
            }

            l_accountFound = Account.FindByUsername(l_strUsername);
            if ( l_accountFound != null )
            {
                lblMessageToUser.Text = "Username already taken";
                return;
            }

            // now we can do the create
            Account l_accountToCreate = new Account();
            l_accountToCreate.AddressCity = l_strAddressCity;
            l_accountToCreate.AddressNumber = l_strAddressNumber;
            l_accountToCreate.AddressPostCode = l_strAddressPostCode;
            l_accountToCreate.AddressStreet = l_strAddressStreet;
            l_accountToCreate.CountryId = l_iCountryId;
            l_accountToCreate.DateOfBirth = l_dtDateOfBirth;
            l_accountToCreate.DateOfRegistration = l_dtDateOfRegistration;
            l_accountToCreate.Email = l_strEmail;
            l_accountToCreate.Firstname = l_strFirstname;
            l_accountToCreate.Mobile = l_strMobile;
            l_accountToCreate.Password = l_strPassword;
            l_accountToCreate.Surname = l_strSurname;
            l_accountToCreate.Telephone = l_strTelephone;
            l_accountToCreate.TitleId = l_iTitleId;
            l_accountToCreate.Username = l_strUsername;
            string l_strIpOnRegistration = Request.UserHostAddress;
            if ( txtbxIpOnRegistration.Text != "" )
            {
                l_strIpOnRegistration = txtbxIpOnRegistration.Text;
            }
            if ( l_strIpOnRegistration != "" )
            {
                l_accountToCreate.IpAddressOnRegistration = l_strIpOnRegistration;    
            }            
            l_accountToCreate = Account.Create(l_accountToCreate);
            if ( l_accountToCreate == null )
            {
                lblMessageToUser.Text = "Problem creating the account";
                return;
            }

            Response.Redirect("~/Default.aspx");

        } // Submit_Click ()