/
Setting_ManagerImportExport.ascx.cs
191 lines (129 loc) · 5.19 KB
/
Setting_ManagerImportExport.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
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using DotNetNuke.Services.Localization;
using DotNetNuke.Common;
using System.Web.Script.Serialization;
using System.Text;
namespace DNNGo.Modules.DNNGalleryPro
{
public partial class Setting_ManagerImportExport : BaseModule
{
#region "==属性=="
/// <summary>
/// 提示操作类
/// </summary>
MessageTips mTips = new MessageTips();
private List<KeyValueEntity> ImportPictureList = new List<KeyValueEntity>();
#endregion
#region "==方法=="
#endregion
#region "==事件=="
/// <summary>
/// 页面加载
/// </summary>
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
//如果查询到当前有字段时,需要给用户提示会清除掉原有的字段
cmdImportFormXml.Attributes.Add("onClick", "javascript:return confirm('" + Localization.GetString("ImportContent", this.LocalResourceFile) + "');");
}
}
catch (Exception ex)
{
DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(this, ex);
}
}
/// <summary>
/// 导出数据到XML
/// </summary>
protected void cmdExportToXml_Click(object sender, EventArgs e)
{
try
{
ImportExportHelper ieHelper = new ImportExportHelper();
ieHelper.ModuleID = ModuleId;
ieHelper.UserId = UserId;
StringBuilder PostContent = new StringBuilder();
PostContent.Append( ieHelper.Export());
if (PostContent != null && PostContent.Length >0 )
{
PostContent.AppendLine()
.AppendLine().Append(" ")
.AppendLine()
.AppendLine()
.AppendLine()
.AppendLine()
.AppendLine().Append(" ");
Response.Clear();
Response.ClearContent();
Response.AddHeader("Content-disposition", "attachment;filename=DNNGalleryPro.xml");
Response.AddHeader("content-length", PostContent.Length.ToString());
Response.ContentEncoding = Encoding.UTF8;
Response.ContentType = "text/xml";
Response.Write(PostContent);
Response.Flush();
Response.Close();
Response.End();
}
else
{
//没有可导出的文章条目
mTips.IsPostBack = true;
mTips.LoadMessage("ExportContentError", EnumTips.Success, this, new String[] { "" });
}
}
catch (Exception ex)
{
DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(this, ex);
}
}
/// <summary>
/// 从XML导入数据
/// </summary>
protected void cmdImportFormXml_Click(object sender, EventArgs e)
{
try
{
HttpPostedFile hpfile = fuImportFormXml.PostedFile;
if (hpfile.ContentLength > 0)
{
if (Path.GetExtension(hpfile.FileName).IndexOf(".xml", StringComparison.CurrentCultureIgnoreCase) >= 0)
{
ImportExportHelper ieHelper = new ImportExportHelper();
ieHelper.ModuleID = ModuleId;
ieHelper.UserId = UserId;
Int32 InsertResult = ieHelper.Import(hpfile);
//提示
mTips.LoadMessage("ImportContentSuccess", EnumTips.Success, this, new String[] { InsertResult.ToString() });
//跳转
Response.Redirect(xUrl("ManagerList"));
}
else
{
//上传文件的后缀名错误
mTips.IsPostBack = true;
mTips.LoadMessage("ImportContentExtensionError", EnumTips.Success, this, new String[] { "" });
}
}
else
{
//为上传任何数据
mTips.IsPostBack = true;
mTips.LoadMessage("ImportContentNullError", EnumTips.Success, this, new String[] { "" });
}
}
catch (Exception ex)
{
DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(this, ex);
}
}
#endregion
}
}