<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/MasterPage.master" AutoEventWireup="True" Inherits="Kesion.NET.WebSite.Admin_UserImport" Codebehind="KS.UserImport.aspx.cs" %>

<asp:Content ID="Content1" ContentPlaceHolderID="KSContent" runat="Server">
    <div id="manage_top" class="toptitle menu_top_fixed">
        <ul class="titleTab">
            <li><a href="KS.UserAdd.Aspx">新增用户</a></li>
            <li class="curr"><a href="KS.UserImport.Aspx">外部数据源批量导入</a></li>
        </ul>
    </div>
    <div class="menu_top_fixed_height"></div>
    <div class="content-area">

        <style type="text/css">
            .graph {
                width: 450px;
                border: 1px solid #9bdf70;
                height: 25px;
            }

            #bar {
                display: block;
                background: #FFE7F4;
                float: left;
                height: 100%;
                text-align: center;
            }

            #barNum {
                position: absolute;
            }
        </style>

        <asp:Panel ID="top" runat="server" Width="100%">

            <div class="myTitle">第一步 请选择数据源</div>
            <table width="96%" align="center" border="0" cellpadding="0" cellspacing="0" class="CTable no-borderTable">
                <tr>
                    <td class="lefttd" style="height: 30px; text-align: right"><strong>数 据 源：</strong></td>
                    <td class="righttd" style="height: 30px; text-align: left">
                        <asp:DropDownList ID="LabelDataSource" runat="server"> 
                            <asp:ListItem Value="7" Selected="true">外部CSV数据源</asp:ListItem>
                        </asp:DropDownList>
                        <br />
                        <a href="/admin/user/用户导入示例.csv">下载导入示例</a><br/>
                    </td>
                </tr>
                <tr>
                    <td class="lefttd" style="height: 30px; text-align: right">
                        <strong>连接字符串：</strong></td>
                    <td class="righttd" style="height: 30px; text-align: left">
                        <asp:TextBox ID="ConnStr" runat="server" Height="50px" TextMode="MultiLine" Width="450px">/DBPath/数据库.mdb</asp:TextBox>
                        <div id="excelstr" style="display: none;">
                            &nbsp;<input type="button" class="button" onclick="SelectFiles('<%=this.ConnStr.ClientID%>',0);" value="选择Excel文件" />
                            <%=Kesion.APPCode.UploadAPI.EchoUpload("uploadexcelfile",this.ConnStr.ClientID) %>
                        </div>
                        <br />
                        <asp:Button ID="TextButton" runat="server" Text="测试数据源" CssClass="mt20 button button_on" CausesValidation="False" UseSubmitBehavior="False" />
                    </td>
                </tr>
                <tbody style="display: none;" id="showtable">
                    <tr style="display:none;">
                        <td class="lefttd" style="height: 30px; text-align: right"><strong>请选择要导入数据表：</strong></td>
                        <td class="righttd" style="height: 30px; text-align: left">
                            <select name="tablename" id="tablename"></select>
                        </td>
                    </tr>
                    <tr>
                        <td class="lefttd" style="height: 30px; text-align: right"></td>
                        <td class="righttd" style="height: 30px; text-align: left">
                            <asp:Button ID="Button1" runat="server" CssClass="button button_on" OnClick="Button1_Click" Text="下一步" />
                        </td>
                    </tr>
                </tbody>
            </table>
        </asp:Panel>



        <asp:Panel ID="list" runat="server" Width="100%">

            <asp:Label ID="Label1" runat="server" Text="Label" />
            <br />
            <asp:Button ID="Button2" CssClass="button" runat="server" Text="确定导入" OnClick="Button2_Click" />


        </asp:Panel>

    </div>



    <script type="text/javascript">
        function loadTable() {
            jQuery("#showtable").show();
            jQuery.get('KS.UserImport.aspx', { action: 'loadTable', lst: jQuery('#<%=this.LabelDataSource.ClientID %>>option:selected').val(), cstr: jQuery('#<%=this.ConnStr.ClientID %>').val() }, function (s) {
                jQuery("#tablename").empty().append(s);
            });
        }
        function checkdatasource() {
            jQuery.get('KS.UserImport.aspx', { action: 'CheckDataSource', lst: jQuery('#<%=this.LabelDataSource.ClientID %>>option:selected').val(), cstr: jQuery('#<%=this.ConnStr.ClientID %>').val() }, function (s) {
                if (s == 'true') {
                    KesionJS.AlertByTime(1, '恭喜，数据源连接测试通过!', 2);
                    loadTable();
                }
                else {
                    KesionJS.AlertByTime(2, '连接出错，请检查连接字符串!', 2);
                }
                return false;
            });
        }

        function changeconnstr() {
            switch (parseInt(jQuery('#<%=this.LabelDataSource.ClientID %>>option:selected').val())) {
            case 1:
                $("#excelstr").hide();

                jQuery('#<%=this.ConnStr.ClientID %>').val('/DBPath/数据库.mdb');
                break;
            case 2:
                $("#excelstr").hide();

                jQuery('#<%=this.ConnStr.ClientID %>').val('User ID=sa; Password=989066; Initial Catalog=kesionicms; server=(local);');
                break;
            case 3:
                $("#excelstr").hide();

                jQuery('#<%=this.ConnStr.ClientID %>').val('DSN=数据源名;UID=用户名;PWD=密码');
                break;
            case 4:
                $("#excelstr").hide();

                jQuery('#<%=this.ConnStr.ClientID %>').val('Data Source=数据源名;User Id=用户名;Password=密码;Integrated Security=no;');
                break;
            case 5:
                $("#excelstr").show();

                jQuery('#<%=this.ConnStr.ClientID %>').val('/DBPath/test.xls');
                break;
            case 6:
                $("#excelstr").hide();

                jQuery('#<%=this.ConnStr.ClientID %>').val('Data Source=完整数据库路径+名称;Provider=Microsoft.JET.OLEDB.4.0;');
                break;
            case 7:
                $("#excelstr").show();

                jQuery('#<%=this.ConnStr.ClientID %>').val('/DBPath/test.csv');
                    break;
            }
        }
        changeconnstr();
    </script>
</asp:Content>

