您现在的位置: 军旅同心 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 文章正文
带日期标注的日历控件
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 13:17:33
控件名称:Calendar with Date Mark
版    本:1.0
类    型:HTML Component
运行需求:IE 5(推荐IE5.5或更高版本)、MSXML、ASP或ASP.NET(后台)
费    用:免费
支    持:不提供支持
源 代 码:XML Scriptlet
------------------------------------------------------------------------
<public:attach event="oncontentready" onevent="init()"/>
<public:property name="value" get="getValue" put="setValue"/>
<public:property name="stringValue" get="getStringValue" />
<public:property name="mark" get="getCurrentMark" put="setCurrentMark" />
<public:property name="markList" get="getMarkList" />
<public:method name="refresh" />
<public:method name="addMark" />
<public:method name="removeMark" />
<public:method name="removeAllMark" />
<public:method name="loadMark" />
<public:method name="saveMark" />
<public:event name="onvaluechange" id="vlcg" />
<script language="JScript">

//----------------------------------------------------------------
//  HTML Component : Calendar with date mark(带时间标注的日历控件)
//
//  Version        : 1.0
//
//  Request        : Microsoft IE 5 or up
//
//  Author         : JoJo
//
//  Last Realse    : 5/9/2001
//
//  Copyright      : Think Space Soft Tec
//
//  Contact        : thinkspace@163.net
//----------------------------------------------------------------

var date = new Date();
var activeDate = new Date();

var marklist = new ActiveXObject("Scripting.Dictionary");

function WriteXMLToDictionary(xmldoc,dict,rewrite){
  var xnodelist = xmldoc.documentElement.selectNodes("Mark");
  if (rewrite) dict.RemoveAll();
  for (var i=0;i<xnodelist.length;i++){
    var xnode = xnodelist.item(i);
    var xdate = xnode.selectSingleNode("MarkDate");
    var xnote = xnode.selectSingleNode("Note");
    //alert(xdate.text + "," + xnote.text);
    if (xdate.text && xnote.text){
      dict.item(xdate.text) = xnote.text;
    }
  }
}

function postxml(xmldoc,url){
  var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  xmlhttp.Open("POST",url,false);
  xmlhttp.Send(xmldoc);
  var xdoc = new ActiveXObject("Microsoft.XMLDom");
  xdoc.async = false;
  xdoc.loadXML(xmlhttp.responseText);
  return !!xdoc.documentElement.text;
}

function saveMark(url){
  var xmldoc = new ActiveXObject("Microsoft.XMLDom");
  WriteDictionaryToXML(marklist,xmldoc);
  if(postxml(xmldoc,url)){
    refresh();
    sendEvent();
    return true;
  }
  return false;
}

function WriteDictionaryToXML(dict,xmldoc){
  xmldoc.loadXML("<MarkList/>");
  var keys = (new VBArray(dict.Keys())).toArray();
  for (var i=0;i<keys.length;i++){
    try{
      var d = new Date(keys[i]);
    }catch(e){
      continue;
    }
    if (!dict.item(keys[i])) continue;
    var xmark = xmldoc.createElement("Mark");
    var xmarkdate = xmldoc.createElement("MarkDate");
    xmarkdate.text = dateToSortString(d);
    var xnote = xmldoc.createElement("Note");
    xnote.text = dict.item(keys[i]);
    xmark.appendChild(xmarkdate);
    xmark.appendChild(xnote);
    xmldoc.documentElement.appendChild(xmark);
  }
}

function loadMark(url,rewrite){
  var xmldoc = new ActiveXObject("Microsoft.FreeThreadedXMLDOM");
  xmldoc.async = false;
  xmldoc.load(url);
  //alert(xmldoc.xml);
  WriteXMLToDictionary(xmldoc,marklist,rewrite);
  refresh();
  sendEvent();
}

function refresh(){
  fillCalendar(date);
}

function getCurrentMark(){
  if(!getMark(activeDate)) return "";
  return getMark(activeDate);
}

function setCurrentMark(markvalue){
  addMark(activeDate,markvalue);
}

function getMarkList(){
  return marklist;
}

function dateToSortString(adate){
  return (adate.getMonth()+1) + "/" + adate.getDate() + "/" + adate.getFullYear();
}

function getMark(adate){
  if (marklist.Exists(dateToSortString(adate)))
    return marklist.Item(dateToSortString(adate));
}

function addMark(adate,note){
  if (!note) return false;
  try{
    var d = new Date(adate);
    marklist.item(dateToSortString(d)) = note;
    fillCalendar(date);
    return true;
  }catch(e){
    return false;
  }
}

function removeMark(adate){
  try
  {
    marklist.Remove(dateToSortString(adate));
    fillCalendar(date);
  }catch(e){
  }
}

function removeAllMark(){
  marklist.RemoveAll();
  fillCalendar(date);
}

function sendEvent(){
  var oevent = createEventObject();
  vlcg.fire(oevent);
}

function getStringValue(){
  return activeDate.getFullYear() + "年" + (activeDate.getMonth() + 1) + "月" + activeDate.getDate() + "日";
}

function getValue(){
  return activeDate;
}

function setValue(invalue){
  try{
    var tdate = new Date(invalue);
    activeDate.setFullYear(tdate.getFullYear(),tdate.getMonth(),tdate.getDate());
    date.setFullYear(tdate.getFullYear(),tdate.getMonth(),tdate.getDate());
    fillCalendar(date);
    sendEvent();
  }catch(e){
    return;
  }
}
function fillCalendar(adate){
  ynm.innerText = adate.getFullYear() + "年" + (adate.getMonth() + 1) + "月";
  var tempdate = new Date();
  tempdate.setFullYear(adate.getFullYear(),adate.getMonth(),1);
  var first = true;
  for (var i=0;i<tblbd.rows.length;i++){
    for (var j=0;j<tblbd.rows(i).cells.length;j++){
      var cell = tblbd.rows(i).cells(j);
      cell.innerHTML = "&nbsp;";
      cell.bgcolor = "";
      cell.title = "";
      cell.style.backgroundColor = "";
      
      if (tempdate.getDay() == j){
        if (!first) continue;
        cell.innerText = tempdate.getDate();

        if (getMark(tempdate)){
          cell.bgcolor = "wheat";
          cell.style.backgroundColor = cell.bgcolor;
          var tt = getMark(tempdate);
          if (tt.length<20)
            cell.title = tt
          else
            cell.title = tt.substr(0,20) + "...";
        }
        
        if (tempdate.getDate() == activeDate.getDate()){
          hightLightDate(cell);
        }
        
        tempdate.setFullYear(tempdate.getFullYear(),tempdate.getMonth(),tempdate.getDate()+1);
        first = tempdate.getDate() > 1;
      }
    }
  }
}

function hightLightDate(object){
  var tds = tblbd.all.tags

[1] [2] 下一页


 
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 网站公告 | 管理登录 |