public List <Email_order> getOrderAll() { List <Email_order> orderList = new List <Email_order>(); int custID; string email, cust_name, contact_no, mbr_status, password, regdatetime; string queryStr = "SELECT * FROM cust_info Order By cust_id"; SqlConnection conn = new SqlConnection(_connstr); SqlCommand cmd = new SqlCommand(queryStr, conn); conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); //Continue to read the resultsets row by row if not the end while (dr.Read()) { custID = Convert.ToInt32(dr["cust_id"].ToString()); email = dr["email"].ToString(); cust_name = dr["cust_name"].ToString(); contact_no = dr["contact_no"].ToString(); mbr_status = dr["mbr_status"].ToString(); password = dr["password"].ToString(); regdatetime = dr["regdatetime"].ToString(); Email_order a = new Email_order(custID, email, cust_name, contact_no, mbr_status, password, regdatetime); orderList.Add(a); } conn.Close(); dr.Close(); dr.Dispose(); return(orderList); }
protected void btn_update_Click(object sender, EventArgs e) { int result = 0; Email_order cust = new Email_order(); result = cust.CustomerUpdate(Convert.ToInt32(lbl_custid.Text), tb_custname.Text, tb_email.Text, tb_contactno.Text); if (result > 0) { Response.Write("<script>alert('Customer updated successfully');</script>"); } else { Response.Write("<script>alert('Customer NOT updated');</script>"); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["cust_id"] == null && Session["emp_id"] == null && Session["dvr_id"] == null && Session["admin_id"] == null) { Response.Redirect("Login.aspx"); } if (!Page.IsPostBack) { int cust_id = Convert.ToInt32(Session["cust_id"].ToString()); Email_order cust = new Email_order(); Email_order data = cust.getOrder(cust_id); lbl_custname.Text = null; lbl_custname.Text = data.cust_name.ToString(); } }
protected void Page_Load(object sender, EventArgs e) { // only commenet the first line away when integration // if statement add to every single page there nids to lock in then can see //Session["cust_id"] = 5; if (Session["cust_id"] == null && Session["emp_id"] == null && Session["dvr_id"] == null && Session["admin_id"] == null) { Response.Redirect("Login.aspx"); } if (!Page.IsPostBack) { int cust_id = Convert.ToInt32(Session["cust_id"].ToString());//Request.QueryString["cust_id"]; Email_order cust = new Email_order(); Email_order data = cust.getOrder(cust_id); lbl_custid.Text = data.cust_id.ToString(); tb_custname.Text = data.cust_name.ToString(); tb_email.Text = data.email.ToString(); tb_contactno.Text = data.contact_no.ToString(); lbl_mbrstatus.Text = data.mbr_status.ToString(); } }
//Below as the Class methods for some DB operations. //We will revisit these section in our next practical public Email_order getOrder(int custID) { Email_order orderDetail = null; string email, cust_name, contact_no, mbr_status, password, regdatetime; string queryStr = "Select * FROM cust_info WHERE cust_id = @custID"; SqlConnection conn = new SqlConnection(_connstr); SqlCommand cmd = new SqlCommand(queryStr, conn); cmd.Parameters.AddWithValue("@custID", custID); conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); //sheck if there are any resultsets if (dr.Read()) { email = dr["email"].ToString(); cust_name = dr["cust_name"].ToString(); contact_no = dr["contact_no"].ToString(); mbr_status = dr["mbr_status"].ToString(); password = dr["password"].ToString(); regdatetime = dr["regdatetime"].ToString(); orderDetail = new Email_order(custID, email, cust_name, contact_no, mbr_status, password, regdatetime); } else { orderDetail = null; } conn.Close(); dr.Close(); dr.Dispose(); return(orderDetail); }