-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStock_M.aspx.cs
More file actions
126 lines (107 loc) · 4.37 KB
/
Stock_M.aspx.cs
File metadata and controls
126 lines (107 loc) · 4.37 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
124
125
126
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class Stock_M : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
UnobtrusiveValidationMode = UnobtrusiveValidationMode.None;
}
protected void Button2_Click(object sender, EventArgs e)
{
string productId = txtPid.Text;
string connectionString = "Server=DESKTOP-1RBA5OG;Database=Inventory_MS;Integrated Security=True";
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
int parsedProductId;
if (int.TryParse(productId, out parsedProductId))
{
using (SqlCommand command = new SqlCommand("SELECT count(*) FROM Stock WHERE P_ID = @P_Id", conn))
{
command.Parameters.AddWithValue("@P_Id", productId);
int result = (int)command.ExecuteScalar();
if (result > 0)
{
// If product exists, redirect to update page with the product ID
Response.Redirect($"Update_Product.aspx?productId={productId}");
}
else
{
lblMessage.Text = "No product with this ID.";
}
}
}
}
}
protected void Button1_Click1(object sender, EventArgs e)
{
int id;
if (int.TryParse(txtPid.Text, out id))
{
// Redirect to the notification page with the Product ID as a query string parameter
Response.Redirect($"Delete_Notification.aspx?P_Id={id}");
}
else
{
lblMessage.Text = "Error: ID must be an integer.";
}
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
protected void Button3_Click(object sender, EventArgs e)
{
string productId = txtPid.Text; // Assume txtProductId is the ID of your TextBox
int parsedProductId;
if (int.TryParse(productId, out parsedProductId))
{
if (!string.IsNullOrEmpty(productId))
{
DataTable dt = GetProductData(productId);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
else
{
GridView1.DataSource = null;
GridView1.DataBind();
lblMessage.Text = "No product found with the specified ID."; // Ensure you have a Label control with ID lblMessage
}
}
}}
private DataTable GetProductData(string productId)
{
string connectionString = "Server=DESKTOP-1RBA5OG;Database=Inventory_MS;Integrated Security=True";
DataTable dt = new DataTable();
using (SqlConnection conn = new SqlConnection(connectionString)) // Ensure connectionString is correctly defined
{
conn.Open();
string sql = "SELECT P_Id, P_name, Catagory, P_Price, Quantity, Sell_Price FROM Stock WHERE P_Id = @P_Id";
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.AddWithValue("@P_Id", productId);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(dt);
}
}
return dt;
}
protected void GridView1_SelectedIndexChanged2(object sender, EventArgs e)
{
// Get the currently selected row using the SelectedIndex property.
GridViewRow row = GridView1.SelectedRow;
// Display a message or redirect based on the selected product
lblMessage.Text = "You selected product ID: " + row.Cells[0].Text; // Assuming the first cell contains the product ID
}
}
}