asp.net get图

前段

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
<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>

  后端

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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
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 

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
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

posted @   人走茶亦凉  阅读(168)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示