/
checkout.aspx.cs
185 lines (160 loc) · 6.86 KB
/
checkout.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using E3zmni.BLL;
using System.Data;
using System.Net.Mail;
using System.Configuration;
namespace E3zemni_WebGUI
{
public partial class checkout : System.Web.UI.Page
{
public int EnverlopID
{
get
{
if (Request.QueryString["eid"] != null)
{
try
{
return int.Parse(Request.QueryString["eid"].ToString());
}
catch (Exception ex)
{
return 0;
}
}
else
{
return 0;
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["UserPayment"] != null)
{
BindOrder();
Master.PageTitle = "Checkout";
Master.Path = "";
Master.ViewPath = true;
}
}
}
private void BindOrder()
{
UserPayement order = new UserPayement();
order = (UserPayement)Session["UserPayment"];
if (EnverlopID != 0)
{
order.EnvelopID = EnverlopID;
order.EnvelopCount = 1;
}
uiRepeaterOrder.DataSource = order.DefaultView;
uiRepeaterOrder.DataBind();
}
protected void uiRepeaterOrder_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
Image envelop = (Image)e.Item.FindControl("uiImageEnvelop");
Label maxQty = (Label)e.Item.FindControl("uiLabelMaxQty");
Label Envdash = (Label)e.Item.FindControl("uiLabelEnvDash");
DataRowView row = (DataRowView)e.Item.DataItem;
Cards card = new Cards();
card.LoadByPrimaryKey(Convert.ToInt32(row["CardID"]));
if (card.IsColumnNull("IsPartySupplier"))
{
maxQty.Visible = true;
}
else if (card.IsPartySupplier)
{
maxQty.Visible = false;
}
else if (!card.IsPartySupplier)
{
maxQty.Visible = true;
}
if (EnverlopID != 0)
{
Envelops envelopTemp = new Envelops();
envelopTemp.LoadByPrimaryKey(Convert.ToInt32(row["EnvelopID"].ToString()));
envelop.ImageUrl = envelopTemp.ImagePath;
Envdash.Visible = false;
}
else
{
Envdash.Visible = true;
}
}
}
protected void uiLinkButtonCheckout_Click(object sender, EventArgs e)
{
UserPayement order = new UserPayement();
order = (UserPayement)Session["UserPayment"];
foreach (RepeaterItem dli in uiRepeaterOrder.Items)
{
if (dli.ItemType == ListItemType.Item || dli.ItemType == ListItemType.AlternatingItem)
{
TextBox CQty = (TextBox)dli.FindControl("uiTextBoxQty");
TextBox EQty = (TextBox)dli.FindControl("uiTextBoxEQty");
order.EnvelopCount = !string.IsNullOrEmpty(EQty.Text) ? Convert.ToInt32(EQty.Text) : 0;
order.CardCount = !string.IsNullOrEmpty(CQty.Text) ? Convert.ToInt32(CQty.Text) : 0;
}
}
if (Session["CurrentUser"] != null)
{
UserInfo user = (UserInfo)Session["CurrentUser"];
order.UserID = user.UserID;
order.Save();
MailMessage msg = new MailMessage();
if (Session["Order_Mail"] != null)
{
msg = (MailMessage)Session["Order_Mail"];
msg.Body = " Full Name : " + user.FullName +
"<br /> Address : " + user.UserAddress +
"<br /> Shipping Address : " + user.ShippingAddress +
"<br /> Phone : " + user.LandLine +
"<br /> Email: " + user.Email +
"<br/> UserName : " + user.UserName +
"<br />" + msg.Body;
msg.Body += "<br /> =========================================================== <br />";
msg.Body += " ========================= Order info ================== <br />";
msg.Body += " Order Number : " + order.PayementID.ToString();
msg.Body += "<br /> Card Quantity : " + order.CardCount.ToString();
if (order.EnvelopCount > 0 && !order.IsColumnNull("EnvelopID"))
{
Envelops env = new Envelops();
env.LoadByPrimaryKey(order.EnvelopID);
msg.Body += "<br /> Envelop count : " + order.EnvelopCount.ToString();
msg.Attachments.Add(new Attachment(Server.MapPath("~" + env.ImagePath)));
}
string mail = ConfigurationManager.AppSettings["mail"];
string mailto = ConfigurationManager.AppSettings["mailto"];
msg.To.Add(mailto);
msg.From = new MailAddress(mail);
msg.Subject = " New order - order no. " + order.PayementID.ToString();
SmtpClient client = new SmtpClient(ConfigurationManager.AppSettings["mailserver"], 25);
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(mail, ConfigurationManager.AppSettings["mailpass"]);
client.Send(msg);
Session["UserPayment"] = order;
Response.Redirect("Success.aspx");
}
/*order.UserID = user.UserID;
order.Save();
Session["UserPayment"] = null;
Response.Redirect("~/browse.aspx");*/
}
else
{
Response.Redirect("~/login.aspx?url=checkout.aspx");
}
}
}
}