<%@ Control Language="C#" %>
<%@ Import Namespace="Kesion.Publics" %>
<%@ Import Namespace="Kesion.BLL" %>
<%@ Import Namespace="Kesion.Cache" %>
<%@ Import Namespace="Kesion.HtmlTags" %>
<%@ Import Namespace="Kesion.APPCode" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Kesion.Course" %>
<%@ Import Namespace="System.IO" %>
<script runat="server" type="text/C#">
	dynamic __user = HttpContext.Current.Items["user"];                //初始化用户信息，
	private static dynamic __info = new System.Dynamic.ExpandoObject();   //初始化当前页信息
	bool isLoadPage = true;  //定义页面是否加载
    public static DataTable dt;
    public static DataTable dts;
    public int sum = 0;
    public int num = 0;
    public int dbtype;
    public int passmd5 = 0;
    public int groupid = 0;
    public string ConnectionString;
    public int succnum = 0;
    public int errornum = 0;
    public string errorstu = "0";
    public string[] sk = new string[100];
    public string[] csk = new string[100];
    public StringBuilder sb = new StringBuilder();//导入成功数据
    public StringBuilder ss = new StringBuilder(); //导入失效数据
    public string otherop = "";//导入成功后，其他操作
    public int roomid = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        string action = KSCMS.S("action");
        roomid = Utils.StrToInt(KSCMS.S("roomid"));
        if (UserManage.GetUserInfo() != null)
        {
            int GroupID = UserManage.GetUserInfo().GroupID;
            if (GroupID == 4 && roomid != 0)
            {
                otherop = "1";//班级学员导入
            }
            else if (GroupID == 3)
            {
                otherop ="2";//机构学员导入
            }
            if (KSCMS.S("do").Equals("group"))
            {
                dts = DataFactory.GetDataTable("select BoardID,BoardName from KS_BBSBoard where userid=" + new TemporaryVar().UserID + "");
                if (dts.Rows.Count <= 0)
                {
                    Msg.Alert("对不起，请先创建兴趣小组!",KSCMS.GetComeUrl());
                    isLoadPage = false;
                    return;
                }
                otherop = "3";//小组学员导入
            }
        }
        if (action.Equals("import"))
        {
            check();
        }
       
    }
  
    private string GetDataField(string fieldname)
    {
        DataTable sourceFieldDT = null;

        if (sourceFieldDT == null)
        {
            string tablename = KSCMS.S("tablename");
            sourceFieldDT = LabelSource.getTableFiled(dbtype, ConnectionString, tablename);
        }
        StringBuilder sb = new StringBuilder();

        if (fieldname.ToLower() == "groupid")
        {
            sb.Append("<select name='" + fieldname + @"' onchange=""if (this.value==0){ jQuery('#showgroup').show(); }else{ jQuery('#showgroup').hide(); } "">");
            sb.Append("<option value='0'>从数据源字段导入</option>");
            using (DataTable dt = MyCache.GetUserGroupTable())
            {
                foreach (DataRow dr in dt.Rows)
                {
                    if (dr["groupid"].ToString() != "0" && dr["groupid"].ToString() != "1" && dr["groupid"].ToString() != "3" && dr["groupid"].ToString() != "4" && dr["groupid"].ToString() != "-3")
                    sb.AppendFormat("<option value='{0}'{2}>{1}</option>", dr["groupid"].ToString(), dr["groupname"].ToString(), dr["groupid"].ToString() == "2" ? " selected" : string.Empty);
                }
            }
            sb.Append("</select>");
            sb.Append("<select id='showgroup' style='display:none' name='field" + fieldname + "'>");
        }
        else
        {
            sb.Append("<select id='" + fieldname + "' name='field" + fieldname + "'>");
        }

        sb.Append("<option value='0'>此字段不导入</option>");
        using (DataTable dtfield = sourceFieldDT)
        {
            foreach (DataRow dr in dtfield.Rows)
            {
                sb.Append(string.Format("<option value='{0}'{1}>{0}</option>", dr["COLUMN_NAME"].ToString(), fieldname.ToLower() == dr["COLUMN_NAME"].ToString().ToLower() ? " selected" : ""));
            }
        }
        sb.Append("</select>");
        return sb.ToString();

    }

    public void check()
    {

        if (dt != null)
        {
             int importgroup=0;
            int maxuserid = 0;
            string AddDate = Utils.GetDateTime();
            //if (otherop == "1")
            //{
            //     maxuserid = CommonData.GetMaxId("KS_User", "userid");
            //}
            int PauseTime = 1;
            int count = Utils.StrToInt(KSCMS.S("CurrNowNum"));
            int nownum = 0;
            if (Utils.StrToInt(KSCMS.S("CurrNowNum")) > 0)
            {
                nownum = Utils.StrToInt(KSCMS.S("CurrNowNum"));
            }
            if (nownum == 0)
            {
                succnum = 0;
                errornum = 0;
            }
            if (otherop == "3")
            {
                importgroup = Utils.StrToInt(KSCMS.S("importgroup"));
                if (importgroup <= 0)
                {
                    Msg.Alert("对不起，请选择小组！");
                }
            }
            ShowMain();
            for (int i = nownum; i < dt.Rows.Count; i++)
            {
                DataRow dr = dt.Rows[i];
                Hashtable ht = new Hashtable();
                if (KSCMS.S("flag") != "pause")
                {
                    passmd5 = Utils.StrToInt(KSCMS.S("passmd5"));
                    groupid = Utils.StrToInt(KSCMS.S("groupid"));
                    using (DataTable dtfield = LabelSource.getTableFiled(0, ConnectionString, "KS_User", true))
                    {
                        int j = 0;
                        foreach (DataRow dc in dtfield.Rows)
                        {
                            if (dc["COLUMN_NAME"].ToString().ToLower() != "groupid" || (dc["COLUMN_NAME"].ToString().ToLower() == "groupid" && groupid == 0))
                            {
                                //KSCMS.W(KSCMS.S("field" + dc["COLUMN_NAME"].ToString()) + "==" + dc["COLUMN_NAME"].ToString() + "<br/>");
                                sk[j] = KSCMS.S("field" + dc["COLUMN_NAME"].ToString());
                                csk[j] = dc["COLUMN_NAME"].ToString();
                                j++;
                            }
                        }
                    }
                }
                string[] dateField = { "regdate", "joindate", "begindate", "lastlogintime", "birthday" };
                string[] numField = { "privacy", "logintimes", "chargetype", "edays", "score", "money", "scorehasuse", "point", "locked" };

                if (groupid != 0) ht.Add("groupid", groupid);

                string username = "";
                for (int kk = 0; kk < sk.Length; kk++)
                {
                    if (sk[kk] != "0" && !string.IsNullOrEmpty(sk[kk]))
                    {
                        #region 有选择导入的字段
                        if (csk[kk].ToUpper() == "USERNAME")
                        {
                            username = dr[sk[kk]].ToString();
                        }

                        if (csk[kk].ToUpper() == "PASSWORD" && passmd5 == 1)
                        {
                            string salt = Utils.RndKey(32);
                            string password = Utils.MD5(dr[sk[kk]].ToString() + salt, 32);
                            ht.Add(csk[kk], password);
                            ht.Add("salt", salt);
                        }
                        else if (csk[kk].ToUpper() == "GROUPID" && groupid != 0)
                        {
                            ht.Add(csk[kk].ToLower(), groupid);
                        }
                        else
                        {
                            switch (csk[kk].ToLower())
                            {
                                case "chargetype":
                                case "logintimes":
                                case "edays":
                                case "score":
                                case "money":
                                case "scorehasuse":
                                case "point":
                                case "locked":
                                case "groupid":
                                    ht.Add(csk[kk], Utils.StrToInt(dr[sk[kk]].ToString()));
                                    break;
                                case "regdate":
                                case "joindate":
                                case "begindate":
                                case "lastlogintime":
                                case "birthday":
                                    if (Utils.IsDateTime(dr[sk[kk]].ToString()))
                                    {
                                        ht.Add(csk[kk], dr[sk[kk]].ToString());
                                    }
                                    else
                                    {
                                        ht.Add(csk[kk], DateTime.Now);
                                    }
                                    break;
                                default:
                                    ht.Add(csk[kk], dr[sk[kk]].ToString());
                                    break;
                            }
                        }
                        #endregion
                    }
                    else if (sk[kk] == "0")
                    {
                        if (Utils.InArray(csk[kk].ToLower(), dateField, true) == true)
                        {
                            ht.Add(csk[kk], DateTime.Now);
                        }
                        else if (Utils.InArray(csk[kk].ToLower(), numField, true) == true)
                        {
                            if (csk[kk].ToLower() == "chargetype")
                            {
                                ht.Add(csk[kk], 1);
                            }
                            else
                            {
                                ht.Add(csk[kk], 0);
                            }
                        }
                    }
                }

                if (string.IsNullOrEmpty(username))
                {
                    errornum++;
                }
                else
                {
                    string sql = "select top 1 userid from ks_user where username='" + username + "'";
                    int id = Utils.StrToInt(DataFactoryUser.GetOnlyValue(sql)); //判断用户是否已经存在
                    if (id <= 0)
                    {
                        succnum++;
                        string time = Utils.GetDateTime();
                        ht.Add("RegDate", time);
                        ht.Add("JoinDate", time);
                        ht.Add("LastLoginTime", time);
                        ht.Add("BeginDate", time);
                        if (otherop == "2")
                        {
                            ht.Add("schoolid", new TemporaryVar().UserID);
                        }
                        CommonDataUser.Insert("ks_user", ht);
                        if (otherop == "1")
                        {
                            ht.Clear();
                            ht.Add("userid", CommonData.GetMaxId("KS_User", "userid"));
                            ht.Add("adddate", AddDate);
                            ht.Add("verify", 1);
                            ht.Add("roomid", roomid);
                            CommonDataUser.Insert("KS_CosClassStudent", ht);
                        }
                        if (otherop == "3")
                        {
                            ht.Clear();
                            ht.Add("userid", CommonData.GetMaxId("KS_User", "userid"));
                            ht.Add("username", username);
                            ht.Add("boardid", importgroup);
                            CommonDataUser.Insert("KS_BBSMember", ht);
                        }
                        
                        sb.AppendLine("会员名[" + username + "]导入成功\n");
                    }
                    else
                    {
                        errornum++;
                            ss.Append("<span>会员名[" + username + "]已存在</span></br>");
                        
                    }
                }
                count++;
                InnerJS(count, dt.Rows.Count, "位会员");
                if (count % 100 == 0)
                {
                    string url = "KS.UserImport.aspx?action=content&from=" + KSCMS.S("from") + "&flag=pause&CurrNowNum=" + count;
                    KSCMS.W("<" + "script>");
                    KSCMS.W(@"fsohtml.innerHTML='<div style=""text-align:cdenter""><div style=""margin:10px;height:80px;padding:8px;border:1px dashed #cccccc;text-align:left;""><img src=""../../admin/images/info_success_48.gif"" align=""left""><br>&nbsp;&nbsp;&nbsp;&nbsp;<b>温馨提示：</b><br>&nbsp;&nbsp;&nbsp;&nbsp;以免过度占用服务器资源，系统暂停" + PauseTime + @"秒后继续<img src=""../../admin/images/wait.gif""><br>&nbsp;&nbsp;&nbsp;&nbsp;如果" + PauseTime + @"秒后没有继续，请点此<a href=""" + url + @"""><font color=red>继续</font></a>或点此<a href=""KS.UserImport.aspx""><font color=red>停止</font></a>!</div></div>';");
                    KSCMS.W("</" + "script>");
                    KSCMS.W(@"<meta http-equiv=""refresh"" content=""" + PauseTime + @";url=" + url + @""">");
                }
            }
            if (otherop == "1")
            {
                Kesion.Course.Course.CheckCount("KS_CosClassStudent", "roomid=" + roomid + "", "studentid", 1, "KS_CosClassRoom", "buycount", "roomid=" + roomid + "");
            }
            if (otherop == "3")
            {
                Kesion.Course.Course.CheckCount("KS_BBSMember", "boardid=" + importgroup + "", "memberid", 1, "KS_BBSBoard", "StudentNum", "boardid=" + importgroup + "");
            }
        }
        else
        {
            Msg.Alert("请绑定数据源", BasicField.GetUserUrl("teacher/stuimport", "roomid-" + Utils.StrToInt(KSCMS.S("roomid"))));
        }

        sucss(sb.ToString()); //导入成功记录    
        final(ss.ToString());   //导入失效记录   

        KSCMS.W("<script>");
        KSCMS.W("fsohtml.innerHTML='';");
        KSCMS.W("img2.width=400;");
        KSCMS.W("txt2.innerHTML='导入进度:100';");
        if (dt != null)
        {
            KSCMS.W(string.Format(@"txt3.innerHTML=""总共有 <font color=blue><b>{0}</b></font> 位会员， 导入成功 <font color=green><b>{1}</b></font> 位，导入失败 <font color=red><b>{2}</b></font> 位！</br>{3}"";", dt.Rows.Count, succnum, errornum,ss.ToString()));
        }
        KSCMS.W("</" + "script>");

        string backurl = BasicField.GetUserUrl("teacher/TcClassStudent", "roomid-" + KSCMS.S("roomid"));
        if (otherop == "2")
            backurl = BasicField.GetUserUrl("teacher/EpTjUserList");
        if (otherop == "3")
            backurl = BasicField.GetUserUrl("teacher/TcGroup");
        KSCMS.W("<div class='t_tybox' style='text-align: center; padding-top:10px;'><input type='button' value='返回' onclick=\"location.href='" + backurl + "';\" class='button'/></div>");

    }

    public void sucss(string str)
    {
        try
        {
            FileStream fs = new FileStream(Server.MapPath("~/UploadFiles/temp/user_import_success_log.txt"), FileMode.CreateNew);
            StreamWriter sw = new StreamWriter(fs);
            sw.WriteLine(str);
            fs.Close();
        }
        catch (Exception)
        {

        }
    }
    public void final(string str)
    {

        try
        {
            FileStream fs = new FileStream(Server.MapPath("~/UploadFiles/temp/user_import_error_log.txt"), FileMode.CreateNew);
            StreamWriter sw = new StreamWriter(fs);
            sw.WriteLine(str);
            sw.Flush();
            fs.Close();
        }
        catch (Exception)
        {

        }
    }

    private void ShowMain()
    {
        #region 显示主体
        string str = @"
                    <!DOCTYPE html><html>
                    <head>
                      
                    </head>
                  <body scroll=no bgcolor='transparent'>
                   ";

        	str += @"<div class='t_tybox'><br><br>";
        	str += @"<table id=""BarShowArea"" width=""400""  border=""0"" align=""center"" cellspacing=""0"" cellpadding=""0"" style=""margin:auto;"">
						<tr>
							<td bgcolor=000000>
								<table width=""400"" border=""0"" cellspacing=""0"" cellpadding=""0"" style=""margin:auto;"">
									<tr>
									<td bgcolor=ffffff height=9><img src=""../../sysimg/default/bar.gif"" width=0 height=10 id=img2 name=img2 align=absmiddle></td></tr></table>
									<td bgcolor=ffffff height=9><span width=0 height=16 id=Span1 name=img2 align=absmiddle bgcolor='#000000'></span></td></tr>
								</table>
							</td>
						</tr>
					</table>
				    <table width=""400"" border=""0"" align=""center"" cellspacing=""0"" cellpadding=""0"" style=""margin:auto;"" class=""stuimportT"">
						<tr>
							<td align=center> <span id=txt2 name=txt2 style=""font-size:9pt"">0</span><span id=txt4 style=""font-size:9pt"">%</span></td>
						</tr>
						<tr>
							<td align=center><span id=txt3 name=txt3 style=""font-size:9pt"">0</span></td>
						</tr>
				    </table>
					<table width=""80%""  border=""0"" align=""center"" cellpadding=""0"" cellspacing=""0"">
					  	<tr>
							<td height=""50"">
								<div align=""center""></div>
							</td>
						</tr>
					</table>
					<table width=""100%""  border=""0"" cellpadding=""0"" cellspacing=""0"">
					  	<tr>
							<td height=""50"" id=""fsohtml""></td>
						</tr>
					</table>
			 </div>
           </body>
         </htmL>
              ";
        KSCMS.W(str);
        #endregion
    }

    private void InnerJS(int NowNum, int TotalNum, string itemname)
    {
        #region 显示进度
        KSCMS.W("<script>");
        // KSCMS.W(string.Format(@"fsohtml.innerHTML='{0}';", ListStr));
        KSCMS.W(string.Format(@"img2.width={0};", ((double)NowNum / TotalNum) * 400));
        KSCMS.W(string.Format(@"txt2.innerHTML=""导入进度:{0}"";", (((double)NowNum / TotalNum) * 100).ToString("f2")));
        KSCMS.W(string.Format(@"txt3.innerHTML=""总共导入 <font color=red><b>{0}</b></font> {1},<font color=red><b>在此过程中请勿刷新此页面！！！</b></font> 系统正在导入第 <font color=red><b>{2}</b></font> {1}"";", TotalNum, itemname, NowNum));
        KSCMS.W("<"+"/"+"script>");
        KSCMS.Flush();
        #endregion

    }
    


</script>
<%
    if (!isLoadPage) return;
    
%>

<script type="text/javascript">

    function loadTable() {
    
        jQuery.get('/plus/course/CourseAjax.ashx', { action: 'loadTable', lst: jQuery('#LabelDataSource>option:selected').val(), cstr: jQuery('#ConnStr').val() }, function (s) {
            if (s != "") {
                jQuery("#showtable").show();
                jQuery("#tablename").empty().append(s);
            }
            else {
                KesionJS.AlertByTime(2, '连接出错，请检查连接字符串!', 2);
            }
        });
    }
    function checkdatasource() {
        if (jQuery('#ConnStr').val() == "") {
            alert("对不起，请上传表格！");

        }
        else {
            jQuery.get('/plus/course/CourseAjax.ashx', { action: 'CheckDataSource', lst: jQuery('#LabelDataSource>option:selected').val(), cstr: jQuery('#ConnStr').val() }, function (s) {

                if (s == 'true') {
                  //  KesionJS.AlertByTime(1, '恭喜，数据源连接测试通过!', 2);
                    loadTable();
                }
                else {
                    KesionJS.AlertByTime(2, '连接出错，请检查连接字符串!', 2);
                }
                return false;
            });
        }
    }

    function changeconnstr() {
        switch (parseInt(jQuery('#LabelDataSource>option:selected').val())) {
            case 1:
                jQuery('#ConnStr').val('/DBPath/数据库.mdb');
                break;
            case 2:
                jQuery('#ConnStr').val('User ID=sa; Password=989066; Initial Catalog=kesionicms; server=(local);');
                break;
            case 3:
                jQuery('#ConnStr').val('DSN=数据源名;UID=用户名;PWD=密码');
                break;
            case 4:
                jQuery('#ConnStr').val('Data Source=数据源名;User Id=用户名;Password=密码;Integrated Security=no;');
                break;
            case 5:
                jQuery('#ConnStr').val('/DBPath/test.xls');
                break;
            case 6:
                jQuery('#ConnStr').val('Data Source=完整数据库路径+名称;Provider=Microsoft.JET.OLEDB.4.0;');
                break;
        }
    }

    </script>
<% if (!KSCMS.S("action").Equals("step1"))
   { %>
  <div class="t_tybox">
    <div id="top" style="width:100%;">
        <% if (!KSCMS.S("action").Equals("import"))
       { %>
          <form name="myform" action="<%=BasicField.GetUserUrl("teacher/stuimport","roomid-"+KSCMS.S("roomid")+"") %>" method="post" id="myform" >
            <input type="hidden" name="action" value="step1" />
          <table width="100%" align="center" border="0" cellpadding="1" cellspacing="1" class="border" style="padding:0">  
              <tr><td class="lefttd" style="text-align:left;padding-left:20px;height:30px;line-height:30px;background-color:#f9f9f9"><strong>第一步 请选择数据源</strong></td></tr>
              </table>
        <br />
          <table width="96%" align="center" border="0" cellpadding="1" cellspacing="1" class="border">  
               <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="LabelDataSource" id="LabelDataSource" onchange="changeconnstr();">
            <option  value="1">外部Access数据源</option>
            <option value="2">外部MS SQL数据源</option>
            <option value="3">外部ODBC数据源</option>
            <option value="4">外部Oracle数据源</option>
            <option selected="selected" value="5">外部Excel数据源</option>
            <option value="6">外部OLE数据源</option>
        </select>
                    </td>
                </tr>
      <tr>
                <td class="" >上传Excel：</td>
                <td class="tag_left"> 
                    <table>
                        <tr>
                        <td>
                            <input id="ConnStr" name="ConnStr" width="350px" class="textbox" style="float:left"  type="text" value="" />
                        </td>
                        <td style="width:550px;"><%=Kesion.APPCode.UploadAPI.EchoUpload("courseExcel","ConnStr") %></td>
                        <script> 
                            $('#upframe').css({
                                'height':'80px',
                                'position':'relative',
                                'top':'20px'
                                
                            })
                        </script>
                      </tr>
                        <tr>
                            <td style="text-align:left">
                            <span class="tips" style="padding:0"><a target="_blank" href="/KS_Inc/example/importExample.xls" class="button">点击此处</a>下载导入示例</span>
                        </td>       
                            </tr>
                    </table>
                
                      <br />
                            <div class="cz_btn" style="margin-left:10px">
                        <input type="button" name="TextButton" value="测试数据源" onclick="return (checkdatasource());" id="TextButton" class="button" />
                                  </div>
                 </td>
         </tr>
    
              <tbody  style="display:none;" id="showtable">
            <tr>
            <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">  
                    <div class="cz_btn">
                           <input name="do" value="<%=KSCMS.S("do") %>" type="hidden"/>
                   <input type="submit" name="Button1" value="下一步" id="Button1" class="button" />
                           </div>
                </td>
              </tr>
                  </tbody> 
      </table>
      </form>
        <%} %>
         
       
    </div>   
</div>
<%}else{ %>
<div class="t_tybox">
   <form name="myform2" action="<%=BasicField.GetUserUrl("teacher/stuimport","roomid-"+KSCMS.S("roomid")+"") %>" method="post" id="Form1" >
   
    <%
        dbtype = Utils.StrToInt(KSCMS.S("LabelDataSource"));
        ConnectionString = KSCMS.S("ConnStr");
        if (ConnectionString.IndexOf("://") != -1)
        {
            ConnectionString = ConnectionString.Replace("http://ftp.lobn.com.cn", "");  //获取
        }
        string tablename = "[" + KSCMS.S("tablename") + "]";
        Utils.WriteLog(Utils.GetMapPath(ConnectionString));
        dt = LabelSource.ReturnDataTable(dbtype, ConnectionString, "select * from " + tablename);


        StringBuilder sb = new StringBuilder();
        sb.Append(@"<table width='90%' align='center' cellpadding=""1"" cellspacing=""1"" class=""border"">");
        sb.Append("<tr><td class='lefttd' style='text-align:left;padding-left:4px;'><strong>第二步  选择导入的字段</strong></td></tr>");
        sb.Append("</table><br/>");

        sb.Append(@"<table width='90%' align='center' cellpadding=""1"" cellspacing=""1"" class=""border"">");
        sb.Append(@"<tr class=""CTitle""><th height=""25"" align='center'><strong>目标表字段</strong></th><th  align='left'><strong>数据源字段</strong></th></tr>");

        //必须字段
        sb.Append(@"<tr><td class=""lefttd"" style=""width:200px;text-align:left;font-weight:bold;padding-left:3px;"" colspan=""2"">必须导入的字段：</td></tr>");


        //选择小组
        if (otherop == "3")
        {
            using (DataTable dts = DataFactory.GetDataTable("select BoardID,BoardName from KS_BBSBoard where userid=" + new TemporaryVar().UserID + ""))
            {
                sb.Append("<tr><td class=\"lefttd\" >选择导入小组：</td><td  class=\"righttd\"><select name=\"importgroup\">");
                if (dts.Rows.Count > 0)
                {
                    foreach (DataRow dr in dts.Rows)
                    {
                        sb.Append("<option value=\"" + dr["BoardID"].ToString() + "\">" + dr["BoardName"].ToString() + "</option>");
                    }
                }
                sb.Append("</select>    <input name=\"do\" value=\"" + KSCMS.S("do") + "\" type=\"hidden\"/></td></tr>");
            }
        }

        string[] mustField = { "username", "password", "groupid" };
        string[] MustFieldTitle = { "用户名", "密码", "用户组ID" };
        string hide = string.Empty;
        for (int i = 0; i < mustField.Length; i++)
        {
            string passMd5 = string.Empty;
            if (mustField[i] == "password")
            {
                passMd5 = " <input type='checkbox' checked name='passmd5' value='1'>MD5加密码";
            }
            if (mustField[i] == "groupid")
            {
                hide = "style='display:none'";
            }

            sb.Append("<tr " + hide + "><td class=\"lefttd\" style=\"text-align:right;\">" + MustFieldTitle[i] + "(" + mustField[i] + ")</td>");
            sb.Append(string.Format(@"<td align='left' class=""righttd""><={0}{1}</td><tr>", GetDataField(mustField[i]), passMd5));

        }

        //可选字段
        string[] noImportField = { "userid", "alipayid", "isapi", "qqopenid", "qqtoken", "rndpassword", "sinaid", "sinatoken" };

        sb.Append(@"<tr><td class=""lefttd"" style=""text-align:left;font-weight:bold;padding-left:3px;"" colspan=""2"">可选导入的字段：</td></tr>");
        using (DataTable dtfield = LabelSource.getTableFiled(0, ConnectionString, "KS_User", true))
        {
            foreach (DataRow dr in dtfield.Rows)
            {
                if (Utils.InArray(dr["COLUMN_NAME"].ToString().ToLower(), mustField, true) == false)
                {
                    if (Utils.InArray(dr["COLUMN_NAME"].ToString().ToLower(), noImportField, true) == false)
                    {
                        if ((",email,sex,pic,").IndexOf("," + dr["COLUMN_NAME"].ToString().ToLower() + ",") == -1)
                        {
                            continue;
                        }
                        sb.Append(@"<tr><td class=""lefttd"" style=""text-align:right;"">");

                        sb.Append(dr["COLUMN_NAME"].ToString());
                        sb.Append(string.Format(@"</td><td align='left' class=""righttd""><={0}</td><tr>", GetDataField(dr["COLUMN_NAME"].ToString())));
                    }
                }
            }
        }
        sb.Append("</table>");
        KSCMS.W(sb.ToString());

      %>
         <input type="hidden" name="action" value="import" />
          	<div class="cz_btn">
             <input type="submit" value="确定导入" class="button" />   
                  </div>
               <div class="clear"></div>
       </form>
    </div>
<%} %>

  