Success.
I created an aspx page with a button and a multiline text box.
Using Sql query designer created a query to retreive the required details.
Using an sqltable adapter I read thru the rows and added the users.
The Only strange thing is that if I set the subscribe to newsletter to false, the users would not appear in admin user manager, so had to set it to true.
Kind Regards
Paul
____________________
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using DSC = DotShoppingCart.Commercial.Core;
using DotShoppingCart.Commercial.Core;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Data;
public partial class Admin_Create_User : System.Web.UI.Page
{
string userName;
string password;
string email;
bool newsLetter;
int? referralId;
string firstName;
string lastName;
string companyName;
string address;
string address2;
string city;
string state;
string zipcode;
int countryId;
string phone;
string phoneExt;
DateTime created;
bool copyToShippingAddress;
protected void Page_Load(object sender, EventArgs e)
{
}
// public static void AddUser(string userName, bool newsLetter, int? referralId, string firstName, string lastName, string companyName, string address, string address2, string city, string state, string zipcode, int countryId, string phone, string phoneExt, DateTime created, bool copyToShippingAddress);
protected void Button1_Click(object sender, EventArgs e)
{
Membership.RequiresQuestionAndAnswer;
// Assumes that customerConnection is a valid SqlConnection object.
// Assumes that orderConnection is a valid OleDbConnection object.
SqlConnection customerConnection = new SqlConnection("//whatever you connection string is
string Selectstring = //whatever your select statement is
SqlDataAdapter custAdapter = new SqlDataAdapter(
Selectstring, customerConnection);
DataSet customerOrders = new DataSet();
custAdapter.Fill(customerOrders, "Customers");
foreach (DataRow pRow in customerOrders.Tables["Customers"].Rows)
{
// TextBox1.Text += + "/n";
userName = pRow["username"].ToString().Trim();//the names are aliases in sql select statment.
password = pRow["password"].ToString();
email = pRow["email"].ToString();
newsLetter = true;
referralId = CoreHelper.GetReferralId();
string[] split = pRow["contactName"].ToString().Split(' ');
firstName = split[0];
lastName = split[1];
companyName = pRow["companyName"].ToString();
address = pRow["address1"].ToString();
// address2 = pRow["address2"].ToString();
city = pRow["city"].ToString();
state = pRow["state"].ToString();
zipcode = pRow["postcode"].ToString();
countryId = 8;
phone = pRow["phone1"].ToString();
phoneExt = "";
created = DateTime.Now;
copyToShippingAddress = false;
// Console.WriteLine(pRow["CustomerID"]);
// foreach (DataRow cRow in pRow.GetChildRows(relation))
// Console.WriteLine("\t" + cRow["OrderID"]);
MembershipCreateStatus status;
try
{
// MembershipUser newuser = Membership.CreateUser(userName,password,email,"question","answer",true,out status);
// Membership.DeleteUser(userName); // uncomment to delete a user and refresh details, you will lose users sales history I would suspect?
MembershipUser newuser= Membership.CreateUser(userName, password, email, "question", "answer", true, out status);
if (newuser == null)
{
TextBox1.Text += GetErrorMessage(status) + Environment.NewLine;
}
else
{
TextBox1.Text += "added user " + userName+Environment.NewLine;
// DSC.User.Delete(userName); // uncomment to delete a user and refresh details, you will lose users sales history I would suspect?
DSC.User.AddUser(userName, newsLetter, CoreHelper.GetReferralId(), firstName, lastName, companyName, address, address2, city, state, zipcode, countryId, phone, phoneExt, created, false);
}
}
catch
{
TextBox1.Text += "An exception occurred creating the user."+Environment.NewLine;
}
}
}
public string GetErrorMessage(MembershipCreateStatus status)
{
switch (status)
{
case MembershipCreateStatus.DuplicateUserName:
return "Username already exists. Please enter a different user name.";
case MembershipCreateStatus.DuplicateEmail:
return "A username for that e-mail address already exists. Please enter a different e-mail address.";
case MembershipCreateStatus.InvalidPassword:
return "The password provided is invalid. Please enter a valid password value.";
case MembershipCreateStatus.InvalidEmail:
return "The e-mail address provided is invalid. Please check the value and try again.";
case MembershipCreateStatus.InvalidAnswer:
return "The password retrieval answer provided is invalid. Please check the value and try again.";
case MembershipCreateStatus.InvalidQuestion:
return "The password retrieval question provided is invalid. Please check the value and try again.";
case MembershipCreateStatus.InvalidUserName:
return "The user name provided is invalid. Please check the value and try again.";
case MembershipCreateStatus.ProviderError:
return "The authentication provider returned an error. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
case MembershipCreateStatus.UserRejected:
return "The user creation request has been canceled. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
default:
return "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
}
}
}
|