-
Notifications
You must be signed in to change notification settings - Fork 0
/
News.asmx.cs
117 lines (116 loc) · 4.6 KB
/
News.asmx.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Web.Services;
namespace SnnuWebService
{
/// <summary>
/// News 的摘要说明
/// </summary>
[WebService(Namespace = "http://webxml.zhaoqi.vip/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
// [System.Web.Script.Services.ScriptService]
public class News : System.Web.Services.WebService
{
private DAL.Message dal = new DAL.Message();
[WebMethod(Description =
"所支持查询的部门")]
public string[] getSupportDep()
{
List<string> ret = new List<string>();
MySqlDataReader reader = dal.AllDep();
while (reader.Read())
{
ret.Add(reader.GetValue(0).ToString());
}
reader.Close();
return ret.ToArray();
}
[WebMethod(Description =
"查询某个部门最近两周内的新闻")]
public Model.Message[] getNewsByDepartment(string dep)
{
List<Model.Message> ret = new List<Model.Message>();
MySqlDataReader reader = dal.QueryByDepartment(dep, "新闻");
while (reader.Read())
{
Model.Message temp = new Model.Message();
temp.Department = reader["Department"].ToString();
temp.Title = reader["Title"].ToString();
temp.Link = reader["Link"].ToString();
temp.Type = "新闻";
temp.Date = DateTime.Parse(reader["Date"].ToString());
ret.Add(temp);
}
return ret.ToArray();
}
[WebMethod(Description =
"查询以某个日期为准前后两周的新闻")]
public Model.Message[] getNewsByDate(string date)
{
List<Model.Message> ret = new List<Model.Message>();
DateTime d;
bool flag = DateTime.TryParse(date, out d);
if (flag == false)
return null;
DateTime start = d.AddDays(-7);
DateTime end = d.AddDays(7);
MySqlDataReader reader = dal.QueryByDate(start, end, "新闻");
while (reader.Read())
{
Model.Message temp = new Model.Message();
temp.Department = reader["Department"].ToString();
temp.Title = reader["Title"].ToString();
temp.Link = reader["Link"].ToString();
temp.Type = "新闻";
temp.Date = DateTime.Parse(reader["Date"].ToString());
ret.Add(temp);
}
return ret.ToArray();
}
[WebMethod(Description =
"查询某个部门的某个日期前后两周的新闻")]
public Model.Message[] getNewsByDepartmentAndDate(string dep, string date)
{
List<Model.Message> ret = new List<Model.Message>();
DateTime d;
bool flag = DateTime.TryParse(date, out d);
if (flag == false)
return null;
DateTime start = d.AddDays(-7);
DateTime end = d.AddDays(7);
MySqlDataReader reader = dal.QueryByDateAndDep(start, end, dep, "新闻");
while (reader.Read())
{
Model.Message temp = new Model.Message();
temp.Department = reader["Department"].ToString();
temp.Title = reader["Title"].ToString();
temp.Link = reader["Link"].ToString();
temp.Type = "通知";
temp.Date = DateTime.Parse(reader["Date"].ToString());
ret.Add(temp);
}
return ret.ToArray();
}
[WebMethod(Description =
"通过标题查询新闻(模糊查询)")]
public Model.Message[] getNewsByLikeTitle(string keyword)
{
List<Model.Message> ret = new List<Model.Message>();
MySqlDataReader reader = dal.QueryByLikeTitle(keyword, "新闻");
while (reader.Read())
{
Model.Message temp = new Model.Message();
temp.Department = reader["Department"].ToString();
temp.Title = reader["Title"].ToString();
temp.Link = reader["Link"].ToString();
temp.Type = "新闻";
temp.Date = DateTime.Parse(reader["Date"].ToString());
ret.Add(temp);
}
return ret.ToArray();
}
}
}