当前位置: 移动技术网 > IT编程>开发语言>.net > ASP.NET My97DatePicker日期控件实现OA日期记事功能

ASP.NET My97DatePicker日期控件实现OA日期记事功能

2017年12月12日  | 移动技术网IT编程  | 我要评论

裸婚时代的女主角,朝鲜宣布实施大赦,pioneerl1621a

my97datepicker日期控件是一个非常好用的日期控件,功能非常优秀的日期控件.
对实现页面刷新完善的很好,用日期控件时可以有比较好的享受,这次的oa日期记事功能也得益于此控件,具体效果图如下:

部分代码:
default页布局一个calendar日期控件

 <div>
    <asp:calendar id="calendar1" runat="server" width="100%" 
      showgridlines="true" ondayrender="calendar1_dayrender" >
    </asp:calendar>
  </div>

default页cs代码:

using system;
using system.collections.generic;
using system.linq;
using system.web;
using system.web.ui;
using system.web.ui.webcontrols;
using system.data;
using system.text;

public partial class _default : system.web.ui.page 
{
  private datatable table ;

  protected void page_load(object sender, eventargs e)
  {
    
  }
  protected void calendar1_dayrender(object sender, dayrendereventargs e)
  {
    //获取现在绑定的日期
    calendarday day = e.day;
    //获取当前日期的单元格
    tablecell cell = e.cell;

    int currentmonth = datetime.now.month ;
    cell.controls.clear();
    table = planoperator.selectplanbymonth(day.date);
    if (day.date.month >= currentmonth)
    {
      stringbuilder builder = new stringbuilder();
      builder.appendformat("<font color='blue'><h5>{0}</h5></font><img src='images/add.png' alt='添加日程' onclick='window.open(\"editplan.aspx?action=new&startdate={0}\",\"\",\"menu=no,tool=no,status=no,width=400,height=500\");' /> <br/>", day.date.toshortdatestring());
      datarow[] planrows = table.select(string.format("startdate<='{0}' and enddate>='{1}' ", day.date, day.date.adddays(1)));

      cell.style["background-color"] = planrows.length <= 0 ? "#e9e9e9" : "#ffffff";

      int index = 1;
      foreach (datarow row in planrows)
      {
        string title = row["title"].tostring().length > 10 ? row["title"].tostring().substring(0, 10) + "..." : row["title"].tostring();
        builder.appendformat("<a onclick='window.open(\"editplan.aspx?action=edit&planid={1}\",\"\",\"menu=no,tool=no,status=no,width=400,height=500\");'>{0}.{2}</a><br/>", index, row["planid"], title);
        index++;
        continue;
      }

      cell.controls.add(new literalcontrol(builder.tostring()));
    }
    else
    {
      cell.style["background-color"] = "#e9e9e9"; 
    }
  }


  
}

控件编辑前台代码:

<head runat="server">
  <title></title>
  <script type="text/javascript" language="javascript" src="my97datepicker/wdatepicker.js">
  </script>
  <script type="text/javascript" language="javascript">
    function valistartdate(source, clientside_arguments) {
      if (clientside_arguments.value > new date()) {
        clientside_arguments.isvalid = true;
      }
      else {
        clientside_arguments.isvalid = false;
      }
    }
  </script>
</head>
<body>
  <form id="form1" runat="server">
  <h3>日程信息</h3>
  <div >
    日程主题:<asp:textbox runat="server" id="txttitle" width="270px" 
      bordercolor="#0066ff" borderstyle="solid" borderwidth="1px" ></asp:textbox> <br />
    日程内容:<asp:textbox runat="server" id="txtcontent" textmode="multiline" height="96px"></asp:textbox> <br />
    起始日期:<asp:textbox runat="server" id="txtstartdate" cssclass="wdate" onfocus="wdatepicker({mindate:'%y-%m-01',datefmt:'yyyy-mm-dd hh:mm',maxdate:'%y-%m-%ld'})" /></asp:textbox>
    <br />
    结束日期:<asp:textbox runat="server" id="txtenddate" cssclass="wdate" onfocus="wdatepicker({mindate:'%y-%m-01',datefmt:'yyyy-mm-dd hh:mm',maxdate:'%y-%m-%ld'})" /></asp:textbox>
    <asp:panel runat="server" id="pnlnew">
      <asp:button runat="server" id="btninsertplan" text="添加" 
        onclick="btninsertplan_click" />
                 
                 
      <input type="reset" id="btnreset" value="重置" />
    </asp:panel>
    <asp:panel runat="server" id="pnledit">
       <asp:button runat="server" id="btnupdate" text="更新" 
         onclick="btnupdate_click1" />
                 
                 
      <asp:button runat="server" id="btndelete" text="删除" onclick="btndelete_click" 
         />
      <asp:hiddenfield runat="server" id="hidplanid" />
    </asp:panel>
    <asp:validationsummary id="validationsummary1" runat="server" 
      headertext="提交对日程的修改中出现了以下问题:" /><br />
  </div>
  </form>
</body>

控件编辑后台cs:

using system;
using system.collections.generic;
using system.linq;
using system.web;
using system.web.ui;
using system.web.ui.webcontrols;
using system.data;

public partial class editplan : system.web.ui.page
{
  public datetime startdate
  {
    get { return (datetime)this.viewstate["startdate"]; }
    set { this.viewstate["startdate"] = value; }
  }

  public datetime enddate
  {
    get { return (datetime)this.viewstate["enddate"]; }
    set { this.viewstate["enddate"] = value; }
  }

  

  protected void page_load(object sender, eventargs e)
  {
    if (this.request.querystring.count != 2)
    {
      this.response.end();
      return;
    }

    if (!this.ispostback)
    {
      string action = this.request.querystring["action"];


      switch (action)
      {
        case "new":
          this.startdate = convert.todatetime(this.request.querystring["startdate"]);
          this.enddate = new datetime(datetime.now.year, datetime.now.month, (datetime.now.addmonths(1) - datetime.now).days);
          this.pnlnew.visible = true;
          this.pnledit.visible = false;
          break;
        case "edit":
          int planid = convert.toint32(this.request.querystring["planid"]);
          datatable table = planoperator.selectplanbyid(planid);
          this.txttitle.text = table.rows[0]["title"].tostring();
          this.txtcontent.text = table.rows[0]["plancontent"].tostring();
          this.txtstartdate.text = table.rows[0]["startdate"].tostring();
          this.txtenddate.text = table.rows[0]["enddate"].tostring();
          this.hidplanid.value = table.rows[0]["planid"].tostring();
          this.pnlnew.visible = false;
          this.pnledit.visible = true;
          break;
        default:
          break;
      }
    }
  }

  protected void btninsertplan_click(object sender, eventargs e)
  {
    int i=planoperator.insertplan(this.txttitle.text, this.txtcontent.text,this.txtstartdate.text, this.txtenddate.text);
    if (i == 1)
    {
      this.response.write("<script type='text/javascript' language='javascript'>alert('添加日程成功!'); window.opener.location=window.opener.location+'?'+math.random();window.opener='';window.close();</script>");
      return;
    }
    this.response.write("<script type='text/javascript' language='javascript'>alert('添加日程失败!'); window.opener.location=window.opener.location+'?'+math.random();window.opener='';window.close();</script>");
    return;
  }

  protected void btnupdate_click1(object sender, eventargs e)
  {
    int i = planoperator.updateplan(convert.toint32(this.hidplanid.value),this.txttitle.text, this.txtcontent.text, this.txtstartdate.text, this.txtenddate.text);
    if (i == 1)
    {
      this.response.write("<script type='text/javascript' language='javascript'>alert('更新日程成功!'); window.opener.location=window.opener.location+'?'+math.random();window.opener='';window.close();</script>");
      return;
    }
    this.response.write("<script type='text/javascript' language='javascript'>alert('更新日程失败!'); window.opener.location=window.opener.location+'?'+math.random();window.opener='';window.close();</script>");
    return;
  }

  protected void btndelete_click(object sender, eventargs e)
  {
    int i = planoperator.deleteplan(convert.toint32(this.hidplanid.value));
    if (i == 1)
    {
      this.response.write("<script type='text/javascript' language='javascript'>alert('删除日程成功!'); window.opener.location=window.opener.location+'?'+math.random();window.opener='';window.close();</script>");
      return;
    }
    this.response.write("<script type='text/javascript' language='javascript'>alert('删除日程失败!'); window.opener.location=window.opener.location+'?'+math.random();window.opener='';window.close();</script>");
    return;
  }
}

以上就是关于my97datepicker日期控件实现oa日期记事功能的全部内容,希望大家会喜欢。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网