File manager - Edit - G:/PleskVhosts/indiaminerals.in/vgm.INFOFIXDEVELOPERS.COM/admin/Stock_QuantityReport.aspx.cs
Back
using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using WebApp.LIBS; namespace VGM.admin { public partial class Stock_QuantityReport : BasePageClass { private object quantityFilter; SqlDataAdapter da1; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string cs = ConfigurationManager.ConnectionStrings["gav"].ConnectionString; // Construct your SQL query to retrieve all data, including Medicine_name string query = "SELECT S.Stock_id, M.Medicine_name AS Medicine_id, S.Purchase_stock " + "FROM stock AS S " + "INNER JOIN medicine AS M ON S.Medicine_id = M.ID " + "ORDER BY S.Stock_id"; using (SqlConnection con = new SqlConnection(cs)) { using (SqlCommand cmd = new SqlCommand(query, con)) { con.Open(); using (SqlDataAdapter da = new SqlDataAdapter(cmd)) { DataTable dt = new DataTable(); da.Fill(dt); Gridview1.DataSource = dt; Gridview1.DataBind(); } } } string medicine = "Select distinct(Medicine_name) from medicine"; using (SqlConnection conn = new SqlConnection(cs)) { using (SqlCommand cmd = new SqlCommand(medicine, conn)) { conn.Open(); using (SqlDataAdapter da1 = new SqlDataAdapter(cmd)) { DataTable dt1 = new DataTable(); da1.Fill(dt1); ddlMedicine.DataSource = dt1; ddlMedicine.DataTextField = "Medicine_name"; ddlMedicine.DataBind(); } } } } } protected void Button1_Click(object sender, EventArgs e) { try { string cs = ConfigurationManager.ConnectionStrings["gav"].ConnectionString; string query = "SELECT S.Stock_id, M.Medicine_name AS Medicine_id, S.Purchase_stock " + "FROM stock AS S " + "INNER JOIN medicine AS M ON S.Medicine_id = M.ID "; int quantityFilter; // Declare quantityFilter outside of the if statements if (radio1.Checked) { // Show items with Purchase_stock less than or equal to 5 query += "WHERE S.Purchase_stock <= 5"; } else if (radio2.Checked) { // Show items with Purchase_stock less than or equal to 10 query += "WHERE S.Purchase_stock <= 10"; } else if (!string.IsNullOrWhiteSpace(TextBox1.Text) && int.TryParse(TextBox1.Text, out quantityFilter)) { // Show items with Purchase_stock less than or equal to the entered quantity query += "WHERE S.Purchase_stock <= @QuantityFilter"; } using (SqlConnection con = new SqlConnection(cs)) { con.Open(); using (SqlCommand cmd = new SqlCommand(query, con)) { if (!string.IsNullOrWhiteSpace(TextBox1.Text) && int.TryParse(TextBox1.Text, out quantityFilter)) { cmd.Parameters.AddWithValue("@QuantityFilter", quantityFilter); } using (SqlDataAdapter da = new SqlDataAdapter(cmd)) { DataTable dt = new DataTable(); da.Fill(dt); Gridview1.DataSource = dt; Gridview1.DataBind(); } } } } catch (Exception ex) { Response.Write("<script>alert('An error occurred: " + ex.Message + "')</script>"); } } protected void ddlMedicine_SelectedIndexChanged(object sender, EventArgs e) { try { string cs = ConfigurationManager.ConnectionStrings["gav"].ConnectionString; string query = "select s.Stock_id, m.Medicine_name AS Medicine_id, s.Purchase_stock from stock as s inner join medicine as m on m.ID = s.Medicine_id where m.Medicine_name = @medicine"; using (SqlConnection con = new SqlConnection(cs)) { con.Open(); using (SqlCommand cmd = new SqlCommand(query, con)) { cmd.Parameters.AddWithValue("@medicine", ddlMedicine.SelectedItem.Text); using (SqlDataAdapter da = new SqlDataAdapter(cmd)) { DataTable dt = new DataTable(); da.Fill(dt); Gridview1.DataSource = dt; Gridview1.DataBind(); } } } } catch (Exception ex) { Response.Write("<script>alert('An error occurred: " + ex.Message + "')</script>"); } } } }
| ver. 1.4 |
Github
|
.
| PHP 7.3.33 | Generation time: 0.05 |
proxy
|
phpinfo
|
Settings