<%@ Page language="c#" Inherits="Discuz.ForumPage.Admin.smilegrid" Codebehind="forum_smilegrid.aspx.cs" %>
<%@ Register TagPrefix="cc1" Namespace="Discuz.Control" Assembly="Discuz.Control" %>
<%@ Import NameSpace="Discuz.Common"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
	<head>
		<title>论坛图标文件列表</title>		
	    <link href="../styles/datagrid.css" type="text/css" rel="stylesheet" />		
		<script language="javascript" src="../js/common.js"></script>
		<link href="../styles/dntmanager.css" type="text/css" rel="stylesheet" />  
		<script type="text/javascript">
		function validate()
		{
		    var str = ",<%=ViewState["code"]%>";
			var count = 2;
			while(true)
			{
				if(	document.getElementById("id" + count) != null)
				{
					for(var i = count - 1; i >= 1; i--)
					{
						if(!document.getElementById("id" + i).checked) continue;
						if(!document.getElementById("id" + count).checked) continue;
						if(document.getElementById("code" + i).value == document.getElementById("code" + count).value)
						{
							Message("第" + i + "行的代码名称与第" + count + "行相同");
							return false;
						}
					}
					count++;
				}
				else
					break;
			}
			for(var i = 1;;i++)
			{
				if(document.getElementById("id" + i) == null)
				{
					Message("没有要提交的数据!");
					return false;
				}
				if(document.getElementById("id" + i).checked) break;
			}
			for(var i = 1;; i++)
			{
				if(document.getElementById("id" + i) == null)
					return true;
				else
				{
					if(document.getElementById("code" + i).value == "")
					{
						Message("第" + i + "行的代码名称为空！");
						document.getElementById("code" + i).focus();
						return;
					}
					if(document.getElementById("id" + i).checked)
					{
						if(str.indexOf("," + document.getElementById("code" + i).value + ",") >= 0)
						{
							Message("第" + i + "行的代码名称与原有的代码名称相同");
							return false;
						}
						if(isNaNEx(document.getElementById("order" + i).value))
						{
							Message("第" + i + "行为非零数字");
							return false;
						}
					}
				}
			}
		}
		
		function Message(m)
		{
			document.getElementById("success").style.display = 'none';
			document.getElementById("SubmitButton").disabled = false;
			alert(m);
		}
		
		function isNaNEx(str)
		{
			return !(/^\d+$/.test(str));
		}
		
		function CheckSelect(form)
		{
			for (var i=0;i<form.elements.length;i++)
			{
				var e = form.elements[i];
				if (e.name != 'chkall' && e.name =='id')
				e.checked = form.chkall.checked;
			}
		}
		
		function checkFileList(form)
		{
			var i = 1;
			while(true)
			{
				if(form.elements["id" + i] == null)
					break;
				form.elements["id" + i].checked = form.cfile.checked;
				i++;
			}
		}
	</script>
</head>

	<body>
		<form id="Form1" method="post" runat="server"><br>
		<script language="javascript">showhint(0, '显示顺序须为整数, 代码和文件名最大长度将为30. ');</script>
		<table cellspacing="1" cellpadding="4" width="100%" align="center" class="table1" style="margin: 0px;">
				<TBODY>
					<tr>
						<td class="category"><input title="选中/取消选中 本页所有Case" onclick="CheckSelect(this.form)" type="checkbox" name="chkall" id="chkall">全选/取消全选 &nbsp; 
							<cc1:Button id="DelRec" runat="server" Text=" 删 除 " ButtonImgUrl="../images/del.gif"></cc1:Button>  &nbsp; 
								<button type="button" class="Managerbutton" onclick="javascript:window.location.href='forum_addsmile.aspx?typeid=<%=DNTRequest.GetInt("typeid",0)%>';"><img src="../images/add.gif" /> 添加表情</button></span>
				                <cc1:Button id="EditSmile" runat="server" Text=" 编辑提交 "></cc1:Button>
							</TD></TR></TBODY></TABLE>
		<cc1:datagrid id="smilesgrid" runat="server" OnCancelCommand="DataGrid_Cancel" OnEditCommand="DataGrid_Edit"
				OnPageIndexChanged="DataGrid_PageIndexChanged" OnSortCommand="Sort_Grid" OnUpdateCommand="DataGrid_Update"
				OnDeleteCommand="DataGrid_Delete" IsFixConlumnControls="true" pagesize="10">
				<Columns>
				
				    <asp:TemplateColumn HeaderText="" Visible="true"><headerstyle width="10%"/><ItemStyle width="50px"/>
						<ItemTemplate>
							<INPUT id="id" onclick="javascript:SH_SelectOne(this)" type="checkbox" value="<%# DataBinder.Eval(Container, "DataItem.id").ToString()%>"	name="id">
							<%# smilesgrid.LoadSelectedCheckBox(DataBinder.Eval(Container, "DataItem.id").ToString())%>
						</ItemTemplate>
					</asp:TemplateColumn>
					<asp:BoundColumn DataField="ID" SortExpression="id" HeaderText="图标id" Visible="false" ></asp:BoundColumn>
					<asp:BoundColumn DataField="type" SortExpression="type" HeaderText="类型" Visible="false"></asp:BoundColumn>
					<asp:BoundColumn DataField="code" SortExpression="code" HeaderText="代码" ><headerstyle width="20%"/></asp:BoundColumn>
					<asp:BoundColumn DataField="displayorder" SortExpression="displayorder" HeaderText="显示顺序"><headerstyle width="20%"/></asp:BoundColumn>
					<asp:BoundColumn DataField="url" SortExpression="url" HeaderText="文件名"><headerstyle width="40%"/></asp:BoundColumn>
								
					<asp:TemplateColumn HeaderText="图片">
						<ItemTemplate>
							<asp:Label id=Label4 runat="server" Text='<%# PicStr(DataBinder.Eval(Container, "DataItem.url").ToString()) %>'>
							</asp:Label>
						</ItemTemplate>
					</asp:TemplateColumn>
			
				</Columns>
			</cc1:datagrid>
	<div class="ManagerForm">
    <fieldset>
	<legend style="background:url(../images/icons/icon49.jpg) no-repeat 6px 50%;">增加现有表情</legend>
		<table class="datagridStyles" cellspacing="0" cellpadding="3" rules="rows" border="0" width="100%">
			<tr>
			  <td width="5%"><input type="checkbox" name="cfile" onclick="checkFileList(this.form)"></td>
			  <td width="25%">代码</td>
			  <td width="25%">显示顺序</td>
			  <td width="35%">文件名</td>
			  <td width="10%">图片</td>
			</tr>
			<asp:Literal ID="fileinfoList" Runat="server" />
			<tr><td align="center" colspan="5"><cc1:Button id="SubmitButton" runat="server" Text=" 提 交 " ValidateForm="true"></cc1:Button></td></tr>
		  </table>
    </fieldset>
    </div>
		</form>
			<%=footer%>
	</body>
</HTML>
