用日历存储信息

日历显示主界面

<body>
<form id="form1" runat="server">
<div>
<asp:Calendar ID="Calendar1" runat="server" CellPadding="0" FirstDayOfWeek="Sunday" NextMonthText="下一月" OnDayRender="Calendar1_DayRender" OnSelectionChanged="Calendar1_SelectionChanged" PrevMonthText="上一月" ShowGridLines="True" Width="100%">
<DayHeaderStyle BackColor="#6666FF" />
<DayStyle Font-Bold="True" Height="80px" HorizontalAlign="Right" VerticalAlign="Top" />
<OtherMonthDayStyle ForeColor="#CCCCCC" />

</asp:Calendar>
</div>
</form>
</body>

显示界面后端代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

public partial class Show : System.Web.UI.Page
{
private MydbDataContext _Context = new MydbDataContext();
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
e.Cell.Controls.Clear();
//造一个Label 对象 给每个格加上日期标题
Label lab = new Label();
lab.Text = e.Day.Date.Day.ToString();
//修改标签样式

lab.Width = Unit.Percentage(100);
lab.BackColor = Color.Maroon;
lab.ForeColor = Color.White;
lab.Font.Italic =true;
lab.Font.Bold = true;

//给标题栏标题添加双击弹出添加窗口的JS
lab.Attributes.Add("ondblclick", "window.open('Add.aspx?dt="+e.Day.Date.Date.ToString("yyyy-MM-dd")+"','_blank','top=200 left=300 width=350 height=350 tolbar=no location=no')");
e.Cell.Controls.Add(lab);


//加载日程
//2个date 是取年月日 不要时分秒
var var1 = _Context.RiLi.Where(p => p.Date == e.Day.Date.Date);
if(var1.Count()>0)
{
foreach(RiLi data in var1)
{
//造日程项,加到日历的单元格中
Label lblItem = new Label();
lblItem.Text = data.Title;
lblItem.Width = Unit.Percentage(100);
lblItem.BackColor = Color.FromName(data.Color);
lblItem.Attributes.Add("ondblclick", "window.open('Eidt.aspx?id="+data.Ids+"','_blank','top=200 left=300 width=350 height=350 toolbar=no location=no')");
lblItem.ToolTip = data.Content;
e.Cell.Controls.Add(lblItem);
}
}

}

添加日历进程界面

</head>
<body>
<form id="form1" runat="server">
<h1 align="center">添加日程</h1>
<div align="center" style="background-color:#98a5d7">

日期:<asp:Label ID="txtriqi" runat="server" Text="Label"></asp:Label>
<br />
标题<asp:TextBox ID="txtbiaoti" runat="server" Width="186px"></asp:TextBox>
<br />
内容:<br />
<asp:TextBox ID="txtneirong" runat="server" Height="97px" TextMode="MultiLine" Width="287px"></asp:TextBox>
<br />
颜色<asp:RadioButtonList ID="txtcolor" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow">
<asp:ListItem Value="#ffcccc">&lt;font color=red&gt;红色&lt;/font&gt;</asp:ListItem>
<asp:ListItem Value="#ffffcc">&lt;font color=#ffffcc&gt;黄色&lt;/font&gt;</asp:ListItem>
<asp:ListItem Value="#ccffcc">&lt;font color=#ccffcc&gt;绿色&lt;/font&gt;</asp:ListItem>
<asp:ListItem Value="#ccccff">&lt;font color=#ccccff&gt;蓝色&lt;/font&gt;</asp:ListItem>
<asp:ListItem Selected="True" Value="#ffffff">白色</asp:ListItem>
</asp:RadioButtonList>

<br />
<asp:Button ID="butAdd" runat="server" Text="添加日程" OnClick="butAdd_Click" />
<input id="Reset1" type="reset" value="重置" /><asp:Literal ID="Literal1" runat="server"></asp:Literal>
</div>
</form>
</body>

添加日历进程后端代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Add : System.Web.UI.Page
{
private MydbDataContext _Context = new MydbDataContext();
protected void Page_Load(object sender, EventArgs e)
{
if(Request["dt"]!=null)
{
txtriqi.Text = Request["dt"].ToString();
}
}
protected void butAdd_Click(object sender, EventArgs e)
{
//取界面数据
DateTime date = Convert.ToDateTime(txtriqi.Text);
string title = txtbiaoti.Text;
string content = txtneirong.Text;
string color = txtcolor.SelectedValue;
//送到数据库中区
RiLi data = new RiLi();
data.Date = date;
data.Title = title;
data.Content = content;
data.Color = color;

_Context.RiLi.InsertOnSubmit(data);
_Context.SubmitChanges();
//关闭当前窗口,刷新原窗口。

Literal1.Text = "<script language=javascript>opener.location.reload();window.close();</script>";
}
}

修改删除界面

<title></title>
</head>
<body>
<h1 align="center">修改日程</h1>
<form id="form1" runat="server">
<div align="center">

日期:<asp:Label ID="labdate" runat="server" Text="Label"></asp:Label>
<br />
标题:<asp:TextBox ID="txtbiaoti" runat="server"></asp:TextBox>
<br />
内容:
<br />
<asp:TextBox ID="txtneirong" runat="server" Height="123px" TextMode="MultiLine" Width="218px"></asp:TextBox>
<br />
颜色:<asp:RadioButtonList ID="txtcolor" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="#ffcccc">&lt;font color=#ffcccc&gt;红色&lt;/font&gt;</asp:ListItem>
<asp:ListItem Value="#ffffcc">&lt;span style=&#39;background-color:#ffff00&#39;&gt;黄色&lt;/span&gt;</asp:ListItem>
<asp:ListItem Value="#ccffcc">绿色</asp:ListItem>
<asp:ListItem Value="#ccccff">蓝色</asp:ListItem>
<asp:ListItem Selected="True" Value="#FFFFFF">白色</asp:ListItem>
</asp:RadioButtonList>
<asp:Button ID="OK" runat="server" Text="更新" OnClick="OK_Click" />
<input id="Reset1" type="reset" value="重置" /><asp:Button ID="Button1" runat="server" Text="删除日志" OnClick="Button1_Click" />
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
<asp:Literal ID="Literal2" runat="server"></asp:Literal>
</div>
</form>
</body>
</html>

修改删除后端代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Eidt : System.Web.UI.Page
{
private MydbDataContext _Context = new MydbDataContext();

//把数据库中的值取出来放在页面上显示
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
if(Request["id"]!=null)
{
var var = _Context.RiLi.Where(p => p.Ids == Convert.ToInt32(Request["id"]));
if(var.Count()>0)
{
RiLi data = var.First();
labdate.Text = data.Date.Value.ToString("yyyy-MM-dd");
txtbiaoti.Text = data.Title;
txtneirong.Text = data.Content;
txtcolor.SelectedValue = data.Color;
}
}
}
}

//修改按钮
protected void OK_Click(object sender, EventArgs e)
{
DateTime date =Convert.ToDateTime (labdate.Text);
string title = txtbiaoti.Text;
string content = txtneirong.Text;
string color = txtcolor.Text;

//查数据
var query = _Context.RiLi.Where(p=>p.Ids == Convert.ToInt32(Request["id"]));

//把值改一下 
if (query.Count() > 0)
{
RiLi data = query.First();
data.Date = date;
data.Title = title;
data.Content = content;
data.Color = color;

//送到数据库中去

_Context.SubmitChanges();
}
Literal1.Text = "<script language='javascript'>opener.location.reload();window.close();</script>";

}
protected void Button1_Click(object sender, EventArgs e)
{
//删除
var var = _Context.RiLi.Where(p => p.Ids ==Convert.ToInt32 (Request["id"]));
if(var.Count()>0)
{
RiLi data = var.First();

_Context.RiLi.DeleteOnSubmit(data);
_Context.SubmitChanges();

//关闭当前页面  刷新显示页面

Literal1.Text = "<script language='javascript'>opener.location.reload();window.close();</script>";

}
}
}

原文地址:https://www.cnblogs.com/tianxuan/p/4749127.html