forked from openstore-ecommerce/OpenStore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrintView.aspx.cs
192 lines (170 loc) · 7.76 KB
/
PrintView.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
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
// --- Copyright (c) notice NevoWeb ---
// Copyright (c) 2014 SARL NevoWeb. www.nevoweb.com. The MIT License (MIT).
// Author: D.C.Lee
// ------------------------------------------------------------------------
// 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.
// ------------------------------------------------------------------------
// This copyright notice may NOT be removed, obscured or modified without written consent from the author.
// --- End copyright notice ---
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI.WebControls;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Users;
using DotNetNuke.Framework;
using NBrightCore.common;
using NBrightCore.render;
using NBrightDNN;
using Nevoweb.DNN.NBrightBuy.Admin;
using Nevoweb.DNN.NBrightBuy.Components;
using Nevoweb.DNN.NBrightBuy.Components.Interfaces;
namespace Nevoweb.DNN.NBrightBuy
{
/// -----------------------------------------------------------------------------
/// <summary>
/// The ViewNBrightGen class displays the content
/// </summary>
/// -----------------------------------------------------------------------------
public partial class PrintView : CDefault
{
private String _itemid = "";
private String _template = "";
private String _printcode = "";
private String _theme = "";
private String _printtype = "";
private String _scode = "";
#region Event Handlers
override protected void OnInit(EventArgs e)
{
base.OnInit(e);
try
{
_itemid = Utils.RequestParam(HttpContext.Current, "itemid");
_template = Utils.RequestParam(HttpContext.Current, "template");
_printcode = Utils.RequestParam(HttpContext.Current, "printcode");
_theme = Utils.RequestParam(HttpContext.Current, "theme");
_printtype = Utils.RequestParam(HttpContext.Current, "printtype");
_scode = Utils.RequestParam(HttpContext.Current, "scode");
}
catch (Exception exc)
{
//display the error on the template (don;t want to log it here, prefer to deal with errors directly.)
var l = new Literal();
l.Text = exc.ToString();
phData.Controls.Add(l);
}
}
protected override void OnLoad(EventArgs e)
{
try
{
base.OnLoad(e);
if (Page.IsPostBack == false)
{
PageLoad();
}
}
catch (Exception exc) //Module failed to load
{
//display the error on the template (don;t want to log it here, prefer to deal with errors directly.)
var l = new Literal();
l.Text = exc.ToString();
phData.Controls.Add(l);
}
}
private void PageLoad()
{
var portalId = PortalSettings.Current.PortalId;
var objUserInfo = UserController.Instance.GetCurrentUserInfo();
if (_theme == "") _theme = StoreSettings.Current.Get("emailthemefolder");
if (_theme == "") _theme = "ClassicRazor";
switch (_printcode)
{
case "printorder":
{
DisplayOrderData(portalId, objUserInfo, _itemid);
break;
}
case "printproduct":
{
DisplayProductData(portalId, _itemid);
break;
}
}
}
#endregion
#region "print display functions"
private void DisplayOrderData(int portalId, UserInfo userInfo, String entryId)
{
var strOut = "***ERROR*** Invalid Data";
if (Utils.IsNumeric(entryId) && entryId != "0")
{
var orderData = new OrderData(portalId, Convert.ToInt32(entryId));
if (orderData.PurchaseInfo.TypeCode == "ORDER")
{
strOut = "***ERROR*** Invalid Security";
if (_scode == orderData.PurchaseInfo.GetXmlProperty("genxml/securitycode") || userInfo.UserID == orderData.UserId || userInfo.IsInRole(StoreSettings.ManagerRole) || userInfo.IsInRole(StoreSettings.EditorRole) || userInfo.IsInRole(StoreSettings.SalesRole))
{
var doProv = false;
//check the payment provider for a print url
var shippingprovider = orderData.PurchaseInfo.GetXmlProperty("genxml/extrainfo/genxml/radiobuttonlist/shippingprovider");
if (shippingprovider != "")
{
var shipprov = ShippingInterface.Instance(shippingprovider);
if (shipprov != null)
{
if (_printtype == "shiplabel")
{
var printurl = shipprov.GetDeliveryLabelUrl(orderData.PurchaseInfo);
if (printurl != "")
{
doProv = true;
Response.Redirect(printurl);
}
}
}
}
if (!doProv)
{
var printtemplate = "printorder.cshtml";
var obj = new NBrightInfo(true);
obj.PortalId = PortalSettings.Current.PortalId;
obj.ModuleId = 0;
obj.Lang = Utils.GetCurrentCulture();
obj.GUIDKey = _printtype;
obj.ItemID = -1;
strOut = NBrightBuyUtils.RazorTemplRender(printtemplate, 0, "", obj, "/DesktopModules/NBright/NBrightBuy", _theme, Utils.GetCurrentCulture(), StoreSettings.Current.Settings());
}
}
}
}
var l = new Literal();
l.Text = strOut;
phData.Controls.Add(l);
}
private void DisplayProductData(int portalId, String entryId)
{
var strOut = "***ERROR*** Invalid Data";
if (Utils.IsNumeric(entryId) && entryId != "0")
{
var prodData = ProductUtils.GetProductData(Convert.ToInt32(entryId),Utils.GetCurrentCulture());
if (prodData.Exists)
{
var templCtrl = NBrightBuyUtils.GetTemplateGetter(_theme);
var strTempl = templCtrl.GetTemplateData(_template, Utils.GetCurrentCulture(), true, true, true, StoreSettings.Current.Settings());
strOut = GenXmlFunctions.RenderRepeater(prodData.Info, strTempl, "", "XMLData", Utils.GetCurrentCulture(), StoreSettings.Current.Settings());
if (_template.EndsWith(".xsl")) strOut = XslUtils.XslTransInMemory(prodData.Info.XMLData, strOut);
}
}
var l = new Literal();
l.Text = strOut;
phData.Controls.Add(l);
}
#endregion
}
}