<%@ Page Language="C#" AutoEventWireup="true" Inherits="WebApp.Admin.DBServiceList"
    CodeBehind="DBServiceList.aspx.cs" %>

<!DOCTYPE html>
<!--[if lt IE 9]><html class="lte-ie8"><![endif]-->
<!--[if gt IE 8]><!-->
<html>
<!--<![endif]-->
<head runat="server">
    <title>数据库服务器维护</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <!--#include file = "../Css/adminCssEdit.htm" -->

    <script language="javascript">
		    function selectServer(val)
		    {
		        showModalDialog("selectServer.aspx?type=" + val,window, "dialogWidth:302px;dialogHeight:378px;help:no;scroll:no;status:no");		        
		    }
		    function BindSelect(type, txt, val)
		    {
		        if(type=="1")
		        {
		            document.all.txtServerName1.value = txt;
		            document.all.hiddenWebServer.value = val;
		        }
		        else
		        {
		            document.all.txtServerName2.value = txt;
		            document.all.hiddenSqlServer.value = val;
		        }
		    }
		    function checkPort()
		    {
		        if(document.all.txtWebIp.value.LTrim().RTrim().length==0)
		        {
		            alert("请输入服务器IP！");
		            return false;
		        }
		        if(document.all.txtWebPort.value.LTrim().RTrim().length==0)
		        {
		            alert("请输入端口号！");
		            return false;
		        }
		        if(IP2V(document.all.txtWebIp.value.LTrim().RTrim())==false)
		        {
		            alert("IP地址格式不正确！");
		            return false;
		        }
		        return true;
		    }
		    String.prototype.Trim = function() 
            { 
            return this.replace(/(^\s*)|(\s*$)/g, ""); 
            } 

            String.prototype.LTrim = function() 
            { 
            return this.replace(/(^\s*)/g, ""); 
            } 

            String.prototype.RTrim = function() 
            { 
            return this.replace(/(\s*$)/g, ""); 
            } 
            function IP2V(ip)
            {
                re=/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/g;  //匹配IP地址的正则表达式
                if(re.test(ip))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }

    </script>

</head>
<body>
    <div class="edit-func-box func-box">
        <form id="form1" runat="server">
        <div class="hd">
            <asp:Label ID="lblTitle" runat="server"></asp:Label>
        </div>
        <div class="bd">
            <div class="function-hd">
                <div class="search-box fr">
                </div>
                <div class="action-field">
                    <asp:Button ID="btnSaveDB" runat="server" CausesValidation="False" Text="保存表格" CssClass="btn"
                    OnClick="btnSaveDB_Click" />
                </div>
                <!--/action-field-->
            </div>
            <asp:DataGrid ID="dgSqlServer" runat="server" class="list-table" AutoGenerateColumns="False"
                DataKeyField="pkID" Width="100%" OnItemCommand="dgSqlServer_ItemCommand" OnItemDataBound="dgSqlServer_ItemDataBound">
                <Columns>
                    <asp:BoundColumn DataField="pkID" HeaderText="ID" HeaderStyle-CssClass="title"></asp:BoundColumn>
                    <asp:BoundColumn DataField="serviceName" HeaderText="名称" HeaderStyle-CssClass="title">
                    </asp:BoundColumn>
                    <asp:BoundColumn DataField="ip" HeaderText="IP" HeaderStyle-CssClass="title"></asp:BoundColumn>
                    <asp:BoundColumn DataField="dbUser" HeaderText="数据库管理员" HeaderStyle-CssClass="title">
                    </asp:BoundColumn>
                    <asp:BoundColumn DataField="dbPwd" HeaderText="管理员密码" HeaderStyle-CssClass="title">
                    </asp:BoundColumn>
                    <asp:BoundColumn DataField="dbPort" HeaderText="端口" HeaderStyle-CssClass="title">
                    </asp:BoundColumn>
                    <asp:TemplateColumn HeaderText="是否在用" HeaderStyle-CssClass="title">
                        <ItemTemplate>
                            <asp:DropDownList ID="ddlSqlOnUsing" runat="server" SelectedValue='<%# DataBinder.Eval(Container, "DataItem.OnUsing") %>'>
                                <asp:ListItem Value="0">禁用</asp:ListItem>
                                <asp:ListItem Value="1">使用</asp:ListItem>
                            </asp:DropDownList>
                        </ItemTemplate>
                    </asp:TemplateColumn>
                    <asp:TemplateColumn HeaderStyle-CssClass="title">
                        <ItemTemplate>
                            <asp:LinkButton ID="editSql" runat="server" CausesValidation="false" CommandName="edit">编辑</asp:LinkButton>&nbsp;
                            <asp:LinkButton ID="delSql" runat="server" CommandName="delete" CausesValidation="false"
                                CommandArgument='<%# DataBinder.Eval(Container, "DataItem.serviceName") %>'>删除</asp:LinkButton>&nbsp;
                            <asp:HyperLink ID="hplViewWebSite" runat="server" NavigateUrl='<%# "WebSiteList.aspx?dbId="+Eval("pkId")+"&name=" + Eval("serviceName") %>'>查看子站列表</asp:HyperLink>
                        </ItemTemplate>
                    </asp:TemplateColumn>
                </Columns>
            </asp:DataGrid>
            <asp:Label ID="lblSqlPage" runat="server"></asp:Label>
        </div>
        <div class="ft">
            <div class="pagination">
                </div>
            <!--/action-field-->
        </div>
        <table class="edit-table">
            <tr>
                <th width="25%">
                    服务名称：
                </th>
                <td width="75%">
                    <asp:TextBox ID="txtSqlName" runat="server" CssClass="input-txt input-txt3"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <th>
                    服务器IP：
                </th>
                <td>
                    <asp:TextBox ID="txtSqlIp" runat="server" CssClass="input-txt input-txt3"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <th>
                    数据库端口：
                </th>
                <td>
                    <asp:TextBox ID="txtDbPort" runat="server" CssClass="input-txt input-txt3" Enabled="false"
                        ReadOnly="True">1433</asp:TextBox>
                </td>
            </tr>
            <tr>
                <th>
                    数据库管理员：
                </th>
                <td>
                    <asp:TextBox ID="txtDbAdmin" runat="server" CssClass="input-txt input-txt3">sa</asp:TextBox>
                </td>
            </tr>
            <tr>
                <th>
                    管理员密码：
                </th>
                <td>
                    <asp:TextBox ID="txtDbPwd" runat="server" CssClass="input-txt input-txt3"></asp:TextBox>
                </td>
            </tr>
        </table>
        <input id="sqlId" runat="server" style="height: 15px; width: 58px;" type="hidden"
            name="sqlId" />
        <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="txtSqlName"
            Display="None" ErrorMessage="请输入数据库服务器名称！"></asp:RequiredFieldValidator>&nbsp;
        <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ControlToValidate="txtSqlIp"
            Display="None" ErrorMessage="请输入服务器Ip！"></asp:RequiredFieldValidator>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" ControlToValidate="txtDbPort"
            Display="None" ErrorMessage="请输入数据库端口！"></asp:RequiredFieldValidator>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ControlToValidate="txtDbAdmin"
            Display="None" ErrorMessage="请输入数据库管理员！"></asp:RequiredFieldValidator>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator12" runat="server" ControlToValidate="txtDbPwd"
            Display="None" ErrorMessage="请输入管理员密码！"></asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="txtSqlIp"
            Display="None" ErrorMessage="IP地址格式不正确！" ValidationExpression="^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$"></asp:RegularExpressionValidator>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ControlToValidate="txtDbPort"
            Display="None" ErrorMessage="端口必须为大于0的整数！" ValidationExpression="^[0-9]*[1-9][0-9]*$"></asp:RegularExpressionValidator>
        <div class="ft">
            <div class="action-field txt-c">
                <asp:Button ID="btnAddDB" runat="server" Text="添加" CssClass="btn" OnClick="btnAddDB_Click" />&nbsp;
                <asp:Button ID="btnCancelDB" runat="server" Text="取消" CssClass="btn" CausesValidation="False"
                    OnClick="btnCancelDB_Click" />
            </div>
        </div>
        <input id="hiddenIp" runat="server" name="hiddenIp" type="hidden" />
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"
            ShowSummary="False" />
        </form>
    </div>
</body>
</html>

<script language="javascript">
			function ShowWebSiteList(dbId, name)
			{
				window.open("WebSiteList.aspx?dbId=" + dbId + "&name=" + name,"", "Width=760,Height=500");
			}
</script>

