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;
namespace ChatAPISample
{
//Have to inherit from ZBit Chat Page calss instead of standrad Page class in order to use chat API
public class CustomLogin : chat_net3.ZbChatPage
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label lblMsg;
protected System.Web.UI.WebControls.HyperLink lnkChat;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.ListBox lstRooms;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
RoomListRender();
}
}
private void RoomListRender()
{
lstRooms.Items.Clear();
lstRooms.Items.Add(new ListItem("** Any Room **","-2"));
lstRooms.Items.Add(new ListItem("** Do NOT enter room - just login **","-1"));
int iSiteId=int.Parse(this.SiteIdGet());
string sDelimListOfRoomIds,sDelimListOfRoomNames,sDelimListOfUserNames,sDelimListOfUserCounts,
sDelimListOfFlags,sDelimListOfTopics,sSiteName,sErr="";
if(this.SiteRoomListGet(iSiteId,out sDelimListOfRoomIds,out sDelimListOfRoomNames, out sDelimListOfUserNames,out sDelimListOfUserCounts,out sDelimListOfFlags,out sDelimListOfTopics,out sSiteName,ref sErr))
{
string[] asRoomIds=sDelimListOfRoomIds.Split((char)1);
string[] asRoomNames=sDelimListOfRoomNames.Split((char)1);
string[] asUseCounts=sDelimListOfUserCounts.Split((char)1);
for(int i=0;i<asRoomIds.Length;i++){
lstRooms.Items.Add(new ListItem(string.Format("{0} ({1})",asRoomNames[i],asUseCounts[i]),asRoomIds[i]));
}
}else{
lblMsg.Text="Error getting room list: " + sErr;
}
}
#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)
{
Session["unused"]=0;//this is a hack to work around the bug with session state not being initialized
int iSiteId=int.Parse(this.SiteIdGet());
// This is just a sample. In real application you would take those
// variable form session, form, cookies or any other method that you use.
string sUserId="user1";
string sPwd="";
int iRoomId=-2; //room ID -2 will not enter any room, -1 will not enter any room
iRoomId=int.Parse(lstRooms.SelectedValue);
string sErr="";int iErr=0;
if(this.UserLogin(Session.SessionID,iSiteId,sUserId,sPwd,false,iRoomId,ref iErr,ref sErr)){
lblMsg.Text=string.Format("Successfully logged in user {0} into site {1}, room {2}.",sUserId,iSiteId,iRoomId);
//instead you can just put all this code in your page_load event and use redirect to chat page here.
lnkChat.Visible=true;
RoomListRender();
}else{
//depending on error code you may take different action here
lblMsg.Text=string.Format("Failed to logged in user {0} into site {1}, room {2}. Error ({3}) {4}",sUserId,iSiteId,iRoomId,iErr,sErr);
lnkChat.Visible=false;
}
}
private void Button2_Click(object sender, System.EventArgs e) {
int iSiteId=int.Parse(this.SiteIdGet());
// This is just a sample. In real application you would take those
// variable form session, form, cookies or any other method that you use.
string sUserId="user1";
string sErr="";int iErr=0;
if(this.UserLogout(iSiteId,sUserId,ref iErr,ref sErr)){
lblLogout.Text=string.Format("Successfully logged out user {0} from site {1}.",sUserId,iSiteId);
//instead you can just put all this code in your page_load event and use redirect to chat page here.
//lnkChat.Visible=true;
}
else
{
//depending on error code you may take different action here
lblLogout.Text=string.Format("Failed to log out user {0} from site {1}. Error ({2}) {3}",sUserId,iSiteId,iErr,sErr);
}
RoomListRender();
lnkChat.Visible=false;
}
}
}