protected void Button1_payment(object sender, EventArgs e) { try { Parent_ID = Login_page.getParentIDFromDatabase(); Parent_name = Label1.Text; ChildrenQ = GetChildQuantity().ToString(); Total_Amount = GetTotalAmount().ToString(); payment_date = LabelDate.Text; inserted_amount = TextBox3.Text; SqlConnection conn = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename = C:\Users\tumi\source\repos\LearnOnlineSystem\LearnOnlineSystem\App_Data\Learn_Online_System.mdf; Integrated Security = True"); conn.Open(); SqlCommand cmd = new SqlCommand("INSERT into payment (Parent_ID,Parent_name,ChildrenQ,Total_Amount,payment_date,inserted_amount)values (@Parent_ID,@Parent_name,@ChildrenQ,@Total_Amount,@payment_date,@inserted_amount)"); cmd.Parameters.AddWithValue("@Parent_ID", Parent_ID); cmd.Parameters.AddWithValue("@Parent_name", Parent_name); cmd.Parameters.AddWithValue("@ChildrenQ", ChildrenQ); cmd.Parameters.AddWithValue("@Total_Amount", Total_Amount); cmd.Parameters.AddWithValue("@payment_date", payment_date); cmd.Parameters.AddWithValue("@inserted_amount", inserted_amount); cmd.Connection = conn; cmd.ExecuteNonQuery(); conn.Close(); Response.Redirect("ConfirmationPayment.aspx"); ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "Thank you payment completed" + "'); ", true); //alert shown. } catch (FormatException) { ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "you already Paid " + "'); ", true); //alert shown. } }
public int GetPaymentIDFromDatabaseTable() { SqlConnection conn = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename = C:\Users\tumi\source\repos\LearnOnlineSystem\LearnOnlineSystem\App_Data\Learn_Online_System.mdf; Integrated Security = True"); conn.Open(); string selectQuery = "SELECT * FROM payment WHERE Parent_ID =" + Login_page.getParentIDFromDatabase(); SqlCommand comm = new SqlCommand(selectQuery, conn); SqlDataReader mdr = comm.ExecuteReader(); if (mdr.Read()) { paymentId = (mdr["payment_id"].ToString()); } conn.Close(); return(int.Parse(paymentId)); }
public static int GetChildQuantity() { SqlConnection conn = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename = C:\Users\tumi\source\repos\LearnOnlineSystem\LearnOnlineSystem\App_Data\Learn_Online_System.mdf; Integrated Security = True"); conn.Open(); string selectQuery = "SELECT COUNT(parentID) FROM child WHERE parentID='" + Login_page.getParentIDFromDatabase() + "';"; SqlCommand comm = new SqlCommand(selectQuery, conn); Int32 count = Convert.ToInt32(comm.ExecuteScalar()); if (count > 0) { AVG = count.ToString(); } else { AVG = "0"; } conn.Close(); return(int.Parse(AVG)); }