API Examples - Custom User Profile

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using System.Data.Odbc;

using System.Configuration;

 

namespace ChatAPISample{

public class CustomUserInfo  : chat_net3.ZbChatPage{

protected System.Web.UI.WebControls.TextBox TextBox1;

protected System.Web.UI.WebControls.Label Label1;

protected System.Web.UI.WebControls.Button Button1;

protected System.Web.UI.WebControls.TextBox TextBox2;

protected System.Web.UI.WebControls.Label Label2;

protected System.Web.UI.WebControls.ListBox ListBox1;

protected System.Web.UI.WebControls.Label Label3;

 

 

override protected void OnInit(EventArgs e){

InitializeComponent();

base.OnInit(e);

}

 

private void InitializeComponent(){    

this.Button1.Click += new System.EventHandler(this.Button1_Click);

}

 

private void Button1_Click(object sender, System.EventArgs e){

int iSiteId=int.Parse(TextBox1.Text);

string sSql="execute zbc_user_get ?,?"; //it's better to use a stored procedure

OdbcConnection oCon=new OdbcConnection(ConfigurationSettings.AppSettings["zbc.ConnectionString"]);

OdbcCommand oCom=new OdbcCommand(sSql,oCon);

oCom.CommandType=CommandType.Text;

oCom.Parameters.Add("@login_id",OdbcType.VarChar,50).Value=TextBox2.Text;

oCom.Parameters.Add("@site_id",OdbcType.Int).Value=iSiteId;

ListBox1.Items.Clear();

bool bFound = false;

try{

oCon.Open();

OdbcDataReader myReader = oCom.ExecuteReader(CommandBehavior.CloseConnection);

while(myReader.Read()) {

for (int i = 0;i<myReader.FieldCount;i++)

ListBox1.Items.Add(myReader.GetName(i) + ": " + myReader.GetString(i));

bFound = true;

}

myReader.Close();

}catch(Exception ex){

Label3.Text=string.Format("Error occured while trying to get user record: {0} call stock: {1}",ex.Message,ex.StackTrace);

return;

} finally {

oCon.Close();

}

if(!bFound){

Label3.Text = "User " + TextBox2.Text + " not found on Site " + iSiteId;

}else {

Label3.Text = "User " + TextBox2.Text + " found on Site " + iSiteId;

}

}

}

}