ASP.NET My97DatePicker日期控件实现OA日期记事功能
更新时间:2021年9月22日 10:08 点击:1716
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日期记事功能的全部内容,希望大家会喜欢。
相关文章
- 这篇文章主要为大家详细介绍了ASP.NET购物车的实现过程,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-09-22
- 这篇文章主要给大家介绍了关于C#创建自定义控件及添加自定义属性和事件使用的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用C#具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧...2020-06-25
- 在开发过程中,使用Visual Studio的断点调试功能可以很方便帮我们调试发现程序存在的错误,同样Visual Studio也支持对SQL Server里面的存储过程进行调试,下面就让我们看看具体的调试方法。...2021-09-22
- 这篇文章主要介绍了C#实现跨线程操作控件方法,主要采用异步访问方式实现,需要的朋友可以参考下...2020-06-25
- 一、日期减去天数等于第二个日期function cc(dd,dadd){//可以加上错误处理var a = new Date(dd)a = a.valueOf()a = a - dadd * 24 * 60 * 60 * 1000a = new Date(a)alert(a.getFullYear() + "年" + (a.getMonth() +...2015-11-08
- 本文实例讲述了php计算两个日期相差天数的方法。...2015-03-15
- 这篇文章主要介绍了PostgreSQL 字符串处理与日期处理操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-01
ASP.NET Core根据环境变量支持多个 appsettings.json配置文件
这篇文章主要介绍了ASP.NET Core根据环境变量支持多个 appsettings.json配置文件,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-09-22- 这篇文章主要介绍了记一次EFCore类型转换错误及解决方案,帮助大家更好的理解和学习使用asp.net core,感兴趣的朋友可以了解下...2021-09-22
- 实例讲解之前,先来介绍几个核心函数: mktime 函数 mktime() 函数返回一个日期的 Unix 时间戳。 参数总是表示 GMT 日期,因此 is_dst 对结果没有影响。 参数可以从右到左依次空着,空着的参数会被设为相应的当前 GMT 值。...2015-11-08
- moment是一款多语言支持的日期处理类库, 在vue中如何使用呢?这篇文章主要给大家介绍了关于vue之moment使用的相关资料,需要的朋友可以参考下...2021-05-13
- 这篇文章主要介绍了C#实现将字符串转换成日期格式的方法,涉及C#操作时间及字符串的相关技巧,非常简单实用,需要的朋友可以参考下...2020-06-25
- 分享一个利用php根据日期或时间戳获取相应的干支纪年,生肖和星座信息的函数方法,具体函数代码以及使用方法如下: /** 判断干支、生肖和星座 */ function birthext($birth){ if(strstr($birth,'-')===false&&strlen($bi...2015-10-21
- 这篇文章主要介绍了C# 如何设置label(标签)控件的背景颜色为透明,帮助大家更好的理解和使用c#,感兴趣的朋友可以了解下...2020-12-08
java8时间 yyyyMMddHHmmss格式转为日期的代码
这篇文章主要介绍了java8时间 yyyyMMddHHmmss格式转为日期的代码,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-09-17- 本篇文章是对C#中自定义控件的制作与使用实例进行了详细的分析介绍,需要的朋友参考下...2020-06-25
- 这篇文章主要为大家详细介绍了Bootstrap树形控件使用方法,感兴趣的小伙伴们可以参考一下...2016-01-29
详解ASP.NET Core 中基于工厂的中间件激活的实现方法
这篇文章主要介绍了ASP.NET Core 中基于工厂的中间件激活的实现方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-09-22- 这篇文章主要介绍了C#判断日期是否到期的方法,是C#程序设计中非常实用的技巧,需要的朋友可以参考下...2020-06-25
- 这篇文章主要介绍了C#实现根据指定容器和控件名字获得控件的方法,其中包括了遍历与递归的应用,需要的朋友可以参考下...2020-06-25