-
Notifications
You must be signed in to change notification settings - Fork 0
/
Manager_Library.ascx.cs
645 lines (495 loc) · 23.4 KB
/
Manager_Library.ascx.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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetNuke.Services.Localization;
using DotNetNuke.Entities.Users;
using System.IO;
namespace Playngo.Modules.ClientZone
{
public partial class Manager_Library : BaseModule
{
#region "属性"
/// <summary>
/// 提示操作类
/// </summary>
MessageTips mTips = new MessageTips();
/// <summary>
/// 当前页码
/// </summary>
public Int32 PageIndex = WebHelper.GetIntParam(HttpContext.Current.Request, "PageIndex", 1);
/// <summary>
/// 文件类型
/// </summary>
public Int32 FileType = WebHelper.GetIntParam(HttpContext.Current.Request, "type", -1);
/// <summary>
/// 文章搜索_标题
/// </summary>
public String Search_Title = WebHelper.GetStringParam(HttpContext.Current.Request, "SearchText", "");
/// <summary>
/// 可见性
/// </summary>
public Int32 Visibility = WebHelper.GetIntParam(HttpContext.Current.Request, "Visibility", -1);
/// <summary>
/// 总页码数
/// </summary>
public Int32 RecordPages
{
get;
set;
}
/// <summary>
/// 当前页面URL(不包含分页)
/// </summary>
public String CurrentUrl
{
get
{
List<String> urls = new List<String>();
if (FileType >= 0)
{
urls.Add(String.Format("type={0}", FileType));
}
if (!String.IsNullOrEmpty(Orderfld))
{
urls.Add(String.Format("sort_f={0}", Orderfld));
}
if (OrderType == 0)
{
urls.Add(String.Format("sort_t={0}", OrderType));
}
if (!String.IsNullOrEmpty(Search_Title))
{
urls.Add(String.Format("SearchText={0}", Search_Title));
}
if (Visibility >= 0)
{
urls.Add(String.Format("Visibility={0}", Visibility));
}
return xUrl("", "", Token, urls.ToArray());
}
}
/// <summary>
/// 排序字段
/// </summary>
public string Orderfld = WebHelper.GetStringParam(HttpContext.Current.Request, "sort_f", "");
/// <summary>
/// 排序类型 1:降序 0:升序
/// </summary>
public int OrderType = WebHelper.GetIntParam(HttpContext.Current.Request, "sort_t", 1);
#endregion
#region "方法"
/// <summary>
/// 绑定列表
/// </summary>
private void BindDataList()
{
QueryParam qp = new QueryParam();
qp.OrderType = OrderType;
if (!String.IsNullOrEmpty(Orderfld))
{
qp.Orderfld = Orderfld;
}
else
{
qp.Orderfld = Playngo_ClientZone_Files._.ID;
}
#region "分页的一系列代码"
int RecordCount = 0;
int pagesize = qp.PageSize = Settings_General_ManagerPerPage;
qp.PageIndex = PageIndex;
#endregion
//查询的方法
qp.Where = BindSearch();
List<Playngo_ClientZone_Files> Comments = Playngo_ClientZone_Files.FindAll(qp, out RecordCount);
qp.RecordCount = RecordCount;
RecordPages = qp.Pages;
lblRecordCount.Text = String.Format("{0} {2} / {1} {3}", RecordCount, RecordPages, ViewResourceText("Title_Items", "Items"), ViewResourceText("Title_Pages", "Pages"));
Boolean is_admin = !IsAdministrator && !IsAdmin;
hlFileMateAll.Text = String.Format("{1} ({0})", Playngo_ClientZone_Files.FindCountByType(PortalId, Visibility, - 1, is_admin, UserId), ViewResourceText("hlFileMateAll", "All"));
hlFileMateImage.Text = String.Format("{1} ({0})", Playngo_ClientZone_Files.FindCountByType(PortalId, Visibility, (Int32)EnumFileMate.Image, is_admin, UserId), ViewResourceText("hlFileMateImage", "Image"));
hlFileMateZip.Text = String.Format("{1} ({0})", Playngo_ClientZone_Files.FindCountByType(PortalId, Visibility, (Int32)EnumFileMate.Zip, is_admin, UserId), ViewResourceText("hlFileMateZip", "Zip"));
hlFileMateVideo.Text = String.Format("{1} ({0})", Playngo_ClientZone_Files.FindCountByType(PortalId, Visibility, (Int32)EnumFileMate.Video, is_admin, UserId), ViewResourceText("hlFileMateVideo", "Video"));
hlFileMateDoc.Text = String.Format("{1} ({0})", Playngo_ClientZone_Files.FindCountByType(PortalId, Visibility, (Int32)EnumFileMate.Doc, is_admin, UserId), ViewResourceText("hlFileMateDoc", "Doc"));
//ctlPagingControl.TotalRecords = RecordCount;
//if (RecordCount <= pagesize)
//{
// ctlPagingControl.Visible = false;
//}
gvCommentList.DataSource = Comments;
gvCommentList.DataBind();
BindGridViewEmpty<Playngo_ClientZone_Files>(gvCommentList, new Playngo_ClientZone_Files());
}
/// <summary>
/// 绑定页面项
/// </summary>
private void BindPageItem()
{
hlFileMateAll.NavigateUrl = xUrl("Visibility", Visibility.ToString(), Token);
hlFileMateImage.NavigateUrl = xUrl("type", ((Int32)EnumFileMate.Image).ToString(),Token, String.Format("Visibility={0}", Visibility));
hlFileMateZip.NavigateUrl = xUrl("type", ((Int32)EnumFileMate.Zip).ToString(), Token, String.Format("Visibility={0}", Visibility));
hlFileMateVideo.NavigateUrl = xUrl("type", ((Int32)EnumFileMate.Video).ToString(), Token, String.Format("Visibility={0}", Visibility));
hlFileMateDoc.NavigateUrl = xUrl("type", ((Int32)EnumFileMate.Doc).ToString(), Token, String.Format("Visibility={0}", Visibility));
switch (FileType)
{
case -1: hlFileMateAll.CssClass = "btn btn-default active"; break;
case (Int32)EnumFileMate.Image: hlFileMateImage.CssClass = "btn btn-default active"; break;
case (Int32)EnumFileMate.Zip: hlFileMateZip.CssClass = "btn btn-default active"; break;
case (Int32)EnumFileMate.Video: hlFileMateVideo.CssClass = "btn btn-default active"; break;
case (Int32)EnumFileMate.Doc: hlFileMateDoc.CssClass = "btn btn-default active"; break;
default: hlFileMateAll.CssClass = "btn btn-default active"; break;
}
//hlAddNewLink.NavigateUrl = xUrl("AddMedia");
//插入图片按钮的连接
hlAddNewLink.Attributes.Add("data-href", String.Format("{0}Resource_jQueryFileUpload.aspx?ModuleId={1}&PortalId={2}&TabId={3}&Visibility={4}", ModulePath, ModuleId, PortalId, TabId, Visibility));
//同步图片等设置的菜单
hlSynchronizeFiles.NavigateUrl = xUrl("Visibility", Visibility.ToString(), "Synchronize");
DotNetNuke.UI.Utilities.ClientAPI.RegisterKeyCapture(txtSearch, btnSearch, 13);
}
/// <summary>
/// 绑定查询的方法
/// </summary>
private List<SearchParam> BindSearch()
{
List<SearchParam> Where = new List<SearchParam>();
Where.Add(new SearchParam("PortalId", PortalId, SearchType.Equal));
//Where.Add(new SearchParam("ModuleId", ModuleId, SearchType.Equal));
//不是管理员,只能看到自己发布文章的评论
if (!IsAdministrator && !IsAdmin)
{
Where.Add(new SearchParam(Playngo_ClientZone_Files._.LastUser, UserId, SearchType.Equal));
}
//else if (ViewSettingT<string>("General.MediaLibrary", "public") == "private")
//{
// Where.Add(new SearchParam(Playngo_ClientZone_Files._.LastUser, UserId, SearchType.Equal));
//}
//筛选文章的状态
if (FileType >= 0)
{
Where = Playngo_ClientZone_Files.ByType(Where, FileType);
}
if (!String.IsNullOrEmpty(Search_Title))
{
txtSearch.Text = HttpUtility.UrlDecode(Search_Title);
Where.Add(new SearchParam(Playngo_ClientZone_Files._.Name, HttpUtility.UrlDecode(Search_Title), SearchType.Like));
}
if (Visibility >= 0)
{
Where.Add(new SearchParam(Playngo_ClientZone_Files._.Extension1, Visibility, SearchType.Equal));
}
return Where;
}
/// <summary>
/// 批量改名
/// 由于之前导入文件会把多加一个.zip的名称
/// 暂时不删除
/// </summary>
public void BatchReNames()
{
Int32 ReName = WebHelper.GetIntParam(Request, "rename", 0);
if (ReName > 0)
{
Int32 RecordCount = 0;
QueryParam qp = new QueryParam();
if (Visibility >= 0)
{
qp.Where.Add(new SearchParam(Playngo_ClientZone_Files._.Extension1, Visibility, SearchType.Equal));
}
qp.Where.Add(new SearchParam(Playngo_ClientZone_Files._.FileName, ".zip.zip", SearchType.Like));
List<Playngo_ClientZone_Files> Files = Playngo_ClientZone_Files.FindAll(qp, out RecordCount);
if (Files != null && Files.Count > 0)
{
foreach (var file in Files)
{
//得到新的文件名称和路径
String NewFileName = Common.ReplaceNoCase(file.FileName, ".zip.zip", ".zip");
String NewFilePath = Common.ReplaceNoCase(file.FilePath, ".zip.zip", ".zip");
var NewFileInfo = new FileInfo(MapPath(String.Format("{0}{1}", PortalSettings.HomeDirectory, NewFilePath)));
//得到老的文件路径
var OldFileInfo = new FileInfo(MapPath(String.Format("{0}{1}", PortalSettings.HomeDirectory, file.FilePath)));
//需要将存储的文件更名
OldFileInfo.MoveTo(NewFileInfo.FullName);
//需要移除掉重复的文件名
file.FileName = NewFileName;
//需要移除掉路径中重复的文件名
file.FilePath = NewFilePath;
//保存当前的修改
file.Update();
}
}
}
}
#endregion
#region "事件"
/// <summary>
/// 页面加载
/// </summary>
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
//BatchReNames();
BindDataList();
BindPageItem();
}
}
catch (Exception ex)
{
ProcessModuleLoadException( ex);
}
}
/// <summary>
/// 列表行创建
/// </summary>
protected void gvCommentList_RowCreated(object sender, GridViewRowEventArgs e)
{
Int32 DataIDX = 0;
if (e.Row.RowType == DataControlRowType.Header)
{
//增加check列头全选
TableCell cell = new TableCell();
cell.Width = Unit.Pixel(5);
cell.Text = "<label> <input id='CheckboxAll' value='0' type='checkbox' class='input_text' onclick='SelectAll()'/></label>";
e.Row.Cells.AddAt(0, cell);
foreach (TableCell var in e.Row.Cells)
{
if (var.Controls.Count > 0 && var.Controls[0] is LinkButton)
{
string Colume = ((LinkButton)var.Controls[0]).CommandArgument;
if (Colume == Orderfld)
{
LinkButton l = (LinkButton)var.Controls[0];
l.Text += string.Format("<i class=\"fa {0}{1}\"></i>", Orderfld == "Title" ? "fa-sort-alpha-" : "fa-sort-amount-", (OrderType == 0) ? "asc" : "desc");
}
}
}
}
else
{
//增加行选项
DataIDX = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "ID"));
TableCell cell = new TableCell();
cell.Width = Unit.Pixel(5);
cell.Text = string.Format("<label> <input name='Checkbox' id='Checkbox' value='{0}' type='checkbox' type-item=\"true\" class=\"input_text\" /></label>", DataIDX);
e.Row.Cells.AddAt(0, cell);
}
}
/// <summary>
/// 列表行绑定
/// </summary>
protected void gvCommentList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//还原出数据
Playngo_ClientZone_Files Media = e.Row.DataItem as Playngo_ClientZone_Files;
if (Media != null && Media.ID > 0)
{
#region "编辑&删除按钮"
HyperLink hlEdit = e.Row.FindControl("hlEdit") as HyperLink;
HyperLink hlMobileEdit = e.Row.FindControl("hlMobileEdit") as HyperLink;
LinkButton btnRemove = e.Row.FindControl("btnRemove") as LinkButton;
LinkButton btnMobileRemove = e.Row.FindControl("btnMobileRemove") as LinkButton;
//设置按钮的CommandArgument
btnRemove.CommandArgument = btnMobileRemove.CommandArgument = Media.ID.ToString();
//设置删除按钮的提示
//if (Media.Status == (Int32)EnumFileStatus.Recycle)
//{
btnRemove.Attributes.Add("onClick", "javascript:return confirm('" + Localization.GetString("DeleteItem") + "');");
btnMobileRemove.Attributes.Add("onClick", "javascript:return confirm('" + Localization.GetString("DeleteItem") + "');");
//}
//else
//{
// btnRemove.Attributes.Add("onClick", "javascript:return confirm('" + ViewResourceText("DeleteRecycleItem", "Are you sure to move it to recycle bin?") + "');");
// btnMobileRemove.Attributes.Add("onClick", "javascript:return confirm('" + ViewResourceText("DeleteRecycleItem", "Are you sure to move it to recycle bin?") + "');");
//}
hlEdit.NavigateUrl = hlMobileEdit.NavigateUrl = xUrl("ID", Media.ID.ToString(), "AddMedia");
#endregion
//发布者信息
e.Row.Cells[3].Text = "--";
if (Media.LastUser > 0)
{
UserInfo uInfo = UserController.GetUserById(PortalId, Media.LastUser);
if (uInfo != null && uInfo.UserID > 0) e.Row.Cells[3].Text = String.Format("{0}<br />{1}", uInfo.Username, uInfo.DisplayName);
}
//发布时间
e.Row.Cells[4].Text = Media.LastTime.ToShortDateString();
//状态
e.Row.Cells[5].Text = EnumHelper.GetEnumTextVal( Media.Status ,typeof(EnumFileStatus));
Label lblFileExtension = e.Row.FindControl("lblFileExtension") as Label;
lblFileExtension.Text = Media.FileExtension;
Image imgFileName = e.Row.FindControl("imgFileName") as Image;
HyperLink hlFileName = e.Row.FindControl("hlFileName") as HyperLink;
hlFileName.Text = Media.FileName.Replace("." + Media.FileExtension, "");
imgFileName.ImageUrl = GetPhotoExtension(Media.FileExtension, Media.FilePath);
hlFileName.NavigateUrl = GetPhotoPath(Media.FilePath);
Label lblSize = e.Row.FindControl("lblSize") as Label;
if (Media.FileSize > 1024)
{
lblSize.Text = String.Format("{0} MB", Media.FileSize/1024);
}
else
{
lblSize.Text = String.Format("{0} KB", Media.FileSize);
}
}
}
}
/// <summary>
/// 列表排序
/// </summary>
protected void gvCommentList_Sorting(object sender, GridViewSortEventArgs e)
{
if (Orderfld == e.SortExpression)
{
if (OrderType == 0)
{
OrderType = 1;
}
else
{
OrderType = 0;
}
}
Orderfld = e.SortExpression;
//BindDataList();
Response.Redirect(CurrentUrl, false);
}
/// <summary>
/// 列表上的项删除事件
/// </summary>
protected void btnRemove_Click(object sender, EventArgs e)
{
try
{
LinkButton btnRemove = (LinkButton)sender;
if (btnRemove != null && !String.IsNullOrEmpty(btnRemove.CommandArgument))
{
mTips.IsPostBack = true;
Playngo_ClientZone_Files Multimedia = Playngo_ClientZone_Files.FindByKeyForEdit(btnRemove.CommandArgument);
if (Multimedia != null && Multimedia.ID > 0)
{
//if (Multimedia.Status == (Int32)EnumFileStatus.Recycle)
//{
//要删除实际的文件
String DeletePath = Server.MapPath(GetPhotoPath(Multimedia.FilePath));
if (Multimedia.Delete() > 0)
{
//删除文件
if (File.Exists(DeletePath))
{
File.Delete(DeletePath);
}
//操作成功
mTips.LoadMessage("DeleteMediaLibrarySuccess", EnumTips.Success, this, new String[] { Multimedia.FileName });
}
else
{
//操作失败
mTips.LoadMessage("DeleteMediaLibraryError", EnumTips.Success, this, new String[] { Multimedia.FileName });
}
//}
//else
//{
// Multimedia.Status = (Int32)EnumFileStatus.Recycle;
// if (Multimedia.Update() > 0)
// {
// //移动到回收站操作成功
// mTips.LoadMessage("DeleteCommentSuccess", EnumTips.Success, this, new String[] { Multimedia.FileName });
// }
// else
// {
// //移动到回收站操作失败
// mTips.LoadMessage("DeleteCommentError", EnumTips.Success, this, new String[] { Multimedia.FileName });
// }
//}
BindDataList();
}
}
}
catch (Exception ex)
{
ProcessModuleLoadException( ex);
}
}
/// <summary>
/// 搜索按钮事件
/// </summary>
protected void btnSearch_Click(object sender, EventArgs e)
{
try
{
Search_Title = HttpUtility.UrlEncode(txtSearch.Text.Trim());
Response.Redirect(CurrentUrl, false);
}
catch (Exception ex)
{
ProcessModuleLoadException( ex);
}
}
/// <summary>
/// 状态应用按钮事件
/// </summary>
protected void btnApply_Click(object sender, EventArgs e)
{
try
{
Int32 Status = WebHelper.GetIntParam(Request, ddlStatus.UniqueID, -1);
if (Status >= 0)
{
string Checkbox_Value = WebHelper.GetStringParam(Request, "Checkbox", "");
string[] Checkbox_Value_Array = Checkbox_Value.Split(',');
Int32 IDX = 0;
mTips.IsPostBack = true;
for (int i = 0; i < Checkbox_Value_Array.Length; i++)
{
if (Int32.TryParse(Checkbox_Value_Array[i], out IDX))
{
Playngo_ClientZone_Files Multimedia = Playngo_ClientZone_Files.FindByKeyForEdit(IDX);
if (Multimedia != null && Multimedia.ID > 0)
{
//if (Multimedia.Status == (Int32)EnumFileStatus.Recycle && Status == (Int32)EnumFileStatus.Recycle)
//{
//要删除实际的文件
String DeletePath = Server.MapPath(GetPhotoPath(Multimedia.FilePath));
if (Multimedia.Delete() > 0)
{
//删除文件
if (File.Exists(DeletePath))
{
File.Delete(DeletePath);
}
//操作成功
mTips.LoadMessage("DeleteMediaLibrarySuccess", EnumTips.Success, this, new String[] { Multimedia.FileName });
}
else
{
//操作失败
mTips.LoadMessage("DeleteMediaLibraryError", EnumTips.Success, this, new String[] { Multimedia.FileName });
}
//}
//else
//{
// Multimedia.Status = Status;
// if (Multimedia.Update() > 0)
// {
// }
//}
}
}
}
BindDataList();
}
}
catch (Exception ex)
{
ProcessModuleLoadException( ex);
}
}
#endregion
}
}