-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathImport.ascx.cs
178 lines (149 loc) · 6.38 KB
/
Import.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
//Engage: Locator - http://www.engagemodules.com
//Copyright (c) 2004-2007
//by Engage Software ( http://www.engagesoftware.com )
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
//TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
//THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
//CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
//DEALINGS IN THE SOFTWARE.
using System;
using System.Collections;
using System.Data;
using System.IO;
using System.Globalization;
using System.Web.UI.WebControls;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.FileSystem;
using DotNetNuke.Services.Localization;
using DotNetNuke.UI.UserControls;
using DotNetNuke.UI.Utilities;
using Engage.Dnn.Locator.Data;
using Engage.Dnn.Locator.Components;
using Engage.Dnn.Locator.Maps;
using FileInfo=DotNetNuke.Services.FileSystem.FileInfo;
using Globals=DotNetNuke.Common.Globals;
namespace Engage.Dnn.Locator
{
partial class Import : ModuleBase
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (DotNetNuke.Framework.AJAX.IsInstalled())
{
DotNetNuke.Framework.AJAX.RegisterScriptManager();
}
lbSettings.Visible = IsEditable;
lbManageComments.Visible = IsEditable;
lbManageLocations.Visible = IsEditable;
lbLocationTypes.Visible = IsEditable;
lgImport.InnerText = Localization.GetString("lgImport", LocalResourceFile);
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
if (fileImport.PostedFile == null || fileImport.PostedFile.ContentLength < 1)
{
lblMessage.Text = Localization.GetString("NoFileSelected", LocalResourceFile);
return;
}
if (!fileImport.PostedFile.FileName.EndsWith(".csv", StringComparison.OrdinalIgnoreCase))
{
lblMessage.Text = Localization.GetString("UseCSVFile", LocalResourceFile);
return;
}
else
{
lblMessage.Text = Localization.GetString("lblMessage", LocalResourceFile);
}
VerifyFolders();
UploadFile();
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
protected void UploadFile()
{
System.Web.HttpPostedFile postedFile = fileImport.PostedFile;
FolderInfo fi = FileSystemUtils.GetFolder(PortalId, "Location Import");
//ArrayList al = FileSystemUtils.GetFilesByFolder(PortalId, fi.FolderID);
string[] files = Directory.GetFiles(fi.PhysicalPath);
FileController fc = new FileController();
string fileName = Path.GetFileName(postedFile.FileName);
string newPath = fi.PhysicalPath + fileName;
foreach (string s in files)
{
if (s == fileName)
{
lblMessage.Text = Localization.GetString("FileExists", LocalResourceFile);
return;
}
}
postedFile.SaveAs(newPath);
string ext = Path.GetExtension(postedFile.FileName).Substring(1);
int fileId = fc.AddFile(PortalId, fileName,ext , postedFile.ContentLength, Null.NullInteger, Null.NullInteger, postedFile.ContentType, fi.FolderPath, fi.FolderID, true);
DataProvider provider = DataProvider.Instance();
provider.InsertFileInfo(fileId, UserId, TabModuleId, PortalId, DateTime.Now, false, false);
lblMessage.Text = Localization.GetString("FileUploaded", LocalResourceFile);
}
protected void VerifyFolders()
{
string loc = "Location Import";
string home = PortalSettings.HomeDirectoryMapPath;
string homeImport = PortalSettings.HomeDirectoryMapPath + loc;
string working = "Working";
string completed = "Completed";
string error = "Error";
if (FileSystemUtils.GetFolder(PortalId, loc) == null)
{
FileSystemUtils.AddFolder(PortalSettings, home, loc);
}
if (FileSystemUtils.GetFolder(PortalId, loc + "/" + working) == null)
{
FileSystemUtils.AddFolder(PortalSettings, homeImport, working);
}
if (FileSystemUtils.GetFolder(PortalId, loc + "/" + completed) == null)
{
FileSystemUtils.AddFolder(PortalSettings, homeImport, completed);
}
if (FileSystemUtils.GetFolder(PortalId, loc + "/" + error) == null)
{
FileSystemUtils.AddFolder(PortalSettings, homeImport, error);
}
}
protected void btnBack_Click(object sender, EventArgs e)
{
Response.Redirect(Globals.NavigateURL(TabId));
}
protected void Page_Load(object sender, EventArgs e)
{
// Global navigation
if (UserInfo.IsSuperUser)
{
lbImportFile.Enabled = false;
lbImportFile.CssClass = "mnavDisabled";
lbImportFile.ImageUrl = "~/desktopmodules/EngageLocator/images/importBtDisabled.gif";
}
string error = String.Empty;
if (MainDisplay.IsConfigured(TabModuleId, ref error))
{
if (!Page.IsPostBack)
{
}
}
else
{
lblConfigured.Visible = true;
lblConfigured.Text = lblConfigured.Text + " " + error;
}
}
protected void btnCancel_Click(object sender, EventArgs e)
{
Response.Redirect(Globals.NavigateURL(TabId));
}
}
}