ASP.NET My97DatePicker日期控件實(shí)現(xiàn)OA日期記事功能
My97DatePicker日期控件是一個(gè)非常好用的日期控件,功能非常優(yōu)秀的日期控件.
對(duì)實(shí)現(xiàn)頁面刷新完善的很好,用日期控件時(shí)可以有比較好的享受,這次的OA日期記事功能也得益于此控件,具體效果圖如下:
部分代碼:
Default頁布局一個(gè)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) { //獲取現(xiàn)在綁定的日期 CalendarDay day = e.Day; //獲取當(dāng)前日期的單元格 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"; } } }
控件編輯前臺(tái)代碼:
<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 /> 日程內(nèi)容:<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 /> 結(jié)束日期:<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="提交對(duì)日程的修改中出現(xiàn)了以下問題:" /><br /> </div> </form> </body>
控件編輯后臺(tái)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; } }
以上就是關(guān)于My97DatePicker日期控件實(shí)現(xiàn)OA日期記事功能的全部?jī)?nèi)容,希望大家會(huì)喜歡。
相關(guān)文章
asp.net下實(shí)現(xiàn)URL重寫技術(shù)的代碼
asp.net下實(shí)現(xiàn)URL重寫技術(shù)的代碼...2007-10-10ASP.NET實(shí)現(xiàn)的生成驗(yàn)證碼功能示例【附demo源碼】
這篇文章主要介紹了ASP.NET實(shí)現(xiàn)的生成驗(yàn)證碼功能,結(jié)合實(shí)例形式較為詳細(xì)的分析了asp.net生成驗(yàn)證碼的原理、步驟與相關(guān)實(shí)現(xiàn)技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2017-07-07ASP.NET技巧:請(qǐng)求網(wǎng)址并解析返回的html
ASP.NET技巧:請(qǐng)求網(wǎng)址并解析返回的html...2006-09-09建立自定義的數(shù)據(jù)驅(qū)動(dòng)的本地化資源provider
本文探討了自定義的本地化資源提供者.如果想用一個(gè)可替代系統(tǒng)的資源處理方案,例如把所有的資源放入數(shù)據(jù)庫中,而不是放在分散的資源文件里,你可以自定義一個(gè)resource provider.2010-06-06時(shí)間輕松學(xué)會(huì).NET Core操作ElasticSearch7的方法
這篇文章主要介紹了時(shí)間輕松學(xué)會(huì).NET Core操作ElasticSearch7,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04asp.net core webapi文件上傳功能的實(shí)現(xiàn)
這篇文章主要介紹了asp.net core webapi文件上傳功能的實(shí)現(xiàn),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-12-12MVC微信網(wǎng)頁授權(quán)獲取用戶OpenId
這篇文章主要為大家詳細(xì)介紹了MVC微信網(wǎng)頁授權(quán),在模板頁中獲取用戶openid,感興趣的小伙伴們可以參考一下2016-09-09GridView高效分頁和搜索功能的實(shí)現(xiàn)代碼
GridView高效分頁和搜索功能的實(shí)現(xiàn)代碼,需要的朋友可以參考一下2013-03-03Mvc動(dòng)態(tài)注冊(cè)HttpModule詳解
本文主要介紹了Mvc動(dòng)態(tài)注冊(cè)HttpModule的方法。具有很好的參考價(jià)值,下面跟著小編一起來看下吧2017-03-03