using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TopWinCMS.BLL;
using TopWinCMS.Common;
using TopWinCMS.Model;
namespace TopWinCMS.WebUI.Member
{
    public partial class Message : TopWinCMS.BLL.PageFactory.Pages.ClientPublicPage
    {
        SQLModel s_model = new SQLModel();
        string Action = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = Config.SiteName + "→ 会员中心 → 短信管理";
            Action = Request["Action"];
            if (MemberRightsCheck.IsLogined == false)
            {
                MsgBox.Alert("登录超时，请重新登录。", "Login.aspx");
            }
            if (!IsPostBack)
            {
                Bind();
            }
        }
        private void Bind()
        {
            string Action = Request["Action"];
            if (string.IsNullOrEmpty(Action) == true || Action == "Inbox")//收件箱
            {
                LB_Path.Text = "收件箱";
                s_model.WHERE = " Incept='" + MemberLoginInfo.UserName + "'";
                new MessageManage().BindList(GV_List, PageNavigation1, s_model);
                if (GV_List.Rows.Count <= 0)
                {
                    LB_NoShow.Text = "<img src='/Images/NoData.gif'><br/>";
                }
                else
                {
                    LB_NoShow.Visible = false;
                }
            }
            else if (Action == "Outbox")//发件箱
            {

                LB_Path.Text = "发件箱";
                s_model.WHERE = " Sender='" + MemberLoginInfo.UserName + "'";
                new MessageManage().BindList(GV_List, PageNavigation1, s_model);
                if (GV_List.Rows.Count <= 0)
                {
                    LB_NoShow.Text = "<img src='/Images/NoData.gif'><br/>";
                }
                else
                {
                    LB_NoShow.Visible = false;
                }
            }
            else if (Action == "Trash")//废件箱
            {
                LB_Path.Text = "废件箱";
                s_model.WHERE = " Incept='" + MemberLoginInfo.UserName + "' and DelSend=1";
                new MessageManage().BindList(GV_List, PageNavigation1, s_model);
                if (GV_List.Rows.Count <= 0)
                {
                    LB_NoShow.Text = "<img src='/Images/NoData.gif'><br/>";
                }
                else
                {
                    LB_NoShow.Visible = false;
                }

            }

        }
        protected void GV_List_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                TableCell myTableCell = e.Row.Cells[4];//回复
                HyperLink hl = myTableCell.Controls[0] as HyperLink;
                if (Action == "Outbox")//发件箱
                {
                    hl.Enabled = false;
                }


                myTableCell = e.Row.Cells[5];//删除

                LinkButton btn = myTableCell.Controls[0] as LinkButton;
                if (Action == "Outbox")//发件箱
                {
                    btn.Enabled = false;
                }
                else
                {
                    btn.Attributes.Add("onclick", "return confirm('您确定要删除？');");
                }
            }
        }

        protected void PageNavigation1_PageChanging(object src, TopWinCMS.WebControls.PageChangingEventArgs e)
        {
            s_model.PageNo = e.NewPageIndex;
            Bind();
        }

        protected void GV_List_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

            string ID = GV_List.DataKeys[e.RowIndex].Value.ToString();

            if (Action == "Trash")
            {
                new MessageManage().Delete(ID, UpdatePanel1);
            }
            else
            {
                new MessageManage().LogicDeleteOrRestoration(ID, UpdatePanel1);
            }

            Bind();
        }
    }
}