public List <Email_orderDriver> getOrderAll() { List <Email_orderDriver> orderList = new List <Email_orderDriver>(); string custID, email, cust_name, contact_no, mbr_status; 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 = 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(); Email_orderDriver a = new Email_orderDriver(custID, email, cust_name, contact_no, mbr_status); orderList.Add(a); } conn.Close(); dr.Close(); dr.Dispose(); return(orderList); }
//Below as the Class methods for some DB operations. //We will revisit these section in our next practical public Email_orderDriver getOrder(string custID) { Email_orderDriver orderDetail = null; string cust_name, contact_no, mbr_status; 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(); orderDetail = new Email_orderDriver(email, cust_name, contact_no, mbr_status); } else { orderDetail = null; } conn.Close(); dr.Close(); dr.Dispose(); return(orderDetail); }
protected void btn_Accepted_Click(object sender, EventArgs e) { // Get button from the gridview, sender is the object of the butotn Button btn = (Button)sender; // Gets the row of the button in the gridview GridViewRow gvr = (GridViewRow)btn.NamingContainer; // Gets the order id from the gridview string order_id = gvr.Cells[0].Text; // Create object and use the method OrderDriver orders = new OrderDriver(); int result = orders.orderUpdateStatus(order_id, "Completed"); string email; /* * Open database and using customer pk to find it * string customer_ID = gvr.Cells[3].Text; * customer.getcustomer(customer_Id); //get single customer data out from database * email = customer.email.tostring(); // make string email to the customer email * */ Email_orderDriver Eo = new Email_orderDriver(); string customer_ID = gvr.Cells[3].Text; Email_orderDriver customer = Eo.getOrder(customer_ID); email = customer.email.ToString(); //Response.Write(String.Format("<script>alert('{0}');</script>", email)); if (result > 0) { // If validated properly Response.Write("<script>alert('Product updated');</script>"); //ADD EMAIL HERE string psender = "*****@*****.**"; string subject = "Order Completed"; string body = "Order have been Completed. Enjoy"; try { MailMessage message = new MailMessage(psender, email, subject, body); message.IsBodyHtml = true; SmtpClient client = new SmtpClient("smtp.gmail.com", 587); client.EnableSsl = true; client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Ebusiness"); client.Send(message); } catch (Exception ex) { } } else { // If something went wrong Response.Write("<script>alert('Product NOT updated');</script>"); } //Reload the table bind(); // NOTE THAT WHEN YOU UPDATE TO ACCEPTED, IT WILL NOT SHOW ON DRIVER.ASPX BECAUSE BIND() VARIABLE IS "NEW" (Line 21) //NEW PLAN //click pickup update status to collected //BELOW IS OLD PLAN /* * Session["orderID"] = 1; //change 1 to order id of the row you click * Session["hello"] = "pickup"; * * * //in other aspx.cs page_load * if(Session["hello"].Equals("pickup")) * { * //display all the pickup info * } * else if (Session["hello"].Equals("delivery")) * { //display all the pickup info * * } */ }
protected void btn_Rejected_Click(object sender, EventArgs e) { // Get button from the gridview, sender is the object of the butotn Button btn = (Button)sender; // Gets the row of the button in the gridview GridViewRow gvr = (GridViewRow)btn.NamingContainer; // Gets the order id from the gridview string order_id = gvr.Cells[0].Text; // Create object and use the method OrderDriver orders = new OrderDriver(); int result = orders.orderUpdateStatus(order_id, "REJECTED"); string email; /* * Open database and using customer pk to find it * string customer_ID = gvr.Cells[3].Text; * customer.getcustomer(customer_Id); //get single customer data out from database * email = customer.email.tostring(); // make string email to the customer email * */ Email_orderDriver Eo = new Email_orderDriver(); string customer_ID = gvr.Cells[3].Text; Email_orderDriver customer = Eo.getOrder(customer_ID); email = customer.email.ToString(); //Response.Write(String.Format("<script>alert('{0}');</script>", email)); if (result > 0) { // If validated properly Response.Write("<script>alert('Product updated');</script>"); //ADD EMAIL HERE string psender = "*****@*****.**"; string subject = "Found Driver"; string body = "Order have been cancel. Please try again later"; try { MailMessage message = new MailMessage(psender, email, subject, body); message.IsBodyHtml = true; SmtpClient client = new SmtpClient("smtp.gmail.com", 587); client.EnableSsl = true; client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Ebusiness"); client.Send(message); } catch (Exception ex) { } } else { // If something went wrong Response.Write("<script>alert('Product NOT updated');</script>"); } //Reload the table bind(); // NOTE THAT WHEN YOU UPDATE TO ACCEPTED, IT WILL NOT SHOW ON DRIVER.ASPX BECAUSE BIND() VARIABLE IS "NEW" (Line 21) }