Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["currentUser"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            else
            {
                User currentUser = (User)Session["currentUser"];

                Boolean superuser = false;
                foreach (String s in currentUser.getRoles())
                {
                    if (s.Equals("superuser"))
                    {
                        superuser = true;
                    }
                }
                if (!superuser)
                {
                    Response.Redirect("errorPage.aspx");
                }
                else
                {
                    if (!IsPostBack)
                    {
                        ChatBotInitializeMsgDAO cbimDAO = new ChatBotInitializeMsgDAO();
                        int messageID = Convert.ToInt32(Request.QueryString["id"]);
                        ChatBotInitializeMsg currentMessage = cbimDAO.getChatBotInitializeMsgByID(messageID);
                        txtMsgInput.Text = currentMessage.message;
                    }
                }
            }
        }
        public ChatBotInitializeMsg getChatBotInitializeMsgByID(int messageID)
        {
            SqlConnection        conn     = new SqlConnection();
            ChatBotInitializeMsg toReturn = new ChatBotInitializeMsg();

            try
            {
                conn = new SqlConnection();
                string connstr = ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString();
                conn.ConnectionString = connstr;
                conn.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection  = conn;
                comm.CommandText = "select * from [ChatBotInitialization] where messageID=@messageID";
                comm.Parameters.AddWithValue("@messageID", messageID);
                SqlDataReader dr = comm.ExecuteReader();
                while (dr.Read())
                {
                    toReturn.messageID = (int)dr["messageID"];
                    toReturn.message   = (string)dr["message"];
                    toReturn.levels    = (int)dr["levels"];
                }
                dr.Close();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return(toReturn);
        }