-
Notifications
You must be signed in to change notification settings - Fork 0
/
inventory.aspx.cs
235 lines (167 loc) · 7.42 KB
/
inventory.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
228
229
230
231
232
233
234
235
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 Microsoft.Reporting.WebForms;
using Microsoft.Reporting.Common;
using Microsoft.Reporting;
public partial class inventory : System.Web.UI.Page
{
// public DataGrid gridview_inventory{get; set;}
public string html_table{get;set;}
//
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["shopingConnectionString1"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
// public DataGrid gridview_inventory{get; set;}
if (!IsPostBack)
{
// Declare the query string.
String queryString =
"SELECT id,productName as 'Supplier_Inventory_product_name' ,brand,catagory,desciption,price,rating,comments 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_inventory.DataSource = ds;
gridview_inventory.DataBind();
dt = ds.Tables[0];
}
else
{
msg.Text = "Unable to connect to the database.";
}
html_table = ConvertDataTableToHTML(dt);
}
}
public static string ConvertDataTableToHTML(DataTable dt)
{
/*
c# - Datatable to html Table - Stack Overflow. . c# - Datatable to html Table - Stack Overflow. [ONLINE] Available at: http://stackoverflow.com/questions/19682996/datatable-to-html-table. [Accessed 15 November 2016].
*/
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)
{
DataSet ds = new DataSet();
try
{
// Connect to the database and run the query.
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["shopingConnectionString1"].ConnectionString);
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 = "Update product set catagory='" + cat_name.SelectedValue.ToString().Trim() + "',productName='" + txt_product_name.Text.Trim() + "',brand='" + txt_brand.Text.Trim() + "',desciption='" + txt_description.Text.Trim() + "',price='" + txt_price.Text.Trim() + "',rating='" + txt_rating.Text.Trim() + "' ,comments='" + txt_comments.Text.Trim() + "',quantity='"+qty.Text.Trim()+"' where id='" + item_id.SelectedValue.ToString().Trim() + "' ";
con.Open();
cmd.Connection = con;
cmd.CommandText = query;
cmd.ExecuteNonQuery();
if (cmd.ExecuteNonQuery() > 0)
{
msg.Text = "Updated Successfully.";
} con.Close();
}
protected void total_btn_Click(object sender, EventArgs e)
{
if (qty.Text != null || unit_price!=null)
{
double d = Double.Parse(qty.Text);
double d1 = Double.Parse(unit_price.Text);
double total_price = d * d1;
total.Text = total_price.ToString();
}
}
protected void total_TextChanged(object sender, EventArgs e)
{
if (Double.Parse(qty.Text) >= 0)
{
double d = Double.Parse(qty.Text);
double d1 = Double.Parse(unit_price.Text);
double total_price = d * d1;
total.Text = total_price.ToString();
}
}
protected void total_btn_Click1(object sender, EventArgs e)
{
if (qty.Text != null || unit_price != null)
{
double d = Double.Parse(qty.Text);
double d1 = Double.Parse(unit_price.Text);
double total_price = d * d1;
total.Text = total_price.ToString();
}
}
private void Generatereport(DataTable dt)
{
ReportViewer1.SizeToReportContent = true;
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/inventory_new.rdlc");
ReportViewer1.LocalReport.DataSources.Clear();
ReportDataSource _rsource = new ReportDataSource("DataSet2", dt);
ReportViewer1.LocalReport.DataSources.Add(_rsource);
ReportViewer1.LocalReport.Refresh();
}
protected void btnReport_Click(object sender, EventArgs e)
{
Response.Write("8888");
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/inventory_new.rdlc");
MyDigitalDevicesDataSet MyDigitalDevicesDataSet = new MyDigitalDevicesDataSet();
String s = "SELECT [id],[productName] as 'Supplier_Inventory_product_name' ,[brand],[catagory],[desciption] ,[price],[rating],[comments] FROM [product]";
SqlDataAdapter da = new SqlDataAdapter(s, con);
DataTable dtable = new DataTable();
da.Fill(MyDigitalDevicesDataSet, MyDigitalDevicesDataSet.Tables["product"].TableName);
dtable = MyDigitalDevicesDataSet.Tables["product"];
//YouTube. 2016. how to create report in C# net using Dataset,visual studio - YouTube. [ONLINE] Available at: https://www.youtube.com/watch?v=uRICO1sZ3Hc. [Accessed 29 December 2016].
Generatereport(dtable);
}
protected void Button1_Click(object sender, EventArgs e)
{
string s = @"~\img\product\" + FileUpload1.FileName;
FileUpload1.PostedFile.SaveAs(Server.MapPath(s));
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["shopingConnectionString1"].ConnectionString);
SqlCommand cmd = new SqlCommand();
string query = "insert into product(catagory,productName,brand,desciption,price,rating,comments,image,quantity) values('" + cat_name.SelectedValue.ToString().Trim() + "','" + txt_product_name.Text.Trim() + "','" + txt_brand.Text.Trim() + "','" + txt_description.Text.Trim() + "','" + txt_price.Text.Trim() + "','" + txt_rating.Text.Trim() + "','" + txt_comments.Text.Trim() + "','" + s + "','" + qty.Text.Trim()+ "') ";
con.Open();
cmd.Connection = con;
cmd.CommandText = query;
cmd.ExecuteNonQuery();
if (cmd.ExecuteNonQuery() > 0)
{
msg.Text = "Added new inventory items Successfully.";
} con.Close();
}
}