<%@ Control Language="C#" %>
<%@ Import Namespace="Kesion.Cache" %>
<%@ Import Namespace="Kesion.Publics" %>
<%@ Import Namespace="Kesion.BLL" %>
<%@ Import Namespace="Kesion.Config" %>
<%@ Import Namespace="Kesion.Components" %>
<%@ Import Namespace="Kesion.HtmlTags" %>
<%@ Import Namespace="System.Data" %>
<script runat="server" type="text/C#">
    dynamic __user = HttpContext.Current.Items["user"];                //初始化用户信息，
    bool isLoadPage = true;  //定义页面是否加载

    private string action = string.Empty;
    private int Id = 0;

    int recordcount, pagecount;
    int CurrPage = new BasicField().GetCurrPage;
    int PageSize = 10;

    protected void Page_Load(object sender, EventArgs e)
    {
        action = KSCMS.S("action");
        if (string.IsNullOrEmpty(action))
        {
            action = KSCMS.S("do");
        }
        Id = Utils.StrToInt(BasicField.GetParam("id"));

        action = action.ToLower();
        switch (action)
        {
            case "delete":
                isLoadPage = false;
                DoDelete();
                break;

        }



    }
    protected void DoDelete()
    {
        if (KSCMS.S("ids") != "")
        {
           if (KSCMS.S("ids") != "")
            {
                string ids = KSCMS.S("ids").Replace(" ","");
                string[] ids_arr = ids.Split(',');
                Hashtable param = new Hashtable();
                foreach (string id in ids_arr)
                {
                    param.Add("id", id);
                    param.Add("fromusername", __user.UserName);
                    CommonData.Delete("[KS_Message]", param);
                    param.Clear();
                }
            }
        }
        Msg.Alert("恭喜，删除成功!", KSCMS.S("flag")=="message"?BasicField.GetUserUrl("message/sentmessage"):KSCMS.GetComeUrl());
    }

    public string GetMsgStatus(int ReadTF)
    {
        if (ReadTF == 0)
            return "<font color=red>未读</font>";
        else if (ReadTF == 1)
            return "<font color=#999999>已读</font>";
        else
            return "<font color=#cccccc>已回复</font>";

    }


</script>

<%
    if (!isLoadPage) return;
%>

<div class="r_tybox nomar t_tybox">
    <div class="r_title tytitle pd0">
     <h4 class="ty-none">站内信息</h4> 

      <div class="tabs">  
          <ul>
              <%
                  Response.Write(@"<li class=""puton""><a href=""" + BasicField.GetUserUrl("message/Receivedmessage") + @""">站内消息</a></li>");
                  Response.Write(@"<li><a href=""" + BasicField.GetUserUrl("other/mychatinfo") + @""">我的咨询</a></li>");
                  Response.Write(@"<li><a href=""" + BasicField.GetUserUrl("other/comment") + @""">我的评价</a></li>");
                  if (CommonJsonCache.CheckYunAPPHasAllow("plus.ask"))
                  {
                      Response.Write(@"<li><a href=""" + BasicField.GetUserUrl("other/MyAsk") + @""">问题互动</a></li>");
                  }
                  if (BaseFun.CheckModulePower("edu"))
                  {
                      Response.Write(@"<li><a href=""" + BasicField.GetUserUrl("Course/MyCosZan", "optype") + @""">我的点赞</a></li>");
                      Response.Write(@" <li><a href=""" + BasicField.GetUserUrl("Course/MyInteractRecord") + @""">互动礼物</a></li>");
                  }
                 %>
          </ul>
        </div>    
    </div> 

     <div class="top-sort clearfix">
        <div class="top-sort-tab">
             <ul>
                <li><a href="<%=BasicField.GetUserUrl("message/receivedmessage") %>">我收到的消息</a></li>
                <li class="puton"><a href="<%=BasicField.GetUserUrl("message/sentmessage") %>">我发出的消息</a></li>
                <li><a href="<%=BasicField.GetUserUrl("message/Garbagemessage") %>">垃圾消息</a></li>
                <li><a href="<%=BasicField.GetUserUrl("message/Sendmessage") %>">发送短消息</a></li>
            </ul>           
        </div>

     </div>
    
  <%
      if (string.IsNullOrEmpty(action))
      {
          Kesion.APPCode.EditorAPI.EchoHead();

          StringBuilder sb = new StringBuilder();
          using (DataTable dt = DataFactory.GetPage("id,MsgTitle,ToUserName,MsgContactMan,MsgTel,AddDate,ReadTf", "[KS_Message] where DelTF=0 and FromUserName='"+Utils.ChkSQL((new TemporaryVar()).UserName)+"'", "id", "order by id desc",  CurrPage, PageSize, out recordcount, out pagecount))
          {
              if (dt.Rows.Count > 0)
              {
                  foreach (DataRow dr in dt.Rows)
                  {
                      sb.AppendLine(@" <tr class=""tdbg"">
          <td class=""splittd"" align=""center""><input type=""checkbox"" name=""ids"" value=""" + dr["ID"].ToString() + @""" /></td>
          <td class=""splittd"" align=""center"">" +
                      GetMsgStatus(Convert.ToInt16(dr["ReadTF"].ToString())) + @"
          </td>
          <td class=""splittd""><a href=""" + BasicField.GetUserUrl("message/sentmessage", "Action-Show,ID-" + dr["ID"].ToString()) + @""">" + dr["MsgTitle"].ToString() + @"</a>
          <br /><span style=""color:#999"">" + Utils.FormatHumanizedTime(Convert.ToDateTime(dr["AddDate"].ToString())) + @"</span>
          </td> 
          <td class=""splittd"" style=""text-align:center"">" +
                      dr["ToUserName"].ToString() + @"
          </td>
         
      </tr> ");

                  }

              }
              else
              {

                  sb.Append(@" <tr class=""tr-nobor"">
                <td class=""splittd"" colspan=""4"">
                  <div class=""empty"">没有发出消息！</div>
                </td>
              </tr><style>.cz_btn{display:none;}</style>");

              }
          }
    %>
   
    <form name="myform" action="{$GetCurrUrl}" method="post" id="myform">
      	<input type="hidden" name="action" id="action" value="delete"/>
      	<table id="tablist" width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
          <tr align="center" class="title">
            	<td width="30" align="center">选择</td>
    	        <td align="center" width="70">状态</td>
            	<td align="center">标题</td>
              	<td align="center" width="150">发给</td>
          </tr>
          <%=sb.ToString() %>
      	</table>
      	<div class="fy_box">
          <%
          #region 分页
           string PageStr=__user.GroupID==3||__user.GroupID==4?"[KS:PageStr1]": "[KS:PageStr2]";
          BasicField.ReplaceFilterPage(ref PageStr, CurrPage, PageSize, pagecount, recordcount);
          KSCMS.W(PageStr);
          #endregion
           %>
      	</div>
      	<div class="cz_btn">
            <span class="check-all"><input type="checkbox" name="chkall" class="checkbtn" id="chkall" onclick="CheckAll(this.form);"/>全选</span>
            <span><input type="submit" ID="ButtonDel" class="green-bt button" value="永久删除" onmousedown="return(GetIDS());" onclick="return (setAction('delete', '永久删除'))"/></span>
      	</div>
	  	<div class="clearfix"></div>
		<script>
            function setAction(a,t) {
                $("#action").val(a);
                return (confirm('确定将选中的消息' + t + '吗?'));
            }
        </script>
	</form>

<%}
    else if (action == "show")
    {

        using (DataTable dt = DataFactory.GetDataTable("select top 1 * From KS_Message Where ID=" + Id+ " and FromUserName='" + __user.UserName + "'"))
        {
            if (dt.Rows.Count <= 0)
            {
                Msg.Alert("找不到记录！", KSCMS.GetComeUrl());
                return;
            }
            else
            {
                DataRow dr = dt.Rows[0];

         %>

    <table width="100%" border="0" align="center" class="border" cellpadding="0" cellspacing="0">
      <tr class="title">
        <td>我发出的消息</td>
      </tr>
    </table>

    
<table width="98%" align="center" border="0" cellspacing="0" cellpadding="5" class="border">
  <tr class="tdbg">
    <td class="splittd" style="word-break:break-all;text-align:left;">
        <div style="border: 1px solid #fdf0d9;margin-bottom:20px;line-height: 30px;padding: 5px 15px;background: #fffcf5;border-radius:3px;">
            <b>主题：</b><%= dr["MsgTitle"].ToString() %><br />
            <b>发给：</b><%=dr["ToUserName"].ToString() %><br />
            <strong>时间：</strong><%=dr["AddDate"].ToString() %>
        </div>
        <%= Utils.HtmlDecode(dr["MsgContent"].ToString()) %>
        
      </td>
  </tr>
</table>
 <div style="margin-top:20px;text-align:center">
 	<div class="cz_btn">
       	<form name="myform" action="{$GetCurrUrl}" method="post" id="myform">
            <input type="hidden" name="action" id="action" value="delete"/>
            <input type="hidden" name="ids" value="<%=Id %>"/>
            <input type="hidden" name="flag" value="message"/>
            <span><input type="submit" ID="ButtonDel" class="grey-bt d-inline-block button" value="永久删除"  onclick="return (setAction('delete', '永久删除'))"/></span>
            <span><input type="button" class="grey-bt d-inline-block button" value=" 返 回 " onclick="history.back()" /></span>
       	</form>
        <script>
			function setAction(a,t) {
				$("#action").val(a);
				return (confirm('确定将选中的消息' + t + '吗?'));
			}
		</script>
    </div>
    <div class="clearfix"></div>         
 </div>




<%}
        }
    }

    %>
    

    </div>