Repository navigation
Expand file tree
/
Copy pathorder.aspx.cs
More file actions
123 lines (101 loc) · 4.16 KB
/
Copy pathorder.aspx.cs
File metadata and controls
123 lines (101 loc) · 4.16 KB
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
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
//using CrystalDecisions.Shared;
using CrystalDecisions.Web;
namespace JenStore
{
public partial class order1 : System.Web.UI.Page
{
string connect = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection con;
SqlCommand cmd;
SqlDataAdapter da;
DataSet ds;
private CrystalDecisions.CrystalReports.Engine.ReportDocument cr = new ReportDocument();
static string path = "";
protected void Page_Load(object sender, EventArgs e)
{
getcon();
if (Session["UserID"] == null)
{
Response.Redirect("login_register.aspx");
return;
}
if (!IsPostBack)
{
fillOrderDL();
}
}
void fillOrderDL()
{
int userId = Convert.ToInt32(Session["UserID"]);
int latestOrderId = 0;
cmd = new SqlCommand("select top 1 order_id from Orders where user_id = " + userId + " order by order_id desc", con);
object result = cmd.ExecuteScalar();
if (result == null || result == DBNull.Value)
{
orderDetailsContainer.Visible = false;
return;
}
latestOrderId = Convert.ToInt32(result);
decimal grandTotal = 0;
SqlDataAdapter da = new SqlDataAdapter("select order_date, order_status, payment_method, shipping_address, total_amount from Orders where order_id = " + latestOrderId, con);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
lblOrderID.Text = "#ORD-" + latestOrderId;
lblOrderDate.Text = Convert.ToDateTime(ds.Tables[0].Rows[0][0]).ToString("MMMM dd, yyyy");
lblOrderStatus.Text = ds.Tables[0].Rows[0][1].ToString();
lblPaymentMethod.Text = ds.Tables[0].Rows[0][2].ToString();
lblShippingAddress.Text = ds.Tables[0].Rows[0][3].ToString().Replace(", ", "<br />");
grandTotal = Convert.ToDecimal(ds.Tables[0].Rows[0][4]);
}
// Fetch the items from order details
SqlDataAdapter sda = new SqlDataAdapter("select od.quantity, od.price_at_purchase, p.product_name, p.image_url from OrderDetails od inner join Products p on od.product_id = p.product_id where od.order_id = " + latestOrderId, con);
DataTable dtItems = new DataTable();
sda.Fill(dtItems);
dlOrderItems.DataSource = dtItems;
dlOrderItems.DataBind();
// Calculate totals
decimal subTotal = 0;
foreach (DataRow row in dtItems.Rows)
{
subTotal += Convert.ToDecimal(row["price_at_purchase"]) * Convert.ToInt32(row["quantity"]);
}
decimal shippingFee = grandTotal - subTotal;
// Display totals
lblSubTotal.Text = subTotal.ToString("C");
lblShipping.Text = shippingFee.ToString("C");
lblGrandTotal.Text = grandTotal.ToString("C");
}
protected void btnDownloadInvoice_Click(object sender, EventArgs e)
{
getcon();
da = new SqlDataAdapter("select * from orders", con);
ds = new DataSet();
da.Fill(ds);
string xml = "D:/WorkSpaces/DotNet/JenStore/orders.xml";
ds.WriteXmlSchema(xml);
path = Server.MapPath("orders_rpt.rpt");
cr.Load(path);
cr.SetDataSource(ds);
cr.Database.Tables[0].SetDataSource(ds);
cr.Refresh();
CrystalReportViewer1.ReportSource = cr;
cr.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "Orders");
}
void getcon()
{
con = new SqlConnection(connect);
con.Open();
}
}
}