using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Collections;
using System.Text.RegularExpressions;
using System.Web.Script.Serialization;
using System.Configuration;
using System.Security.Cryptography;
using System.Data.SqlClient;
using NPOI.HSSF.UserModel;
using NPOI.XSSF.UserModel;
using NPOI.POIFS.FileSystem;
public static class ExhListSharedLib
public static String SqlConnStr = ConfigurationManager.ConnectionStrings["ExhListConnStr"].ConnectionString;
private static int CheckUserID (){
if(HttpContext.Current.Session["UserID"] != null)
return (int)HttpContext.Current.Session["UserID"];
public static JObject HashtableToJObj (Hashtable inHashtable) {
JObject outJObj = new JObject();
foreach (Object tKey in inHashtable.Keys) {
Hashtable hashRow = (Hashtable)inHashtable[tKey];
JObject tJRowObj = new JObject();
foreach (Object ttKey in hashRow.Keys) {
Object tObj = hashRow[ttKey];
if (tObj.GetType() == typeof(ArrayList)) {
JArray jarr = new JArray();
foreach (String ttValue in (ArrayList)tObj) {
tJRowObj[ttKey.ToString()] = jarr;
tJRowObj[ttKey.ToString()] = hashRow[ttKey].ToString();
outJObj[tKey.ToString()] = tJRowObj;
outJObj[tKey] = inHashtable[tKey].ToString();
public static Hashtable JObjToHashtable (JObject inJObj) {
Hashtable hashList = new Hashtable();
foreach (System.Collections.Generic.KeyValuePair<string,Newtonsoft.Json.Linq.JToken> jObj in inJObj) {
string tRowKey = jObj.Key;
JObject jRowObj = (JObject)jObj.Value;
Hashtable hashRow = new Hashtable();
foreach (System.Collections.Generic.KeyValuePair<string,Newtonsoft.Json.Linq.JToken> jRowItem in jRowObj) {
hashRow[jRowItem.Key] = jRowItem.Value;
hashList[tRowKey] = hashRow;
public static SortedList SortHashtable (Hashtable inHashtable, String inKey) {
SortedList outList = SortHashtable(inHashtable, inKey, "string");
public static SortedList SortHashtable (Hashtable inHashtable, String inKey, String inDataType) {
SortedList outList = new SortedList();
foreach (Object tKey in inHashtable.Keys) {
Hashtable hashRow = (Hashtable)inHashtable[tKey];
if (hashRow[inKey] != null) {
if (inDataType == "int") {
if (!outList.ContainsKey(Int32.Parse(hashRow[inKey].ToString()))) {
outList.Add(Int32.Parse(hashRow[inKey].ToString()), hashRow);
if (!outList.Contains(hashRow[inKey].ToString())) {
outList.Add(hashRow[inKey].ToString(), hashRow);
outList.Add(hashRow[inKey].ToString() + "_" + tKey, hashRow);
public static String getIP() {
String ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (string.IsNullOrEmpty(ip))
ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
public static String DoMD5 (String inText) {
System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
byte[] hash = md5.ComputeHash(System.Text.Encoding.ASCII.GetBytes(inText));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++) {
sb.Append(hash[i].ToString("X2"));
return sb.ToString().ToLower();
public static String sendErrLogEmail (String inErr) {
System.Net.Mail.MailAddress mailTo = new System.Net.Mail.MailAddress("don.chow@gmail.com", "To Don");
System.Net.Mail.MailAddress mailFrom = new System.Net.Mail.MailAddress("don.chow@gmail.com", "From Don");
System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage(mailFrom, mailTo);
System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("127.0.0.1");
mailMessage.Subject = "eFile Debug (eNewsSharedLib) - " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff");
mailMessage.IsBodyHtml = true;
mailMessage.Body = inErr;
mailClient.Send(mailMessage);
JObject jsonObject = new JObject();
jsonObject["Result"] = "Error";
jsonObject["Err"] = ex.StackTrace.Substring(ex.StackTrace.Length - 7, 7) + ": " + ex.Message;
return jsonObject.ToString();
public static String getMD5(String inStr) {
return Convert.ToBase64String(md5.ComputeHash(Encoding.Default.GetBytes(inStr)));
static bool chkADLogin (string inDomain, string inLogin, string inPassword) {
MD5 md5 = new MD5CryptoServiceProvider();
Hashtable outHash = new Hashtable();
string inPara = "{\"domain\":\""+inDomain+"\",\"login\":\""+inLogin+"\",\"password\":\""+inPassword+"\"}";
string inAuth = Regex.Replace(BitConverter.ToString(md5.ComputeHash(ASCIIEncoding.Default.GetBytes(inPara + "ubmasiasinglelogon2013"))), "-", "");
string postData = "inUserIP=&inPara="+HttpUtility.UrlEncode(inPara)+"&inAuth="+inAuth;
WebRequest request = WebRequest.Create(System.Configuration.ConfigurationManager.AppSettings["ADAUTH"] + "/Auth?" + postData);
using (WebResponse response = request.GetResponse())
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
wsResponse = reader.ReadToEnd().Trim();
HttpContext.Current.Response.Write(ex.ToString());
String outResponse = Regex.Replace(wsResponse, "<.*?>", string.Empty);
if (outResponse.Trim() == "true") {
public static Hashtable runLogin(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
String inLogin = (inPara["Login"] != null) ? inPara["Login"].ToString() : "";
String inPassword = (inPara["Password"] != null) ? inPara["Password"].ToString() : "";
bool inboolAD = (inPara["boolAD"] != null) ? (bool)inPara["boolAD"] : false;
if (inLogin.Contains("\\")) {
string[] arrADLogin = inLogin.Split('\\');
inADdomain = arrADLogin[0];
inADlogin = arrADLogin[1];
if (arrADLogin[0] != "UBMASIA") {
if (arrADLogin[0].ToString().ToUpper().Contains(System.Configuration.ConfigurationManager.AppSettings["ADDomain"])) {
outADdomain = arrADLogin[0];
outADdomain = arrADLogin[0] + "." + System.Configuration.ConfigurationManager.AppSettings["ADDomain"];
outADlogin = arrADLogin[0] + "." + System.Configuration.ConfigurationManager.AppSettings["ADDomain"] + "\\" + inADlogin;
outADdomain = System.Configuration.ConfigurationManager.AppSettings["ADDomain"];
outADlogin = System.Configuration.ConfigurationManager.AppSettings["ADDomain"] + "\\" + inADlogin;
else if (inLogin.ToLower().Contains("@informa.com"))
outADdomain = System.Configuration.ConfigurationManager.AppSettings["ADDomain"];
outADlogin = System.Configuration.ConfigurationManager.AppSettings["ADDomain"] + "\\" + inLogin;
String strUserAgent = HttpContext.Current.Request.UserAgent;
strUserAgent = (strUserAgent.Length > 1000) ? strUserAgent.Substring(0,1000) : strUserAgent;
String currMonth = DateTime.Now.ToString("yyMM");
String strAllowedFair = "";
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
int isLogTableExist3 = 0;
HttpContext.Current.Response.Write(outADdomain + "-" + inADlogin + "-" + inPassword);
bool isADLogin = chkADLogin(outADdomain,inADlogin,inPassword);
bool isLocalLogin = false;
if (!inboolAD && !isADLogin) {
strSQL = "select count(*) from [User17] where Login=@Login and Password=@Password and Valid='true'";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@Login", inLogin);
cmd.Parameters.AddWithValue("@Password", inPassword);
cmd.CommandType = CommandType.Text;
int dbCountLogin = Convert.ToInt32(cmd.ExecuteScalar());
if (inboolAD || isLocalLogin || isADLogin) {
Hashtable hashUser = new Hashtable();
strSQL = "SELECT TOP (1) u.UserID, u.Name, u.Login, u.Email, u.AdminLevel FROM [User17] AS u WHERE (u.Valid = 'true') AND ((u.Login = @Login) or (u.Login = @ADLogin))";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@Login", inLogin);
cmd.Parameters.AddWithValue("@ADLogin", outADlogin);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read())
for (int i = 0; i < rdrBrowsers.FieldCount; i++)
hashUser[rdrBrowsers.GetName(i).ToString()] = rdrBrowsers.GetValue(i);
if (hashUser.ContainsKey("UserID")) {
strSQL = "select distinct substring((";
strSQL += " Select ','+ LTRIM(STR(u2.FairID,10)) AS [text()] From UserFairRelation u2 Where u1.UserID = u2.UserID ORDER BY u1.FairID";
strSQL += " For XML PATH ('')), 2, 1000) [FairPermission]";
strSQL += " From UserFairRelation u1 where u1.UserID=@UserID";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@UserID", (int)hashUser["UserID"]);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
strAllowedFair = rdrBrowsers["FairPermission"].ToString();
String sLogTable = "ActionLog";
string strSQL2 = "SELECT count(*) FROM sys.tables WHERE name = @TableName";
cmd.CommandText = strSQL2;
cmd.Parameters.AddWithValue("@TableName", sLogTable + "_" + currMonth);
isLogTableExist = (int)cmd.ExecuteScalar();
if (isLogTableExist == 0)
strSQL2 = "select * into " + sLogTable + "_" + currMonth + " from " + sLogTable + "_YYMM where 1=0; Alter Table dbo." + sLogTable + "_" + currMonth + " Drop Column rowID; ALTER TABLE dbo." + sLogTable + "_" + currMonth + " ADD rowID INT IDENTITY(1,1); ALTER TABLE dbo." + sLogTable + "_" + currMonth + " ADD CONSTRAINT PK_" + sLogTable + "_" + currMonth + " PRIMARY KEY(rowID); ";
cmd.CommandText = strSQL2;
String strLoginType = (inboolAD) ? "AutoLogin" : "Login";
strSQL = "insert into " + sLogTable + "_" + currMonth + "(UserID,FairID,Action,ActionPara,UserAgent,UserIP,CreateTime) values (@UserID,@FairID,@Action,@ActionPara,@UserAgent,@UserIP,{fn NOW()})";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@UserID", hashUser["UserID"]);
cmd.Parameters.AddWithValue("@FairID", 0);
cmd.Parameters.AddWithValue("@Action", strLoginType);
cmd.Parameters.AddWithValue("@ActionPara", "");
cmd.Parameters.AddWithValue("@UserAgent", strUserAgent);
cmd.Parameters.AddWithValue("@UserIP", getIP());
cmd.CommandType = CommandType.Text;
int dbLogID = Convert.ToInt32(cmd.ExecuteScalar());
strSQL = "update [User17] set LastLogin={fn NOW()} where UserID=@UserID ";
strSQL += " select @@ROWCOUNT;";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@UserID", hashUser["UserID"]);
cmd.CommandType = CommandType.Text;
int dbLogID2 = Convert.ToInt32(cmd.ExecuteScalar());
HttpContext.Current.Session["UserID"] = (int)hashUser["UserID"];
fromUserID = (int)hashUser["UserID"];
HttpContext.Current.Session["AdminLevel"] = (int)hashUser["AdminLevel"];
HttpContext.Current.Session["Name"] = hashUser["Name"].ToString();
HttpContext.Current.Session["Email"] = hashUser["Email"].ToString();
HttpContext.Current.Session["Login"] = hashUser["Login"].ToString();
HttpContext.Current.Session["FairPermission"] = strAllowedFair;
String sLogTable3 = "LoginFailLog";
strSQL3 = "SELECT count(*) FROM sys.tables WHERE name = @TableName";
cmd.CommandText = strSQL3;
cmd.Parameters.AddWithValue("@TableName", sLogTable3 + "_" + currMonth);
isLogTableExist3 = (int)cmd.ExecuteScalar();
if (isLogTableExist3 == 0)
strSQL3 = "select * into " + sLogTable3 + "_" + currMonth + " from " + sLogTable3 + "_YYMM where 1=0; Alter Table dbo." + sLogTable3 + "_" + currMonth + " Drop Column rowID; ALTER TABLE dbo." + sLogTable3 + "_" + currMonth + " ADD rowID INT IDENTITY(1,1); ALTER TABLE dbo." + sLogTable3 + "_" + currMonth + " ADD CONSTRAINT PK_" + sLogTable3 + "_" + currMonth + " PRIMARY KEY(rowID); ";
cmd.CommandText = strSQL3;
strSQL = "insert into " + sLogTable3 + "_" + currMonth + "(Login,Password,Reason,UserAgent,UserIP,CreateTime) values (@Login,@Password,@Reason,@UserAgent,@UserIP,{fn NOW()})";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@Login", inLogin);
cmd.Parameters.AddWithValue("@Password", inPassword);
cmd.Parameters.AddWithValue("@Action", "Login");
cmd.Parameters.AddWithValue("@Reason", "NoAccessRight");
cmd.Parameters.AddWithValue("@UserAgent", strUserAgent);
cmd.Parameters.AddWithValue("@UserIP", getIP());
cmd.CommandType = CommandType.Text;
int dbLogID3 = Convert.ToInt32(cmd.ExecuteScalar());
outHash["Err"] = "NoAccessRight";
String sLogTable3 = "LoginFailLog";
strSQL3 = "SELECT count(*) FROM sys.tables WHERE name = @TableName";
cmd.CommandText = strSQL3;
cmd.Parameters.AddWithValue("@TableName", sLogTable3 + "_" + currMonth);
isLogTableExist3 = (int)cmd.ExecuteScalar();
if (isLogTableExist3 == 0)
strSQL3 = "select * into " + sLogTable3 + "_" + currMonth + " from " + sLogTable3 + "_YYMM where 1=0; Alter Table dbo." + sLogTable3 + "_" + currMonth + " Drop Column rowID; ALTER TABLE dbo." + sLogTable3 + "_" + currMonth + " ADD rowID INT IDENTITY(1,1); ALTER TABLE dbo." + sLogTable3 + "_" + currMonth + " ADD CONSTRAINT PK_" + sLogTable3 + "_" + currMonth + " PRIMARY KEY(rowID); ";
cmd.CommandText = strSQL3;
strSQL = "insert into " + sLogTable3 + "_" + currMonth + "(Login,Password,Reason,UserAgent,UserIP,CreateTime) values (@Login,@Password,@Reason,@UserAgent,@UserIP,{fn NOW()})";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@Login", inLogin);
cmd.Parameters.AddWithValue("@Password", inPassword);
cmd.Parameters.AddWithValue("@Action", "Login");
cmd.Parameters.AddWithValue("@Reason", "InvalidPassword");
cmd.Parameters.AddWithValue("@UserAgent", strUserAgent);
cmd.Parameters.AddWithValue("@UserIP", getIP());
cmd.CommandType = CommandType.Text;
int dbLogID3 = Convert.ToInt32(cmd.ExecuteScalar());
outHash["Err"] = "InvalidPassword";
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable runLogout(Hashtable inPara) {
Hashtable outHash = new Hashtable();
HttpContext.Current.Session.Clear();
public static Hashtable getUser(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int inUserID = (inPara["UserID"] == null || inPara["UserID"].ToString() == "") ? 0 : Int32.Parse(inPara["UserID"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
Hashtable hashUserFairPermission = new Hashtable();
strSQL = "select UserID,FairID from UserFairRelation where UserID=@UserID";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@UserID", inUserID);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
String strUserPermission = hashUserFairPermission.ContainsKey((int)rdrBrowsers["UserID"]) ? hashUserFairPermission[(int)rdrBrowsers["UserID"]].ToString() : "";
strUserPermission += (strUserPermission=="") ? "" : ",";
strUserPermission += rdrBrowsers["FairID"];
hashUserFairPermission[(int)rdrBrowsers["UserID"]] = strUserPermission;
Hashtable hashUser = new Hashtable();
strSQL = "SELECT u.*,u1.Name as CreateBy,u2.Name as UpdateBy from [User17] u left outer join [User17] u1 on u.CreateByUserID=u1.UserID left outer join [User17] u2 on u.UpdateByUserID=u2.UserID where u.Valid='true'";
strSQL += (inUserID > 0) ? " and u.UserID=@UserID " : "";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@UserID", inUserID);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
Hashtable hashRow = new Hashtable();
for (int i = 0; i < rdrBrowsers.FieldCount; i++) {
switch (rdrBrowsers.GetName(i).ToString()) {
DateTime tDate = (!DBNull.Value.Equals(rdrBrowsers.GetValue(i))) ? (DateTime)rdrBrowsers.GetValue(i) : DateTime.MinValue;
String tValue = tDate.ToString("yyyy-MM-dd HH:mm:ss");
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
hashRow[rdrBrowsers.GetName(i).ToString()] = rdrBrowsers.GetValue(i);
hashRow["FairPermission"] = (hashUserFairPermission.ContainsKey((int)hashRow["UserID"])) ? hashUserFairPermission[(int)hashRow["UserID"]] : "";
hashUser[(int)rdrBrowsers["UserID"]] = hashRow;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable updateUser(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inUserID = (inPara["UserID"] == null || inPara["UserID"].ToString() == "") ? 0 : Int32.Parse(inPara["UserID"].ToString());
string inLogin = (inPara["Login"] == null) ? "" : inPara["Login"].ToString();
string inName = (inPara["Name"] == null) ? "" : inPara["Name"].ToString();
string inEmail = (inPara["Email"] == null) ? "" : inPara["Email"].ToString();
int inAdminLevel = (inPara["AdminLevel"] == null || inPara["AdminLevel"].ToString() == "") ? 0 : Int32.Parse(inPara["AdminLevel"].ToString());
string inRemark = (inPara["Remark"] == null) ? "" : inPara["Remark"].ToString();
string inFairPermission = (inPara["FairPermission"] == null) ? "" : inPara["FairPermission"].ToString();
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
strSQL = "update [User17] set Login=@Login,Name=@Name,Email=@Email,AdminLevel=@AdminLevel,Remark=@Remark,UpdateByUserID=@UpdateByUserID, UpdateTime={fn NOW()} where UserID=@UserID;";
strSQL += " select @@ROWCOUNT;";
cmd.Parameters.AddWithValue("@UserID", inUserID);
strSQL = "insert into [User17] (Login,Name,Email,AdminLevel,Remark,CreateTime,CreateByUserID,UpdateTime,UpdateByUserID,Valid) values (@Login,@Name,@Email,@AdminLevel,@Remark,{fn NOW()},@CreateByUserID,{fn NOW()},@UpdateByUserID,@Valid);";
strSQL += "select @@IDENTITY;";
cmd.Parameters.AddWithValue("@Valid", true);
cmd.Parameters.AddWithValue("@CreateByUserID", fromUserID);
cmd.Parameters.AddWithValue("@Login", inLogin);
cmd.Parameters.AddWithValue("@Name", inName);
cmd.Parameters.AddWithValue("@Email", inEmail);
cmd.Parameters.AddWithValue("@AdminLevel", inAdminLevel);
cmd.Parameters.AddWithValue("@Remark", inRemark);
cmd.Parameters.AddWithValue("@UpdateByUserID", fromUserID);
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
int dbUserID = Convert.ToInt32(cmd.ExecuteScalar());
int currUserID = (inUserID == 0) ? dbUserID : inUserID;
strSQL = "delete from UserFairRelation where UserID=@UserID;";
strSQL += " select @@ROWCOUNT;";
cmd.Parameters.AddWithValue("@UserID", currUserID);
cmd.CommandText = strSQL;
int dbUpdated = Convert.ToInt32(cmd.ExecuteScalar());
if (inFairPermission != "") {
strSQL = "insert into UserFairRelation (UserID, FairID) values ";
String[] arrFair = inFairPermission.Split(',');
foreach (String tFairID in arrFair) {
strSQLval += (strSQLval == "") ? "" : ",";
strSQLval += "(" + currUserID + "," + tFairID + ")";
strSQL += strSQLval + "; select @@ROWCOUNT;";
cmd.CommandText = strSQL;
int dbUpdated2 = Convert.ToInt32(cmd.ExecuteScalar());
outHash["Updated"] = dbUserID;
outHash["Updated"] = (dbUserID > 0) ? 1 : 0;
outHash["UserID"] = dbUserID;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable delUser(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inUserID = (inPara["UserID"] == null || inPara["UserID"].ToString() == "") ? 0 : Int32.Parse(inPara["UserID"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
String strSQL = "update [User17] set Valid='false', UpdateByUserID=@UpdateByUserID, UpdateTime={fn NOW()} where UserID=@UserID ";
strSQL += " select @@ROWCOUNT;";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@UpdateByUserID", fromUserID);
cmd.Parameters.AddWithValue("@UserID", inUserID);
cmd.CommandType = CommandType.Text;
int dbLogID = Convert.ToInt32(cmd.ExecuteScalar());
outHash["Updated"] = dbLogID;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable getFair(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
Hashtable hashUserFairPermission = new Hashtable();
strSQL = "select UserID,FairID from UserFairRelation where FairID=@FairID";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
String strUserPermission = hashUserFairPermission.ContainsKey((int)rdrBrowsers["FairID"]) ? hashUserFairPermission[(int)rdrBrowsers["FairID"]].ToString() : "";
strUserPermission += (strUserPermission=="") ? "" : ",";
strUserPermission += rdrBrowsers["UserID"];
hashUserFairPermission[(int)rdrBrowsers["FairID"]] = strUserPermission;
Hashtable hashFair = new Hashtable();
strSQL = "SELECT f.*,(select count(*) from EnquiryExhibitorMatch eem left outer join Exhibitor ex on eem.ExhibitorID=ex.ExhibitorID where ex.FairID=f.FairID) as EnquiryCount,u1.Name as CreateBy,u2.Name as UpdateBy from Fair f left outer join [User17] u1 on f.CreateByUserID=u1.UserID left outer join [User17] u2 on f.UpdateByUserID=u2.UserID where f.Status='true'";
strSQL += (inFairID > 0) ? " and f.FairID=@FairID " : "";
strSQL += " order by f.FairID ";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
Hashtable hashRow = new Hashtable();
for (int i = 0; i < rdrBrowsers.FieldCount; i++) {
switch (rdrBrowsers.GetName(i).ToString()) {
DateTime tDate = (!DBNull.Value.Equals(rdrBrowsers.GetValue(i))) ? (DateTime)rdrBrowsers.GetValue(i) : DateTime.MinValue;
String tValue = tDate.ToString("yyyy-MM-dd HH:mm:ss");
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
hashRow[rdrBrowsers.GetName(i).ToString()] = rdrBrowsers.GetValue(i);
hashRow["UserPermission"] = (hashUserFairPermission.ContainsKey((int)hashRow["FairID"])) ? hashUserFairPermission[(int)hashRow["FairID"]] : "";
hashFair[(int)rdrBrowsers["FairID"]] = hashRow;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable updateFair(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
string inEMSFairID = (inPara["EMSFairID"] == null) ? "" : inPara["EMSFairID"].ToString();
string inName = (inPara["Name"] == null) ? "" : inPara["Name"].ToString();
string inURL = (inPara["URL"] == null) ? "" : inPara["URL"].ToString();
int inEMSIndustryID = (inPara["EMSIndustryID"] == null || inPara["EMSIndustryID"].ToString() == "") ? 0 : Int32.Parse(inPara["EMSIndustryID"].ToString());
int inIndustryID = (inPara["IndustryID"] == null || inPara["IndustryID"].ToString() == "") ? 0 : Int32.Parse(inPara["IndustryID"].ToString());
int inApiVer = (inPara["ApiVer"] == null || inPara["ApiVer"].ToString() == "") ? 0 : Int32.Parse(inPara["ApiVer"].ToString());
String inEnquiryEmailSubject = (inPara["EnquiryEmailSubject"] == null) ? "" : inPara["EnquiryEmailSubject"].ToString();
String inEnquiryFromEmail = (inPara["EnquiryFromEmail"] == null) ? "" : inPara["EnquiryFromEmail"].ToString();
String inEnquiryFromName = (inPara["EnquiryFromName"] == null) ? "" : inPara["EnquiryFromName"].ToString();
bool inEnquiryTestingMode = (inPara["EnquiryTestingMode"] == null || inPara["EnquiryTestingMode"] == "") ? false : Convert.ToBoolean(inPara["EnquiryTestingMode"].ToString());
String inEnquiryTestingEmail = (inPara["EnquiryTestingEmail"] == null) ? "" : inPara["EnquiryTestingEmail"].ToString();
String inEnquiryBccEmail = (inPara["EnquiryBccEmail"] == null) ? "" : inPara["EnquiryBccEmail"].ToString();
int inNumOfProduct = (inPara["NumOfProduct"] == null || inPara["NumOfProduct"].ToString() == "") ? 0 : Int32.Parse(inPara["NumOfProduct"].ToString());
String[] inlabExhibitorField = new String[31];
for (int I=1; I<=30; I++) {
string strI = (I < 10) ? "0" + I : I.ToString();
inlabExhibitorField[I] = (inPara["labExhibitorField" + strI] == null) ? "" : inPara["labExhibitorField" + strI].ToString();
String[] inlabProductField = new String[10];
for (int I=1; I<=9; I++) {
inlabProductField[I] = (inPara["labProductField" + I] == null) ? "" : inPara["labProductField" + I].ToString();
string inUserPermission = (inPara["UserPermission"] == null) ? "" : inPara["UserPermission"].ToString();
bool inCopyMode = (inPara["CopyMode"] == null || inPara["CopyMode"] == "") ? false : Convert.ToBoolean(inPara["CopyMode"].ToString());
int inCopyFromFairID = (inPara["CopyFromFairID"] == null || inPara["CopyFromFairID"].ToString() == "") ? 0 : Int32.Parse(inPara["CopyFromFairID"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
strSQL = "update fair set EMSFairID=@EMSFairID,EMSIndustryID=@EMSIndustryID,Name=@Name,URL=@URL,IndustryID=@IndustryID";
strSQL += ",ApiVer=@ApiVer,EnquiryEmailSubject=@EnquiryEmailSubject,EnquiryFromEmail=@EnquiryFromEmail,EnquiryFromName=@EnquiryFromName,EnquiryTestingMode=@EnquiryTestingMode,EnquiryTestingEmail=@EnquiryTestingEmail,EnquiryBccEmail=@EnquiryBccEmail,NumOfProduct=@NumOfProduct";
for (int I=1; I<=30; I++) {
string strI = (I < 10) ? "0" + I : I.ToString();
strSQL += ",labExhibitorField" + strI + "=@labExhibitorField" + strI;
for (int I=1; I<=9; I++) {
strSQL += ",labProductField" + I + "=@labProductField" + I;
strSQL += ",UpdateByUserID=@UpdateByUserID, UpdateTime={fn NOW()} where FairID=@FairID;";
strSQL += " select @@ROWCOUNT;";
cmd.Parameters.AddWithValue("@FairID", inFairID);
strSQL = "insert into fair";
strSQL += "(EMSFairID,EMSIndustryID,Name,URL,IndustryID,CopyFromFairID,ApiVer,EnquiryEmailSubject,EnquiryFromEmail,EnquiryFromName,EnquiryTestingMode,EnquiryTestingEmail,EnquiryBccEmail,NumOfProduct";
for (int I=1; I<=30; I++) {
string strI = (I < 10) ? "0" + I : I.ToString();
strSQL += ",labExhibitorField" + strI;
for (int I=1; I<=9; I++) {
strSQL += ",labProductField" + I;
strSQL += ",CreateTime,CreateByUserID,UpdateTime,UpdateByUserID,Status) values ";
strSQL += "(@EMSFairID,@EMSIndustryID,@Name,@URL,@IndustryID,@CopyFromFairID,@ApiVer,@EnquiryEmailSubject,@EnquiryFromEmail,@EnquiryFromName,@EnquiryTestingMode,@EnquiryTestingEmail,@EnquiryBccEmail,@NumOfProduct";
for (int I=1; I<=30; I++) {
string strI = (I < 10) ? "0" + I : I.ToString();
strSQL += ",@labExhibitorField" + strI;
for (int I=1; I<=9; I++) {
strSQL += ",@labProductField" + I;
strSQL += ",{fn NOW()},@CreateByUserID,{fn NOW()},@UpdateByUserID,@Status);";
strSQL += "select @@IDENTITY;";
cmd.Parameters.AddWithValue("@CopyFromFairID", inCopyFromFairID);
cmd.Parameters.AddWithValue("@Status", true);
cmd.Parameters.AddWithValue("@CreateByUserID", fromUserID);
cmd.Parameters.AddWithValue("@EMSFairID", inEMSFairID);
cmd.Parameters.AddWithValue("@EMSIndustryID", inEMSIndustryID);
cmd.Parameters.AddWithValue("@Name", inName);
cmd.Parameters.AddWithValue("@URL", inURL);
cmd.Parameters.AddWithValue("@IndustryID", inIndustryID);
cmd.Parameters.AddWithValue("@ApiVer", inApiVer);
cmd.Parameters.AddWithValue("@EnquiryEmailSubject", inEnquiryEmailSubject);
cmd.Parameters.AddWithValue("@EnquiryFromEmail", inEnquiryFromEmail);
cmd.Parameters.AddWithValue("@EnquiryFromName", inEnquiryFromName);
cmd.Parameters.AddWithValue("@EnquiryTestingMode", inEnquiryTestingMode);
cmd.Parameters.AddWithValue("@EnquiryTestingEmail", inEnquiryTestingEmail);
cmd.Parameters.AddWithValue("@EnquiryBccEmail", inEnquiryBccEmail);
cmd.Parameters.AddWithValue("@NumOfProduct", inNumOfProduct);
for (int I=1; I<=30; I++) {
string strI = (I < 10) ? "0" + I : I.ToString();
cmd.Parameters.AddWithValue("@labExhibitorField" + strI, inlabExhibitorField[I]);
for (int I=1; I<=9; I++) {
cmd.Parameters.AddWithValue("@labProductField" + I, inlabProductField[I]);
cmd.Parameters.AddWithValue("@UpdateByUserID", fromUserID);
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
int dbFairID = Convert.ToInt32(cmd.ExecuteScalar());
int currFairID = (inFairID == 0) ? dbFairID : inFairID;
strSQL = "delete from UserFairRelation where FairID=@FairID;";
strSQL += " select @@ROWCOUNT;";
cmd.Parameters.AddWithValue("@FairID", currFairID);
cmd.CommandText = strSQL;
int dbUpdated = Convert.ToInt32(cmd.ExecuteScalar());
if (inUserPermission != "") {
strSQL = "insert into UserFairRelation (UserID, FairID) values ";
String[] arrUser = inUserPermission.Split(',');
foreach (String tUserID in arrUser) {
strSQLval += (strSQLval == "") ? "" : ",";
strSQLval += "(" + tUserID + "," + currFairID + ")";
strSQL += strSQLval + "; select @@ROWCOUNT;";
cmd.CommandText = strSQL;
int dbUpdated2 = Convert.ToInt32(cmd.ExecuteScalar());
if (inCopyMode == true && inCopyFromFairID > 0) {
strSQL = "insert into UserFairRelation (FairID, UserID) ";
strSQL += "select @NewFairID, UserID from UserFairRelation where FairID=@FairID";
strSQL += " select @@ROWCOUNT;";
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@NewFairID", dbFairID);
cmd.Parameters.AddWithValue("@FairID", inCopyFromFairID);
int dbItemCount = Convert.ToInt32(cmd.ExecuteScalar());
strSQL = "insert into FairLocation (FairID, VenueID, HallID, ItemOrder, Status, CreateTime, UpdateTime, CreateByUserID, UpdateByUserID) ";
strSQL += "select @NewFairID, VenueID, HallID, ItemOrder, Status, {fn NOW()}, {fn NOW()}, @CreateByAdminID, @UpdateByAdminID ";
strSQL += "from FairLocation where FairID=@FairID and Status = 'true'";
strSQL += " select @@ROWCOUNT;";
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@NewFairID", dbFairID);
cmd.Parameters.AddWithValue("@FairID", inCopyFromFairID);
cmd.Parameters.AddWithValue("@UpdateByAdminID", fromUserID);
cmd.Parameters.AddWithValue("@CreateByAdminID", fromUserID);
dbItemCount = Convert.ToInt32(cmd.ExecuteScalar());
strSQL = "insert into ProductCategory (FairID, ParentProductCategoryID, ItemOrder, NameEn, NameEnShort, NameCht, NameChtShort, NameChs, NameChsShort, CopyFromProductCategoryID, Status, CreateTime, UpdateTime, CreateByUserID, UpdateByUserID) ";
strSQL += "select @NewFairID, ParentProductCategoryID, ItemOrder, NameEn, NameEnShort, NameCht, NameChtShort, NameChs, NameChsShort, ProductCategoryID, Status, {fn NOW()}, {fn NOW()}, @CreateByAdminID, @UpdateByAdminID ";
strSQL += "from ProductCategory where FairID=@FairID and Status = 'true'";
strSQL += " select @@ROWCOUNT;";
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@NewFairID", dbFairID);
cmd.Parameters.AddWithValue("@FairID", inCopyFromFairID);
cmd.Parameters.AddWithValue("@UpdateByAdminID", fromUserID);
cmd.Parameters.AddWithValue("@CreateByAdminID", fromUserID);
dbItemCount = Convert.ToInt32(cmd.ExecuteScalar());
Hashtable hashProductCatOldToNew = new Hashtable();
strSQL = "select ProductCategoryID, CopyFromProductCategoryID from ProductCategory where FairID=@FairID";
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@FairID", dbFairID);
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read())
hashProductCatOldToNew[(int)rdrBrowsers["CopyFromProductCategoryID"]] = (int)rdrBrowsers["ProductCategoryID"];
foreach (int tOldProductCatID in hashProductCatOldToNew.Keys) {
strSQL = "update ProductCategory set ParentProductCategoryID=@ParentProductCategoryID ";
strSQL += " where FairID=@FairID and ParentProductCategoryID=@OldParentProductCategoryID ;";
strSQL += " select @@ROWCOUNT;";
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@FairID", dbFairID);
cmd.Parameters.AddWithValue("@ParentProductCategoryID", (int)hashProductCatOldToNew[tOldProductCatID]);
cmd.Parameters.AddWithValue("@OldParentProductCategoryID", tOldProductCatID);
dbItemCount = Convert.ToInt32(cmd.ExecuteScalar());
strSQL = "insert into BusinessNature (FairID, ItemOrder, NameEn, NameEnShort, NameCht, NameChtShort, NameChs, NameChsShort, Status, CreateTime, UpdateTime, CreateByUserID, UpdateByUserID) ";
strSQL += "select @NewFairID, ItemOrder, NameEn, NameEnShort, NameCht, NameChtShort, NameChs, NameChsShort, Status, {fn NOW()}, {fn NOW()}, @CreateByAdminID, @UpdateByAdminID ";
strSQL += "from BusinessNature where FairID=@FairID and Status = 'true'";
strSQL += " select @@ROWCOUNT;";
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@NewFairID", dbFairID);
cmd.Parameters.AddWithValue("@FairID", inCopyFromFairID);
cmd.Parameters.AddWithValue("@UpdateByAdminID", fromUserID);
cmd.Parameters.AddWithValue("@CreateByAdminID", fromUserID);
dbItemCount = Convert.ToInt32(cmd.ExecuteScalar());
strSQL = "insert into ExhibitorType (FairID, ItemOrder, NameEn, NameEnShort, NameCht, NameChtShort, NameChs, NameChsShort, Status, CreateTime, UpdateTime, CreateByUserID, UpdateByUserID) ";
strSQL += "select @NewFairID, ItemOrder, NameEn, NameEnShort, NameCht, NameChtShort, NameChs, NameChsShort, Status, {fn NOW()}, {fn NOW()}, @CreateByAdminID, @UpdateByAdminID ";
strSQL += "from ExhibitorType where FairID=@FairID and Status = 'true'";
strSQL += " select @@ROWCOUNT;";
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@NewFairID", dbFairID);
cmd.Parameters.AddWithValue("@FairID", inCopyFromFairID);
cmd.Parameters.AddWithValue("@UpdateByAdminID", fromUserID);
cmd.Parameters.AddWithValue("@CreateByAdminID", fromUserID);
dbItemCount = Convert.ToInt32(cmd.ExecuteScalar());
outHash["Updated"] = dbFairID;
outHash["Updated"] = (dbFairID > 0) ? 1 : 0;
outHash["FairID"] = dbFairID;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable delFair(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
String strSQL = "update fair set Status='false', UpdateByUserID=@UpdateByUserID, UpdateTime={fn NOW()} where FairID=@FairID ";
strSQL += " select @@ROWCOUNT;";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@UpdateByUserID", fromUserID);
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.CommandType = CommandType.Text;
int dbLogID = Convert.ToInt32(cmd.ExecuteScalar());
outHash["Updated"] = dbLogID;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable getExhibitorPrefix(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
string inLang = (inPara["LangCode"] == null) ? "En" : inPara["LangCode"].ToString();
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
Hashtable hashExhibitor = new Hashtable();
strSQL = "SELECT DISTINCT SUBSTRING(ExhibitorName"+inLang+", 1, 1) AS CompanyNamePrefix FROM Exhibitor AS e WHERE (Status = 'true')";
strSQL += (inFairID > 0) ? " and FairID=@FairID " : "";
strSQL += "ORDER BY CompanyNamePrefix";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
Hashtable hashRow = new Hashtable();
for (int i = 0; i < rdrBrowsers.FieldCount; i++) {
switch (rdrBrowsers.GetName(i).ToString()) {
DateTime tDate = (!DBNull.Value.Equals(rdrBrowsers.GetValue(i))) ? (DateTime)rdrBrowsers.GetValue(i) : DateTime.MinValue;
String tValue = tDate.ToString("yyyy-MM-dd HH:mm:ss");
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
hashRow[rdrBrowsers.GetName(i).ToString()] = rdrBrowsers.GetValue(i);
hashExhibitor[rdrBrowsers["CompanyNamePrefix"]] = hashRow;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable getExhibitor(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int inExhibitorID = (inPara["ExhibitorID"] == null || inPara["ExhibitorID"].ToString() == "") ? 0 : Int32.Parse(inPara["ExhibitorID"].ToString());
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
int inLangID = (inPara["LangID"] == null || inPara["LangID"].ToString() == "") ? 0 : Int32.Parse(inPara["LangID"].ToString());
bool inIncludeDeleted = (inPara["IncludeDeleted"] == null || inPara["IncludeDeleted"] == "") ? false : Convert.ToBoolean(inPara["IncludeDeleted"].ToString());
bool inShowDeletedOnly = (inPara["ShowDeletedOnly"] == null || inPara["ShowDeletedOnly"] == "") ? false : Convert.ToBoolean(inPara["ShowDeletedOnly"].ToString());
String inDTorderfields = (inPara["orderfields"] == null) ? "" : inPara["orderfields"].ToString();
bool inDTmode = (inPara["DTmode"] == null || inPara["DTmode"] == "") ? false : Convert.ToBoolean(inPara["DTmode"].ToString());
bool inDTcount = (inPara["DTcount"] == null || inPara["DTcount"] == "") ? false : Convert.ToBoolean(inPara["DTcount"].ToString());
int inDTstart = (inPara["start"] == null || inPara["start"].ToString() == "") ? 0 : Int32.Parse(inPara["start"].ToString());
int inDTlength = (inPara["length"] == null || inPara["length"].ToString() == "") ? 0 : Int32.Parse(inPara["length"].ToString());
int inDTordercol = (inPara["order[0][column]"] == null || inPara["order[0][column]"].ToString() == "") ? 0 : Int32.Parse(inPara["order[0][column]"].ToString());
String inDTorderdir = (inPara["order[0][dir]"] == null) ? "asc" : inPara["order[0][dir]"].ToString();
String inDTsearch = (inPara["search[value]"] == null) ? "" : inPara["search[value]"].ToString();
Hashtable inHashOrdercol = new Hashtable();
for (int i = 0; i <=4; i++){
if (inPara["order["+i.ToString()+"][column]"] != null){
int intCol = inPara["order["+i.ToString()+"][column]"].ToString() == "" ? 2 : Int32.Parse(inPara["order["+i.ToString()+"][column]"].ToString());
inHashOrdercol[intCol] = (inPara["order["+i.ToString()+"][dir]"] == null) ? "asc" : inPara["order["+i.ToString()+"][dir]"].ToString();
Hashtable inDTfilter = new Hashtable();
inDTfilter["Country"] = (inPara["filter[country]"] == null) ? "" : inPara["filter[country]"].ToString();
inDTfilter["CompanyPrefix"] = (inPara["filter[companyprefix]"] == null) ? "" : inPara["filter[companyprefix]"].ToString();
inDTfilter["ProductCategory"] = (inPara["filter[productcategory]"] == null) ? "" : inPara["filter[productcategory]"].ToString();
inDTfilter["BusinessNature"] = (inPara["filter[businessnature]"] == null) ? "" : inPara["filter[businessnature]"].ToString();
inDTfilter["ExhibitorType"] = (inPara["filter[exhibitortype]"] == null) ? "" : inPara["filter[exhibitortype]"].ToString();
inDTfilter["Venue"] = (inPara["filter[venue]"] == null) ? "" : inPara["filter[venue]"].ToString();
inDTfilter["FairLocation"] = (inPara["filter[fairlocation]"] == null) ? "" : inPara["filter[fairlocation]"].ToString();
inDTfilter["New"] = (inPara["filter[new]"] == null || inPara["filter[new]"] == "") ? false : Convert.ToBoolean(inPara["filter[new]"].ToString());
inDTfilter["FeaturedArea"] = (inPara["filter[featuredarea]"] == null) ? "" : inPara["filter[featuredarea]"].ToString();
inDTfilter["ExhibitorID"] = (inPara["filter[exhibitorid]"] == null) ? "" : inPara["filter[exhibitorid]"].ToString();
inDTfilter["SponsorField"] = (inPara["filter[sponsorfield]"] == null) ? "" : inPara["filter[sponsorfield]"].ToString();
for (int I=1; I<=30; I++) {
String strI = (I < 10) ? "0" + I : I.ToString();
inDTfilter["Exhibitor_Field" + strI] = (inPara["filter[exhibitor_field" + strI + "]"] == null) ? "" : inPara["filter[exhibitor_field" + strI + "]"].ToString();
for (int I=1; I<=9; I++) {
inDTfilter["Product_Field" + I] = (inPara["filter[product_field" + I + "]"] == null) ? "" : inPara["filter[product_field" + I + "]"].ToString();
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
Hashtable hashExhibitorProductCat = new Hashtable();
Hashtable hashExhibitorProductCatEn = new Hashtable();
Hashtable hashExhibitorProductCatCht = new Hashtable();
Hashtable hashExhibitorProductCatChs = new Hashtable();
Hashtable hashExhibitorBusinessNature = new Hashtable();
Hashtable hashExhibitorBusinessNatureEn = new Hashtable();
Hashtable hashExhibitorBusinessNatureCht = new Hashtable();
Hashtable hashExhibitorBusinessNatureChs = new Hashtable();
Hashtable hashExhibitorExhibitorType = new Hashtable();
Hashtable hashExhibitorExhibitorTypeEn = new Hashtable();
Hashtable hashExhibitorExhibitorTypeCht = new Hashtable();
Hashtable hashExhibitorExhibitorTypeChs = new Hashtable();
if (inFairID > 0 || inExhibitorID > 0) {
strSQL = "select ep.ExhibitorID,ep.ProductCategoryID,pc.NameEn,pc.NameCht,pc.NameChs from ExhibitorProductCategoryMatch ep join Exhibitor e on ep.ExhibitorID=e.ExhibitorID left outer join ProductCategory pc on ep.ProductCategoryID=pc.ProductCategoryID where ep.Status='true' and e.Status='true'";
strSQL += (inFairID > 0) ? " and e.FairID=@FairID " : "";
strSQL += (inExhibitorID > 0) ? " and e.ExhibitorID=@ExhibitorID " : "";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.Parameters.AddWithValue("@ExhibitorID", inExhibitorID);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
String strProductCat = hashExhibitorProductCat.ContainsKey((int)rdrBrowsers["ExhibitorID"]) ? hashExhibitorProductCat[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
strProductCat += (strProductCat=="") ? "" : ",";
strProductCat += rdrBrowsers["ProductCategoryID"];
hashExhibitorProductCat[(int)rdrBrowsers["ExhibitorID"]] = strProductCat;
strProductCat = hashExhibitorProductCatEn.ContainsKey((int)rdrBrowsers["ExhibitorID"]) ? hashExhibitorProductCatEn[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
strProductCat += (strProductCat=="") ? "" : ",";
strProductCat += rdrBrowsers["NameEn"];
hashExhibitorProductCatEn[(int)rdrBrowsers["ExhibitorID"]] = strProductCat;
strProductCat = hashExhibitorProductCatCht.ContainsKey((int)rdrBrowsers["ExhibitorID"]) ? hashExhibitorProductCatCht[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
strProductCat += (strProductCat=="") ? "" : ",";
strProductCat += rdrBrowsers["NameCht"];
hashExhibitorProductCatCht[(int)rdrBrowsers["ExhibitorID"]] = strProductCat;
strProductCat = hashExhibitorProductCatChs.ContainsKey((int)rdrBrowsers["ExhibitorID"]) ? hashExhibitorProductCatChs[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
strProductCat += (strProductCat=="") ? "" : ",";
strProductCat += rdrBrowsers["NameChs"];
hashExhibitorProductCatChs[(int)rdrBrowsers["ExhibitorID"]] = strProductCat;
if (inFairID > 0 || inExhibitorID > 0) {
strSQL = "select eb.ExhibitorID,eb.BusinessNatureID,bn.NameEn,bn.NameCht,bn.NameChs from ExhibitorBusinessNatureMatch eb join Exhibitor e on eb.ExhibitorID=e.ExhibitorID left outer join BusinessNature bn on eb.BusinessNatureID=bn.BusinessNatureID where eb.Status='true' and e.Status='true'";
strSQL += (inFairID > 0) ? " and e.FairID=@FairID " : "";
strSQL += (inExhibitorID > 0) ? " and e.ExhibitorID=@ExhibitorID " : "";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.Parameters.AddWithValue("@ExhibitorID", inExhibitorID);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
String strBusinessNature = hashExhibitorBusinessNature.ContainsKey((int)rdrBrowsers["ExhibitorID"]) ? hashExhibitorBusinessNature[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
strBusinessNature += (strBusinessNature=="") ? "" : ",";
strBusinessNature += rdrBrowsers["BusinessNatureID"];
hashExhibitorBusinessNature[(int)rdrBrowsers["ExhibitorID"]] = strBusinessNature;
strBusinessNature = hashExhibitorBusinessNatureEn.ContainsKey((int)rdrBrowsers["ExhibitorID"]) ? hashExhibitorBusinessNatureEn[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
strBusinessNature += (strBusinessNature=="") ? "" : ",";
strBusinessNature += rdrBrowsers["NameEn"];
hashExhibitorBusinessNatureEn[(int)rdrBrowsers["ExhibitorID"]] = strBusinessNature;
strBusinessNature = hashExhibitorBusinessNatureCht.ContainsKey((int)rdrBrowsers["ExhibitorID"]) ? hashExhibitorBusinessNatureCht[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
strBusinessNature += (strBusinessNature=="") ? "" : ",";
strBusinessNature += rdrBrowsers["NameCht"];
hashExhibitorBusinessNatureCht[(int)rdrBrowsers["ExhibitorID"]] = strBusinessNature;
strBusinessNature = hashExhibitorBusinessNatureChs.ContainsKey((int)rdrBrowsers["ExhibitorID"]) ? hashExhibitorBusinessNatureChs[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
strBusinessNature += (strBusinessNature=="") ? "" : ",";
strBusinessNature += rdrBrowsers["NameCht"];
hashExhibitorBusinessNatureChs[(int)rdrBrowsers["ExhibitorID"]] = strBusinessNature;
if (inFairID > 0 || inExhibitorID > 0) {
strSQL = "select et.ExhibitorID,et.ExhibitorTypeID,t.NameEn,t.NameCht,t.NameChs from ExhibitorTypeMatch et join Exhibitor e on et.ExhibitorID=e.ExhibitorID left outer join ExhibitorType t on et.ExhibitorTypeID=t.ExhibitorTypeID where et.Status='true' and e.Status='true'";
strSQL += (inFairID > 0) ? " and e.FairID=@FairID " : "";
strSQL += (inExhibitorID > 0) ? " and e.ExhibitorID=@ExhibitorID " : "";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.Parameters.AddWithValue("@ExhibitorID", inExhibitorID);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
String strExhibitorType = hashExhibitorExhibitorType.ContainsKey((int)rdrBrowsers["ExhibitorID"]) ? hashExhibitorExhibitorType[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
strExhibitorType += (strExhibitorType=="") ? "" : ",";
strExhibitorType += rdrBrowsers["ExhibitorTypeID"];
hashExhibitorExhibitorType[(int)rdrBrowsers["ExhibitorID"]] = strExhibitorType;
strExhibitorType = hashExhibitorExhibitorTypeEn.ContainsKey((int)rdrBrowsers["ExhibitorID"]) ? hashExhibitorExhibitorTypeEn[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
strExhibitorType += (strExhibitorType=="") ? "" : ",";
strExhibitorType += rdrBrowsers["NameEn"];
hashExhibitorExhibitorTypeEn[(int)rdrBrowsers["ExhibitorID"]] = strExhibitorType;
strExhibitorType = hashExhibitorExhibitorTypeCht.ContainsKey((int)rdrBrowsers["ExhibitorID"]) ? hashExhibitorExhibitorTypeCht[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
strExhibitorType += (strExhibitorType=="") ? "" : ",";
strExhibitorType += rdrBrowsers["NameCht"];
hashExhibitorExhibitorTypeCht[(int)rdrBrowsers["ExhibitorID"]] = strExhibitorType;
strExhibitorType = hashExhibitorExhibitorTypeChs.ContainsKey((int)rdrBrowsers["ExhibitorID"]) ? hashExhibitorExhibitorTypeChs[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
strExhibitorType += (strExhibitorType=="") ? "" : ",";
strExhibitorType += rdrBrowsers["NameChs"];
hashExhibitorExhibitorTypeChs[(int)rdrBrowsers["ExhibitorID"]] = strExhibitorType;
Hashtable hashExhibitor = new Hashtable();
strSQL = "select count(distinct e.ExhibitorID) as Count ";
strSQL = "SELECT distinct e.*, c.NameEn as Country, c.NameEn as CountryEn, c.NameCht as CountryCht, c.NameChs as CountryChs, f.EMSFairID as Fair, u1.Name AS CreateBy, u2.Name AS UpdateBy ";
strSQL += " ,cl.Name as CountryLang ";
strSQL += " from Exhibitor AS e left outer join Country c on e.CountryID=c.CountryID INNER JOIN Fair AS f ON e.FairID = f.FairID left outer join [User17] AS u1 ON e.CreateByUserID = u1.UserID left outer JOIN [User17] AS u2 ON e.UpdateByUserID = u2.UserID";
strSQL += " left outer join ExhibitorProductCategoryMatch epc on e.ExhibitorID=epc.ExhibitorID ";
strSQL += " left outer join ExhibitorBusinessNatureMatch ebn on e.ExhibitorID=ebn.ExhibitorID ";
strSQL += " left outer join ExhibitorTypeMatch et on e.ExhibitorID=et.ExhibitorID ";
strSQL += " left outer join ExhibitorFairLocationMatch efl on e.ExhibitorID=efl.ExhibitorID ";
strSQL += " left outer join FairLocation fl on efl.FairLocationID=fl.FairLocationID left outer join Venue v on v.VenueID=fl.VenueID ";
strSQL += " left outer join Product p on e.ExhibitorID=p.ExhibitorID ";
strSQL += " left outer join ProductProductCategoryMatch ppc on p.ProductID=ppc.ProductID ";
strSQL += " left outer join ProductCategory pc1 on epc.ProductCategoryID=pc1.ProductCategoryID ";
strSQL += " left outer join ProductCategory pc2 on epc.ProductCategoryID=pc2.ProductCategoryID ";
if (inLangID > 0 && !inDTcount) {
strSQL += " left outer join CountryLang cl on c.CountryID=cl.CountryID ";
strSQL += " WHERE (1=1)";
strSQL += (inShowDeletedOnly) ? " and (e.Status = 'false')" : ((inIncludeDeleted) ? " " : " and (e.Status = 'true')");
strSQL += (inLangID > 0 && !inDTcount) ? " and (cl.LangID=" + inLangID + ") " : "";
strSQL += (inFairID > 0) ? " and e.FairID=@FairID " : "";
strSQL += (inExhibitorID > 0) ? " and e.ExhibitorID=@ExhibitorID " : "";
inDTsearch = inDTsearch.Replace("'","''");
strSQL += "e.ExhibitorNameEn like N'%"+inDTsearch+"%' ";
strSQL += "or e.ExhibitorNameCht like N'%"+inDTsearch+"%' ";
strSQL += "or e.ExhibitorNameChs like N'%"+inDTsearch+"%' ";
strSQL += "or e.BrandEn like N'%"+inDTsearch+"%' ";
strSQL += "or e.BrandCht like N'%"+inDTsearch+"%' ";
strSQL += "or e.BrandChs like N'%"+inDTsearch+"%' ";
for (int I=1; I<=30; I++) {
String strI = (I < 10) ? "0" + I : I.ToString();
strSQL += "or e.Field" + strI + " like N'%"+inDTsearch+"%' ";
strSQL += "or e.StandNoStr like N'%"+inDTsearch+"%' ";
strSQL += "or c.NameEn like N'%"+inDTsearch+"%' ";
strSQL += "or c.NameCht like N'%"+inDTsearch+"%' ";
strSQL += "or c.NameChs like N'%"+inDTsearch+"%' ";
strSQL += "or p.NameEn like N'%"+inDTsearch+"%' ";
strSQL += "or p.NameCht like N'%"+inDTsearch+"%' ";
strSQL += "or p.NameChs like N'%"+inDTsearch+"%' ";
strSQL += "or pc1.NameEn like N'%"+inDTsearch+"%' ";
strSQL += "or pc1.NameCht like N'%"+inDTsearch+"%' ";
strSQL += "or pc1.NameChs like N'%"+inDTsearch+"%' ";
strSQL += "or pc2.NameEn like N'%"+inDTsearch+"%' ";
strSQL += "or pc2.NameCht like N'%"+inDTsearch+"%' ";
strSQL += "or pc2.NameChs like N'%"+inDTsearch+"%' ";
for (int I=1; I<=9; I++) {
strSQL += "or p.Field" + I + " like N'%"+inDTsearch+"%' ";
strSQL += (inDTfilter["Country"] == "") ? "" : " and e.CountryID in (" + inDTfilter["Country"] + ")";
strSQL += (inDTfilter["CompanyPrefix"] == "") ? "" : " and (e.ExhibitorNameEn like N'" + inDTfilter["CompanyPrefix"].ToString().Replace("'","''") + "%' or e.ExhibitorNameCHT like N'" + inDTfilter["CompanyPrefix"].ToString().Replace("'","''") + "%' or e.ExhibitorNameChs like N'" + inDTfilter["CompanyPrefix"].ToString().Replace("'","''") + "%')";
strSQL += (inDTfilter["ProductCategory"] == "") ? "" : " and (epc.ProductCategoryID in (" + inDTfilter["ProductCategory"] + ") or ppc.ProductCategoryID in (" + inDTfilter["ProductCategory"] + "))";
strSQL += (inDTfilter["BusinessNature"] == "") ? "" : " and ebn.BusinessNatureID in (" + inDTfilter["BusinessNature"] + ")";
strSQL += (inDTfilter["ExhibitorType"] == "") ? "" : " and et.ExhibitorTypeID in (" + inDTfilter["ExhibitorType"] + ")";
strSQL += (inDTfilter["FairLocation"] == "") ? "" : " and efl.FairLocationID in (" + inDTfilter["FairLocation"] + ")";
strSQL += (inDTfilter["Venue"] == "") ? "" : " and v.VenueID in (" + inDTfilter["Venue"] + ")";
if (inDTfilter["FeaturedArea"] != "") {
String[] arrFeatredArea = inDTfilter["FeaturedArea"].ToString().Split(',');
String searchFeatredArea = "";
foreach (String tWord in arrFeatredArea) {
searchFeatredArea += (searchFeatredArea == "") ? "" : ",";
searchFeatredArea += "'" + tWord.Replace("'","\'") + "'";
strSQL += " and e.FeaturedArea in (" + searchFeatredArea + ")";
strSQL += ((bool)inDTfilter["New"] == true) ? " and e.JoinedYear = 0" : "";
strSQL += (inDTfilter["ExhibitorID"] == "") ? "" : " and e.ExhibitorID in (" + inDTfilter["ExhibitorID"] + ")";
for (int I=1; I<=30; I++) {
String strI = (I < 10) ? "0" + I : I.ToString();
strSQL += (inDTfilter["Exhibitor_Field" + strI] == "") ? "" : " and e.Field" + strI + " like N'%" + inDTfilter["Exhibitor_Field" + strI] + "%'";
for (int I=1; I<=9; I++) {
strSQL += (inDTfilter["Product_Field" + I] == "") ? "" : " and p.Field" + I + " like N'%" + inDTfilter["Product_Field" + I] + "%'";
string strSponsorSQL = "";
if(inDTfilter["SponsorField"] != "" && !inDTcount){
strSponsorSQL = "select count(distinct e.ExhibitorID) as Count ";
strSponsorSQL = "SELECT distinct e.*, c.NameEn as Country, c.NameEn as CountryEn, c.NameCht as CountryCht, c.NameChs as CountryChs, f.EMSFairID as Fair, u1.Name AS CreateBy, u2.Name AS UpdateBy ";
strSponsorSQL += " ,cl.Name as CountryLang ";
strSponsorSQL += " from Exhibitor AS e left outer join Country c on e.CountryID=c.CountryID INNER JOIN Fair AS f ON e.FairID = f.FairID left outer join [User17] AS u1 ON e.CreateByUserID = u1.UserID left outer JOIN [User17] AS u2 ON e.UpdateByUserID = u2.UserID";
strSponsorSQL += " left outer join ExhibitorProductCategoryMatch epc on e.ExhibitorID=epc.ExhibitorID ";
strSponsorSQL += " left outer join ExhibitorBusinessNatureMatch ebn on e.ExhibitorID=ebn.ExhibitorID ";
strSponsorSQL += " left outer join ExhibitorTypeMatch et on e.ExhibitorID=et.ExhibitorID ";
strSponsorSQL += " left outer join ExhibitorFairLocationMatch efl on e.ExhibitorID=efl.ExhibitorID ";
strSponsorSQL += " left outer join FairLocation fl on efl.FairLocationID=fl.FairLocationID left outer join Venue v on v.VenueID=fl.VenueID ";
strSponsorSQL += " left outer join Product p on e.ExhibitorID=p.ExhibitorID ";
strSponsorSQL += " left outer join ProductProductCategoryMatch ppc on p.ProductID=ppc.ProductID ";
strSponsorSQL += " left outer join ProductCategory pc1 on epc.ProductCategoryID=pc1.ProductCategoryID ";
strSponsorSQL += " left outer join ProductCategory pc2 on epc.ProductCategoryID=pc2.ProductCategoryID ";
if (inLangID > 0 && !inDTcount) {
strSponsorSQL += " left outer join CountryLang cl on c.CountryID=cl.CountryID ";
strSponsorSQL += " WHERE (1=1) and e." + inDTfilter["SponsorField"] + " = '1' ";
strSponsorSQL += (inShowDeletedOnly) ? " and (e.Status = 'false')" : ((inIncludeDeleted) ? " " : " and (e.Status = 'true')");
strSponsorSQL += (inLangID > 0 && !inDTcount) ? " and (cl.LangID=" + inLangID + ") " : "";
strSponsorSQL += (inFairID > 0) ? " and e.FairID=@FairID " : "";
strSponsorSQL += (inExhibitorID > 0) ? " and e.ExhibitorID=@ExhibitorID " : "";
cmd.CommandText = strSponsorSQL;
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.Parameters.AddWithValue("@ExhibitorID", inExhibitorID);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
Hashtable hashRow = new Hashtable();
for (int i = 0; i < rdrBrowsers.FieldCount; i++) {
switch (rdrBrowsers.GetName(i).ToString()) {
hashRow[rdrBrowsers.GetName(i).ToString()] = (rdrBrowsers.GetValue(i) == "") ? "" : "1";
hashRow[rdrBrowsers.GetName(i).ToString()] = rdrBrowsers.GetValue(i);
DateTime tDate = (!DBNull.Value.Equals(rdrBrowsers.GetValue(i))) ? (DateTime)rdrBrowsers.GetValue(i) : DateTime.MinValue;
String tValue = tDate.ToString("yyyy-MM-dd HH:mm:ss");
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
hashRow[rdrBrowsers.GetName(i).ToString()] = rdrBrowsers.GetValue(i);
hashRow["RowNum"] = countSponsor + 1;
hashRow["StandNo"] = hashRow["StandNoStr"].ToString().Replace("|","<br>").Replace("~"," ");
hashRow["ProductCategory"] = (hashExhibitorProductCat.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorProductCat[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashRow["ProductCategoryEn"] = (hashExhibitorProductCatEn.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorProductCatEn[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashRow["ProductCategoryCht"] = (hashExhibitorProductCatCht.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorProductCatCht[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashRow["ProductCategoryChs"] = (hashExhibitorProductCatChs.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorProductCatChs[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashRow["BusinessNature"] = (hashExhibitorBusinessNature.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorBusinessNature[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashRow["BusinessNatureEn"] = (hashExhibitorBusinessNatureEn.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorBusinessNatureEn[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashRow["BusinessNatureCht"] = (hashExhibitorBusinessNatureCht.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorBusinessNatureCht[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashRow["BusinessNatureChs"] = (hashExhibitorBusinessNatureChs.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorBusinessNatureChs[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashRow["ExhibitorType"] = (hashExhibitorExhibitorType.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorExhibitorType[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashRow["ExhibitorTypeEn"] = (hashExhibitorExhibitorTypeEn.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorExhibitorTypeEn[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashRow["ExhibitorTypeCht"] = (hashExhibitorExhibitorTypeCht.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorExhibitorTypeCht[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashRow["ExhibitorTypeChs"] = (hashExhibitorExhibitorTypeChs.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorExhibitorTypeChs[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashExhibitor[(int)rdrBrowsers["ExhibitorID"]] = hashRow;
String orderingString = "";
String sortField = "ExhibitorNameEn";
JArray jField = JArray.Parse(inDTorderfields);
if(inHashOrdercol != null){
foreach (int tID in inHashOrdercol.Keys) {
orderingString += orderingString.Trim() == "" ? (jField[tID].ToString() + " " + inHashOrdercol[tID].ToString()) : (", " +jField[tID].ToString() + " " + inHashOrdercol[tID].ToString());
sortField = jField[inDTordercol].ToString();
orderingString = sortField + " " + inDTorderdir;
strSQL = "select * from (SELECT ROW_NUMBER() OVER (ORDER BY " + orderingString + ") AS RowNum, * FROM (" + strSQL + ") q)";
strSQL += " qq where qq.RowNum between " + ((inDTstart==0) ? inDTstart : (inDTstart + 1 - countSponsor)) + " and " + (inDTstart + inDTlength - countSponsor);
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.Parameters.AddWithValue("@ExhibitorID", inExhibitorID);
cmd.CommandType = CommandType.Text;
outHash["Count"] = cmd.ExecuteScalar();
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
Hashtable hashRow = new Hashtable();
for (int i = 0; i < rdrBrowsers.FieldCount; i++) {
switch (rdrBrowsers.GetName(i).ToString()) {
hashRow[rdrBrowsers.GetName(i).ToString()] = (rdrBrowsers.GetValue(i) == "") ? "" : "1";
hashRow[rdrBrowsers.GetName(i).ToString()] = rdrBrowsers.GetValue(i);
DateTime tDate = (!DBNull.Value.Equals(rdrBrowsers.GetValue(i))) ? (DateTime)rdrBrowsers.GetValue(i) : DateTime.MinValue;
String tValue = tDate.ToString("yyyy-MM-dd HH:mm:ss");
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
hashRow[rdrBrowsers.GetName(i).ToString()] = rdrBrowsers.GetValue(i);
hashRow["RowNum"] = (Int32.Parse(hashRow["RowNum"].ToString()) + countSponsor).ToString();
hashRow["StandNo"] = hashRow["StandNoStr"].ToString().Replace("|","<br>").Replace("~"," ");
hashRow["ProductCategory"] = (hashExhibitorProductCat.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorProductCat[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashRow["ProductCategoryEn"] = (hashExhibitorProductCatEn.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorProductCatEn[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashRow["ProductCategoryCht"] = (hashExhibitorProductCatCht.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorProductCatCht[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashRow["ProductCategoryChs"] = (hashExhibitorProductCatChs.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorProductCatChs[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashRow["BusinessNature"] = (hashExhibitorBusinessNature.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorBusinessNature[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashRow["BusinessNatureEn"] = (hashExhibitorBusinessNatureEn.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorBusinessNatureEn[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashRow["BusinessNatureCht"] = (hashExhibitorBusinessNatureCht.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorBusinessNatureCht[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashRow["BusinessNatureChs"] = (hashExhibitorBusinessNatureChs.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorBusinessNatureChs[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashRow["ExhibitorType"] = (hashExhibitorExhibitorType.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorExhibitorType[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashRow["ExhibitorTypeEn"] = (hashExhibitorExhibitorTypeEn.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorExhibitorTypeEn[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashRow["ExhibitorTypeCht"] = (hashExhibitorExhibitorTypeCht.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorExhibitorTypeCht[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashRow["ExhibitorTypeChs"] = (hashExhibitorExhibitorTypeChs.ContainsKey((int)rdrBrowsers["ExhibitorID"])) ? hashExhibitorExhibitorTypeChs[(int)rdrBrowsers["ExhibitorID"]].ToString() : "";
hashExhibitor[(int)rdrBrowsers["ExhibitorID"]] = hashRow;
String strUserAgent = HttpContext.Current.Request.UserAgent;
strUserAgent = (strUserAgent.Length > 1000) ? strUserAgent.Substring(0,1000) : strUserAgent;
String sLogTable = "SearchLog";
string strSQL2 = "SELECT count(*) FROM sys.tables WHERE name = @TableName";
cmd.CommandText = strSQL2;
cmd.Parameters.AddWithValue("@TableName", sLogTable + "_" + inFairID);
isLogTableExist = (int)cmd.ExecuteScalar();
if (isLogTableExist == 0)
strSQL2 = "select * into " + sLogTable + "_" + inFairID + " from " + sLogTable + "_FairID where 1=0; Alter Table dbo." + sLogTable + "_" + inFairID + " Drop Column rowID; ALTER TABLE dbo." + sLogTable + "_" + inFairID + " ADD rowID INT IDENTITY(1,1); ALTER TABLE dbo." + sLogTable + "_" + inFairID + " ADD CONSTRAINT PK_" + sLogTable + "_" + inFairID + " PRIMARY KEY(rowID); ";
cmd.CommandText = strSQL2;
strSQL2 = "insert into " + sLogTable + "_" + inFairID + "(Keyword,dtStart,dtLength,ProductCategoryID,LocationID,CountryID,CompanyPrefix,BusinessNatureID,ExhibitorTypeID,VenueID,isNew,ExhibitorID,OtherFilter,UserAgent,UserIP,CreateTime) values (@Keyword,@dtStart,@dtLength,@ProductCategoryID,@LocationID,@CountryID,@CompanyPrefix,@BusinessNatureID,@ExhibitorTypeID,@VenueID,@isNew,@ExhibitorID,@OtherFilter,@UserAgent,@UserIP,{fn NOW()})";
cmd.CommandText = strSQL2;
cmd.Parameters.AddWithValue("@Keyword", inDTsearch);
cmd.Parameters.AddWithValue("@dtStart", inDTstart);
cmd.Parameters.AddWithValue("@dtLength", inDTlength);
cmd.Parameters.AddWithValue("@ProductCategoryID", inDTfilter["ProductCategory"]);
cmd.Parameters.AddWithValue("@LocationID", inDTfilter["FairLocation"]);
cmd.Parameters.AddWithValue("@CountryID", inDTfilter["Country"]);
cmd.Parameters.AddWithValue("@CompanyPrefix", inDTfilter["CompanyPrefix"]);
cmd.Parameters.AddWithValue("@BusinessNatureID", inDTfilter["BusinessNature"]);
cmd.Parameters.AddWithValue("@ExhibitorTypeID", inDTfilter["ExhibitorType"]);
cmd.Parameters.AddWithValue("@VenueID", inDTfilter["Venue"]);
cmd.Parameters.AddWithValue("@isNew", inDTfilter["New"]);
cmd.Parameters.AddWithValue("@ExhibitorID", inDTfilter["ExhibitorID"]);
cmd.Parameters.AddWithValue("@OtherFilter", "");
cmd.Parameters.AddWithValue("@UserAgent", strUserAgent);
cmd.Parameters.AddWithValue("@UserIP", getIP());
cmd.CommandType = CommandType.Text;
int dbLogID = Convert.ToInt32(cmd.ExecuteScalar());
outHash["Err"] = "Err: " + ex.ToString() + strSQL;
public static Hashtable hashImportProductCategory = new Hashtable();
public static string updateProductCategoryHash(int inFairID){
string updateStatus = "";
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
strSQL = "select ProductCategoryID, NameEnShort from ProductCategory where FairID=" + inFairID.ToString();
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
hashImportProductCategory[rdrBrowsers["NameEnShort"].ToString().Trim()] = (int)rdrBrowsers["ProductCategoryID"];
hashImportProductCategory["FairID"] = inFairID;
hashImportProductCategory["Err"] = "Err: " + ex.ToString();
public static string ProductCategoryMassage(int inFairID, string strProductCategory){
int hashFairID = hashImportProductCategory["FairID"] == null ? 0 : (int)hashImportProductCategory["FairID"];
if(inFairID != null && inFairID != 0){
if(hashFairID != inFairID)
status = updateProductCategoryHash(inFairID);
String[] arrProductCat = strProductCategory.Split('|');
foreach (String tProductCatID in arrProductCat) {
outString += (outString == "") ? "" : ",";
outString += hashImportProductCategory[tProductCatID.Trim()] == null ? "" : hashImportProductCategory[tProductCatID].ToString();
public static string BusinessNatureMassage(int inFairID, string strBusinessNature){
SqlConnection conn = new SqlConnection(SqlConnStr);
Hashtable outHash = new Hashtable();
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
strSQL = "select BusinessNatureID, NameEnShort from businessnature where fairid =" + inFairID;
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
outHash[rdrBrowsers["NameEnShort"].ToString().Trim()] = (int)rdrBrowsers["BusinessNatureID"];
if(inFairID != null && inFairID != 0){
String[] arrProductCat = strBusinessNature.Split('|');
foreach (String tProductCatID in arrProductCat) {
outString += (outString == "") ? "" : ",";
outString += outHash[tProductCatID.Trim()] == null ? "" : outHash[tProductCatID].ToString();
outString = "Err: " + ex.ToString();
public static string ExhibitorTypeMassage(int inFairID, string strExhibitorType){
SqlConnection conn = new SqlConnection(SqlConnStr);
Hashtable outHash = new Hashtable();
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
strSQL = "select ExhibitorTypeID, NameEnShort from ExhibitorType where fairid =" + inFairID;
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
outHash[rdrBrowsers["NameEnShort"].ToString().Trim()] = (int)rdrBrowsers["ExhibitorTypeID"];
if(inFairID != null && inFairID != 0){
String[] arrProductCat = strExhibitorType.Split('|');
foreach (String tProductCatID in arrProductCat) {
outString += (outString == "") ? "" : ",";
outString += outHash[tProductCatID.Trim()] == null ? "" : outHash[tProductCatID].ToString();
outString = "Err: " + ex.ToString();
public static Hashtable updateExhibitor(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inExhibitorID = (inPara["ExhibitorID"] == null || inPara["ExhibitorID"].ToString() == "") ? 0 : Int32.Parse(inPara["ExhibitorID"].ToString());
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
string inExhibitorNameEn = (inPara["ExhibitorNameEn"] == null) ? "" : inPara["ExhibitorNameEn"].ToString();
string inExhibitorNameCht = (inPara["ExhibitorNameCht"] == null) ? "" : inPara["ExhibitorNameCht"].ToString();
string inExhibitorNameChs = (inPara["ExhibitorNameChs"] == null) ? "" : inPara["ExhibitorNameChs"].ToString();
string inDescEn = (inPara["DescEn"] == null) ? "" : inPara["DescEn"].ToString();
string inDescCht = (inPara["DescCht"] == null) ? "" : inPara["DescCht"].ToString();
string inDescChs = (inPara["DescChs"] == null) ? "" : inPara["DescChs"].ToString();
string inLinkEn = (inPara["LinkEn"] == null) ? "" : inPara["LinkEn"].ToString();
string inLinkCht = (inPara["LinkCht"] == null) ? "" : inPara["LinkCht"].ToString();
string inLinkChs = (inPara["LinkChs"] == null) ? "" : inPara["LinkChs"].ToString();
string inBrandEn = (inPara["BrandEn"] == null) ? "" : inPara["BrandEn"].ToString();
string inBrandCht = (inPara["BrandCht"] == null) ? "" : inPara["BrandCht"].ToString();
string inBrandChs = (inPara["BrandChs"] == null) ? "" : inPara["BrandChs"].ToString();
int inCountryID = (inPara["CountryID"] == null || inPara["CountryID"].ToString() == "") ? 0 : Int32.Parse(inPara["CountryID"].ToString());
string inCountry = (inPara["Country"] == null) ? "" : inPara["Country"].ToString();
string inPhotoURL = (inPara["PhotoURL"] == null) ? "" : inPara["PhotoURL"].ToString();
string inCompanyLogo = (inPara["Company Logo"] == null) ? "" : inPara["Company Logo"].ToString();
string inStandNoStr = (inPara["StandNoStr"] == null) ? "" : inPara["StandNoStr"].ToString();
string inContactPerson = (inPara["ContactPerson"] == null) ? "" : inPara["ContactPerson"].ToString();
string inContactPhone = (inPara["ContactPhone"] == null) ? "" : inPara["ContactPhone"].ToString();
string inContactEmail = (inPara["ContactEmail"] == null) ? "" : inPara["ContactEmail"].ToString();
int inEmsID = (inPara["EMSID"] == null || inPara["EMSID"].ToString() == "") ? 0 : Int32.Parse(inPara["EMSID"].ToString());
string inOemID = (inPara["OEMID"] == null) ? "" : inPara["OEMID"].ToString();
int inJoinedYear = (inPara["JoinedYear"] == null || inPara["JoinedYear"].ToString() == "") ? 0 : Int32.Parse(inPara["JoinedYear"].ToString());
string inMemberID = (inPara["MemberID"] == null) ? "" : inPara["MemberID"].ToString();
string inFeaturedArea = (inPara["FeaturedArea"] == null) ? "" : inPara["FeaturedArea"].ToString();
string inFeaturedExhibitor = (inPara["FeaturedExhibitor"] == null) ? "" : inPara["FeaturedExhibitor"].ToString();
bool inIsSync = (inPara["isSync"] == null || inPara["isSync"] == "") ? false : Convert.ToBoolean(inPara["isSync"].ToString());
bool inStatus = (inPara["Status"] == null || inPara["Status"] == "") ? true : Convert.ToBoolean(inPara["Status"].ToString());
string inBusinessNature = (inPara["BusinessNature"] == null) ? "" : inPara["BusinessNature"].ToString();
string inProductCategory = (inPara["ProductCategory"] == null) ? "" : inPara["ProductCategory"].ToString();
string inExhibitorType = (inPara["ExhibitorType"] == null) ? "" : inPara["ExhibitorType"].ToString();
bool inEmsIDMode = (inPara["EmsIDMode"] == null || inPara["EmsIDMode"] == "") ? false : Convert.ToBoolean(inPara["EmsIDMode"].ToString());
String[] inField = new String[31];
for (int I=1; I<=30; I++) {
String strI = (I < 10) ? "0" + I : I.ToString();
inField[I] = (inPara["Field" + strI] == null) ? "" : inPara["Field" + strI].ToString();
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
strSQL = "select top (1) ExhibitorID from Exhibitor where EMSID=@EMSID and FairID=@FairID order by ExhibitorID desc";
cmd.Parameters.AddWithValue("@EMSID", inEmsID);
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
int dbExhibitorIDFromEms = Convert.ToInt32(cmd.ExecuteScalar());
if (dbExhibitorIDFromEms > 0) {
inExhibitorID = dbExhibitorIDFromEms;
strSQL = "update Exhibitor set FairID=@FairID,ExhibitorNameEn=@ExhibitorNameEn,ExhibitorNameCht=@ExhibitorNameCht,ExhibitorNameChs=@ExhibitorNameChs,DescEn=@DescEn,DescCht=@DescCht,DescChs=@DescChs,LinkEn=@LinkEn,LinkCht=@LinkCht,LinkChs=@LinkChs,BrandEn=@BrandEn,BrandCht=@BrandCht,BrandChs=@BrandChs,CountryID=@CountryID,PhotoURL=@PhotoURL,StandNoStr=@StandNoStr,ContactPerson=@ContactPerson,ContactPhone=@ContactPhone,ContactEmail=@ContactEmail,EMSID=@EMSID,OEMID=@OEMID,JoinedYear=@JoinedYear,MemberID=@MemberID,FeaturedArea=@FeaturedArea,FeaturedExhibitor=@FeaturedExhibitor,ExhibitorType=@ExhibitorType,isSync=@isSync,Status=@Status";
for (int I=1; I<=30; I++) {
String strI = (I < 10) ? "0" + I : I.ToString();
strSQL += ",Field" + strI + "=@Field" + strI;
strSQL += ",UpdateByUserID=@UpdateByUserID, UpdateTime={fn NOW()} where ExhibitorID=@ExhibitorID;";
strSQL += " select @@ROWCOUNT;";
cmd.Parameters.AddWithValue("@Status", inStatus);
cmd.Parameters.AddWithValue("@ExhibitorID", inExhibitorID);
strSQL = "insert into Exhibitor (FairID,ExhibitorNameEn,ExhibitorNameCht,ExhibitorNameChs,DescEn,DescCht,DescChs,LinkEn,LinkCht,LinkChs,BrandEn,BrandCht,BrandChs,CountryID,PhotoURL,StandNoStr,ContactPerson,ContactPhone,ContactEmail,EMSID,OEMID,JoinedYear,MemberID,FeaturedArea,FeaturedExhibitor,ExhibitorType,isSync";
for (int I=1; I<=30; I++) {
String strI = (I < 10) ? "0" + I : I.ToString();
strSQL += ",Field" + strI;
strSQL += ",CreateTime,CreateByUserID,UpdateTime,UpdateByUserID,Status";
strSQL += ") values (@FairID,@ExhibitorNameEn,@ExhibitorNameCht,@ExhibitorNameChs,@DescEn,@DescCht,@DescChs,@LinkEn,@LinkCht,@LinkChs,@BrandEn,@BrandCht,@BrandChs,@CountryID,@PhotoURL,@StandNoStr,@ContactPerson,@ContactPhone,@ContactEmail,@EMSID,@OEMID,@JoinedYear,@MemberID,@FeaturedArea,@FeaturedExhibitor,@ExhibitorType,@isSync";
for (int I=1; I<=30; I++) {
String strI = (I < 10) ? "0" + I : I.ToString();
strSQL += ",@Field" + strI;
strSQL += ",{fn NOW()},@CreateByUserID,{fn NOW()},@UpdateByUserID,@Status);";
strSQL += "select @@IDENTITY;";
cmd.Parameters.AddWithValue("@Status", true);
cmd.Parameters.AddWithValue("@CreateByUserID", fromUserID);
inCountryID = countryMasterHash[inCountry] == null ? 0 :(int)countryMasterHash[inCountry];
cmd.Parameters.AddWithValue("@EMSID", inEmsID);
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.Parameters.AddWithValue("@ExhibitorNameEn", inExhibitorNameEn);
cmd.Parameters.AddWithValue("@ExhibitorNameCht", inExhibitorNameCht);
cmd.Parameters.AddWithValue("@ExhibitorNameChs", inExhibitorNameChs);
cmd.Parameters.AddWithValue("@DescEn", inDescEn);
cmd.Parameters.AddWithValue("@DescCht", inDescCht);
cmd.Parameters.AddWithValue("@DescChs", inDescChs);
cmd.Parameters.AddWithValue("@LinkEn", inLinkEn);
cmd.Parameters.AddWithValue("@LinkCht", inLinkCht);
cmd.Parameters.AddWithValue("@LinkChs", inLinkChs);
cmd.Parameters.AddWithValue("@BrandEn", inBrandEn);
cmd.Parameters.AddWithValue("@BrandCht", inBrandCht);
cmd.Parameters.AddWithValue("@BrandChs", inBrandChs);
cmd.Parameters.AddWithValue("@CountryID", inCountryID);
cmd.Parameters.AddWithValue("@PhotoURL", inPhotoURL);
cmd.Parameters.AddWithValue("@StandNoStr", inStandNoStr);
cmd.Parameters.AddWithValue("@ContactPerson", inContactPerson);
cmd.Parameters.AddWithValue("@ContactPhone", inContactPhone);
cmd.Parameters.AddWithValue("@ContactEmail", inContactEmail);
cmd.Parameters.AddWithValue("@OEMID", inOemID);
cmd.Parameters.AddWithValue("@JoinedYear", inJoinedYear);
cmd.Parameters.AddWithValue("@MemberID", inMemberID);
cmd.Parameters.AddWithValue("@FeaturedArea", inFeaturedArea);
cmd.Parameters.AddWithValue("@FeaturedExhibitor", inFeaturedExhibitor);
cmd.Parameters.AddWithValue("@ExhibitorType", inExhibitorType);
if(inOemID != "" && inFairID != 171 )
cmd.Parameters.AddWithValue("@isSync", inIsSync);
for (int I=1; I<=30; I++) {
String strI = (I < 10) ? "0" + I : I.ToString();
cmd.Parameters.AddWithValue("@Field" + strI, inField[I]);
cmd.Parameters.AddWithValue("@UpdateByUserID", fromUserID);
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
int dbExhibitorID = Convert.ToInt32(cmd.ExecuteScalar());
int currExhibitorID = (inExhibitorID == 0) ? dbExhibitorID : inExhibitorID;
strSQL = "delete from ExhibitorProductCategoryMatch where ExhibitorID=@ExhibitorID;";
strSQL += " select @@ROWCOUNT;";
cmd.Parameters.AddWithValue("@ExhibitorID", inExhibitorID);
cmd.CommandText = strSQL;
int dbUpdated = Convert.ToInt32(cmd.ExecuteScalar());
if (inProductCategory != "") {
if(inOemID != "" && inFairID != 0)
inProductCategory = ProductCategoryMassage(inFairID, inProductCategory);
if (inProductCategory != "") {
strSQL = "insert into ExhibitorProductCategoryMatch (ExhibitorID, ProductCategoryID) values ";
String[] arrProductCat = inProductCategory.Split(',');
foreach (String tProductCatID in arrProductCat) {
strSQLval += (strSQLval == "") ? "" : ",";
strSQLval += "(" + currExhibitorID + "," + tProductCatID + ")";
strSQL += strSQLval + "; select @@ROWCOUNT;";
cmd.CommandText = strSQL;
int dbUpdated2 = Convert.ToInt32(cmd.ExecuteScalar());
strSQL = "delete from ExhibitorBusinessNatureMatch where ExhibitorID=@ExhibitorID;";
strSQL += " select @@ROWCOUNT;";
cmd.Parameters.AddWithValue("@ExhibitorID", inExhibitorID);
cmd.CommandText = strSQL;
dbUpdated = Convert.ToInt32(cmd.ExecuteScalar());
if (inBusinessNature != "") {
if(inOemID != "" && inFairID != 0)
inBusinessNature = BusinessNatureMassage(inFairID, inBusinessNature);
strSQL = "insert into ExhibitorBusinessNatureMatch (ExhibitorID, BusinessNatureID) values ";
String[] arrBusinessNature = inBusinessNature.Split(',');
foreach (String tBusinessNatureID in arrBusinessNature) {
strSQLval += (strSQLval == "") ? "" : ",";
strSQLval += "(" + currExhibitorID + "," + tBusinessNatureID + ")";
strSQL += strSQLval + "; select @@ROWCOUNT;";
cmd.CommandText = strSQL;
int dbUpdated3 = Convert.ToInt32(cmd.ExecuteScalar());
strSQL = "delete from ExhibitorTypeMatch where ExhibitorID=@ExhibitorID;";
strSQL += " select @@ROWCOUNT;";
cmd.Parameters.AddWithValue("@ExhibitorID", inExhibitorID);
cmd.CommandText = strSQL;
dbUpdated = Convert.ToInt32(cmd.ExecuteScalar());
if (inExhibitorType != "") {
strSQL = "insert into ExhibitorTypeMatch (ExhibitorID, ExhibitorTypeID) values ";
String[] arrExhibitorType = inExhibitorType.Split(',');
if(!int.TryParse(arrExhibitorType[0], out tryINT) && inFairID != 0 && inOemID != ""){
inExhibitorType = ExhibitorTypeMassage(inFairID, inExhibitorType);
arrExhibitorType = inExhibitorType.Split(',');
foreach (String tExhibitorTypeID in arrExhibitorType) {
strSQLval += (strSQLval == "") ? "" : ",";
strSQLval += "(" + currExhibitorID + "," + tExhibitorTypeID + ")";
strSQL += strSQLval + "; select @@ROWCOUNT;";
cmd.CommandText = strSQL;
int dbUpdated4 = Convert.ToInt32(cmd.ExecuteScalar());
Hashtable hashFairLocaitonStrToId = new Hashtable();
Hashtable outPara = new Hashtable();
outPara["FairID"] = inFairID;
Hashtable hashFairLocation = ExhListSharedLib.getFairLocation(outPara);
foreach (int tID in hashFairLocation.Keys) {
Hashtable tFairLocaiton = (Hashtable)hashFairLocation[tID];
hashFairLocaitonStrToId[tFairLocaiton["Venue"] + "~" + tFairLocaiton["Hall"]] = tID;
strSQL = "delete from ExhibitorFairLocationMatch where ExhibitorID=@ExhibitorID;";
strSQL += " select @@ROWCOUNT;";
cmd.Parameters.AddWithValue("@ExhibitorID", inExhibitorID);
cmd.CommandText = strSQL;
dbUpdated = Convert.ToInt32(cmd.ExecuteScalar());
if (inStandNoStr != "") {
strSQL = "insert into ExhibitorFairLocationMatch (ExhibitorID, FairLocationID, StandNo, Status) values ";
String[] arrStandNoStr = inStandNoStr.Split('|');
foreach (String tStandNoStr in arrStandNoStr) {
String[] arrThisStand = tStandNoStr.Split('~');
if (arrThisStand.Length > 2 && arrThisStand[0] != "undefined") {
int tFairLocationID = (int)hashFairLocaitonStrToId[arrThisStand[0] + "~" + arrThisStand[1]];
strSQLval += (strSQLval == "") ? "" : ",";
strSQLval += "(" + currExhibitorID + "," + tFairLocationID + ",'" + arrThisStand[2] + "','true')";
strSQL += strSQLval + "; select @@ROWCOUNT;";
cmd.CommandText = strSQL;
int dbUpdated5 = Convert.ToInt32(cmd.ExecuteScalar());
outHash["Updated"] = dbExhibitorID;
outHash["Updated"] = (dbExhibitorID > 0) ? 1 : 0;
outHash["ExhibitorID"] = dbExhibitorID;
outHash["Err"] = "Err: " + ex.ToString();
StringBuilder sb = new StringBuilder();
sb.Append(strSQL + " | " + ex.ToString());
File.AppendAllText("D:\\CMPAsia_Web\\Applications\\ExhibitorList18\\" +"log.txt", sb.ToString());
public static Hashtable delExhibitor(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inExhibitorID = (inPara["ExhibitorID"] == null || inPara["ExhibitorID"].ToString() == "") ? 0 : Int32.Parse(inPara["ExhibitorID"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
String strSQL = "update Exhibitor set Status='false', UpdateByUserID=@UpdateByUserID, UpdateTime={fn NOW()} where ExhibitorID=@ExhibitorID ";
strSQL += " select @@ROWCOUNT;";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@UpdateByUserID", fromUserID);
cmd.Parameters.AddWithValue("@ExhibitorID", inExhibitorID);
cmd.CommandType = CommandType.Text;
int dbLogID = Convert.ToInt32(cmd.ExecuteScalar());
outHash["Updated"] = dbLogID;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable getProduct(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int inProductID = (inPara["ProductID"] == null || inPara["ProductID"].ToString() == "") ? 0 : Int32.Parse(inPara["ProductID"].ToString());
int inExhibitorID = (inPara["ExhibitorID"] == null || inPara["ExhibitorID"].ToString() == "") ? 0 : Int32.Parse(inPara["ExhibitorID"].ToString());
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
String inDTorderfields = (inPara["orderfields"] == null) ? "" : inPara["orderfields"].ToString();
bool inDTmode = (inPara["DTmode"] == null || inPara["DTmode"] == "") ? false : Convert.ToBoolean(inPara["DTmode"].ToString());
bool inDTcount = (inPara["DTcount"] == null || inPara["DTcount"] == "") ? false : Convert.ToBoolean(inPara["DTcount"].ToString());
int inDTstart = (inPara["start"] == null || inPara["start"].ToString() == "") ? 0 : Int32.Parse(inPara["start"].ToString());
int inDTlength = (inPara["length"] == null || inPara["length"].ToString() == "") ? 0 : Int32.Parse(inPara["length"].ToString());
int inDTordercol = (inPara["order[0][column]"] == null || inPara["order[0][column]"].ToString() == "") ? 0 : Int32.Parse(inPara["order[0][column]"].ToString());
String inDTorderdir = (inPara["order[0][dir]"] == null) ? "asc" : inPara["order[0][dir]"].ToString();
String inDTsearch = (inPara["search[value]"] == null) ? "" : inPara["search[value]"].ToString();
Hashtable inDTfilter = new Hashtable();
inDTfilter["Country"] = (inPara["filter[country]"] == null) ? "" : inPara["filter[country]"].ToString();
inDTfilter["CompanyPrefix"] = (inPara["filter[companyprefix]"] == null) ? "" : inPara["filter[companyprefix]"].ToString();
inDTfilter["ProductCategory"] = (inPara["filter[productcategory]"] == null) ? "" : inPara["filter[productcategory]"].ToString();
inDTfilter["BusinessNature"] = (inPara["filter[businessnature]"] == null) ? "" : inPara["filter[businessnature]"].ToString();
inDTfilter["ExhibitorType"] = (inPara["filter[exhibitortype]"] == null) ? "" : inPara["filter[exhibitortype]"].ToString();
inDTfilter["Venue"] = (inPara["filter[venue]"] == null) ? "" : inPara["filter[venue]"].ToString();
inDTfilter["FairLocation"] = (inPara["filter[fairlocation]"] == null) ? "" : inPara["filter[fairlocation]"].ToString();
inDTfilter["New"] = (inPara["filter[new]"] == null || inPara["filter[new]"] == "") ? false : Convert.ToBoolean(inPara["filter[new]"].ToString());
inDTfilter["ExhibitorID"] = (inPara["filter[exhibitorid]"] == null) ? "" : inPara["filter[exhibitorid]"].ToString();
for (int I=1; I<=30; I++) {
String strI = (I < 10) ? "0" + I : I.ToString();
inDTfilter["Exhibitor_Field" + strI] = (inPara["filter[exhibitor_field" + strI + "]"] == null) ? "" : inPara["filter[exhibitor_field" + strI + "]"].ToString();
for (int I=1; I<=9; I++) {
inDTfilter["Product_Field" + I] = (inPara["filter[product_field" + I + "]"] == null) ? "" : inPara["filter[product_field" + I + "]"].ToString();
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
Hashtable hashProductCat = new Hashtable();
if (inFairID > 0 || inExhibitorID > 0 || inProductID > 0) {
strSQL = "select pp.ProductID,pp.ProductCategoryID from ProductProductCategoryMatch pp join Product p on pp.ProductID=p.ProductID where pp.Status='true' and p.Status='true'";
strSQL += (inFairID > 0) ? " and p.FairID=@FairID " : "";
strSQL += (inExhibitorID > 0) ? " and p.ExhibitorID=@ExhibitorID " : "";
strSQL += (inProductID > 0) ? " and p.ProductID=@ProductID " : "";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.Parameters.AddWithValue("@ExhibitorID", inExhibitorID);
cmd.Parameters.AddWithValue("@ProductID", inProductID);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
String strProductCat = hashProductCat.ContainsKey((int)rdrBrowsers["ProductID"]) ? hashProductCat[(int)rdrBrowsers["ProductID"]].ToString() : "";
strProductCat += (strProductCat=="") ? "" : ",";
strProductCat += rdrBrowsers["ProductCategoryID"];
hashProductCat[(int)rdrBrowsers["ProductID"]] = strProductCat;
Hashtable hashProduct = new Hashtable();
strSQL = "select count(distinct p.ProductID) as Count ";
strSQL = "SELECT distinct p.*,e.ExhibitorNameEn as ExhibitorName,e.ExhibitorNameEn as ExhibitorNameEn,e.ExhibitorNameCht as ExhibitorNameCht,e.ExhibitorNameChs as ExhibitorNameChs,e.StandNoStr,u1.Name as CreateBy,u2.Name as UpdateBy ";
strSQL += "from Product p left outer join Exhibitor e on p.ExhibitorID=e.ExhibitorID left outer join [User17] u1 on p.CreateByUserID=u1.UserID left outer join [User17] u2 on p.UpdateByUserID=u2.UserID ";
strSQL += " left outer join ProductProductCategoryMatch ppc on p.ProductID=ppc.ProductID ";
strSQL += " left outer join ExhibitorProductCategoryMatch epc on e.ExhibitorID=epc.ExhibitorID ";
strSQL += " left outer join ExhibitorBusinessNatureMatch ebn on e.ExhibitorID=ebn.ExhibitorID ";
strSQL += " left outer join ExhibitorTypeMatch et on e.ExhibitorID=et.ExhibitorID ";
strSQL += " left outer join ExhibitorFairLocationMatch efl on e.ExhibitorID=efl.ExhibitorID ";
strSQL += " left outer join FairLocation fl on efl.FairLocationID=fl.FairLocationID left outer join Venue v on v.VenueID=fl.VenueID ";
strSQL += "where p.Status='true' and e.Status='true'";
strSQL += (inProductID > 0) ? " and p.ProductID=@ProductID " : "";
strSQL += (inExhibitorID > 0) ? " and p.ExhibitorID=@ExhibitorID " : "";
strSQL += (inFairID > 0) ? " and p.FairID=@FairID " : "";
inDTsearch = inDTsearch.Replace("'","''");
strSQL += "e.ExhibitorNameEn like N'%"+inDTsearch+"%' ";
strSQL += "or e.ExhibitorNameCht like N'%"+inDTsearch+"%' ";
strSQL += "or e.ExhibitorNameChs like N'%"+inDTsearch+"%' ";
strSQL += "or e.BrandEn like N'%"+inDTsearch+"%' ";
strSQL += "or e.BrandCht like N'%"+inDTsearch+"%' ";
strSQL += "or e.BrandChs like N'%"+inDTsearch+"%' ";
for (int I=1; I<=30; I++) {
String strI = (I < 10) ? "0" + I : I.ToString();
strSQL += "or e.Field" + strI + " like N'%"+inDTsearch+"%' ";
strSQL += "or e.StandNoStr like N'%"+inDTsearch+"%' ";
strSQL += "or p.NameEn like N'%"+inDTsearch+"%' ";
strSQL += "or p.NameCht like N'%"+inDTsearch+"%' ";
strSQL += "or p.NameChs like N'%"+inDTsearch+"%' ";
for (int I=1; I<=9; I++) {
strSQL += "or p.Field" + I + " like N'%"+inDTsearch+"%' ";
strSQL += (inDTfilter["Country"] == "") ? "" : " and e.CountryID in (" + inDTfilter["Country"] + ")";
strSQL += (inDTfilter["CompanyPrefix"] == "") ? "" : " and e.ExhibitorNameEn like '" + inDTfilter["CompanyPrefix"].ToString().Replace("'","''") + "%'";
strSQL += (inDTfilter["ProductCategory"] == "") ? "" : " and (epc.ProductCategoryID in (" + inDTfilter["ProductCategory"] + ") or ppc.ProductCategoryID in (" + inDTfilter["ProductCategory"] + "))";
strSQL += (inDTfilter["BusinessNature"] == "") ? "" : " and ebn.BusinessNatureID in (" + inDTfilter["BusinessNature"] + ")";
strSQL += (inDTfilter["ExhibitorType"] == "") ? "" : " and et.ExhibitorTypeID in (" + inDTfilter["ExhibitorType"] + ")";
strSQL += (inDTfilter["FairLocation"] == "") ? "" : " and efl.FairLocationID in (" + inDTfilter["FairLocation"] + ")";
strSQL += (inDTfilter["Venue"] == "") ? "" : " and v.VenueID in (" + inDTfilter["Venue"] + ")";
strSQL += ((bool)inDTfilter["New"] == true) ? " and e.JoinedYear = 0" : "";
strSQL += (inDTfilter["ExhibitorID"] == "") ? "" : " and e.ExhibitorID in (" + inDTfilter["ExhibitorID"] + ")";
for (int I=1; I<=30; I++) {
String strI = (I < 10) ? "0" + I : I.ToString();
strSQL += (inDTfilter["Exhibitor_Field" + strI] == "") ? "" : " and e.Field" + strI + " like N'%" + inDTfilter["Exhibitor_Field" + strI] + "%'";
for (int I=1; I<=9; I++) {
strSQL += (inDTfilter["Product_Field" + I] == "") ? "" : " and p.Field" + I + " like N'%" + inDTfilter["Product_Field" + I] + "%'";
String sortField = "NameEn";
JArray jField = JArray.Parse(inDTorderfields);
sortField = jField[inDTordercol].ToString();
strSQL = "select * from (SELECT ROW_NUMBER() OVER (ORDER BY " + sortField + " " + inDTorderdir+ ") AS RowNum, * FROM (" + strSQL + ") q)";
strSQL += " qq where qq.RowNum between " + ((inDTstart==0) ? inDTstart : (inDTstart+1)) + " and " + (inDTstart + inDTlength);
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@ProductID", inProductID);
cmd.Parameters.AddWithValue("@ExhibitorID", inExhibitorID);
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.CommandType = CommandType.Text;
outHash["Count"] = cmd.ExecuteScalar();
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
Hashtable hashRow = new Hashtable();
for (int i = 0; i < rdrBrowsers.FieldCount; i++) {
switch (rdrBrowsers.GetName(i).ToString()) {
DateTime tDate = (!DBNull.Value.Equals(rdrBrowsers.GetValue(i))) ? (DateTime)rdrBrowsers.GetValue(i) : DateTime.MinValue;
String tValue = tDate.ToString("yyyy-MM-dd HH:mm:ss");
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
hashRow[rdrBrowsers.GetName(i).ToString()] = rdrBrowsers.GetValue(i);
hashRow["ProductCategory"] = (hashProductCat.ContainsKey((int)rdrBrowsers["ProductID"])) ? hashProductCat[(int)rdrBrowsers["ProductID"]].ToString() : "";
hashProduct[(int)rdrBrowsers["ProductID"]] = hashRow;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable updateProduct(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inProductID = (inPara["ProductID"] == null || inPara["ProductID"].ToString() == "") ? 0 : Int32.Parse(inPara["ProductID"].ToString());
int inExhibitorID = (inPara["ExhibitorID"] == null || inPara["ExhibitorID"].ToString() == "") ? 0 : Int32.Parse(inPara["ExhibitorID"].ToString());
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
string inNameEn = (inPara["NameEn"] == null) ? "" : inPara["NameEn"].ToString();
string inNameCht = (inPara["NameCht"] == null) ? "" : inPara["NameCht"].ToString();
string inNameChs = (inPara["NameChs"] == null) ? "" : inPara["NameChs"].ToString();
string inDescEn = (inPara["DescEn"] == null) ? "" : inPara["DescEn"].ToString();
string inDescCht = (inPara["DescCht"] == null) ? "" : inPara["DescCht"].ToString();
string inDescChs = (inPara["DescChs"] == null) ? "" : inPara["DescChs"].ToString();
string inPhotoUrl = (inPara["PhotoUrl"] == null) ? "" : inPara["PhotoUrl"].ToString();
string inVideoUrl = (inPara["VideoUrl"] == null) ? "" : inPara["VideoUrl"].ToString();
string inSubmitTime = (inPara["SubmitTime"] == null) ? "" : inPara["SubmitTime"].ToString();
int inSequence = (inPara["Sequence"] == null || inPara["Sequence"].ToString() == "") ? 0 : Int32.Parse(inPara["Sequence"].ToString());
bool inIsSync = (inPara["isSync"] == null || inPara["isSync"] == "") ? false : Convert.ToBoolean(inPara["isSync"].ToString());
bool inStatus = (inPara["Status"] == null || inPara["Status"] == "") ? true : Convert.ToBoolean(inPara["Status"].ToString());
bool inEmsIDMode = (inPara["EmsIDMode"] == null || inPara["EmsIDMode"] == "") ? false : Convert.ToBoolean(inPara["EmsIDMode"].ToString());
int inEmsID = (inPara["EMSID"] == null || inPara["EMSID"].ToString() == "") ? 0 : Int32.Parse(inPara["EMSID"].ToString());
String[] inField = new String[10];
for (int I=1; I<=9; I++) {
inField[I] = (inPara["Field" + I] == null) ? "" : inPara["Field" + I].ToString();
string inProductCategory = (inPara["ProductCategory"] == null) ? "" : inPara["ProductCategory"].ToString();
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
if (inEmsIDMode && inFairID > 0 && inEmsID > 0) {
strSQL = "select ExhibitorID from Exhibitor where FairID=@FairID and EmsID=@EmsID";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.Parameters.AddWithValue("@EmsID", inEmsID);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
inExhibitorID = (int)rdrBrowsers["ExhibitorID"];
strSQL = "select ProductID from Product where FairID=@FairID and ExhibitorID=@ExhibitorID and Sequence=@Sequence";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.Parameters.AddWithValue("@ExhibitorID", inExhibitorID);
cmd.Parameters.AddWithValue("@Sequence", inSequence);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
inProductID = (int)rdrBrowsers["ProductID"];
if (inProductID == 0 && inNameEn == "") {
strSQL = "update product set ExhibitorID=@ExhibitorID,FairID=@FairID,NameEn=@NameEn,NameCht=@NameCht,NameChs=@NameChs,DescEn=@DescEn,DescCht=@DescCht,DescChs=@DescChs,[PhotoUrl]=@PhotoUrl,VideoUrl=@VideoUrl,Sequence=@Sequence,SubmitTime=@SubmitTime,isSync=@isSync,Status=@Status";
for (int I=1; I<=9; I++) {
strSQL += ",Field" + I + "=@Field" + I;
strSQL += ",UpdateByUserID=@UpdateByUserID, UpdateTime={fn NOW()} where ProductID=@ProductID;";
strSQL += " select @@ROWCOUNT;";
cmd.Parameters.AddWithValue("@Status", inStatus);
cmd.Parameters.AddWithValue("@ProductID", inProductID);
strSQL = "insert into product";
strSQL += "(ExhibitorID,FairID,NameEn,NameCht,NameChs,DescEn,DescCht,DescChs,PhotoUrl,VideoUrl,Sequence,SubmitTime,isSync";
for (int I=1; I<=9; I++) {
strSQL += ",CreateTime,CreateByUserID,UpdateTime,UpdateByUserID,Status) values ";
strSQL += "(@ExhibitorID,@FairID,@NameEn,@NameCht,@NameChs,@DescEn,@DescCht,@DescChs,@PhotoUrl,@VideoUrl,@Sequence,@SubmitTime,@isSync";
for (int I=1; I<=9; I++) {
strSQL += ",{fn NOW()},@CreateByUserID,{fn NOW()},@UpdateByUserID,@Status);";
strSQL += "select @@IDENTITY;";
cmd.Parameters.AddWithValue("@Status", true);
cmd.Parameters.AddWithValue("@CreateByUserID", fromUserID);
cmd.Parameters.AddWithValue("@ExhibitorID", inExhibitorID);
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.Parameters.AddWithValue("@NameEn", inNameEn);
cmd.Parameters.AddWithValue("@NameCht", inNameCht);
cmd.Parameters.AddWithValue("@NameChs", inNameChs);
cmd.Parameters.AddWithValue("@DescEn", inDescEn);
cmd.Parameters.AddWithValue("@DescCht", inDescCht);
cmd.Parameters.AddWithValue("@DescChs", inDescChs);
cmd.Parameters.AddWithValue("@PhotoUrl", inPhotoUrl);
cmd.Parameters.AddWithValue("@VideoUrl", inVideoUrl);
cmd.Parameters.AddWithValue("@Sequence", inSequence);
cmd.Parameters.AddWithValue("@SubmitTime", inSubmitTime);
cmd.Parameters.AddWithValue("@isSync", inIsSync);
for (int I=1; I<=9; I++) {
cmd.Parameters.AddWithValue("@Field" + I, inField[I]);
cmd.Parameters.AddWithValue("@UpdateByUserID", fromUserID);
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
int dbProductID = Convert.ToInt32(cmd.ExecuteScalar());
int currProductID = (inProductID == 0) ? dbProductID : inProductID;
strSQL = "delete from ProductProductCategoryMatch where ProductID=@ProductID;";
strSQL += " select @@ROWCOUNT;";
cmd.Parameters.AddWithValue("@ProductID", currProductID);
cmd.CommandText = strSQL;
int dbUpdated = Convert.ToInt32(cmd.ExecuteScalar());
if (inProductCategory != "") {
strSQL = "insert into ProductProductCategoryMatch (ProductCategoryID, ProductID, Status) values ";
String[] arrCat = inProductCategory.Split(',');
foreach (String tCatID in arrCat) {
strSQLval += (strSQLval == "") ? "" : ",";
strSQLval += "(" + tCatID + "," + currProductID + ", 'true')";
strSQL += strSQLval + "; select @@ROWCOUNT;";
cmd.CommandText = strSQL;
int dbUpdated2 = Convert.ToInt32(cmd.ExecuteScalar());
outHash["Updated"] = dbProductID;
outHash["Updated"] = (dbProductID > 0) ? 1 : 0;
outHash["ProductID"] = dbProductID;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable delProduct(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inProductID = (inPara["ProductID"] == null || inPara["ProductID"].ToString() == "") ? 0 : Int32.Parse(inPara["ProductID"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
String strSQL = "update Product set Status='false', UpdateByUserID=@UpdateByUserID, UpdateTime={fn NOW()} where ProductID=@ProductID ";
strSQL += " select @@ROWCOUNT;";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@UpdateByUserID", fromUserID);
cmd.Parameters.AddWithValue("@ProductID", inProductID);
cmd.CommandType = CommandType.Text;
int dbLogID = Convert.ToInt32(cmd.ExecuteScalar());
outHash["Updated"] = dbLogID;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable countryMasterHash = new Hashtable();
public static Hashtable getCountryHash(){
Hashtable outHash = new Hashtable();
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
strSQL = "select CountryID, NameEnShort from Country";
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
outHash[rdrBrowsers["NameEnShort"]] = (int)rdrBrowsers["CountryID"];
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable importExhibitor(Hashtable inPara) {
Hashtable outHash = new Hashtable();
Hashtable outPara = new Hashtable();
Hashtable hashFair = new Hashtable();
countryMasterHash = getCountryHash();
foreach (String tKey in inPara.Keys) {
String jsonItem = inPara[tKey].ToString();
JObject inJObj = JObject.Parse(jsonItem);
outPara = new Hashtable();
foreach (System.Collections.Generic.KeyValuePair<string,Newtonsoft.Json.Linq.JToken> jObj in inJObj) {
outPara[jObj.Key] = jObj.Value;
Hashtable hashFairs = getFair(outPara);
foreach (int tFairID in hashFairs.Keys) {
hashFair = (Hashtable)hashFairs[tFairID];
Hashtable hashResult = updateExhibitor(outPara);
if (hashFair.ContainsKey("NumOfProduct") && (int)hashFair["NumOfProduct"] > 0) {
for (int I=1; I<=(int)hashFair["NumOfProduct"]; I++) {
Hashtable outPdPara = new Hashtable();
outPdPara["EmsIDMode"] = true;
outPdPara["Sequence"] = I;
outPdPara["FairID"] = outPara["FairID"];
outPdPara["EMSID"] = outPara["EMSID"];
outPdPara["NameEn"] = outPara["Product" + I + "_NameEn"];
outPdPara["NameCht"] = outPara["Product" + I + "_NameCht"];
outPdPara["NameChs"] = outPara["Product" + I + "_NameChs"];
outPdPara["DescEn"] = outPara["Product" + I + "_DescEn"];
outPdPara["DescCht"] = outPara["Product" + I + "_DescCht"];
outPdPara["DescChs"] = outPara["Product" + I + "_DescChs"];
outPdPara["PhotoUrl"] = outPara["Product" + I + "_PhotoUrl"];
outPdPara["VideoUrl"] = outPara["Product" + I + "_VideoUrl"];
outPdPara["SubmitTime"] = outPara["Product" + I + "_SubmitTime"];
outPdPara["ProductCategory"] = outPara["Product" + I + "_ProductCategory"];
outPdPara["Field1"] = outPara["Product" + I + "_Field1"];
outPdPara["Field2"] = outPara["Product" + I + "_Field2"];
outPdPara["Field3"] = outPara["Product" + I + "_Field3"];
outPdPara["Field4"] = outPara["Product" + I + "_Field4"];
outPdPara["Field5"] = outPara["Product" + I + "_Field5"];
outPdPara["Field6"] = outPara["Product" + I + "_Field6"];
outPdPara["Field7"] = outPara["Product" + I + "_Field7"];
outPdPara["Field8"] = outPara["Product" + I + "_Field8"];
outPdPara["Field9"] = outPara["Product" + I + "_Field9"];
Hashtable hashResult2 = updateProduct(outPdPara);
outHash["Updated"] = updateCount;
public static Hashtable getFairLocation(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int inFairLocationID = (inPara["FairLocationID"] == null || inPara["FairLocationID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairLocationID"].ToString());
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
bool inExhibitorOnly = (inPara["ExhibitorOnly"] == null || inPara["ExhibitorOnly"] == "") ? false : Convert.ToBoolean(inPara["ExhibitorOnly"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
Hashtable hashLocation = new Hashtable();
if (inExhibitorOnly && inFairID > 0) {
strSQL = "SELECT DISTINCT eflm.FairLocationID, v.NameEn AS VenueEn, v.NameEnShort AS VenueEnShort, v.NameCht AS VenueCht, v.NameChtShort AS VenueChtShort, v.NameChs AS VenueChs, v.NameChsShort AS VenueChsShort, v.NameEnShort AS VenueEnShort, h.NameEn AS HallEn, h.NameEn AS HallEnShort, h.NameCht AS HallCht, h.NameCht AS HallChtShort, h.NameChs AS HallChs, h.NameChs AS HallChsShort, l.ItemOrder FROM ExhibitorFairLocationMatch AS eflm LEFT OUTER JOIN FairLocation AS l ON eflm.FairLocationID = l.FairLocationID LEFT OUTER JOIN Venue AS v ON l.VenueID = v.VenueID LEFT OUTER JOIN Hall AS h ON l.HallID = h.HallID LEFT OUTER JOIN Exhibitor AS e ON eflm.ExhibitorID = e.ExhibitorID WHERE (e.Status = 'true') ";
strSQL = "SELECT l.*, f.EMSFairID as Fair, v.NameEnShort as Venue, h.NameEnShort AS Hall, u1.Name AS CreateBy, u2.Name AS UpdateBy FROM FairLocation AS l INNER JOIN Fair AS f ON l.FairID = f.FairID INNER JOIN Venue AS v ON l.VenueID = v.VenueID INNER JOIN Hall AS h ON l.HallID = h.HallID left outer JOIN [User17] AS u1 ON l.CreateByUserID = u1.UserID left outer JOIN [User17] AS u2 ON l.UpdateByUserID = u2.UserID WHERE (l.Status = 'true')";
strSQL += (inFairID > 0) ? " and l.FairID=@FairID " : "";
strSQL += (inFairLocationID > 0) ? " and l.FairLocationID=@FairLocationID " : "";
strSQL += " order by l.ItemOrder";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@FairID", inFairID);
if (inFairLocationID > 0) {
cmd.Parameters.AddWithValue("@FairLocationID", inFairLocationID);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
Hashtable hashRow = new Hashtable();
for (int i = 0; i < rdrBrowsers.FieldCount; i++) {
switch (rdrBrowsers.GetName(i).ToString()) {
DateTime tDate = (!DBNull.Value.Equals(rdrBrowsers.GetValue(i))) ? (DateTime)rdrBrowsers.GetValue(i) : DateTime.MinValue;
String tValue = tDate.ToString("yyyy-MM-dd HH:mm:ss");
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
hashRow[rdrBrowsers.GetName(i).ToString()] = rdrBrowsers.GetValue(i);
hashLocation[(int)rdrBrowsers["FairLocationID"]] = hashRow;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable updateFairLocation(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inFairLocationID = (inPara["FairLocationID"] == null || inPara["FairLocationID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairLocationID"].ToString());
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
int inVenueID = (inPara["VenueID"] == null || inPara["VenueID"].ToString() == "") ? 0 : Int32.Parse(inPara["VenueID"].ToString());
int inHallID = (inPara["HallID"] == null || inPara["HallID"].ToString() == "") ? 0 : Int32.Parse(inPara["HallID"].ToString());
int inItemOrder = (inPara["ItemOrder"] == null || inPara["ItemOrder"].ToString() == "") ? 0 : Int32.Parse(inPara["ItemOrder"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
if (inFairLocationID > 0) {
strSQL = "update FairLocation set FairID=@FairID,VenueID=@VenueID,HallID=@HallID,ItemOrder=@ItemOrder,UpdateByUserID=@UpdateByUserID, UpdateTime={fn NOW()} where FairLocationID=@FairLocationID;";
strSQL += " select @@ROWCOUNT;";
cmd.Parameters.AddWithValue("@FairLocationID", inFairLocationID);
strSQL = "insert into FairLocation (FairID,VenueID,HallID,ItemOrder,CreateTime,CreateByUserID,UpdateTime,UpdateByUserID,Status) values (@FairID,@VenueID,@HallID,@ItemOrder,{fn NOW()},@CreateByUserID,{fn NOW()},@UpdateByUserID,@Status);";
strSQL += "select @@IDENTITY;";
cmd.Parameters.AddWithValue("@Status", true);
cmd.Parameters.AddWithValue("@CreateByUserID", fromUserID);
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.Parameters.AddWithValue("@VenueID", inVenueID);
cmd.Parameters.AddWithValue("@HallID", inHallID);
cmd.Parameters.AddWithValue("@ItemOrder", inItemOrder);
cmd.Parameters.AddWithValue("@UpdateByUserID", fromUserID);
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
int dbFairLocationID = Convert.ToInt32(cmd.ExecuteScalar());
if (inFairLocationID > 0) {
outHash["Updated"] = dbFairLocationID;
outHash["Updated"] = (dbFairLocationID > 0) ? 1 : 0;
outHash["FairLocationID"] = dbFairLocationID;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable delFairLocation(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inFairLocationID = (inPara["FairLocationID"] == null || inPara["FairLocationID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairLocationID"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
String strSQL = "update FairLocation set Status='false', UpdateByUserID=@UpdateByUserID, UpdateTime={fn NOW()} where FairLocationID=@FairLocationID ";
strSQL += " select @@ROWCOUNT;";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@UpdateByUserID", fromUserID);
cmd.Parameters.AddWithValue("@FairLocationID", inFairLocationID);
cmd.CommandType = CommandType.Text;
int dbLogID = Convert.ToInt32(cmd.ExecuteScalar());
outHash["Updated"] = dbLogID;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable getFeaturedArea(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
bool inExhibitorOnly = (inPara["ExhibitorOnly"] == null || inPara["ExhibitorOnly"] == "") ? false : Convert.ToBoolean(inPara["ExhibitorOnly"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
Hashtable hashFeaturedArea = new Hashtable();
if (inExhibitorOnly && inFairID > 0) {
strSQL = "SELECT DISTINCT e.FeaturedArea FROM Exhibitor e WHERE (e.Status = 'true') ";
strSQL += (inFairID > 0) ? " and e.FairID=@FairID " : "";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
Hashtable hashRow = new Hashtable();
for (int i = 0; i < rdrBrowsers.FieldCount; i++) {
switch (rdrBrowsers.GetName(i).ToString()) {
DateTime tDate = (!DBNull.Value.Equals(rdrBrowsers.GetValue(i))) ? (DateTime)rdrBrowsers.GetValue(i) : DateTime.MinValue;
String tValue = tDate.ToString("yyyy-MM-dd HH:mm:ss");
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
hashRow[rdrBrowsers.GetName(i).ToString()] = rdrBrowsers.GetValue(i);
hashFeaturedArea[rdrBrowsers["FeaturedArea"].ToString()] = hashRow;
outHash = hashFeaturedArea;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable getVenue(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int inVenueID = (inPara["VenueID"] == null || inPara["VenueID"].ToString() == "") ? 0 : Int32.Parse(inPara["VenueID"].ToString());
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
bool inExhibitorOnly = (inPara["ExhibitorOnly"] == null || inPara["ExhibitorOnly"] == "") ? false : Convert.ToBoolean(inPara["ExhibitorOnly"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
Hashtable hashVenue = new Hashtable();
if (inExhibitorOnly && inFairID > 0) {
strSQL = "SELECT DISTINCT v.VenueID, v.NameEn, v.NameEnShort, v.NameCht, v.NameChtShort, v.NameChs, v.NameChsShort, v.NameEnShort FROM ExhibitorFairLocationMatch AS eflm LEFT OUTER JOIN FairLocation AS l ON eflm.FairLocationID = l.FairLocationID LEFT OUTER JOIN Venue AS v ON l.VenueID = v.VenueID LEFT OUTER JOIN Exhibitor AS e ON eflm.ExhibitorID = e.ExhibitorID WHERE (e.Status = 'true') ";
strSQL += (inFairID > 0) ? " and e.FairID=@FairID " : "";
strSQL = "SELECT v.*,u1.Name as CreateBy,u2.Name as UpdateBy from Venue v left outer join [User17] u1 on v.CreateByUserID=u1.UserID left outer join [User17] u2 on v.UpdateByUserID=u2.UserID where v.Status='true'";
strSQL += (inVenueID > 0) ? " and v.VenueID=@VenueID " : "";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.Parameters.AddWithValue("@VenueID", inVenueID);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
Hashtable hashRow = new Hashtable();
for (int i = 0; i < rdrBrowsers.FieldCount; i++) {
switch (rdrBrowsers.GetName(i).ToString()) {
DateTime tDate = (!DBNull.Value.Equals(rdrBrowsers.GetValue(i))) ? (DateTime)rdrBrowsers.GetValue(i) : DateTime.MinValue;
String tValue = tDate.ToString("yyyy-MM-dd HH:mm:ss");
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
hashRow[rdrBrowsers.GetName(i).ToString()] = rdrBrowsers.GetValue(i);
hashVenue[(int)rdrBrowsers["VenueID"]] = hashRow;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable updateVenue(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inVenueID = (inPara["VenueID"] == null || inPara["VenueID"].ToString() == "") ? 0 : Int32.Parse(inPara["VenueID"].ToString());
string inNameEn = (inPara["NameEn"] == null) ? "" : inPara["NameEn"].ToString();
string inNameCht = (inPara["NameCht"] == null) ? "" : inPara["NameCht"].ToString();
string inNameChs = (inPara["NameChs"] == null) ? "" : inPara["NameChs"].ToString();
string inNameEnShort = (inPara["NameEnShort"] == null) ? "" : inPara["NameEnShort"].ToString();
string inNameChtShort = (inPara["NameChtShort"] == null) ? "" : inPara["NameChtShort"].ToString();
string inNameChsShort = (inPara["NameChsShort"] == null) ? "" : inPara["NameChsShort"].ToString();
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
strSQL = "update Venue set NameEn=@NameEn,NameEnShort=@NameEnShort,NameCht=@NameCht,NameChtShort=@NameChtShort,NameChs=@NameChs,NameChsShort=@NameChsShort,UpdateByUserID=@UpdateByUserID, UpdateTime={fn NOW()} where VenueID=@VenueID;";
strSQL += " select @@ROWCOUNT;";
cmd.Parameters.AddWithValue("@VenueID", inVenueID);
strSQL = "insert into Venue (NameEn,NameEnShort,NameCht,NameChtShort,NameChs,NameChsShort,CreateTime,CreateByUserID,UpdateTime,UpdateByUserID,Status) values (@NameEn,@NameEnShort,@NameCht,@NameChtShort,@NameChs,@NameChsShort,{fn NOW()},@CreateByUserID,{fn NOW()},@UpdateByUserID,@Status);";
strSQL += "select @@IDENTITY;";
cmd.Parameters.AddWithValue("@Status", true);
cmd.Parameters.AddWithValue("@CreateByUserID", fromUserID);
cmd.Parameters.AddWithValue("@NameEn", inNameEn);
cmd.Parameters.AddWithValue("@NameEnShort", inNameEnShort);
cmd.Parameters.AddWithValue("@NameCht", inNameCht);
cmd.Parameters.AddWithValue("@NameChtShort", inNameChtShort);
cmd.Parameters.AddWithValue("@NameChs", inNameChs);
cmd.Parameters.AddWithValue("@NameChsShort", inNameChsShort);
cmd.Parameters.AddWithValue("@UpdateByUserID", fromUserID);
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
int dbVenueID = Convert.ToInt32(cmd.ExecuteScalar());
outHash["Updated"] = dbVenueID;
outHash["Updated"] = (dbVenueID > 0) ? 1 : 0;
outHash["VenueID"] = dbVenueID;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable delVenue(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inVenueID = (inPara["VenueID"] == null || inPara["VenueID"].ToString() == "") ? 0 : Int32.Parse(inPara["VenueID"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
String strSQL = "update Venue set Status='false', UpdateByUserID=@UpdateByUserID, UpdateTime={fn NOW()} where VenueID=@VenueID ";
strSQL += " select @@ROWCOUNT;";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@UpdateByUserID", fromUserID);
cmd.Parameters.AddWithValue("@VenueID", inVenueID);
cmd.CommandType = CommandType.Text;
int dbLogID = Convert.ToInt32(cmd.ExecuteScalar());
outHash["Updated"] = dbLogID;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable getHall(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int inHallID = (inPara["HallID"] == null || inPara["HallID"].ToString() == "") ? 0 : Int32.Parse(inPara["HallID"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
Hashtable hashHall = new Hashtable();
strSQL = "SELECT h.*,u1.Name as CreateBy,u2.Name as UpdateBy from Hall h left outer join [User17] u1 on h.CreateByUserID=u1.UserID left outer join [User17] u2 on h.UpdateByUserID=u2.UserID where h.Status='true'";
strSQL += (inHallID > 0) ? " and h.HallID=@HallID " : "";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@HallID", inHallID);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
Hashtable hashRow = new Hashtable();
for (int i = 0; i < rdrBrowsers.FieldCount; i++) {
switch (rdrBrowsers.GetName(i).ToString()) {
DateTime tDate = (!DBNull.Value.Equals(rdrBrowsers.GetValue(i))) ? (DateTime)rdrBrowsers.GetValue(i) : DateTime.MinValue;
String tValue = tDate.ToString("yyyy-MM-dd HH:mm:ss");
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
hashRow[rdrBrowsers.GetName(i).ToString()] = rdrBrowsers.GetValue(i);
hashHall[(int)rdrBrowsers["HallID"]] = hashRow;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable updateHall(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inHallID = (inPara["HallID"] == null || inPara["HallID"].ToString() == "") ? 0 : Int32.Parse(inPara["HallID"].ToString());
string inNameEn = (inPara["NameEn"] == null) ? "" : inPara["NameEn"].ToString();
string inNameCht = (inPara["NameCht"] == null) ? "" : inPara["NameCht"].ToString();
string inNameChs = (inPara["NameChs"] == null) ? "" : inPara["NameChs"].ToString();
string inNameEnShort = (inPara["NameEnShort"] == null) ? "" : inPara["NameEnShort"].ToString();
string inNameChtShort = (inPara["NameChtShort"] == null) ? "" : inPara["NameChtShort"].ToString();
string inNameChsShort = (inPara["NameChsShort"] == null) ? "" : inPara["NameChsShort"].ToString();
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
strSQL = "update Hall set NameEn=@NameEn,NameEnShort=@NameEnShort,NameCht=@NameCht,NameChtShort=@NameChtShort,NameChs=@NameChs,NameChsShort=@NameChsShort,UpdateByUserID=@UpdateByUserID, UpdateTime={fn NOW()} where HallID=@HallID;";
strSQL += " select @@ROWCOUNT;";
cmd.Parameters.AddWithValue("@HallID", inHallID);
strSQL = "insert into Hall (NameEn,NameEnShort,NameCht,NameChtShort,NameChs,NameChsShort,CreateTime,CreateByUserID,UpdateTime,UpdateByUserID,Status) values (@NameEn,@NameEnShort,@NameCht,@NameChtShort,@NameChs,@NameChsShort,{fn NOW()},@CreateByUserID,{fn NOW()},@UpdateByUserID,@Status);";
strSQL += "select @@IDENTITY;";
cmd.Parameters.AddWithValue("@Status", true);
cmd.Parameters.AddWithValue("@CreateByUserID", fromUserID);
cmd.Parameters.AddWithValue("@NameEn", inNameEn);
cmd.Parameters.AddWithValue("@NameEnShort", inNameEnShort);
cmd.Parameters.AddWithValue("@NameCht", inNameCht);
cmd.Parameters.AddWithValue("@NameChtShort", inNameChtShort);
cmd.Parameters.AddWithValue("@NameChs", inNameChs);
cmd.Parameters.AddWithValue("@NameChsShort", inNameChsShort);
cmd.Parameters.AddWithValue("@UpdateByUserID", fromUserID);
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
int dbHallID = Convert.ToInt32(cmd.ExecuteScalar());
outHash["Updated"] = dbHallID;
outHash["Updated"] = (dbHallID > 0) ? 1 : 0;
outHash["HallID"] = dbHallID;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable delHall(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inHallID = (inPara["HallID"] == null || inPara["HallID"].ToString() == "") ? 0 : Int32.Parse(inPara["HallID"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
String strSQL = "update Hall set Status='false', UpdateByUserID=@UpdateByUserID, UpdateTime={fn NOW()} where HallID=@HallID ";
strSQL += " select @@ROWCOUNT;";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@UpdateByUserID", fromUserID);
cmd.Parameters.AddWithValue("@HallID", inHallID);
cmd.CommandType = CommandType.Text;
int dbLogID = Convert.ToInt32(cmd.ExecuteScalar());
outHash["Updated"] = dbLogID;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable getProductCategory(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int inProductCategoryID = (inPara["ProductCategoryID"] == null || inPara["ProductCategoryID"].ToString() == "") ? 0 : Int32.Parse(inPara["ProductCategoryID"].ToString());
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
bool inExhibitorOnly = (inPara["ExhibitorOnly"] == null || inPara["ExhibitorOnly"] == "") ? false : Convert.ToBoolean(inPara["ExhibitorOnly"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
Hashtable hashProductCategory = new Hashtable();
if (inExhibitorOnly && inFairID > 0) {
strSQL = "SELECT DISTINCT p.*, p1.NameEn AS ParentProductCategory, f.EMSFairID AS Fair FROM ProductCategory AS p LEFT OUTER JOIN ProductCategory AS p1 ON p.ParentProductCategoryID = p1.ProductCategoryID INNER JOIN Fair AS f ON p.FairID = f.FairID LEFT OUTER JOIN User17 AS u1 ON p.CreateByUserID = u1.UserID LEFT OUTER JOIN User17 AS u2 ON p.UpdateByUserID = u2.UserID ";
strSQL += " LEFT OUTER JOIN ExhibitorProductCategoryMatch AS epc ON p.ProductCategoryID = epc.ProductCategoryID ";
strSQL += " LEFT OUTER JOIN Exhibitor AS e ON epc.ExhibitorID = e.ExhibitorID ";
strSQL += " LEFT OUTER JOIN ProductProductCategoryMatch AS ppc ON p.ProductCategoryID = ppc.ProductCategoryID ";
strSQL += " LEFT OUTER JOIN Product AS pd ON ppc.ProductID = pd.ProductID ";
strSQL += " WHERE (p.Status = 'true') AND (p.FairID = @FairID) AND ((e.Status = 'true') or (pd.Status='true')) AND (epc.Status = 'true')";
strSQL = "SELECT p.*, p1.NameEn as ParentProductCategory, f.EMSFairID as Fair, u1.Name AS CreateBy, u2.Name AS UpdateBy FROM ProductCategory AS p left outer join ProductCategory as p1 on p.ParentProductCategoryID=p1.ProductCategoryID INNER JOIN Fair AS f ON p.FairID = f.FairID left outer JOIN [User17] AS u1 ON p.CreateByUserID = u1.UserID left outer JOIN [User17] AS u2 ON p.UpdateByUserID = u2.UserID WHERE (p.Status = 'true')";
strSQL += (inFairID > 0) ? " and p.FairID=@FairID " : "";
strSQL += (inProductCategoryID > 0) ? " and p.ProductCategoryID=@ProductCategoryID " : "";
strSQL += " order by p.FairID,p.ItemOrder";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@FairID", inFairID);
if (inProductCategoryID > 0) {
cmd.Parameters.AddWithValue("@ProductCategoryID", inProductCategoryID);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
Hashtable hashRow = new Hashtable();
for (int i = 0; i < rdrBrowsers.FieldCount; i++) {
switch (rdrBrowsers.GetName(i).ToString()) {
DateTime tDate = (!DBNull.Value.Equals(rdrBrowsers.GetValue(i))) ? (DateTime)rdrBrowsers.GetValue(i) : DateTime.MinValue;
String tValue = tDate.ToString("yyyy-MM-dd HH:mm:ss");
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
hashRow[rdrBrowsers.GetName(i).ToString()] = rdrBrowsers.GetValue(i);
hashProductCategory[(int)rdrBrowsers["ProductCategoryID"]] = hashRow;
outHash = hashProductCategory;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable updateProductCategory(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inProductCategoryID = (inPara["ProductCategoryID"] == null || inPara["ProductCategoryID"].ToString() == "") ? 0 : Int32.Parse(inPara["ProductCategoryID"].ToString());
int inParentProductCategoryID = (inPara["ParentProductCategoryID"] == null || inPara["ParentProductCategoryID"].ToString() == "") ? 0 : Int32.Parse(inPara["ParentProductCategoryID"].ToString());
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
string inNameEn = (inPara["NameEn"] == null) ? "" : inPara["NameEn"].ToString();
string inNameCht = (inPara["NameCht"] == null) ? "" : inPara["NameCht"].ToString();
string inNameChs = (inPara["NameChs"] == null) ? "" : inPara["NameChs"].ToString();
string inNameEnShort = (inPara["NameEnShort"] == null) ? "" : inPara["NameEnShort"].ToString();
string inNameChtShort = (inPara["NameChtShort"] == null) ? "" : inPara["NameChtShort"].ToString();
string inNameChsShort = (inPara["NameChsShort"] == null) ? "" : inPara["NameChsShort"].ToString();
int inItemOrder = (inPara["ItemOrder"] == null || inPara["ItemOrder"].ToString() == "") ? 0 : Int32.Parse(inPara["ItemOrder"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
if (inProductCategoryID > 0) {
strSQL = "update ProductCategory set NameEn=@NameEn,NameEnShort=@NameEnShort,NameCht=@NameCht,NameChtShort=@NameChtShort,NameChs=@NameChs,NameChsShort=@NameChsShort,ItemOrder=@ItemOrder,ParentProductCategoryID=@ParentProductCategoryID,FairID=@FairID,UpdateByUserID=@UpdateByUserID, UpdateTime={fn NOW()} where ProductCategoryID=@ProductCategoryID;";
strSQL += " select @@ROWCOUNT;";
cmd.Parameters.AddWithValue("@ProductCategoryID", inProductCategoryID);
strSQL = "insert into ProductCategory (NameEn,NameEnShort,NameCht,NameChtShort,NameChs,NameChsShort,ItemOrder,ParentProductCategoryID,FairID,CreateTime,CreateByUserID,UpdateTime,UpdateByUserID,Status) values (@NameEn,@NameEnShort,@NameCht,@NameChtShort,@NameChs,@NameChsShort,@ItemOrder,@ParentProductCategoryID,@FairID,{fn NOW()},@CreateByUserID,{fn NOW()},@UpdateByUserID,@Status);";
strSQL += "select @@IDENTITY;";
cmd.Parameters.AddWithValue("@Status", true);
cmd.Parameters.AddWithValue("@CreateByUserID", fromUserID);
cmd.Parameters.AddWithValue("@NameEn", inNameEn);
cmd.Parameters.AddWithValue("@NameEnShort", inNameEnShort);
cmd.Parameters.AddWithValue("@NameCht", inNameCht);
cmd.Parameters.AddWithValue("@NameChtShort", inNameChtShort);
cmd.Parameters.AddWithValue("@NameChs", inNameChs);
cmd.Parameters.AddWithValue("@NameChsShort", inNameChsShort);
cmd.Parameters.AddWithValue("@ItemOrder", inItemOrder);
cmd.Parameters.AddWithValue("@ParentProductCategoryID", inParentProductCategoryID);
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.Parameters.AddWithValue("@UpdateByUserID", fromUserID);
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
int dbProductCategoryID = Convert.ToInt32(cmd.ExecuteScalar());
if (inProductCategoryID > 0) {
outHash["Updated"] = dbProductCategoryID;
outHash["Updated"] = (dbProductCategoryID > 0) ? 1 : 0;
outHash["ProductCategoryID"] = dbProductCategoryID;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable delProductCategory(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inProductCategoryID = (inPara["ProductCategoryID"] == null || inPara["ProductCategoryID"].ToString() == "") ? 0 : Int32.Parse(inPara["ProductCategoryID"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
String strSQL = "update ProductCategory set Status='false', UpdateByUserID=@UpdateByUserID, UpdateTime={fn NOW()} where ProductCategoryID=@ProductCategoryID ";
strSQL += " select @@ROWCOUNT;";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@UpdateByUserID", fromUserID);
cmd.Parameters.AddWithValue("@ProductCategoryID", inProductCategoryID);
cmd.CommandType = CommandType.Text;
int dbLogID = Convert.ToInt32(cmd.ExecuteScalar());
outHash["Updated"] = dbLogID;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable getBusinessNature(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int inBusinessNatureID = (inPara["BusinessNatureID"] == null || inPara["BusinessNatureID"].ToString() == "") ? 0 : Int32.Parse(inPara["BusinessNatureID"].ToString());
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
bool inExhibitorOnly = (inPara["ExhibitorOnly"] == null || inPara["ExhibitorOnly"] == "") ? false : Convert.ToBoolean(inPara["ExhibitorOnly"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
Hashtable hashBusinessNature = new Hashtable();
if (inExhibitorOnly && inFairID > 0) {
strSQL = "SELECT DISTINCT b.*, f.EMSFairID AS Fair FROM BusinessNature AS b INNER JOIN Fair AS f ON b.FairID = f.FairID LEFT OUTER JOIN User17 AS u1 ON b.CreateByUserID = u1.UserID LEFT OUTER JOIN User17 AS u2 ON b.UpdateByUserID = u2.UserID ";
strSQL += " LEFT OUTER JOIN ExhibitorBusinessNatureMatch AS ebn ON b.BusinessNatureID = ebn.BusinessNatureID ";
strSQL += " LEFT OUTER JOIN Exhibitor AS e ON ebn.ExhibitorID = e.ExhibitorID ";
strSQL += " WHERE (b.Status = 'true') AND (b.FairID = @FairID) AND (e.Status = 'true')";
strSQL = "SELECT b.*, f.EMSFairID as Fair, u1.Name AS CreateBy, u2.Name AS UpdateBy FROM BusinessNature AS b INNER JOIN Fair AS f ON b.FairID = f.FairID left outer JOIN [User17] AS u1 ON b.CreateByUserID = u1.UserID left outer JOIN [User17] AS u2 ON b.UpdateByUserID = u2.UserID WHERE (b.Status = 'true')";
strSQL += (inFairID > 0) ? " and b.FairID=@FairID " : "";
strSQL += (inBusinessNatureID > 0) ? " and b.BusinessNatureID=@BusinessNatureID " : "";
strSQL += " order by b.FairID,b.ItemOrder";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@FairID", inFairID);
if (inBusinessNatureID > 0) {
cmd.Parameters.AddWithValue("@BusinessNatureID", inBusinessNatureID);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
Hashtable hashRow = new Hashtable();
for (int i = 0; i < rdrBrowsers.FieldCount; i++) {
switch (rdrBrowsers.GetName(i).ToString()) {
DateTime tDate = (!DBNull.Value.Equals(rdrBrowsers.GetValue(i))) ? (DateTime)rdrBrowsers.GetValue(i) : DateTime.MinValue;
String tValue = tDate.ToString("yyyy-MM-dd HH:mm:ss");
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
hashRow[rdrBrowsers.GetName(i).ToString()] = rdrBrowsers.GetValue(i);
hashBusinessNature[(int)rdrBrowsers["BusinessNatureID"]] = hashRow;
outHash = hashBusinessNature;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable updateBusinessNature(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inBusinessNatureID = (inPara["BusinessNatureID"] == null || inPara["BusinessNatureID"].ToString() == "") ? 0 : Int32.Parse(inPara["BusinessNatureID"].ToString());
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
string inNameEn = (inPara["NameEn"] == null) ? "" : inPara["NameEn"].ToString();
string inNameCht = (inPara["NameCht"] == null) ? "" : inPara["NameCht"].ToString();
string inNameChs = (inPara["NameChs"] == null) ? "" : inPara["NameChs"].ToString();
string inNameEnShort = (inPara["NameEnShort"] == null) ? "" : inPara["NameEnShort"].ToString();
string inNameChtShort = (inPara["NameChtShort"] == null) ? "" : inPara["NameChtShort"].ToString();
string inNameChsShort = (inPara["NameChsShort"] == null) ? "" : inPara["NameChsShort"].ToString();
int inItemOrder = (inPara["ItemOrder"] == null || inPara["ItemOrder"].ToString() == "") ? 0 : Int32.Parse(inPara["ItemOrder"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
if (inBusinessNatureID > 0) {
strSQL = "update BusinessNature set NameEn=@NameEn,NameEnShort=@NameEnShort,NameCht=@NameCht,NameChtShort=@NameChtShort,NameChs=@NameChs,NameChsShort=@NameChsShort,ItemOrder=@ItemOrder,FairID=@FairID,UpdateByUserID=@UpdateByUserID, UpdateTime={fn NOW()} where BusinessNatureID=@BusinessNatureID;";
strSQL += " select @@ROWCOUNT;";
cmd.Parameters.AddWithValue("@BusinessNatureID", inBusinessNatureID);
strSQL = "insert into BusinessNature (NameEn,NameEnShort,NameCht,NameChtShort,NameChs,NameChsShort,ItemOrder,FairID,CreateTime,CreateByUserID,UpdateTime,UpdateByUserID,Status) values (@NameEn,@NameEnShort,@NameCht,@NameChtShort,@NameChs,@NameChsShort,@ItemOrder,@FairID,{fn NOW()},@CreateByUserID,{fn NOW()},@UpdateByUserID,@Status);";
strSQL += "select @@IDENTITY;";
cmd.Parameters.AddWithValue("@Status", true);
cmd.Parameters.AddWithValue("@CreateByUserID", fromUserID);
cmd.Parameters.AddWithValue("@NameEn", inNameEn);
cmd.Parameters.AddWithValue("@NameEnShort", inNameEnShort);
cmd.Parameters.AddWithValue("@NameCht", inNameCht);
cmd.Parameters.AddWithValue("@NameChtShort", inNameChtShort);
cmd.Parameters.AddWithValue("@NameChs", inNameChs);
cmd.Parameters.AddWithValue("@NameChsShort", inNameChsShort);
cmd.Parameters.AddWithValue("@ItemOrder", inItemOrder);
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.Parameters.AddWithValue("@UpdateByUserID", fromUserID);
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
int dbBusinessNatureID = Convert.ToInt32(cmd.ExecuteScalar());
if (inBusinessNatureID > 0) {
outHash["Updated"] = dbBusinessNatureID;
outHash["Updated"] = (dbBusinessNatureID > 0) ? 1 : 0;
outHash["BusinessNatureID"] = dbBusinessNatureID;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable delBusinessNature(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inBusinessNatureID = (inPara["BusinessNatureID"] == null || inPara["BusinessNatureID"].ToString() == "") ? 0 : Int32.Parse(inPara["BusinessNatureID"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
String strSQL = "update BusinessNature set Status='false', UpdateByUserID=@UpdateByUserID, UpdateTime={fn NOW()} where BusinessNatureID=@BusinessNatureID ";
strSQL += " select @@ROWCOUNT;";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@UpdateByUserID", fromUserID);
cmd.Parameters.AddWithValue("@BusinessNatureID", inBusinessNatureID);
cmd.CommandType = CommandType.Text;
int dbLogID = Convert.ToInt32(cmd.ExecuteScalar());
outHash["Updated"] = dbLogID;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable getExhibitorType(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int inExhibitorTypeID = (inPara["ExhibitorTypeID"] == null || inPara["ExhibitorTypeID"].ToString() == "") ? 0 : Int32.Parse(inPara["ExhibitorTypeID"].ToString());
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
bool inExhibitorOnly = (inPara["ExhibitorOnly"] == null || inPara["ExhibitorOnly"] == "") ? false : Convert.ToBoolean(inPara["ExhibitorOnly"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
Hashtable hashExhibitorType = new Hashtable();
if (inExhibitorOnly && inFairID > 0) {
strSQL = "SELECT et.*, f.EMSFairID as Fair, u1.Name AS CreateBy, u2.Name AS UpdateBy FROM ExhibitorType AS et INNER JOIN Fair AS f ON et.FairID = f.FairID left outer JOIN [User17] AS u1 ON et.CreateByUserID = u1.UserID left outer JOIN [User17] AS u2 ON et.UpdateByUserID = u2.UserID LEFT OUTER JOIN ExhibitorTypeMatch AS etm ON etm.ExhibitorTypeID = et.ExhibitorTypeID LEFT OUTER JOIN Exhibitor AS e ON etm.ExhibitorID = e.ExhibitorID WHERE (et.Status = 'true') and e.Status='true' ";
strSQL = "SELECT et.*, f.EMSFairID as Fair, u1.Name AS CreateBy, u2.Name AS UpdateBy FROM ExhibitorType AS et INNER JOIN Fair AS f ON et.FairID = f.FairID left outer JOIN [User17] AS u1 ON et.CreateByUserID = u1.UserID left outer JOIN [User17] AS u2 ON et.UpdateByUserID = u2.UserID WHERE (et.Status = 'true')";
strSQL += (inFairID > 0) ? " and et.FairID=@FairID " : "";
strSQL += (inExhibitorTypeID > 0) ? " and et.ExhibitorTypeID=@ExhibitorTypeID " : "";
strSQL += " order by et.FairID,et.ItemOrder";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@FairID", inFairID);
if (inExhibitorTypeID > 0) {
cmd.Parameters.AddWithValue("@ExhibitorTypeID", inExhibitorTypeID);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
Hashtable hashRow = new Hashtable();
for (int i = 0; i < rdrBrowsers.FieldCount; i++) {
switch (rdrBrowsers.GetName(i).ToString()) {
DateTime tDate = (!DBNull.Value.Equals(rdrBrowsers.GetValue(i))) ? (DateTime)rdrBrowsers.GetValue(i) : DateTime.MinValue;
String tValue = tDate.ToString("yyyy-MM-dd HH:mm:ss");
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
hashRow[rdrBrowsers.GetName(i).ToString()] = rdrBrowsers.GetValue(i);
hashExhibitorType[(int)rdrBrowsers["ExhibitorTypeID"]] = hashRow;
outHash = hashExhibitorType;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable updateExhibitorType(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inExhibitorTypeID = (inPara["ExhibitorTypeID"] == null || inPara["ExhibitorTypeID"].ToString() == "") ? 0 : Int32.Parse(inPara["ExhibitorTypeID"].ToString());
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
string inNameEn = (inPara["NameEn"] == null) ? "" : inPara["NameEn"].ToString();
string inNameCht = (inPara["NameCht"] == null) ? "" : inPara["NameCht"].ToString();
string inNameChs = (inPara["NameChs"] == null) ? "" : inPara["NameChs"].ToString();
string inNameEnShort = (inPara["NameEnShort"] == null) ? "" : inPara["NameEnShort"].ToString();
string inNameChtShort = (inPara["NameChtShort"] == null) ? "" : inPara["NameChtShort"].ToString();
string inNameChsShort = (inPara["NameChsShort"] == null) ? "" : inPara["NameChsShort"].ToString();
int inItemOrder = (inPara["ItemOrder"] == null || inPara["ItemOrder"].ToString() == "") ? 0 : Int32.Parse(inPara["ItemOrder"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
if (inExhibitorTypeID > 0) {
strSQL = "update ExhibitorType set NameEn=@NameEn,NameEnShort=@NameEnShort,NameCht=@NameCht,NameChtShort=@NameChtShort,NameChs=@NameChs,NameChsShort=@NameChsShort,ItemOrder=@ItemOrder,FairID=@FairID,UpdateByUserID=@UpdateByUserID, UpdateTime={fn NOW()} where ExhibitorTypeID=@ExhibitorTypeID;";
strSQL += " select @@ROWCOUNT;";
cmd.Parameters.AddWithValue("@ExhibitorTypeID", inExhibitorTypeID);
strSQL = "insert into ExhibitorType (NameEn,NameEnShort,NameCht,NameChtShort,NameChs,NameChsShort,ItemOrder,FairID,CreateTime,CreateByUserID,UpdateTime,UpdateByUserID,Status) values (@NameEn,@NameEnShort,@NameCht,@NameChtShort,@NameChs,@NameChsShort,@ItemOrder,@FairID,{fn NOW()},@CreateByUserID,{fn NOW()},@UpdateByUserID,@Status);";
strSQL += "select @@IDENTITY;";
cmd.Parameters.AddWithValue("@Status", true);
cmd.Parameters.AddWithValue("@CreateByUserID", fromUserID);
cmd.Parameters.AddWithValue("@NameEn", inNameEn);
cmd.Parameters.AddWithValue("@NameEnShort", inNameEnShort);
cmd.Parameters.AddWithValue("@NameCht", inNameCht);
cmd.Parameters.AddWithValue("@NameChtShort", inNameChtShort);
cmd.Parameters.AddWithValue("@NameChs", inNameChs);
cmd.Parameters.AddWithValue("@NameChsShort", inNameChsShort);
cmd.Parameters.AddWithValue("@ItemOrder", inItemOrder);
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.Parameters.AddWithValue("@UpdateByUserID", fromUserID);
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
int dbExhibitorTypeID = Convert.ToInt32(cmd.ExecuteScalar());
if (inExhibitorTypeID > 0) {
outHash["Updated"] = dbExhibitorTypeID;
outHash["Updated"] = (dbExhibitorTypeID > 0) ? 1 : 0;
outHash["ExhibitorTypeID"] = dbExhibitorTypeID;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable delExhibitorType(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inExhibitorTypeID = (inPara["ExhibitorTypeID"] == null || inPara["ExhibitorTypeID"].ToString() == "") ? 0 : Int32.Parse(inPara["ExhibitorTypeID"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
String strSQL = "update ExhibitorType set Status='false', UpdateByUserID=@UpdateByUserID, UpdateTime={fn NOW()} where ExhibitorTypeID=@ExhibitorTypeID ";
strSQL += " select @@ROWCOUNT;";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@UpdateByUserID", fromUserID);
cmd.Parameters.AddWithValue("@ExhibitorTypeID", inExhibitorTypeID);
cmd.CommandType = CommandType.Text;
int dbLogID = Convert.ToInt32(cmd.ExecuteScalar());
outHash["Updated"] = dbLogID;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable getEnquiry(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int inEnquiryID = (inPara["EnquiryID"] == null || inPara["EnquiryID"].ToString() == "") ? 0 : Int32.Parse(inPara["EnquiryID"].ToString());
int inExhibitorID = (inPara["ExhibitorID"] == null || inPara["ExhibitorID"].ToString() == "") ? 0 : Int32.Parse(inPara["ExhibitorID"].ToString());
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
Hashtable hashEnquiry = new Hashtable();
strSQL = "SELECT e.*, ex.ExhibitorNameEn, u2.Name AS UpdateBy FROM Enquiry AS e INNER JOIN Fair AS f ON e.FairID = f.FairID left outer JOIN [User17] AS u2 ON e.UpdateByUserID = u2.UserID left outer join EnquiryExhibitorMatch eem on e.ID=eem.EnquiryID left outer join Exhibitor ex on eem.ExhibitorID=ex.ExhibitorID WHERE (e.Status = 'true')";
strSQL += (inFairID > 0) ? " and e.FairID=@FairID " : "";
strSQL += (inExhibitorID > 0) ? " and e.ExhibitorID=@ExhibitorID " : "";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.Parameters.AddWithValue("@ExhibitorID", inExhibitorID);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
Hashtable hashRow = new Hashtable();
for (int i = 0; i < rdrBrowsers.FieldCount; i++) {
switch (rdrBrowsers.GetName(i).ToString()) {
DateTime tDate = (!DBNull.Value.Equals(rdrBrowsers.GetValue(i))) ? (DateTime)rdrBrowsers.GetValue(i) : DateTime.MinValue;
String tValue = tDate.ToString("yyyy-MM-dd HH:mm:ss");
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
hashRow[rdrBrowsers.GetName(i).ToString()] = rdrBrowsers.GetValue(i);
hashEnquiry[(int)rdrBrowsers["ID"]] = hashRow;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable updateEnquiry(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inEnquiryID = (inPara["EnquiryID"] == null || inPara["EnquiryID"].ToString() == "") ? 0 : Int32.Parse(inPara["EnquiryID"].ToString());
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
int inLangID = (inPara["LangID"] == null || inPara["LangID"].ToString() == "") ? 0 : Int32.Parse(inPara["LangID"].ToString());
string inSalutation = inPara["Salutation"] == null ? "" : inPara["Salutation"].ToString();
string inFirstName = inPara["FirstName"] == null ? "" : inPara["FirstName"].ToString();
string inLastName = inPara["LastName"] == null ? "" : inPara["LastName"].ToString();
string inCompanyName = inPara["CompanyName"] == null ? "" : inPara["CompanyName"].ToString();
string inCountry = inPara["Country"] == null ? "" : inPara["Country"].ToString();
string inPhoneCountryCode = inPara["PhoneCountryCode"] == null ? "" : inPara["PhoneCountryCode"].ToString();
string inPhoneArea = inPara["PhoneArea"] == null ? "" : inPara["PhoneArea"].ToString();
string inPhoneNo = inPara["PhoneNo"] == null ? "" : inPara["PhoneNo"].ToString();
string inEmail = inPara["Email"] == null ? "" : inPara["Email"].ToString();
string inEmailCC = inPara["EmailCC"] == null ? "" : inPara["EmailCC"].ToString();
string inJobTitle = inPara["JobTitle"] == null ? "" : inPara["JobTitle"].ToString();
string inAddress1 = inPara["Address1"] == null ? "" : inPara["Address1"].ToString();
string inAddress2 = inPara["Address2"] == null ? "" : inPara["Address2"].ToString();
string inAddress3 = inPara["Address3"] == null ? "" : inPara["Address3"].ToString();
string inEnquiryMessage = inPara["EnquiryMessage"] == null ? "" : inPara["EnquiryMessage"].ToString();
bool inChkOptIn = (inPara["ChkOptIn"] == null || inPara["ChkOptIn"] == "") ? false : Convert.ToBoolean(inPara["ChkOptIn"].ToString());
bool inChkMakeAppointment = (inPara["ChkMakeAppointment"] == null || inPara["ChkMakeAppointment"] == "") ? false : Convert.ToBoolean(inPara["ChkMakeAppointment"].ToString());
bool inChkRecvProductInfo = (inPara["ChkRecvProductInfo"] == null || inPara["ChkRecvProductInfo"] == "") ? false : Convert.ToBoolean(inPara["ChkRecvProductInfo"].ToString());
bool inChkRecvCompanyInfo = (inPara["ChkRecvCompanyInfo"] == null || inPara["ChkRecvCompanyInfo"] == "") ? false : Convert.ToBoolean(inPara["ChkRecvCompanyInfo"].ToString());
string inEnquiryExhibitors = inPara["EnquiryExhibitors"] == null ? "" : inPara["EnquiryExhibitors"].ToString();
string inUserIP = inPara["UserIP"] == null ? "" : inPara["UserIP"].ToString();
String inUserAgent = inPara["UserIP"] == null ? "" : inPara["UserIP"].ToString();
inUserAgent = (inUserAgent.Length > 1000) ? inUserAgent.Substring(0,1000) : inUserAgent;
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
strSQL = "update Enquiry set FairID=@FairID,LangID=@LangID,Salutation=@Salutation,FirstName=@FirstName,LastName=@LastName,CompanyName=@CompanyName,Country=@Country,PhoneCountryCode=@PhoneCountryCode,PhoneArea=@PhoneArea,PhoneNo=@PhoneNo,Email=@Email,EmailCC=@EmailCC,JobTitle=@JobTitle,Address1=@Address1,Address2=@Address2,Address3=@Address3,EnquiryMessage=@EnquiryMessage,ChkOptIn=@ChkOptIn,ChkMakeAppointment=@ChkMakeAppointment,ChkRecvProductInfo=@ChkRecvProductInfo,ChkRecvCompanyInfo=@ChkRecvCompanyInfo,UserIP=@UserIP,UserAgent=@UserAgent,UpdateByUserID=@UpdateByUserID, UpdateTime={fn NOW()} where ID=@EnquiryID;";
strSQL += " select @@ROWCOUNT;";
cmd.Parameters.AddWithValue("@EnquiryID", inEnquiryID);
strSQL = "insert into Enquiry (FairID,LangID,Salutation,FirstName,LastName,CompanyName,Country,PhoneCountryCode,PhoneArea,PhoneNo,Email,EmailCC,JobTitle,Address1,Address2,Address3,EnquiryMessage,ChkOptIn,ChkMakeAppointment,ChkRecvProductInfo,ChkRecvCompanyInfo,UserIP,UserAgent,SubmitTime,UpdateTime,UpdateByUserID,Status) values (@FairID,@LangID,@Salutation,@FirstName,@LastName,@CompanyName,@Country,@PhoneCountryCode,@PhoneArea,@PhoneNo,@Email,@EmailCC,@JobTitle,@Address1,@Address2,@Address3,@EnquiryMessage,@ChkOptIn,@ChkMakeAppointment,@ChkRecvProductInfo,@ChkRecvCompanyInfo,@UserIP,@UserAgent,{fn NOW()},{fn NOW()},@UpdateByUserID,@Status);";
strSQL += "select @@IDENTITY;";
cmd.Parameters.AddWithValue("@Status", true);
cmd.Parameters.AddWithValue("@CreateByUserID", fromUserID);
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.Parameters.AddWithValue("@LangID", inLangID);
cmd.Parameters.AddWithValue("@Salutation", inSalutation);
cmd.Parameters.AddWithValue("@FirstName", inFirstName);
cmd.Parameters.AddWithValue("@LastName", inLastName);
cmd.Parameters.AddWithValue("@CompanyName", inCompanyName);
cmd.Parameters.AddWithValue("@Country", inCountry);
cmd.Parameters.AddWithValue("@PhoneCountryCode", inPhoneCountryCode);
cmd.Parameters.AddWithValue("@PhoneArea", inPhoneArea);
cmd.Parameters.AddWithValue("@PhoneNo", inPhoneNo);
cmd.Parameters.AddWithValue("@Email", inEmail);
cmd.Parameters.AddWithValue("@EmailCC", inEmailCC);
cmd.Parameters.AddWithValue("@JobTitle", inJobTitle);
cmd.Parameters.AddWithValue("@Address1", inAddress1);
cmd.Parameters.AddWithValue("@Address2", inAddress2);
cmd.Parameters.AddWithValue("@Address3", inAddress3);
cmd.Parameters.AddWithValue("@EnquiryMessage", inEnquiryMessage);
cmd.Parameters.AddWithValue("@ChkOptIn", inChkOptIn);
cmd.Parameters.AddWithValue("@ChkMakeAppointment", inChkMakeAppointment);
cmd.Parameters.AddWithValue("@ChkRecvProductInfo", inChkRecvProductInfo);
cmd.Parameters.AddWithValue("@ChkRecvCompanyInfo", inChkRecvCompanyInfo);
cmd.Parameters.AddWithValue("@UserIP", inUserIP);
cmd.Parameters.AddWithValue("@UserAgent", inUserAgent);
cmd.Parameters.AddWithValue("@UpdateByUserID", fromUserID);
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
int dbEnquiryID = Convert.ToInt32(cmd.ExecuteScalar());
int currEnquiryID = (inEnquiryID == 0) ? dbEnquiryID : inEnquiryID;
strSQL = "delete from EnquiryExhibitorMatch where EnquiryID=@EnquiryID;";
strSQL += " select @@ROWCOUNT;";
cmd.Parameters.AddWithValue("@EnquiryID", currEnquiryID);
cmd.CommandText = strSQL;
int dbUpdated = Convert.ToInt32(cmd.ExecuteScalar());
if (inEnquiryExhibitors != "") {
strSQL = "insert into EnquiryExhibitorMatch (EnquiryID, ExhibitorID) values ";
String[] arrExhID = inEnquiryExhibitors.Split(',');
foreach (String tID in arrExhID) {
strSQLval += (strSQLval == "") ? "" : ",";
strSQLval += "(" + currEnquiryID + "," + tID + ")";
strSQL += strSQLval + "; select @@ROWCOUNT;";
cmd.CommandText = strSQL;
int dbUpdated2 = Convert.ToInt32(cmd.ExecuteScalar());
outHash["Updated"] = dbEnquiryID;
outHash["Updated"] = (dbEnquiryID > 0) ? 1 : 0;
outHash["EnquiryID"] = dbEnquiryID;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable delEnquiry(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inEnquiryID = (inPara["EnquiryID"] == null || inPara["EnquiryID"].ToString() == "") ? 0 : Int32.Parse(inPara["EnquiryID"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
String strSQL = "update Enquiry set Status='false', UpdateByUserID=@UpdateByUserID, UpdateTime={fn NOW()} where EnquiryID=@EnquiryID ";
strSQL += " select @@ROWCOUNT;";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@UpdateByUserID", fromUserID);
cmd.Parameters.AddWithValue("@EnquiryID", inEnquiryID);
cmd.CommandType = CommandType.Text;
int dbLogID = Convert.ToInt32(cmd.ExecuteScalar());
outHash["Updated"] = dbLogID;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable getActionLog(Hashtable inPara) {
Hashtable outHash = new Hashtable();
String inMonth = (inPara["Month"] == null) ? "" : inPara["Month"].ToString();
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
strSQL = "SELECT l.UserID, l.FairID, l.Action, l.ActionPara, l.UserAgent, l.UserIP, l.CreateTime, l.rowID, u.Name, f.EMSFairID AS Event from ActionLog_" + inMonth + " AS l LEFT OUTER JOIN [User17] AS u ON l.UserID = u.UserID LEFT OUTER JOIN Fair AS f ON l.FairID = f.FairID";
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
Hashtable hashRow = new Hashtable();
for (int i = 0; i < rdrBrowsers.FieldCount; i++) {
switch (rdrBrowsers.GetName(i).ToString()) {
DateTime tDate = (!DBNull.Value.Equals(rdrBrowsers.GetValue(i))) ? (DateTime)rdrBrowsers.GetValue(i) : DateTime.MinValue;
String tValue = tDate.ToString("yyyy-MM-dd HH:mm:ss");
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
hashRow[rdrBrowsers.GetName(i).ToString()] = rdrBrowsers.GetValue(i);
outHash[(int)rdrBrowsers["rowID"]] = hashRow;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable getCountry(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
int inLangID = (inPara["LangID"] == null || inPara["LangID"].ToString() == "") ? 0 : Int32.Parse(inPara["LangID"].ToString());
bool inExhibitorOnly = (inPara["ExhibitorOnly"] == null || inPara["ExhibitorOnly"] == "") ? false : Convert.ToBoolean(inPara["ExhibitorOnly"].ToString());
bool inNoState = (inPara["NoState"] == null || inPara["NoState"] == "") ? false : Convert.ToBoolean(inPara["NoState"].ToString());
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
Hashtable hashCountry = new Hashtable();
if (inFairID > 0 && inExhibitorOnly) {
strSQL = "select distinct c.*, cl.Name as NameLang from Exhibitor e left outer join Country c on e.CountryID=c.CountryID left outer join CountryLang cl on c.CountryID=cl.CountryID where e.FairID=@FairID and e.Status='true' and c.CountryID is not null and cl.LangID=" + inLangID;
strSQL = "SELECT distinct c.* from Exhibitor e left outer join Country c on e.CountryID=c.CountryID where e.FairID=@FairID and e.Status='true' and c.CountryID is not null ";
strSQL = "select c.*, cl.Name as NameLang from Country c left outer join CountryLang cl on c.CountryID=cl.CountryID where c.Status = 'true' and cl.LangID=" + inLangID;
strSQL = "SELECT c.* from Country c WHERE (c.Status = 'true') ";
strSQL += (inNoState) ? " and c.ItemOrder < 10000 " : "";
strSQL += " order by c.ItemOrder";
cmd.CommandText = strSQL;
if (inFairID > 0 && inExhibitorOnly) {
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
Hashtable hashRow = new Hashtable();
for (int i = 0; i < rdrBrowsers.FieldCount; i++) {
switch (rdrBrowsers.GetName(i).ToString()) {
DateTime tDate = (!DBNull.Value.Equals(rdrBrowsers.GetValue(i))) ? (DateTime)rdrBrowsers.GetValue(i) : DateTime.MinValue;
String tValue = tDate.ToString("yyyy-MM-dd HH:mm:ss");
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
hashRow[rdrBrowsers.GetName(i).ToString()] = rdrBrowsers.GetValue(i);
hashCountry[(int)rdrBrowsers["CountryID"]] = hashRow;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable getLoginFailLog(Hashtable inPara) {
Hashtable outHash = new Hashtable();
String inMonth = (inPara["Month"] == null) ? "" : inPara["Month"].ToString();
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
strSQL = "SELECT * FROM LoginFailLog_" + inMonth;
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
Hashtable hashRow = new Hashtable();
for (int i = 0; i < rdrBrowsers.FieldCount; i++) {
switch (rdrBrowsers.GetName(i).ToString()) {
DateTime tDate = (!DBNull.Value.Equals(rdrBrowsers.GetValue(i))) ? (DateTime)rdrBrowsers.GetValue(i) : DateTime.MinValue;
String tValue = tDate.ToString("yyyy-MM-dd HH:mm:ss");
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
hashRow[rdrBrowsers.GetName(i).ToString()] = rdrBrowsers.GetValue(i);
outHash[(int)rdrBrowsers["rowID"]] = hashRow;
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable getExhibitorExcel(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
Hashtable hashFairs = getFair(inPara);
Hashtable hashFair = (Hashtable)hashFairs[inFairID];
Hashtable hashProductCategory = getProductCategory(inPara);
Hashtable hashBusinessNature = getBusinessNature(inPara);
Hashtable hashExhibitorType = getExhibitorType(inPara);
List<string> listFieldCaption = new List<string>();
List<string> listFieldLink = new List<string>();
List<string> listFieldDesc = new List<string>();
List<string> listFieldType = new List<string>();
List<string> listFieldExample = new List<string>();
List<int> listFieldWidth = new List<int>();
Hashtable hashFieldToCaption = new Hashtable();
string strPath = @System.Configuration.ConfigurationManager.AppSettings.Get("PhysicalUploadPath");
String strFile = "ExhList_" + hashFair["EMSFairID"] + "_" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + ".xlsx";
Hashtable hashExhibitor = getExhibitor(inPara);
Hashtable hashProduct = getProduct(inPara);
DataTable dt = new DataTable();
dt.TableName = "ExhList_" + hashFair["EMSFairID"].ToString();
String[] dtField = {"EMSID", "Country", "ExhibitorNameEn", "ExhibitorNameCht", "ExhibitorNameChs", "DescEn", "DescCht", "DescChs", "LinkEn", "LinkCht", "LinkChs", "BrandEn", "BrandCht", "BrandChs", "PhotoURL", "ContactPerson", "ContactPhone", "ContactEmail", "OEMID", "Venue", "Hall", "StandNo", "ProductCategory", "MemberID", "JoinedYear", "Status", "IsSync", "FeaturedArea", "FeaturedExhibitor", "ExhibitorType", "BusinessNature"};
String[] dtFieldLink = {"A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "A10", "A11", "A12", "A13", "A14", "A15", "A16", "A18", "A19", "A20", "A22", "A24", "A25", "A26", "A28", "A30", "A31", "A32", "A33", "A35", "A36", "A38", "A39"};
String[] dtFieldDesc = {"Unique number for an exhibitor (Must not duplicated)", "Country for Exhibitor, must use Country Name in [CountryMaster] worksheet", "Company Name for Exhibitor, in English", "Company Name for Exhibitor, in Language 2", "Company Name for Exhibitor, in Language 3", "Company Description for Exhibitor, in English", "Company Description for Exhibitor, in Language 2", "Company Description for Exhibitor, in Language 3", "Company Website URL for Exhibitor - English Version", "Company Website URL for Exhibitor - Language 2 Version", "Company Website URL for Exhibitor - Language 3 Version", "Brands, in English", "Brands, in Language 2", "Brands, in Language 3", "Company Logo Picture File", "Name of Contact Person for Enquiry (Optional)", "Phone number for Enquiry (Optional)", "Email for Receiving Enquiry", "ID of Exhibitor in OEM System (System Generated)", "Exhibition Venue of Stand Location, copy the line for multiple stand", "Exhibition Hall of Stand Location, copy the line for multiple stand", "Stand Number of Stand Location, copy the line for multiple stand", "Product Category, use the [Code] in [ProductCategoryMaster], | to separate multiple codes", "ID for B2B Portal (Optional)", "Number of year have been joined, will show 'New Exhibitor' if input 0, otherwise input -1 (Optional)", "Input 'True' to keep the record, 'False' to delete from exhibitor list", "Input 'True'", "Name for Featured Area (Optional)", "Code for Featured Exhibitor (Optional)", "Exhibitor Type Code, | to separate multiple codes (Optional)", "Business Nature Code, | to separate multiple codes (Optional)"};
String[] dtFieldType = {"number", "CountryMaster", "text", "text", "text", "text", "text", "text", "url (Link)", "url (Link)", "url (Link)", "text", "text", "text", "url (Link)", "text", "text", "text", "number", "text", "text", "text", "ProductCategoryMaster", "number", "number", "true/false", "true/false", "text", "text", "text", "text"};
String[] dtFieldExample = {"1001", "HONG KONG SAR", "ABC Company", "ABC 公司", "ABC 公司", "ABC Company is a building company.", "ABC 公司是一間建築公司。", "ABC 公司是一间建筑公司。", "http://abc.com", "http://abc.com", "http://abc.com", "XYZ", "XYZ", "XYZ", "http://abc.com/logo.jpg", "John Smith", "+852 21234567", "info@abc.com", "123", "HKCEC", "Hall 3", "3C-234", "Rubies| Emeralds| Sapphires", "9876", "0", "True", "True", "Natural & Organic", "1", "BOAA| Best Showroom", "Agent| Exporter| Importer| Service Provider"};
int[] dtFieldWidth = {8, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 8, 10, 10, 10, 30, 8, 8, 8, 8, 30, 30, 30, 30 };
listFieldCaption = dtField.OfType<string>().ToList();
listFieldLink = dtFieldLink.OfType<string>().ToList();
listFieldDesc = dtFieldDesc.OfType<string>().ToList();
listFieldType = dtFieldType.OfType<string>().ToList();
listFieldExample = dtFieldExample.OfType<string>().ToList();
listFieldWidth = dtFieldWidth.OfType<int>().ToList();
for (int I=1;I<=30;I++) {
String strI = (I < 10) ? "0" + I : I.ToString();
if (hashFair["labExhibitorField" + strI].ToString() != "") {
hashFieldToCaption["Field" + strI] = hashFair["labExhibitorField" + strI].ToString();
listFieldCaption.Add(hashFair["labExhibitorField" + strI].ToString());
listFieldExample.Add("");
for (int I=1;I<=(int)hashFair["NumOfProduct"];I++) {
listFieldCaption.Add("Product" + I + "_NameEn");
listFieldLink.Add("A41");
listFieldDesc.Add("Name of Product " + I + ", in English (Optional)");
listFieldType.Add("text");
listFieldExample.Add("Product ABC");
listFieldCaption.Add("Product" + I + "_NameCht");
listFieldLink.Add("A42");
listFieldDesc.Add("Name of Product " + I + ", in Language 2 (Optional)");
listFieldType.Add("text");
listFieldExample.Add("產品 ABC");
listFieldCaption.Add("Product" + I + "_NameChs");
listFieldLink.Add("A43");
listFieldDesc.Add("Name of Product " + I + ", in Language 3 (Optional)");
listFieldType.Add("text");
listFieldExample.Add("产品 ABC");
listFieldCaption.Add("Product" + I + "_DescEn");
listFieldLink.Add("A44");
listFieldDesc.Add("Description of Product " + I + ", in English (Optional)");
listFieldType.Add("text");
listFieldExample.Add("Product ABC is very popular!");
listFieldCaption.Add("Product" + I + "_DescCht");
listFieldLink.Add("A45");
listFieldDesc.Add("Description of Product " + I + ", in Language 2 (Optional)");
listFieldType.Add("text");
listFieldExample.Add("產品 ABC 很受歡迎!");
listFieldCaption.Add("Product" + I + "_DescChs");
listFieldLink.Add("A46");
listFieldDesc.Add("Description of Product " + I + ", in Language 3 (Optional)");
listFieldType.Add("text");
listFieldExample.Add("产品 ABC 很受欢迎!");
listFieldCaption.Add("Product" + I + "_PhotoUrl");
listFieldLink.Add("A47");
listFieldDesc.Add("Product " + I + "Photo File (Optional)");
listFieldType.Add("url (Link)");
listFieldExample.Add("http://abc.com/product1.jpg");
listFieldCaption.Add("Product" + I + "_VideoUrl");
listFieldLink.Add("A48");
listFieldDesc.Add("Link of Product " + I + "Video (Upload to Youtube / Yougu first) (Optional)");
listFieldType.Add("url (Link)");
listFieldExample.Add("http://youtube.com/watch?v=ad!43ADbca");
listFieldCaption.Add("Product" + I + "_ProductCategory");
listFieldLink.Add("A49");
listFieldDesc.Add("Product Category for Product " + I + ", use the [Code] in [ProductCategoryMaster], | to separate multiple codes (Optional)");
listFieldType.Add("text");
listFieldExample.Add("Rubies| Emeralds| Sapphires");
if (hashFair["labProductField" + J].ToString() != "") {
listFieldCaption.Add("Product" + I + "_" + hashFair["labProductField" + J].ToString());
listFieldDesc.Add("Field for Product " + I);
listFieldExample.Add("");
String[] dtFieldCaption = listFieldCaption.ToArray();
dtFieldLink = listFieldLink.ToArray();
dtFieldDesc = listFieldDesc.ToArray();
dtFieldType = listFieldType.ToArray();
dtFieldExample = listFieldExample.ToArray();
dtFieldWidth = listFieldWidth.ToArray();
foreach (String tCol in dtFieldCaption) {
dt.Columns.Add(tCol, typeof(string));
Hashtable hashExhProduct = new Hashtable();
if (hashProduct.Count > 0) {
foreach (Hashtable tProduct in hashProduct.Values) {
Hashtable tExh = (hashExhProduct.ContainsKey((int)tProduct["ExhibitorID"])) ? (Hashtable)hashExhProduct[(int)tProduct["ExhibitorID"]] : new Hashtable();
tExh[(int)tProduct["Sequence"]] = tProduct;
hashExhProduct[(int)tProduct["ExhibitorID"]] = tExh;
if (hashExhibitor.Count > 0) {
foreach (Hashtable tExhibitor in hashExhibitor.Values) {
DataRow dr = dt.NewRow();
Hashtable hashExtraRows = new Hashtable();
foreach (String tCol in tExhibitor.Keys) {
String tCatStr = tExhibitor[tCol].ToString();
String[] tCatArr = tCatStr.Split(',');
foreach (String tCatID in tCatArr) {
int intCatID = Int32.Parse(tCatID);
if (hashProductCategory.ContainsKey(intCatID)) {
Hashtable tRow = (Hashtable)hashProductCategory[intCatID];
outCatStr += (outCatStr == "") ? "" : "| ";
outCatStr += tRow["NameEnShort"];
String tBnStr = tExhibitor[tCol].ToString();
String[] tBnArr = tBnStr.Split(',');
foreach (String tBnID in tBnArr) {
int intBnID = Int32.Parse(tBnID);
if (hashBusinessNature.ContainsKey(intBnID)) {
Hashtable tRow = (Hashtable)hashBusinessNature[intBnID];
outBnStr += (outBnStr == "") ? "" : "| ";
outBnStr += tRow["NameEnShort"];
String tExhTypeStr = tExhibitor[tCol].ToString();
String outExhTypeStr = "";
String[] tExhTypeArr = tExhTypeStr.Split(',');
foreach (String tExhTypeID in tExhTypeArr) {
int intExhTypeID = Int32.Parse(tExhTypeID);
if (hashExhibitorType.ContainsKey(intExhTypeID)) {
Hashtable tRow = (Hashtable)hashExhibitorType[intExhTypeID];
outExhTypeStr += (outExhTypeStr == "") ? "" : "| ";
outExhTypeStr += tRow["NameEn"];
dr[tCol] = outExhTypeStr;
String tStandNoStr = tExhibitor[tCol].ToString();
String outStandNoStr = "";
String[] tStandNoArr = tStandNoStr.Split('|');
foreach (String ttStandNoStr in tStandNoArr) {
String[] ttStandNoArr = ttStandNoStr.Split('~');
dr["Venue"] = ttStandNoArr[0];
dr["Hall"] = ttStandNoArr[1];
dr["StandNo"] = ttStandNoArr[2];
Hashtable tExtraRow = new Hashtable();
tExtraRow["Venue"] = ttStandNoArr[0];
tExtraRow["Hall"] = ttStandNoArr[1];
tExtraRow["StandNo"] = ttStandNoArr[2];
tExtraRow["EMSID"] = tExhibitor["EMSID"];
tExtraRow["ExhibitorNameEn"] = tExhibitor["ExhibitorNameEn"];
hashExtraRows[StandCount] = tExtraRow;
if (hashFieldToCaption.ContainsKey(tCol)) {
dr[hashFieldToCaption[tCol].ToString()] = tExhibitor[tCol].ToString();
dr[tCol] = tExhibitor[tCol].ToString();
if (hashExhProduct.ContainsKey((int)tExhibitor["ExhibitorID"])) {
Hashtable tExh = (Hashtable)hashExhProduct[(int)tExhibitor["ExhibitorID"]];
foreach (int tSequence in tExh.Keys) {
Hashtable tProduct = (Hashtable)tExh[tSequence];
dr["Product" + tSequence + "_NameEn"] = tProduct["NameEn"].ToString();
dr["Product" + tSequence + "_NameCht"] = tProduct["NameCht"].ToString();
dr["Product" + tSequence + "_NameChs"] = tProduct["NameChs"].ToString();
dr["Product" + tSequence + "_DescEn"] = tProduct["DescEn"].ToString();
dr["Product" + tSequence + "_DescCht"] = tProduct["DescCht"].ToString();
dr["Product" + tSequence + "_DescChs"] = tProduct["DescChs"].ToString();
dr["Product" + tSequence + "_PhotoUrl"] = tProduct["PhotoUrl"].ToString();
dr["Product" + tSequence + "_VideoUrl"] = tProduct["VideoUrl"].ToString();
String tCatStr = tProduct["ProductCategory"].ToString();
String[] tCatArr = tCatStr.Split(',');
foreach (String tCatID in tCatArr) {
int intCatID = Int32.Parse(tCatID);
if (hashProductCategory.ContainsKey(intCatID)) {
Hashtable tRow = (Hashtable)hashProductCategory[intCatID];
outCatStr += (outCatStr == "") ? "" : "| ";
outCatStr += tRow["NameEnShort"];
dr["Product" + tSequence + "_ProductCategory"] = outCatStr;
if (hashFair["labProductField" + J].ToString() != "") {
dr["Product" + tSequence + "_" + hashFair["labProductField" + J].ToString()] = tProduct["Field" + J].ToString();
if (hashExtraRows.Count > 0) {
foreach (Hashtable tExtraRow in hashExtraRows.Values) {
DataRow drExtra = dt.NewRow();
foreach (String tKey in tExtraRow.Keys) {
drExtra[tKey] = tExtraRow[tKey];
DataRow dr = dt.NewRow();
DataTable_To_Excel(dt, dtFieldLink, dtFieldDesc, dtFieldType, dtFieldExample, dtFieldWidth, strPath + strFile, inFairID);
outHash["filename"] = strFile;
outHash["path"] = strPath;
private static void DataTable_To_Excel(DataTable dt, string[] dtFieldLink, string[] dtFieldDesc, string[] dtFieldType, string[] dtFieldExample, int[] dtFieldWidth, string pFilePath, int inFairID) {
if (dt != null && dt.Rows.Count > 0)
IWorkbook workbook = null;
ISheet wsCountryMasterList = null;
ISheet wsProductCatMasterList = null;
ISheet wsFieldDesc = null;
using (FileStream stream = new FileStream(pFilePath, FileMode.Create, FileAccess.ReadWrite))
string Ext = System.IO.Path.GetExtension(pFilePath);
HSSFWorkbook workbookH = new HSSFWorkbook();
NPOI.HPSF.DocumentSummaryInformation dsi = NPOI.HPSF.PropertySetFactory.CreateDocumentSummaryInformation();
dsi.Company = "Cutcsa"; dsi.Manager = "Departamento Informatico";
workbookH.DocumentSummaryInformation = dsi;
case ".xlsx": workbook = new XSSFWorkbook(); break;
worksheet = workbook.CreateSheet(dt.TableName);
wsFieldDesc = workbook.CreateSheet("Field Description");
wsCountryMasterList = workbook.CreateSheet("CountryMaster");
wsProductCatMasterList = workbook.CreateSheet("ProductCategoryMaster");
foreach (int tWidth in dtFieldWidth) {
worksheet.SetColumnWidth(colNo, tWidth * 256);
XSSFCellStyle defaultCellStyle = (XSSFCellStyle)workbook.CreateCellStyle();
defaultCellStyle.IsLocked = false;
XSSFCellStyle cs = (XSSFCellStyle)workbook.CreateCellStyle();
cs.FillForegroundColor = 30;
cs.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground;
XSSFFont font1 = (XSSFFont)workbook.CreateFont();
font1.Boldweight = (short)NPOI.SS.UserModel.FontBoldWeight.Bold;
if (dt.Columns.Count > 0)
IRow fila = worksheet.CreateRow(iRow);
foreach (DataColumn columna in dt.Columns)
ICell cell = fila.CreateCell(iCol, CellType.String);
worksheet.SetDefaultColumnStyle(iCol, defaultCellStyle);
cell.SetCellValue(columna.ColumnName);
ICreationHelper createHelper = workbook.GetCreationHelper();
XSSFHyperlink link = (XSSFHyperlink)createHelper.CreateHyperlink(HyperlinkType.Document);
if (dtFieldLink[iCol] != "") {
link.Location = "'Field Description'!" + dtFieldLink[iCol];
String strComment = columna.ColumnName + "\r\n\r\n" + dtFieldDesc[iCol] + "\r\n";
if (dtFieldType[iCol] != "") {
strComment += "\r\nData Type: " + dtFieldType[iCol];
if (dtFieldExample[iCol] != "") {
strComment += "\r\nExample: " + dtFieldExample[iCol];
XSSFDrawing patriarch = (XSSFDrawing)worksheet.CreateDrawingPatriarch();
XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, iCol, 1, iCol + 2, 10);
IComment comment = patriarch.CreateCellComment(anchor);
IRichTextString formattedCellContent = new XSSFRichTextString(strComment);
comment.String = formattedCellContent;
cell.CellComment = comment;
ICellStyle unlockedCellStyle = workbook.CreateCellStyle();
unlockedCellStyle.IsLocked = false;
foreach (DataRow row in dt.Rows)
IRow fila = worksheet.CreateRow(iRow);
foreach (DataColumn column in dt.Columns)
object cellValue = row[iCol];
switch (column.DataType.ToString())
if (cellValue != DBNull.Value)
cell = fila.CreateCell(iCol, CellType.Boolean);
if (Convert.ToBoolean(cellValue)) { cell.SetCellFormula("TRUE()"); }
else { cell.SetCellFormula("FALSE()"); }
if (cellValue != DBNull.Value)
cell = fila.CreateCell(iCol, CellType.String);
cell.SetCellValue(Convert.ToString(cellValue));
if (cellValue != DBNull.Value)
cell = fila.CreateCell(iCol, CellType.Numeric);
cell.SetCellValue(Convert.ToInt32(cellValue));
if (cellValue != DBNull.Value)
cell = fila.CreateCell(iCol, CellType.Numeric);
cell.SetCellValue(Convert.ToInt64(cellValue));
if (cellValue != DBNull.Value)
cell = fila.CreateCell(iCol, CellType.Numeric);
cell.SetCellValue(Convert.ToDouble(cellValue));
if (cellValue != DBNull.Value)
cell = fila.CreateCell(iCol, CellType.Numeric);
cell.SetCellValue(Convert.ToDouble(cellValue));
if (cellValue != DBNull.Value)
cell = fila.CreateCell(iCol, CellType.Numeric);
cell.SetCellValue(Convert.ToDateTime(cellValue));
cell.CellStyle = unlockedCellStyle;
worksheet.CreateFreezePane(0, 1, 0, 1);
String[] dtMasterField = {"Country"};
int[] dtMasterFieldWidth = {40};
IRow tRow = wsCountryMasterList.CreateRow(0);
foreach (String tField in dtMasterField) {
ICell cell = tRow.CreateCell(tCol, CellType.String);
cell.SetCellValue(tField);
foreach (int tFieldWidth in dtMasterFieldWidth) {
wsCountryMasterList.SetColumnWidth(tCol, tFieldWidth * 256);
Hashtable hashCountry = getCountry(new Hashtable());
SortedList sortedCountry = SortHashtable(hashCountry, "ItemOrder", "int");
foreach (Hashtable hashRow in sortedCountry.Values) {
IRow tRow2 = wsCountryMasterList.CreateRow(iRow2);
ICell cell = tRow2.CreateCell(0, CellType.String);
cell.SetCellValue(Convert.ToString(hashRow["NameEn"]));
wsCountryMasterList.CreateFreezePane(0, 1, 0, 1);
String[] dtProductCatMasterField = {"Sequence", "ID", "Code", "Description"};
int[] dtProductCatMasterFieldWidth = {10, 10, 80, 100};
tRow = wsProductCatMasterList.CreateRow(0);
foreach (String tField in dtProductCatMasterField) {
ICell cell = tRow.CreateCell(tCol, CellType.String);
cell.SetCellValue(tField);
foreach (int tFieldWidth in dtProductCatMasterFieldWidth) {
wsProductCatMasterList.SetColumnWidth(tCol, tFieldWidth * 256);
Hashtable outPara = new Hashtable();
outPara["FairID"] = inFairID;
Hashtable hashProductCat = getProductCategory(outPara);
SortedList sortedProductCat = SortHashtable(hashProductCat, "ItemOrder", "int");
foreach (Hashtable hashRow in sortedProductCat.Values) {
IRow tRow3 = wsProductCatMasterList.CreateRow(iRow3);
ICell cell = tRow3.CreateCell(0, CellType.String);
cell.SetCellValue(Convert.ToString(hashRow["ItemOrder"]));
cell = tRow3.CreateCell(1, CellType.String);
cell.SetCellValue(Convert.ToString(hashRow["ProductCategoryID"]));
cell = tRow3.CreateCell(2, CellType.String);
cell.SetCellValue(Convert.ToString(hashRow["NameEnShort"]));
cell = tRow3.CreateCell(3, CellType.String);
cell.SetCellValue(Convert.ToString(hashRow["NameEn"]));
wsProductCatMasterList.CreateFreezePane(0, 1, 0, 1);
String[] dtFieldDescMasterField = {"Field Name", "Description", "Data Type", "Example"};
int[] dtFieldDescMasterFieldWidth = {25, 80, 25, 80};
tRow = wsFieldDesc.CreateRow(0);
foreach (String tField in dtFieldDescMasterField) {
ICell cell = tRow.CreateCell(tCol, CellType.String);
cell.SetCellValue(tField);
foreach (int tFieldWidth in dtFieldDescMasterFieldWidth) {
wsFieldDesc.SetColumnWidth(tCol, tFieldWidth * 256);
for (int J=0; J<=14; J++) {
tRow4 = wsFieldDesc.CreateRow(iRow4);
cell4 = tRow4.CreateCell(0, CellType.String);
cell4.SetCellValue(dt.Columns[J].ColumnName);
cell4 = tRow4.CreateCell(1, CellType.String);
cell4.SetCellValue(dtFieldDesc[J]);
cell4 = tRow4.CreateCell(2, CellType.String);
cell4.SetCellValue(dtFieldType[J]);
cell4 = tRow4.CreateCell(3, CellType.String);
cell4.SetCellValue(dtFieldExample[J]);
tRow4 = wsFieldDesc.CreateRow(iRow4);
for (int J=15; J<=17; J++) {
tRow4 = wsFieldDesc.CreateRow(iRow4);
cell4 = tRow4.CreateCell(0, CellType.String);
cell4.SetCellValue(dt.Columns[J].ColumnName);
cell4 = tRow4.CreateCell(1, CellType.String);
cell4.SetCellValue(dtFieldDesc[J]);
cell4 = tRow4.CreateCell(2, CellType.String);
cell4.SetCellValue(dtFieldType[J]);
cell4 = tRow4.CreateCell(3, CellType.String);
cell4.SetCellValue(dtFieldExample[J]);
tRow4 = wsFieldDesc.CreateRow(iRow4);
tRow4 = wsFieldDesc.CreateRow(iRow4);
cell4 = tRow4.CreateCell(0, CellType.String);
cell4.SetCellValue(dt.Columns[18].ColumnName);
cell4 = tRow4.CreateCell(1, CellType.String);
cell4.SetCellValue(dtFieldDesc[18]);
cell4 = tRow4.CreateCell(2, CellType.String);
cell4.SetCellValue(dtFieldType[18]);
cell4 = tRow4.CreateCell(3, CellType.String);
cell4.SetCellValue(dtFieldExample[18]);
tRow4 = wsFieldDesc.CreateRow(iRow4);
for (int J=19; J<=21; J++) {
tRow4 = wsFieldDesc.CreateRow(iRow4);
cell4 = tRow4.CreateCell(0, CellType.String);
cell4.SetCellValue(dt.Columns[J].ColumnName);
cell4 = tRow4.CreateCell(1, CellType.String);
cell4.SetCellValue(dtFieldDesc[J]);
cell4 = tRow4.CreateCell(2, CellType.String);
cell4.SetCellValue(dtFieldType[J]);
cell4 = tRow4.CreateCell(3, CellType.String);
cell4.SetCellValue(dtFieldExample[J]);
tRow4 = wsFieldDesc.CreateRow(iRow4);
tRow4 = wsFieldDesc.CreateRow(iRow4);
cell4 = tRow4.CreateCell(0, CellType.String);
cell4.SetCellValue(dt.Columns[22].ColumnName);
cell4 = tRow4.CreateCell(1, CellType.String);
cell4.SetCellValue(dtFieldDesc[22]);
cell4 = tRow4.CreateCell(2, CellType.String);
cell4.SetCellValue(dtFieldType[22]);
cell4 = tRow4.CreateCell(3, CellType.String);
cell4.SetCellValue(dtFieldExample[22]);
tRow4 = wsFieldDesc.CreateRow(iRow4);
for (int J=23; J<=26; J++) {
tRow4 = wsFieldDesc.CreateRow(iRow4);
cell4 = tRow4.CreateCell(0, CellType.String);
cell4.SetCellValue(dt.Columns[J].ColumnName);
cell4 = tRow4.CreateCell(1, CellType.String);
cell4.SetCellValue(dtFieldDesc[J]);
cell4 = tRow4.CreateCell(2, CellType.String);
cell4.SetCellValue(dtFieldType[J]);
cell4 = tRow4.CreateCell(3, CellType.String);
cell4.SetCellValue(dtFieldExample[J]);
tRow4 = wsFieldDesc.CreateRow(iRow4);
for (int J=27; J<=28; J++) {
tRow4 = wsFieldDesc.CreateRow(iRow4);
cell4 = tRow4.CreateCell(0, CellType.String);
cell4.SetCellValue(dt.Columns[J].ColumnName);
cell4 = tRow4.CreateCell(1, CellType.String);
cell4.SetCellValue(dtFieldDesc[J]);
cell4 = tRow4.CreateCell(2, CellType.String);
cell4.SetCellValue(dtFieldType[J]);
cell4 = tRow4.CreateCell(3, CellType.String);
cell4.SetCellValue(dtFieldExample[J]);
tRow4 = wsFieldDesc.CreateRow(iRow4);
for (int J=29; J<=30; J++) {
tRow4 = wsFieldDesc.CreateRow(iRow4);
cell4 = tRow4.CreateCell(0, CellType.String);
cell4.SetCellValue(dt.Columns[J].ColumnName);
cell4 = tRow4.CreateCell(1, CellType.String);
cell4.SetCellValue(dtFieldDesc[J]);
cell4 = tRow4.CreateCell(2, CellType.String);
cell4.SetCellValue(dtFieldType[J]);
cell4 = tRow4.CreateCell(3, CellType.String);
cell4.SetCellValue(dtFieldExample[J]);
tRow4 = wsFieldDesc.CreateRow(iRow4);
if (dt.Columns.Count > 31) {
for (int J=31; J < dt.Columns.Count; J++) {
tRow4 = wsFieldDesc.CreateRow(iRow4);
cell4 = tRow4.CreateCell(0, CellType.String);
cell4.SetCellValue(dt.Columns[J].ColumnName);
cell4 = tRow4.CreateCell(1, CellType.String);
cell4.SetCellValue(dtFieldDesc[J]);
cell4 = tRow4.CreateCell(2, CellType.String);
cell4.SetCellValue(dtFieldType[J]);
cell4 = tRow4.CreateCell(3, CellType.String);
cell4.SetCellValue(dtFieldExample[J]);
wsFieldDesc.CreateFreezePane(0, 1, 0, 1);
public static Hashtable addLog(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int fromUserID = CheckUserID();
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
String inActionType = (inPara["ActionType"] != null) ? inPara["ActionType"].ToString() : "";
String inActionPara = (inPara["ActionPara"] != null) ? inPara["ActionPara"].ToString() : "";
String strUserAgent = HttpContext.Current.Request.UserAgent;
strUserAgent = (strUserAgent.Length > 1000) ? strUserAgent.Substring(0,1000) : strUserAgent;
String currMonth = DateTime.Now.ToString("yyMM");
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
int isLogTableExist3 = 0;
String sLogTable = "ActionLog";
string strSQL2 = "SELECT count(*) FROM sys.tables WHERE name = @TableName";
cmd.CommandText = strSQL2;
cmd.Parameters.AddWithValue("@TableName", sLogTable + "_" + currMonth);
isLogTableExist = (int)cmd.ExecuteScalar();
if (isLogTableExist == 0)
strSQL2 = "select * into " + sLogTable + "_" + currMonth + " from " + sLogTable + "_YYMM where 1=0; Alter Table dbo." + sLogTable + "_" + currMonth + " Drop Column rowID; ALTER TABLE dbo." + sLogTable + "_" + currMonth + " ADD rowID INT IDENTITY(1,1); ALTER TABLE dbo." + sLogTable + "_" + currMonth + " ADD CONSTRAINT PK_" + sLogTable + "_" + currMonth + " PRIMARY KEY(rowID); ";
cmd.CommandText = strSQL2;
strSQL = "insert into " + sLogTable + "_" + currMonth + "(UserID,FairID,Action,ActionPara,UserAgent,UserIP,CreateTime) values (@UserID,@FairID,@Action,@ActionPara,@UserAgent,@UserIP,{fn NOW()})";
cmd.CommandText = strSQL;
cmd.Parameters.AddWithValue("@UserID", fromUserID);
cmd.Parameters.AddWithValue("@FairID", inFairID);
cmd.Parameters.AddWithValue("@Action", inActionType);
cmd.Parameters.AddWithValue("@ActionPara", inActionPara);
cmd.Parameters.AddWithValue("@UserAgent", strUserAgent);
cmd.Parameters.AddWithValue("@UserIP", getIP());
cmd.CommandType = CommandType.Text;
int dbLogID = Convert.ToInt32(cmd.ExecuteScalar());
outHash["Err"] = "Err: " + ex.ToString();
public static Hashtable getSearchLogExcel(Hashtable inPara) {
Hashtable outHash = new Hashtable();
int inFairID = (inPara["FairID"] == null || inPara["FairID"].ToString() == "") ? 0 : Int32.Parse(inPara["FairID"].ToString());
outHash["FairID"] = inFairID;
SqlConnection conn = new SqlConnection(SqlConnStr);
SqlCommand cmd = new SqlCommand();
IDataReader rdrBrowsers = null;
cmd = conn.CreateCommand();
Hashtable hashFair = new Hashtable();
Hashtable hashFairLocation = new Hashtable();
Hashtable hashVenue = new Hashtable();
Hashtable hashCountry = new Hashtable();
Hashtable hashProductCat = new Hashtable();
Hashtable hashBusinessNature = new Hashtable();
Hashtable hashExhibitorType = new Hashtable();
Hashtable hashOutData = new Hashtable();
Hashtable outPara = new Hashtable();
outPara = new Hashtable();
outPara["FairID"] = inFairID;
Hashtable hashFairs = getFair(outPara);
foreach (int tFairID in hashFairs.Keys) {
hashFair = (Hashtable)hashFairs[tFairID];
outPara = new Hashtable();
outPara["FairID"] = inFairID;
hashFairLocation = getFairLocation(outPara);
hashCountry = getCountry(new Hashtable());
outPara = new Hashtable();
outPara["FairID"] = inFairID;
hashProductCat = getProductCategory(outPara);
outPara = new Hashtable();
outPara["FairID"] = inFairID;
hashBusinessNature = getBusinessNature(outPara);
outPara = new Hashtable();
outPara["FairID"] = inFairID;
hashExhibitorType = getExhibitorType(outPara);
string strPath = @System.Configuration.ConfigurationManager.AppSettings.Get("PhysicalUploadPath");
String strFile = "ExhListSearchLog_" + hashFair["EMSFairID"] + "_" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + ".xlsx";
String pFilePath = strPath + strFile;
DataTable dt = new DataTable();
dt.TableName = "SearchLog_" + hashFair["EMSFairID"].ToString();
String[] dtField = {"rowID", "Keyword", "dtStart", "dtLength", "ProductCategoryID", "LocationID", "CountryID", "CompanyPrefix", "BusinessNatureID", "ExhibitorTypeID", "VenueID", "isNew", "ExhibitorID", "OtherFilter", "UserIP", "UserAgent", "CreateTime"};
String[] dtFieldCaption = {"rowID", "Keyword", "dtStart", "dtLength", "ProductCategoryID", "LocationID", "CountryID", "CompanyPrefix", "BusinessNatureID", "ExhibitorTypeID", "VenueID", "isNew", "ExhibitorID", "OtherFilter", "UserIP", "UserAgent", "CreateTime"};
int[] dtFieldWidth = {10,30,10,10,100,30,30,10,50,30,30,10,10,100,20,50,50};
foreach (String tCol in dtFieldCaption) {
dt.Columns.Add(tCol, typeof(string));
strSQL = "SELECT * from SearchLog_" + inFairID;
cmd.CommandText = strSQL;
cmd.CommandType = CommandType.Text;
rdrBrowsers = cmd.ExecuteReader();
while (rdrBrowsers.Read()) {
Hashtable hashRow = new Hashtable();
DataRow dr = dt.NewRow();
for (int i = 0; i < rdrBrowsers.FieldCount; i++) {
switch (rdrBrowsers.GetName(i).ToString()) {
String tCountryStr = rdrBrowsers.GetValue(i).ToString();
int tCountryID = (tCountryStr == "") ? 0 : Int32.Parse(tCountryStr);
Hashtable tCountry = (Hashtable)hashCountry[tCountryID];
tValue = tCountry["NameEn"].ToString();
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
dr[rdrBrowsers.GetName(i).ToString()] = tValue;
case "ProductCategoryID":
String tProductCatStr = rdrBrowsers.GetValue(i).ToString();
if (tProductCatStr != "") {
String[] arrProductCat = tProductCatStr.Split(',');
foreach (String ttProductCatStr in arrProductCat) {
int tProductCatID = Int32.Parse(ttProductCatStr);
Hashtable tProductCat = (Hashtable)hashProductCat[tProductCatID];
tValue += (tValue == "") ? "" : ",";
tValue = tProductCat["NameEn"].ToString();
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
dr[rdrBrowsers.GetName(i).ToString()] = tValue;
String tBusinessNatureStr = rdrBrowsers.GetValue(i).ToString();
if (tBusinessNatureStr != "") {
String[] arrBusinessNature = tBusinessNatureStr.Split(',');
foreach (String ttBusinessNatureStr in arrBusinessNature) {
int tBusinessNatureID = Int32.Parse(ttBusinessNatureStr);
Hashtable tBusinessNature = (Hashtable)hashBusinessNature[tBusinessNatureID];
tValue += (tValue == "") ? "" : ",";
tValue = tBusinessNature["NameEn"].ToString();
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
dr[rdrBrowsers.GetName(i).ToString()] = tValue;
String tExhibitorTypeStr = rdrBrowsers.GetValue(i).ToString();
if (tExhibitorTypeStr != "") {
String[] arrExhibitorType = tExhibitorTypeStr.Split(',');
foreach (String ttExhibitorTypeStr in arrExhibitorType) {
int tExhibitorTypeID = Int32.Parse(ttExhibitorTypeStr);
Hashtable tExhibitorType = (Hashtable)hashBusinessNature[tExhibitorTypeID];
tValue += (tValue == "") ? "" : ",";
tValue = tExhibitorType["NameEn"].ToString();
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
dr[rdrBrowsers.GetName(i).ToString()] = tValue;
String tLocationStr = rdrBrowsers.GetValue(i).ToString();
if (tLocationStr != "") {
String[] arrLocation = tLocationStr.Split(',');
foreach (String ttLocationStr in arrLocation) {
int tLocationID = Int32.Parse(ttLocationStr);
Hashtable tLocation = (Hashtable)hashFairLocation[tLocationID];
tValue += (tValue == "") ? "" : ",";
tValue = tLocation["Venue"].ToString() + " " + tLocation["Hall"].ToString();
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
dr[rdrBrowsers.GetName(i).ToString()] = tValue;
DateTime tDate = (!DBNull.Value.Equals(rdrBrowsers.GetValue(i))) ? (DateTime)rdrBrowsers.GetValue(i) : DateTime.MinValue;
tValue = tDate.ToString("yyyy-MM-dd HH:mm:ss");
hashRow[rdrBrowsers.GetName(i).ToString()] = tValue;
dr[rdrBrowsers.GetName(i).ToString()] = tValue;
hashRow[rdrBrowsers.GetName(i).ToString()] = rdrBrowsers.GetValue(i);
dr[rdrBrowsers.GetName(i).ToString()] = rdrBrowsers.GetValue(i);
hashOutData[(int)rdrBrowsers["rowID"]] = hashRow;
if (dt != null && dt.Rows.Count > 0)
IWorkbook workbook = null;
using (FileStream stream = new FileStream(pFilePath, FileMode.Create, FileAccess.ReadWrite))
string Ext = System.IO.Path.GetExtension(pFilePath);
HSSFWorkbook workbookH = new HSSFWorkbook();
NPOI.HPSF.DocumentSummaryInformation dsi = NPOI.HPSF.PropertySetFactory.CreateDocumentSummaryInformation();
dsi.Company = "Cutcsa"; dsi.Manager = "Departamento Informatico";
workbookH.DocumentSummaryInformation = dsi;
case ".xlsx": workbook = new XSSFWorkbook(); break;
worksheet = workbook.CreateSheet(dt.TableName);
foreach (int tWidth in dtFieldWidth) {
worksheet.SetColumnWidth(colNo, tWidth * 256);
XSSFCellStyle defaultCellStyle = (XSSFCellStyle)workbook.CreateCellStyle();
defaultCellStyle.IsLocked = false;
XSSFCellStyle cs = (XSSFCellStyle)workbook.CreateCellStyle();
cs.FillForegroundColor = 30;
cs.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground;
XSSFFont font1 = (XSSFFont)workbook.CreateFont();
font1.Boldweight = (short)NPOI.SS.UserModel.FontBoldWeight.Bold;
if (dt.Columns.Count > 0)
IRow fila = worksheet.CreateRow(iRow);
foreach (DataColumn columna in dt.Columns)
ICell cell = fila.CreateCell(iCol, CellType.String);
worksheet.SetDefaultColumnStyle(iCol, defaultCellStyle);
cell.SetCellValue(columna.ColumnName);
ICreationHelper createHelper = workbook.GetCreationHelper();
XSSFHyperlink link = (XSSFHyperlink)createHelper.CreateHyperlink(HyperlinkType.Document);
ICellStyle unlockedCellStyle = workbook.CreateCellStyle();
unlockedCellStyle.IsLocked = false;
foreach (DataRow row in dt.Rows)
IRow fila = worksheet.CreateRow(iRow);
foreach (DataColumn column in dt.Columns)
object cellValue = row[iCol];
switch (column.DataType.ToString())
if (cellValue != DBNull.Value)
cell = fila.CreateCell(iCol, CellType.Boolean);
if (Convert.ToBoolean(cellValue)) { cell.SetCellFormula("TRUE()"); }
else { cell.SetCellFormula("FALSE()"); }
if (cellValue != DBNull.Value)
cell = fila.CreateCell(iCol, CellType.String);
cell.SetCellValue(Convert.ToString(cellValue));
if (cellValue != DBNull.Value)
cell = fila.CreateCell(iCol, CellType.Numeric);
cell.SetCellValue(Convert.ToInt32(cellValue));
if (cellValue != DBNull.Value)
cell = fila.CreateCell(iCol, CellType.Numeric);
cell.SetCellValue(Convert.ToInt64(cellValue));
if (cellValue != DBNull.Value)
cell = fila.CreateCell(iCol, CellType.Numeric);
cell.SetCellValue(Convert.ToDouble(cellValue));
if (cellValue != DBNull.Value)
cell = fila.CreateCell(iCol, CellType.Numeric);
cell.SetCellValue(Convert.ToDouble(cellValue));
if (cellValue != DBNull.Value)
cell = fila.CreateCell(iCol, CellType.Numeric);
cell.SetCellValue(Convert.ToDateTime(cellValue));
cell.CellStyle = unlockedCellStyle;
worksheet.CreateFreezePane(0, 1, 0, 1);
outHash["filename"] = strFile;
outHash["path"] = strPath;
outHash["filename"] = strFile;
outHash["path"] = strPath;
outHash["Err"] = "Err: " + ex.ToString();
private static Hashtable runDTQuery(Hashtable inPara) {
Hashtable outHash = new Hashtable();
String inSql = (inPara["sql"] != null) ? inPara["sql"].ToString() : "";
String inSqlGroupBy = (inPara["sqlGroupBy"] != null) ? inPara["sqlGroupBy"].ToString() : "";
SqlConnection conn = new SqlConnection(SqlConnStr);
outHash["recordsFiltered"] = 0;
outHash["result"] = new Hashtable();