public bool checkRegKey(string regKey, string deviceId)
        {
            string    sql     = "select regkey from device where regkey= '" + regKey + "' and device_id = '" + deviceId + "'";
            RadDBImpl _dbImpl = new RadDBImpl();
            bool      val     = false;

            using (IDataReader reader = _dbImpl.GetDataReader(sql))
            {
                try
                {
                    if (reader.Read())
                    {
                        val = true;
                    }
                    else
                    {
                        val = false;
                    }
                }
                catch
                { }
                finally
                {
                    reader.Close();
                }
            }
            return(val);
        }
        public bool checkUserExists(string userId)
        {
            bool      val     = false;
            RadDBImpl _dbImpl = new RadDBImpl();
            string    sql     = "select userId from users where userid = '" + userId.ToUpper() + "'";

            using (IDataReader reader = _dbImpl.GetDataReader(sql))
            {
                try
                {
                    if (reader.Read())
                    {
                        val = true;
                    }
                    else
                    {
                        val = false;
                    }
                }
                catch
                { }
                finally
                {
                    reader.Close();
                }
            }
            return(val);
        }
        public bool isUserActive(string userId)
        {
            RadDBImpl _dbImpl = new RadDBImpl();
            bool      val     = false;
            string    sql     = "select userId from users where userid = '" + userId.ToUpper() + "' and ACTIVE = 'Y'";

            using (IDataReader reader = _dbImpl.GetDataReader(sql))
            {
                try
                {
                    if (reader.Read())
                    {
                        val = true;
                    }
                    else
                    {
                        val = false;
                    }
                }
                catch
                { }
                finally
                {
                    reader.Close();
                }
            }
            return(val);
        }
        public string checkDeviceExists(string deviceId)
        {
            RadDBImpl _dbImpl = new RadDBImpl();

            string val = "false";

            if (string.IsNullOrEmpty(deviceId))
            {
                return("false");
            }
            else
            {
                string      sql = "select device_id from device where device_id = '" + deviceId + "'";
                IDataReader rd  = _dbImpl.GetDataReader(sql);
                try
                {
                    if (rd.Read())
                    {
                        val = "true";
                    }
                    else
                    {
                        val = "false";
                    }
                }
                catch { }
                finally { rd.Close(); }
            }

            return(val);
        }
        public byte[] getImageByteArray(string deviceId)
        {
            string sql = "select dt,IMAGE_NAME from image where device_id = '" + deviceId + "' order by dt desc";

            byte[]    byteArray = null;
            RadDBImpl _dbImpl   = new RadDBImpl();

            using (IDataReader reader = _dbImpl.GetDataReader(sql))
            {
                try
                {
                    while (reader.Read())
                    {
                        byteArray = (Byte[])reader["IMAGE_NAME"];
                    }
                }
                catch
                { }
                finally
                {
                    reader.Close();
                }
            }

            return(byteArray);
        }
        public string GetUserId(string deviceId)
        {
            string    returnVal = string.Empty;
            RadDBImpl _dbImpl   = new RadDBImpl();
            string    sql       = "select userId from device_users where device_id = '" + deviceId + "' and active = 'Y'";

            if (string.IsNullOrEmpty(deviceId))
            {
                return(string.Empty);
            }
            using (IDataReader reader = _dbImpl.GetDataReader(sql))
            {
                try
                {
                    while (reader.Read())
                    {
                        returnVal = reader["userId"].ToString();
                    }
                }
                catch
                { }
                finally
                {
                    reader.Close();
                }
            }


            return(returnVal);
        }
        public string GetRegistrationKey(string deviceId)
        {
            string    returnVal = string.Empty;
            RadDBImpl _dbImpl   = new RadDBImpl();
            string    sql       = "select REGKEY from DEVICE where device_id = '" + deviceId + "'";

            if (string.IsNullOrEmpty(deviceId))
            {
                return(string.Empty);
            }
            using (IDataReader reader = _dbImpl.GetDataReader(sql))
            {
                try
                {
                    while (reader.Read())
                    {
                        returnVal = reader["REGKEY"].ToString();
                    }
                }
                catch
                { }
                finally
                {
                    reader.Close();
                }
            }

            return(returnVal);
        }
        public string GetDeviceId(string userId)
        {
            RadDBImpl _dbImpl   = new RadDBImpl();
            string    returnVal = string.Empty;
            string    sql       = "select device_id from DEVICE_USERS where userId = '" + userId + "' AND ACTIVE = 'Y' ";

            if (string.IsNullOrEmpty(userId))
            {
                return(string.Empty);
            }

            using (IDataReader reader = _dbImpl.GetDataReader(sql))
            {
                try
                {
                    while (reader.Read())
                    {
                        returnVal = reader["device_id"].ToString();
                    }
                }
                catch
                { }
                finally
                {
                    reader.Close();
                }
            }
            return(returnVal);
        }
        public bool checkUser(string UserId, string password)
        {
            RadDBImpl _dbImpl = new RadDBImpl();
            bool      val     = false;
            string    sql     = "select USERID from users where USERID = '" + UserId.ToUpper() + "' and PASSWORD = '******' AND ACTIVE = 'Y' ";

            if (string.IsNullOrEmpty(UserId) || string.IsNullOrEmpty(password))
            {
                return(false);
            }
            using (IDataReader reader = _dbImpl.GetDataReader(sql))
            {
                try
                {
                    if (reader.Read())
                    {
                        val = true;
                    }
                    else
                    {
                        val = false;
                    }
                }
                catch
                { }
                finally
                {
                    reader.Close();
                }
            }
            Logging.WriteMessage("Check User" + UserId.ToUpper() + " - " + val);

            return(val);
        }
        public bool CheckUser(string UserId, string password)
        {
            RadDBImpl _dbImpl = new RadDBImpl();
            DataTable dt      = new DataTable();

            dt.Columns.Add("check", typeof(string));
            DataRow dr  = dt.NewRow();
            bool    val = false;
            string  sql = "select USER_ID from LKP_USERS where USER_ID = '" + UserId.ToUpper() + "' and PASSWORD = '******'";

            if (string.IsNullOrEmpty(UserId) || string.IsNullOrEmpty(password))
            {
                //dr["check"] = "false";
                //dt.Rows.Add(dr);
                return(val);
            }
            using (IDataReader reader = _dbImpl.GetDataReader(sql))
            {
                try
                {
                    if (reader.Read())
                    {
                        //dr["check"] = "true";
                        //dt.Rows.Add(dr);
                        val = true;
                    }
                    else
                    {
                        //dr["check"] = "false";
                        //dt.Rows.Add(dr);
                        val = false;
                    }
                }
                catch
                { }
                finally
                {
                    reader.Close();
                }
            }
            //Logging.WriteMessage("Check User" + UserId.ToUpper() + " - " + val);

            //return GetJson(dt);
            return(val);
        }