-
Notifications
You must be signed in to change notification settings - Fork 0
/
order_list.aspx.cs
227 lines (159 loc) · 6.85 KB
/
order_list.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.Windows;
using Microsoft.Reporting.WebForms;
using Microsoft.Reporting.Common;
using Microsoft.Reporting;
public partial class order_list : System.Web.UI.Page
{
// public DataGrid gridview_inventory{get; set;} UPDATE Table SET Field=CONCAT(Field,'your extra html');
public string html_table{get;set;}
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["shopingConnectionString1"].ConnectionString);
//
protected void Page_Load(object sender, EventArgs e)
{
// Declare the query string.
String queryString =
"SELECT [productName] as 'order_product_name' ,[brand],[catagory],[desciption] ,[quantity] as 'order_quantity' FROM [product]";
// Run the query and bind the resulting DataSet
// to the GridView control.
DataSet ds = GetData(queryString);
DataTable dt = new DataTable();
if (ds.Tables.Count > 0)
{
gridview_order_list.DataSource = ds;
gridview_order_list.DataBind();
dt = ds.Tables[0];
}
else
{
msg.Text = "Unable to connect to the database.";
}
// html_table = ConvertDataTableToHTML(dt);
}
public static string ConvertDataTableToHTML(DataTable dt)
{
string html = "<table class='table table-inverse'>";
//add header row
html += "<tr>";
for (int i = 0; i < dt.Columns.Count; i++)
html += "<td>" + dt.Columns[i].ColumnName + "</td>";
html += "</tr>";
//add rows
for (int i = 0; i < dt.Rows.Count; i++)
{
html += "<tr>";
for (int j = 0; j < dt.Columns.Count; j++)
html += "<td>" + dt.Rows[i][j].ToString() + "</td>";
html += "</tr>";
}
html += "</table>";
return html;
}
DataSet GetData(String queryString)
{
//SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["shopingConnectionString1"].ConnectionString);
// String connectionString=System.Web.Configuration.WebConfigurationManager.ConnectionStrings["shopingConnectionString1"].ConnectionString;
// Retrieve the connection string stored in the Web.config file.
// String connectionString = ConfigurationManager.ConnectionStrings["shopingConnectionString1"].ConnectionString;
DataSet ds = new DataSet();
try
{
// Connect to the database and run the query.
SqlConnection connection = new SqlConnection("Data Source=(LocalDB)\\v11.0;AttachDbFilename=|DataDirectory|\\shoping.mdf;Integrated Security=True;MultipleActiveResultSets=True");
SqlDataAdapter adapter = new SqlDataAdapter(queryString, connection);
// Fill the DataSet.
adapter.Fill(ds);
}
catch (Exception ex)
{
// The connection failed. Display an error message.
msg.Text = "Unable to connect to the database.";
}
return ds;
}
protected void Button_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["shopingConnectionString1"].ConnectionString);
SqlCommand cmd = new SqlCommand();
string query = "insert into product(id,productName,brand,image,catagory,price,quantity) values(" + product_id.Text.Trim() + ",'" + product_name.Text.Trim() + "','" + brand_name.Text.Trim() + "','" + img_path.Text.Trim() + "','" + category.Text.Trim() + "'," + unit_price.Text.Trim() + ","+qty.Text.Trim()+");";
con.Open();
cmd.Connection = con;
cmd.CommandText = query;
cmd.ExecuteNonQuery();
if (cmd.ExecuteNonQuery() > 0)
{
msg.Text = "Added an new order from supplier Successfully. The supplier will update it shortly!";
} con.Close();
}
public string DefaultFileName = "~/img/"; //---- is the folder where files are uploaded to
protected void FileUploader_DataBinding(object sender, EventArgs e)
{
if (FileUploader.HasFile)
try
{
FileUploader.SaveAs(Server.MapPath(DefaultFileName) +
FileUploader.FileName);
img_path.Text = FileUploader.PostedFile.FileName;
}
catch (Exception ex)
{
img_path.Text = "ERROR: " + ex.Message.ToString();
}
else
{
img_path.Text = "You have not specified a file.";
}
}
protected void img_btn_Click(object sender, EventArgs e)
{
if (FileUploader.HasFile)
try
{
FileUploader.SaveAs(Server.MapPath(DefaultFileName) +
FileUploader.FileName);
img_path.Text = FileUploader.PostedFile.FileName;
}
catch (Exception ex)
{
img_path.Text = "ERROR: " + ex.Message.ToString();
}
else
{
img_path.Text = "You have not specified a file.";
}
}
protected void btnReport_Click(object sender, EventArgs e)
{
//**********************
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/order_list.rdlc");
MyDigitalDevicesDataSet MyDigitalDevicesDataSet = new MyDigitalDevicesDataSet();
String s = "SELECT [productName] ,[image],[brand],[catagory],[desciption] ,[quantity] FROM [product]";
SqlDataAdapter da = new SqlDataAdapter(s, con);
DataTable dt = new DataTable();
da.Fill(MyDigitalDevicesDataSet, MyDigitalDevicesDataSet.Tables["product"].TableName);
dt = MyDigitalDevicesDataSet.Tables["product"];
//YouTube. 2016. crystal report,how to create crystal report in C# net using Dataset,visual studio - YouTube. [ONLINE] Available at: https://www.youtube.com/watch?v=uRICO1sZ3Hc. [Accessed 29 December 2016].
Generatereport(dt);
}
private void Generatereport(DataTable dt)
{
ReportViewer1.SizeToReportContent = true;
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/order_list.rdlc");
ReportViewer1.LocalReport.DataSources.Clear();
ReportDataSource _rsource = new ReportDataSource("DataSet1", dt);
ReportViewer1.LocalReport.DataSources.Add(_rsource);
ReportViewer1.LocalReport.Refresh();
}
protected void gridview_order_list_SelectedIndexChanged(object sender, EventArgs e)
{
}
}