<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Template_AddField.aspx.cs" Inherits="PowerEasy.Module.General.WebSite.Admin.Template.Template_AddField" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>添加模板上数据源的字段</title>
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Cache-Control" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
     <base target="_self" />
</head>
<body>
    <form id="form1" runat="server">
    <table width="100%" height="100%" border="0" cellpadding="2" cellspacing="0">
        <tr height="30">
            <td bgcolor="#999999" valign="middle">
                <img src="../../Admin/Images/img_u.gif" alt="" /><span style="color: #0000FF; font-weight: bold;
                    font-size: 18px;">添加模板上数据源的字段</span>
            </td>
        </tr>
        <tr>
            <td>
                <div style="height: 100%;border: 1px double #ffffff">
                    <div style="width: 100%; text-align: center; background: #9999bb">
                        请选择你要添加的数据源字段</div>
                    <div style="width: 95%; text-align: center">
                    <asp:Panel ID="pnlContent" runat="server">
                    <table style="text-align:left;">
                        <tr><td align="right">数据源</td>
                            <td align="left">
                                <asp:DropDownList ID="ddlDataSource" runat="server" AutoPostBack="True" 
                                    onselectedindexchanged="ddlDataSource_SelectedIndexChanged" Width="220px">
                                    <asp:ListItem Text="请选择" Value="-1"></asp:ListItem>
                                </asp:DropDownList>
                            </td>
                        </tr>
                        <tr><td align="right">字段列表</td>
                            <td align="left">
                            <asp:ListBox ID="listfield" SelectionMode="Multiple" runat="server" Width="220px" Height="87px">
                            </asp:ListBox>
                            </td>
                        </tr>
                        <tr><td align="right">启用循环<input id="InstertRepeat" type="checkbox" onclick="showmod()" /></td>
                            <td align="left" bgcolor="#cccccc">                            
                                循环次数<input id="loopnum" type="text" size="3" value="0" onmousewheel="changenum(this)" />
                                &nbsp;循环起始<input id="loopbegin" type="text" size="3" value="0" onmousewheel="changenum(this)" /><br />
                            </td>
                        </tr>
                        <tr id="repeatautoid" style="visibility:hidden"><td align="right">插入ＩＤ<input id="Instertautoid" type="checkbox"/></td>
                            <td align="left" bgcolor="#dddddd">                            
                                ＩＤ起始<input id="autoidbegin" type="text" size="3" value="0" onmousewheel="changenum(this)" />
                            </td>
                        </tr>
                        <tr id="repeatmod" style="visibility:hidden"><td align="right">启用间隔<input id="InstertMod" type="checkbox" /></td>
                            <td align="left" bgcolor="#cccccc">
                                间隔行数<input id="modnum" type="text" size="3" value="1" onmousewheel="changenum(this)" /><br />
                                <textarea id="modcontent" rows="3" cols="40">请输入插入内容</textarea>
                            </td>
                        </tr>
                    </table>
                    </asp:Panel>
                    <pe:ExtendedLabel ID="lblMsg" runat="server" HtmlEncode="false" Visible="true" Width="90%" Height="100">test</pe:ExtendedLabel>
                    <asp:TextBox ID="nodata" runat="server" Visible="false">
                        未搜索到数据源标签字段.请在你的数据源标签中添加如下标记:
                        <br/><span style="color:Red;">〈!-- FieldTipsStart --〉</span>
                        <br/>
                        你的数据源标签字段包括在此标记内.
                        <br/><span style="color:Red;">〈!-- FieldTipsEnd --〉</span>
                    </asp:TextBox>
                    </div>
                </div>
            </td>
        </tr>
        <tr height="40">
            <td bgcolor="#999999" color="#ffffff" align="center">
                <input type="button" runat="server" id="btnAdd" class="inputbutton" value="添加" onclick="submitdate();" />&nbsp;&nbsp;
                <input type="button" class="inputbutton" value="取消" onclick="drapDrop();" />
            </td>
        </tr>
    </table>
    
    <script language="JavaScript" type="text/javascript">
    <!--
      function drapDrop() {
          parent.closeByButton = false;
          parent.CloseWindow();
      }
    
    function submitdate(){
        var returnstr = "";
        var ds = document.getElementById("<% =ddlDataSource.ClientID %>");
        var isInstertRepeat = document.getElementById("InstertRepeat").checked;
        var isInstertautoid = document.getElementById("Instertautoid").checked;
        if (ds.value != "-1") {
	    if(isInstertRepeat)
            {
                returnstr += "{PE.Repeat id=\"" + ds.value + "\"";
                var loopnm = document.getElementById("loopnum").value;
                if(loopnm > 0)
                {
                    returnstr += " loop=\"" + loopnm.toString() + "\"" ;
                }
                var loopbegin = document.getElementById("loopbegin").value;
                if(loopbegin > 0)
                {
                    returnstr += " loopbegin=\"" + loopbegin.toString() + "\"" ;
                }
                var countbase = document.getElementById("autoidbegin").value;
                if(isInstertautoid && (countbase > 0))
                {
                    returnstr += " countbase=\"" + loopbegin.toString() + "\"" ;
                }
                returnstr += "}\r\n";
            }
            if(isInstertautoid)
            {
                returnstr += "{PE.Field.AutoId/}\r\n";
            }
            var fields = document.getElementById("<% =listfield.ClientID %>");
            for(var i=0;i<fields.length;i++)
            {
                if(fields[i].selected)
                {
                    returnstr += "{PE.Field id=\"" + ds.value + "\" fieldname=\"" + fields[i].value + "\" /}\r\n";
                }
            }
            if(isInstertRepeat)
            {
                if(document.getElementById("InstertMod").checked)
                {
                    returnstr += "{PE.RMod";
                    var modnum = document.getElementById("modnum").value;
                    if(modnum < 1)
                    {
                        alert("请输入正确的行号");
                        return false;
                    }
                    else
                    {
                        returnstr += " mod=\"" + document.getElementById("modnum").value.toString() +"\"";
                    }
                    returnstr += "}";
                    returnstr += document.getElementById("modcontent").value;
                    returnstr += "{/PE.RMod}\r\n";
                }
                returnstr += "{/PE.Repeat}";
            }

            if (parent.isRightMenu) {
                parent.setlabel(returnstr);
            }
            else {
                parent.getInsertText(returnstr);
            }
            parent.closeByButton = true;
        }
        parent.CloseWindow();
    }
    
    function showmod()
    {
        var isInstertRepeat = document.getElementById("InstertRepeat").checked;
        if(isInstertRepeat)
        {
            document.getElementById("repeatautoid").style.visibility = "visible";
            document.getElementById("repeatmod").style.visibility = "visible";
        }
        else
        {
            document.getElementById("repeatautoid").style.visibility = "hidden";
            document.getElementById("repeatmod").style.visibility = "hidden";
        }
    }

    function changenum(n){
        n.value = parseInt(n.value) + parseInt(event.wheelDelta / 120);
        if(n.value < 0) {n.value = 0}
    } 
    -->
    </script>
    
    </form>
</body>
</html>
