示例#1
0
    protected void MailGrid_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
    {
        if (string.IsNullOrEmpty(e.Parameters))
        {
            return;
        }
        var args = e.Parameters.Split('|');

        if (args[0] == "FolderChanged")
        {
            MailGrid.FilterExpression = "";
            BindGrid();
            MailGrid.ExpandAll();
        }
        if (args[0] == "Search")
        {
            if (string.IsNullOrEmpty(SearchText))
            {
                MailGrid.FilterExpression = "";
            }
            CriteriaOperator criteria = new GroupOperator(GroupOperatorType.Or,
                                                          new FunctionOperator(FunctionOperatorType.Contains, new OperandProperty(ShowToColumn() ? "To" : "From"), SearchText),
                                                          new FunctionOperator(FunctionOperatorType.Contains, new OperandProperty("Subject"), SearchText)
                                                          );
            MailGrid.FilterExpression = criteria.ToString();

            BindGrid();
            MailGrid.ExpandAll();
        }
        if (args[0] == "SendMail" || args[0] == "SaveMail")
        {
            var    subject     = SubjectEditor.Text;
            var    to          = ToEditor.Text;
            string messageText = MailEditor.Html.Length <= 10000 ? MailEditor.Html : MailEditor.Html.Substring(0, 10000);
            string folder      = args[0] == "SendMail" ? "Sent Items" : "Drafts";
            int    id;
            if (args.Length == 2 && int.TryParse(args[1], out id))
            {
                MessageBL bl = new MessageBL();
                bl.UpdateMessage(id, subject, to, messageText, folder);
            }
            else
            {
                MessageBL bl      = new MessageBL();
                bool      IsReply = false;
                if (Session["CurrentReplyEmailID"] != null)
                {
                    IsReply = true;
                }
                bl.AddMessage(subject, User.Identity.Name, to, messageText, folder, IsReply);
            }

            Session["CurrentReplyEmailID"] = null;
            BindGrid();
        }
        if (args[0] == "Delete" && args.Length > 1)
        {
            int[] keys = null;
            if (!TryParseKeyValues(args.Skip(1), out keys))
            {
                return;
            }

            MessageBL bl = new MessageBL();

            bl.DeleteMessages(keys);
            BindGrid();
        }
    }