示例#1
0
    private void sendReceipt()
    {
        var message = new StringBuilder();
        email.RenderControl(new HtmlTextWriter(new StringWriter(message)));

        string s = message.ToString();

        EmailAlert alerter = new EmailAlert();

        alerter.sendEmail(GenericQuery.getUserEmail(User.Identity.Name), "Web Shop Receipt", s);
    }
示例#2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     EmailAlert instance = new EmailAlert();
     bool test = instance.sendEmail("*****@*****.**", "Very Important thing", "DO IT NOW");
     if (test == true)
     {
         ShowPopUpMsg("True");
     }
     else
     {
         ShowPopUpMsg("False");
     }
 }
    protected void EnableButton_Click(object sender, EventArgs e)
    {
        MembershipUser user = Membership.GetUser(UserName.Text.Trim());
        if (user != null)
        {
            user.IsApproved = true;
            Membership.UpdateUser(user);

            string connectionString = "AsiaWebShopDBConnectionString";
            string query = "UPDATE [Member]"+ "SET [active]="+ 1 +"WHERE ([username] =N'" + UserName.Text.Trim() + "')";
            // Create the connection and the SQL command.
            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings[connectionString].ConnectionString))
            using (SqlCommand command = new SqlCommand(query, connection))
            {
                // Open the connection, execute the INSERT query and close the connection.
                command.Connection.Open();
                command.ExecuteNonQuery();
                command.Connection.Close();
            }
            MemberGridView.DataBind();

            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["AsiaWebShopDBConnectionString"].ConnectionString))
            {
                // start to connect sql server
                connection.Open();

                Int32 count = 0;
                int emailSentNum = 0;
                do
                {
                    SqlCommand command = new SqlCommand("SELECT COUNT(*) FROM [WishListItem] WHERE (([userName]= N'" + UserName.Text.Trim() + "') AND ([emailSent] = N'" + false + "')  AND ([isAlert] = N'" + true + "') AND ([userName] in (SELECT userName FROM [member] WHERE [active] = N'" + true + "')))", connection);
                    count = (Int32)command.ExecuteScalar();

                    if (count != 0)
                    {
                        SqlCommand test = new SqlCommand("SELECT upc FROM [WishListItem] WHERE (([userName]= N'" + UserName.Text.Trim() + "') AND ([emailSent] = N'" + false + "')  AND ([isAlert] = N'" + true + "') AND ([userName] in (SELECT userName FROM [member] WHERE [active] = N'" + true + "')))", connection);
                        String upcNum = test.ExecuteScalar().ToString().Trim();
                        SqlCommand name = new SqlCommand("SELECT name FROM [Item] WHERE (([upc] = N'" + upcNum + "'))", connection);
                        String itemName = name.ExecuteScalar().ToString().Trim();
                        SqlCommand userEmail = new SqlCommand("SELECT email FROM [member] WHERE (([userName] = N'" + UserName.Text.Trim() + "'))", connection);
                        String email = userEmail.ExecuteScalar().ToString().Trim();

                        EmailAlert instance = new EmailAlert();
                        bool isEmailSent = instance.sendEmail(email, itemName + " is now availiable. Come to AisaWebShop.", "Dear customer " + UserName.Text.Trim() + ":\n\n  "
                            + itemName + " is now on stock. Visit our website and You will find products you want are all in our shop.\n\nBest wishes, \nASiaWebShop");
                        if (isEmailSent == true)
                        {
                            SqlCommand alertEmailSent = new SqlCommand("UPDATE [WishListItem] SET [isAlert]=N'" + false + "', [emailSent]= N'" + true + "' WHERE (([upc] = N'" + upcNum + "') AND ([userName] = N'" + UserName.Text.Trim() + "'))", connection);
                            alertEmailSent.ExecuteScalar();
                            emailSentNum++;
                        }
                        else
                        {
                            ShowPopUpMsg("Email can't be sent");
                        }
                    }
                } while (count != 0);

                if (emailSentNum != 0)
                    ShowPopUpMsg(emailSentNum + " email(s) are sent");
                connection.Close();

            }
        }
    }
    protected bool sendEmail(string upc)
    {
        using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["AsiaWebShopDBConnectionString"].ConnectionString))
        {
            // start to connect sql server
            connection.Open();

            Int32 count = 0;
            int emailSentNum = 0;
            do
            {
                SqlCommand command = new SqlCommand("SELECT COUNT(*) FROM [WishListItem] WHERE (([upc] = N'" + upc + "') AND ([emailSent] = N'" + false + "')  AND ([isAlert] = N'" + true + "') AND ([userName] in (SELECT userName FROM [member] WHERE [active] = N'" + true + "')))", connection);
                count = (Int32)command.ExecuteScalar();

                if (count != 0)
                {
                    SqlCommand test = new SqlCommand("SELECT userName FROM [WishListItem] WHERE (([upc] = N'" + upc + "') AND ([emailSent] = N'" + false + "')  AND ([isAlert] = N'" + true + "') AND ([userName] in (SELECT userName FROM [member] WHERE [active] = N'" + true + "')))", connection);
                    String customerName = test.ExecuteScalar().ToString().Trim();
                    SqlCommand name = new SqlCommand("SELECT name FROM [Item] WHERE (([upc] = N'" + upc + "'))", connection);
                    String itemName = name.ExecuteScalar().ToString().Trim();
                    SqlCommand userEmail = new SqlCommand("SELECT email FROM [member] WHERE (([userName] = N'" + customerName + "'))", connection);
                    String email = userEmail.ExecuteScalar().ToString().Trim();

                    EmailAlert instance = new EmailAlert();
                    bool isEmailSent = instance.sendEmail(email, itemName + " is now availiable. Come to AisaWebShop.", "Dear customer " + customerName + ":\n\n  "
                        + itemName + " is now on stock. Visit our website and You will find products you want are all in our shop.\n\nBest wishes, \nASiaWebShop");
                    if (isEmailSent == true)
                    {
                        SqlCommand alertEmailSent = new SqlCommand("UPDATE [WishListItem] SET [isAlert]= N'" + false + "', [emailSent]= N'" + true + "' WHERE (([upc] = N'" + upc + "') AND ([userName] = N'" + customerName + "'))", connection);
                        alertEmailSent.ExecuteScalar();
                        emailSentNum++;
                    }
                    else
                    {
                        ShowPopUpMsg("Email can't be sent");
                    }
                }
            } while (count != 0);

            if (emailSentNum != 0)
                ShowPopUpMsg(emailSentNum + " email(s) are sent");
            connection.Close();

        }
        return true;
    }