示例#1
0
    protected void InitJs()
    {
        Button AddMessageButton  = (Button)AddMessageLoginView.FindControl("AddMessageButton");
        Button EditMessageButton = (Button)AddMessageLoginView.FindControl("EditMessageButton");
        Button CancelEditButton  = (Button)AddMessageLoginView.FindControl("CancelEdit");

        try
        {
            string EditMessageID = AddMessageLoginView.FindControl("EditMessageDiv").ClientID.ToString();
            string AddMessageID  = AddMessageLoginView.FindControl("AddMessageDiv").ClientID.ToString();

            if (CancelEditButton != null)
            {
                CancelEditButton.OnClientClick = "return CancelEdit('" + EditMessageID + "','" + AddMessageID + "')";
            }
        }
        catch (Exception ex) { }

        /*
         * if (AddMessageButton != null)
         *  AddMessageButton.OnClientClick = "Encode(" + AddMessageLoginView.FindControl("MessageTB").ClientID.ToString() + ")";
         * if (EditMessageButton != null)
         *  EditMessageButton.OnClientClick = "return Encode(" + AddMessageLoginView.FindControl("EditMessageTB").ClientID.ToString() + ")";
         */
    }
示例#2
0
    protected void MessageListView_ItemBound(object sender, ListViewItemEventArgs e)
    {
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            LoginView   QuoteLoginView      = (LoginView)e.Item.FindControl("QuoteLoginView");
            Button      EditMessageButton   = (Button)e.Item.FindControl("EditMessageButton");
            Button      DeleteMessageButton = (Button)e.Item.FindControl("DeleteMessageButton");
            Label       SignatureLabel      = (Label)e.Item.FindControl("MessageSignature");
            HiddenField ItemContentHF       = (HiddenField)e.Item.FindControl("ItemContentHF");
            Control     AuthorDiv           = e.Item.FindControl("MessageAuthor");

            var    dataItem     = e.Item.DataItem;
            string ItemId       = Guid.Parse(DataBinder.Eval(dataItem, "Id").ToString()).ToString();
            string ItemUserName = DataBinder.Eval(dataItem, "UserName").ToString();
            string ItemContent  = DataBinder.Eval(dataItem, "Description").ToString();

            bool ItemIsAuthor    = DataBinder.Eval(dataItem, "Editable").ToString() == "Author";
            bool ItemIsModerator = false;
            try
            {
                string username = Membership.GetUser().UserName;
                ItemIsModerator = Roles.IsUserInRole(username, "Moderator");
            }
            catch (Exception ex) { }

            if (EditMessageButton != null)
            {
                try
                {
                    string EditDiv = AddMessageLoginView.FindControl("EditMessageDiv").ClientID.ToString();
                    string EditTB  = AddMessageLoginView.FindControl("EditMessageTB").ClientID.ToString();
                    string EditID  = AddMessageLoginView.FindControl("EditMessageID").ClientID.ToString();
                    string AddDiv  = AddMessageLoginView.FindControl("AddMessageDiv").ClientID.ToString();

                    EditMessageButton.OnClientClick = "return ShowEdit('" + EditDiv + "','" + EditID + "','" + ItemId + "','" + EditTB + "','" + ItemContent + "','" + AddDiv + "')";
                }
                catch (Exception ex) { }
            }
            if (DeleteMessageButton != null)
            {
                DeleteMessageButton.CommandArgument = ItemId;
            }
            if (AuthorDiv != null)
            {
                AuthorDiv.Visible = ItemIsAuthor || ItemIsModerator;
            }
            if (SignatureLabel != null)
            {
                SignatureLabel.Text = Profile.GetProfile(ItemUserName).Semnatura.ToString();
            }
            if (ItemContentHF != null)
            {
                ItemContentHF.Value = ItemContent;
            }
            SetLoginViewActions(QuoteLoginView);
        }
    }
示例#3
0
    protected void QuoteMessage(object source, ListViewCommandEventArgs e)
    {
        Button  b = (Button)e.CommandSource;
        Literal QuoteMessageDescription = (Literal)b.Parent.FindControl("QuoteMessageDescription");
        TextBox MessageTB = (TextBox)AddMessageLoginView.FindControl("MessageTB");

        if (MessageTB == null || QuoteMessageDescription == null)
        {
            return;
        }
        MessageTB.Text += "[quote]" + QuoteMessageDescription.Text + "[/quote]";
    }
示例#4
0
    protected void EditMessage(object source, EventArgs e)
    {
        HiddenField h = (HiddenField)AddMessageLoginView.FindControl("EditMessageID");
        TextBox     t = (TextBox)AddMessageLoginView.FindControl("EditMessageTB");
        Literal     EditMessageResponse = (Literal)AddMessageLoginView.FindControl("EditMessageResponse");


        if (t == null)
        {
            return;
        }

        string sub_id      = Session["sub_id"].ToString();
        string m_id        = Guid.Parse(h.Value.ToString()).ToString();
        string description = t.Text;

        try
        {
            SqlConnection connection = new SqlConnection();
            connection.ConnectionString = MessageSqlDataSource.ConnectionString;
            connection.Open();

            String     cmd     = "UPDATE [Message] SET [Description] = @Description, [LastUpdate] = @LastUpdate WHERE [Id] = @Id";
            SqlCommand command = new SqlCommand(cmd, connection);
            command.Parameters.AddWithValue("Description", description);
            command.Parameters.AddWithValue("LastUpdate", DateTime.Now);
            command.Parameters.AddWithValue("Id", m_id);

            try
            {
                command.ExecuteNonQuery();
                Response.Redirect("~/Subject.aspx?sub_id=" + sub_id);
            }
            catch (SqlException sqex)
            {
                EditMessageResponse.Text = sqex.Message;
            }

            connection.Close();
        }
        catch (Exception ex)
        {
            EditMessageResponse.Text = ex.Message;
        }
    }
示例#5
0
    protected void AddMessage(object sender, EventArgs e)
    {
        string  sub_id             = Session["sub_id"].ToString();
        string  author_id          = Membership.GetUser().ProviderUserKey.ToString();
        TextBox MessageTB          = (TextBox)AddMessageLoginView.FindControl("MessageTB");
        Literal AddMessageResponse = (Literal)AddMessageLoginView.FindControl("AddMessageResponse");
        string  message            = MessageTB.Text;

        try
        {
            SqlConnection connection = new SqlConnection();
            connection.ConnectionString = MessageSqlDataSource.ConnectionString;
            connection.Open();

            String cmd = "INSERT INTO [Message] ([AuthorId], [IdPicture], [Description], [Date], [LastUpdate])"
                         + "VALUES (@AuthorId, @IdPicture, @Description, @Date, @LastUpdate)";
            SqlCommand command = new SqlCommand(cmd, connection);


            command.Parameters.AddWithValue("AuthorId", author_id);
            command.Parameters.AddWithValue("IdPicture", sub_id);
            command.Parameters.AddWithValue("Description", message);
            command.Parameters.AddWithValue("Date", DateTime.Now);
            command.Parameters.AddWithValue("LastUpdate", DateTime.Now);

            try
            {
                command.ExecuteNonQuery();
                Response.Redirect("~/Subject.aspx?sub_id=" + sub_id);
            }
            catch (SqlException sqex)
            {
                AddMessageResponse.Text = sqex.Message;
            }

            connection.Close();
        }
        catch (Exception ex)
        {
            AddMessageResponse.Text = ex.Message;
        }
    }