API Examples - Custom Register

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Data.Odbc;

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.Configuration;

 

namespace ChatAPISample

{

//Have to inherit from ZBit Chat Page calss instead of standrad Page class in order to use chat API

public class CustomRegister : chat_net3.ZbChatPage

{

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

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

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

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

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

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

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

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

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

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

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

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

protected Label lblMsg;

 

private void Page_Load(object sender, System.EventArgs e)

 {

// Put user code to initialize the page here

}

 

#region Web Form Designer generated code

override protected void OnInit(EventArgs e) {

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}

 

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent() {    

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

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

 

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

{

int iRaf=0;

int iSiteId=int.Parse(this.SiteIdGet());

string sSql="insert into zbc_user (login_id,site_id,login_psw,email,age) values(?,?,?,?,?)"; //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=txtLogin.Text;

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

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

oCom.Parameters.Add("@lemail",OdbcType.VarChar,80).Value=txtEmail.Text;

oCom.Parameters.Add("@age",OdbcType.Int).Value=txtAge.Text;

try{

oCon.Open();

iRaf=oCom.ExecuteNonQuery();

}catch(Exception ex){

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

return;

}finally{

oCon.Close();

}

if(1==iRaf){

lblMsg.Text=string.Format("User record is inserted and chat server site id {0} is updated",iSiteId);

}else{

lblMsg.Text="Error insering user. Records affected: " + iRaf;

}

}

}

}