Code as follows
string sourceUser = (string)HttpContext.Current.Session["TargetUserID"];
System.Data.DataSet blank = new System.Data.DataSet();
System.Data.DataSet ds = new System.Data.DataSet();
protected void Page_Load(object sender, EventArgs e)
{
if (lstCopyTargetUsers.Items.Count < 1)
{
if (Page.IsPostBack)
{
Sage.Platform.Data.IDataService service = Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Data.IDataService>();
string connStr = service.GetConnectionString();
Sage.SalesLogix.Security.SLXUserService usersvc = (Sage.SalesLogix.Security.SLXUserService)Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Security.IUserService>();
Sage.Entity.Interfaces.IUser user = usersvc.GetUser();
string loggedinid = user.Id.ToString();
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(connStr);
conn.Open();
System.Data.OleDb.OleDbCommand reps = new System.Data.OleDb.OleDbCommand();
//Build and execute SQL
reps.Connection = new System.Data.OleDb.OleDbConnection(connStr);
reps.Connection.Open();
reps.CommandText = "SELECT userid,username FROM USERINFO WHERE USERID = '" + loggedinid + "' or USERID in (select userid from usersecurity where managerid ='" + loggedinid + "')";
System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter(reps.CommandText, conn);
da.SelectCommand = reps;
da.Fill(ds);
lstTeam.DataSource = ds;
lstTeam.DataValueField = ds.Tables[0].Columns["userid"].ToString();
lstTeam.DataTextField = ds.Tables[0].Columns["username"].ToString();
lstTeam.DataBind();
blank = ds.Clone();
lstTeam.Items.Remove(lstTeam.Items.FindByValue(sourceUser));
reps.Connection.Close();
}
}
}
protected void btnAdd_Click(object sender, EventArgs e)
{
int i;
if (lstTeam.SelectedIndex != -1)
{
//foreach(System.Data.DataRow dr in ds.Tables[0].Rows)
//{
for (i = 0; i < lstTeam.Items.Count; i++ )
{
if(lstTeam.SelectedItem.Text == ds.Tables[0].Rows[i][1].ToString())
{
blank.Tables[0].ImportRow(ds.Tables[0].Rows[i]);
lstCopyTargetUsers.DataSource = blank;
lstCopyTargetUsers.DataValueField = ds.Tables[0].Columns["userid"].ToString();
lstCopyTargetUsers.DataTextField = ds.Tables[0].Columns["username"].ToString();
lstCopyTargetUsers.DataBind();
ds.Tables[0].Rows[i].Delete();
lstTeam.DataSource = ds;
lstTeam.DataValueField = ds.Tables[0].Columns["userid"].ToString();
lstTeam.DataTextField = ds.Tables[0].Columns["username"].ToString();
lstTeam.DataBind();
}
}
lstTeam.Items.Remove(lstTeam.Items.FindByValue(sourceUser));
lstCopyTargetUsers.Items.Remove(lstTeam.Items.FindByValue(sourceUser));
//}
}
}

New Topic/Question
Reply
MultiQuote






|