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

来源:互联网 发布:如何弄死一个淘宝店铺 编辑:程序博客网 时间:2024/06/06 23:50

部分代码:
Default页布局一个Calendar日期控件

?
1
2
3
4
5
<div>
   <asp:CalendarID="Calendar1"runat="server"Width="100%"
     ShowGridLines="True"ondayrender="Calendar1_DayRender">
   </asp:Calendar>
 </div>

Default页cs代码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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;
 
publicpartial class_Default : System.Web.UI.Page
{
  privateDataTable table ;
 
  protectedvoid Page_Load(objectsender, EventArgs e)
  {
     
  }
  protectedvoid Calendar1_DayRender(objectsender, DayRenderEventArgs e)
  {
    //获取现在绑定的日期
    CalendarDay day = e.Day;
    //获取当前日期的单元格
    TableCell cell = e.Cell;
 
    intcurrentMonth = 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";
 
      intindex = 1;
      foreach(DataRow row inplanRows)
      {
        stringtitle = 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(newLiteralControl(builder.ToString()));
    }
    else
    {
      cell.Style["background-color"] ="#E9E9E9";
    }
  }
 
 
   
}

控件编辑前台代码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<headrunat="server">
  <title></title>
  <scripttype="text/javascript"language="javascript"src="My97DatePicker/WdatePicker.js">
  </script>
  <scripttype="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>
  <formid="form1"runat="server">
  <h3>日程信息</h3>
  <div>
    日程主题:<asp:TextBoxrunat="server"ID="txtTitle"Width="270px"
      BorderColor="#0066FF"BorderStyle="Solid"BorderWidth="1px"></asp:TextBox> <br/>
    日程内容:<asp:TextBoxrunat="server"ID="txtContent"TextMode="MultiLine"Height="96px"></asp:TextBox> <br/>
    起始日期:<asp:TextBoxrunat="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:TextBoxrunat="server"ID="txtEndDate"CssClass="Wdate"onfocus="WdatePicker({minDate:'%y-%M-01',dateFmt:'yyyy-MM-dd HH:mm',maxDate:'%y-%M-%ld'})"/></asp:TextBox>
    <asp:Panelrunat="server"ID="pnlNew">
      <asp:Buttonrunat="server"ID="btnInsertPlan"Text="添加"
        onclick="btnInsertPlan_Click"/>
                  
                  
      <inputtype="reset"id="btnReset"value="重置"/>
    </asp:Panel>
    <asp:Panelrunat="server"ID="pnlEdit">
       <asp:Buttonrunat="server"ID="btnUpdate"Text="更新"
         onclick="btnUpdate_Click1"/>
                  
                  
      <asp:Buttonrunat="server"ID="btnDelete"Text="删除"onclick="btnDelete_Click"
         />
      <asp:HiddenFieldrunat="server"ID="hidPlanID"/>
    </asp:Panel>
    <asp:ValidationSummaryID="ValidationSummary1"runat="server"
      HeaderText="提交对日程的修改中出现了以下问题:"/><br />
  </div>
  </form>
</body>

控件编辑后台cs:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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
{
  publicDateTime StartDate
  {
    get{ return (DateTime)this.ViewState["StartDate"]; }
    set{ this.ViewState["StartDate"] = value; }
  }
 
  publicDateTime EndDate
  {
    get{ return (DateTime)this.ViewState["EndDate"]; }
    set{ this.ViewState["EndDate"] = value; }
  }
 
   
 
  protectedvoid Page_Load(objectsender, EventArgs e)
  {
    if(this.Request.QueryString.Count != 2)
    {
      this.Response.End();
      return;
    }
 
    if(!this.IsPostBack)
    {
      stringaction = 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":
          intplanID = 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;
      }
    }
  }
 
  protectedvoid btnInsertPlan_Click(objectsender, EventArgs e)
  {
    inti=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;
  }
 
  protectedvoid btnUpdate_Click1(objectsender, EventArgs e)
  {
    inti = 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;
  }
 
  protectedvoid btnDelete_Click(objectsender, EventArgs e)
  {
    inti = 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;
  }
}


0 0
原创粉丝点击