<%@ page language="C#" masterpagefile="AdminIndexMaster.master" autoeventwireup="true" inherits="HL_Admin_Admin_LabelIO, WebApp_deploy" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<style>
.p_button{margin:20px;}
.p_button input{font-family:Verdana}
</style>
<table  class="tableForm" id="step1">
    <tr>
        <td class="tit" colspan="2" align="center">
            第一步：<b>选择外部数据库</b></td>
    </tr>
    <tr >
        <th>
            <strong>标签数据库文件路径：&nbsp;</strong></th>
        <td align='left'>
            <asp:TextBox ID="TxtLabelMdb" runat="server" Width="332px">/Label/LabelBak.config</asp:TextBox>
            <asp:Button  ID="BtnTestDataSource" OnClientClick="settext()" runat="server" Text="下一步" OnClick="BtnTestDataSource_Click"/><br />
            <asp:Label ID="TxtTestStat" runat="server"/>
        </td>
    </tr>
</table>
<asp:Panel ID="LabelList" runat="server" Visible="false">
<script type="text/javascript">
var _step1Obj=document.getElementById("step1");
if(null!=_step1Obj)_step1Obj.style.display="none";
</script>
<table  class="tableForm">
    <tr>
        <td class="tit" colspan="2" align="center">
            第二步：<b>选择导入或导出标签，点击确定按钮执行操作</b></td>
    </tr>
 </table>   
   <div style="width:40%;float:left">
       <b>系统内的标签（可使用的标签）</b><br />
       <asp:CheckBox ID="ChkSystemDel" runat="server" Text=" 导出后删除"  />&nbsp;
       <asp:CheckBox ID="ChkClearOut" runat="server" Text="导出前先清空外部数据库" Checked="false" />&nbsp;
       <input type="checkbox" id="SysAllCheck"  onclick="SelectAll('ctl00_ContentPlaceHolder1_SourceLabel',this)" />全选<br />
       <asp:ListBox ID="SourceLabel" runat="server" Width="98%" Height="400px" SelectionMode="Multiple"/><br />
       <input type="submit" value="删除选中标签" id="deleteSourceBtn" onclick="deleteLabel('ctl00_ContentPlaceHolder1_SourceLabel','in');" />
  </div>
  <div style="width:15%;float:left">
      <p class="p_button" style="margin-top:100px;">
         <input type="checkbox" id="recover" name="recover" value="1"  onclick="lockSelect(this)"/><label for="recover">覆盖同名标签</label>
      </p>
      <p class="p_button" >
      <input type="button" id="inputOutBtn" value="导出>>>>>" onclick="sendTo('ctl00_ContentPlaceHolder1_SourceLabel','ctl00_ContentPlaceHolder1_TargetLabel','out')" />
      </p>
      <p class="p_button">
      <input type="button" id="ouputBtn" value="<<<<<导入" onclick="sendTo('ctl00_ContentPlaceHolder1_TargetLabel','ctl00_ContentPlaceHolder1_SourceLabel','in')" />
      </p>
      <p class="p_button">
      <input type="reset" value="重设"  onclick="resetIO();" />
      </p>
      <p class="p_button">
      <input type="submit" value="确定导入导出" id="submitBtn" onclick="return confirm('确定要转换吗？');" disabled=disabled/>
      </p>
     
  </div>
  <div style="width:40%;float:left">
     <b>外部数据库中的标签（备份的标签）</b><br />
     <asp:CheckBox ID="ChkOutDel" runat="server" Text=" 导入后删除"  />&nbsp;
     <input type="checkbox" id="OutAllCheck" onclick="SelectAll('ctl00_ContentPlaceHolder1_TargetLabel',this)"/>全选<br />
     <asp:ListBox ID="TargetLabel" runat="server" Width="98%" Height="400px"  SelectionMode="Multiple"/><br />
     <input type="submit" value="删除选中标签" id="deleteTargetBtn" onclick="deleteLabel('ctl00_ContentPlaceHolder1_TargetLabel','out');" />
  </div>
  <div style="clear:both">提示：按住“Ctrl”或“Shift”键可以多选</div>
</asp:Panel>
<asp:Literal ID="label_class_type" runat="server" />

<input type="hidden" name="h_action" id="h_action" value="import" />
<input type="hidden" name="h_type" id="h_type" value="" />
<input type="hidden" name="h_import_value" id="h_import_value" value="" />
<input type="hidden" name="h_recover" id="h_recover" />
<script type="text/javascript">
  var _inputOutBtn=document.getElementById("inputOutBtn");
  var _ouputBtn=document.getElementById("ouputBtn");
  var _hactionObj=document.getElementById("h_action");
  var _typeObj=document.getElementById("h_type");
  var _h_importObj=document.getElementById("h_import_value");
  var _sourceObj=document.getElementById("ctl00_ContentPlaceHolder1_SourceLabel");
  var _targetObj=document.getElementById("ctl00_ContentPlaceHolder1_TargetLabel")
  var sourceLength=_sourceObj.length;
  var targetLength=_targetObj.length;
  var _submitBtn=document.getElementById("submitBtn");
  var _deleteTargetBtn=document.getElementById("deleteTargetBtn");
  var _deleteSourceBtn=document.getElementById("deleteSourceBtn");
  var hasSameLable=new Array();
  var allowRecover=false;
  var h_recover=document.getElementById("h_recover");
  var recoverObj=document.getElementById("recover");
function sendTo(sourceID,targetID,type){
  var sourceobj=document.getElementById(sourceID);
  var targetobj=document.getElementById(targetID);
  
  if(recoverObj.checked)
  {
    allowRecover=true;
    h_recover.value="1";
  }
  else
  {
    allowRecover=false;
    h_recover.value="0";
  }
  if(type=="in"){
    _inputOutBtn.disabled=true;
    _ouputBtn.disabled=false;
    
  }
  else{
     _inputOutBtn.disabled=false;
    _ouputBtn.disabled=true;
  }
  _typeObj.value=type;
  _hactionObj.value="import";
  _submitBtn.disabled=false;
  _deleteTargetBtn.disabled=true;
  _deleteSourceBtn.disabled=true;
  hasSameLable.length=0;;
  for(var i=0;i<sourceobj.length;i++){
    if(sourceobj.options[i].selected){
      var label_name=sourceobj.options[i].text;
      var label_id=sourceobj.options[i].value;
      AddItem(targetobj,label_name,label_id);
    }
  }
  if(hasSameLable.length>0)
  {
     var labelNameStr="";
     for(var i=0;i<hasSameLable.length;i++)
     {
        labelNameStr+="标签:"+hasSameLable[i]+"已存在,忽略此操作\r\n";
     }
     alert(labelNameStr);
  }

}
function AddItem(obj,name,id){
   for(var i=0;i<obj.length;i++){
     if(allowRecover==false && obj.options[i].text==name){
       hasSameLable.push(name);
       return;
     }     
   }
   var _length=obj.length;
   obj.options[_length]=new Option(name,id);
   obj.options[_length].selected=true;
   var _importValue=_h_importObj.value;
   var _value_array=_importValue.split(',');
   for(var i=0;i<_value_array.length;i++){
      if(id==_value_array[i]){
        return;
      }
   
   }
   if(_importValue ==""){
      _importValue=id;
   }
   else{
      _importValue=_importValue+","+id;
   }
   _h_importObj.value=_importValue;
   
   
   
}
function SelectAll(id,checkObj){
  var _selectAll=false;
  if(checkObj.checked){
    _selectAll=true;
  }
  var obj=document.getElementById(id);
  for(var i=0;i<obj.length;i++){
      obj.options[i].selected=_selectAll;
    
   }
}
function resetIO(){
    _inputOutBtn.disabled=false;
    _ouputBtn.disabled =false;
    _submitBtn.disabled=true;
    recoverObj.disabled=false;
    _h_importObj.value ="";
    _hactionObj.value  ="";
    _typeObj.value="";
    _sourceObj.length  = sourceLength;
    _targetObj.length  = targetLength;
    _deleteTargetBtn.disabled=false;
    _deleteSourceBtn.disabled=false;
    h_recover.value="0";
    

}
function deleteLabel(id,type){

 if(confirm('确定要删除吗？')){
    _hactionObj.value="delete";
    _typeObj.value=type;
    _h_importObj.value="";
    var obj=document.getElementById(id);
    var deleteID="";
    for(var i=0;i<obj.length;i++){
      if(obj.options[i].selected){         
         deleteID +=obj.options[i].value+",";
      }
    
    }
    if(deleteID!=""){
      deleteID=deleteID.substr(0,deleteID.length-1);
    }
    _h_importObj.value=deleteID;
    
 }

}
function lockSelect(obj)
{
   obj.disabled=true;
}
</script>  

</asp:Content>

