前段
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <script src="../script/jquery-1.9.1.js"></script> <script> $(document).ready(function () { $(".head").dblclick(function () { //获取日期 var dt = $(this).attr("aaa"); window.open(‘WoDeRiChengAdd.aspx?d=‘ + dt, ‘_blank‘, ‘width=450 height=350 toolbar=no‘); }); $(".body").dblclick(function () { //获得双击要修改的主键值 var key = $(this).attr("aaa"); window.open("WoDeRiChengEdit.aspx?id=" + key, "_blank", "width=450 height=350 toolbar=no"); }); }); </script> </head> <body> <form id="form1" runat="server"> <div> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/RiChengGuanLi/WoDeYueJiHuaAdd.aspx">编制新计划</asp:HyperLink> </div> <div align="center"> <h3 >我的月计划</h3> <table bgcolor="black" border="0" cellpadding="0" cellspacing="1"> <tr id="head"> <%=ShowDay() %></tr> <tr id="body"> <%=ShowDaySpan() %></tr> </table> </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; using System.Globalization; using System.Text; public partial class RiChengGuanLi_WoDeYueJiHua : System.Web.UI.Page { public string ShowDay() { StringBuilder builder = new StringBuilder(); builder.Append("<tr align=‘center‘ bgcolor=‘navy‘ style=‘color:white;font-weight:bold;‘>"); int year = DateTime.Now.Year; int month = DateTime.Now.Month; if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { for (int i = 1; i <= 31; i++) { builder.Append("<td width=‘30‘>"+i.ToString()+"</td>"); } } else if (month == 4 || month == 6 || month == 9 || month == 11) { for (int i = 1; i <= 30; i++) { builder.Append("<td width=‘30‘>" + i.ToString() + "</td>"); } } else { if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) { //闰年2月 for (int i = 1; i <= 29; i++) { builder.Append("<td width=‘30‘>" + i.ToString() + "</td>"); } } else { //平年2月 for (int i = 1; i <= 28; i++) { builder.Append("<td width=‘30‘>" + i.ToString() + "</td>"); } } } builder.Append("</tr>"); return builder.ToString(); //GregorianCalendar gc = new GregorianCalendar(); //DateTime dt =new DateTime(); ////int qq = dt.Day; ////int ww = dt.Year; ////int aa = dt.Month; //gc.GetDaysInMonth(dt.Year,dt.Month,21); //return null; } public string ShowDaySpan() { StringBuilder builder = new StringBuilder(); //查询本人本月所有的计划 List<MonthPlans> plans = new MonthPlansBF().SelectMonthPlans(Session["user"].ToString(), DateTime.Now.Month); foreach (MonthPlans data in plans) { builder.Append("<tr align=‘center‘ bgcolor=‘white‘ height=‘15‘ style=‘color:blue;font-weight:bold;‘>"); int year = DateTime.Now.Year; int month = DateTime.Now.Month; if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { for (int i = 1; i <= 31; i++) { List<MonthPlans> dayPlans = new MonthPlansBF().Select(data.PlanCode, new DateTime(year, month, i)); if (dayPlans.Count > 0) { TimeSpan ts = data.EndDay.Value - data.StartDay.Value; //计划开始与结束之间的时间间隔 int colspan = ts.Days+1; //要合并几个单元格 if (i == data.StartDay.Value.Day) //开始合并单元格的第一个单元格 { builder.Append("<td colspan=‘" + colspan + "‘ width=‘30‘ bgcolor=‘#FFFF00‘ title=‘" + data.Content + "‘>" + data.Content + "</td>"); } } else { builder.Append("<td width=‘30‘></td>"); } } } else if (month == 4 || month == 6 || month == 9 || month == 11) { for (int i = 1; i <= 30; i++) { List<MonthPlans> dayPlans = new MonthPlansBF().Select(data.PlanCode, new DateTime(year, month, i)); if (dayPlans.Count > 0) { builder.Append("<td width=‘30‘ bgcolor=‘#FFFF00‘></td>"); } else { builder.Append("<td width=‘30‘></td>"); } } } else { if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) { //闰年2月 for (int i = 1; i <= 29; i++) { List<MonthPlans> dayPlans = new MonthPlansBF().Select(data.PlanCode, new DateTime(year, month, i)); if (dayPlans.Count > 0) { builder.Append("<td width=‘30‘ bgcolor=‘#FFFF00‘></td>"); } else { builder.Append("<td width=‘30‘></td>"); } } } else { //平年2月 for (int i = 1; i <= 28; i++) { List<MonthPlans> dayPlans = new MonthPlansBF().Select(data.PlanCode, new DateTime(year, month, i)); if (dayPlans.Count > 0) { builder.Append("<td width=‘30‘ bgcolor=‘#FFFF00‘></td>"); } else { builder.Append("<td width=‘30‘></td>"); } } } } builder.Append("</tr>"); } return builder.ToString(); } public string ShowTimeSpan() { StringBuilder builder = new StringBuilder(); GregorianCalendar gc = new GregorianCalendar(); DateTime dt = new DateTime(); int n = gc.GetDaysInMonth(dt.Year, dt.Month); for (int i = 1; i <= n; i++) { builder.Append("<div style=‘height:30px;border-bottom:1px solid black;text-align:center;line-height:30px; vertical-align:middle‘>"); builder.Append(i.ToString("00")); builder.Append("</div>"); } return builder.ToString(); } protected void Page_Load(object sender, EventArgs e) { } }
MouthPlanBF
using System; using System.Collections.Generic; using System.Linq; using System.Web; public class MonthPlansBF { private DataClassesDataContext _Context = new DataClassesDataContext(); public List<MonthPlans> SelectMonthPlans(string owner, int month) { var query = _Context.MonthPlans.Where(p=>p.Owner == owner && p.StartDay.Value.Month == month); return query.ToList(); } public List<MonthPlans> Select(string planCode,DateTime date) { var query = _Context.MonthPlans.Where(p => p.PlanCode == planCode && date >= p.StartDay && date <= p.EndDay); return query.ToList(); } public void Insert(string planCode, string owner, DateTime start, DateTime end, string content, string responser, string method, string goal) { MonthPlans data = new MonthPlans { PlanCode = planCode, Owner = owner, StartDay = start, EndDay = end, Content = content, Responser = responser, Method = method, Goal = goal }; _Context.MonthPlans.InsertOnSubmit(data); _Context.SubmitChanges(); } }
sql server
时间: 2024-10-17 03:20:55