-
Notifications
You must be signed in to change notification settings - Fork 0
/
Db_Ret_Update - Copy.aspx.cs
140 lines (106 loc) · 4.12 KB
/
Db_Ret_Update - Copy.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
using System;
using System.Collections.Generic;
//using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.IO;
using System.Windows.Forms;
//using System.Windows.Forms;
public partial class Db_Retailer : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrated Security=True");
SqlCommand cmd;
SqlDataAdapter da;
DataSet ds = new DataSet();
string query;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
query = "select * from Category";
da = new SqlDataAdapter(query, con);
da.Fill(ds);
if (ds.Tables[0].Rows.Count >= 0)
{
Category.DataSource = ds;
Category.DataTextField = "Name";
Category.DataValueField = "Category_Id";
Category.DataBind();
Category.Items.Insert(0, new ListItem ("Chooose Category","0"));
}
ProdName.Items.Insert(0, "No Product Available");
}
}
protected void Save_Button1_Click1(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
con.Open();
String cat = ProdName.SelectedItem.Text.ToString();
SqlCommand cmd1 = new SqlCommand("Select * from Product_Details where Product_Name='"+cat.ToString()+"'",con);
String pid=(String)cmd1.ExecuteScalar();
SqlCommand cmd=new SqlCommand("update Products SET Unit_Price='"+UnitPrice.Text+"', Unit_In_Stock='"+UnitinStock.Text+"',Discount='"+Disc.Text+"',ExpectedDelivery='"+ExpectDelS.Text+ "',ExpectedDeliveryNS='"+ ExpectDelNS.Text+"'where Product_Id='"+pid+"'",con);
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
// Response.Redirect("Profile.aspx");
}
protected void Category_SelectedIndexChanged(object sender, EventArgs e)
{
con.Open();
ds.Clear();
string get_name, name;
name = Category.SelectedItem.Text;
get_name = Category.SelectedValue.ToString();
if (get_name != "0")
{
query = "select Product_Name,Product_Id from Product_Details where Category_Id='" + get_name.ToString() + "' ";
da = new SqlDataAdapter(query, con);
da.Fill(ds);
if (ds.Tables[0].Rows.Count >= 0)
{
ProdName.DataSource = ds;
ProdName.DataTextField = "Product_Name";
ProdName.DataValueField = "Product_Id";
ProdName.DataBind();
ProdName.Items.Insert(0, new ListItem("Choose " + name.ToString() + " Product ", "0"));
ProdName.SelectedIndex = 0;
}
}
else
{
ProdName.Items.Insert(0, "No Product Available");
ProdName.DataBind();
}
}
protected void Button3_Click(object sender, EventArgs e)
{
Disc.Enabled = true;
UnitinStock.Enabled = true;
UnitPrice.Enabled = true;
ExpectDelNS.Enabled = true;
ExpectDelS.Enabled = true;
}
protected void ProdName_SelectedIndexChanged(object sender, EventArgs e)
{
con.Open();
String cat = ProdName.SelectedItem.Text.ToString();
SqlCommand cmd1 = new SqlCommand("Select Product_Id from Product_Details where Product_Name='" + cat.ToString() + "'", con);
String pid = (String)cmd1.ExecuteScalar();
SqlCommand cmd = new SqlCommand("Select * from Products where Product_Id='" + pid + "'", con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
UnitPrice.Text += dr[2].ToString();
UnitinStock.Text += dr[3].ToString();
Disc.Text += dr[4].ToString();
ExpectDelS.Text += dr[5].ToString();
ExpectDelS.Text += dr[6].ToString();
}
}
}