-
Notifications
You must be signed in to change notification settings - Fork 0
/
NewsView.aspx.cs
135 lines (131 loc) · 4.46 KB
/
NewsView.aspx.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class NewsView : System.Web.UI.Page
{
DBClassDataContext db = new DBClassDataContext();
public clsSecurity Security = new clsSecurity();
clsLanguage lang = new clsLanguage();
string strLang = string.Empty;
public NewsView()
{
strLang = lang.LanguageCurrent;
}
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
BindNews();
BindContent();
clsDefault clsDefault = new clsDefault();
Response.Write(clsDefault.URLRouting("id"));
Response.Write(clsDefault.URLRouting("name"));
if (Security.LoginGroup == "Admin")
{
pnAdminButton.Visible = true;
//btAdmin.Visible = true;
}
}
}
private void BindNews()
{
var tbNews = from n in db.News
where n.StatusFlag == "A" && DateTime.Today >= n.ActiveDateFrom && (DateTime.Today <= n.ActiveDateTo || n.ActiveDateTo == null)
&& n.LanguageUID == findLangUID(strLang)
orderby n.ActiveDateFrom descending
select n;
gvNews.DataSource = tbNews;
gvNews.DataBind();
}
private void BindContent()
{
//Check Title
if (strLang == "th-TH")
{
lblTitle.Text = "ข่าวประชาสัมพันธ์";
lblSiteMap.Text = "ข่าวสารโรงพยาบาล > ข่าวประชาสัมพันธ์";
}
else if (strLang == "en-US")
{
lblTitle.Text = "News";
lblSiteMap.Text = "Hospital News > News";
}
else
{
lblTitle.Text = "ข่าวประชาสัมพันธ์";
lblSiteMap.Text = "ข่าวสารโรงพยาบาล > ข่าวประชาสัมพันธ์";
}
}
private int findLangUID(string LangShort)
{
int LangUID = 0;
try
{
var tbLang = from l in db.Languages
where l.Name == LangShort.Trim() && l.Active == '1'
select l;
foreach (Language l in tbLang)
{
LangUID = l.UID;
}
}
catch (Exception ex)
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Information", "alert('" + ex.ToString() + "')", true);
}
return LangUID;
}
protected void gvNews_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//ถ้า Login ให้แสดงปุ่ม Delete
if (Security.LoginGroup == "Admin")
{
((Button)e.Row.FindControl("btDelete")).Visible = true;
//((Button)e.Row.FindControl("btEdit")).Visible = true;
}
else//ถ้าไม่ได้ Login ให้ซ่อนปุ่ม Delete
{
((Button)e.Row.FindControl("btDelete")).Visible = false;
//((Button)e.Row.FindControl("btEdit")).Visible = false;
}
}
}
protected void gvNews_RowCommand(object sender, GridViewCommandEventArgs e)
{
int UID = Convert.ToInt32(e.CommandArgument);
//ถ้ากดปุ่ม Delete
if (e.CommandName == "DeleteNews")
{
var tbNews = from n in db.News
where n.UID == UID
select n;
foreach (New n in tbNews)
{
db.News.DeleteOnSubmit(n);
}
try
{
db.SubmitChanges();
}
catch (Exception ex)
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "Information", "alert('" + ex.ToString() + "')", true);
}
BindNews();
}
//ถ้ากดปุ่ม Edit
else if (e.CommandName == "EditNews")
{
ucColorBox1.IFrame("NewsForm.aspx?UID=" + UID + "", "90%", "90%", false);
}
}
//protected void btAdmin_Click(object sender, EventArgs e)
//{
// ucColorBox1.IFrame("NewsForm.aspx", "90%", "90%", true);
//}
}