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

所属分类: 网络编程 / ASP.NET 阅读数: 416
收藏 0 赞 0 分享

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" />
      &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
       &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
      <input type="reset" id="btnReset" value="重置" />
    </asp:Panel>
    <asp:Panel runat="server" ID="pnlEdit">
       <asp:Button runat="server" ID="btnUpdate" Text="更新" 
         onclick="btnUpdate_Click1" />
      &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
       &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
      <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日期记事功能的全部内容,希望大家会喜欢。

更多精彩内容其他人还在看

asp.net 虚方法、抽象方法、接口疑问

asp.net 虚方法、抽象方法、接口疑问等说明。
收藏 0 赞 0 分享

c#  操作符?? null coalescing operator

?? "null coalescing" operator 是c#新提供的一个操作符,这个操作符提供的功能是判断左侧的操作数是否是null,如果是则返回结果是右侧的操作数;非null则返回左侧的操作数。
收藏 0 赞 0 分享

.net 反序题目的详细解答第1/2页

在各种答案,以及平时面试过程中,这道题总归会有一些非常典型的错误发生。其中给老赵的感觉也非常有意思,不知其中的“思路”是否如老赵猜测那样。
收藏 0 赞 0 分享

implicitly convert type 'int' to 'short'的原因与解决方法

implicitly convert type 'int' to 'short'的原因与解决方法
收藏 0 赞 0 分享

比较完整的 asp.net 学习流程

好多朋友想学习后台编程语言,但请注意的事,学习后台是个循序渐进的过程,不可能一下就到位,其实不只是asp.net其它的编程语言都需要下面的一些知识。
收藏 0 赞 0 分享

官网 Ext direct包中.NET版的问题

下载了官网的 Ext direct 包进行研究,发现服务器端返回结果存在一点小问题。
收藏 0 赞 0 分享

C# XML操作 代码大全(读XML,写XML,更新,删除节点,与dataset结合等)第1/2页

C#操作XML(读XML,写XML,更新,删除节点,与dataset结合等),以下就是操作XML的所有方法,相信可以满足很大一部份的使用了。
收藏 0 赞 0 分享

c# 连接字符串数据库服务器端口号 .net状态服务器端口号

正常的数据库连接字符串配置,这是在MSSQL服务器端口是1433(默认)的情况下。
收藏 0 赞 0 分享

ASP.NET 路径问题的解决方法

相对路径和绝对路径在ASP.NET中可以用~/来解决.
收藏 0 赞 0 分享

asp.net TemplateField模板中的Bind方法和Eval方法

在TemplateField模板中为了能够有限制的或者取出数据库中某列的值时,可以用Bind和Eval方法来实现。以下是Bind方法的格式,Eval的格式也是和Bind一样的。 Bind("列的名称","显示的格式文")
收藏 0 赞 0 分享
查看更多