function jsOtherInfo(){

};
jsOtherInfo.DetailOtherInfoTemplateGrid=null;/*其它资料列表*/

/*服务登记明细模式列表*/
jsOtherInfo.initDetailOtherInfoGrid=function(){
  try {
         var w =  $("#middleContanier").width()-2;
         var gh = 145;
         var Sys = {};
         var ua = navigator.userAgent.toLowerCase();
         if (window.ActiveXObject) {
             Sys.ie = ua.match(/msie ([\d.]+)/)[1]
         }
         if (Sys.ie == "6.0") {
             gh = 112;
         }
         var option = {
             height: gh,
             width: w,
             colModel:[
                { display: '编号', name: 'ID', width: (w * 0.15), sortable: true, align: 'left',hide:true},
                { display: '标题', name: 'Title', width: (w * 0.15), sortable: true, align: 'left',process:jsOtherInfo.FormatDetailTitle,processType:'text'},
                { display: '内容', name: 'Content', width: (w * 0.3), sortable: true, align: 'left',process:jsOtherInfo.FormatDetailContent,processType:'text'},
                { display: '创建时间', name: 'CreateTime', width: (w * 0.3), sortable: true, align: 'left',process:jsOtherInfo.FormatCreateTime,processType:'text'},
	            { display: '操作', name: 'ID', width: (w * 0.1), sortable: true,process: jsOtherInfo.operateDetailButton}
		     ],
             customFunction: jsOtherInfo.ShowDetailOtherInfo,
             rp: 5,
             rowHeight:24,
             rowbinddata:true,
             sortname: 'ID',
             sortorder: 'desc'
         };
        jsOtherInfo.DetailOtherInfoTemplateGrid = $("#tbOtherInfoList").ikegrid(option);
    }
    catch (e) {
        alert("jsOtherInfo.initDetailOtherInfoGrid:" + e.message);
    }
};

/*获取列表数据*/
jsOtherInfo.ShowDetailOtherInfo=function(pageSize, pageIndex, searchStr,extpara,order){
    var countTop=pageSize*(pageIndex-1);
    var strSql = "SELECT ID,Title,Content,CreateTime,COMPANY_ID,EMPLOYEE_ID FROM T_OTHERINFO ";
    var strWhere =" where 1=1 " ;//_Titel:strTitle,_Content:strContent,_EmpID:empID,_ComID:comID
    if (searchStr != "" && searchStr != undefined) {     
         if( searchStr[0]._ComID!="" && searchStr[0]._ComID!=null)
          {
            strWhere +="AND (COMPANY_ID="+  searchStr[0]._ComID;
            var strEmpIDList=jsOtherInfo.GetEmpIDListByComID(searchStr[0]._ComID);
            if(strEmpIDList!=""){
                strWhere+="OR EMPLOYEE_ID IN("+strEmpIDList+")";
            }
            strWhere+=")";
          }    
          if( searchStr[0]._EmpID!="" && searchStr[0]._EmpID!=null)
          {
            strWhere +="AND EMPLOYEE_ID ="+  searchStr[0]._EmpID;
          }    
          if(searchStr[0]._Title!="" && searchStr[0]._Title!=null)
          {
            strWhere+=" AND Title like '%"+searchStr[0]._Title+"%'"
          }      
           if(searchStr[0]._Content!="" && searchStr[0]._Content!=null)
          {
            strWhere+=" AND Content like '%"+searchStr[0]._Content+"%'"
          }     
    }
    else{
        strWhere+="AND ID=-1";
    }
   var strOrderBy="";
   if(order !="" && order != null)
   {
        var str=order.toUpperCase().replace(/ASC/i,"").replace(/DESC/i,"").replace(/\s/g, "");
        if(str !="ID"){
            strOrderBy=order+",ID DESC";
         }
        else{
            strOrderBy=order;
         }   
   }
  strSql += strWhere+" Order By "+strOrderBy;   //  window.clipboardData.setData("text",strSql);
    /*分页代码*/
    if(countTop >0){
         strSql="select TOP "+ pageSize +" (select count(ID) from ( " + strSql +")) as AllCount, * from (" + strSql +") where ID NOT IN (SELECT TOP "+ countTop +" ID from (" + strSql + "))";
    }
    else{
        strSql="select TOP "+ pageSize +" (select count(ID) from ( " + strSql +")) as AllCount,  * from (" + strSql +") ";
    }
 
    var strResult=DBReader.selectSqlForJson(strSql);
    var result;
    if(strResult!=null)
    {
        result=eval("[{"+strResult+"}]");
        result[0].pageIndex=pageIndex;    
    }
    strResult=null;strOrderBy=null;

    CollectGarbage();
    return strResult=null?null:result[0];
};

/*搜索*/
jsOtherInfo.OtherInfoSearchString=function(){
    var  strWhere=[];
    var strTitle=$("#txtOtherInfoTitle").val().split('\"').join('“').split('\'').join('‘');
    var strContent=$("#txtOtherInfoContent").val().split('\"').join('“').split('\'').join('‘');
    var empID=jsOtherInfo.GetEmpID();
    var comID=jsOtherInfo.GetComID();
    strWhere.push({_Title:strTitle,_Content:strContent,_EmpID:empID,_ComID:comID});
    $("#tbOtherInfoList").DoSearch(strWhere);
    document.getElementById("imgAddOtherInfoRow").style.display='';
}
/*清空*/
jsOtherInfo.CancelOtherInfo=function(){
    $("#txtOtherInfoTitle").val("");
    $("#txtOtherInfoContent").val("");    
    jsOtherInfo.OtherInfoSearchString();
}

/*联系人模式下——获取联系人ID*/
jsOtherInfo.GetEmpID=function(){
    var returnResult="";
    if(jsCallBookList.GetCurComOrEmpModel()=="Emp"){
        if(jsBookListModle.CurSeletedBookListGridRow!=null && jsBookListModle.CurSeletedBookListGridRow.attr("EMPLOYEE_ID")>0){
            returnResult=jsBookListModle.CurSeletedBookListGridRow.attr("EMPLOYEE_ID");
        }
        else if($("#hhideEmployeeID").val()>0){
            returnResult=$("#hhideEmployeeID").val();
        }
    }
    return returnResult;
};
/*公司模式下——获取公司ID*/
jsOtherInfo.GetComID=function(){
    var returnResult="";
    if(jsCallBookList.GetCurComOrEmpModel()=="Com"){
        if(jsAdrBookForCompany.CurCompanyGridSelRow!=null && jsAdrBookForCompany.CurCompanyGridSelRow.attr("COMPANY_ID")>0){
            returnResult=jsAdrBookForCompany.CurCompanyGridSelRow.attr("COMPANY_ID");
        }
        else if($("#hhideCompanyIDC").val()>0){
            returnResult=$("#hhideCompanyIDC").val();
        }
    }
    return returnResult;
}
/*根据公司ID获得联系人ID串*/
jsOtherInfo.GetEmpIDListByComID=function(comID){
   var returnResult="";
   var strSql="SELECT EMPLOYEE_ID FROM T_EMPLOYEE WHERE COMPANY_ID="+comID;
   var obj= DBReader.selectSqlForJson(strSql);//alert(obj);
    if(obj!=null)
    {
        var result=eval("[{"+obj+"}]");
        if(result[0].result==1 && result[0].table!=undefined)
        {
            for(var i=0;i<result[0].table.length;i++)
            {
                if(returnResult!="")
                {
                    returnResult+=",";
                }
                returnResult+=result[0].table[i].EMPLOYEE_ID;
            }
        }
        result=null;
    }    
    strSql=null;
    obj=null;
    CollectGarbage();
    return returnResult;
}

/*信息主题*/
jsOtherInfo.FormatDetailTitle=function(value,pid,rows){
    if(value.toString()!=""){
         return '<input id="txtOInfoTitle_'+pid+'" class="inputList" type="text" style="width:90%" value="'+value.toString()+'" />';
    }
    else{
         return '<input id="txtOInfoTitle_'+pid+'" class="inputList" type="text" style="width:90%"/>';
    }
};

/*信息内容*/
jsOtherInfo.FormatDetailContent=function(value,pid,rows){
    if(value.toString()!=""){
         return '<input id="txtOInfoContent_'+pid+'"  type="text" style="width:90%" class="inputList" value="'+value.toString()+'" />';
    }
    else{
         return '<input id="txtOInfoContent_'+pid+'" class="inputList" type="text" style="width:90%"/>';
    }
};

/*创建时间*/
jsOtherInfo.FormatCreateTime=function(value,pid,rows){
    App.SetNullHref(0);
    var nowTime=""    
    if(value.toString==""){
        var dt=new Date();
         nowTime=dt.Format("yyyy-MM-dd");        
    }else{
       var nowTime=new Date(Date.parse(value.replace(/-/g,"/")));       
    }         
    return '<input type="text" id="createTime_'+pid+'"  readonly="readonly" title="选择" class="Wdate" value="'+nowTime.Format("yyyy-MM-dd")+'"  onclick="WdatePicker({dateFmt:\'yyyy-MM-dd\',maxDate:\'2099-10-01\'})"/>';//onload="showRemindTime("createTime_'+pid+'");"
}

/*操作列*/
jsOtherInfo.operateDetailButton=function(value,pid,rows){
      return '<a onclick="jsOtherInfo.delOtherInfoMethod(\''+pid+'\');" style="cursor:pointer;"><img src="../AppFrame/APICss/default/ico/user_delete.gif" />删除</a>&nbsp;<a onclick="jsOtherInfo.SaveOtherInfo(\''+pid+'\');" style="cursor:pointer;"><img src="../AppFrame/APICss/default/ico/user_add.png" />保存</a>';
};

/*删除数据*/
jsOtherInfo.delOtherInfoMethod=function(rowID){
    var rowObj=jsOtherInfo.DetailOtherInfoTemplateGrid.getRowByID(rowID);
    if (window.confirm("确定删除吗？")) {
       var rowData = jsOtherInfo.DetailOtherInfoTemplateGrid.getRowData(rowObj);
       if(rowData[0].ID>0){
            var txtSql="DELETE * FROM T_OTHERINFO WHERE ID="+rowData[0].ID;
            DBReader.execSql(txtSql);
            txtSql=null;
       }
       rowData=null;
       jsOtherInfo.DetailOtherInfoTemplateGrid.deleteRow(rowObj.rowIndex);
    }
    rowObj=null;
    CollectGarbage();
};

/*保存数据*/
jsOtherInfo.SaveOtherInfo=function(rowID){
    var empID=jsOtherInfo.GetEmpID();
    var comID=jsOtherInfo.GetComID();
    var result=-1;
    if(empID>0 || comID>0){        
        var rowObj = jsOtherInfo.DetailOtherInfoTemplateGrid.getRowByID(rowID);
        var rowData = jsOtherInfo.DetailOtherInfoTemplateGrid.getRowData(rowObj);
        if(unescape(rowData[0].Title)!=""){
            var entity= jsEntity.CreateEntityByTableName_access("T_OTHERINFO");
            entity.Fields.COMPANY_ID=comID;
            entity.Fields.EMPLOYEE_ID=empID;
            entity.Fields.Title=unescape(rowData[0].Title);
            entity.Fields.Content=unescape(rowData[0].Content);     
            if(rowData[0].ID>0){
                entity.Fields.ID=rowData[0].ID;
                result=entity.Update(entity);
            }
            else{       
                entity.Fields.CreateTime=unescape(rowData[0].CreateTime);
                result=entity.Insert(entity);
            }
            
            if(result){
                jsOtherInfo.OtherInfoSearchString();
                alert("保存成功！");
            }
            else{
                alert("保存没有成功！");
            }
            DBReader.DisposeEntity(entity);
        }else{
            alert("标题不能为空！");
        }
        rowObj=null;
        rowData=null;        
     }
     else{
        alert("请先选择要添加资料的客户！");
     }
     
     empID=null;
     comID=null;
     CollectGarbage();
};

/*新增行*/
jsOtherInfo.AddOtherInfoRow=function(){
    var newRowObj= jsOtherInfo.DetailOtherInfoTemplateGrid.addRow(0);
    var dt=new Date();
    var nowTime=dt.Format("yyyy-MM-dd");
    var initValue = [{'ID':'', 'Title': '', 'Content': '','CreateTime':nowTime}];
    jsOtherInfo.DetailOtherInfoTemplateGrid.setRowData(newRowObj,initValue);
    newRowObj=null;
    dt=null;
    nowTime=null;
    initValue=null;
    CollectGarbage();
};

/*根据EMPLOYEE_ID删除数据*/
jsOtherInfo.DeleteOtherInfoByEmpID=function(empID){
    if(empID!=""){
        var txtSql="DELETE * FROM T_OTHERINFO WHERE EMPLOYEE_ID IN("+empID+")";
        DBReader.execSql(txtSql);
        txtSql=null;
        CollectGarbage();
    }
}
/*根据COMPANY_ID删除数据*/
jsOtherInfo.DeleteOtherInfoByComID=function(comID){
    if(comID>0){
        var strEmpIDList=jsOtherInfo.GetEmpIDListByComID(comID);
        var txtSql="DELETE * FROM T_OTHERINFO WHERE COMPANY_ID="+comID;
        if(strEmpIDList!=""){
            txtSql+=" or EMPLOYEE_ID IN('"+strEmpIDList+"')";
        }
        DBReader.execSql(txtSql);
        strEmpIDList=null;
        txtSql=null;
        CollectGarbage();
    }
}

/*选择其它资料便签*/
jsOtherInfo.LoadOtherInfoTab=function(){
      jsCallMiddlePanel.listNo="OtherInfo";   
      jsOtherInfo.initDetailOtherInfoGrid();/*其它资料列表*/ 
      if(jsOtherInfo.GetComID()>0 || jsOtherInfo.GetEmpID()>0){
        document.getElementById("imgAddOtherInfoRow").style.display='';    
        jsOtherInfo.OtherInfoSearchString();
      }
};